From c5f39ea2cd7cf02246705ea8872d3b350526165c Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Fri, 24 May 2024 09:05:42 -0400 Subject: initial --- src/web/_model/_comments.php | 66 ++++++++++++++++++++++++++++++ src/web/_model/blog.php | 80 ++++++++++++++++++++++++++++++++++++ src/web/_model/bucket.php | 26 ++++++++++++ src/web/_model/error.php | 31 ++++++++++++++ src/web/_model/main.php | 97 ++++++++++++++++++++++++++++++++++++++++++++ src/web/_model/projects.php | 36 ++++++++++++++++ 6 files changed, 336 insertions(+) create mode 100644 src/web/_model/_comments.php create mode 100644 src/web/_model/blog.php create mode 100644 src/web/_model/bucket.php create mode 100644 src/web/_model/error.php create mode 100644 src/web/_model/main.php create mode 100644 src/web/_model/projects.php (limited to 'src/web/_model') diff --git a/src/web/_model/_comments.php b/src/web/_model/_comments.php new file mode 100644 index 0000000..73c1fc7 --- /dev/null +++ b/src/web/_model/_comments.php @@ -0,0 +1,66 @@ + $line) { + if ($line == '') { + continue; + } + if ($idx != 0) { + $regex .= '|'; + } + $regex .= $line; + } + $regex .= ')/'; + + return $regex; + } + + public function is_vulgar($text) { + $profanity = $this->load_profanity(); + return preg_match($profanity, $text); + } + + public function get_comments($page) { + $ip = $this->main->info['ip']; + $query = $this->db + ->select('*') + ->from('admin.comment c') + ->where('c.page') + ->eq($page) + ->query('AND ( + (c.vulgar IS FALSE) OR + (c.vulgar IS TRUE and c.ip = ?) + )') + ->order_by('c.id', 'DESC'); + $result = $query->rows($ip); + return $result; + } + + public function ban_user() { + $ip = $this->main->info['ip']; + $this->db + ->insert_into('admin.banned', 'ip', 'reason') + ->values($ip, 'vulgar language') + ->execute(); + } + + public function post_comment($author, $content, $page, $vulgar) { + $ip = $this->main->info['ip']; + return $this->db + ->insert_into('admin.comment', + 'author', 'content', 'page', 'ip', 'vulgar') + ->values($author, $content, $page, $ip, $vulgar) + ->execute(); + } + +} diff --git a/src/web/_model/blog.php b/src/web/_model/blog.php new file mode 100644 index 0000000..42cee97 --- /dev/null +++ b/src/web/_model/blog.php @@ -0,0 +1,80 @@ +markdown = new MarkdownParser(); + } + + private function load_blog(&$data) { + $blog = array(); + $dir = $GLOBALS['assetroot'] . '/blog'; + if ($handle = opendir($dir)) { + while (false !== ($entry = readdir($handle))) { + if (str_starts_with($entry, ".")) { + continue; + } + $path = $dir . '/' . $entry; + $md = $this->markdown->parse($path); + $blog[$entry] = $md; + } + } + krsort($blog); + $data['blog'] = $blog; + } + + public function get_data(): ?array { + $data = parent::get_data(); + $this->load_blog($data); + $data['title'] = lang('title'); + $data['desc'] = lang('blog_short_desc'); + return $data; + } + + private function load_post($name) { + $dir = $GLOBALS['assetroot'] . '/blog'; + $path = $dir . '/' . $name; + if(!file_exists($path)) { + return FALSE; + } + $md = $this->markdown->parse($path); + return $md; + } + + public function get_post($name) { + $data = parent::get_data(); + $post = $this->load_post($name); + if (!$post) { + return FALSE; + } + $data['title'] = $post['meta']['name']; + $data['desc'] = $post['meta']['desc']; + $data['post'] = $post; + return $data; + } + + private function load_writeup($name) { + $dir = $GLOBALS['assetroot'] . '/writeup'; + $path = $dir . '/' . $name; + if(!file_exists($path)) { + return FALSE; + } + $md = $this->markdown->parse($path); + return $md; + } + + public function get_writeup($name) { + $data = parent::get_data(); + $writeup = $this->load_writeup($name); + if (!$writeup) { + return FALSE; + } + $data['title'] = $writeup['meta']['name']; + $data['desc'] = $writeup['meta']['desc']; + $data['post'] = $writeup; + return $data; + } +} +?> diff --git a/src/web/_model/bucket.php b/src/web/_model/bucket.php new file mode 100644 index 0000000..f38bebe --- /dev/null +++ b/src/web/_model/bucket.php @@ -0,0 +1,26 @@ + diff --git a/src/web/_model/error.php b/src/web/_model/error.php new file mode 100644 index 0000000..0a08fdd --- /dev/null +++ b/src/web/_model/error.php @@ -0,0 +1,31 @@ +get_msg($data); + return $data; + } +} +?> diff --git a/src/web/_model/main.php b/src/web/_model/main.php new file mode 100644 index 0000000..6767010 --- /dev/null +++ b/src/web/_model/main.php @@ -0,0 +1,97 @@ +\d+)/i', @$_SERVER['HTTP_USER_AGENT'], $B)) { + return $B['v']; + } else { + return PHP_INT_MAX; + } + } + + /** + * Gets the full url including the http scheme and host part + * Needed for IE 6 & 7 need. + */ + public function get_url_full($path): string { + $host = $_SERVER['HTTP_HOST']; + $base = lang('base_path'); + $url = "http://{$host}{$base}{$path}"; + return $url; + } + + /** + * Gets a full path url from a relative path + */ + public function get_url($path): string { + if ($this->get_ie_version() <= 7) { + return $this->get_url_full($path); + } + $base = lang('base_path'); + $url = "{$base}{$path}"; + return $url; + } + + /** + * Loads a css html link + * @param string $path - the path to the css file + */ + public function link_css($path): string { + $stamp = $this->asset_stamp($path); + $href = $this->get_url("public/{$path}?stamp={$stamp}"); + return ''; + } + + /** + * Loads a css html link + * @param string $path - the path to the css file + */ + public function embed_css($path): string { + $file = $GLOBALS['publicroot'] . '/' . $path; + if (file_exists($file)) { + $text = file_get_contents($file); + return ""; + } else { + return ""; + } + } + + /** + * Formats a ISO date + * @param $iso_date the ISO date + */ + public function format_date($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 new file mode 100644 index 0000000..5373a78 --- /dev/null +++ b/src/web/_model/projects.php @@ -0,0 +1,36 @@ +markdown = new MarkdownParser(); + } + + private function load_projects(&$data) { + $projects = array(); + $dir = $GLOBALS['assetroot'] . '/projects'; + if ($handle = opendir($dir)) { + while (false !== ($entry = readdir($handle))) { + if (str_starts_with($entry, ".")) { + continue; + } + $path = $dir . '/' . $entry; + $md = $this->markdown->parse($path); + $projects[$entry] = $md; + } + } + krsort($projects); + $data['projects'] = $projects; + } + + public function get_data(): ?array { + $data = parent::get_data(); + $this->load_projects($data); + $data['title'] = lang('title'); + $data['desc'] = lang('short_desc'); + return $data; + } +} +?> -- cgit v1.2.3-freya