aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2018-11-12 11:11:58 +0100
committervincent-peugnet <v.peugnet@free.fr>2018-11-12 11:11:58 +0100
commit89b05effb2eb45382762fcfcfae2373b7754caa7 (patch)
treede7a5298f1ef7a095c4b99e684c80b9152c686b1 /app
parenta64af357ff41a61f5248e2052274315b390e979c (diff)
downloadwcms-89b05effb2eb45382762fcfcfae2373b7754caa7.tar.gz
wcms-89b05effb2eb45382762fcfcfae2373b7754caa7.zip
url-cleaning-redirect-correct-id
Diffstat (limited to 'app')
-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
-rw-r--r--app/fn/fn.php10
-rw-r--r--app/view/templates/edit.php2
-rw-r--r--app/view/templates/editleftbar.php2
-rw-r--r--app/view/templates/editrightbar.php12
10 files changed, 108 insertions, 29 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
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 @@
<?php $this->insert('editleftbar', ['art' => $art, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel]) ?>
<?php $this->insert('edittabs', ['tablist' => $tablist, 'opentab' => $art->interface()]) ?>
- <?php $this->insert('editrightbar', ['art' => $art, 'artlist' => $artlist, 'showrightpanel' => $showrightpanel]) ?>
+ <?php $this->insert('editrightbar', ['art' => $art, 'artlist' => $artlist, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts]) ?>
</div>
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 @@
-<div id="leftbar">
+<div id="leftbar" class="bar">
<input id="showleftpanel" name="workspace[showleftpanel]" value="1" class="toggle" type="checkbox" <?= $showleftpanel == true ? 'checked' : '' ?>>
<label for="showleftpanel" class="toogle">◧</label>
<div id="leftbarpanel" class="panel">
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 @@
-<div id="rightbar">
+<div id="rightbar" class="bar">
<input id="showrightpanel" name="workspace[showrightpanel]" value="1" class="toggle" type="checkbox" <?= $showrightpanel == true ? 'checked' : '' ?>>
<label for="showrightpanel" class="toogle">◧</label>
<div id="rightbarpanel" class="panel">
@@ -14,6 +14,16 @@
?>
</details>
+ <details id="fonts" open>
+ <summary>Fonts</summary>
+ <select multiple>
+ <?php
+ foreach ($fonts as $font ) {
+ echo '<option value="'.$font.'">'.$font.'</option>';
+ }
+ ?>
+ </select>
+ </details>
</div>