From 0968351067f99e8afc882d4237902642e608e6f5 Mon Sep 17 00:00:00 2001
From: vincent-peugnet Set the name of the first folder that is going to store all your work';
if(!Config::checkbasepath()) {
echo '
';
@@ -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 = '
-
+
-
+
404 Error
';
- }
- }
-
- 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 @@
-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 @@
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 @@
+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 @@
-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 @@
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 @@
+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 @@
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 . '' . 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 .= '' . PHP_EOL;
- $head .= '' . 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 .= '
' . 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 '';
+ $page = $this->page;
+ $text = preg_replace_callback('~\%DATE\%~', function ($matches) use ($page) {
+ return '';
}, $text);
- $text = preg_replace_callback('~\%TIME\%~', function ($matches) use ($art) {
- return '';
+ $text = preg_replace_callback('~\%TIME\%~', function ($matches) use ($page) {
+ return '';
}, $text);
return $text;
@@ -551,7 +551,7 @@ class Modelrender extends Modelart
*/
public function thumbnail(string $text) : string
{
- $img = '';
+ $img = '
';
$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 = '
' . PHP_EOL ;
foreach ($table2 as $page ) {
$content .= '
= empty(Config::alertlinktext()) ? Config::alertlink() : Config::alertlinktext() ?>
+= empty(Config::alertlinktext()) ? Config::alertlink() : Config::alertlinktext() ?>
isadmin()) { diff --git a/app/view/templates/connect.php b/app/view/templates/connect.php index 82c01ec..dca4303 100644 --- a/app/view/templates/connect.php +++ b/app/view/templates/connect.php @@ -14,7 +14,7 @@