From e4768cd0647d934eff424f73bfd9f5c8f6223c94 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 12 Nov 2018 13:55:40 +0100 Subject: link+log --- app/class/config.php | 15 +++++++++++- app/class/controller.php | 29 ----------------------- app/class/controllerconnect.php | 52 +++++++++++++++++++++++++++++++++++++++-- app/class/modelrender.php | 31 ++++++++++++++++++++---- app/class/routes.php | 2 ++ app/view/templates/connect.php | 8 +++---- app/view/templates/navart.php | 10 ++++---- 7 files changed, 102 insertions(+), 45 deletions(-) (limited to 'app') 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 '' . $matches[1] . ''; + return '' . $matches[1] . ''; } else { - return '' . $matchart->title() . ''; + return '' . $matchart->title() . ''; } }, $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 @@ isvisitor()) { ?> -
+ - +
-
- + +
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 { isvisitor()) { ?>
  • -
    + - + +
  • -
    - + + +
  • -- cgit v1.2.3