diff options
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/application.php | 8 | ||||
-rw-r--r-- | app/class/backrouter.php | 80 | ||||
-rw-r--r-- | app/class/config.php | 22 | ||||
-rw-r--r-- | app/class/controller.php | 12 | ||||
-rw-r--r-- | app/class/controlleradmin.php | 10 | ||||
-rw-r--r-- | app/class/controllerart.php | 409 | ||||
-rw-r--r-- | app/class/controllerconnect.php | 14 | ||||
-rw-r--r-- | app/class/controllerhome.php | 14 | ||||
-rw-r--r-- | app/class/controllerpage.php | 409 | ||||
-rw-r--r-- | app/class/element.php | 12 | ||||
-rw-r--r-- | app/class/event.php | 4 | ||||
-rw-r--r-- | app/class/modelanalyse.php | 38 | ||||
-rw-r--r-- | app/class/modelart.php | 306 | ||||
-rw-r--r-- | app/class/modelhome.php | 16 | ||||
-rw-r--r-- | app/class/modelpage.php | 306 | ||||
-rw-r--r-- | app/class/modelrender.php | 172 | ||||
-rw-r--r-- | app/class/modeltimeline.php | 2 | ||||
-rw-r--r-- | app/class/opt.php | 28 | ||||
-rw-r--r-- | app/class/page.php (renamed from app/class/art2.php) | 4 | ||||
-rw-r--r-- | app/class/route.php | 2 | ||||
-rw-r--r-- | app/class/routes.php | 30 |
21 files changed, 909 insertions, 989 deletions
diff --git a/app/class/application.php b/app/class/application.php index b749d9b..784a388 100644 --- a/app/class/application.php +++ b/app/class/application.php @@ -40,12 +40,12 @@ class Application } else { if(Config::readconfig()) { - if(!Config::checkbasepath() || empty(Config::arttable()) || !is_dir(Model::RENDER_DIR) || !Config::checkdomain()) { + if(!Config::checkbasepath() || empty(Config::pagetable()) || !is_dir(Model::RENDER_DIR) || !Config::checkdomain()) { echo '<ul>'; if(!Config::checkbasepath()) { echo '<li>Wrong path</li>'; } - if(empty(Config::arttable())) { + if(empty(Config::pagetable())) { echo '<li>Unset table name</li>'; } if(!Config::checkdomain()) { @@ -91,9 +91,9 @@ class Application </div> <div> <h2> - <label for="arttable">Name of your database table</label> + <label for="pagetable">Name of your database table</label> </h2> - <input type="text" name="configinit[arttable]" value="<?= Config::arttable() ?>" id="arttable"> + <input type="text" name="configinit[pagetable]" value="<?= Config::pagetable() ?>" id="pagetable"> <p><i>Set the name of the first folder that is going to store all your work</i></p> </div> <input type="submit" value="set"> diff --git a/app/class/backrouter.php b/app/class/backrouter.php deleted file mode 100644 index 356a021..0000000 --- a/app/class/backrouter.php +++ /dev/null @@ -1,80 +0,0 @@ -<?php - - -class Backrouter -{ - protected $route; - protected $altorouter; - - const ROUTES = [ - 'art' => ['art', 'read'], - 'art aff=read' => ['art', 'read'], - 'art aff=edit' => ['art', 'edit'], - 'art aff=log' => ['art', 'log'], - 'art action=update' => ['art', 'update'], - 'art action=update home' => ['art', 'update', 'home'], - 'art action=add' => ['art', 'add'], - 'art action=delete' => ['art', 'delete'], - 'aff=home action=massedit', - 'aff=home' => ['home', 'desktop'], - '' => ['home', 'desktop'], - 'aff=home action=massedit' => ['home', 'massedit'], - 'action=massedit' => ['home', 'massedit'], - 'action=analyseall' => ['home', 'analyseall'], - 'aff=home action=analyseall' => ['home', 'analyseall'], - 'art action=login' => ['art', 'login', 'art'], - 'home action=login' => ['home', 'login', 'home'], - 'action=login' => ['home', 'login'], - 'art action=logout' => ['art', 'logout', 'art'], - 'home action=logout' => ['home', 'logout', 'home'], - 'action=logout' => ['home', 'logout'], - 'aff=db' => ['db', 'desktop'], - 'aff=db action=add' => ['db', 'add'], - 'aff=media' => ['media', 'desktop'], - 'aff=media action=addmedia' => ['media', 'addmedia'], - 'aff=admin' => ['admin', 'desktop'], - 'aff=co' => ['connect', 'desktop'], - ]; - - public function __construct($router) - { - $this->altorouter = $router; - } - - public function run() { - if($this->matchroute()) { - $this->callmethod(); - } else { - echo '<h1>404 Error</h1>'; - } - } - - public function matchroute() - { - $this->route = new route($_GET); - $match = array_key_exists($this->route->tostring(), self::ROUTES); - return $match; - - } - - public function callmethod() - { - $method = self::ROUTES[$this->route->tostring()]; - - $class = 'controller' . $method[0]; - $function = $method[1]; - $controller = new $class($this->altorouter); - $params = array_slice($method, 2); - $controller->$function(...$params); - } - - - -} - - - - - - -?>
\ No newline at end of file diff --git a/app/class/config.php b/app/class/config.php index 26adf62..3d67908 100644 --- a/app/class/config.php +++ b/app/class/config.php @@ -4,7 +4,7 @@ abstract class Config { - protected static $arttable = 'mystore'; + protected static $pagetable = 'mystore'; protected static $domain = ''; protected static $fontsize = 15; protected static $basepath = ''; @@ -20,7 +20,7 @@ abstract class Config protected static $notpublishedpass = false; protected static $alertcss = false; protected static $defaultbody = '%HEADER%'. PHP_EOL .PHP_EOL . '%NAV%'. PHP_EOL .PHP_EOL . '%ASIDE%'. PHP_EOL .PHP_EOL . '%MAIN%'. PHP_EOL .PHP_EOL . '%FOOTER%'; - protected static $defaultart = ''; + protected static $defaultpage = ''; protected static $defaultfavicon = ''; protected static $analytics = ''; protected static $externallinkblank = true; @@ -112,9 +112,9 @@ abstract class Config // ________________________________________ G E T _______________________________________ - public static function arttable() + public static function pagetable() { - return self::$arttable; + return self::$pagetable; } public static function domain() @@ -192,9 +192,9 @@ abstract class Config return self::$defaultbody; } - public static function defaultart() + public static function defaultpage() { - return self::$defaultart; + return self::$defaultpage; } public static function defaultfavicon() @@ -250,9 +250,9 @@ abstract class Config // __________________________________________ S E T ______________________________________ - public static function setarttable($arttable) + public static function setpagetable($pagetable) { - self::$arttable = strip_tags($arttable); + self::$pagetable = strip_tags($pagetable); } public static function setdomain($domain) @@ -356,10 +356,10 @@ abstract class Config } } - public static function setdefaultart($defaultart) + public static function setdefaultpage($defaultpage) { - if(is_string($defaultart)) { - self::$defaultart = idclean($defaultart); + if(is_string($defaultpage)) { + self::$defaultpage = idclean($defaultpage); } } diff --git a/app/class/controller.php b/app/class/controller.php index b925236..a5bd33b 100644 --- a/app/class/controller.php +++ b/app/class/controller.php @@ -11,8 +11,8 @@ class Controller /** @var Modeluser */ protected $usermanager; - /** @var Modelart */ - protected $artmanager; + /** @var Modelpage */ + protected $pagemanager; protected $plates; @@ -22,7 +22,7 @@ class Controller public function __construct($router) { $this->setuser(); $this->router = $router; - $this->artmanager = new Modelart(); + $this->pagemanager = new Modelpage(); $this->initplates(); $this->now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); } @@ -40,8 +40,8 @@ class Controller $this->plates->registerFunction('url', function (string $string, array $vars = []) use ($router) { return $router->generate($string, $vars); }); - $this->plates->registerFunction('uart', function (string $string, string $id) use ($router) { - return $router->generate($string, ['art' => $id]); + $this->plates->registerFunction('upage', function (string $string, string $id) use ($router) { + return $router->generate($string, ['page' => $id]); }); } @@ -56,7 +56,7 @@ class Controller $commonsparams = []; $commonsparams['router'] = $this->router; $commonsparams['user'] = $this->user; - $commonsparams['pagelist'] = $this->artmanager->list(); + $commonsparams['pagelist'] = $this->pagemanager->list(); $commonsparams['css'] = Model::csspath(); return $commonsparams; } diff --git a/app/class/controlleradmin.php b/app/class/controlleradmin.php index e3e1b2a..dda0a54 100644 --- a/app/class/controlleradmin.php +++ b/app/class/controlleradmin.php @@ -9,14 +9,14 @@ class Controlleradmin extends Controller public function desktop() { if($this->user->isadmin()) { - $artlist = $this->artmanager->list(); + $pagelist = $this->pagemanager->list(); $this->mediamanager = new Modelmedia(); $faviconlist = $this->mediamanager->listfavicon(); $interfacecsslist = $this->mediamanager->listinterfacecss(); - if(in_array(Config::defaultart(), $artlist)) { - $defaultartexist = true; + if(in_array(Config::defaultpage(), $pagelist)) { + $defaultpageexist = true; } else { - $defaultartexist = true; + $defaultpageexist = true; } $globalcssfile = Model::GLOBAL_DIR . 'global.css'; @@ -27,7 +27,7 @@ class Controlleradmin extends Controller $globalcss = ""; } - $admin = ['artlist' => $artlist, 'defaultartexist' => $defaultartexist, 'globalcss' => $globalcss, 'faviconlist' => $faviconlist, 'interfacecsslist' => $interfacecsslist]; + $admin = ['pagelist' => $pagelist, 'defaultpageexist' => $defaultpageexist, 'globalcss' => $globalcss, 'faviconlist' => $faviconlist, 'interfacecsslist' => $interfacecsslist]; $this->showtemplate('admin', $admin); } else { $this->routedirect('home'); diff --git a/app/class/controllerart.php b/app/class/controllerart.php deleted file mode 100644 index 8d8e3bb..0000000 --- a/app/class/controllerart.php +++ /dev/null @@ -1,409 +0,0 @@ -<?php - -class Controllerart extends Controller -{ - /** @var Art2 */ - protected $art; - protected $fontmanager; - protected $mediamanager; - - const COMBINE = false; - - public function __construct($router) - { - parent::__construct($router); - - $this->fontmanager = new Modelfont(); - $this->mediamanager = new Modelmedia(); - - } - - public function setart(string $id, string $route) - { - $cleanid = idclean($id); - if ($cleanid !== $id) { - $this->routedirect($route, ['art' => $cleanid]); - } else { - $this->art = new Art2(['id' => $cleanid]); - } - } - - public function importart() - { - if (isset($_SESSION['artupdate']) && $_SESSION['artupdate']['id'] == $this->art->id()) { - $art = new Art2($_SESSION['artupdate']); - unset($_SESSION['artupdate']); - } else { - $art = $this->artmanager->get($this->art); - } - if ($art !== false) { - $this->art = $art; - return true; - } else { - return false; - } - - } - - /** - * show credentials for unconnected editors for a specific page - * - * @param string $route direction to redirect after the connection form - * @return void - */ - public function artconnect(string $route) - { - if($this->user->isvisitor()) { - $this->showtemplate('connect', ['route' => $route, 'id' => $this->art->id()]); - exit; - } - } - - - public function canedit() - { - if ($this->user->issupereditor()) { - return true; - } elseif ($this->user->isinvite() || $this->user->iseditor()) { - if (in_array($this->user->id(), $this->art->authors())) { - return true; - } else { - return false; - } - } else { - return false; - } - } - - function render($id) - { - $this->setart($id, 'artupdate'); - - if ($this->importart() && $this->user->iseditor()) { - $this->art = $this->renderart($this->art); - $this->artmanager->update($this->art); - } - $this->routedirect('artread/', ['art' => $this->art->id()]); - } - - /** - * Render given page - * - * @param Art2 $art input - * - * @return Art2 rendered $art - */ - public function renderart(Art2 $art) : Art2 - { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - - $renderengine = new Modelrender($this->router); - - $renderengine->render($art); - $art->setdaterender($now); - $art->setlinkfrom($renderengine->linkfrom()); - $art->setlinkto($renderengine->linkto()); - - return $art; - - } - - public function reccursiverender(Art2 $art) - { - $relatedarts = array_diff($art->linkto(), [$art->id()]); - foreach ($relatedarts as $artid ) { - $art = $this->artmanager->get($artid); - if($art !== false) { - $art = $this->renderart($art); - $this->artmanager->update($art); - } - } - } - - - public function read($id) - { - $this->setart($id, 'artread/'); - - $artexist = $this->importart(); - $canread = $this->user->level() >= $this->art->secure(); - $page = ['head' => '', 'body' => '']; - - if ($artexist) { - - if ($this->art->daterender() < $this->art->datemodif()) { - if(Config::reccursiverender()) { - $this->reccursiverender($this->art); - } - $this->art = $this->renderart($this->art); - } - if ($canread) { - $this->art->addaffcount(); - if ($this->user->level() < 2) { - $this->art->addvisitcount(); - } - } - $this->artmanager->update($this->art); - } - - if($artexist && $canread) { - $filedir = Model::HTML_RENDER_DIR . $id . '.html'; - if(file_exists($filedir)) { - $html = file_get_contents($filedir); - echo $html; - } else { - echo 'Please render this page'; - } - } else { - $this->showtemplate('alert', ['art' => $this->art, 'artexist' => $artexist, 'canedit' => $this->canedit()]); - } - - } - - public function edit($id) - { - $this->setart($id, 'artedit'); - - $this->artconnect('artedit'); - - - if ($this->importart() && $this->canedit()) { - $tablist = ['main' => $this->art->main(), 'css' => $this->art->css(), 'header' => $this->art->header(), 'nav' => $this->art->nav(), 'aside' => $this->art->aside(), 'footer' => $this->art->footer(), 'body' => $this->art->body(), 'javascript' => $this->art->javascript()]; - - $faviconlist = $this->mediamanager->listfavicon(); - $idlist = $this->artmanager->list(); - - - $artlist = $this->artmanager->getlister(); - $tagartlist = $this->artmanager->tagartlist($this->art->tag('array'), $artlist); - $lasteditedartlist = $this->artmanager->lasteditedartlist(5, $artlist); - - $editorlist = $this->usermanager->getlisterbylevel(2, '>='); - - if (isset($_SESSION['workspace'])) { - $showleftpanel = $_SESSION['workspace']['showleftpanel']; - $showrightpanel = $_SESSION['workspace']['showrightpanel']; - } else { - $showleftpanel = false; - $showrightpanel = false; - } - $fonts = []; - - $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true, 'tablist' => $tablist, 'artlist' => $idlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts, 'tagartlist' => $tagartlist, 'lasteditedartlist' => $lasteditedartlist, 'faviconlist' => $faviconlist, 'editorlist' => $editorlist, 'user' => $this->user]); - } else { - $this->routedirect('artread/', ['art' => $this->art->id()]); - } - - } - - public function log($id) - { - $this->setart($id, 'artlog'); - $this->importart(); - var_dump($this->art); - } - - public function add($id) - { - $this->setart($id, 'artadd'); - - $this->artconnect('artadd'); - - if ($this->user->iseditor() && !$this->importart()) { - $this->art->reset(); - if (!empty(Config::defaultart())) { - $defaultart = $this->artmanager->get(Config::defaultart()); - if ($defaultart !== false) { - $defaultbody = $defaultart->body(); - } - } - if (empty(Config::defaultart()) || $defaultart === false) { - $defaultbody = Config::defaultbody(); - } - $this->art->setbody($defaultbody); - $this->artmanager->add($this->art); - $this->routedirect('artedit', ['art' => $this->art->id()]); - } else { - $this->routedirect('artread/', ['art' => $this->art->id()]); - } - } - - public function confirmdelete($id) - { - $this->setart($id, 'artconfirmdelete'); - if ($this->user->iseditor() && $this->importart()) { - - $this->showtemplate('confirmdelete', ['art' => $this->art, 'artexist' => true]); - - } else { - $this->routedirect('artread/', ['art' => $this->art->id()]); - } - } - - public function download($id) - { - if($this->user->isadmin()) { - - $file = Model::DATABASE_DIR . Config::arttable() . DIRECTORY_SEPARATOR . $id . '.json'; - - if (file_exists($file)) { - header('Content-Description: File Transfer'); - header('Content-Type: application/json; charset=utf-8'); - header('Content-Disposition: attachment; filename="'.basename($file).'"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate'); - header('Pragma: public'); - header('Content-Length: ' . filesize($file)); - readfile($file); - exit; - } - } else { - $this->routedirect('artread/', ['art' => $id]); - } - } - - /** - * Import page and save it into the database - */ - public function upload() - { - $art = $this->artmanager->getfromfile(); - - - if(!empty($_POST['id'])) { - $art->setid(idclean($_POST['id'])); - } - - if($_POST['datecreation']) { - $art->setdatecreation($this->now); - } - - if($_POST['author']) { - $art->setauthors([$this->user->id()]); - } - - $art->setdaterender($art->datecreation('date')); - - if($art !== false) { - if($_POST['erase'] || $this->artmanager->get($art) === false) { - $this->artmanager->add($art); - } - } - $this->routedirect('home'); - } - - public function delete($id) - { - $this->setart($id, 'artdelete'); - if ($this->user->iseditor() && $this->importart()) { - - $this->artmanager->delete($this->art); - } - $this->routedirect('home'); - } - - public function update($id) - { - $this->setart($id, 'artupdate'); - - $this->movepanels(); - $this->fontsize(); - - $date = new DateTimeImmutable($_POST['pdate'] . $_POST['ptime'], new DateTimeZone('Europe/Paris')); - $date = ['date' => $date]; - - if ($this->importart()) { - if ($this->canedit()) { - - // Check if someone esle edited the page during the editing. - $oldart = clone $this->art; - $this->art->hydrate($_POST); - - if (self::COMBINE && $_POST['thisdatemodif'] === $oldart->datemodif('string')) { - - } - - $this->art->hydrate($date); - $this->art->updateedited(); - $this->art->addauthor($this->user->id()); - $this->art->removeeditby($this->user->id()); - - // Add thumbnail image file under 1Mo - $this->mediamanager->simpleupload('thumbnail', Model::THUMBNAIL_DIR . $this->art->id(), 1024*1024, ['jpg', 'jpeg', 'JPG', 'JPEG'], true); - - - $this->artmanager->update($this->art); - - $this->routedirect('artedit', ['art' => $this->art->id()]); - - //$this->showtemplate('updatemerge', $compare); - } else { - // If the editor session finished during the editing, let's try to reconnect to save the editing - $_SESSION['artupdate'] = $_POST; - $_SESSION['artupdate']['id'] = $this->art->id(); - $this->routedirect('connect'); - } - - } - $this->routedirect('art'); - } - - /** - * This function set the actual editor of the page - * - * @param string $artid as the page id - */ - public function editby(string $artid) - { - $this->art = new Art2(['id' => $artid]); - if($this->importart($artid)) { - $this->art->addeditby($this->user->id()); - $this->artmanager->update($this->art); - echo json_encode(['success' => true]); - } else { - $this->error(400); - } - } - - /** - * This function remove the actual editor of the page - * - * @param string $artid as the page id - */ - public function removeeditby(string $artid) - { - $this->art = new Art2(['id' => $artid]); - if($this->importart($artid)) { - $this->art->removeeditby($this->user->id()); - $this->artmanager->update($this->art); - echo json_encode(['success' => true]); - } else { - $this->error(400); - } - } - - - public function movepanels() - { - $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']); - $_SESSION['workspace']['showleftpanel'] = isset($_POST['workspace']['showleftpanel']); - } - - public function fontsize() - { - if (!empty($_POST['fontsize']) && $_POST['fontsize'] !== Config::fontsize()) { - Config::setfontsize($_POST['fontsize']); - Config::savejson(); - } - } - - public function artdirect($id) - { - $this->routedirect('artread/', ['art' => idclean($id)]); - } -} - - - - -?>
\ No newline at end of file diff --git a/app/class/controllerconnect.php b/app/class/controllerconnect.php index bf1b72d..1bd0a5a 100644 --- a/app/class/controllerconnect.php +++ b/app/class/controllerconnect.php @@ -19,13 +19,13 @@ class Controllerconnect extends Controller public function connect() { - if(isset($_SESSION['artupdate'])) { - $artupdate['route'] = 'artedit'; - $artupdate['id'] = $_SESSION['artupdate']['id']; + if(isset($_SESSION['pageupdate'])) { + $pageupdate['route'] = 'pageedit'; + $pageupdate['id'] = $_SESSION['pageupdate']['id']; } else { - $artupdate = ['route' => 'home']; + $pageupdate = ['route' => 'home']; } - $this->showtemplate('connect', $artupdate); + $this->showtemplate('connect', $pageupdate); } @@ -47,7 +47,7 @@ class Controllerconnect extends Controller } } if ($id !== null) { - $this->routedirect($route, ['art' => $id]); + $this->routedirect($route, ['page' => $id]); } else { $this->routedirect($route); } @@ -58,7 +58,7 @@ class Controllerconnect extends Controller $this->user = $this->usermanager->logout(); $this->usermanager->writesession($this->user); if ($id !== null && $route !== 'home') { - $this->routedirect($route, ['art' => $id]); + $this->routedirect($route, ['page' => $id]); } else { $this->routedirect($route); } diff --git a/app/class/controllerhome.php b/app/class/controllerhome.php index 7691bab..d263611 100644 --- a/app/class/controllerhome.php +++ b/app/class/controllerhome.php @@ -1,6 +1,6 @@ <?php -class Controllerhome extends Controllerart +class Controllerhome extends Controllerpage { /** @var Modelhome */ protected $modelhome; @@ -20,7 +20,7 @@ class Controllerhome extends Controllerart public function desktop() { if ($this->user->isvisitor() && Config::homepage() === 'redirect' && Config::homeredirect() !== null) { - $this->routedirect('artread/', ['art' => Config::homeredirect()]); + $this->routedirect('pageread/', ['page' => Config::homeredirect()]); } else { @@ -34,7 +34,7 @@ class Controllerhome extends Controllerart $columns = $this->modelhome->setcolumns($this->user->columns()); $vars = ['user' => $this->user, 'table2' => $table2, 'opt' => $this->opt, 'columns' => $columns]; - $vars['footer'] = ['version' => getversion(), 'total' => count($table), 'database' => Config::arttable()]; + $vars['footer'] = ['version' => getversion(), 'total' => count($table), 'database' => Config::pagetable()]; if (isset($_POST['query']) && $this->user->iseditor()) { $datas = array_merge($_POST, $_SESSION['opt']); @@ -64,11 +64,11 @@ class Controllerhome extends Controllerart if (isset($_POST['action'])) { switch ($_POST['action']) { case 'read': - $this->routedirect('artread/', ['art' => $_POST['id']]); + $this->routedirect('pageread/', ['page' => $_POST['id']]); break; case 'edit': - $this->routedirect('artedit', ['art' => $_POST['id']]); + $this->routedirect('pageedit', ['page' => $_POST['id']]); break; } } @@ -85,8 +85,8 @@ class Controllerhome extends Controllerart if ($this->user->iseditor()) { $pagelist = $this->modelhome->getlister(); foreach ($pagelist as $page) { - $this->renderart($page); - $this->artmanager->update($page); + $this->renderpage($page); + $this->pagemanager->update($page); } } $this->routedirect('home'); diff --git a/app/class/controllerpage.php b/app/class/controllerpage.php new file mode 100644 index 0000000..9cced39 --- /dev/null +++ b/app/class/controllerpage.php @@ -0,0 +1,409 @@ +<?php + +class Controllerpage extends Controller +{ + /** @var Page */ + protected $page; + protected $fontmanager; + protected $mediamanager; + + const COMBINE = false; + + public function __construct($router) + { + parent::__construct($router); + + $this->fontmanager = new Modelfont(); + $this->mediamanager = new Modelmedia(); + + } + + public function setpage(string $id, string $route) + { + $cleanid = idclean($id); + if ($cleanid !== $id) { + $this->routedirect($route, ['page' => $cleanid]); + } else { + $this->page = new Page(['id' => $cleanid]); + } + } + + public function importpage() + { + if (isset($_SESSION['pageupdate']) && $_SESSION['pageupdate']['id'] == $this->page->id()) { + $page = new Page($_SESSION['pageupdate']); + unset($_SESSION['pageupdate']); + } else { + $page = $this->pagemanager->get($this->page); + } + if ($page !== false) { + $this->page = $page; + return true; + } else { + return false; + } + + } + + /** + * show credentials for unconnected editors for a specific page + * + * @param string $route direction to redirect after the connection form + * @return void + */ + public function pageconnect(string $route) + { + if($this->user->isvisitor()) { + $this->showtemplate('connect', ['route' => $route, 'id' => $this->page->id()]); + exit; + } + } + + + public function canedit() + { + if ($this->user->issupereditor()) { + return true; + } elseif ($this->user->isinvite() || $this->user->iseditor()) { + if (in_array($this->user->id(), $this->page->authors())) { + return true; + } else { + return false; + } + } else { + return false; + } + } + + function render($id) + { + $this->setpage($id, 'pageupdate'); + + if ($this->importpage() && $this->user->iseditor()) { + $this->page = $this->renderpage($this->page); + $this->pagemanager->update($this->page); + } + $this->routedirect('pageread/', ['page' => $this->page->id()]); + } + + /** + * Render given page + * + * @param Page $page input + * + * @return Page rendered $page + */ + public function renderpage(Page $page) : Page + { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + + $renderengine = new Modelrender($this->router); + + $renderengine->render($page); + $page->setdaterender($now); + $page->setlinkfrom($renderengine->linkfrom()); + $page->setlinkto($renderengine->linkto()); + + return $page; + + } + + public function reccursiverender(Page $page) + { + $relatedpages = array_diff($page->linkto(), [$page->id()]); + foreach ($relatedpages as $pageid ) { + $page = $this->pagemanager->get($pageid); + if($page !== false) { + $page = $this->renderpage($page); + $this->pagemanager->update($page); + } + } + } + + + public function read($id) + { + $this->setpage($id, 'pageread/'); + + $pageexist = $this->importpage(); + $canread = $this->user->level() >= $this->page->secure(); + $page = ['head' => '', 'body' => '']; + + if ($pageexist) { + + if ($this->page->daterender() < $this->page->datemodif()) { + if(Config::reccursiverender()) { + $this->reccursiverender($this->page); + } + $this->page = $this->renderpage($this->page); + } + if ($canread) { + $this->page->addaffcount(); + if ($this->user->level() < 2) { + $this->page->addvisitcount(); + } + } + $this->pagemanager->update($this->page); + } + + if($pageexist && $canread) { + $filedir = Model::HTML_RENDER_DIR . $id . '.html'; + if(file_exists($filedir)) { + $html = file_get_contents($filedir); + echo $html; + } else { + echo 'Please render this page'; + } + } else { + $this->showtemplate('alert', ['page' => $this->page, 'pageexist' => $pageexist, 'canedit' => $this->canedit()]); + } + + } + + public function edit($id) + { + $this->setpage($id, 'pageedit'); + + $this->pageconnect('pageedit'); + + + if ($this->importpage() && $this->canedit()) { + $tablist = ['main' => $this->page->main(), 'css' => $this->page->css(), 'header' => $this->page->header(), 'nav' => $this->page->nav(), 'aside' => $this->page->aside(), 'footer' => $this->page->footer(), 'body' => $this->page->body(), 'javascript' => $this->page->javascript()]; + + $faviconlist = $this->mediamanager->listfavicon(); + $idlist = $this->pagemanager->list(); + + + $pagelist = $this->pagemanager->getlister(); + $tagpagelist = $this->pagemanager->tagpagelist($this->page->tag('array'), $pagelist); + $lasteditedpagelist = $this->pagemanager->lasteditedpagelist(5, $pagelist); + + $editorlist = $this->usermanager->getlisterbylevel(2, '>='); + + if (isset($_SESSION['workspace'])) { + $showleftpanel = $_SESSION['workspace']['showleftpanel']; + $showrightpanel = $_SESSION['workspace']['showrightpanel']; + } else { + $showleftpanel = false; + $showrightpanel = false; + } + $fonts = []; + + $this->showtemplate('edit', ['page' => $this->page, 'pageexist' => true, 'tablist' => $tablist, 'pagelist' => $idlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts, 'tagpagelist' => $tagpagelist, 'lasteditedpagelist' => $lasteditedpagelist, 'faviconlist' => $faviconlist, 'editorlist' => $editorlist, 'user' => $this->user]); + } else { + $this->routedirect('pageread/', ['page' => $this->page->id()]); + } + + } + + public function log($id) + { + $this->setpage($id, 'pagelog'); + $this->importpage(); + var_dump($this->page); + } + + public function add($id) + { + $this->setpage($id, 'pageadd'); + + $this->pageconnect('pageadd'); + + if ($this->user->iseditor() && !$this->importpage()) { + $this->page->reset(); + if (!empty(Config::defaultpage())) { + $defaultpage = $this->pagemanager->get(Config::defaultpage()); + if ($defaultpage !== false) { + $defaultbody = $defaultpage->body(); + } + } + if (empty(Config::defaultpage()) || $defaultpage === false) { + $defaultbody = Config::defaultbody(); + } + $this->page->setbody($defaultbody); + $this->pagemanager->add($this->page); + $this->routedirect('pageedit', ['page' => $this->page->id()]); + } else { + $this->routedirect('pageread/', ['page' => $this->page->id()]); + } + } + + public function confirmdelete($id) + { + $this->setpage($id, 'pageconfirmdelete'); + if ($this->user->iseditor() && $this->importpage()) { + + $this->showtemplate('confirmdelete', ['page' => $this->page, 'pageexist' => true]); + + } else { + $this->routedirect('pageread/', ['page' => $this->page->id()]); + } + } + + public function download($id) + { + if($this->user->isadmin()) { + + $file = Model::DATABASE_DIR . Config::pagetable() . DIRECTORY_SEPARATOR . $id . '.json'; + + if (file_exists($file)) { + header('Content-Description: File Transfer'); + header('Content-Type: application/json; charset=utf-8'); + header('Content-Disposition: attachment; filename="'.basename($file).'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . filesize($file)); + readfile($file); + exit; + } + } else { + $this->routedirect('pageread/', ['page' => $id]); + } + } + + /** + * Import page and save it into the database + */ + public function upload() + { + $page = $this->pagemanager->getfromfile(); + + + if(!empty($_POST['id'])) { + $page->setid(idclean($_POST['id'])); + } + + if($_POST['datecreation']) { + $page->setdatecreation($this->now); + } + + if($_POST['author']) { + $page->setauthors([$this->user->id()]); + } + + $page->setdaterender($page->datecreation('date')); + + if($page !== false) { + if($_POST['erase'] || $this->pagemanager->get($page) === false) { + $this->pagemanager->add($page); + } + } + $this->routedirect('home'); + } + + public function delete($id) + { + $this->setpage($id, 'pagedelete'); + if ($this->user->iseditor() && $this->importpage()) { + + $this->pagemanager->delete($this->page); + } + $this->routedirect('home'); + } + + public function update($id) + { + $this->setpage($id, 'pageupdate'); + + $this->movepanels(); + $this->fontsize(); + + $date = new DateTimeImmutable($_POST['pdate'] . $_POST['ptime'], new DateTimeZone('Europe/Paris')); + $date = ['date' => $date]; + + if ($this->importpage()) { + if ($this->canedit()) { + + // Check if someone esle edited the page during the editing. + $oldpage = clone $this->page; + $this->page->hydrate($_POST); + + if (self::COMBINE && $_POST['thisdatemodif'] === $oldpage->datemodif('string')) { + + } + + $this->page->hydrate($date); + $this->page->updateedited(); + $this->page->addauthor($this->user->id()); + $this->page->removeeditby($this->user->id()); + + // Add thumbnail image file under 1Mo + $this->mediamanager->simpleupload('thumbnail', Model::THUMBNAIL_DIR . $this->page->id(), 1024*1024, ['jpg', 'jpeg', 'JPG', 'JPEG'], true); + + + $this->pagemanager->update($this->page); + + $this->routedirect('pageedit', ['page' => $this->page->id()]); + + //$this->showtemplate('updatemerge', $compare); + } else { + // If the editor session finished during the editing, let's try to reconnect to save the editing + $_SESSION['pageupdate'] = $_POST; + $_SESSION['pageupdate']['id'] = $this->page->id(); + $this->routedirect('connect'); + } + + } + $this->routedirect('page'); + } + + /** + * This function set the actual editor of the page + * + * @param string $pageid as the page id + */ + public function editby(string $pageid) + { + $this->page = new Page(['id' => $pageid]); + if($this->importpage($pageid)) { + $this->page->addeditby($this->user->id()); + $this->pagemanager->update($this->page); + echo json_encode(['success' => true]); + } else { + $this->error(400); + } + } + + /** + * This function remove the actual editor of the page + * + * @param string $pageid as the page id + */ + public function removeeditby(string $pageid) + { + $this->page = new Page(['id' => $pageid]); + if($this->importpage($pageid)) { + $this->page->removeeditby($this->user->id()); + $this->pagemanager->update($this->page); + echo json_encode(['success' => true]); + } else { + $this->error(400); + } + } + + + public function movepanels() + { + $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']); + $_SESSION['workspace']['showleftpanel'] = isset($_POST['workspace']['showleftpanel']); + } + + public function fontsize() + { + if (!empty($_POST['fontsize']) && $_POST['fontsize'] !== Config::fontsize()) { + Config::setfontsize($_POST['fontsize']); + Config::savejson(); + } + } + + public function pagedirect($id) + { + $this->routedirect('pageread/', ['page' => idclean($id)]); + } +} + + + + +?>
\ No newline at end of file diff --git a/app/class/element.php b/app/class/element.php index 824a0b6..113daad 100644 --- a/app/class/element.php +++ b/app/class/element.php @@ -19,10 +19,10 @@ class Element - public function __construct($datas = [], $artid) + public function __construct($datas = [], $pageid) { $this->hydrate($datas); - $this->analyse($artid); + $this->analyse($pageid); } public function hydrate($datas) @@ -36,18 +36,18 @@ class Element } } - private function analyse(string $artid) + private function analyse(string $pageid) { if(!empty($this->options)) { // Replace "!" by the real page name - $this->options = str_replace('!', $artid, $this->options); + $this->options = str_replace('!', $pageid, $this->options); preg_match('~(:([a-z0-9-_+!]+))?(\/([a-z0-9-,_+=]+))?~', $this->options, $matches); if(isset($matches[2]) && !empty($matches[2])) { $this->sources = explode('+', $matches[2]); } else { - $this->sources[] = $artid; + $this->sources[] = $pageid; } if(isset($matches[4])) { $this->params = explode(',', $matches[4]); @@ -56,7 +56,7 @@ class Element $this->readoptions(); } else { - $this->sources[] = $artid; + $this->sources[] = $pageid; } } diff --git a/app/class/event.php b/app/class/event.php index 9fc75d2..ddf177b 100644 --- a/app/class/event.php +++ b/app/class/event.php @@ -10,9 +10,9 @@ class Event extends Dbitem protected $message; protected $clap = 0; - const EVENT_TYPES = ['message', 'art_add', 'art_edit', 'art_delete', 'media_add', 'media_delete', 'font_add']; + const EVENT_TYPES = ['message', 'page_add', 'page_edit', 'page_delete', 'media_add', 'media_delete', 'font_add']; const EVENT_BASE = ['message']; - const EVENT_ART = ['art_add', 'art_edit', 'art_delete']; + const EVENT_ART = ['page_add', 'page_edit', 'page_delete']; const EVENT_MEDIA = ['media_add', 'media_delete']; const EVENT_FONT = ['font_add', 'font_delete']; const MESSAGE_MAX_LENGTH = 2 ** 10; diff --git a/app/class/modelanalyse.php b/app/class/modelanalyse.php index 379c41a..66a443e 100644 --- a/app/class/modelanalyse.php +++ b/app/class/modelanalyse.php @@ -2,7 +2,7 @@ -class Modelanalyse extends Modelart +class Modelanalyse extends Modelpage { @@ -12,38 +12,38 @@ class Modelanalyse extends Modelart public function analyseall() { - $artlist = $this->getlister(); + $pagelist = $this->getlister(); - $artlist2 = []; - foreach ($artlist as $art) { - $art->setlinkfrom($this->analyselinkfrom($art)); - $artlist2[] = $art; + $pagelist2 = []; + foreach ($pagelist as $page) { + $page->setlinkfrom($this->analyselinkfrom($page)); + $pagelist2[] = $page; } - foreach ($artlist2 as $art) { - $art->setlinkto($this->analyselinkto($art->id(), $artlist)); - $this->update($art); + foreach ($pagelist2 as $page) { + $page->setlinkto($this->analyselinkto($page->id(), $pagelist)); + $this->update($page); } } - public function analyse(Art2 $art) + public function analyse(Page $page) { - $art->setlinkfrom($this->analyselinkfrom($art)); + $page->setlinkfrom($this->analyselinkfrom($page)); - $artlist = $this->getlister(); - $art->setlinkto($this->analyselinkto($art->id(), $artlist)); + $pagelist = $this->getlister(); + $page->setlinkto($this->analyselinkto($page->id(), $pagelist)); - return $art; + return $page; } - public function analyselinkto($id, $artlist) + public function analyselinkto($id, $pagelist) { - //analyse les liens vers cet article en fouillant tout les linkfrom de la bdd, génere un tableau à stocker dans l'article + //analyse les liens vers cet pageicle en fouillant tout les linkfrom de la bdd, génere un tableau à stocker dans l'pageicle $linkto = []; - foreach ($artlist as $link) { + foreach ($pagelist as $link) { if (in_array($id, $link->linkfrom('array')) && $id != $link->id()) { $linkto[] = $link->id(); } @@ -51,11 +51,11 @@ class Modelanalyse extends Modelart return $linkto; } - public function analyselinkfrom(Art2 $art) + public function analyselinkfrom(Page $page) { $linkfrom = []; foreach (self::TEXT_ELEMENTS as $element) { - preg_match_all('#\]\((\?id=|=)(\w+)\)#', $art->$element(), $out); + preg_match_all('#\]\((\?id=|=)(\w+)\)#', $page->$element(), $out); $linkfrom = array_merge($linkfrom, $out[2]); } return array_unique($linkfrom); diff --git a/app/class/modelart.php b/app/class/modelart.php deleted file mode 100644 index 8dee09c..0000000 --- a/app/class/modelart.php +++ /dev/null @@ -1,306 +0,0 @@ -<?php -class Modelart extends Modeldb -{ - - const SELECT = ['title', 'id', 'description', 'tag', 'date', 'datecreation', 'datemodif', 'daterender', 'css', 'quickcss', 'javascript', 'body', 'header', 'main', 'nav', 'aside', 'footer', 'render', 'secure', 'invitepassword', 'interface', 'linkfrom', 'linkto', 'template', 'affcount', 'editcount']; - const BY = ['datecreation', 'title', 'id', 'description', 'datemodif', 'secure']; - const ORDER = ['DESC', 'ASC']; - - - public function __construct() - { - parent::__construct(); - $this->storeinit(Config::arttable()); - if(!$this->dircheck(Model::HTML_RENDER_DIR)) { - throw new Exception("Media error : Cant create /rendernew folder"); - } - } - - /** - * Scan library for all pages as objects - * - * @return array of Pages objects - */ - public function getlister() - { - $artlist = []; - $list = $this->repo->findAll(); - foreach ($list as $artdata) { - $artlist[$artdata->id] = new Art2($artdata); - } - return $artlist; - } - - - public function getlisterid(array $idlist = []) - { - $artdatalist = $this->repo->query() - ->where('__id', 'IN', $idlist) - ->execute(); - - $artlist = []; - foreach ($artdatalist as $id => $artdata) { - $artlist[$id] = new Art2($artdata); - } - return $artlist; - } - - public function add(Art2 $art) - { - - $artdata = new \JamesMoss\Flywheel\Document($art->dry()); - $artdata->setId($art->id()); - $this->repo->store($artdata); - } - - /** - * Obtain a page object from the database - * - * @param Art2|string $id could be an Art2 object or a id string - * - * @return Art2|false The Art2 object or false if it does not exist. - */ - public function get($id) - { - if ($id instanceof Art2) { - $id = $id->id(); - } - if (is_string($id)) { - $artdata = $this->repo->findById($id); - if ($artdata !== false) { - return new Art2($artdata); - } else { - return false; - } - } else { - return false; - } - } - - /** - * Transform File to Art2 Oject - * - * @return false|Art2 - */ - public function getfromfile() - { - if(!isset($_FILES['pagefile']) || $_FILES['pagefile']['error'] > 0 ) return false; - - $ext = substr(strrchr($_FILES['pagefile']['name'],'.'),1); - if($ext !== 'json') return false; - - $files = $_FILES; - - $json = file_get_contents($_FILES['pagefile']['tmp_name']); - $pagedata = json_decode($json, true); - - if($pagedata === false) return false; - - $page = new Art2($pagedata); - - return $page; - - } - - public function getartelement($id, $element) - { - if (in_array($element, Model::TEXT_ELEMENTS)) { - $art = $this->get($id); - if ($art !== false) { - return $art->$element(); - } else { - return false; - } - } - } - - public function delete(Art2 $art) - { - $this->repo->delete($art->id()); - $this->unlink($art->id()); - } - - - public function unlink(string $artid) - { - $files = ['.css', '.quick.css', '.js']; - foreach ($files as $file) { - if (file_exists(Model::RENDER_DIR . $artid . $file)) { - unlink(Model::RENDER_DIR . $artid . $file); - } - } - if(file_exists(Model::HTML_RENDER_DIR . $artid . '.html')) { - unlink(Model::HTML_RENDER_DIR . $artid . '.html'); - } - } - - public function update(Art2 $art) - { - $artdata = new \JamesMoss\Flywheel\Document($art->dry()); - $artdata->setId($art->id()); - $this->repo->store($artdata); - } - - public function combine(Art2 $arta, Art2 $artb) - { - $mergeart = $arta; - $merge = []; - $diff = []; - foreach ($arta::TABS as $element) { - if($arta->$element() !== $artb->$element()) { - $merge[$element] = compare($arta->$element(), $artb->$element()); - $diff[] = $element; - } - } - $mergeart->hydrate($merge); - - return ['diff' => $diff, 'mergeart' => $mergeart]; - } - - // public function diffartelement(Art2 $arta, Art2 $artb) - // { - // $diff = []; - // foreach ($arta::TABS as $element) { - // if($arta->$element() !== $artb->$element()) { - // $diff[] = $element; - // } - // } - // return $diff; - // } - - public function artcompare($art1, $art2, $method = 'id', $order = 1) - { - $result = ($art1->$method('sort') <=> $art2->$method('sort')); - return $result * $order; - } - - public function buildsorter($sortby, $order) - { - return function ($art1, $art2) use ($sortby, $order) { - $result = $this->artcompare($art1, $art2, $sortby, $order); - return $result; - }; - } - - - - public function artlistsort(&$artlist, $sortby, $order = 1) - { - return usort($artlist, $this->buildsorter($sortby, $order)); - } - - - /** - * @param array $artlist List of Art2 - * @param array $tagchecked list of tags - * @param string $tagcompare string, can be 'OR' or 'AND', set the tag filter method - * @return array $array - */ - - public function filtertagfilter(array $artlist, array $tagchecked, $tagcompare = 'OR') - { - - $filteredlist = []; - foreach ($artlist as $art) { - if (empty($tagchecked)) { - $filteredlist[] = $art->id(); - } else { - $inter = (array_intersect($art->tag('array'), $tagchecked)); - if ($tagcompare == 'OR') { - if (!empty($inter)) { - $filteredlist[] = $art->id(); - } - } elseif ($tagcompare == 'AND') { - if (!array_diff($tagchecked, $art->tag('array'))) { - $filteredlist[] = $art->id(); - } - } - } - } - return $filteredlist; - } - - public function filterauthorfilter(array $artlist, array $authorchecked, $authorcompare = 'OR') - { - - $filteredlist = []; - foreach ($artlist as $art) { - if (empty($authorchecked)) { - $filteredlist[] = $art->id(); - } else { - $inter = (array_intersect($art->authors('array'), $authorchecked)); - if ($authorcompare == 'OR') { - if (!empty($inter)) { - $filteredlist[] = $art->id(); - } - } elseif ($authorcompare == 'AND') { - if (!array_diff($authorchecked, $art->authors('array'))) { - $filteredlist[] = $art->id(); - } - } - } - } - return $filteredlist; - } - - public function filtersecure(array $artlist, $secure) - { - $filteredlist = []; - foreach ($artlist as $art) { - if ($art->secure() == intval($secure)) { - $filteredlist[] = $art->id(); - } elseif (intval($secure) >= 4) { - $filteredlist[] = $art->id(); - } - } - return $filteredlist; - } - - - public function tag(array $artlist, $tagchecked) - { - $artcheckedlist = []; - foreach ($artlist as $art) { - if (in_array($tagchecked, $art->tag('array'))) { - $artcheckedlist[] = $art; - } - } - return $artcheckedlist; - } - - public function taglist(array $artlist, array $tagcheckedlist) - { - $taglist = []; - foreach ($tagcheckedlist as $tag) { - $taglist[$tag] = $this->tag($artlist, $tag); - } - return $taglist; - } - - /** - * @param array $taglist list of tags - * @param array $artlist list of Art2 - * @return array list of tags each containing list of id - */ - - public function tagartlist(array $taglist, array $artlist) - { - $tagartlist = []; - foreach ($taglist as $tag) { - $tagartlist[$tag] = $this->filtertagfilter($artlist, [$tag]); - } - return $tagartlist; - } - - public function lasteditedartlist(int $last, array $artlist) - { - $this->artlistsort($artlist, 'datemodif', -1); - $artlist = array_slice($artlist, 0, $last); - $idlist = []; - foreach ($artlist as $art) { - $idlist[] = $art->id(); - } - return $idlist; - } - -} diff --git a/app/class/modelhome.php b/app/class/modelhome.php index 1154e78..d90a3d3 100644 --- a/app/class/modelhome.php +++ b/app/class/modelhome.php @@ -1,6 +1,6 @@ <?php -class Modelhome extends Modelart +class Modelhome extends Modelpage { public function __construct() { @@ -10,7 +10,7 @@ class Modelhome extends Modelart public function optinit($table) { - $opt = new Opt(Art2::classvarlist()); + $opt = new Opt(Page::classvarlist()); $opt->setcol(['id', 'tag', 'linkfrom', 'linkto', 'description', 'title', 'datemodif', 'datecreation', 'date', 'secure', 'visitcount', 'editcount', 'affcount']); $opt->settaglist($table); $opt->setauthorlist($table); @@ -28,7 +28,7 @@ class Modelhome extends Modelart */ public function Optlistinit(array $table) { - $optlist = new Optlist(Art2::classvarlist()); + $optlist = new Optlist(Page::classvarlist()); $optlist->settaglist($table); $optlist->setauthorlist($table); @@ -53,11 +53,11 @@ class Modelhome extends Modelart $filter = array_intersect($filtertagfilter, $filtersecure, $filterauthorfilter); $table2 = []; $table2invert = []; - foreach ($table as $art) { - if (in_array($art->id(), $filter)) { - $table2[] = $art; + foreach ($table as $page) { + if (in_array($page->id(), $filter)) { + $table2[] = $page; } else { - $table2invert[] = $art; + $table2invert[] = $page; } @@ -67,7 +67,7 @@ class Modelhome extends Modelart $table2 = $table2invert; } - $this->artlistsort($table2, $opt->sortby(), $opt->order()); + $this->pagelistsort($table2, $opt->sortby(), $opt->order()); if($opt->limit() !== 0) { $table2 = array_slice($table2, 0, $opt->limit()); diff --git a/app/class/modelpage.php b/app/class/modelpage.php new file mode 100644 index 0000000..a47ebdb --- /dev/null +++ b/app/class/modelpage.php @@ -0,0 +1,306 @@ +<?php +class Modelpage extends Modeldb +{ + + const SELECT = ['title', 'id', 'description', 'tag', 'date', 'datecreation', 'datemodif', 'daterender', 'css', 'quickcss', 'javascript', 'body', 'header', 'main', 'nav', 'aside', 'footer', 'render', 'secure', 'invitepassword', 'interface', 'linkfrom', 'linkto', 'template', 'affcount', 'editcount']; + const BY = ['datecreation', 'title', 'id', 'description', 'datemodif', 'secure']; + const ORDER = ['DESC', 'ASC']; + + + public function __construct() + { + parent::__construct(); + $this->storeinit(Config::pagetable()); + if(!$this->dircheck(Model::HTML_RENDER_DIR)) { + throw new Exception("Media error : Cant create /rendernew folder"); + } + } + + /** + * Scan library for all pages as objects + * + * @return array of Pages objects + */ + public function getlister() + { + $pagelist = []; + $list = $this->repo->findAll(); + foreach ($list as $pagedata) { + $pagelist[$pagedata->id] = new Page($pagedata); + } + return $pagelist; + } + + + public function getlisterid(array $idlist = []) + { + $pagedatalist = $this->repo->query() + ->where('__id', 'IN', $idlist) + ->execute(); + + $pagelist = []; + foreach ($pagedatalist as $id => $pagedata) { + $pagelist[$id] = new Page($pagedata); + } + return $pagelist; + } + + public function add(Page $page) + { + + $pagedata = new \JamesMoss\Flywheel\Document($page->dry()); + $pagedata->setId($page->id()); + $this->repo->store($pagedata); + } + + /** + * Obtain a page object from the database + * + * @param Page|string $id could be an Page object or a id string + * + * @return Page|false The Page object or false if it does not exist. + */ + public function get($id) + { + if ($id instanceof Page) { + $id = $id->id(); + } + if (is_string($id)) { + $pagedata = $this->repo->findById($id); + if ($pagedata !== false) { + return new Page($pagedata); + } else { + return false; + } + } else { + return false; + } + } + + /** + * Transform File to Page Oject + * + * @return false|Page + */ + public function getfromfile() + { + if(!isset($_FILES['pagefile']) || $_FILES['pagefile']['error'] > 0 ) return false; + + $ext = substr(strrchr($_FILES['pagefile']['name'],'.'),1); + if($ext !== 'json') return false; + + $files = $_FILES; + + $json = file_get_contents($_FILES['pagefile']['tmp_name']); + $pagedata = json_decode($json, true); + + if($pagedata === false) return false; + + $page = new Page($pagedata); + + return $page; + + } + + public function getpageelement($id, $element) + { + if (in_array($element, Model::TEXT_ELEMENTS)) { + $page = $this->get($id); + if ($page !== false) { + return $page->$element(); + } else { + return false; + } + } + } + + public function delete(Page $page) + { + $this->repo->delete($page->id()); + $this->unlink($page->id()); + } + + + public function unlink(string $pageid) + { + $files = ['.css', '.quick.css', '.js']; + foreach ($files as $file) { + if (file_exists(Model::RENDER_DIR . $pageid . $file)) { + unlink(Model::RENDER_DIR . $pageid . $file); + } + } + if(file_exists(Model::HTML_RENDER_DIR . $pageid . '.html')) { + unlink(Model::HTML_RENDER_DIR . $pageid . '.html'); + } + } + + public function update(Page $page) + { + $pagedata = new \JamesMoss\Flywheel\Document($page->dry()); + $pagedata->setId($page->id()); + $this->repo->store($pagedata); + } + + public function combine(Page $pagea, Page $pageb) + { + $mergepage = $pagea; + $merge = []; + $diff = []; + foreach ($pagea::TABS as $element) { + if($pagea->$element() !== $pageb->$element()) { + $merge[$element] = compare($pagea->$element(), $pageb->$element()); + $diff[] = $element; + } + } + $mergepage->hydrate($merge); + + return ['diff' => $diff, 'mergepage' => $mergepage]; + } + + // public function diffpageelement(Page $pagea, Page $pageb) + // { + // $diff = []; + // foreach ($pagea::TABS as $element) { + // if($pagea->$element() !== $pageb->$element()) { + // $diff[] = $element; + // } + // } + // return $diff; + // } + + public function pagecompare($page1, $page2, $method = 'id', $order = 1) + { + $result = ($page1->$method('sort') <=> $page2->$method('sort')); + return $result * $order; + } + + public function buildsorter($sortby, $order) + { + return function ($page1, $page2) use ($sortby, $order) { + $result = $this->pagecompare($page1, $page2, $sortby, $order); + return $result; + }; + } + + + + public function pagelistsort(&$pagelist, $sortby, $order = 1) + { + return usort($pagelist, $this->buildsorter($sortby, $order)); + } + + + /** + * @param array $pagelist List of Page + * @param array $tagchecked list of tags + * @param string $tagcompare string, can be 'OR' or 'AND', set the tag filter method + * @return array $array + */ + + public function filtertagfilter(array $pagelist, array $tagchecked, $tagcompare = 'OR') + { + + $filteredlist = []; + foreach ($pagelist as $page) { + if (empty($tagchecked)) { + $filteredlist[] = $page->id(); + } else { + $inter = (array_intersect($page->tag('array'), $tagchecked)); + if ($tagcompare == 'OR') { + if (!empty($inter)) { + $filteredlist[] = $page->id(); + } + } elseif ($tagcompare == 'AND') { + if (!array_diff($tagchecked, $page->tag('array'))) { + $filteredlist[] = $page->id(); + } + } + } + } + return $filteredlist; + } + + public function filterauthorfilter(array $pagelist, array $authorchecked, $authorcompare = 'OR') + { + + $filteredlist = []; + foreach ($pagelist as $page) { + if (empty($authorchecked)) { + $filteredlist[] = $page->id(); + } else { + $inter = (array_intersect($page->authors('array'), $authorchecked)); + if ($authorcompare == 'OR') { + if (!empty($inter)) { + $filteredlist[] = $page->id(); + } + } elseif ($authorcompare == 'AND') { + if (!array_diff($authorchecked, $page->authors('array'))) { + $filteredlist[] = $page->id(); + } + } + } + } + return $filteredlist; + } + + public function filtersecure(array $pagelist, $secure) + { + $filteredlist = []; + foreach ($pagelist as $page) { + if ($page->secure() == intval($secure)) { + $filteredlist[] = $page->id(); + } elseif (intval($secure) >= 4) { + $filteredlist[] = $page->id(); + } + } + return $filteredlist; + } + + + public function tag(array $pagelist, $tagchecked) + { + $pagecheckedlist = []; + foreach ($pagelist as $page) { + if (in_array($tagchecked, $page->tag('array'))) { + $pagecheckedlist[] = $page; + } + } + return $pagecheckedlist; + } + + public function taglist(array $pagelist, array $tagcheckedlist) + { + $taglist = []; + foreach ($tagcheckedlist as $tag) { + $taglist[$tag] = $this->tag($pagelist, $tag); + } + return $taglist; + } + + /** + * @param array $taglist list of tags + * @param array $pagelist list of Page + * @return array list of tags each containing list of id + */ + + public function tagpagelist(array $taglist, array $pagelist) + { + $tagpagelist = []; + foreach ($taglist as $tag) { + $tagpagelist[$tag] = $this->filtertagfilter($pagelist, [$tag]); + } + return $tagpagelist; + } + + public function lasteditedpagelist(int $last, array $pagelist) + { + $this->pagelistsort($pagelist, 'datemodif', -1); + $pagelist = array_slice($pagelist, 0, $last); + $idlist = []; + foreach ($pagelist as $page) { + $idlist[] = $page->id(); + } + return $idlist; + } + +} diff --git a/app/class/modelrender.php b/app/class/modelrender.php index d74ddec..237d9b5 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -1,11 +1,11 @@ <?php -class Modelrender extends Modelart +class Modelrender extends Modelpage { protected $router; - /** @var art2 */ - protected $art; - protected $artlist; + /** @var page2 */ + protected $page; + protected $pagelist; protected $linkfrom = []; protected $sum = []; protected $internallinkblank = ''; @@ -20,7 +20,7 @@ class Modelrender extends Modelart parent::__construct(); $this->router = $router; - $this->artlist = $this->getlister(); + $this->pagelist = $this->getlister(); if(Config::internallinkblank()) { $this->internallinkblank = ' target="_blank" '; @@ -31,20 +31,20 @@ class Modelrender extends Modelart } } - public function uart($id) + public function upage($id) { - return $this->router->generate('artread/', ['art' => $id]); + return $this->router->generate('pageread/', ['page' => $id]); } /** * Main function * - * @param Art2 $art page to render + * @param Page $page page to render */ - public function render(Art2 $art) + public function render(Page $page) { - $this->art = $art; + $this->page = $page; $this->write($this->gethmtl()); } @@ -69,17 +69,17 @@ class Modelrender extends Modelart public function readbody() { - if (!empty($this->art->templatebody())) { - $templateid = $this->art->templatebody(); - $templateart = $this->get($templateid); - if($templateart !== false) { - $body = $templateart->body(); + if (!empty($this->page->templatebody())) { + $templateid = $this->page->templatebody(); + $templatepage = $this->get($templateid); + if($templatepage !== false) { + $body = $templatepage->body(); } else { - $body = $this->art->body(); - $this->art->settemplatebody(''); + $body = $this->page->body(); + $this->page->settemplatebody(''); } } else { - $body = $this->art->body(); + $body = $this->page->body(); } $body = $this->article($body); $body = $this->automedialist($body); @@ -115,7 +115,7 @@ class Modelrender extends Modelart // First, analyse the synthax and call the corresponding methods if(isset($matches)) { foreach ($matches as $key => $match) { - $element = new Element($match, $this->art->id()); + $element = new Element($match, $this->page->id()); $element->setcontent($this->getelementcontent($element)); $element->setcontent($this->elementparser($element)); $element->addtags(); @@ -136,8 +136,8 @@ class Modelrender extends Modelart $subseparator = PHP_EOL . PHP_EOL; foreach($element->sources() as $source) { - if($source !== $this->art->id()) { - $subcontent = $this->getartelement($source, $element->type()); + if($source !== $this->page->id()) { + $subcontent = $this->getpageelement($source, $element->type()); if($subcontent !== false) { if(empty($subcontent && self::RENDER_VERBOSE > 0)) { $subcontent = PHP_EOL . '<!-- The ' . strtoupper($element->type()) . ' from page "' . $source . '" is currently empty ! -->' . PHP_EOL; @@ -149,7 +149,7 @@ class Modelrender extends Modelart } else { $type = $element->type(); - $subcontent = $this->art->$type(); + $subcontent = $this->page->$type(); } $content .= $subseparator . $subcontent; } @@ -183,27 +183,27 @@ class Modelrender extends Modelart */ public function write(string $html) { - file_put_contents(Model::HTML_RENDER_DIR . $this->art->id() . '.html', $html); - file_put_contents(Model::RENDER_DIR . $this->art->id() . '.css', $this->art->css()); - //file_put_contents(Model::RENDER_DIR . $this->art->id() . '.quick.css', $this->art->quickcss()); - file_put_contents(Model::RENDER_DIR . $this->art->id() . '.js', $this->art->javascript()); + file_put_contents(Model::HTML_RENDER_DIR . $this->page->id() . '.html', $html); + file_put_contents(Model::RENDER_DIR . $this->page->id() . '.css', $this->page->css()); + //file_put_contents(Model::RENDER_DIR . $this->page->id() . '.quick.css', $this->page->quickcss()); + file_put_contents(Model::RENDER_DIR . $this->page->id() . '.js', $this->page->javascript()); } public function writetemplates() { - if (array_key_exists('css', $this->art->template('array'))) { - $tempaltecssart = $this->get($this->art->template('array')['css']); - file_put_contents(Model::RENDER_DIR . $tempaltecssart->id() . '.css', $tempaltecssart->css()); + if (array_key_exists('css', $this->page->template('array'))) { + $tempaltecsspage = $this->get($this->page->template('array')['css']); + file_put_contents(Model::RENDER_DIR . $tempaltecsspage->id() . '.css', $tempaltecsspage->css()); } - if (array_key_exists('quickcss', $this->art->template('array'))) { - $tempaltequickcssart = $this->get($this->art->template('array')['quickcss']); - file_put_contents(Model::RENDER_DIR . $tempaltequickcssart->id() . '.quick.css', $tempaltequickcssart->quickcss()); + if (array_key_exists('quickcss', $this->page->template('array'))) { + $tempaltequickcsspage = $this->get($this->page->template('array')['quickcss']); + file_put_contents(Model::RENDER_DIR . $tempaltequickcsspage->id() . '.quick.css', $tempaltequickcsspage->quickcss()); } - if (array_key_exists('javascript', $this->art->template('array'))) { - $templatejsart = $this->get($this->art->template('array')['javascript']); - file_put_contents(Model::RENDER_DIR . $templatejsart->id() . '.js', $templatejsart->javascript()); + if (array_key_exists('javascript', $this->page->template('array'))) { + $templatejspage = $this->get($this->page->template('array')['javascript']); + file_put_contents(Model::RENDER_DIR . $templatejspage->id() . '.js', $templatejspage->javascript()); } } @@ -216,32 +216,32 @@ class Modelrender extends Modelart $head = ''; $head .= '<meta charset="utf8" />' . PHP_EOL; - $head .= '<title>' . $this->art->title() . '</title>' . PHP_EOL; - if (!empty($this->art->favicon())) { - $head .= '<link rel="shortcut icon" href="' . Model::faviconpath() . $this->art->favicon() . '" type="image/x-icon">'; + $head .= '<title>' . $this->page->title() . '</title>' . PHP_EOL; + if (!empty($this->page->favicon())) { + $head .= '<link rel="shortcut icon" href="' . Model::faviconpath() . $this->page->favicon() . '" type="image/x-icon">'; } elseif (!empty(Config::defaultfavicon())) { $head .= '<link rel="shortcut icon" href="' . Model::faviconpath() . Config::defaultfavicon() . '" type="image/x-icon">'; } - $head .= '<meta name="description" content="' . $this->art->description() . '" />' . PHP_EOL; + $head .= '<meta name="description" content="' . $this->page->description() . '" />' . PHP_EOL; $head .= '<meta name="viewport" content="width=device-width" />' . PHP_EOL; - $head .= '<meta property="og:title" content="' . $this->art->title() . '">' . PHP_EOL; - $head .= '<meta property="og:description" content="' . $this->art->description() . '">' . PHP_EOL; + $head .= '<meta property="og:title" content="' . $this->page->title() . '">' . PHP_EOL; + $head .= '<meta property="og:description" content="' . $this->page->description() . '">' . PHP_EOL; - if($this->art->thumbnailexist()) { - $head .= '<meta property="og:image" content="' . Config::domain() . self::thumbnailpath() . $this->art->id() . '.jpg">' . PHP_EOL; + if($this->page->thumbnailexist()) { + $head .= '<meta property="og:image" content="' . Config::domain() . self::thumbnailpath() . $this->page->id() . '.jpg">' . PHP_EOL; } - $head .= '<meta property="og:url" content="' . Config::url() . $this->art->id() . '/">' . PHP_EOL; + $head .= '<meta property="og:url" content="' . Config::url() . $this->page->id() . '/">' . PHP_EOL; - foreach ($this->art->externalcss() as $externalcss) { + foreach ($this->page->externalcss() as $externalcss) { $head .= '<link href="' . $externalcss . '" rel="stylesheet" />' . PHP_EOL; } - if (!empty($this->art->templatecss() && in_array('externalcss', $this->art->templateoptions()))) { - $templatecss = $this->get($this->art->templatecss()); + if (!empty($this->page->templatecss() && in_array('externalcss', $this->page->templateoptions()))) { + $templatecss = $this->get($this->page->templatecss()); if($templatecss !== false) { foreach ($templatecss->externalcss() as $externalcss) { @@ -250,24 +250,24 @@ class Modelrender extends Modelart } } - $head .= PHP_EOL . $this->art->customhead() . PHP_EOL; + $head .= PHP_EOL . $this->page->customhead() . PHP_EOL; $head .= '<link href="' . Model::globalpath() . 'fonts.css" rel="stylesheet" />' . PHP_EOL; $head .= '<link href="' . Model::globalpath() . 'global.css" rel="stylesheet" />' . PHP_EOL; - if (!empty($this->art->templatecss())) { - $tempaltecssart = $this->art->templatecss(); - $head .= '<link href="' . Model::renderpath() . $tempaltecssart . '.css" rel="stylesheet" />' . PHP_EOL; + if (!empty($this->page->templatecss())) { + $tempaltecsspage = $this->page->templatecss(); + $head .= '<link href="' . Model::renderpath() . $tempaltecsspage . '.css" rel="stylesheet" />' . PHP_EOL; } - $head .= '<link href="' . Model::renderpath() . $this->art->id() . '.css" rel="stylesheet" />' . PHP_EOL; + $head .= '<link href="' . Model::renderpath() . $this->page->id() . '.css" rel="stylesheet" />' . PHP_EOL; - if (!empty($this->art->templatejavascript())) { - $templatejsart = $this->art->templatejavascript(); - $head .= '<script src="' . Model::renderpath() . $templatejsart . '.js" async/></script>' . PHP_EOL; + if (!empty($this->page->templatejavascript())) { + $templatejspage = $this->page->templatejavascript(); + $head .= '<script src="' . Model::renderpath() . $templatejspage . '.js" async/></script>' . PHP_EOL; } - if (!empty($this->art->javascript())) { - $head .= '<script src="' . Model::renderpath() . $this->art->id() . '.js" async/></script>' . PHP_EOL; + if (!empty($this->page->javascript())) { + $head .= '<script src="' . Model::renderpath() . $this->page->id() . '.js" async/></script>' . PHP_EOL; } if (!empty(Config::analytics())) { @@ -308,7 +308,7 @@ class Modelrender extends Modelart $text = $this->wurl($text); $text = $this->wikiurl($text); - $text = $this->desctitle($text, $this->art->description(), $this->art->title()); + $text = $this->desctitle($text, $this->page->description(), $this->page->title()); $text = str_replace('href="http', ' class="external" target="_blank" href="http', $text); @@ -343,12 +343,12 @@ class Modelrender extends Modelart $text = preg_replace_callback( '%href="([\w-]+)\/?(#?[a-z-_]*)"%', function ($matches) use ($rend, &$linkfrom) { - $matchart = $rend->get($matches[1]); - if (!$matchart) { - $link = 'href="' . $rend->uart($matches[1]) . '"" title="' . Config::existnot() . '" class="internal existnot"' . $this->internallinkblank; + $matchpage = $rend->get($matches[1]); + if (!$matchpage) { + $link = 'href="' . $rend->upage($matches[1]) . '"" title="' . Config::existnot() . '" class="internal existnot"' . $this->internallinkblank; } else { - $linkfrom[] = $matchart->id(); - $link = 'href="' . $rend->uart($matches[1]) . $matches[2] . '" title="' . $matchart->description() . '" class="internal exist '. $matchart->secure('string') .'"' . $this->internallinkblank; + $linkfrom[] = $matchpage->id(); + $link = 'href="' . $rend->upage($matches[1]) . $matches[2] . '" title="' . $matchpage->description() . '" class="internal exist '. $matchpage->secure('string') .'"' . $this->internallinkblank; } return $link; }, @@ -365,12 +365,12 @@ class Modelrender extends Modelart $text = preg_replace_callback( '%\[([\w-]+)\/?#?([a-z-_]*)\]%', function ($matches) use ($rend, &$linkfrom) { - $matchart = $rend->get($matches[1]); - if (!$matchart) { - return '<a href="' . $rend->uart($matches[1]) . '"" title="' . Config::existnot() . '" class="internal existnot" '. $this->internallinkblank .' >' . $matches[1] . '</a>'; + $matchpage = $rend->get($matches[1]); + if (!$matchpage) { + return '<a href="' . $rend->upage($matches[1]) . '"" title="' . Config::existnot() . '" class="internal existnot" '. $this->internallinkblank .' >' . $matches[1] . '</a>'; } else { - $linkfrom[] = $matchart->id(); - return '<a href="' . $rend->uart($matches[1]) . $matches[2] . '" title="' . $matchart->description() . '" class="internal exist '. $matchart->secure('string') .'" '. $this->internallinkblank .' >' . $matchart->title() . '</a>'; + $linkfrom[] = $matchpage->id(); + return '<a href="' . $rend->upage($matches[1]) . $matches[2] . '" title="' . $matchpage->description() . '" class="internal exist '. $matchpage->secure('string') .'" '. $this->internallinkblank .' >' . $matchpage->title() . '</a>'; } }, $text @@ -499,21 +499,21 @@ class Modelrender extends Modelart $taglist = $this->autotaglist($text); foreach ($taglist as $tag) { $li = []; - foreach ($this->artlist as $item) { + foreach ($this->pagelist as $item) { if (in_array($tag, $item->tag('array'))) { $li[] = $item; } } $ul = '<ul class="taglist" id="' . $tag . '">' . PHP_EOL; - $this->artlistsort($li, 'date', -1); + $this->pagelistsort($li, 'date', -1); foreach ($li as $item) { - if ($item->id() === $this->art->id()) { + if ($item->id() === $this->page->id()) { $actual = ' actualpage'; } else { $actual = ''; } - $ul .= '<li><a href="' . $this->router->generate('artread/', ['art' => $item->id()]) . '" title="' . $item->description() . '" class="internal' . $actual . '" '. $this->internallinkblank .' >' . $item->title() . '</a></li>' . PHP_EOL; + $ul .= '<li><a href="' . $this->router->generate('pageread/', ['page' => $item->id()]) . '" title="' . $item->description() . '" class="internal' . $actual . '" '. $this->internallinkblank .' >' . $item->title() . '</a></li>' . PHP_EOL; } $ul .= '</ul>' . PHP_EOL; @@ -531,12 +531,12 @@ class Modelrender extends Modelart public function date(string $text) { - $art = $this->art; - $text = preg_replace_callback('~\%DATE\%~', function ($matches) use ($art) { - return '<time datetime=' . $art->date('string') . '>' . $art->date('dmy') . '</time>'; + $page = $this->page; + $text = preg_replace_callback('~\%DATE\%~', function ($matches) use ($page) { + return '<time datetime=' . $page->date('string') . '>' . $page->date('dmy') . '</time>'; }, $text); - $text = preg_replace_callback('~\%TIME\%~', function ($matches) use ($art) { - return '<time datetime=' . $art->date('string') . '>' . $art->date('ptime') . '</time>'; + $text = preg_replace_callback('~\%TIME\%~', function ($matches) use ($page) { + return '<time datetime=' . $page->date('string') . '>' . $page->date('ptime') . '</time>'; }, $text); return $text; @@ -551,7 +551,7 @@ class Modelrender extends Modelart */ public function thumbnail(string $text) : string { - $img = '<img class="thumbnail" src="' . Model::thumbnailpath() . $this->art->id() . '.jpg" alt="' . $this->art->title() . '">'; + $img = '<img class="thumbnail" src="' . Model::thumbnailpath() . $this->page->id() . '.jpg" alt="' . $this->page->title() . '">'; $img = PHP_EOL . $img . PHP_EOL; $text = str_replace('%THUMBNAIL%', $img, $text); @@ -592,7 +592,7 @@ class Modelrender extends Modelart */ public function authenticate(string $text) { - $id = $this->art->id(); + $id = $this->page->id(); $regex = '~\%CONNECT(\?dir=([a-zA-Z0-9-_]+))?\%~'; $text = preg_replace_callback($regex, function ($matches) use ($id) { if(isset($matches[2])) { @@ -600,7 +600,7 @@ class Modelrender extends Modelart } $form = '<form action="/!co" method="post"> <input type="password" name="pass" id="loginpass" placeholder="password"> - <input type="hidden" name="route" value="artread/"> + <input type="hidden" name="route" value="pageread/"> <input type="hidden" name="id" value="' . $id . '"> <input type="submit" name="log" value="login" id="button"> </form>'; @@ -625,14 +625,14 @@ class Modelrender extends Modelart if(isset($matches)) { foreach ($matches as $match) { - $optlist = $modelhome->Optlistinit($this->artlist); + $optlist = $modelhome->Optlistinit($this->pagelist); $optlist->parsehydrate($match['options']); - $table2 = $modelhome->table2($this->artlist, $optlist); + $table2 = $modelhome->table2($this->pagelist, $optlist); $content = '<ul>' . PHP_EOL ; foreach ($table2 as $page ) { $content .= '<li>' . PHP_EOL; - $content .= '<a href="' . $this->uart($page->id()) . '">' . $page->title() . '</a>' . PHP_EOL; + $content .= '<a href="' . $this->upage($page->id()) . '">' . $page->title() . '</a>' . PHP_EOL; if($optlist->description()) { $content .= '<em>' . $page->description() . '</em>' . PHP_EOL; } @@ -673,9 +673,9 @@ class Modelrender extends Modelart public function linkto() { $linkto = []; - foreach ($this->artlist as $art) { - if (in_array($this->art->id(), $art->linkfrom())) { - $linkto[] = $art->id(); + foreach ($this->pagelist as $page) { + if (in_array($this->page->id(), $page->linkfrom())) { + $linkto[] = $page->id(); } } return $linkto; diff --git a/app/class/modeltimeline.php b/app/class/modeltimeline.php index b575dda..fa4f709 100644 --- a/app/class/modeltimeline.php +++ b/app/class/modeltimeline.php @@ -3,7 +3,7 @@ class Modeltimeline extends Modeldb { const EVENT_BASE = ['message']; - const EVENT_ART = ['art_add', 'art_edit', 'art_delete']; + const EVENT_ART = ['page_add', 'page_edit', 'page_delete']; const EVENT_MEDIA = ['media_add', 'media_delete']; const EVENT_FONT = ['font_add', 'font_delete']; diff --git a/app/class/opt.php b/app/class/opt.php index 1cfa299..bf732c5 100644 --- a/app/class/opt.php +++ b/app/class/opt.php @@ -16,7 +16,7 @@ class Opt protected $invert = 0; protected $limit= 0; - protected $artvarlist; + protected $pagevarlist; public function __construct(array $donnees = []) { @@ -131,7 +131,7 @@ class Opt { $class = get_class_vars(get_class($this)); $object = get_object_vars($this); - $class['artvarlist'] = $object['artvarlist']; + $class['pagevarlist'] = $object['pagevarlist']; $class['taglist'] = $object['taglist']; $class['authorlist'] = $object['authorlist']; $query = array_diff_assoc_recursive($object, $class); @@ -213,9 +213,9 @@ class Opt return $this->invert; } - public function artvarlist() + public function pagevarlist() { - return $this->artvarlist; + return $this->pagevarlist; } public function limit() @@ -228,7 +228,7 @@ class Opt public function setsortby($sortby) { - if (is_string($sortby) && in_array($sortby, $this->artvarlist)) { + if (is_string($sortby) && in_array($sortby, $this->pagevarlist)) { $this->sortby = strtolower(strip_tags($sortby)); } } @@ -321,15 +321,15 @@ class Opt public function setcol($col) { if (is_array($col)) { - $this->col = array_intersect($this->artvarlist(), $col); + $this->col = array_intersect($this->pagevarlist(), $col); } } - public function settaglist(array $artlist) + public function settaglist(array $pagelist) { $taglist = []; - foreach ($artlist as $art) { - foreach ($art->tag('array') as $tag) { + foreach ($pagelist as $page) { + foreach ($page->tag('array') as $tag) { if (!array_key_exists($tag, $taglist)) { $taglist[$tag] = 1; } else { @@ -341,11 +341,11 @@ class Opt $this->taglist = $taglist; } - public function setauthorlist(array $artlist) + public function setauthorlist(array $pagelist) { $authorlist = []; - foreach ($artlist as $art) { - foreach ($art->authors('array') as $author) { + foreach ($pagelist as $page) { + foreach ($page->authors('array') as $author) { if (!array_key_exists($author, $authorlist)) { $authorlist[$author] = 1; } else { @@ -378,8 +378,8 @@ class Opt } - public function setartvarlist(array $artvarlist) + public function setpagevarlist(array $pagevarlist) { - $this->artvarlist = $artvarlist; + $this->pagevarlist = $pagevarlist; } } diff --git a/app/class/art2.php b/app/class/page.php index 754ba14..299e448 100644 --- a/app/class/art2.php +++ b/app/class/page.php @@ -1,6 +1,6 @@ <?php -class Art2 +class Page { protected $id; protected $title; @@ -116,7 +116,7 @@ class Art2 foreach (get_class_vars(__class__) as $var => $default) { $classvarlist[] = $var; } - return ['artvarlist' => $classvarlist]; + return ['pagevarlist' => $classvarlist]; } public function dry() diff --git a/app/class/route.php b/app/class/route.php index cc2fe59..8e58945 100644 --- a/app/class/route.php +++ b/app/class/route.php @@ -28,7 +28,7 @@ class Route { $array = []; if (!empty($this->id)) { - $array[] = 'art'; + $array[] = 'page'; } if (!empty($this->aff)) { $array[] = 'aff='.$this->aff; diff --git a/app/class/routes.php b/app/class/routes.php index 4119e58..44f30bd 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -19,7 +19,7 @@ class Routes ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], ['GET', '//renderall', 'Controllerhome#renderall', 'homerenderall'], ['POST', '/bookmark', 'Controllerhome#bookmark', 'homebookmark'], - ['POST', '/upload', 'Controllerart#upload', 'artupload'], + ['POST', '/upload', 'Controllerpage#upload', 'pageupload'], ['POST', '/!co', 'Controllerconnect#log', 'log'], ['GET', '/!co', 'Controllerconnect#connect', 'connect'], ['POST', '/!search', 'Controllerhome#search', 'search'], @@ -41,19 +41,19 @@ class Routes ['GET', '/!timeline', 'Controllertimeline#desktop', 'timeline'], ['POST', '/!timeline/add', 'Controllertimeline#add', 'timelineadd'], ['POST', '/!timeline/clap', 'Controllertimeline#clap', 'timelineclap'], - ['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]/render', 'Controllerart#render', 'artrender'], - ['GET', '/[cid:art]/log', 'Controllerart#log', 'artlog'], - ['GET', '/[cid:art]/download', 'Controllerart#download', 'artdownload'], - ['POST', '/[cid:art]/edit', 'Controllerart#update', 'artupdate'], - ['POST', '/[cid:art]/editby', 'Controllerart#editby', 'arteditby'], - ['POST', '/[cid:art]/removeeditby', 'Controllerart#removeeditby', 'artremoveeditby'], - ['GET', '/[cid:art]/delete', 'Controllerart#confirmdelete', 'artconfirmdelete'], - ['POST', '/[cid:art]/delete', 'Controllerart#delete', 'artdelete'], - ['GET', '/[cid:art]/[*]', 'Controllerart#artdirect', 'artread/etoile'], + ['GET', '/[cid:page]/', 'Controllerpage#read', 'pageread/'], + ['GET', '/[cid:page]', 'Controllerpage#read', 'pageread'], + ['GET', '/[cid:page]/add', 'Controllerpage#add', 'pageadd'], + ['GET', '/[cid:page]/edit', 'Controllerpage#edit', 'pageedit'], + ['GET', '/[cid:page]/render', 'Controllerpage#render', 'pagerender'], + ['GET', '/[cid:page]/log', 'Controllerpage#log', 'pagelog'], + ['GET', '/[cid:page]/download', 'Controllerpage#download', 'pagedownload'], + ['POST', '/[cid:page]/edit', 'Controllerpage#update', 'pageupdate'], + ['POST', '/[cid:page]/editby', 'Controllerpage#editby', 'pageeditby'], + ['POST', '/[cid:page]/removeeditby', 'Controllerpage#removeeditby', 'pageremoveeditby'], + ['GET', '/[cid:page]/delete', 'Controllerpage#confirmdelete', 'pageconfirmdelete'], + ['POST', '/[cid:page]/delete', 'Controllerpage#delete', 'pagedelete'], + ['GET', '/[cid:page]/[*]', 'Controllerpage#pagedirect', 'pageread/etoile'], ]); $match = $router->match(); @@ -70,7 +70,7 @@ class Routes else { if(!empty(Config::route404())) { $controller = new Controller($router); - $controller->routedirect('artread/', ['art' => Config::route404()]); + $controller->routedirect('pageread/', ['page' => Config::route404()]); } else { header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); } |