aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
Diffstat (limited to 'app/class')
-rw-r--r--app/class/config.php12
-rw-r--r--app/class/controller.php7
-rw-r--r--app/class/controllerart.php27
-rw-r--r--app/class/model.php10
-rw-r--r--app/class/modelfont.php31
-rw-r--r--app/class/routes.php24
6 files changed, 85 insertions, 26 deletions
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 @@
+<?php
+
+class Modelfont extends Model
+{
+ public function list()
+ {
+ if ($handle = opendir(Model::fontpath())) {
+ $list = [];
+ while (false !== ($entry = readdir($handle))) {
+ if ($entry != "." && $entry != "..") {
+
+ $list[] = $entry;
+
+ }
+ }
+ }
+
+ return $list;
+
+ }
+}
+
+
+
+
+
+
+
+
+
+?> \ 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