From d46c05b12b9dcd65d2d9cd230bf45b5bdf6fa8bd Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Thu, 22 Nov 2018 00:09:55 +0100 Subject: linkfrom analyse --- app/class/controller.php | 13 +------------ app/class/controllerart.php | 34 +++++++++++++++++++++++++--------- app/class/controllermedia.php | 7 +------ app/class/model.php | 11 ++++++++++- app/class/modelrender.php | 23 ++++++++++++++++++++--- app/class/modeluser.php | 12 +++++++++++- app/class/routes.php | 1 + app/class/user.php | 8 ++++---- app/view/templates/home.php | 2 +- app/view/templates/hometopbar.php | 2 +- app/view/templates/media.php | 5 +---- app/view/templates/navart.php | 4 ++-- app/view/templates/navback.php | 2 +- app/view/templates/read.php | 2 +- 14 files changed, 80 insertions(+), 46 deletions(-) diff --git a/app/class/controller.php b/app/class/controller.php index c722b1a..b0681bb 100644 --- a/app/class/controller.php +++ b/app/class/controller.php @@ -31,18 +31,6 @@ class Controller return $router->generate($string, ['art' => $id]); }); } - - public function useriseditor() - { - if ($this->user->level() >= $this->usermanager::EDITOR) { - echo '

Editor access

'; - return true; - } else { - echo '

Not enought rights to see more...

'; - return false; - } - } - public function showtemplate($template, $params) { @@ -62,6 +50,7 @@ class Controller + public function redirect($url) { header('Location: ' . $url); diff --git a/app/class/controllerart.php b/app/class/controllerart.php index ab3fec6..7a0ec93 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -39,6 +39,23 @@ class Controllerart extends Controller } } + + public function canedit() + { + if($this->user->iseditor()) { + return true; + } elseif($this->user->isinvite()) { + if($this->user->password() === $this->art->invitepassword()) { + return true; + } else { + return false; + } + } else { + return false; + } + } + + public function read($id) { $this->setart($id, 'artread/'); @@ -47,7 +64,6 @@ class Controllerart extends Controller $artexist = $this->importart(); $canread = $this->user->level() >= $this->art->secure(); - $cancreate = $this->user->cancreate(); $alerts = ['alertnotexist' => 'This page does not exist yet', 'alertprivate' => 'You cannot see this page']; $body = ''; $head = ''; @@ -60,7 +76,7 @@ class Controllerart extends Controller $body = $this->renderengine->renderbody($this->art); $this->art->setrender($body); $this->art->setdaterender($now); - $this->artmanager->update($this->art); + $this->art->setlinkfrom($this->renderengine->linkfrom()); } else { $body = $this->art->render(); } @@ -73,7 +89,7 @@ class Controllerart extends Controller } - $data = array_merge($alerts, ['art' => $this->art, 'artexist' => $artexist, 'canread' => $canread, 'cancreate' => $cancreate, 'readernav' => true, 'body' => $body, 'head' => $head]); + $data = array_merge($alerts, ['art' => $this->art, 'artexist' => $artexist, 'canread' => $canread, 'readernav' => true, 'body' => $body, 'head' => $head]); $this->showtemplate('read', $data); @@ -87,7 +103,7 @@ class Controllerart extends Controller $this->setart($id, 'artedit'); - if ($this->importart() && $this->user->canedit()) { + if ($this->importart() && $this->canedit()) { $tablist = ['section' => $this->art->md(), 'css' => $this->art->css(), 'header' => $this->art->header(), 'nav' => $this->art->nav(), 'aside' => $this->art->aside(), 'footer' => $this->art->footer(), 'html' => $this->art->html(), 'javascript' => $this->art->javascript()]; $artlist = $this->artmanager->list(); @@ -118,7 +134,7 @@ class Controllerart extends Controller public function add($id) { $this->setart($id, 'artadd'); - if ($this->user->canedit() && !$this->importart()) { + if ($this->user->iseditor() && !$this->importart()) { $this->art->reset(); $this->artmanager->add($this->art); $this->routedirect('artedit', ['art' => $this->art->id()]); @@ -130,7 +146,7 @@ class Controllerart extends Controller public function confirmdelete($id) { $this->setart($id, 'artconfirmdelete'); - if ($this->user->canedit() && $this->importart()) { + if ($this->user->iseditor() && $this->importart()) { $this->showtemplate('confirmdelete', ['art' => $this->art, 'artexist' => true]); @@ -142,7 +158,7 @@ class Controllerart extends Controller public function delete($id) { $this->setart($id, 'artdelete'); - if ($this->user->canedit() && $this->importart()) { + if ($this->user->iseditor() && $this->importart()) { $this->artmanager->delete($this->art); } @@ -158,7 +174,7 @@ class Controllerart extends Controller $date = new DateTimeImmutable($_POST['pdate'] . $_POST['ptime'], new DateTimeZone('Europe/Paris')); $date = ['date' => $date]; - if ($this->importart() && $this->user->canedit()) { + if ($this->importart() && $this->user->iseditor()) { $this->art->hydrate($_POST); $this->art->hydrate($date); $this->art->updateedited(); @@ -166,7 +182,7 @@ class Controllerart extends Controller } - $this->routedirect('artupdate', ['art' => $this->art->id()]); + $this->routedirect('artedit', ['art' => $this->art->id()]); diff --git a/app/class/controllermedia.php b/app/class/controllermedia.php index 75540e2..48f803b 100644 --- a/app/class/controllermedia.php +++ b/app/class/controllermedia.php @@ -14,12 +14,7 @@ class Controllermedia extends Controller public function desktop() { - - if($this->useriseditor()) { - - - - } + } public function addmedia() diff --git a/app/class/model.php b/app/class/model.php index b6e2ee6..cd0733c 100644 --- a/app/class/model.php +++ b/app/class/model.php @@ -5,7 +5,7 @@ abstract 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 MEDIA_DIR = '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; const DATABASE_DIR = '.' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR; @@ -32,6 +32,15 @@ abstract class Model return DIRECTORY_SEPARATOR . $basepath . Model::CSS_DIR; } + public static function mediapath() + { + $basepath = ''; + if(!empty(Config::basepath())) { + $basepath = Config::basepath() . DIRECTORY_SEPARATOR ; + } + return DIRECTORY_SEPARATOR . $basepath . Model::MEDIA_DIR; + } + public static function fontpath() { $basepath = ''; diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 82911aa..3fb1f81 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -4,6 +4,7 @@ class Modelrender extends Modelart { protected $router; protected $artlist; + protected $linkfrom = []; const SUMMARY = '%SUMMARY%'; @@ -172,7 +173,8 @@ class Modelrender extends Modelart $text = $this->wikiurl($text); $text = str_replace('href="http', ' class="external" target="_blank" href="http', $text); - $text = str_replace('autourl($text); @@ -188,37 +190,43 @@ class Modelrender extends Modelart public function wurl(string $text) { + $linkfrom = []; $rend = $this; $text = preg_replace_callback( '%href="([\w-]+)"%', - function ($matches) use ($rend) { + function ($matches) use ($rend, &$linkfrom) { $matchart = $rend->get($matches[1]); if (!$matchart) { return 'href="' . $rend->uart($matches[1]) . '"" title="' . Config::existnot() . '" class="internal"'; } else { + $linkfrom[] = $matchart->id(); return 'href="' . $rend->uart($matches[1]) . '" title="' . $matchart->description() . '" class="internal"'; } }, $text ); + $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom)); return $text; } public function wikiurl(string $text) { + $linkfrom = []; $rend = $this; $text = preg_replace_callback( '%\[([\w-]+)\]%', - function ($matches) use ($rend) { + function ($matches) use ($rend, &$linkfrom) { $matchart = $rend->get($matches[1]); if (!$matchart) { return '' . $matches[1] . ''; } else { + $linkfrom[] = $matchart->id(); return '' . $matchart->title() . ''; } }, $text ); + $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom)); return $text; } @@ -321,10 +329,19 @@ class Modelrender extends Modelart $text = str_replace('%%'.$tag.'%%', $ul, $text); + $this->linkfrom = array_unique(array_merge($this->linkfrom, $li)); } return $text; } + public function linkfrom() + { + sort($this->linkfrom); + $linkfrom = $this->linkfrom; + $this->linkfrom = []; + return $linkfrom; + } + diff --git a/app/class/modeluser.php b/app/class/modeluser.php index 899d1cc..1644a35 100644 --- a/app/class/modeluser.php +++ b/app/class/modeluser.php @@ -39,13 +39,23 @@ class Modeluser extends Model return $level = self::READ; } elseif (strip_tags($pass) == Config::editor()) { return $level = self::EDITOR; - } elseif (strip_tags($pass) == Config::invite()) { + } elseif ($this->invitetest(strip_tags($pass))) { return $level = self::INVITE; } else { return $level = self::FREE; } } + public function invitetest() + { + $invitepasslist = []; + if(in_array($pass, $invitepasslist)) { + return true; + } else { + return false; + } + } + public function logout() { $user = new User(['level' => self::FREE]); diff --git a/app/class/routes.php b/app/class/routes.php index dda30d7..d2658a5 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -17,6 +17,7 @@ class Routes ['GET|POST', '/', 'Backrouter#run', 'backrouter'], ['POST', '/!co', 'Controllerconnect#log', 'log'], ['GET', '/!co', 'Controllerconnect#connect', 'connect'], + ['GET', '/!m', 'Controllermedia#desktop', 'media'], ['GET', '/[cid:art]/', 'Controllerart#read', 'artread/'], ['GET', '/[cid:art]', 'Controllerart#read', 'artread'], ['GET', '/[cid:art]/add', 'Controllerart#add', 'artadd'], diff --git a/app/class/user.php b/app/class/user.php index 77d6ba2..fc5a665 100644 --- a/app/class/user.php +++ b/app/class/user.php @@ -3,6 +3,7 @@ class User { protected $level = 0; + protected $password; public function __construct($datas = []) { if(!empty($datas)) { @@ -36,15 +37,14 @@ class User return $this->level === Modeluser::FREE; } - public function canedit() + public function iseditor() { - // a modifier en prenant compte du code invitation de l'article return $this->level >= Modeluser::EDITOR; } - public function cancreate() + public function isinvite() { - return $this->level >=Modeluser::EDITOR; + return $this->level >= Modeluser::INVITE; } public function isadmin() diff --git a/app/view/templates/home.php b/app/view/templates/home.php index b5b9f67..a11f9e3 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -10,7 +10,7 @@ insert('hometopbar', ['user' => $user]) ?> -canedit()) { ?> +iseditor()) { ?>
diff --git a/app/view/templates/hometopbar.php b/app/view/templates/hometopbar.php index 0640119..ff0b5f8 100644 --- a/app/view/templates/hometopbar.php +++ b/app/view/templates/hometopbar.php @@ -21,7 +21,7 @@ User level : level() ?> -canedit()) { ?> +iseditor()) { ?> diff --git a/app/view/templates/media.php b/app/view/templates/media.php index 8b189d5..31e3ad0 100644 --- a/app/view/templates/media.php +++ b/app/view/templates/media.php @@ -1,4 +1 @@ -layout('base', ['title' => 'Media']) ?> - -

Media

-

Hello, e($interface)?>

\ No newline at end of file +layout('layout', ['title' => 'Media']) ?> diff --git a/app/view/templates/navart.php b/app/view/templates/navart.php index a98eed6..d3baef5 100644 --- a/app/view/templates/navart.php +++ b/app/view/templates/navart.php @@ -89,7 +89,7 @@ -canedit() && $artexist) { ?> +iseditor() && $artexist) { ?>
  • display @@ -101,7 +101,7 @@ -canedit()) { ?> +iseditor()) { ?>
  • Media diff --git a/app/view/templates/navback.php b/app/view/templates/navback.php index c738ae2..8218897 100644 --- a/app/view/templates/navback.php +++ b/app/view/templates/navback.php @@ -31,7 +31,7 @@ -canedit()) { ?> +iseditor()) { ?>
  • Media diff --git a/app/view/templates/read.php b/app/view/templates/read.php index 1911cf6..4e18cb3 100644 --- a/app/view/templates/read.php +++ b/app/view/templates/read.php @@ -52,7 +52,7 @@ $this->stop(); } else { echo '

    ' . $alertnotexist . '

    '; - if ($cancreate) { + if ($user->iseditor()) { ?> ⭐ Create