diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-11-12 13:55:40 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-11-12 13:55:40 +0100 |
commit | e4768cd0647d934eff424f73bfd9f5c8f6223c94 (patch) | |
tree | b36029a8152d79108e0dd57aacd73f80b7232b33 /app | |
parent | 0f44c6d918a2932b68019c02de5bc55e7057600a (diff) | |
download | wcms-e4768cd0647d934eff424f73bfd9f5c8f6223c94.tar.gz wcms-e4768cd0647d934eff424f73bfd9f5c8f6223c94.zip |
link+log
Diffstat (limited to 'app')
-rw-r--r-- | app/class/config.php | 15 | ||||
-rw-r--r-- | app/class/controller.php | 29 | ||||
-rw-r--r-- | app/class/controllerconnect.php | 52 | ||||
-rw-r--r-- | app/class/modelrender.php | 31 | ||||
-rw-r--r-- | app/class/routes.php | 2 | ||||
-rw-r--r-- | app/view/templates/connect.php | 8 | ||||
-rw-r--r-- | app/view/templates/navart.php | 10 |
7 files changed, 102 insertions, 45 deletions
diff --git a/app/class/config.php b/app/class/config.php index bfc0c9e..3b05c1a 100644 --- a/app/class/config.php +++ b/app/class/config.php @@ -13,7 +13,8 @@ abstract class Config protected static $color4; protected static $fontsize = 15; protected static $basepath = ''; - protected static $route404 = ''; + protected static $route404; + protected static $existnot = 'This page does not exist yet'; @@ -121,6 +122,11 @@ abstract class Config return self::$route404; } + public static function existnot() + { + return self::$existnot; + } + // __________________________________________ S E T ______________________________________ @@ -184,6 +190,13 @@ abstract class Config } } + public static function setexistnot($description) + { + if(is_string($description)) { + self::$existnot = strip_tags($description); + } + } + diff --git a/app/class/controller.php b/app/class/controller.php index f7a3bd6..c722b1a 100644 --- a/app/class/controller.php +++ b/app/class/controller.php @@ -59,30 +59,6 @@ class Controller return $commonsparams; } - public function login($redirect = 'home') - { - if(isset($_POST['pass'])) { - $this->user = $this->usermanager->login($_POST['pass']); - $this->usermanager->writesession($this->user); - } - if($redirect == 'art') { - $this->redirect('?id=' . $this->art->id()); - } else { - $this->redirect('?aff=' . $redirect); - } - } - - public function logout($redirect = 'home') - { - $this->user = $this->usermanager->logout(); - $this->usermanager->writesession($this->user); - if($redirect == 'art') { - $this->redirect('?id=' . $this->art->id()); - } else { - $this->redirect('?aff=' . $redirect); - } - } - @@ -96,11 +72,6 @@ class Controller $this->redirect($this->router->generate($route, $vars)); } - public function uart($id) - { - return $this->router->generate('artread/', ['art' => $id]); - } - } diff --git a/app/class/controllerconnect.php b/app/class/controllerconnect.php index 2bda1b0..da3c96f 100644 --- a/app/class/controllerconnect.php +++ b/app/class/controllerconnect.php @@ -3,11 +3,59 @@ class Controllerconnect extends Controller { - public function desktop() + public function log() { - $this->showtemplate('connect', ['user' => $this->user]); + if (isset($_POST['log'])) { + if (isset($_POST['id'])) { + $id = $_POST['id']; + } else { + $id = null; + } + if ($_POST['log'] === 'login') { + $this->login($id); + } elseif ($_POST['log'] === 'logout') { + $this->logout($id); + } + } + + } + + + public function connect() + { + $this->showtemplate('connect', []); } + + + + + public function login($id) + { + if (isset($_POST['pass'])) { + $this->user = $this->usermanager->login($_POST['pass']); + $this->usermanager->writesession($this->user); + } + if (!empty($id)) { + $this->routedirect('artedit', ['art' => $id]); + } else { + $this->routedirect('backrouter'); + } + } + + public function logout($id) + { + $this->user = $this->usermanager->logout(); + $this->usermanager->writesession($this->user); + if (!empty($id)) { + $this->routedirect('artread/', ['art' => $id]); + } else { + $this->routedirect('backrouter'); + } + } + + + } diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 0951537..2d56f6b 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -43,7 +43,11 @@ class Modelrender extends Modelart if (isset($art->template('array')[$element])) { $templateid = $art->template('array')[$element]; $tempalteart = $this->get($templateid); - $text = $tempalteart->$element() . PHP_EOL . $art->$element(); + if($tempalteart) { + $text = $tempalteart->$element() . PHP_EOL . $art->$element(); + } else { + $text = $art->$element(); + } } else { $text = $art->$element(); } @@ -151,6 +155,7 @@ class Modelrender extends Modelart $text = str_replace(self::SUMMARY, $this->sumparser($text), $text); + $text = $this->wurl($text); $text = $this->wikiurl($text); $text = $this->tooltip($art->linkfrom('array'), $text); @@ -170,18 +175,35 @@ class Modelrender extends Modelart return $text; } + public function wurl(string $text) + { + $rend = $this; + $text = preg_replace_callback( + '%href="([\w-]+)"%', + function ($matches) use ($rend) { + $matchart = $rend->get($matches[1]); + if (!$matchart) { + return 'href="' . $rend->uart($matches[1]) . '"" title="' . Config::existnot() . '" class="internal"'; + } else { + return 'href="' . $rend->uart($matches[1]) . '" title="' . $matchart->description() . '" class="internal"'; + } + }, + $text + ); + return $text; + } + public function wikiurl(string $text) { $rend = $this; - $artlist = []; $text = preg_replace_callback( '%\[([\w-]+)\]%', function ($matches) use ($rend) { $matchart = $rend->get($matches[1]); if (!$matchart) { - return '<a href="' . $rend->uart($matches[1]) . '">' . $matches[1] . '</a>'; + return '<a href="' . $rend->uart($matches[1]) . '"" title="' . Config::existnot() . '" class="internal">' . $matches[1] . '</a>'; } else { - return '<a href="' . $rend->uart($matches[1]) . '" title="' . $matchart->description() . '">' . $matchart->title() . '</a>'; + return '<a href="' . $rend->uart($matches[1]) . '" title="' . $matchart->description() . '" class="internal">' . $matchart->title() . '</a>'; } }, $text @@ -189,7 +211,6 @@ class Modelrender extends Modelart return $text; } - public function markdown($text) { //use Michelf\MarkdownExtra; diff --git a/app/class/routes.php b/app/class/routes.php index 71b75d6..f240f6b 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -15,6 +15,8 @@ class Routes $router->addMatchTypes(array('cid' => '[a-zA-Z0-9-_+,\'!%@&.$€=\(\|\)]+')); $router->addRoutes([ ['GET|POST', '/', 'Backrouter#run', 'backrouter'], + ['POST', '/!co', 'Controllerconnect#log', 'log'], + ['GET', '/!co', 'Controllerconnect#connect', 'connect'], ['GET', '/[cid:art]/', 'Controllerart#read', 'artread/'], ['GET', '/[cid:art]', 'Controllerart#read', 'artread'], ['GET', '/[cid:art]/add', 'Controllerart#add', 'artadd'], diff --git a/app/view/templates/connect.php b/app/view/templates/connect.php index a4d58e7..06fe9c8 100644 --- a/app/view/templates/connect.php +++ b/app/view/templates/connect.php @@ -11,16 +11,16 @@ <?php if($user->isvisitor()) { ?> -<form action="./?action=login" method="post"> +<form action="<?= $this->url('log') ?>" method="post"> <input type="password" name="pass" id="loginpass" placeholder="password"> -<input type="submit" value="login"> +<input name="log" type="submit" value="login"> </form> <?php } else { ?> -<form action="./?action=logout" method="post"> -<input type="submit" value="logout"> +<form action="<?= $this->url('log') ?>" method="post"> +<input name="log" type="submit" value="logout"> </form> diff --git a/app/view/templates/navart.php b/app/view/templates/navart.php index f747eca..9ce932d 100644 --- a/app/view/templates/navart.php +++ b/app/view/templates/navart.php @@ -33,17 +33,19 @@ div#dropmenu { <?php if($user->isvisitor()) { ?> <li> - <form action="./?action=login<?= $art->id() !== null ? '&id=' . $art->id() : '' ?>" method="post"> + <form action="<?= $this->url('log') ?>" method="post"> <input type="password" name="pass" id="loginpass" placeholder="password"> - <input type="submit" value="login"> + <input type="hidden" name="id" value="<?= $art->id() ?>"> + <input type="submit" name="log" value="login"> </form> </li> <?php } else { ?> <li> - <form action="./?action=logout<?= $art->id() !== null ? '&id=' . $art->id() : '' ?>" method="post"> - <input type="submit" value="logout"> + <form action="<?= $this->url('log') ?>" method="post"> + <input type="hidden" name="id" value="<?= $art->id() ?>"> + <input type="submit" name="log" value="logout"> </form> </li> |