summaryrefslogtreecommitdiff
path: root/src/web/_model
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-07-08 17:22:30 -0400
committerFreya Murphy <freya@freyacat.org>2024-07-08 17:22:30 -0400
commit8a2c577823b69117af8eda9b1a46bfbcae8153c6 (patch)
treee89dee0f77377a665c78d8a3cea6012888d9af73 /src/web/_model
parentfix2 (diff)
downloadwebsite-8a2c577823b69117af8eda9b1a46bfbcae8153c6.tar.gz
website-8a2c577823b69117af8eda9b1a46bfbcae8153c6.tar.bz2
website-8a2c577823b69117af8eda9b1a46bfbcae8153c6.zip
a few fixes, just a few....
Diffstat (limited to 'src/web/_model')
-rw-r--r--src/web/_model/blog.php42
-rw-r--r--src/web/_model/main.php43
-rw-r--r--src/web/_model/projects.php5
3 files changed, 59 insertions, 31 deletions
diff --git a/src/web/_model/blog.php b/src/web/_model/blog.php
index 42cee97..52fb97c 100644
--- a/src/web/_model/blog.php
+++ b/src/web/_model/blog.php
@@ -7,8 +7,11 @@ class Blog_model extends Model {
parent::__construct($load);
$this->markdown = new MarkdownParser();
}
-
- private function load_blog(&$data) {
+ /**
+ * @param mixed $data
+ * @return void
+ */
+ private function load_blog(&$data): void {
$blog = array();
$dir = $GLOBALS['assetroot'] . '/blog';
if ($handle = opendir($dir)) {
@@ -32,44 +35,55 @@ class Blog_model extends Model {
$data['desc'] = lang('blog_short_desc');
return $data;
}
-
- private function load_post($name) {
+ /**
+ * @param mixed $name
+ * @return bool|<missing>
+ */
+ private function load_post($name): ?array {
$dir = $GLOBALS['assetroot'] . '/blog';
$path = $dir . '/' . $name;
if(!file_exists($path)) {
- return FALSE;
+ return NULL;
}
$md = $this->markdown->parse($path);
return $md;
}
-
- public function get_post($name) {
+ /**
+ * @param mixed $name
+ * @return bool|null|array
+ */
+ public function get_post($name): ?array {
$data = parent::get_data();
$post = $this->load_post($name);
if (!$post) {
- return FALSE;
+ return NULL;
}
$data['title'] = $post['meta']['name'];
$data['desc'] = $post['meta']['desc'];
$data['post'] = $post;
return $data;
}
-
- private function load_writeup($name) {
+ /**
+ * @param mixed $name
+ */
+ private function load_writeup($name): ?string {
$dir = $GLOBALS['assetroot'] . '/writeup';
$path = $dir . '/' . $name;
if(!file_exists($path)) {
- return FALSE;
+ return NULL;
}
$md = $this->markdown->parse($path);
return $md;
}
-
- public function get_writeup($name) {
+ /**
+ * @param mixed $name
+ * @return bool|null|array
+ */
+ public function get_writeup($name): ?array {
$data = parent::get_data();
$writeup = $this->load_writeup($name);
if (!$writeup) {
- return FALSE;
+ return NULL;
}
$data['title'] = $writeup['meta']['name'];
$data['desc'] = $writeup['meta']['desc'];
diff --git a/src/web/_model/main.php b/src/web/_model/main.php
index 5728932..cbcf498 100644
--- a/src/web/_model/main.php
+++ b/src/web/_model/main.php
@@ -2,16 +2,16 @@
class Main_model extends Model {
// stores the current request info
- public $info;
+ public mixed $info;
// the main loader
- public $load;
+ public Loader $load;
/**
* Loads the main model
* @param Loader $load - the main loader object
*/
- function __construct($load) {
+ function __construct(Loader $load) {
parent::__construct($load, TRUE);
$GLOBALS['main_model'] = $this;
}
@@ -20,7 +20,7 @@ class Main_model extends Model {
* Gets the stamp for a asset path
* @param string $path
*/
- private function asset_stamp($path): int {
+ private function asset_stamp(string $path): int {
$root = $GLOBALS['webroot'];
$path = $root . '/../public/' . $path;
return @filemtime($path);
@@ -41,25 +41,36 @@ class Main_model extends Model {
/**
* Gets the full url including the http scheme and host part
* Needed for IE 6 & 7 need.
- */
- public function get_url_full($path): string {
+ * @param string $path
+ * @param bool $timestamp
+ */
+ public function get_url_full(string $path, bool $timestamp = FALSE): string {
$host = $_SERVER['HTTP_HOST'];
$base = lang('base_path');
- $time = @filemtime($GLOBALS['rootroot'] . '/' . $path);
- $url = "http://{$host}{$base}{$path}?timestamp={$time}";
+
+ $url = "http://{$host}{$base}{$path}";
+ if ($timestamp) {
+ $time = @filemtime($GLOBALS['rootroot'] . '/' . $path);
+ $url .= "?timestamp={$time}";
+ }
return $url;
}
/**
* Gets a full path url from a relative path
- */
- public function get_url($path): string {
+ * @param string $path
+ * @param bool $timestamp
+ */
+ public function get_url(string $path, bool $timestamp = FALSE): string {
if ($this->get_ie_version() <= 7) {
- return $this->get_url_full($path);
+ return $this->get_url_full($path, $timestamp);
}
$base = lang('base_path');
- $time = @filemtime($GLOBALS['rootroot'] . '/' . $path);
- $url = "{$base}{$path}?timestamp={$time}";
+ $url = "{$base}{$path}";
+ if ($timestamp) {
+ $time = @filemtime($GLOBALS['rootroot'] . '/' . $path);
+ $url .= "?timestamp={$time}";
+ }
return $url;
}
@@ -67,7 +78,7 @@ class Main_model extends Model {
* Loads a css html link
* @param string $path - the path to the css file
*/
- public function link_css($path): string {
+ public function link_css(string $path): string {
$stamp = $this->asset_stamp($path);
$href = $this->get_url("public/{$path}?stamp={$stamp}");
return '<link rel="stylesheet" href="'. $href .'">';
@@ -77,7 +88,7 @@ class Main_model extends Model {
* Loads a css html link
* @param string $path - the path to the css file
*/
- public function embed_css($path): string {
+ public function embed_css(string $path): string {
$file = $GLOBALS['publicroot'] . '/' . $path;
if (file_exists($file)) {
$text = file_get_contents($file);
@@ -91,7 +102,7 @@ class Main_model extends Model {
* Formats a ISO date
* @param $iso_date the ISO date
*/
- public function format_date($iso_date): string {
+ public function format_date(string $iso_date): string {
return date("Y-m-d D H:m", strtotime($iso_date));
}
}
diff --git a/src/web/_model/projects.php b/src/web/_model/projects.php
index 5373a78..784e12a 100644
--- a/src/web/_model/projects.php
+++ b/src/web/_model/projects.php
@@ -8,7 +8,10 @@ class Projects_model extends Model {
$this->markdown = new MarkdownParser();
}
- private function load_projects(&$data) {
+ /**
+ * @param array<string,mixed> $data
+ */
+ private function load_projects(&$data): void {
$projects = array();
$dir = $GLOBALS['assetroot'] . '/projects';
if ($handle = opendir($dir)) {