# HG changeset patch # User m15o # Date 1684862084 -7200 # Tue May 23 19:14:44 2023 +0200 # Node ID b12f3da3f7763f5274ac61608036bed23f08e5bc # Parent 6fd928ef2e8034bb6f8a4e7039dbce85c7f118e8 add helper functions diff --git a/classes/Validate.php b/classes/Validate.php --- a/classes/Validate.php +++ b/classes/Validate.php @@ -21,24 +21,9 @@ return filter_var($str, FILTER_VALIDATE_EMAIL); } - public static function isAvailableFilename($id, $filename) { - clearstatcache(); - return !file_exists(file_path($id, $filename)); - } - - public static function isFilename($str) + public static function isPage($str) { - // check extension - if (!in_array(strtolower(pathinfo($str, PATHINFO_EXTENSION)), ['jpeg', 'jpg', 'png', 'gif'])) { - return false; - } - - // check basename - if (!preg_match('/^[A-z0-9_()-]+$/', pathinfo($str, PATHINFO_FILENAME))) { - return false; - } - - return true; + return preg_match('/^[a-z0-9_-]+$/', $str); } public static function isAcceptableHTML($str) { diff --git a/home_update.php b/home_update.php --- a/home_update.php +++ b/home_update.php @@ -16,7 +16,7 @@
-

Editing home

+

Editing home

diff --git a/includes/app.php b/includes/app.php --- a/includes/app.php +++ b/includes/app.php @@ -140,6 +140,15 @@ } } +function get_url($username, $page = null) +{ + if (isset($page)) { + return "site.php?u=$username&p=$page"; + } else { + return "site.php?u=$username"; + } +} + function home_link($user_id, $name) { return "$name"; @@ -214,7 +223,7 @@ return $res; } -define('LINK_REGEXP', '/\[\[([\w\d-]+)\]\]/'); +define('LINK_REGEXP', '/\[\[([a-z0-9_-]+)\]\]/'); function content_to_html($content, $user_id) { return preg_replace_callback(LINK_REGEXP, function ($match) use ($user_id) { diff --git a/includes/home.php b/includes/home.php --- a/includes/home.php +++ b/includes/home.php @@ -7,12 +7,11 @@

's site

Welcome to your site! Use the edit button to edit this page.

-
- + \ No newline at end of file diff --git a/includes/page.php b/includes/page.php --- a/includes/page.php +++ b/includes/page.php @@ -6,35 +6,33 @@

Not found

-

Create page for ?

+

Create page for ?

- - - - - + - - - + + + + diff --git a/includes/site_header.php b/includes/site_header.php --- a/includes/site_header.php +++ b/includes/site_header.php @@ -14,7 +14,7 @@
diff --git a/page_create.php b/page_create.php --- a/page_create.php +++ b/page_create.php @@ -15,6 +15,7 @@ $name = trim($form['name']); // todo: more validation + Validate::isPage($name) or $errors[] = "Slug can only contain a-z0-9_-"; if (!count($errors)) { $id = $GLOBALS['app']->getPage()->create($GLOBALS['user']['id'], $name, ''); diff --git a/site.php b/site.php --- a/site.php +++ b/site.php @@ -9,7 +9,9 @@ if ($p) { $page = $app->getPage()->get($site_user['id'], $p); $related = $app->getPage()->related($site_user['id'], $p); - $content = content_to_html2($page['content'], $site_user); + if ($page) { + $content = content_to_html2($page['content'], $site_user); + } include 'includes/page.php'; } else { $content = content_to_html2($site_user['home'], $site_user); diff --git a/style.css b/style.css --- a/style.css +++ b/style.css @@ -1,11 +1,12 @@ body { font-family: sans-serif; margin: 40px auto; - padding: 0px 10px; + padding: 1em; max-width: 650px; line-height: 1.6; font-size: 18px; background-color: floralwhite; + border: 1px solid; } textarea { @@ -31,27 +32,20 @@ footer { border-top: 1px solid; + margin-top: 1em; padding-top: 1em; } -header { - background-color: plum; - padding: 10px; -} - .page-admin { padding: 10px; background-color: powderblue; - margin-top: 2em; -} - -main { - margin-bottom: 2em; + margin-top: 1em; } .related { border: 1px dashed midnightblue; padding: 1em; + margin-top: 1em; } .link::before {