summaryrefslogtreecommitdiff
path: root/src
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
parentfix2 (diff)
downloadwebsite-8a2c577823b69117af8eda9b1a46bfbcae8153c6.tar.gz
website-8a2c577823b69117af8eda9b1a46bfbcae8153c6.tar.bz2
website-8a2c577823b69117af8eda9b1a46bfbcae8153c6.zip
a few fixes, just a few....
Diffstat (limited to 'src')
-rw-r--r--src/web/_controller/_comments.php2
-rw-r--r--src/web/_controller/_meta.php8
-rw-r--r--src/web/_controller/blog.php4
-rw-r--r--src/web/_model/blog.php42
-rw-r--r--src/web/_model/main.php43
-rw-r--r--src/web/_model/projects.php5
-rw-r--r--src/web/_views/comments.php3
-rw-r--r--src/web/_views/head.php14
-rw-r--r--src/web/core/_controller.php15
-rw-r--r--src/web/core/_model.php13
-rw-r--r--src/web/core/loader.php7
-rw-r--r--src/web/core/router.php28
-rw-r--r--src/web/helpers/aria.php2
-rw-r--r--src/web/helpers/database.php80
-rw-r--r--src/web/helpers/image.php4
-rw-r--r--src/web/helpers/lang.php31
-rw-r--r--src/web/helpers/markdown.php5
-rw-r--r--src/web/helpers/sanitize.php2
18 files changed, 189 insertions, 119 deletions
diff --git a/src/web/_controller/_comments.php b/src/web/_controller/_comments.php
index 4b87a94..059b926 100644
--- a/src/web/_controller/_comments.php
+++ b/src/web/_controller/_comments.php
@@ -9,7 +9,7 @@ class _comments_controller extends Controller {
}
- public function comments($page, $ref): void {
+ public function comments(string $page, string $ref): void {
$data = $this->comments_model->get_comments($page);
$this->view('comments', array(
'comments' => $data,
diff --git a/src/web/_controller/_meta.php b/src/web/_controller/_meta.php
index 801d254..e78f8b3 100644
--- a/src/web/_controller/_meta.php
+++ b/src/web/_controller/_meta.php
@@ -5,7 +5,7 @@ class _meta_controller extends Controller {
parent::__construct($load);
}
- public function robots() {
+ public function robots(): void {
header("Content-Type: text/plain");
$sitemap = $this->main->get_url_full('sitemap.xml');
@@ -18,14 +18,14 @@ class _meta_controller extends Controller {
echo "Sitemap: {$sitemap}\n";
}
- private function sitemap_page($url, $priority) {
+ private function sitemap_page(string $url, string $priority): void {
echo "<url>\n";
echo "<loc>{$this->main->get_url_full($url)}</loc>\n";
echo "<priority>{$priority}</priority>\n";
echo "</url>";
}
- public function sitemap() {
+ public function sitemap(): void {
header("Content-Type: application/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
@@ -46,7 +46,7 @@ class _meta_controller extends Controller {
echo "</urlset>\n";
}
- public function manifest() {
+ public function manifest(): void {
$json = array(
'short_name' => lang('domain'),
'name' => lang('domain'),
diff --git a/src/web/_controller/blog.php b/src/web/_controller/blog.php
index f13ffd1..4a961e1 100644
--- a/src/web/_controller/blog.php
+++ b/src/web/_controller/blog.php
@@ -18,7 +18,7 @@ class Blog_controller extends Controller {
$this->view('footer', $data);
}
- private function protect($folder) {
+ private function protect(string $folder): void {
if (!array_key_exists('name', $_GET)) {
$this->error(400);
}
@@ -62,7 +62,7 @@ class Blog_controller extends Controller {
$this->view('footer', $data);
}
- public function rss() {
+ public function rss(): void {
$data = $this->blog_model->get_data();
header('Content-Type: application/xml');
$this->view('apps/blog_rss', $data);
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)) {
diff --git a/src/web/_views/comments.php b/src/web/_views/comments.php
index d72afd6..7f8acf2 100644
--- a/src/web/_views/comments.php
+++ b/src/web/_views/comments.php
@@ -2,8 +2,7 @@
<?=aria_section('comments', lang('comments'))?>
<?php
foreach($comments as $comment) {
- $date = date_create($comment['created']);
- $date = date_format($date, "Y-m-d H:i");
+ $date = $this->main->format_date($comment['created']);
echo '<div class="comment">';
echo '<h3 class="header">' . esc($comment['author']) . '</h3>';
diff --git a/src/web/_views/head.php b/src/web/_views/head.php
index ef0d86c..5534070 100644
--- a/src/web/_views/head.php
+++ b/src/web/_views/head.php
@@ -12,14 +12,14 @@
<meta property="og:description" content="<?=$desc?>">
<meta property="og:title" content="<?=$title?>">
<meta property="og:site_name" content="<?=lang('domain')?>">
- <meta property="og:image" content="<?=$this->main->get_url_full('public/icons/logo640.png')?>">
+ <meta property="og:image" content="<?=$this->main->get_url_full('public/icons/logo640.png', TRUE)?>">
<title><?=$title?></title>
- <link rel="icon" type="image/png" sizes="16x16" href="<?=$this->main->get_url("public/icons/logo16.png")?>">
- <link rel="icon" type="image/png" sizes="32x32" href="<?=$this->main->get_url("public/icons/logo32.png")?>">
- <link rel="icon" type="image/png" sizes="64x64" href="<?=$this->main->get_url("public/icons/logo64.png")?>">
- <link rel="icon" type="image/png" sizes="320x320" href="<?=$this->main->get_url("public/icons/logo320.png")?>">
- <link rel="icon" type="image/png" sizes="512x512" href="<?=$this->main->get_url("public/icons/logo512.png")?>">
- <link rel="icon" type="image/png" sizes="640x640" href="<?=$this->main->get_url("public/icons/logo640.png")?>">
+ <link rel="icon" type="image/png" sizes="16x16" href="<?=$this->main->get_url("public/icons/logo16.png", TRUE)?>">
+ <link rel="icon" type="image/png" sizes="32x32" href="<?=$this->main->get_url("public/icons/logo32.png", TRUE)?>">
+ <link rel="icon" type="image/png" sizes="64x64" href="<?=$this->main->get_url("public/icons/logo64.png", TRUE)?>">
+ <link rel="icon" type="image/png" sizes="320x320" href="<?=$this->main->get_url("public/icons/logo320.png", TRUE)?>">
+ <link rel="icon" type="image/png" sizes="512x512" href="<?=$this->main->get_url("public/icons/logo512.png", TRUE)?>">
+ <link rel="icon" type="image/png" sizes="640x640" href="<?=$this->main->get_url("public/icons/logo640.png", TRUE)?>">
<link rel="manifest" href="/manifest.json">
<?php if($this->main->get_ie_version() <= 7)
echo $this->main->link_css('css/legacy.css');
diff --git a/src/web/core/_controller.php b/src/web/core/_controller.php
index 0dbb5b8..1da5a96 100644
--- a/src/web/core/_controller.php
+++ b/src/web/core/_controller.php
@@ -2,10 +2,10 @@
abstract class Controller {
// the main model
- public $main;
+ public Main_model $main;
// the loader
- public $load;
+ public Loader $load;
/**
* Creates a constructor
@@ -23,14 +23,17 @@ abstract class Controller {
}
}
- public function index() {}
+ public function index(): void {}
- public function redirect($link) {
+ public function redirect(string $link): void {
header('Location: '. $link, true, 301);
die();
}
- protected function view($__name, $data = array()) {
+ /**
+ * @param array<int,mixed> $data
+ */
+ protected function view(string $__name, array $data = array()): void {
$__root = $GLOBALS['webroot'];
$__path = $__root . '/_views/' . $__name . '.php';
if (is_file($__path)) {
@@ -40,7 +43,7 @@ abstract class Controller {
}
}
- protected function error($code): void {
+ protected function error(int $code): void {
$_GET['code'] = $code;
$this->main->info['app'] = 'error';
$error_controller = $this->load->controller('error');
diff --git a/src/web/core/_model.php b/src/web/core/_model.php
index 4c27b1b..57127de 100644
--- a/src/web/core/_model.php
+++ b/src/web/core/_model.php
@@ -2,19 +2,20 @@
abstract class Model {
// the main model
// shared by all controllers and models
- public $main;
- public $load;
+ public Main_model $main;
+ public Loader $load;
// the database
- public $db;
+ public DatabaseHelper $db;
- private $config;
+ private mixed $config;
/**
* Creates a model
* @param Loader $load - the main loader object
- */
- function __construct($load, $main = FALSE) {
+ * @param ?Main_model $main
+ */
+ function __construct(Loader $load, bool $main = FALSE) {
$this->load = $load;
if ($main) {
$this->main = $this;
diff --git a/src/web/core/loader.php b/src/web/core/loader.php
index b0a1cbd..101abef 100644
--- a/src/web/core/loader.php
+++ b/src/web/core/loader.php
@@ -2,13 +2,14 @@
class Loader {
// keep track of what has been loaded
- private $loaded;
+ private array $loaded;
// the database
- private $db;
+ private ?DatabaseHelper $db;
function __construct() {
$this->loaded = array();
+ $this->db = NULL;
}
/**
@@ -99,7 +100,7 @@ class Loader {
}
}
- public function db() {
+ public function db(): DatabaseHelper {
if ($this->db) {
return $this->db;
} else {
diff --git a/src/web/core/router.php b/src/web/core/router.php
index c8fb142..1ad6cb5 100644
--- a/src/web/core/router.php
+++ b/src/web/core/router.php
@@ -2,15 +2,15 @@
class Router {
// the loader
- private $load;
+ private Loader $load;
// the main model
- private $main;
+ private Main_model $main;
// the database
- private $db;
+ private DatabaseHelper $db;
- private $db_ready;
+ private bool $db_ready;
/**
* Creates a router
@@ -123,7 +123,7 @@ class Router {
* @param int $code - the http error code
* @param bool $recursed
*/
- private function handle_error($code, $recursed): void {
+ private function handle_error(int $code, bool $recursed): void {
if ($recursed) {
die($code . ' (recursed)');
}
@@ -137,7 +137,10 @@ class Router {
$this->handle_req($req, TRUE);
}
- private function load_htc($req, $recursed): void {
+ /**
+ * @param array<int,mixed> $req
+ */
+ private function load_htc(array $req, bool $recursed): void {
$parts = explode('/', $req['uri_str']);
$file = end($parts);
$path = $GLOBALS['publicroot'] . '/polyfills/' . $file;
@@ -152,9 +155,10 @@ class Router {
/**
* @param array $req
+ * @param array<int,mixed> $req
* @param bool $recursed
*/
- private function handle_req($req, $recursed = FALSE): void {
+ private function handle_req(array $req, bool $recursed = FALSE): void {
if ($recursed === false) {
if (
@@ -202,7 +206,10 @@ class Router {
$ref->invoke($controller);
}
- private function log_request($req): void {
+ /**
+ * @param array<int,mixed> $req
+ */
+ private function log_request(array $req): void {
if (
$req === FALSE ||
$this->db_ready === FALSE ||
@@ -220,7 +227,10 @@ class Router {
$query->execute();
}
- private function check_banned($req) {
+ /**
+ * @param array<int,mixed> $req
+ */
+ private function check_banned(array $req): bool {
$ip = FALSE;
if ($req) {
$ip = $req['ip'];
diff --git a/src/web/helpers/aria.php b/src/web/helpers/aria.php
index 8ebfcc5..9782299 100644
--- a/src/web/helpers/aria.php
+++ b/src/web/helpers/aria.php
@@ -1,6 +1,6 @@
<?php /* Copyright (c) 2024 Freya Murphy */
-function aria_section($id, $title = NULL): string {
+function aria_section(string $id, ?string $title = NULL): string {
$out = '';
if ($title) {
$idh = $id . '_heading';
diff --git a/src/web/helpers/database.php b/src/web/helpers/database.php
index 25cb5ba..132ed81 100644
--- a/src/web/helpers/database.php
+++ b/src/web/helpers/database.php
@@ -1,16 +1,24 @@
<?php /* Copyright (c) 2024 Freya Murphy */
+function __nullify(mixed $val): mixed {
+ if (!$val) {
+ return NULL;
+ } else {
+ return $val;
+ }
+}
+
class DatabaseQuery {
- private $conn;
- private $query;
+ private \PDO $conn;
+ private string $query;
- private $where;
- private $set;
+ private bool $where;
+ private bool $set;
- private $param;
+ private array $param;
- function __construct($conn) {
+ function __construct(\PDO $conn) {
$this->conn = $conn;
$this->query = '';
@@ -23,7 +31,7 @@ class DatabaseQuery {
/// ARBITRARY QUERY
///
- public function query($query) {
+ public function query(string $query): DatabaseQuery {
$this->query .= $query;
return $this;
}
@@ -32,12 +40,12 @@ class DatabaseQuery {
/// SELECT
///
- public function select($select) {
+ public function select(string $select): DatabaseQuery {
$this->query .= "SELECT $select\n";
return $this;
}
- public function from($from) {
+ public function from(string $from): DatabaseQuery {
$this->query .= "FROM $from\n";
return $this;
}
@@ -46,7 +54,7 @@ class DatabaseQuery {
/// INSERT
///
- public function insert_into($insert, ...$columns) {
+ public function insert_into(string $insert, string ...$columns): DatabaseQuery {
$this->query .= "INSERT INTO $insert\n (";
foreach ($columns as $idx => $column) {
if ($idx !== 0) {
@@ -58,7 +66,7 @@ class DatabaseQuery {
return $this;
}
- public function values(...$values) {
+ public function values(mixed ...$values): DatabaseQuery {
$this->query .= "VALUES (";
foreach ($values as $idx => $value) {
if ($idx !== 0) {
@@ -75,7 +83,7 @@ class DatabaseQuery {
/// WHERE
///
- public function where($cond) {
+ public function where(string $cond): DatabaseQuery {
if (!$this->where) {
$this->where = TRUE;
$this->query .= "WHERE ";
@@ -86,7 +94,10 @@ class DatabaseQuery {
return $this;
}
- public function where_in($column, $array) {
+ /**
+ * @param array<mixed> $array
+ */
+ public function where_in(string $column, array $array): DatabaseQuery {
if (!$this->where) {
$this->where = TRUE;
$this->query .= "WHERE ";
@@ -102,7 +113,10 @@ class DatabaseQuery {
return $this;
}
- private function in($array) {
+ /**
+ * @param array<mixed> $array
+ */
+ private function in(array $array): DatabaseQuery {
$in = 'IN (';
foreach ($array as $idx => $item) {
if ($idx != 0) {
@@ -119,31 +133,31 @@ class DatabaseQuery {
/// OPERATORS
///
- public function like($item) {
+ public function like(mixed $item): DatabaseQuery {
$this->query .= "LIKE ?\n";
array_push($this->param, $item);
return $this;
}
- public function eq($item) {
+ public function eq(mixed $item): DatabaseQuery {
$this->query .= "= ?\n";
array_push($this->param, $item);
return $this;
}
- public function ne($item) {
+ public function ne(mixed $item): DatabaseQuery {
$this->query .= "<> ?\n";
array_push($this->param, $item);
return $this;
}
- public function lt($item) {
+ public function lt(mixed $item): DatabaseQuery {
$this->query .= "< ?\n";
array_push($this->param, $item);
return $this;
}
- public function le($item) {
+ public function le(mixed $item): DatabaseQuery {
$this->query .= "<= ?\n";
array_push($this->param, $item);
return $this;
@@ -153,7 +167,7 @@ class DatabaseQuery {
/// JOINS
///
- public function join($table, $on, $type = 'LEFT') {
+ public function join(string $table, string $on, string $type = 'LEFT'): DatabaseQuery {
$this->query .= "$type JOIN $table ON $on\n";
return $this;
}
@@ -162,19 +176,19 @@ class DatabaseQuery {
/// LIMIT, OFFSET, ORDER
///
- public function limit($limit) {
+ public function limit(int $limit): DatabaseQuery {
$this->query .= "LIMIT ?\n";
array_push($this->param, $limit);
return $this;
}
- public function offset($offset) {
+ public function offset(int $offset): DatabaseQuery {
$this->query .= "OFFSET ?\n";
array_push($this->param, $offset);
return $this;
}
- public function order_by($column, $order = 'ASC') {
+ public function order_by(string $column, string $order = 'ASC'): DatabaseQuery {
$this->query .= "ORDER BY " . $column . ' ' . $order . ' ';
return $this;
}
@@ -183,7 +197,7 @@ class DatabaseQuery {
/// COLLECT
///
- public function rows(...$params) {
+ public function rows(mixed ...$params): ?array {
$args = $this->param;
foreach ($params as $param) {
array_push($args, $param);
@@ -196,20 +210,20 @@ class DatabaseQuery {
echo '<br> >> caused by <<<br>';
echo str_replace("\n", "<br>", $this->query);
}
- return $stmt->fetchAll(PDO::FETCH_ASSOC);
+ return __nullify($stmt->fetchAll(PDO::FETCH_ASSOC));
}
- public function row(...$params) {
+ public function row(mixed ...$params): ?array {
$args = $this->param;
foreach ($params as $param) {
array_push($args, $param);
}
$stmt = $this->conn->prepare($this->query);
$stmt->execute($args);
- return $stmt->fetch(PDO::FETCH_ASSOC);
+ return __nullify($stmt->fetch(PDO::FETCH_ASSOC));
}
- public function execute(...$params) {
+ public function execute(mixed ...$params): bool {
$args = $this->param;
foreach ($params as $param) {
array_push($args, $param);
@@ -234,13 +248,13 @@ class DatabaseQuery {
*/
class DatabaseHelper {
- private $conn;
+ private ?\PDO $conn;
function __construct() {
$this->conn = NULL;
}
- private function connect() {
+ private function connect(): \PDO {
if ($this->conn === NULL) {
$user = getenv("POSTGRES_USER");
$pass = getenv("POSTGRES_PASSWORD");
@@ -261,19 +275,19 @@ class DatabaseHelper {
return $this->conn;
}
- public function select($select) {
+ public function select(string $select): DatabaseQuery {
$conn = $this->connect();
$query = new DatabaseQuery($conn);
return $query->select($select);
}
- public function insert_into($insert, ...$columns) {
+ public function insert_into(string $insert, string ...$columns): DatabaseQuery {
$conn = $this->connect();
$query = new DatabaseQuery($conn);
return $query->insert_into($insert, ...$columns);
}
- public function query($query_str) {
+ public function query(string $query_str): DatabaseQuery {
$conn = $this->connect();
$query = new DatabaseQuery($conn);
return $query->query($query_str);
diff --git a/src/web/helpers/image.php b/src/web/helpers/image.php
index c18154a..fd395b5 100644
--- a/src/web/helpers/image.php
+++ b/src/web/helpers/image.php
@@ -30,7 +30,7 @@ function __make_source(
$media = '';
}
$main = $GLOBALS['main_model'];
- $path = $main->get_url('public/' . $name . '.' . $format);
+ $path = $main->get_url('public/' . $name . '.' . $format, TRUE);
$mime = __get_mime($format);
return sprintf('<source type="%s" srcset="%s" %s>',
$mime, $path, $media);
@@ -69,7 +69,7 @@ function image(
$format = end($formats);
$main = $GLOBALS['main_model'];
- $path = $main->get_url('public/' . $name . '.' . $format);
+ $path = $main->get_url('public/' . $name . '.' . $format, TRUE);
$out .= "<img src=\"$path\"";
if ($alt) {
$alt = lang($alt);
diff --git a/src/web/helpers/lang.php b/src/web/helpers/lang.php
index e8fa29e..b11cc7c 100644
--- a/src/web/helpers/lang.php
+++ b/src/web/helpers/lang.php
@@ -1,7 +1,13 @@
<?php /* Copyright (c) 2024 Freya Murphy */
$lang = array();
-function lang($key, $default = NULL, $sub = NULL) {
+/**
+ * @param ?array<string,mixed> $sub
+ */
+function lang(
+ string $key,
+ ?string $default = NULL,
+ ?array $sub = NULL) {
$lang = $GLOBALS['lang'];
if(array_key_exists($key, $lang)) {
if ($sub) {
@@ -17,15 +23,20 @@ function lang($key, $default = NULL, $sub = NULL) {
}
}
-function ilang($key,
- $class = NULL,
- $id = NULL,
- $href = NULL,
- $click = NULL,
- $attrs = array(),
- $sub = NULL,
- $button = FALSE,
- $container = 'span'
+/**
+ * @param array<string,string> $attrs
+ * @param ?array<string,mixed> $sub
+ */
+function ilang(
+ string $key,
+ string $class = NULL,
+ string $id = NULL,
+ string $href = NULL,
+ string $click = NULL,
+ array $attrs = array(),
+ ?array $sub = NULL,
+ bool $button = FALSE,
+ string $container = 'span'
) {
$text = ucfirst(lang($key . "_text", FALSE, sub: $sub));
$tip = lang($key . "_tip", FALSE, sub: $sub);
diff --git a/src/web/helpers/markdown.php b/src/web/helpers/markdown.php
index 39b430c..5279a1f 100644
--- a/src/web/helpers/markdown.php
+++ b/src/web/helpers/markdown.php
@@ -8,7 +8,10 @@ class MarkdownParser {
$this->parsedown = new ParsedownExtra();
}
- function parse($path) {
+ /**
+ * @return array<string,mixed>
+ */
+ function parse(string $path): array {
$content = file_get_contents($path);
$data = array(
'meta' => array(),
diff --git a/src/web/helpers/sanitize.php b/src/web/helpers/sanitize.php
index 5d37852..495c249 100644
--- a/src/web/helpers/sanitize.php
+++ b/src/web/helpers/sanitize.php
@@ -1,6 +1,6 @@
<?php /* Copyright (c) 2024 Freya Murphy */
-function esc($data) {
+function esc(string $data): string {
$data = str_replace('&', '&amp;', $data);
$data = str_replace('<', '&lt;', $data);
$data = str_replace('>', '&gt;', $data);