From 89b05effb2eb45382762fcfcfae2373b7754caa7 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 12 Nov 2018 11:11:58 +0100 Subject: url-cleaning-redirect-correct-id --- .gitignore | 1 + app/class/config.php | 12 +++++++++++ app/class/controller.php | 7 +----- app/class/controllerart.php | 27 +++++++++++++---------- app/class/model.php | 10 +++++++++ app/class/modelfont.php | 31 ++++++++++++++++++++++++++ app/class/routes.php | 24 +++++++++++++-------- app/fn/fn.php | 10 +++++++++ app/view/templates/edit.php | 2 +- app/view/templates/editleftbar.php | 2 +- app/view/templates/editrightbar.php | 12 ++++++++++- assets/css/edit.css | 43 +++++++++++++++++++++++++++++-------- assets/css/home.css | 7 +++++- 13 files changed, 149 insertions(+), 39 deletions(-) create mode 100644 app/class/modelfont.php diff --git a/.gitignore b/.gitignore index ed2c57b..fd4c020 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .vscode/* assets/render/* database/* +fonts/* media/* vendor/* config.json diff --git a/app/class/config.php b/app/class/config.php index 83982de..39c741a 100644 --- a/app/class/config.php +++ b/app/class/config.php @@ -13,6 +13,8 @@ abstract class Config protected static $color4; protected static $fontsize = 15; protected static $basepath = ''; + protected static $route404 = ''; + // _______________________________________ F U N _______________________________________ @@ -114,6 +116,11 @@ abstract class Config return self::$basepath; } + public static function route404() + { + return self::$route404; + } + // __________________________________________ S E T ______________________________________ @@ -170,6 +177,11 @@ abstract class Config self::$basepath = strip_tags($basepath); } + public static function setroute404(string $id) + { + self::$route404 = idclean($id); + } + diff --git a/app/class/controller.php b/app/class/controller.php index db13d5a..1c3fee5 100644 --- a/app/class/controller.php +++ b/app/class/controller.php @@ -11,8 +11,7 @@ class Controller public function __construct($router) { $this->setuser(); $this->router = $router; - $this->initplates(); - $this->initconfig(); + $this->initplates(); } public function setuser() @@ -44,10 +43,6 @@ class Controller } } - public function initconfig() - { - Config::readconfig(); - } public function showtemplate($template, $params) { diff --git a/app/class/controllerart.php b/app/class/controllerart.php index 0010f33..bec4b1d 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -16,9 +16,13 @@ class Controllerart extends Controller } - public function setart($id) + public function setart(string $id, string $route) { - $this->art = new Art2(['id' => $id]); + $cleanid = idclean($id); + if($cleanid !== $id) { + $this->routedirect($route, ['art' => $cleanid]); + } + $this->art = new Art2(['id' => $cleanid]); } public function importart() @@ -35,7 +39,7 @@ class Controllerart extends Controller public function read($id) { - $this->setart($id); + $this->setart($id, 'artread/'); $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); @@ -78,7 +82,7 @@ class Controllerart extends Controller public function edit($id) { - $this->setart($id); + $this->setart($id, 'artedit'); if ($this->importart() && $this->user->canedit()) { @@ -93,9 +97,10 @@ class Controllerart extends Controller $showleftpanel = false; $showrightpanel = false; } + $fontmanager = new Modelfont; + $fonts = $fontmanager->list(); - - $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel]); + $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts]); } else { $this->routedirect('artread/', ['art' => $this->art->id()]); } @@ -104,14 +109,14 @@ class Controllerart extends Controller public function log($id) { - $this->setart($id); + $this->setart($id, 'artlog'); $this->importart(); var_dump($this->art); } public function add($id) { - $this->setart($id); + $this->setart($id, 'artadd'); if ($this->user->canedit() && !$this->importart()) { $this->art->reset(); $this->artmanager->add($this->art); @@ -123,7 +128,7 @@ class Controllerart extends Controller public function confirmdelete($id) { - $this->setart($id); + $this->setart($id, 'artconfirmdelete'); if ($this->user->canedit() && $this->importart()) { $this->showtemplate('confirmdelete', ['art' => $this->art, 'artexist' => true]); @@ -135,7 +140,7 @@ class Controllerart extends Controller public function delete($id) { - $this->setart($id); + $this->setart($id, 'artdelete'); if ($this->user->canedit() && $this->importart()) { $this->artmanager->delete($this->art); @@ -145,7 +150,7 @@ class Controllerart extends Controller public function update($id) { - $this->setart($id); + $this->setart($id, 'artupdate'); $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']); $_SESSION['workspace']['showleftpanel'] = isset($_POST['workspace']['showleftpanel']); diff --git a/app/class/model.php b/app/class/model.php index d7f34da..6d8aec3 100644 --- a/app/class/model.php +++ b/app/class/model.php @@ -4,6 +4,7 @@ class Model const CONFIG_FILE = 'config.json'; const CSS_DIR = 'assets' . DIRECTORY_SEPARATOR .'css' . DIRECTORY_SEPARATOR; + const FONT_DIR = 'fonts' . DIRECTORY_SEPARATOR; const MEDIA_DIR = '.' . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR; const TEMPLATES_DIR = '.'. DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; const RENDER_DIR = 'assets'. DIRECTORY_SEPARATOR . 'render' . DIRECTORY_SEPARATOR; @@ -31,6 +32,15 @@ class Model return DIRECTORY_SEPARATOR . $basepath . Model::CSS_DIR; } + public function fontpath() + { + $basepath = ''; + if(!empty(Config::basepath())) { + $basepath = Config::basepath() . DIRECTORY_SEPARATOR ; + } + return $basepath . Model::FONT_DIR; + } + } diff --git a/app/class/modelfont.php b/app/class/modelfont.php new file mode 100644 index 0000000..135a3df --- /dev/null +++ b/app/class/modelfont.php @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/app/class/routes.php b/app/class/routes.php index 89f82e6..71b75d6 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -12,16 +12,17 @@ class Routes if(!empty(Config::basepath())) { $router->setBasePath(DIRECTORY_SEPARATOR . Config::basepath()); } + $router->addMatchTypes(array('cid' => '[a-zA-Z0-9-_+,\'!%@&.$€=\(\|\)]+')); $router->addRoutes([ ['GET|POST', '/', 'Backrouter#run', 'backrouter'], - ['GET', '/[a:art]/', 'Controllerart#read', 'artread/'], - ['GET', '/[a:art]', 'Controllerart#read', 'artread'], - ['GET', '/[a:art]/add', 'Controllerart#add', 'artadd'], - ['GET', '/[a:art]/edit', 'Controllerart#edit', 'artedit'], - ['GET', '/[a:art]/log', 'Controllerart#log', 'artlog'], - ['POST', '/[a:art]/edit', 'Controllerart#update', 'artupdate'], - ['GET', '/[a:art]/delete', 'Controllerart#confirmdelete', 'artconfirmdelete'], - ['POST', '/[a:art]/delete', 'Controllerart#delete', 'artdelete'], + ['GET', '/[cid:art]/', 'Controllerart#read', 'artread/'], + ['GET', '/[cid:art]', 'Controllerart#read', 'artread'], + ['GET', '/[cid:art]/add', 'Controllerart#add', 'artadd'], + ['GET', '/[cid:art]/edit', 'Controllerart#edit', 'artedit'], + ['GET', '/[cid:art]/log', 'Controllerart#log', 'artlog'], + ['POST', '/[cid:art]/edit', 'Controllerart#update', 'artupdate'], + ['GET', '/[cid:art]/delete', 'Controllerart#confirmdelete', 'artconfirmdelete'], + ['POST', '/[cid:art]/delete', 'Controllerart#delete', 'artdelete'], ]); $match = $router->match(); @@ -36,7 +37,12 @@ class Routes } //404 else { - header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); + if(!empty(Config::route404())) { + $controller = new Controller($router); + $controller->routedirect('artread/', ['art' => Config::route404()]); + } else { + header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); + } } } } \ No newline at end of file diff --git a/app/fn/fn.php b/app/fn/fn.php index 029e9d3..03bb2d0 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -70,6 +70,16 @@ function arrayclean($input) return $output; } +function idclean(string $input) +{ + $input = urldecode($input); + $search = ['é', 'à', 'è', 'ç', ' ']; + $replace = ['e', 'a', 'e', 'c', '-']; + $input = str_replace($search, $replace, $input); + + return preg_replace('%[^a-z0-9-_+]%', '', strtolower(trim($input))); +} + diff --git a/app/view/templates/edit.php b/app/view/templates/edit.php index 7379378..a729302 100644 --- a/app/view/templates/edit.php +++ b/app/view/templates/edit.php @@ -20,7 +20,7 @@ insert('editleftbar', ['art' => $art, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel]) ?> insert('edittabs', ['tablist' => $tablist, 'opentab' => $art->interface()]) ?> - insert('editrightbar', ['art' => $art, 'artlist' => $artlist, 'showrightpanel' => $showrightpanel]) ?> + insert('editrightbar', ['art' => $art, 'artlist' => $artlist, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts]) ?> diff --git a/app/view/templates/editleftbar.php b/app/view/templates/editleftbar.php index 7533599..247e271 100644 --- a/app/view/templates/editleftbar.php +++ b/app/view/templates/editleftbar.php @@ -1,4 +1,4 @@ -
+
>
diff --git a/app/view/templates/editrightbar.php b/app/view/templates/editrightbar.php index a6cc2a0..74ba1dd 100644 --- a/app/view/templates/editrightbar.php +++ b/app/view/templates/editrightbar.php @@ -1,4 +1,4 @@ -
+
>
@@ -14,6 +14,16 @@ ?> +
+ Fonts + +
diff --git a/assets/css/edit.css b/assets/css/edit.css index e5f6cda..e166418 100644 --- a/assets/css/edit.css +++ b/assets/css/edit.css @@ -9,7 +9,8 @@ div#main { body { margin: 0; height: 100%; - background-color: #b1b1b1; + font-family: monospace; + font-size: 15px; } .menu { @@ -26,6 +27,7 @@ body { flex: 2; position: relative; height: 100%; + background-color: lightgrey; } @@ -119,13 +121,13 @@ body { .tab label { margin-right: 10px; - border: outset; - background-color: var(--color1); + border: solid rgba(0, 0, 0, 0); + padding: 0px 2px; } .checkboxtab:checked ~ label { - border: inset; + border: solid 1px; } .checkboxtab:checked ~ .content @@ -146,7 +148,7 @@ html { height: 100%; } -.tabs textarea {height: 100%;width: 100%;border: none;resize: none;} +.tabs textarea {height: 100%;width: 100%;border: none;resize: none;padding: 1%;} * { box-sizing: border-box; @@ -157,6 +159,8 @@ html { } .editor #topbar { + height: 30px; + background-color: #7b97b9; line-height: 30px; } @@ -165,7 +169,7 @@ html { padding: 0; } -.editor #leftbar select { +.editor .bar select { width: 100%; } @@ -174,8 +178,29 @@ html { } -.editor a {color: black;text-decoration: none;} -.editor a:hover { - color: white; + +details { + background-color: darkgrey; +} + +.bar { + background-color: lightgrey; +} + +input#fontsize { + width: 36px; } + +span#headid { + border: solid 1px; + padding: 2px 4px; +} + +a { + color: black; +} + +#fonts select { + height: 150px; +} \ No newline at end of file diff --git a/assets/css/home.css b/assets/css/home.css index 582042a..2fc3773 100644 --- a/assets/css/home.css +++ b/assets/css/home.css @@ -9,10 +9,15 @@ div#main { body { margin: 0; height: 100%; - background-color: #b1b1b1; + background-color: lightgrey; + font-family: monospace; + font-size: 15px; } .menu { position: fixed; right: 0; } + + + -- cgit v1.2.3