# HG changeset patch # User m15o # Date 1684866504 -7200 # Tue May 23 20:28:24 2023 +0200 # Node ID 8dbba43951f4ec7084fb2136e2e474f8bdba8181 # Parent 234b61788adc139a7b6f052ecb60e68583a499ae finish refactor diff --git a/classes/Page.php b/classes/Page.php --- a/classes/Page.php +++ b/classes/Page.php @@ -9,14 +9,15 @@ $this->db = $db; } - public function getAll($id) + public function getAll($name) { $sql = "SELECT - slug, content + slug, content, name FROM pages - WHERE user_id=? + LEFT JOIN users on pages.user_id = users.id + WHERE name=? ORDER BY slug"; - return $this->db->runSQL($sql, [$id])->fetchAll(); + return $this->db->runSQL($sql, [$name])->fetchAll(); } public function getActivity() diff --git a/includes/app.php b/includes/app.php --- a/includes/app.php +++ b/includes/app.php @@ -67,22 +67,9 @@ echo ''; } -function get_id() -{ - if (!($id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT))) { - page_not_found(); - } - - return $id; -} - function get_param($param) { - if (!($rv = filter_input(INPUT_GET, $param, FILTER_SANITIZE_SPECIAL_CHARS))) { - page_not_found(); - } - - return $rv; + return filter_input(INPUT_GET, $param, FILTER_SANITIZE_SPECIAL_CHARS); } function timeAgo($dateString) diff --git a/includes/site_header.php b/includes/site_header.php --- a/includes/site_header.php +++ b/includes/site_header.php @@ -15,7 +15,7 @@
diff --git a/pages_index.php b/pages.php rename from pages_index.php rename to pages.php --- a/pages_index.php +++ b/pages.php @@ -1,9 +1,9 @@ getPage()->getAll($id); -$site_user = $App->getUser()->get($id) or page_not_found(); +$u = get_param("u"); +$pages = $App->getPage()->getAll($u); +$site_user = $App->getUser()->getFromUsername($u) or page_not_found(); ?> diff --git a/site.php b/site.php --- a/site.php +++ b/site.php @@ -2,7 +2,7 @@ require 'includes/app.php'; $u = get_param("u"); -$p = filter_input(INPUT_GET, 'p', FILTER_SANITIZE_SPECIAL_CHARS); +$p = get_param("p"); $site_user = $App->getUser()->getFromUsername($u) or page_not_found(); $is_admin = is_site_admin($site_user);