From e802d5204b96d645ec3d40b81b4a8bdc6e0ee675 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Mon, 4 Nov 2019 23:31:31 +0100 Subject: refactor: switch to psr-4 autoloading --- app/class/Application.php | 145 ++++++ app/class/Config.php | 465 +++++++++++++++++++ app/class/Controller.php | 105 +++++ app/class/Controlleradmin.php | 69 +++ app/class/Controllerconnect.php | 78 ++++ app/class/Controllerfont.php | 56 +++ app/class/Controllerhome.php | 130 ++++++ app/class/Controllerinfo.php | 27 ++ app/class/Controllermedia.php | 115 +++++ app/class/Controllerpage.php | 417 +++++++++++++++++ app/class/Controllertimeline.php | 58 +++ app/class/Controlleruser.php | 117 +++++ app/class/Dbitem.php | 34 ++ app/class/Element.php | 204 ++++++++ app/class/Event.php | 162 +++++++ app/class/Flywheel/Formatter/JSON.php | 21 + app/class/Flywheel/Predicate.php | 11 + app/class/Flywheel/Query.php | 16 + app/class/Flywheel/Repository.php | 30 ++ app/class/Media.php | 233 ++++++++++ app/class/Medialist.php | 155 +++++++ app/class/Model.php | 115 +++++ app/class/Modelanalyse.php | 73 +++ app/class/Modelconfig.php | 41 ++ app/class/Modeldb.php | 45 ++ app/class/Modelfont.php | 132 ++++++ app/class/Modelhome.php | 107 +++++ app/class/Modelmassedit.php | 0 app/class/Modelmedia.php | 320 +++++++++++++ app/class/Modelpage.php | 325 +++++++++++++ app/class/Modelrender.php | 693 ++++++++++++++++++++++++++++ app/class/Modeltimeline.php | 143 ++++++ app/class/Modeluser.php | 196 ++++++++ app/class/Opt.php | 388 ++++++++++++++++ app/class/Optlist.php | 115 +++++ app/class/Page.php | 820 +++++++++++++++++++++++++++++++++ app/class/Quickcss.php | 293 ++++++++++++ app/class/Record.php | 118 +++++ app/class/Route.php | 86 ++++ app/class/Routes.php | 82 ++++ app/class/User.php | 303 ++++++++++++ app/class/application.php | 144 ------ app/class/config.php | 464 ------------------- app/class/controller.php | 100 ---- app/class/controlleradmin.php | 67 --- app/class/controllerconnect.php | 76 --- app/class/controllerfont.php | 54 --- app/class/controllerhome.php | 128 ----- app/class/controllerinfo.php | 25 - app/class/controllermedia.php | 113 ----- app/class/controllerpage.php | 412 ----------------- app/class/controllertimeline.php | 56 --- app/class/controlleruser.php | 115 ----- app/class/dbitem.php | 32 -- app/class/element.php | 202 -------- app/class/event.php | 156 ------- app/class/media.php | 231 ---------- app/class/medialist.php | 153 ------ app/class/model.php | 112 ----- app/class/modelanalyse.php | 73 --- app/class/modelconfig.php | 39 -- app/class/modeldb.php | 37 -- app/class/modelfont.php | 130 ------ app/class/modelhome.php | 105 ----- app/class/modelmassedit.php | 0 app/class/modelmedia.php | 318 ------------- app/class/modelpage.php | 320 ------------- app/class/modelrender.php | 691 --------------------------- app/class/modeltimeline.php | 139 ------ app/class/modeluser.php | 192 -------- app/class/opt.php | 385 ---------------- app/class/optlist.php | 113 ----- app/class/page.php | 814 -------------------------------- app/class/quickcss.php | 291 ------------ app/class/record.php | 116 ----- app/class/route.php | 84 ---- app/class/routes.php | 79 ---- app/class/user.php | 298 ------------ app/class/wflywheel/formatter/json.php | 21 - app/class/wflywheel/predicate.php | 11 - app/class/wflywheel/query.php | 16 - app/class/wflywheel/repository.php | 30 -- app/fn/fn.php | 11 +- app/view/templates/admin.php | 58 +-- app/view/templates/alert.php | 26 +- app/view/templates/backtopbar.php | 14 +- app/view/templates/edit.php | 4 +- app/view/templates/editleftbar.php | 2 +- app/view/templates/edittopbar.php | 6 +- app/view/templates/home.php | 12 +- app/view/templates/homemenu.php | 6 +- app/view/templates/layout.php | 10 +- app/view/templates/media.php | 4 +- 93 files changed, 7115 insertions(+), 7023 deletions(-) create mode 100644 app/class/Application.php create mode 100644 app/class/Config.php create mode 100644 app/class/Controller.php create mode 100644 app/class/Controlleradmin.php create mode 100644 app/class/Controllerconnect.php create mode 100644 app/class/Controllerfont.php create mode 100644 app/class/Controllerhome.php create mode 100644 app/class/Controllerinfo.php create mode 100644 app/class/Controllermedia.php create mode 100644 app/class/Controllerpage.php create mode 100644 app/class/Controllertimeline.php create mode 100644 app/class/Controlleruser.php create mode 100644 app/class/Dbitem.php create mode 100644 app/class/Element.php create mode 100644 app/class/Event.php create mode 100644 app/class/Flywheel/Formatter/JSON.php create mode 100644 app/class/Flywheel/Predicate.php create mode 100644 app/class/Flywheel/Query.php create mode 100644 app/class/Flywheel/Repository.php create mode 100644 app/class/Media.php create mode 100644 app/class/Medialist.php create mode 100644 app/class/Model.php create mode 100644 app/class/Modelanalyse.php create mode 100644 app/class/Modelconfig.php create mode 100644 app/class/Modeldb.php create mode 100644 app/class/Modelfont.php create mode 100644 app/class/Modelhome.php create mode 100644 app/class/Modelmassedit.php create mode 100644 app/class/Modelmedia.php create mode 100644 app/class/Modelpage.php create mode 100644 app/class/Modelrender.php create mode 100644 app/class/Modeltimeline.php create mode 100644 app/class/Modeluser.php create mode 100644 app/class/Opt.php create mode 100644 app/class/Optlist.php create mode 100644 app/class/Page.php create mode 100644 app/class/Quickcss.php create mode 100644 app/class/Record.php create mode 100644 app/class/Route.php create mode 100644 app/class/Routes.php create mode 100644 app/class/User.php delete mode 100644 app/class/application.php delete mode 100644 app/class/config.php delete mode 100644 app/class/controller.php delete mode 100644 app/class/controlleradmin.php delete mode 100644 app/class/controllerconnect.php delete mode 100644 app/class/controllerfont.php delete mode 100644 app/class/controllerhome.php delete mode 100644 app/class/controllerinfo.php delete mode 100644 app/class/controllermedia.php delete mode 100644 app/class/controllerpage.php delete mode 100644 app/class/controllertimeline.php delete mode 100644 app/class/controlleruser.php delete mode 100644 app/class/dbitem.php delete mode 100644 app/class/element.php delete mode 100644 app/class/event.php delete mode 100644 app/class/media.php delete mode 100644 app/class/medialist.php delete mode 100644 app/class/model.php delete mode 100644 app/class/modelanalyse.php delete mode 100644 app/class/modelconfig.php delete mode 100644 app/class/modeldb.php delete mode 100644 app/class/modelfont.php delete mode 100644 app/class/modelhome.php delete mode 100644 app/class/modelmassedit.php delete mode 100644 app/class/modelmedia.php delete mode 100644 app/class/modelpage.php delete mode 100644 app/class/modelrender.php delete mode 100644 app/class/modeltimeline.php delete mode 100644 app/class/modeluser.php delete mode 100644 app/class/opt.php delete mode 100644 app/class/optlist.php delete mode 100644 app/class/page.php delete mode 100644 app/class/quickcss.php delete mode 100644 app/class/record.php delete mode 100644 app/class/route.php delete mode 100644 app/class/routes.php delete mode 100644 app/class/user.php delete mode 100644 app/class/wflywheel/formatter/json.php delete mode 100644 app/class/wflywheel/predicate.php delete mode 100644 app/class/wflywheel/query.php delete mode 100644 app/class/wflywheel/repository.php (limited to 'app') diff --git a/app/class/Application.php b/app/class/Application.php new file mode 100644 index 0000000..70c899f --- /dev/null +++ b/app/class/Application.php @@ -0,0 +1,145 @@ +usermanager = new Modeluser(); + } + + public function wakeup() + { + if(isset($_POST['configinit'])) { + if(Config::readconfig()) { + Config::createconfig($_POST['configinit']); + } else { + Config::hydrate($_POST['configinit']); + } + Config::getdomain(); + if(!is_dir(Model::RENDER_DIR)) { + mkdir(Model::RENDER_DIR); + } + if(!Config::savejson()) { + echo 'Cant write config file'; + exit; + } else{ + header('Location: ./'); + exit; + } + } elseif(isset($_POST['userinit']) && !empty($_POST['userinit']['id']) && !empty($_POST['userinit']['password'])) { + $userdata = $_POST['userinit']; + $userdata['level'] = 10; + $user = new User($userdata); + $this->usermanager->add($user); + header('Location: ./'); + exit; + + } else { + if(Config::readconfig()) { + if(!Config::checkbasepath() || empty(Config::pagetable()) || !is_dir(Model::RENDER_DIR) || !Config::checkdomain()) { + echo ''; + $this->configform(); + exit; + } else { + if($this->usermanager->admincount() === 0) { + echo 'missing admin user'; + $this->adminform(); + exit; + } + } + } else { + echo 'Missing config file'; + $this->configform(); + exit; + } + } + } + + public function configform() + { + ?> +

Configuration

+ +

Version :

+ +

+ +
+
+

+ +

+ +

Leave it empty if W-CMS is in your root folder, otherwise, indicate the subfolder(s) in witch you installed the CMS

+
+
+

+ +

+ +

Set the name of the first folder that is going to store all your work

+
+ +
+ + + +
+
+

+ +

+ +

Your user id as the first administrator.

+
+
+

+ +

+ +

Your user passworder as first administrator.

+
+ +
+ + \ No newline at end of file diff --git a/app/class/Config.php b/app/class/Config.php new file mode 100644 index 0000000..1a4bb17 --- /dev/null +++ b/app/class/Config.php @@ -0,0 +1,465 @@ + $value) { + $method = 'set' . $key; + if (method_exists(get_called_class(), $method)) { + self::$method($value); + } + } + } + + public static function readconfig() + { + if (file_exists(Model::CONFIG_FILE)) { + $current = file_get_contents(Model::CONFIG_FILE); + $datas = json_decode($current, true); + self::hydrate($datas); + return true; + } else { + return false; + } + } + + public static function createconfig(array $datas) + { + self::hydrate($datas); + } + + + public static function savejson() + { + $json = self::tojson(); + return file_put_contents(Model::CONFIG_FILE, $json); + } + + + public static function tojson() + { + $arr = get_class_vars(__class__); + $json = json_encode($arr, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT); + return $json; + } + + public static function checkbasepath() + { + $path = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . self::basepath() . DIRECTORY_SEPARATOR . Model::CONFIG_FILE; + return (file_exists($path)); + } + + /** + * Calculate Domain name + */ + public static function getdomain() + { + self::$domain = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']; + } + + /** + * Verify Domain name + */ + public static function checkdomain() + { + return (self::$domain === $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']); + } + + /** + * Generate full url adress where W is installed + * @return string url adress finished by a slash "/" + */ + public static function url($endslash = true) : string + { + return self::$domain . (!empty(self::$basepath) ? '/' . self::$basepath : "") . ($endslash ? '/' : ''); + } + +// ________________________________________ G E T _______________________________________ + + public static function pagetable() + { + return self::$pagetable; + } + + public static function domain() + { + return self::$domain; + } + + public static function fontsize() + { + return self::$fontsize; + } + + public static function basepath() + { + return self::$basepath; + } + + public static function route404() + { + return self::$route404; + } + + public static function alerttitle() + { + return self::$alerttitle; + } + + public static function alertlink() + { + return self::$alertlink; + } + + public static function alertlinktext() + { + return self::$alertlinktext; + } + + public static function existnot() + { + return self::$existnot; + } + + public static function private() + { + return self::$private; + } + + public static function notpublished() + { + return self::$notpublished; + } + + public static function existnotpass() + { + return self::$existnotpass; + } + + public static function privatepass() + { + return self::$privatepass; + } + + public static function notpublishedpass() + { + return self::$notpublishedpass; + } + + public static function alertcss() + { + return self::$alertcss; + } + + public static function defaultbody() + { + return self::$defaultbody; + } + + public static function defaultpage() + { + return self::$defaultpage; + } + + public static function defaultfavicon() + { + return self::$defaultfavicon; + } + + public static function analytics() + { + return self::$analytics; + } + + public static function externallinkblank() + { + return self::$externallinkblank; + } + + public static function internallinkblank() + { + return self::$internallinkblank; + } + + public static function reccursiverender() + { + return self::$reccursiverender; + } + + public static function defaultprivacy() + { + return self::$defaultprivacy; + } + + public static function homepage() + { + return self::$homepage; + } + + public static function homeredirect() + { + return self::$homeredirect; + } + + public static function interfacecss() + { + return self::$interfacecss; + } + + public static function bookmark() + { + return self::$bookmark; + } + + +// __________________________________________ S E T ______________________________________ + + public static function setpagetable($pagetable) + { + self::$pagetable = strip_tags($pagetable); + } + + public static function setdomain($domain) + { + self::$domain = strip_tags(strtolower($domain)); + } + + public static function setfontsize($fontsize) + { + $fontsize = intval($fontsize); + if ($fontsize > 1) { + self::$fontsize = $fontsize; + } + } + + public static function setbasepath($basepath) + { + self::$basepath = strip_tags($basepath); + } + + public static function setroute404($id) + { + if(is_string($id)) { + self::$route404 = idclean($id); + } + } + + public static function setalerttitle($alerttitle) + { + if(is_string($alerttitle)) { + self::$alerttitle = strip_tags($alerttitle); + } + } + + public static function setalertlink($alertlink) + { + if(is_string($alertlink)) { + self::$alertlink = idclean(strip_tags($alertlink)); + } + } + + public static function setalertlinktext($alertlinktext) + { + if(is_string($alertlinktext)) { + self::$alertlinktext = strip_tags($alertlinktext); + } + } + + public static function setexistnot($existnot) + { + if(is_string($existnot)) { + self::$existnot = strip_tags($existnot); + } + } + + public static function setprivate($private) + { + if(is_string($private)) { + self::$private = strip_tags($private); + } + } + + public static function setnotpublished($notpublished) + { + if(is_string($notpublished)) { + self::$notpublished = strip_tags($notpublished); + } + } + + public static function setexistnotpass($existnotpass) + { + self::$existnotpass = boolval($existnotpass); + } + + public static function setprivatepass($privatepass) + { + self::$privatepass = boolval($privatepass); + } + + public static function setnotpublishedpass($notpublishedpass) + { + self::$notpublishedpass = boolval($notpublishedpass); + } + + public static function setalertcss($alertcss) + { + self::$alertcss = boolval($alertcss); + } + + public static function setdefaultbody($defaultbody) + { + if(is_string($defaultbody)) { + self::$defaultbody = $defaultbody; + } + } + + public static function setdefaultfavicon($defaultfavicon) + { + if(is_string($defaultfavicon)) { + self::$defaultfavicon = $defaultfavicon; + } + } + + public static function setdefaultpage($defaultpage) + { + if(is_string($defaultpage)) { + self::$defaultpage = idclean($defaultpage); + } + } + + public static function setanalytics($analytics) + { + if(is_string($analytics) && strlen($analytics) < 25) { + self::$analytics = $analytics; + } + } + + public static function setexternallinkblank($externallinkblank) + { + self::$externallinkblank = boolval($externallinkblank); + } + + public static function setinternallinkblank($internallinkblank) + { + self::$internallinkblank = boolval($internallinkblank); + } + + public static function setreccursiverender($reccursiverender) + { + self::$reccursiverender = boolval($reccursiverender); + } + + public static function setdefaultprivacy($defaultprivacy) + { + $defaultprivacy = intval($defaultprivacy); + if($defaultprivacy >= 0 && $defaultprivacy <= 2) { + self::$defaultprivacy = $defaultprivacy; + } + } + + public static function sethomepage($homepage) + { + if(in_array($homepage, Model::HOMEPAGE)) { + self::$homepage = $homepage; + } + } + + public static function sethomeredirect($homeredirect) + { + if(is_string($homeredirect) && strlen($homeredirect) > 0) { + self::$homeredirect = idclean($homeredirect); + } else { + self::$homeredirect = null; + } + } + + public static function setinterfacecss($interfacecss) + { + if(is_string($interfacecss) && file_exists(Model::CSS_DIR . $interfacecss)) { + self::$interfacecss = $interfacecss; + } else { + self::$interfacecss = null; + } + } + + public static function setbookmark($bookmark) + { + if(is_array($bookmark)) { + self::$bookmark = $bookmark; + } + } + + + + + + + // ______________________________________ F U N _________________________________________ + + public static function addbookmark(string $id, string $query) + { + if(!empty($id) && !empty($query)) { + $id = idclean($id); + $id = substr($id, 0, 16); + self::$bookmark[$id] = $query; + } + } + + public static function deletebookmark(string $id) + { + if(key_exists($id, self::$bookmark)) { + unset(self::$bookmark[$id]); + } + } + + + + +} + + + + + + + + + +?> \ No newline at end of file diff --git a/app/class/Controller.php b/app/class/Controller.php new file mode 100644 index 0000000..32ffc13 --- /dev/null +++ b/app/class/Controller.php @@ -0,0 +1,105 @@ +setuser(); + $this->router = $router; + $this->pagemanager = new Modelpage(); + $this->initplates(); + $this->now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + } + + public function setuser() + { + $this->usermanager = new Modeluser; + $this->user = $this->usermanager->readsession(); + } + + public function initplates() + { + $router = $this->router; + $this->plates = new Engine(Model::TEMPLATES_DIR); + $this->plates->registerFunction('url', function (string $string, array $vars = []) use ($router) { + return $router->generate($string, $vars); + }); + $this->plates->registerFunction('upage', function (string $string, string $id) use ($router) { + return $router->generate($string, ['page' => $id]); + }); + } + + public function showtemplate($template, $params) + { + $params = array_merge($this->commonsparams(), $params); + echo $this->plates->render($template, $params); + } + + public function commonsparams() + { + $commonsparams = []; + $commonsparams['router'] = $this->router; + $commonsparams['user'] = $this->user; + $commonsparams['pagelist'] = $this->pagemanager->list(); + $commonsparams['css'] = Model::csspath(); + return $commonsparams; + } + + + + + + public function redirect($url) + { + header('Location: ' . $url); + } + + public function routedirect(string $route, array $vars = []) + { + $this->redirect($this->router->generate($route, $vars)); + } + + public function routedirectget(string $route, array $vars = []) + { + $get = '?'; + foreach ($vars as $key => $value) { + $get .= $key .'='. $value. '&'; + } + $get = rtrim($get, '&'); + $this->redirect($this->router->generate($route, []) . $get); + } + + public function error(int $code) + { + http_response_code($code); + exit; + } + +} + + + + + +?> \ No newline at end of file diff --git a/app/class/Controlleradmin.php b/app/class/Controlleradmin.php new file mode 100644 index 0000000..3935bff --- /dev/null +++ b/app/class/Controlleradmin.php @@ -0,0 +1,69 @@ +user->isadmin()) { + $pagelist = $this->pagemanager->list(); + $this->mediamanager = new Modelmedia(); + $faviconlist = $this->mediamanager->listfavicon(); + $interfacecsslist = $this->mediamanager->listinterfacecss(); + if(in_array(Config::defaultpage(), $pagelist)) { + $defaultpageexist = true; + } else { + $defaultpageexist = true; + } + + $globalcssfile = Model::GLOBAL_DIR . 'global.css'; + + if(is_file($globalcssfile)) { + $globalcss = file_get_contents($globalcssfile); + } else { + $globalcss = ""; + } + + $admin = ['pagelist' => $pagelist, 'defaultpageexist' => $defaultpageexist, 'globalcss' => $globalcss, 'faviconlist' => $faviconlist, 'interfacecsslist' => $interfacecsslist]; + $this->showtemplate('admin', $admin); + } else { + $this->routedirect('home'); + } + } + + public function update() + { + $this->globaldircheck(); + + $globalcss = file_put_contents(Model::GLOBAL_DIR . 'global.css', $_POST['globalcss']); + + Config::hydrate($_POST); + if(Config::savejson() !== false && $globalcss !== false) { + $this->routedirect('admin'); + } else { + echo 'Can\'t write config file or global css file'; + } + } + + + public function globaldircheck() + { + if(!is_dir(Model::GLOBAL_DIR)) { + return mkdir(Model::GLOBAL_DIR); + } else { + return true; + } + } + + +} + + + + +?> \ No newline at end of file diff --git a/app/class/Controllerconnect.php b/app/class/Controllerconnect.php new file mode 100644 index 0000000..592c0ee --- /dev/null +++ b/app/class/Controllerconnect.php @@ -0,0 +1,78 @@ +login($route, $id); + } elseif ($_POST['log'] === 'logout') { + $this->logout($route, $id); + } + } + } + + + public function connect() + { + if(isset($_SESSION['pageupdate'])) { + $pageupdate['route'] = 'pageedit'; + $pageupdate['id'] = $_SESSION['pageupdate']['id']; + } else { + $pageupdate = ['route' => 'home']; + } + $this->showtemplate('connect', $pageupdate); + } + + + + + + public function login($route, $id = null) + { + if (isset($_POST['pass'])) { + $this->user = $this->usermanager->passwordcheck($_POST['pass']); + if($this->user != false) { + if($this->user->expiredate() === false || $this->user->level() === 10 || $this->user->expiredate('date') > $this->now) { + $this->user->connectcounter(); + $this->usermanager->add($this->user); + $this->usermanager->writesession($this->user); + $_SESSION['workspace']['showleftpanel'] = true; + $_SESSION['workspace']['showrightpanel'] = false; + } + } + } + if ($id !== null) { + $this->routedirect($route, ['page' => $id]); + } else { + $this->routedirect($route); + } + } + + public function logout($route, $id = null) + { + $this->user = $this->usermanager->logout(); + $this->usermanager->writesession($this->user); + if ($id !== null && $route !== 'home') { + $this->routedirect($route, ['page' => $id]); + } else { + $this->routedirect($route); + } + } + + + +} + + + + + + +?> \ No newline at end of file diff --git a/app/class/Controllerfont.php b/app/class/Controllerfont.php new file mode 100644 index 0000000..63b3ced --- /dev/null +++ b/app/class/Controllerfont.php @@ -0,0 +1,56 @@ +fontmanager = new Modelfont(); + + } + + public function desktop() + { + if($this->user->iseditor()) { + + $this->fontmanager->fontdircheck(); + + $fontlist = $this->fontmanager->getfontlist(); + + $this->showtemplate('font', ['fontlist' => $fontlist, 'fonttypes' => $this->fontmanager->getfonttypes(), 'fontfile' => Model::globalpath().'fonts.css']); + } else { + $this->routedirect('home'); + } + } + + public function render() + { + $this->fontmanager->renderfontface(); + $this->routedirect('font'); + } + + public function add() + { + if(isset($_POST['fontname'])) { + $fontname = $_POST['fontname']; + } else { + $fontname = ''; + } + $message = $this->fontmanager->upload($_FILES, 2 ** 16, $fontname); + if($message !== true) { + echo $message; + } else { + $this->render(); + } + } +} + + +?> \ No newline at end of file diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php new file mode 100644 index 0000000..003a325 --- /dev/null +++ b/app/class/Controllerhome.php @@ -0,0 +1,130 @@ +modelhome = new Modelhome; + } + + + + + public function desktop() + { + if ($this->user->isvisitor() && Config::homepage() === 'redirect' && Config::homeredirect() !== null) { + $this->routedirect('pageread/', ['page' => Config::homeredirect()]); + } else { + + + + + $table = $this->modelhome->getlister(); + $this->opt = $this->modelhome->optinit($table); + + $table2 = $this->modelhome->table2($table, $this->opt); + + $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::pagetable()]; + + if (isset($_POST['query']) && $this->user->iseditor()) { + $datas = array_merge($_POST, $_SESSION['opt']); + $this->optlist = $this->modelhome->Optlistinit($table); + $this->optlist->hydrate($datas); + $vars['optlist'] = $this->optlist; + } + + $this->showtemplate('home', $vars); + } + } + + public function columns() + { + if (isset($_POST['columns']) && $this->user->iseditor()) { + $user = $this->usermanager->get($this->user->id()); + $user->hydrate($_POST); + $this->usermanager->add($user); + $this->usermanager->writesession($user); + } + $this->routedirect('home'); + } + + public function search() + { + if (isset($_POST['id']) && !empty($_POST['id'])) { + if (isset($_POST['action'])) { + switch ($_POST['action']) { + case 'read': + $this->routedirect('pageread/', ['page' => $_POST['id']]); + break; + + case 'edit': + $this->routedirect('pageedit', ['page' => $_POST['id']]); + break; + } + } + } else { + $this->routedirect('home'); + } + } + + /** + * Render every pages in the database + */ + public function renderall() + { + if ($this->user->iseditor()) { + $pagelist = $this->modelhome->getlister(); + foreach ($pagelist as $page) { + $this->renderpage($page); + $this->pagemanager->update($page); + } + } + $this->routedirect('home'); + } + + public function bookmark() + { + if ($this->user->iseditor() && isset($_POST['action']) && isset($_POST['id']) && !empty($_POST['id'])) { + if ($_POST['action'] == 'add' && isset($_POST['query'])) { + if (isset($_POST['user']) && $_POST['user'] == $this->user->id()) { + $usermanager = new Modeluser(); + $user = $usermanager->get($_POST['user']); + $user->addbookmark($_POST['id'], $_POST['query']); + $usermanager->add($user); + } else { + Config::addbookmark($_POST['id'], $_POST['query']); + Config::savejson(); + } + } elseif ($_POST['action'] == 'del') { + if(isset($_POST['user']) && $_POST['user'] == $this->user->id()) { + $usermanager = new Modeluser(); + $user = $usermanager->get($_POST['user']); + foreach ($_POST['id'] as $id) { + $user->deletebookmark($id); + } + $usermanager->add($user); + } else { + foreach ($_POST['id'] as $id) { + Config::deletebookmark($id); + } + Config::savejson(); + } + } + } + $this->routedirect('home'); + } +} + +?> diff --git a/app/class/Controllerinfo.php b/app/class/Controllerinfo.php new file mode 100644 index 0000000..af81caf --- /dev/null +++ b/app/class/Controllerinfo.php @@ -0,0 +1,27 @@ +user->iseditor()) { + $this->showtemplate('info', ['version' => getversion()]); + } + } + + + + + + +} + + +?> \ No newline at end of file diff --git a/app/class/Controllermedia.php b/app/class/Controllermedia.php new file mode 100644 index 0000000..f596550 --- /dev/null +++ b/app/class/Controllermedia.php @@ -0,0 +1,115 @@ +mediamanager = new Modelmedia; + + } + + public function desktop() + { + if ($this->user->iseditor()) { + + if (!$this->mediamanager->dircheck(Model::MEDIA_DIR)) { + throw new Exception("Media error : Cant create /media folder"); + } + if (!$this->mediamanager->dircheck(Model::FAVICON_DIR)) { + throw new Exception("Media error : Cant create /media/favicon folder"); + } + if (!$this->mediamanager->dircheck(Model::THUMBNAIL_DIR)) { + throw new Exception("Media error : Cant create /media/thumbnail folder"); + } + + + $dir = rtrim($_GET['path'] ?? Model::MEDIA_DIR, DIRECTORY_SEPARATOR); + $sortby = isset($_GET['sortby']) ? $_GET['sortby'] : 'id'; + $order = isset($_GET['order']) ? $_GET['order'] : '1'; + $opt = ['dir' => $dir, 'sortby' => $sortby, 'order' => $order]; + + if(is_dir($dir)) { + $medialist = $this->mediamanager->getlistermedia($dir . DIRECTORY_SEPARATOR); + $faviconlist = $this->mediamanager->getlistermedia(Model::FAVICON_DIR); + + $dirlist = $this->mediamanager->listdir(Model::MEDIA_DIR); + + $pathlist = []; + + $this->mediamanager->listpath($dirlist, '', $pathlist); + + $this->mediamanager->medialistsort($medialist, $sortby, $order); + + $this->showtemplate('media', ['medialist' => $medialist, 'faviconlist' => $faviconlist, 'dirlist' => $dirlist, 'pathlist' =>$pathlist, 'dir' => $dir, 'opt' => $opt]); + } else { + $this->routedirect('media'); + } + + } else { + $this->routedirect('home'); + } + } + + public function upload() + { + if ($this->user->iseditor()) { + $target = $_POST['dir'] ?? Model::MEDIA_DIR; + if (!empty($_FILES['file']['name'][0])) { + $this->mediamanager->multiupload('file', $target); + } + $this->redirect($this->router->generate('media') . '?path=' . $target); + } else { + $this->routedirect('home'); + } + } + + public function folderadd() + { + if ($this->user->iseditor()) { + $dir = $_POST['dir'] ?? Model::MEDIA_DIR; + $name = idclean($_POST['foldername']) ?? 'new-folder'; + $this->mediamanager->adddir($dir, $name); + } + $this->redirect($this->router->generate('media') . '?path=' . $dir . DIRECTORY_SEPARATOR . $name); + + } + + public function folderdelete() + { + if(isset($_POST['dir'])) { + if(isset($_POST['deletefolder']) && intval($_POST['deletefolder']) && $this->user->issupereditor()) { + $this->mediamanager->deletedir($_POST['dir']); + } else { + $this->redirect($this->router->generate('media') . '?path=' . $_POST['dir']); + exit; + } + } + $this->redirect($this->router->generate('media')); + } + + public function edit() + { + if($this->user->issupereditor() && isset($_POST['action']) && isset($_POST['id'])) { + if($_POST['action'] == 'delete') { + $this->mediamanager->multifiledelete($_POST['id']); + } elseif ($_POST['action'] == 'move' && isset($_POST['dir'])) { + $this->mediamanager->multimovefile($_POST['id'], $_POST['dir']); + } + } + $this->redirect($this->router->generate('media') . '?path=' . $_POST['path']); + } + + +} + + +?> \ No newline at end of file diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php new file mode 100644 index 0000000..5ab2928 --- /dev/null +++ b/app/class/Controllerpage.php @@ -0,0 +1,417 @@ +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 + If(isset($_FILES)) { + $this->mediamanager->dircheck(Model::THUMBNAIL_DIR); + $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/Controllertimeline.php b/app/class/Controllertimeline.php new file mode 100644 index 0000000..8fc40d2 --- /dev/null +++ b/app/class/Controllertimeline.php @@ -0,0 +1,58 @@ +eventmanager = new Modeltimeline; + } + + public function desktop() + { + $eventlist = $this->eventmanager->showlast(['message'], 100, 0); + + $groupedeventlist = $this->eventmanager->group($eventlist); + + $this->showtemplate('timeline', ['eventlist' => $eventlist, 'groupedeventlist' => $groupedeventlist]); + + } + + public function add() + { + if($this->user->level() >= Modeluser::EDITOR && !empty($_POST['message'])) { + + $event = new Event($_POST); + $event->stamp(); + $event->setid($this->eventmanager->getlastfreeid()); + $this->eventmanager->add($event); + } + $this->routedirect('timeline'); + } + + public function clap() + { + if(isset($_POST['id']) && isset($_POST['clap'])) { + $event = $this->eventmanager->get(intval($_POST['id'])); + $event->addclap(); + $this->eventmanager->add($event); + } + $this->routedirect('timeline'); + + } +} + + + + + + + + +?> \ No newline at end of file diff --git a/app/class/Controlleruser.php b/app/class/Controlleruser.php new file mode 100644 index 0000000..3856914 --- /dev/null +++ b/app/class/Controlleruser.php @@ -0,0 +1,117 @@ +user->iseditor()) { + $getuser = $this->usermanager->get($this->user); + if($this->user->isadmin()) { + $userlist = $this->usermanager->getlister(); + $this->showtemplate('user', ['userlist' => $userlist, 'getuser' => $getuser, 'now' => $this->now->format('Y-m-d')]); + } else { + $this->showtemplate('user', ['getuser' => $getuser]); + } + } else { + $this->routedirect('home'); + } + } + + + public function pref() + { + if($this->user->iseditor()) { + $user = $this->usermanager->get($this->user); + $user->hydrate($_POST); + $this->usermanager->add($user); + $this->routedirect('user'); + } else { + $this->routedirect('home'); + } + } + + + + + + public function add() + { + if(isset($_POST['id'])) { + $user = new User($_POST); + if(empty($user->id()) || $this->usermanager->get($user)) { + $this->routedirectget('user', ['error' => 'wrong_id']); + } elseif(empty($user->password()) || $this->usermanager->passwordexist($user->password()) || !$user->validpassword()) { + $this->routedirectget('user', ['error' => 'change_password']); + } else { + if($user->passwordhashed()) { + $user->hashpassword(); + } + $this->usermanager->add($user); + $this->routedirect('user'); + } + } + } + + public function update() + { + if($this->user->isadmin() && isset($_POST['action'])) { + switch ($_POST['action']) { + case 'delete': + $user = new User($_POST); + $user = $this->usermanager->get($user); + if($user !== false) { + if($user->id() === $this->user->id()) { + $this->showtemplate('userconfirmdelete', ['userdelete' => $user, 'candelete' => false]); + } else { + $this->showtemplate('userconfirmdelete', ['userdelete' => $user, 'candelete' => true]); + } + } else { + $this->routedirect('user'); + } + break; + + case 'confirmdelete': + $user = new User($_POST); + $this->usermanager->delete($user); + $this->routedirect('user'); + break; + + case 'update': + $user = $this->usermanager->get($_POST['id']); + $userupdate = clone $user; + $userupdate->hydrate($_POST); + if(empty($userupdate->id())) { + $this->routedirectget('user', ['error' => 'wrong_id']); + } elseif (!empty($_POST['password']) && (empty($userupdate->password()) || $this->usermanager->passwordexist($userupdate->password()) || !$userupdate->validpassword())) { + $this->routedirectget('user', ['error' => 'password_unvalid']); + } elseif (empty($userupdate->level())) { + $this->routedirectget('user', ['error' => 'wrong_level']); + } elseif ($user->level() === 10 && $userupdate->level() !== 10 && $this->user->id() === $user->id()) { + $this->routedirectget('user', ['error' => 'cant_edit_yourself']); + } else { + if($userupdate->password() !== $user->password() && $user->passwordhashed()) { + $userupdate->setpasswordhashed(false); + } + if($userupdate->passwordhashed() && !$user->passwordhashed()) { + $userupdate->hashpassword(); + } + $this->usermanager->add($userupdate); + $this->routedirect('user'); + } + } + } else { + $this->routedirect('home'); + } + } +} + + + +?> \ No newline at end of file diff --git a/app/class/Dbitem.php b/app/class/Dbitem.php new file mode 100644 index 0000000..fb272b1 --- /dev/null +++ b/app/class/Dbitem.php @@ -0,0 +1,34 @@ + $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + + } + + public function dry() + { + $array = []; + foreach (get_object_vars($this) as $var => $value) { + if (in_array($var, $this::VAR_DATE)) { + $array[$var] = $this->$var('string'); + } else { + $array[$var] = $this->$var(); + } + } + return $array; + } +} + + +?> \ No newline at end of file diff --git a/app/class/Element.php b/app/class/Element.php new file mode 100644 index 0000000..09f4e35 --- /dev/null +++ b/app/class/Element.php @@ -0,0 +1,204 @@ +hydrate($datas); + $this->analyse($pageid); + } + + public function hydrate($datas) + { + foreach ($datas as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + private function analyse(string $pageid) + { + if(!empty($this->options)) { + + // Replace "!" by the real page name + $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[] = $pageid; + } + if(isset($matches[4])) { + $this->params = explode(',', $matches[4]); + } + + $this->readoptions(); + + } else { + $this->sources[] = $pageid; + } + } + + private function readoptions() + { + if(!empty($this->params)) { + foreach ($this->params as $param ) { + preg_match('~([a-z0-9-_]+)(=(-?[0-9]+))?~', $param, $optionmatch); + if(isset($optionmatch[1])) { + $key = $optionmatch[1]; + } + if(isset($optionmatch[3])) { + $value = $optionmatch[3]; + } else { + $read = '

Rendering error :

Paramaters must have a value like : /' . $key . '=__value__ for parameter : ' . $key . '

'; + //throw new Exception($read); + } + $method = 'set' . $key; + if (in_array($key, self::OPTIONS)) { + if (!$this->$method($value)) { + $read = '

Rendering error :

Invalid value input : ' . $value . ' for parameter : ' . $key . '

'; + //throw new Exception($read); + + } + } else { + $read = '

Rendering error :

Parameter name : ' . $optionmatch[1] . ' does not exist

'; + //throw new Exception($read); + } + } + } + } + + public function addtags() + { + $this->content = PHP_EOL . '<' . $this->type() . '>' . PHP_EOL . $this->content() . PHP_EOL . 'type() . '>' . PHP_EOL; + } + + + + + + // __________________________________________________ G E T ____________________________________________________________ + + + public function fullmatch() + { + return $this->fullmatch; + } + + public function type() + { + return $this->type; + } + + public function options() + { + return $this->options; + } + + public function params() + { + return $this->params; + } + + public function sources() + { + return $this->sources; + } + + public function autolink() + { + return $this->autolink; + } + + public function markdown() + { + return $this->markdown; + } + + public function content() + { + return $this->content; + } + + + + + + + // __________________________________________________ S E T ____________________________________________________________ + + + public function setfullmatch(string $fullmatch) + { + $this->fullmatch = $fullmatch; + } + + public function settype(string $type) + { + $type = strtolower($type); + if(in_array($type, Model::TEXT_ELEMENTS)) { + $this->type = $type; + } + } + + public function setoptions(string $options) + { + if(!empty($options)) { + $this->options = $options; + } + } + + public function setautolink(int $level) + { + if($level >= 0 && $level <= 16) { + $this->autolink = $level; + return true; + } else { + return false; + } + } + + public function setmarkdown(int $level) + { + if($level >= 0 && $level <= 1) { + $this->markdown = $level; + return true; + } else { + return false; + } + } + + public function setcontent(string $content) + { + $this->content = $content; + } + +} + + + + +?> \ No newline at end of file diff --git a/app/class/Event.php b/app/class/Event.php new file mode 100644 index 0000000..8c1e155 --- /dev/null +++ b/app/class/Event.php @@ -0,0 +1,162 @@ +hydrate($datas); + } + + public function stamp() + { + $this->date = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $this->user = idclean($this->user); + if (in_array($this->type, self::EVENT_ART)) { + $this->target = idclean($this->target); + } elseif ($this->type === 'message') { + $this->message = htmlspecialchars($this->message); + } + } + + public function addclap() + { + $this->clap ++; + } + + // _____________________ G E T __________________________ + + public function id() + { + return $this->id; + } + + public function date($type = 'datetime') + { + switch ($type) { + case 'datetime': + return $this->date; + break; + + case 'string': + return $this->date->format(DateTime::ISO8601); + break; + + case 'hrdi': + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->date->diff($now)); + break; + + } + } + + public function type() + { + return $this->type; + } + + public function user() + { + return $this->user; + } + + public function target() + { + return $this->target; + } + + public function message() + { + return $this->message; + } + + public function clap() + { + return $this->clap; + } + + + + // ________________________ S E T ____________________ + + public function setid($id) + { + if (is_int($id)) { + $this->id = $id; + } + } + + public function setdate($date) + { + if ($date instanceof DateTimeImmutable) { + $this->date = $date; + } elseif (is_string($date)) { + $this->date = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $date, new DateTimeZone('Europe/Paris')); + } + } + + public function settype($type) + { + if (in_array($type, self::EVENT_TYPES)) { + $this->type = $type; + } + } + + public function setuser($user) + { + if (is_string($user) && strlen($user) < Model::MAX_ID_LENGTH) { + $this->user = $user; + } + } + + public function settarget($target) + { + if (is_string($target) && strlen($target) < Model::MAX_ID_LENGTH) { + $this->target = $target; + } + } + + public function setmessage($message) + { + if (is_string($message) && strlen($message) < self::MESSAGE_MAX_LENGTH) { + $this->message = $message; + } + } + + public function setclap($clap) + { + if(is_int($clap)) { + $this->clap = $clap; + } + } + + + + + +} + + +?> \ No newline at end of file diff --git a/app/class/Flywheel/Formatter/JSON.php b/app/class/Flywheel/Formatter/JSON.php new file mode 100644 index 0000000..9659fcb --- /dev/null +++ b/app/class/Flywheel/Formatter/JSON.php @@ -0,0 +1,21 @@ +operators = array( + '>', '>=', '<', '<=', '==', '===', '!=', '!==', 'IN' + ); + } +} diff --git a/app/class/Flywheel/Query.php b/app/class/Flywheel/Query.php new file mode 100644 index 0000000..f002080 --- /dev/null +++ b/app/class/Flywheel/Query.php @@ -0,0 +1,16 @@ +predicate = new Predicate(); + } +} diff --git a/app/class/Flywheel/Repository.php b/app/class/Flywheel/Repository.php new file mode 100644 index 0000000..d0b68eb --- /dev/null +++ b/app/class/Flywheel/Repository.php @@ -0,0 +1,30 @@ +formatter->getFileExtension(); + $files = glob($this->path . DIRECTORY_SEPARATOR . '*.' . $ext); + return $files; + } + + /** + * Get an array containing the id of all files in this repository + * + * @return array An array, item is a id + */ + public function getAllIds() + { + $ext = $this->formatter->getFileExtension(); + return array_map(function($path) use ($ext) { + return $this->getIdFromPath($path, $ext); + }, $this->getAllFiles()); + } +} diff --git a/app/class/Media.php b/app/class/Media.php new file mode 100644 index 0000000..b30b883 --- /dev/null +++ b/app/class/Media.php @@ -0,0 +1,233 @@ +hydrate($donnees); + } + + public function hydrate(array $donnees) + { + foreach ($donnees as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + + public function analyse() + { + $this->settype(); + + $filepath = $this->path . $this->id . '.' . $this->extension; + + $this->size = filesize($filepath); + + if ($this->type == 'image') { + list($width, $height, $type, $attr) = getimagesize($filepath); + $this->width = $width; + $this->height = $height; + } + + + } + + + public function getfullpath() + { + if(!empty(Config::basepath())) { + $base = '/' . Config::basepath(); + } else { + $base = ''; + } + $fullpath = $base . '/'. $this->path() . $this->id() . '.' . $this->extension(); + $fullpath = str_replace('\\', '/', $fullpath); + return $fullpath; + } + + public function getincludepath() + { + $includepath = $this->path() . $this->id() . '.' . $this->extension(); + $includepath = str_replace('\\', '/', $includepath); + $includepath = substr($includepath, 6); + return $includepath; + } + + public function getfulldir() + { + return $this->path . $this->id . '.' . $this->extension; + } + + /** + * Generate html code depending on media type + * + * @return string html code + */ + public function getcode() : string + { + switch ($this->type) { + case 'image': + $code = '![' . $this->id . '](' . $this->getincludepath() . ')'; + break; + + case 'other': + $code = '[' . $this->id . '](' . $this->getincludepath() . ')'; + break; + + case 'sound': + $code = '<audio controls src="' . $this->getincludepath() . '"></audio>'; + break; + + case 'video': + $code = '<video controls=""><source src="' . $this->getincludepath() . '" type="video/' . $this->extension . '"></video>'; + break; + + } + + return $code; + + } + + + +// _________________________________________________ G E T ____________________________________________________ + + public function id() + { + return $this->id; + } + + public function path() + { + return $this->path; + } + + public function extension() + { + return $this->extension; + } + + public function type() + { + return $this->type; + } + + public function size($display = 'binary') + { + if($display == 'hr') { + return readablesize($this->size); + } else { + return $this->size; + } + } + + public function width() + { + return $this->width; + } + + public function height() + { + return $this->height; + } + + public function length() + { + return $this->length; + } + +// ___________________________________________________ S E T __________________________________________________ + + public function setid($id) + { + if (is_string($id)) { + $this->id = $id; + } + } + + public function setpath($path) + { + if (strlen($path) < 40 and is_string($path)) { + $this->path = strip_tags(strtolower($path)); + } + } + + public function setextension($extension) + { + if (strlen($extension) < 7 and is_string($extension)) { + $this->extension = strip_tags(strtolower($extension)); + } + } + + public function settype() + { + if (isset($this->extension)) { + if (in_array($this->extension, $this::IMAGE)) { + $this->type = "image"; + } elseif (in_array($this->extension, $this::SOUND)) { + $this->type = "sound"; + } elseif (in_array($this->extension, $this::VIDEO)) { + $this->type = "video"; + } else { + $this->type = "other"; + } + } + } + + public function setsize($size) + { + if (40 and is_int($size)) { + $this->size = strip_tags(strtolower($size)); + } + } + + public function setwidth($width) + { + if (is_int($width)) { + $this->width = strip_tags(strtolower($width)); + } + } + + public function setheight($height) + { + if (is_int($height)) { + $this->height = strip_tags(strtolower($height)); + } + } + + public function setlength($length) + { + if ($this->type == 'sound') { + $this->length = $length; + } + } + + + + + + +} diff --git a/app/class/Medialist.php b/app/class/Medialist.php new file mode 100644 index 0000000..da5ba4f --- /dev/null +++ b/app/class/Medialist.php @@ -0,0 +1,155 @@ +hydrate($datas); + $this->readoptions(); + $this->generatecontent(); + } + + public function hydrate($datas) + { + foreach ($datas as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function readoptions() + { + parse_str($this->options, $datas); + $this->hydrate($datas); + } + + public function generatecontent() + { + $mediamanager = new Modelmedia(); + $medialist = $mediamanager->getlistermedia(Model::MEDIA_DIR . $this->path . '/'); + if (!$medialist) { + $this->content = 'RENDERING ERROR : path : ' . Model::MEDIA_DIR . $this->path . '/ does not exist'; + return false; + } else { + + $mediamanager->medialistsort($medialist, $this->sortby, $this->order); + + $dirid = str_replace('/', '-', $this->path); + + $div = '

' . PHP_EOL; + + foreach ($medialist as $media) { + $div .= '
'; + if ($media->type() == 'image') { + $div .= '' . $media->id() . ''; + } elseif ($media->type() == 'sound') { + $div .= '
' . PHP_EOL; + } + + $div .= '
' . PHP_EOL; + + $this->content = $div; + + return true; + } + } + + + // __________________________________________________ G E T ____________________________________________________________ + + + public function fullmatch() + { + return $this->fullmatch; + } + + public function options() + { + return $this->options; + } + + public function content() + { + return $this->content; + } + + + + // __________________________________________________ S E T ____________________________________________________________ + + + public function setfullmatch(string $fullmatch) + { + $this->fullmatch = $fullmatch; + } + + + public function setoptions(string $options) + { + if (!empty($options)) { + $this->options = $options; + } + } + + public function setpath(string $path) + { + $this->path = $path; + } + + public function setsortby(string $sortby) + { + if (in_array($sortby, self::SORT_BY_OPTIONS)) { + $this->sortby = $sortby; + } + } + + public function setorder(int $order) + { + if ($order === -1 || $order === 1) { + $this->order = $order; + } + } +} diff --git a/app/class/Model.php b/app/class/Model.php new file mode 100644 index 0000000..81ad626 --- /dev/null +++ b/app/class/Model.php @@ -0,0 +1,115 @@ +getlister(); + + $pagelist2 = []; + foreach ($pagelist as $page) { + $page->setlinkfrom($this->analyselinkfrom($page)); + $pagelist2[] = $page; + } + foreach ($pagelist2 as $page) { + $page->setlinkto($this->analyselinkto($page->id(), $pagelist)); + $this->update($page); + } + } + + + public function analyse(Page $page) + { + $page->setlinkfrom($this->analyselinkfrom($page)); + + $pagelist = $this->getlister(); + $page->setlinkto($this->analyselinkto($page->id(), $pagelist)); + + return $page; + } + + + + + public function analyselinkto($id, $pagelist) + { + //analyse les liens vers cet pageicle en fouillant tout les linkfrom de la bdd, génere un tableau à stocker dans l'pageicle + $linkto = []; + foreach ($pagelist as $link) { + if (in_array($id, $link->linkfrom('array')) && $id != $link->id()) { + $linkto[] = $link->id(); + } + } + return $linkto; + } + + public function analyselinkfrom(Page $page) + { + $linkfrom = []; + foreach (self::TEXT_ELEMENTS as $element) { + preg_match_all('#\]\((\?id=|=)(\w+)\)#', $page->$element(), $out); + $linkfrom = array_merge($linkfrom, $out[2]); + } + return array_unique($linkfrom); + + } + +} + + + + + + + +?> \ No newline at end of file diff --git a/app/class/Modelconfig.php b/app/class/Modelconfig.php new file mode 100644 index 0000000..518f64e --- /dev/null +++ b/app/class/Modelconfig.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/app/class/Modeldb.php b/app/class/Modeldb.php new file mode 100644 index 0000000..756fd81 --- /dev/null +++ b/app/class/Modeldb.php @@ -0,0 +1,45 @@ +dbinit(); + } + + + public function dbinit() + { + $this->database = new Config(Model::DATABASE_DIR, [ + 'query_class' => Query::class, + 'formatter' => new JSON, + ]); + } + + public function storeinit(string $repo) + { + $this->repo = new Repository($repo, $this->database); + } + + public function list() + { + return $this->repo->getAllIds(); + } + + + + + +} diff --git a/app/class/Modelfont.php b/app/class/Modelfont.php new file mode 100644 index 0000000..3f25e21 --- /dev/null +++ b/app/class/Modelfont.php @@ -0,0 +1,132 @@ +fontlist($this->list()); + } + + public function getfonttypes() + { + $fonttypes = array_map(function ($ext) { + return '.' . $ext; + }, $this::FONT_TYPES); + return implode(', ', $fonttypes); + } + + public function renderfontface() + { + $list = $this->list(); + $fontlist = $this->fontlist($list); + $fontface = $this->fontface($fontlist); + $this->write($fontface); + } + + + public function list() + { + if ($handle = opendir(Model::FONT_DIR)) { + $list = []; + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + + $list[] = $entry; + + } + } + } + + return $list; + + } + + public function fontlist(array $list) + { + $fontlist = []; + $fonttypes = implode('|', $this::FONT_TYPES); + $regex = '#(.+)\.(' . $fonttypes . ')#'; + foreach ($list as $font) { + if (preg_match($regex, $font, $out)) { + $fontlist[] = ['id' => $out[1], 'ext' => $out[2], 'size' => filesize(Model::FONT_DIR . $font)]; + } + } + return $fontlist; + } + + public function fontface(array $fontlist) + { + $fontface = ''; + foreach ($fontlist as $font) { + $fontface .= '@font-face {' . PHP_EOL . 'font-family: ' . $font['id'] . ';' . PHP_EOL . ' src: url( ' . Model::fontpath() . $font['id'] . '.' . $font['ext'] . ');' . PHP_EOL . '}' . PHP_EOL . PHP_EOL; + } + return $fontface; + } + + + public function write(string $fontface) + { + $write = file_put_contents(Model::GLOBAL_DIR . 'fonts.css', $fontface); + if ($write !== false) { + + } + } + + public function upload(array $file, $maxsize = 2 ** 24, $id = null) + { + $message = 'runing'; + if (isset($file) and $file['font']['error'] == 0 and $file['font']['size'] < $maxsize) { + $infosfichier = pathinfo($file['font']['name']); + $extension_upload = $infosfichier['extension']; + $extensions_autorisees = $this::FONT_TYPES; + if (in_array($extension_upload, $extensions_autorisees)) { + if (!empty($id)) { + $id = strtolower(strip_tags($id)); + $id = str_replace(' ', '_', $id); + } else { + $id = $infosfichier['filename']; + } + if (!file_exists($this::FONT_DIR . $id . '.' . $extension_upload)) { + + $extension_upload = strtolower($extension_upload); + $uploadok = move_uploaded_file($file['font']['tmp_name'], $this::FONT_DIR . $id . '.' . $extension_upload); + if ($uploadok) { + $message = true; + } else { + $message = 'uploaderror'; + } + } else { + $message = 'filealreadyexist'; + + } + } + } else { + $message = 'filetoobig'; + + } + return $message; + } + + + + +} + + + + +?> \ No newline at end of file diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php new file mode 100644 index 0000000..f12f7d3 --- /dev/null +++ b/app/class/Modelhome.php @@ -0,0 +1,107 @@ +setcol(['id', 'tag', 'linkfrom', 'linkto', 'description', 'title', 'datemodif', 'datecreation', 'date', 'secure', 'visitcount', 'editcount', 'affcount']); + $opt->settaglist($table); + $opt->setauthorlist($table); + $opt->submit(); + + return $opt; + } + + /** + * Initialise Optlist object using + * + * @param array $table the list of all pages objects + * + * @return Optlist Object initialized + */ + public function Optlistinit(array $table) + { + $optlist = new Optlist(Page::classvarlist()); + $optlist->settaglist($table); + $optlist->setauthorlist($table); + + return $optlist; + } + + + + + /** + * @param array $table + * @param Opt $opt + */ + public function table2($table, $opt) + { + + + $filtertagfilter = $this->filtertagfilter($table, $opt->tagfilter(), $opt->tagcompare()); + $filterauthorfilter = $this->filterauthorfilter($table, $opt->authorfilter(), $opt->authorcompare()); + $filtersecure = $this->filtersecure($table, $opt->secure()); + + $filter = array_intersect($filtertagfilter, $filtersecure, $filterauthorfilter); + $table2 = []; + $table2invert = []; + foreach ($table as $page) { + if (in_array($page->id(), $filter)) { + $table2[] = $page; + } else { + $table2invert[] = $page; + } + + + } + + if (!empty($opt->invert())) { + $table2 = $table2invert; + } + + $this->pagelistsort($table2, $opt->sortby(), $opt->order()); + + if($opt->limit() !== 0) { + $table2 = array_slice($table2, 0, $opt->limit()); + } + + + return $table2; + } + + /** + * @param array array of the columns to show from the user + * + * @return array assoc each key columns to a boolean value to show or not + */ + public function setcolumns(array $columns) : array + { + foreach (Model::COLUMNS as $col) { + if(in_array($col, $columns)) { + $showcols[$col] = true; + } else { + $showcols[$col] = false; + } + } + return $showcols; + } +} + + + + + + + + +?> \ No newline at end of file diff --git a/app/class/Modelmassedit.php b/app/class/Modelmassedit.php new file mode 100644 index 0000000..e69de29 diff --git a/app/class/Modelmedia.php b/app/class/Modelmedia.php new file mode 100644 index 0000000..6ac647f --- /dev/null +++ b/app/class/Modelmedia.php @@ -0,0 +1,320 @@ + str_replace('.' . $fileinfo['extension'], '', $fileinfo['filename']), + 'path' => $dir, + 'extension' => $fileinfo['extension'] + ); + return new Media($datas); + } else { + return false; + } + } + + /** + * Display a list of media + * + * @param string $path + * @param string $sortby + * @param string $order + * + * @return array of Media objects + */ + public function getlistermedia($dir, $type = "all") + { + if (is_dir($dir)) { + if ($handle = opendir($dir)) { + $list = []; + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + + $media = $this->getmedia($entry, $dir); + + if ($media != false) { + + $media->analyse(); + + if (in_array($type, self::MEDIA_TYPES)) { + if ($media->type() == $type) { + $list[] = $media; + } + } else { + $list[] = $media; + } + } + } + } + return $list; + } + } else { + return false; + } + } + + + + public function mediacompare($media1, $media2, $method = 'id', $order = 1) + { + $result = ($media1->$method() <=> $media2->$method()); + return $result * $order; + } + + public function buildsorter($sortby, $order) + { + return function ($media1, $media2) use ($sortby, $order) { + $result = $this->mediacompare($media1, $media2, $sortby, $order); + return $result; + }; + } + + + /** + * Sort an array of media + * + * @param array $medialist + * @param string $sortby + * @param int order Can be 1 or -1 + */ + public function medialistsort(array &$medialist, string $sortby = 'id', int $order = 1): bool + { + $sortby = (in_array($sortby, self::MEDIA_SORTBY)) ? $sortby : 'id'; + $order = ($order === 1 || $order === -1) ? $order : 1; + return usort($medialist, $this->buildsorter($sortby, $order)); + } + + + + + public function listfavicon() + { + $glob = Model::FAVICON_DIR . '*.png'; + $faviconlist = glob($glob); + $faviconlist = array_map(function ($input){ + return basename($input); + }, $faviconlist); + return $faviconlist; + } + + + public function listinterfacecss() + { + $glob = Model::CSS_DIR . '*.css'; + $listinterfacecss = glob($glob); + $listinterfacecss = array_map(function ($input) { + return basename($input); + }, $listinterfacecss); + $listinterfacecss = array_diff($listinterfacecss, ['edit.css', 'home.css']); + return $listinterfacecss; + } + + + /** + * Generate an reccursive array where each folder is a array and containing a filecount in each folder + */ + public function listdir(string $dir) : array + { + $result = array(); + + $cdir = scandir($dir); + $result['dirfilecount'] = 0; + foreach ($cdir as $key => $value) { + if (!in_array($value, array(".", ".."))) { + if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) { + $result[$value] = $this->listdir($dir . DIRECTORY_SEPARATOR . $value); + } else { + $result['dirfilecount']++; + } + } + } + + return $result; + } + + /** + * Analyse reccursive array of content to generate list of path + * + * @param array $dirlist Array generated by the listdir function + * @param string $parent used to create the strings + * @param array $pathlist used by reference, must be an empty array + * + * @return array list of path as string + */ + public function listpath(array $dirlist, string $parent = '', array &$pathlist = []) + { + foreach ($dirlist as $dir => $content) { + if(is_array($content)) { + $pathlist[] = $parent . $dir . DIRECTORY_SEPARATOR; + $this->listpath($content, $parent . $dir . DIRECTORY_SEPARATOR, $pathlist); + } + } + } + + /** + * Upload single file + * + * @param string $index The file id + * @param string $destination File final destination + * @param bool|int $maxsize Max file size in octets + * @param bool|array $extensions List of authorized extensions + * @param bool $jpgrename Change the file exentension to .jpg + * + * @return bool If upload process is a succes or not + */ + function simpleupload(string $index, string $destination, $maxsize = false, $extensions = false, bool $jpgrename = false): bool + { + //Test1: if the file is corectly uploaded + if (!isset($_FILES[$index]) || $_FILES[$index]['error'] > 0) return false; + //Test2: check file size + if ($maxsize !== false && $_FILES[$index]['size'] > $maxsize) return false; + //Test3: check extension + $ext = substr(strrchr($_FILES[$index]['name'], '.'), 1); + if ($extensions !== false && !in_array($ext, $extensions)) return false; + if ($jpgrename !== false) { + $destination .= '.jpg'; + } else { + $destination .= '.' . $ext; + } + //Move to dir + return move_uploaded_file($_FILES[$index]['tmp_name'], $destination); + } + + /** + * Upload multiple files + * + * @param string $index Id of the file input + * @param string $target direction to save the files + */ + public function multiupload(string $index, string $target) + { + if ($target[strlen($target) - 1] != DIRECTORY_SEPARATOR) + $target .= DIRECTORY_SEPARATOR; + $count = 0; + foreach ($_FILES[$index]['name'] as $filename) { + $fileinfo = pathinfo($filename); + $extension = idclean($fileinfo['extension']); + $id = idclean($fileinfo['filename']); + + $tmp = $_FILES['file']['tmp_name'][$count]; + $count = $count + 1; + $temp = $target . $id . '.' . $extension; + move_uploaded_file($tmp, $temp); + $temp = ''; + $tmp = ''; + } + } + + public function adddir($dir, $name) + { + $newdir = $dir . DIRECTORY_SEPARATOR . $name; + if (!is_dir($newdir)) { + return mkdir($newdir); + } else { + return false; + } + } + + /** + * Completely delete dir and it's content + * + * @param string $dir Directory to destroy + * + * @return bool depending on operation success + */ + public function deletedir(string $dir) : bool + { + if(substr($dir, -1) !== '/') { + $dir .= '/'; + } + if(is_dir($dir)) { + return $this->deltree($dir); + } else { + return false; + } + } + + /** + * Function do reccursively delete a directory + */ + public function deltree(string $dir) + { + $files = array_diff(scandir($dir), array('.','..')); + foreach ($files as $file) { + (is_dir("$dir/$file")) ? $this->deltree("$dir/$file") : unlink("$dir/$file"); + } + return rmdir($dir); + } + + /** + * Delete a file + */ + public function deletefile(string $filedir) + { + if(is_file($filedir)) { + return unlink($filedir); + } else { + return false; + } + } + + public function multifiledelete(array $filelist) + { + foreach ($filelist as $filedir ) { + if(is_string($filedir)) { + $this->deletefile($filedir); + } + } + } + + public function movefile(string $filedir, string $dir) + { + if(substr($dir, -1) !== '/') { + $dir .= '/'; + } + if(is_file($filedir)) { + $newdir = $dir . basename($filedir); + return rename($filedir, $newdir); + } else { + return false; + } + } + + public function multimovefile(array $filedirlist, string $dir) + { + $success = []; + foreach ($filedirlist as $filedir ) { + if(is_string($filedir)) { + $success[] = $this->movefile($filedir, $dir); + } + } + if(in_array(false, $success)) { + return false; + } else { + return true; + } + } + + + +} diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php new file mode 100644 index 0000000..58bd5d3 --- /dev/null +++ b/app/class/Modelpage.php @@ -0,0 +1,325 @@ +storeinit(Config::pagetable()); + if(!$this->dircheck(Model::HTML_RENDER_DIR)) { + throw new Exception("Media error : Cant create /render 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; + } + + + /** + * Scan database for specific pages IDs and return array of Pages objects + * + * @param array $idlist list of ID strings + * + * @return array of Page objects + */ + public function getlisterid(array $idlist = []) : array + { + $pagedatalist = $this->repo->query() + ->where('__id', 'IN', $idlist) + ->execute(); + + $pagelist = []; + foreach ($pagedatalist as $id => $pagedata) { + $pagelist[$id] = new Page($pagedata); + } + return $pagelist; + } + + /** + * Store new page in the database + * + * @param Page $page object + */ + public function add(Page $page) + { + + $pagedata = new 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 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 new file mode 100644 index 0000000..9f668d4 --- /dev/null +++ b/app/class/Modelrender.php @@ -0,0 +1,693 @@ +router = $router; + $this->pagelist = $this->getlister(); + + if(Config::internallinkblank()) { + $this->internallinkblank = ' target="_blank" '; + } + + if(Config::externallinkblank()) { + $this->externallinkblank = ' target="_blank" '; + } + } + + public function upage($id) + { + return $this->router->generate('pageread/', ['page' => $id]); + } + + + /** + * Main function + * + * @param Page $page page to render + */ + public function render(Page $page) + { + $this->page = $page; + + $this->write($this->gethmtl()); + } + + /** + * Combine body and head to create html file + * + * @return string html string + */ + public function gethmtl() + { + + $head = $this->gethead(); + $body = $this->getbody($this->readbody()); + $parsebody = $this->parser($body); + + $html = '' . PHP_EOL . '' . PHP_EOL . '' . PHP_EOL . $head . PHP_EOL . '' . PHP_EOL . $parsebody . PHP_EOL . ''; + + return $html; + } + + + public function readbody() + { + if (!empty($this->page->templatebody())) { + $templateid = $this->page->templatebody(); + $templatepage = $this->get($templateid); + if($templatepage !== false) { + $body = $templatepage->body(); + } else { + $body = $this->page->body(); + $this->page->settemplatebody(''); + } + } else { + $body = $this->page->body(); + } + $body = $this->article($body); + $body = $this->automedialist($body); + $body = $this->autotaglistupdate($body); + return $body; + } + + + /** + * Analyse BODY, call the corresponding CONTENTs and render everything + * + * @param string $body as the string BODY of the page + * + * @return string as the full rendered BODY of the page + */ + public function getbody(string $body) : string + { + // Elements that can be detected + $types = ['HEADER', 'NAV', 'MAIN', 'ASIDE', 'FOOTER']; + + // First level regex + $regex = '~\%(' . implode("|", $types) . ')(\S*)\%~'; + + // Match the first level regex + preg_match_all($regex, $body, $out); + + // Create a list of all the elements that passed through the first level regex + foreach ($out[0] as $key => $match) { + $matches[$key] = ['fullmatch' => $match, 'type' => $out[1][$key], 'options' => $out[2][$key]]; + } + + + // First, analyse the synthax and call the corresponding methods + if(isset($matches)) { + foreach ($matches as $key => $match) { + $element = new Element($match, $this->page->id()); + $element->setcontent($this->getelementcontent($element)); + $element->setcontent($this->elementparser($element)); + $element->addtags(); + $body = str_replace($element->fullmatch(), $element->content(), $body); + + } + } + + + + return $body; + + } + + public function getelementcontent(Element $element) + { + $content = ''; + $subseparator = PHP_EOL . PHP_EOL; + foreach($element->sources() as $source) + { + 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; + } + } else { + $read = '

Rendering error :

The page ' . $source . ', called in '. $element->fullmatch() . ', does not exist yet.

'; + //throw new Exception($read); + } + + } else { + $type = $element->type(); + $subcontent = $this->page->$type(); + } + $content .= $subseparator . $subcontent; + } + return $content . $subseparator; + } + + public function elementparser(Element $element) + { + $content = $this->article($element->content()); + $content = $this->automedialist($content); + $content = $this->pagelist($content); + $content = $this->autotaglistupdate($content); + $content = $this->date($content); + $content = $this->thumbnail($content); + if($element->autolink()) { + $content = str_replace('%LINK%', '' ,$content); + $content = $this->everylink($content, $element->autolink()); + } else { + $content = $this->taglink($content); + } + if($element->markdown()) { + $content = $this->markdown($content); + } + + return $content; + } + + + /** + * Write css javascript and html as files in the assets folder + */ + public function write(string $html) + { + 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->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->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->page->template('array'))) { + $templatejspage = $this->get($this->page->template('array')['javascript']); + file_put_contents(Model::RENDER_DIR . $templatejspage->id() . '.js', $templatejspage->javascript()); + } + } + + + + + public function gethead() + { + + $head = ''; + + $head .= '' . PHP_EOL; + $head .= '' . $this->page->title() . '' . PHP_EOL; + if (!empty($this->page->favicon())) { + $head .= ''; + } elseif (!empty(Config::defaultfavicon())) { + $head .= ''; + } + $head .= '' . PHP_EOL; + $head .= '' . PHP_EOL; + + + $head .= '' . PHP_EOL; + $head .= '' . PHP_EOL; + + if($this->page->thumbnailexist()) { + $head .= '' . PHP_EOL; + } + + $head .= '' . PHP_EOL; + + + foreach ($this->page->externalcss() as $externalcss) { + $head .= '' . PHP_EOL; + } + + 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) { + $head .= '' . PHP_EOL; + } + } + } + + $head .= PHP_EOL . $this->page->customhead() . PHP_EOL; + + + $head .= '' . PHP_EOL; + $head .= '' . PHP_EOL; + + if (!empty($this->page->templatecss())) { + $tempaltecsspage = $this->page->templatecss(); + $head .= '' . PHP_EOL; + } + $head .= '' . PHP_EOL; + + if (!empty($this->page->templatejavascript())) { + $templatejspage = $this->page->templatejavascript(); + $head .= '' . PHP_EOL; + } + if (!empty($this->page->javascript())) { + $head .= '' . PHP_EOL; + } + + if (!empty(Config::analytics())) { + + $head .= PHP_EOL . ' + + + + ' . PHP_EOL; + } + + + return $head; + } + + public function desctitle($text, $desc, $title) + { + $text = str_replace('%TITLE%', $title, $text); + $text = str_replace('%DESCRIPTION%', $desc, $text); + return $text; + } + + + public function parser(string $text) + { + $text = $this->media($text); + + $text = $this->headerid($text); + + $text = str_replace(self::SUMMARY, $this->sumparser($text), $text); + + $text = $this->wurl($text); + $text = $this->wikiurl($text); + + $text = $this->desctitle($text, $this->page->description(), $this->page->title()); + + + $text = str_replace('href="http', ' class="external" target="_blank" href="http', $text); + + $text = $this->autourl($text); + + $text = $this->authenticate($text); + + return $text; + } + + public function media(string $text) : string + { + $text = preg_replace('%(src|href)="([\w-_]+(\/([\w-_])+)*\.[a-z0-9]{1,5})"%', '$1="' . Model::mediapath() . '$2" target="_blank" class="media"', $text); + if (!is_string($text)) { + //throw new Exception('Rendering error -> media module'); + } + return $text; + } + + + public function autourl($text) + { + $text = preg_replace('#( |\R|>)(https?:\/\/((\S+)\.([^< ]+)))#', '$1externallinkblank .'>$3', $text); + return $text; + } + + public function wurl(string $text) + { + $linkfrom = []; + $rend = $this; + $text = preg_replace_callback( + '%href="([\w-]+)\/?(#?[a-z-_]*)"%', + function ($matches) use ($rend, &$linkfrom) { + $matchpage = $rend->get($matches[1]); + if (!$matchpage) { + $link = 'href="' . $rend->upage($matches[1]) . '"" title="' . Config::existnot() . '" class="internal existnot"' . $this->internallinkblank; + } else { + $linkfrom[] = $matchpage->id(); + $link = 'href="' . $rend->upage($matches[1]) . $matches[2] . '" title="' . $matchpage->description() . '" class="internal exist '. $matchpage->secure('string') .'"' . $this->internallinkblank; + } + return $link; + }, + $text + ); + $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom)); + return $text; + } + + public function wikiurl(string $text) + { + $linkfrom = []; + $rend = $this; + $text = preg_replace_callback( + '%\[([\w-]+)\/?#?([a-z-_]*)\]%', + function ($matches) use ($rend, &$linkfrom) { + $matchpage = $rend->get($matches[1]); + if (!$matchpage) { + return 'internallinkblank .' >' . $matches[1] . ''; + } else { + $linkfrom[] = $matchpage->id(); + return 'internallinkblank .' >' . $matchpage->title() . ''; + } + }, + $text + ); + $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom)); + return $text; + } + + public function headerid($text) + { + $sum = []; + $text = preg_replace_callback( + '/(.+)<\/h[1-6]>/mU', + function ($matches) use (&$sum) { + $cleanid = idclean($matches[4]); + $sum[$cleanid][$matches[1]] = $matches[4]; + return '' . $matches[4] . ''; + }, + $text + ); + $this->sum = $sum; + return $text; + } + + public function markdown($text) + { + //use Michelf\MarkdownExtra; + $fortin = new Michelf\MarkdownExtra; + // id in headers + // $fortin->header_id_func = function ($header) { + // return preg_replace('/[^\w]/', '', strtolower($header)); + // }; + $fortin->hard_wrap = true; + $text = $fortin->transform($text); + return $text; + } + + + + public function article($text) + { + $pattern = '/(\R\R|^\R|^)[=]{3,}([\w-]*)\R\R(.*)(?=\R\R[=]{3,}[\w-]*\R)/sUm'; + $text = preg_replace_callback($pattern, function ($matches) { + if (!empty($matches[2])) { + $id = ' id="' . $matches[2] . '" '; + } else { + $id = ' '; + } + return '
' . PHP_EOL . PHP_EOL . $matches[3] . PHP_EOL . PHP_EOL . '
' . PHP_EOL . PHP_EOL; + }, $text); + $text = preg_replace('/\R\R[=]{3,}([\w-]*)\R/', '', $text); + return $text; + } + + /** + * Check for media list call in the text and insert media list + * @param string $text Text to scan and replace + * + * @return string Output text + */ + public function automedialist(string $text) + { + preg_match_all('~\%MEDIA\?([a-zA-Z0-9\&=\-\/\%]*)\%~', $text, $out); + + foreach ($out[0] as $key => $match) { + $matches[$key] = ['fullmatch' => $match, 'options' => $out[1][$key]]; + } + + if(isset($matches)) { + foreach ($matches as $match) { + $medialist = new Medialist($match); + $text = str_replace($medialist->fullmatch(), $medialist->content(), $text); + } + } + return $text; + } + + + function sumparser($text) + { + preg_match_all('#(.+)#iU', $text, $out); + + + $sum = $this->sum; + + + + $sumstring = ''; + $last = 0; + foreach ($sum as $title => $list) { + foreach ($list as $h => $link) { + if ($h > $last) { + for ($i = 1; $i <= ($h - $last); $i++) { + $sumstring .= '
    '; + } + $sumstring .= '
  • ' . $link . '
  • '; + } elseif ($h < $last) { + for ($i = 1; $i <= ($last - $h); $i++) { + $sumstring .= '
'; + } + $sumstring .= '
  • ' . $link . '
  • '; + } elseif ($h = $last) { + $sumstring .= '
  • ' . $link . '
  • '; + } + $last = $h; + } + } + for ($i = 1; $i <= ($last); $i++) { + $sumstring .= ''; + } + return $sumstring; + } + + + + public function autotaglist($text) + { + $pattern = "/\%TAG:([a-z0-9_-]+)\%/"; + preg_match_all($pattern, $text, $out); + return $out[1]; + + } + + public function autotaglistupdate($text) + { + $taglist = $this->autotaglist($text); + foreach ($taglist as $tag) { + $li = []; + foreach ($this->pagelist as $item) { + if (in_array($tag, $item->tag('array'))) { + $li[] = $item; + } + + } + $ul = '
      ' . PHP_EOL; + $this->pagelistsort($li, 'date', -1); + foreach ($li as $item) { + if ($item->id() === $this->page->id()) { + $actual = ' actualpage'; + } else { + $actual = ''; + } + $ul .= '
    • internallinkblank .' >' . $item->title() . '
    • ' . PHP_EOL; + } + $ul .= '
    ' . PHP_EOL; + + + $text = str_replace('%TAG:' . $tag . '%', $ul, $text); + + $li = array_map(function ($item) { + return $item->id(); + }, $li); + $this->linkfrom = array_unique(array_merge($this->linkfrom, $li)); + } + return $text; + } + + + public function date(string $text) + { + $page = $this->page; + $text = preg_replace_callback('~\%DATE\%~', function ($matches) use ($page) { + return ''; + }, $text); + $text = preg_replace_callback('~\%TIME\%~', function ($matches) use ($page) { + return ''; + }, $text); + + return $text; + } + + /** + * Render thumbnail of the page + * + * @param string $text Text to analyse + * + * @return string The rendered output + */ + public function thumbnail(string $text) : string + { + $img = '' . $this->page->title() . ''; + $img = PHP_EOL . $img . PHP_EOL; + $text = str_replace('%THUMBNAIL%', $img, $text); + + return $text; + } + + public function taglink($text) + { + $rend = $this; + $text = preg_replace_callback('/\%LINK\%(.*)\%LINK\%/msU', function ($matches) use ($rend) { + return $rend->everylink($matches[1], 1); + }, $text); + return $text; + } + + /** + * Autolink Function : transform every word of more than $limit characters in internal link + * + * @param string $text The input text to be converted + * + * @return string Conversion output + */ + public function everylink(string $text, int $limit) : string + { + $regex = '~([\w-_éêèùïüîçà]{' . $limit . ',})(?![^<]*>|[^<>]*<\/)~'; + $text = preg_replace_callback($regex , function ($matches) { + return '' . $matches[1] . ''; + }, $text); + return $text; + } + + + + /** + * @param string $text content to analyse and replace + * + * @return string text ouput + */ + public function authenticate(string $text) + { + $id = $this->page->id(); + $regex = '~\%CONNECT(\?dir=([a-zA-Z0-9-_]+))?\%~'; + $text = preg_replace_callback($regex, function ($matches) use ($id) { + if(isset($matches[2])) { + $id = $matches[2]; + } + $form = '
    + + + + +
    '; + return $form; + + }, $text); + return $text; + } + + /** + * Render pages list + */ + public function pagelist(string $text) : string + { + preg_match_all('~\%LIST\?([a-zA-Z0-9\]\[\&=\-\/\%]*)\%~', $text, $out); + + foreach ($out[0] as $key => $match) { + $matches[$key] = ['fullmatch' => $match, 'options' => $out[1][$key]]; + } + + $modelhome = new Modelhome(); + + if(isset($matches)) { + foreach ($matches as $match) { + $optlist = $modelhome->Optlistinit($this->pagelist); + $optlist->parsehydrate($match['options']); + $table2 = $modelhome->table2($this->pagelist, $optlist); + + $content = '
      ' . PHP_EOL ; + foreach ($table2 as $page ) { + $content .= '
    • ' . PHP_EOL; + $content .= '' . $page->title() . '' . PHP_EOL; + if($optlist->description()) { + $content .= '' . $page->description() . '' . PHP_EOL; + } + if($optlist->date()) { + $content .= '' . $page->date('pdate') . '' . PHP_EOL; + } + if($optlist->time()) { + $content .= '' . $page->date('ptime') . '' . PHP_EOL; + } + if($optlist->author()) { + $content .= $page->authors('string') . PHP_EOL; + } + $content .= '
    • '; + } + $content .= '
    '; + + $text = str_replace($match['fullmatch'], $content, $text); + } + } + return $text; + } + + + + + + + + + public function linkfrom() + { + sort($this->linkfrom); + $linkfrom = $this->linkfrom; + $this->linkfrom = []; + return $linkfrom; + } + + public function linkto() + { + $linkto = []; + foreach ($this->pagelist as $page) { + if (in_array($this->page->id(), $page->linkfrom())) { + $linkto[] = $page->id(); + } + } + return $linkto; + } + + + + +} + + + +?> \ No newline at end of file diff --git a/app/class/Modeltimeline.php b/app/class/Modeltimeline.php new file mode 100644 index 0000000..248e0f6 --- /dev/null +++ b/app/class/Modeltimeline.php @@ -0,0 +1,143 @@ +storeinit('timeline'); + } + + public function get(int $id) + { + $eventdata = $this->repo->findById($id); + if ($eventdata !== false) { + return new Event($eventdata); + } else { + return false; + } + } + + /** + * Retrun a list of Event objects + * + * @return array array of Event where the key is the Event id. + */ + public function getlister() : array + { + $eventlist = []; + $datalist = $this->repo->findAll(); + foreach ($datalist as $eventdata) { + $event = new Event($eventdata); + $id = intval($event->id()); + $eventlist[$id] = $event; + } + return $eventlist; + } + + + public function getlisterid(array $idlist = []) : array + { + $eventdatalist = $this->repo->query() + ->where('__id', 'IN', $idlist) + ->execute(); + + $eventlist = []; + foreach ($eventdatalist as $id => $eventdata) { + $eventlist[$id] = new Event($eventdata); + } + return $eventlist; + } + + + /** + * Store event + * + * @param Event The event to be stored in the repositery + * + * @return bool retrun true if it works, false if it fails + */ + public function add(Event $event) : bool + { + $eventdata = new Document($event->dry()); + $eventdata->setId($event->id()); + $result = $this->repo->store($eventdata); + return $result; + } + + /** + * Return last free id + * + * @return int id + */ + public function getlastfreeid() : int + { + $idlist = $this->list(); + + if (!empty($idlist)) { + $id = max($idlist); + $id++; + } else { + $id = 1; + } + return $id; + } + + public function group(array $events) + { + $id = 0; + $subid = 0; + $lastuser = null; + foreach ($events as $event) { + if($event->user() !== $lastuser) { + $subid = 0; + $id ++; + $groupedevents[$id]['user'] = $event->user(); + } else { + $subid ++; + } + $groupedevents[$id][$subid] = $event; + $lastuser = $event->user(); + } + return $groupedevents; + } + + public function showlast(array $types, int $qty = 25, int $offset = 0) + { + $types = array_intersect($types, $this->types()); + + $eventdatalist = $this->repo->query() + ->where('type', 'IN', $types) + ->orderBy('date DESC') + ->limit($qty, $offset) + ->execute(); + + $eventlist = []; + foreach ($eventdatalist as $id => $eventdata) { + $eventlist[] = new Event($eventdata); + } + + $eventlist = array_reverse($eventlist); + return $eventlist; + } + + + public function types() + { + return array_merge(self::EVENT_ART, self::EVENT_BASE, self::EVENT_MEDIA, self::EVENT_MEDIA); + } + + +} + + +?> \ No newline at end of file diff --git a/app/class/Modeluser.php b/app/class/Modeluser.php new file mode 100644 index 0000000..c921b4c --- /dev/null +++ b/app/class/Modeluser.php @@ -0,0 +1,196 @@ +storeinit(self::USER_REPO_NAME); + } + + public function writesession(User $user) + { + $_SESSION['user' . Config::basepath()] = ['level' => $user->level(), 'id' => $user->id(), 'columns' =>$user->columns()]; + } + + public function writecookie(User $user) + { + $cookiehash = + $cookie = ['level' => $user->level(), 'id' => $user->id()]; + setcookie('user ' . Config::basepath(), $cookie, time() + $user->cookie()*24*3600, null, null, false, true); + } + + public function readsession() + { + $userdatas = []; + if (array_key_exists('user' . Config::basepath(), $_SESSION) && isset($_SESSION['user' . Config::basepath()]['id'])) { + $userdatas = $_SESSION['user' . Config::basepath()]; + $user = new User($userdatas); + $user = $this->get($user); + return $user; + } else { + return new User(['id' => '', 'level' => 0]); + } + } + + + public function logout() + { + $user = new User(['level' => self::FREE]); + return $user; + } + + + + /** + * @return array list of User objects + */ + public function getlister() + { + $userlist = []; + $list = $this->repo->findAll(); + foreach ($list as $userdata) { + $userlist[$userdata->id] = new User($userdata); + } + return $userlist; + } + + + public function getlisterid(array $idlist = []) + { + $userdatalist = $this->repo->query() + ->where('__id', 'IN', $idlist) + ->execute(); + + $userlist = []; + foreach ($userdatalist as $id => $userdata) { + $userlist[$id] = new User($userdata); + } + return $userlist; + } + + public function admincount() + { + $userdatalist = $this->repo->query() + ->where('level', '==', 10) + ->execute(); + + return $userdatalist->total(); + } + + public function getlisterbylevel(int $level, $comp = '==') + { + $userdatalist = $this->repo->query() + ->where('level', $comp, $level) + ->execute(); + + $userlist = []; + foreach ($userdatalist as $user) { + $userlist[] = $user->id; + } + + return $userlist; + } + + /** + * Check if the password is used, and return by who + * + * @param string $pass password clear + * + * @return mixed User or false + */ + public function passwordcheck(string $pass) + { + $userdatalist = $this->getlister(); + foreach ($userdatalist as $user) { + if ($user->passwordhashed()) { + if (password_verify($pass, $user->password())) { + return $user; + } + } else { + if ($user->password() === $pass) { + return $user; + } + } + } + return false; + } + + /** + * Return information if the password is already used or not + * + * @param string $pass password clear + * + * @return bool password exist or not + */ + public function passwordexist(string $pass) : bool + { + if ($this->passwordcheck($pass) !== false) { + return true; + } else { + return false; + } + } + + /** + * @param User $user + * + * @return bool depending on success + */ + public function add(User $user) : bool + { + $userdata = new Document($user->dry()); + $userdata->setId($user->id()); + return $this->repo->store($userdata); + } + + + /** + * @param string|User $id + * + * @return User|false User object or false in case of error + */ + public function get($id) + { + if ($id instanceof User) { + $id = $id->id(); + } + if (is_string($id)) { + $userdata = $this->repo->findById($id); + if ($userdata !== false) { + return new User($userdata); + } else { + return false; + } + } else { + return false; + } + } + + public function delete(User $user) + { + $this->repo->delete($user->id()); + } + + +} + + + + + + +?> \ No newline at end of file diff --git a/app/class/Opt.php b/app/class/Opt.php new file mode 100644 index 0000000..803edce --- /dev/null +++ b/app/class/Opt.php @@ -0,0 +1,388 @@ + '0', 'max' => '0']; + protected $linkfrom = ['min' => '0', 'max' => '0']; + protected $col = ['id']; + protected $taglist = []; + protected $authorlist = []; + protected $invert = 0; + protected $limit= 0; + + protected $pagevarlist; + + public function __construct(array $donnees = []) + { + $this->hydrate($donnees); + } + + public function hydrate(array $donnees) + { + foreach ($donnees as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + + public function resetall() + { + $varlist = get_class_vars(__class__); + + foreach ($varlist as $var => $default) { + $method = 'set' . $var; + $this->$method($default); + } + } + + public function reset($var) + { + $varlist = get_class_vars(__class__); + if (in_array($var, $varlist)) { + $this->$var = $varlist[$var]; + } + } + + public function submit() + { + if (isset($_GET['submit'])) { + if ($_GET['submit'] == 'reset') { + $_SESSION['opt'] = []; + } elseif ($_GET['submit'] == 'filter') { + $this->getall(); + } + } else { + $this->sessionall(); + } + } + + public function getall() + { + $optlist = ['sortby', 'order', 'secure', 'tagcompare', 'tagfilter', 'authorcompare', 'authorfilter', 'limit','invert']; + + foreach ($optlist as $method) { + if (method_exists($this, $method)) { + if (isset($_GET[$method])) { + $setmethod = 'set' . $method; + $this->$setmethod($_GET[$method]); + } else { + $this->reset($method); + } + $_SESSION['opt'][$method] = $this->$method(); + } + } + } + + public function sessionall() + { + if (isset($_SESSION['opt'])) { + $this->hydrate($_SESSION['opt']); + } + } + + public function getadress(string $sortby = '') + { + if ($this->sortby === $sortby) { + $order = $this->order * -1; + } else { + $order = $this->order; + } + if(empty($sortby)) { + $sortby = $this->sortby; + } + $adress = '?sortby=' . $sortby; + $adress .= '&order=' . $order; + $adress .= '&secure=' . $this->secure; + $adress .= '&tagcompare=' . $this->tagcompare; + foreach ($this->tagfilter as $tag) { + $adress .= '&tagfilter[]=' . $tag; + } + $adress .= '&authorcompare=' . $this->authorcompare; + foreach ($this->authorfilter as $author) { + $adress .= '&authorfilter[]=' . $author; + } + if ($this->invert == 1) { + $adress .= '&invert=1'; + } + $adress.= '&limit=' .$this->limit; + $adress .= '&submit=filter'; + + return $adress; + } + + + + /** + * Get the query as http string + * + * @return string The resulted query + */ + public function getquery(): string + { + $class = get_class_vars(get_class($this)); + $object = get_object_vars($this); + $class['pagevarlist'] = $object['pagevarlist']; + $class['taglist'] = $object['taglist']; + $class['authorlist'] = $object['authorlist']; + $query = array_diff_assoc_recursive($object, $class); + + return urldecode(http_build_query($query)); + } + + + + + // _______________________________________________ G E T _______________________________________________ + + public function sortby() + { + return $this->sortby; + } + + public function order() + { + return $this->order; + } + + public function secure() + { + return $this->secure; + } + + public function tagfilter($type = 'array') + { + return $this->tagfilter; + } + + public function tagcompare() + { + return $this->tagcompare; + } + + public function authorfilter($type = 'array') + { + return $this->authorfilter; + } + + public function authorcompare() + { + return $this->authorcompare; + } + + public function linkto($type = 'array') + { + return $this->linkto; + } + + public function linkfrom($type = 'array') + { + return $this->linkfrom; + } + + public function col($type = 'array') + { + if ($type == 'string') { + return implode(', ', $this->col); + } else { + return ($this->col); + } + } + + public function taglist() + { + return $this->taglist; + } + + public function authorlist() + { + return $this->authorlist; + } + + public function invert() + { + return $this->invert; + } + + public function pagevarlist() + { + return $this->pagevarlist; + } + + public function limit() + { + return $this->limit; + } + + + // __________________________________________________ S E T _____________________________________________ + + public function setsortby($sortby) + { + if (is_string($sortby) && in_array($sortby, $this->pagevarlist)) { + $this->sortby = strtolower(strip_tags($sortby)); + } + } + + public function setorder($order) + { + $order = intval($order); + if (in_array($order, [-1, 0, 1])) { + $this->order = $order; + } + } + + public function settagfilter($tagfilter) + { + if (!empty($tagfilter) && is_array($tagfilter)) { + $tagfilterverif = []; + foreach ($tagfilter as $tag) { + if (array_key_exists($tag, $this->taglist)) { + $tagfilterverif[] = $tag; + } + } + $this->tagfilter = $tagfilterverif; + } + } + + public function settagcompare($tagcompare) + { + if (in_array($tagcompare, ['OR', 'AND'])) { + $this->tagcompare = $tagcompare; + } + } + + public function setauthorfilter($authorfilter) + { + if (!empty($authorfilter) && is_array($authorfilter)) { + $authorfilterverif = []; + foreach ($authorfilter as $author) { + if (array_key_exists($author, $this->authorlist)) { + $authorfilterverif[] = $author; + } + } + $this->authorfilter = $authorfilterverif; + } + } + + public function setauthorcompare($authorcompare) + { + if (in_array($authorcompare, ['OR', 'AND'])) { + $this->authorcompare = $authorcompare; + } + } + + public function setsecure($secure) + { + if ($secure >= 0 && $secure <= 5) { + $this->secure = intval($secure); + } + } + + public function setlinkto($range) + { + $this->linkto = $range; + } + + public function setlinkfrom($range) + { + $this->linkfrom = $range; + } + + public function setlinktomin($min) + { + $this->linkto['min'] = intval($min); + } + + public function setlinktomax($max) + { + $this->linkto['max'] = intval($max); + } + + public function setlinkfrommin($min) + { + $this->linkfrom['min'] = intval($min); + } + + public function setlinkfrommax($max) + { + $this->linkfrom['max'] = intval($max); + } + + public function setcol($col) + { + if (is_array($col)) { + $this->col = array_intersect($this->pagevarlist(), $col); + } + } + + public function settaglist(array $pagelist) + { + $taglist = []; + foreach ($pagelist as $page) { + foreach ($page->tag('array') as $tag) { + if (!array_key_exists($tag, $taglist)) { + $taglist[$tag] = 1; + } else { + $taglist[$tag]++; + } + } + } + $taglistsorted = arsort($taglist); + $this->taglist = $taglist; + } + + public function setauthorlist(array $pagelist) + { + $authorlist = []; + foreach ($pagelist as $page) { + foreach ($page->authors('array') as $author) { + if (!array_key_exists($author, $authorlist)) { + $authorlist[$author] = 1; + } else { + $authorlist[$author]++; + } + } + } + $authorlistsorted = arsort($authorlist); + $this->authorlist = $authorlist; + } + + public function setinvert(int $invert) + { + if ($invert == 0 || $invert == 1) { + $this->invert = $invert; + } else { + $this->invert = 0; + } + } + + public function setlimit($limit) + { + $limit = intval($limit); + if($limit < 0) { + $limit = 0; + } elseif ($limit >= 10000) { + $limit = 9999; + } + $this->limit = $limit; + } + + + public function setpagevarlist(array $pagevarlist) + { + $this->pagevarlist = $pagevarlist; + } +} diff --git a/app/class/Optlist.php b/app/class/Optlist.php new file mode 100644 index 0000000..d6a9cdb --- /dev/null +++ b/app/class/Optlist.php @@ -0,0 +1,115 @@ +hydrate($datas); + } + } + + /** + * Get the code to insert directly + */ + public function getcode() : string + { + return '%LIST?' . $this->getquery() . '%'; + } + + + + + // _______________________________________ G E T _____________________________________ + + + public function title() + { + return $this->title; + } + + public function description() + { + return $this->description; + } + + public function thumbnail() + { + return $this->thumbnail; + } + + public function date() + { + return $this->date; + } + + public function time() + { + return $this->time; + } + + public function author() + { + return $this->author; + } + + public function style() + { + return $this->style; + } + + + // _______________________________________ S E T _____________________________________ + + public function settitle($title) + { + $this->title = intval($title); + } + + public function setdescription($description) + { + $this->description = intval($description); + } + + public function setthumbnail($thumbnail) + { + $this->thumbnail = intval($thumbnail); + } + + public function setdate($date) + { + $this->date = intval($date); + } + + public function settime($time) + { + $this->time = intval($time); + } + + public function setauthor($author) + { + $this->author = intval($author); + } + + public function setstyle($style) + { + $this->style = intval($style); + } +} + + + +?> \ No newline at end of file diff --git a/app/class/Page.php b/app/class/Page.php new file mode 100644 index 0000000..2fa4060 --- /dev/null +++ b/app/class/Page.php @@ -0,0 +1,820 @@ +reset(); + $this->hydrate($datas); + } + + public function hydrate($datas) + { + foreach ($datas as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function reset() + { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + + $this->settitle($this->id()); + $this->setdescription(''); + $this->settag([]); + $this->setdate($now); + $this->setdatecreation($now); + $this->setdatecreation($now); + $this->setdatemodif($now); + $this->setdaterender($now); + $this->setcss(''); + $this->setquickcss([]); + $this->setjavascript(''); + $this->setbody(''); + $this->setheader(''); + $this->setmain(''); + $this->setnav(''); + $this->setaside(''); + $this->setfooter(''); + $this->setexternalcss([]); + $this->setcustomhead(''); + $this->setsecure(Config::defaultprivacy()); + $this->setinterface('main'); + $this->setlinkfrom([]); + $this->setlinkto([]); + $this->settemplatebody(''); + $this->settemplatecss(''); + $this->settemplatejavascript(''); + $this->settemplateoptions(['externalcss', 'externaljavascript', 'favicon', 'reccursivecss', 'quickcss']); + $this->setfavicon(''); + $this->setauthors([]); + $this->setinvites([]); + $this->setreaders([]); + $this->setaffcount(0); + $this->setvisitcount(0); + $this->seteditcount(0); + $this->seteditby([]); + } + + + + public static function classvarlist() + { + $classvarlist = []; + foreach (get_class_vars(__class__) as $var => $default) { + $classvarlist[] = $var; + } + return ['pagevarlist' => $classvarlist]; + } + + public function dry() + { + $array = []; + foreach (get_class_vars(__class__) as $var => $value) { + if (in_array($var, self::VAR_DATE)) { + $array[$var] = $this->$var('string'); + } else { + $array[$var] = $this->$var(); + } + } + return $array; + } + + /** + * Check if page have a thumbnail + * @return bool true if the page have a thumbnail otherwise return false. + */ + public function thumbnailexist() : bool + { + $thumbnaillink = Model::THUMBNAIL_DIR . $this->id . '.jpg'; + + $test = file_exists($thumbnaillink); + + $exist = file_exists(Model::THUMBNAIL_DIR . $this->id . '.jpg'); + + return $exist; + } + + + // _____________________________________________________ G E T ____________________________________________________ + + public function id($type = 'string') + { + return $this->id; + } + + public function title($type = 'string') + { + if($type == 'sort') { + return strtolower($this->title); + } else { + return $this->title; + } + } + + public function description($type = 'string') + { + if($type == 'short' && strlen($this->description) > 15 ) { + return substr($this->description, 0, 20) . '...'; + } else { + return $this->description; + } + } + + public function tag($option = 'array') + { + if ($option == 'string') { + return implode(", ", $this->tag); + } elseif ($option == 'array') { + return $this->tag; + } elseif ($option == 'sort') { + return count($this->tag); + } + } + + public function date($option = 'date') + { + if ($option == 'string') { + return $this->date->format(DateTime::ISO8601); + } elseif ($option == 'date' || $option == 'sort') { + return $this->date; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->date->diff($now)); + } elseif ($option == 'pdate') { + return $this->date->format('Y-m-d'); + } elseif ($option == 'ptime') { + return $this->date->format('H:i'); + } elseif ($option = 'dmy') { + return $this->date->format('d/m/Y'); + } + + + } + + public function datecreation($option = 'date') + { + if ($option == 'string') { + return $this->datecreation->format(DateTime::ISO8601); + } elseif ($option == 'date' || $option == 'sort') { + return $this->datecreation; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->datecreation->diff($now)); + } + } + + + public function datemodif($option = 'date') + { + if ($option == 'string') { + return $this->datemodif->format(DateTime::ISO8601); + } elseif ($option == 'date' || $option == 'sort') { + return $this->datemodif; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->datemodif->diff($now)); + } + } + + public function daterender($option = 'date') + { + if ($option == 'string') { + return $this->daterender->format(DateTime::ISO8601); + } elseif ($option == 'date' || $option == 'sort') { + return $this->daterender; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->daterender->diff($now)); + } + } + + public function css($type = 'string') + { + return $this->css; + } + + public function quickcss($type = 'array') + { + if ($type == 'json') { + return json_encode($this->quickcss); + } elseif ($type == 'array') { + return $this->quickcss; + } + } + + public function javascript($type = 'string') + { + return $this->javascript; + } + + public function body($type = 'string') + { + return $this->body; + } + + public function header($type = 'string') + { + return $this->header; + } + + public function main($type = 'string') + { + return $this->main; + } + + public function nav($type = "string") + { + return $this->nav; + } + + public function aside($type = "string") + { + return $this->aside; + } + + public function externalcss($type = "array") + { + return $this->externalcss; + } + + public function customhead($type = "string") + { + if($type === 'string') { + return $this->customhead; + } elseif($type === 'int') { + return substr_count($this->customhead, PHP_EOL) + 1; + } + } + + public function footer($type = "string") + { + return $this->footer; + } + + public function secure($type = 'int') + { + if ($type == 'string') { + if ($this->secure == 0) $secure = 'public'; + if ($this->secure == 1) $secure = 'private'; + if ($this->secure == 2) $secure = 'not_published'; + return $secure; + } else { + return $this->secure; + } + } + + public function invitepassword($type = 'string') + { + return $this->invitepassword; + } + + public function readpassword($type = 'string') + { + return $this->readpassword; + } + + public function interface($type = 'string') + { + return $this->interface; + } + + public function linkfrom($option = 'array') + { + if ($option == 'json') { + $linkfrom = json_encode($this->linkfrom); + } elseif ($option == 'array') { + $linkfrom = $this->linkfrom; + } elseif ($option == 'sort') { + return count($this->linkfrom); + } elseif ($option == 'string') { + return implode(', ', $this->linkfrom); + } + return $linkfrom; + + } + + public function linkto($option = 'array') + { + if ($option == 'json') { + $linkto = json_encode($this->linkto); + } elseif ($option == 'array') { + $linkto = $this->linkto; + } elseif ($option == 'sort') { + return count($this->linkto); + } elseif ($option == 'string') { + return implode(', ', $this->linkto); + } + return $linkto; + + } + + public function templatebody($type = 'string') + { + return $this->templatebody; + } + + public function templatecss($type = 'string') + { + return $this->templatecss; + } + + public function templatejavascript($type = 'string') + { + return $this->templatejavascript; + } + + public function template() + { + $template['body'] = $this->templatebody; + $template['css'] = $this->templatecss; + $template['javascript'] = $this->templatejavascript; + + $template['cssreccursive'] = $this->checkoption('reccursive'); + $template['cssquickcss'] = $this->checkoption('quickcss'); + $template['externalcss'] = $this->checkoption('externalcss'); + $template['cssfavicon'] = $this->checkoption('favicon'); + + $template['externaljavascript'] = $this->checkoption('externaljavascript'); + + return $template; + } + + public function templateoptions($type = 'array') + { + return $this->templateoptions; + } + + function checkoption($option) + { + if (in_array('reccursive', $this->templateoptions)) { + return true; + } else { + return false; + } + } + + public function favicon($type = 'string') + { + return $this->favicon; + } + + public function authors($type = 'array') + { + if($type == 'string') { + return implode(', ', $this->authors); + } elseif ($type == 'array') { + return $this->authors; + } + } + + public function invites($type = 'array') + { + return $this->invites; + } + + public function readers($type = 'array') + { + return $this->invites; + } + + public function affcount($type = 'int') + { + return $this->affcount; + } + + public function visitcount($type = 'int') + { + return $this->visitcount; + } + + public function editcount($type = 'int') + { + return $this->editcount; + } + + public function editby($type = 'array') + { + return $this->editby; + } + + + + + // _____________________________________________________ S E T ____________________________________________________ + + public function setid($id) + { + if (strlen($id) <= Model::MAX_ID_LENGTH and is_string($id)) { + $this->id = strip_tags(strtolower(str_replace(" ", "", $id))); + } + } + + public function settitle($title) + { + if (strlen($title) < self::LEN and is_string($title)) { + $this->title = strip_tags(trim($title)); + } + } + + public function setdescription($description) + { + if (strlen($description) < self::LEN and is_string($description)) { + $this->description = strip_tags(trim($description)); + } + } + + public function settag($tag) + { + if (is_string($tag)) { + + if (strlen($tag) < self::LEN) { + $tag = strip_tags(trim(strtolower($tag))); + $tag = str_replace('*', '', $tag); + $tag = str_replace(' ', '', $tag); + + $taglist = explode(",", $tag); + $taglist = array_filter($taglist); + $this->tag = $taglist; + } + } elseif (is_array($tag)) { + $this->tag = $tag; + } + } + + public function setdate($date) + { + if ($date instanceof DateTimeImmutable) { + $this->date = $date; + } else { + $this->date = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $date, new DateTimeZone('Europe/Paris')); + } + } + + public function setdatecreation($datecreation) + { + if ($datecreation instanceof DateTimeImmutable) { + $this->datecreation = $datecreation; + } else { + $this->datecreation = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $datecreation, new DateTimeZone('Europe/Paris')); + } + } + + public function setdatemodif($datemodif) + { + if ($datemodif instanceof DateTimeImmutable) { + $this->datemodif = $datemodif; + } else { + $this->datemodif = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $datemodif, new DateTimeZone('Europe/Paris')); + } + } + + public function setdaterender($daterender) + { + if ($daterender instanceof DateTimeImmutable) { + $this->daterender = $daterender; + } else { + $this->daterender = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $daterender, new DateTimeZone('Europe/Paris')); + } + } + + + public function setcss($css) + { + if (strlen($css) < self::LENTEXT and is_string($css)) { + $this->css = trim(strtolower($css)); + } + } + + + public function setquickcss($quickcss) + { + if (is_string($quickcss)) { + $quickcss = json_decode($quickcss, true); + } + if (is_array($quickcss)) { + $this->quickcss = $quickcss; + } + } + + public function setjavascript($javascript) + { + if (strlen($javascript < self::LENTEXT && is_string($javascript))) { + $this->javascript = $javascript; + } + } + + + public function setbody($body) + { + if (strlen($body < self::LENTEXT && is_string($body))) { + $this->body = $body; + } + } + + public function setheader($header) + { + if (strlen($header < self::LENTEXT && is_string($header))) { + $this->header = $header; + } + } + + public function setmain($main) + { + if (strlen($main) < self::LENTEXT and is_string($main)) { + $this->main = $main; + } + } + + public function setnav($nav) + { + if (strlen($nav) < self::LENTEXT and is_string($nav)) { + $this->nav = $nav; + } + } + + public function setaside($aside) + { + if (strlen($aside) < self::LENTEXT and is_string($aside)) { + $this->aside = $aside; + } + } + + public function setexternalcss($externalcss) + { + if(is_array($externalcss)) { + $this->externalcss = array_values(array_filter($externalcss)); + } + } + + public function setcustomhead(string $customhead) + { + if(is_string($customhead)) { + $this->customhead = $customhead; + } + } + + public function setfooter($footer) + { + if (strlen($footer) < self::LENTEXT and is_string($footer)) { + $this->footer = $footer; + } + } + + public function setsecure($secure) + { + if ($secure >= 0 and $secure <= self::SECUREMAX) { + $this->secure = intval($secure); + } + } + + public function setinvitepassword($invitepassword) + { + if (is_string($invitepassword) && strlen($invitepassword) < self::LEN) { + $this->invitepassword = $invitepassword; + } + } + + public function setreadpassword($readpassword) + { + if (is_string($readpassword) && strlen($readpassword) < self::LEN) { + $this->readpassword = $readpassword; + } + } + + public function setinterface($interface) + { + if (in_array($interface, self::TABS)) { + $this->interface = $interface; + } + } + + public function setlinkfrom($linkfrom) + { + if (is_array($linkfrom)) { + $this->linkfrom = $linkfrom; + } elseif (is_string($linkfrom)) { + $linkfromjson = json_decode($linkfrom); + if (is_array($linkfromjson)) { + $this->linkfrom = $linkfromjson; + } + } elseif ($linkfrom === null) { + $this->linkfrom = []; + } + } + + public function setlinkto($linkto) + { + if (is_array($linkto)) { + $this->linkto = $linkto; + } elseif (is_string($linkto)) { + $linktojson = json_decode($linkto); + if (is_array($linktojson)) { + $this->linkto = $linktojson; + } + } elseif ($linkto === null) { + $this->linkto = []; + } + } + + public function settemplatebody($templatebody) + { + if (is_string($templatebody)) { + $this->templatebody = $templatebody; + } + } + + public function settemplatecss($templatecss) + { + if (is_string($templatecss)) { + $this->templatecss = $templatecss; + } + } + + public function settemplatejavascript($templatejavascript) + { + if (is_string($templatejavascript)) { + $this->templatejavascript = $templatejavascript; + } + } + + public function settemplateoptions($templateoptions) + { + if(is_array($templateoptions)) { + $this->templateoptions = array_values(array_filter($templateoptions)); + } + } + + public function setfavicon($favicon) + { + if (is_string($favicon)) { + $this->favicon = $favicon; + } + } + + public function setauthors($authors) + { + if(is_array($authors)) { + $this->authors = array_values(array_filter($authors)); + } + } + + public function setinvites($invites) + { + if(is_array($invites)) { + $this->invites = array_values(array_filter($invites)); + } + } + + public function setreaders($readers) + { + if(is_array($readers)) { + $this->readers = array_values(array_filter($readers)); + } + } + + public function setaffcount($affcount) + { + if (is_int($affcount)) { + $this->affcount = $affcount; + } elseif (is_numeric($affcount)) { + $this->affcount = intval($affcount); + } + } + + public function setvisitcount($visitcount) + { + if (is_int($visitcount)) { + $this->visitcount = $visitcount; + } elseif (is_numeric($visitcount)) { + $this->visitcount = intval($visitcount); + } + } + + public function seteditcount($editcount) + { + if (is_int($editcount)) { + $this->editcount = $editcount; + } elseif (is_numeric($editcount)) { + $this->editcount = intval($editcount); + } + } + + public function seteditby($editby) + { + if(is_array($editby)) { + $this->editby = $editby; + } + } + + + // __________________________________ C O U N T E R S ______________________________ + + + public function addeditcount() + { + $this->editcount++; + } + + public function addaffcount() + { + $this->affcount++; + } + + public function addvisitcount() + { + $this->visitcount++; + } + + public function updateedited() + { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $this->setdatemodif($now); + $this->addeditcount(); + } + + public function addauthor(string $id) + { + if(!in_array($id, $this->authors)) { + $this->authors[] = $id; + } + } + + public function addeditby(string $id) + { + $this->editby[$id] = true; + } + + public function removeeditby(string $id) + { + unset($this->editby[$id]); + } + + public function iseditedby() + { + return count($this->editby) > 0; + } + + +} + + +?> \ No newline at end of file diff --git a/app/class/Quickcss.php b/app/class/Quickcss.php new file mode 100644 index 0000000..0173763 --- /dev/null +++ b/app/class/Quickcss.php @@ -0,0 +1,293 @@ + ['left', 'right', 'center', 'justify'], + 'border-style' => ['solid', 'double', 'outset', 'ridge'], + 'font-family' => ['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy'], + 'text-decoration-line' => ['none', 'underline', 'overline', 'line-through', 'underline overline'], + 'display' => ['none', ] + ]; + + + private static function getselect() + { + return array_keys(self::OPTIONS); + } + + private static function getparams() + { + $params = array_merge(self::COLOR, self::SIZE, self::getselect(), self::UNIQUE); + sort($params, SORT_STRING ); + return $params; + } + + public function __construct($data) + { + $this->hydrate($data); } + + public function hydrate($data) + { + foreach ($data as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function calc() + { + $quickcss = $this->intersect($this->values,$this->active); + $quickcss = $this->merge($quickcss, $this->new); + $quickcss = $this->addunits($quickcss, $this->units); + $quickcss = $this->merge($this->jsoncss, $quickcss); + + $this->quickcss = $quickcss; + } + + + + // _________________________________________ P O S T __________________________________________________ + + public function setvalues($data) + { + if(is_array($data)) { + $this->values = $data; + } + } + + public function setunits($data) + { + if(is_array($data)) { + $this->units = $data; + } + } + + public function setactive($data) + { + if(is_array($data)) { + $this->active = $data; + } + } + + public function setnew($data) + { + if (!empty($data['element']) && !empty($data['param']) && in_array($data['param'], self::getparams())) { + $new = array($data['element'] => array($data['param'] => '')); + $this->new = $new; + } + } + + + public function setjson($jsoncss) + { + if(!empty($jsoncss) && is_string($jsoncss)) { + $jsoncss = json_decode($jsoncss); + if(is_array($jsoncss)) { + $this->jsoncss = $jsoncss; + } else { + $this->jsoncss = []; + } + } + } + + + // _______________________________________ C A L C ___________________________________________________ + + public function intersect($values, $active) + { + $intersect = array_intersect_key($values, $active); + + foreach ($intersect as $element => $css) { + $intersect[$element] = array_intersect_key($values[$element], $active[$element]); + } + return $intersect; + } + + public function merge($quickcss, $new) + { + $quickcss = array_merge_recursive($quickcss, $new); + return $quickcss; + } + + public function addunits($quickcss, $units) + { + foreach ($units as $element => $css) { + foreach ($css as $param => $unit) { + if (array_key_exists($element, $quickcss) && array_key_exists($param, $quickcss[$element])) { + $quickcss[$element][$param] = $quickcss[$element][$param] . $unit; + } + } + } + return $quickcss; + } + + + + // __________________________________________ C O M _________________________________________ + + public function tocss() + { + $string = ''; + foreach ($this->quickcss as $element => $css) { + $string .= PHP_EOL . $element . ' {'; + foreach ($css as $param => $value) { + $string .= PHP_EOL . ' ' . $param . ': ' . $value . ';'; + } + $string .= PHP_EOL . '}' . PHP_EOL; + } + return $string; + } + + public function tojson() + { + return json_encode($this->quickcss); + } + + + + + // _____________________________________________ F O R M ____________________________________________ + + public function form($action) + { + echo '
    '; + echo '
    '; + $this->inputs($this->quickcss); + echo '
    '; + echo '
    '; + + } + + public function inputs($quickcss) + { + echo '

    Add element

    '; + + echo ''; + echo ''; + foreach (array_keys($quickcss) as $element) { + echo ''; + + echo ''; + + foreach ($quickcss as $element => $css) { + echo '

    ' . $element . '

    '; + foreach ($css as $param => $value) { + + echo '
    '; + echo ''; + echo ''; + echo '
    '; + + echo '
    '; + + if (in_array($param, self::COLOR)) { + echo ''; + } + + if (in_array($param, self::SIZE)) { + $this->sizeinput($element, $param, $value); + } + + if (in_array($param, self::getselect())) { + $this->selectinput($element, $param, $value); + } + + if (in_array($param, self::UNIQUE)) { + $method = str_replace('-', '', $param) . 'input'; + if (method_exists($this, $method)) { + $this->$method($element, $param, $value); + } + } + + echo '
    '; + } + } + + + } + + + + + + + // ____________________________________ I N P U T __________________________________ + + public function sizeinput($element, $param, $value) + { + echo ''; + + $unit = preg_replace('/\d/', '', $value); + ?> + + '; + + $unit = preg_replace('/\d/', '', $value); + ?> + + '; + } + + public function selectinput($element, $param, $value) + { + echo ''; + } + + +} + + + +?> \ No newline at end of file diff --git a/app/class/Record.php b/app/class/Record.php new file mode 100644 index 0000000..381f10a --- /dev/null +++ b/app/class/Record.php @@ -0,0 +1,118 @@ +hydrate($donnees); + } + + public function hydrate(array $donnees) + { + foreach ($donnees as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + + +// _________________________________________________ G E T ____________________________________________________ + + public function id() + { + return $this->id; + } + + public function path() + { + return $this->path; + } + + public function extension() + { + return $this->extension; + } + + public function size() + { + return $this->size; + } + + public function datetime() + { + return $this->datetime; + } + + public function number() + { + return $this->number; + } + +// ___________________________________________________ S E T __________________________________________________ + + public function setid($id) + { + if (strlen($id) < 100 and is_string($id)) { + $this->id = strip_tags(strtolower($id)); + } + } + + public function setpath($path) + { + if (strlen($path) < 40 and is_string($path)) { + $this->path = strip_tags(strtolower($path)); + } + } + + public function setextension($extension) + { + if (strlen($extension) < 7 and is_string($extension)) { + $this->extension = strip_tags(strtolower($extension)); + } + } + + public function setsize($size) + { + if (40 and is_int($size)) { + $this->size = strip_tags(strtolower($size)); + } + } + + public function setdatetime($datetime) + { + if (is_int($datetime)) { + $this->datetime = strip_tags(strtolower($datetime)); + } + } + + public function setnumber($number) + { + if (is_int($number)) { + $this->number = strip_tags(strtolower($number)); + } + } + + + + + +} + +?> \ No newline at end of file diff --git a/app/class/Route.php b/app/class/Route.php new file mode 100644 index 0000000..4f2a6de --- /dev/null +++ b/app/class/Route.php @@ -0,0 +1,86 @@ +hydrate($vars); + } + + public function hydrate($vars) + { + foreach ($vars as $var => $value) { + $method = 'set' . $var; + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function toarray() + { + $array = []; + if (!empty($this->id)) { + $array[] = 'page'; + } + if (!empty($this->aff)) { + $array[] = 'aff='.$this->aff; + } + if (!empty($this->action)) { + $array[] = 'action=' . $this->action; + } + if (!empty($this->redirect)) { + $array[] = $this->redirect; + } + + + return $array; + } + + function tostring() + { + return implode(' ', $this->toarray()); + } + + + + public function setid($id) + { + $this->id = $id; + } + + public function setaff($aff) + { + $this->aff = $aff; + + } + + public function setaction($action) + { + $this->action = $action; + } + + public function setredirect($redirect) + { + $this->redirect = $redirect; + } + + public function id() + { + return $this->id; + } +} + + + + +?> \ No newline at end of file diff --git a/app/class/Routes.php b/app/class/Routes.php new file mode 100644 index 0000000..a803bd6 --- /dev/null +++ b/app/class/Routes.php @@ -0,0 +1,82 @@ +setBasePath('/' . Config::basepath()); + } + $router->addMatchTypes(array('cid' => '[a-zA-Z0-9-_+,\'!%@&.$€=\(\|\)]+')); + $router->addRoutes([ + ['GET', '/', 'Controllerhome#desktop', 'home'], + ['POST', '/', 'Controllerhome#desktop', 'homequery'], + ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], + ['GET', '//renderall', 'Controllerhome#renderall', 'homerenderall'], + ['POST', '/bookmark', 'Controllerhome#bookmark', 'homebookmark'], + ['POST', '/upload', 'Controllerpage#upload', 'pageupload'], + ['POST', '/!co', 'Controllerconnect#log', 'log'], + ['GET', '/!co', 'Controllerconnect#connect', 'connect'], + ['POST', '/!search', 'Controllerhome#search', 'search'], + ['GET', '/!media', 'Controllermedia#desktop', 'media'], + ['POST', '/!media/upload', 'Controllermedia#upload', 'mediaupload'], + ['POST', '/!media/folderadd', 'Controllermedia#folderadd', 'mediafolderadd'], + ['POST', '/!media/folderdelete', 'Controllermedia#folderdelete', 'mediafolderdelete'], + ['POST', '/!media/edit', 'Controllermedia#edit', 'mediaedit'], + ['GET', '/!font', 'Controllerfont#desktop', 'font'], + ['GET', '/!font/render', 'Controllerfont#render', 'fontrender'], + ['POST', '/!font/add', 'Controllerfont#add', 'fontadd'], + ['POST', '/!admin', 'Controlleradmin#update', 'adminupdate'], + ['GET', '/!admin', 'Controlleradmin#desktop', 'admin'], + ['GET', '/!user', 'Controlleruser#desktop', 'user'], + ['POST', '/!user/add', 'Controlleruser#add', 'useradd'], + ['POST', '/!user/update', 'Controlleruser#update', 'userupdate'], + ['POST', '/!user/pref', 'Controlleruser#pref', 'userpref'], + ['GET', '/!info', 'Controllerinfo#desktop', 'info'], + ['GET', '/!timeline', 'Controllertimeline#desktop', 'timeline'], + ['POST', '/!timeline/add', 'Controllertimeline#add', 'timelineadd'], + ['POST', '/!timeline/clap', 'Controllertimeline#clap', 'timelineclap'], + ['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(); + if ($match) { + $callableParts = explode('#', $match['target']); + $controllerName = '\\Wcms\\' . $callableParts[0]; + $methodName = $callableParts[1]; + + $controller = new $controllerName($router); + + call_user_func_array(array($controller, $methodName), $match['params']); + } + //404 + else { + if(!empty(Config::route404())) { + $controller = new Controller($router); + $controller->routedirect('pageread/', ['page' => Config::route404()]); + } else { + header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); + } + } + } +} \ No newline at end of file diff --git a/app/class/User.php b/app/class/User.php new file mode 100644 index 0000000..8712c72 --- /dev/null +++ b/app/class/User.php @@ -0,0 +1,303 @@ + false]; + + public function __construct($datas = []) + { + if (!empty($datas)) { + $this->hydrate($datas); + } + } + + public function hydrate($datas = []) + { + foreach ($datas as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function dry() + { + $array = []; + foreach (get_class_vars(__class__) as $var => $value) { + $array[$var] = $this->$var(); + } + return $array; + } + + + // _________________________ G E T _______________________ + + public function id() + { + return $this->id; + } + + public function level() + { + return $this->level; + } + + public function password($type = 'string') + { + if ($type === 'int') { + return strlen($this->password); + } elseif ($type = 'string') { + return $this->password; + } + } + + public function signature() + { + return $this->signature; + } + + public function passwordhashed() + { + return $this->passwordhashed; + } + + public function cookie() + { + return $this->cookie; + } + + public function columns() + { + return $this->columns; + } + + public function connectcount() + { + return $this->connectcount; + } + + public function expiredate(string $type = 'string') + { + if ($type == 'string') { + if(!empty($this->expiredate)) { + return $this->expiredate->format('Y-m-d'); + } else { + return false; + } + } elseif ($type == 'date') { + if(!empty($this->expiredate)) { + return $this->expiredate; + } else { + return false; + } + } elseif ($type == 'hrdi') { + if(empty($this->expiredate)) { + return 'never'; + } else { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + if($this->expiredate < $now) { + return 'expired'; + } else { + return hrdi($this->expiredate->diff($now)); + } + } + } + } + + public function bookmark() + { + return $this->bookmark; + } + + public function display() + { + return $this->display; + } + + + // _______________________ S E T _______________________ + + public function setid($id) + { + $id = idclean($id); + if (strlen($id) < Model::MAX_ID_LENGTH and is_string($id)) { + $this->id = $id; + } + } + + public function setlevel($level) + { + $level = intval($level); + if ($level >= 0 && $level <= 10) { + $this->level = $level; + } + } + + public function setpassword($password) + { + if (!empty($password) && is_string($password)) { + $this->password = $password; + } + + } + + public function setsignature(string $signature) + { + if (strlen($signature) <= 128) { + $this->signature = $signature; + } + } + + public function setpasswordhashed($passwordhashed) + { + $this->passwordhashed = boolval($passwordhashed); + + } + + public function setcookie($cookie) + { + $cookie = abs(intval($cookie)); + if($cookie >= 365) {$cookie = 365;} + $this->cookie = $cookie; + } + + public function setcolumns($columns) + { + if(is_array($columns)) { + $columns = array_filter(array_intersect(array_unique($columns), Model::COLUMNS)); + $this->columns = $columns; + } + } + + public function setconnectcount($connectcount) + { + if(is_int($connectcount) && $connectcount >= 0) { + $this->connectcount = $connectcount; + } + } + + public function setexpiredate($expiredate) + { + if ($expiredate instanceof DateTimeImmutable) { + $this->expiredate = $expiredate; + } else { + $this->expiredate = DateTimeImmutable::createFromFormat('Y-m-d', $expiredate, new DateTimeZone('Europe/Paris')); + } + } + + public function setbookmark($bookmark) + { + if(is_array($bookmark)) { + $this->bookmark = $bookmark; + } + } + + public function setdisplay($display) + { + if(is_array($display)) { + $this->display = $display; + } + } + + + + + + + + //____________________________________________________ F U N ____________________________________________________ + + + + + + + + public function hashpassword() + { + $this->password = password_hash($this->password, PASSWORD_DEFAULT); + $this->passwordhashed = true; + } + + public function validpassword() + { + if(is_string($this->password)) { + if(strlen($this->password) >= Model::PASSWORD_MIN_LENGTH && strlen($this->password) <= Model::PASSWORD_MAX_LENGTH) { + return true; + } + } + return false; + } + + + + public function isvisitor() + { + return $this->level === Modeluser::FREE; + } + + public function iseditor() + { + return $this->level >= Modeluser::EDITOR; + } + + public function issupereditor() + { + return $this->level >= Modeluser::SUPEREDITOR; + } + + public function isinvite() + { + return $this->level >= Modeluser::INVITE; + } + + public function isadmin() + { + return $this->level === Modeluser::ADMIN; + } + + + public function connectcounter() + { + $this->connectcount ++; + } + + public function addbookmark(string $id, string $query) + { + if(!empty($id) && !empty($query)) { + $id = idclean($id); + $id = substr($id, 0, 16); + $this->bookmark[$id] = $query; + } + } + + public function deletebookmark(string $id) + { + if(key_exists($id, $this->bookmark)) { + unset($this->bookmark[$id]); + } + } + + +} + + + +?> \ No newline at end of file diff --git a/app/class/application.php b/app/class/application.php deleted file mode 100644 index 784a388..0000000 --- a/app/class/application.php +++ /dev/null @@ -1,144 +0,0 @@ -usermanager = new Modeluser(); - } - - public function wakeup() - { - if(isset($_POST['configinit'])) { - if(Config::readconfig()) { - Config::createconfig($_POST['configinit']); - } else { - Config::hydrate($_POST['configinit']); - } - Config::getdomain(); - if(!is_dir(Model::RENDER_DIR)) { - mkdir(Model::RENDER_DIR); - } - if(!Config::savejson()) { - echo 'Cant write config file'; - exit; - } else{ - header('Location: ./'); - exit; - } - } elseif(isset($_POST['userinit']) && !empty($_POST['userinit']['id']) && !empty($_POST['userinit']['password'])) { - $userdata = $_POST['userinit']; - $userdata['level'] = 10; - $user = new User($userdata); - $this->usermanager->add($user); - header('Location: ./'); - exit; - - } else { - if(Config::readconfig()) { - if(!Config::checkbasepath() || empty(Config::pagetable()) || !is_dir(Model::RENDER_DIR) || !Config::checkdomain()) { - echo '
      '; - if(!Config::checkbasepath()) { - echo '
    • Wrong path
    • '; - } - if(empty(Config::pagetable())) { - echo '
    • Unset table name
    • '; - } - if(!Config::checkdomain()) { - echo '
    • Need to recheck the domain
    • '; - } - if(!is_dir(Model::RENDER_DIR)) { - echo '
    • Render path not existing
    • '; - } - echo '
    '; - $this->configform(); - exit; - } else { - if($this->usermanager->admincount() === 0) { - echo 'missing admin user'; - $this->adminform(); - exit; - } - } - } else { - echo 'Missing config file'; - $this->configform(); - exit; - } - } - } - - public function configform() - { - ?> -

    Configuration

    - -

    Version :

    - -

    - -
    -
    -

    - -

    - -

    Leave it empty if W-CMS is in your root folder, otherwise, indicate the subfolder(s) in witch you installed the CMS

    -
    -
    -

    - -

    - -

    Set the name of the first folder that is going to store all your work

    -
    - -
    - - - -
    -
    -

    - -

    - -

    Your user id as the first administrator.

    -
    -
    -

    - -

    - -

    Your user passworder as first administrator.

    -
    - -
    - - \ No newline at end of file diff --git a/app/class/config.php b/app/class/config.php deleted file mode 100644 index 3d67908..0000000 --- a/app/class/config.php +++ /dev/null @@ -1,464 +0,0 @@ - $value) { - $method = 'set' . $key; - if (method_exists(get_called_class(), $method)) { - self::$method($value); - } - } - } - - public static function readconfig() - { - if (file_exists(Model::CONFIG_FILE)) { - $current = file_get_contents(Model::CONFIG_FILE); - $datas = json_decode($current, true); - self::hydrate($datas); - return true; - } else { - return false; - } - } - - public static function createconfig(array $datas) - { - self::hydrate($datas); - } - - - public static function savejson() - { - $json = self::tojson(); - return file_put_contents(Model::CONFIG_FILE, $json); - } - - - public static function tojson() - { - $arr = get_class_vars(__class__); - $json = json_encode($arr, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT); - return $json; - } - - public static function checkbasepath() - { - $path = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . self::basepath() . DIRECTORY_SEPARATOR . Model::CONFIG_FILE; - return (file_exists($path)); - } - - /** - * Calculate Domain name - */ - public static function getdomain() - { - self::$domain = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']; - } - - /** - * Verify Domain name - */ - public static function checkdomain() - { - return (self::$domain === $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']); - } - - /** - * Generate full url adress where W is installed - * @return string url adress finished by a slash "/" - */ - public static function url($endslash = true) : string - { - return self::$domain . (!empty(self::$basepath) ? '/' . self::$basepath : "") . ($endslash ? '/' : ''); - } - -// ________________________________________ G E T _______________________________________ - - public static function pagetable() - { - return self::$pagetable; - } - - public static function domain() - { - return self::$domain; - } - - public static function fontsize() - { - return self::$fontsize; - } - - public static function basepath() - { - return self::$basepath; - } - - public static function route404() - { - return self::$route404; - } - - public static function alerttitle() - { - return self::$alerttitle; - } - - public static function alertlink() - { - return self::$alertlink; - } - - public static function alertlinktext() - { - return self::$alertlinktext; - } - - public static function existnot() - { - return self::$existnot; - } - - public static function private() - { - return self::$private; - } - - public static function notpublished() - { - return self::$notpublished; - } - - public static function existnotpass() - { - return self::$existnotpass; - } - - public static function privatepass() - { - return self::$privatepass; - } - - public static function notpublishedpass() - { - return self::$notpublishedpass; - } - - public static function alertcss() - { - return self::$alertcss; - } - - public static function defaultbody() - { - return self::$defaultbody; - } - - public static function defaultpage() - { - return self::$defaultpage; - } - - public static function defaultfavicon() - { - return self::$defaultfavicon; - } - - public static function analytics() - { - return self::$analytics; - } - - public static function externallinkblank() - { - return self::$externallinkblank; - } - - public static function internallinkblank() - { - return self::$internallinkblank; - } - - public static function reccursiverender() - { - return self::$reccursiverender; - } - - public static function defaultprivacy() - { - return self::$defaultprivacy; - } - - public static function homepage() - { - return self::$homepage; - } - - public static function homeredirect() - { - return self::$homeredirect; - } - - public static function interfacecss() - { - return self::$interfacecss; - } - - public static function bookmark() - { - return self::$bookmark; - } - - -// __________________________________________ S E T ______________________________________ - - public static function setpagetable($pagetable) - { - self::$pagetable = strip_tags($pagetable); - } - - public static function setdomain($domain) - { - self::$domain = strip_tags(strtolower($domain)); - } - - public static function setfontsize($fontsize) - { - $fontsize = intval($fontsize); - if ($fontsize > 1) { - self::$fontsize = $fontsize; - } - } - - public static function setbasepath($basepath) - { - self::$basepath = strip_tags($basepath); - } - - public static function setroute404($id) - { - if(is_string($id)) { - self::$route404 = idclean($id); - } - } - - public static function setalerttitle($alerttitle) - { - if(is_string($alerttitle)) { - self::$alerttitle = strip_tags($alerttitle); - } - } - - public static function setalertlink($alertlink) - { - if(is_string($alertlink)) { - self::$alertlink = idclean(strip_tags($alertlink)); - } - } - - public static function setalertlinktext($alertlinktext) - { - if(is_string($alertlinktext)) { - self::$alertlinktext = strip_tags($alertlinktext); - } - } - - public static function setexistnot($existnot) - { - if(is_string($existnot)) { - self::$existnot = strip_tags($existnot); - } - } - - public static function setprivate($private) - { - if(is_string($private)) { - self::$private = strip_tags($private); - } - } - - public static function setnotpublished($notpublished) - { - if(is_string($notpublished)) { - self::$notpublished = strip_tags($notpublished); - } - } - - public static function setexistnotpass($existnotpass) - { - self::$existnotpass = boolval($existnotpass); - } - - public static function setprivatepass($privatepass) - { - self::$privatepass = boolval($privatepass); - } - - public static function setnotpublishedpass($notpublishedpass) - { - self::$notpublishedpass = boolval($notpublishedpass); - } - - public static function setalertcss($alertcss) - { - self::$alertcss = boolval($alertcss); - } - - public static function setdefaultbody($defaultbody) - { - if(is_string($defaultbody)) { - self::$defaultbody = $defaultbody; - } - } - - public static function setdefaultfavicon($defaultfavicon) - { - if(is_string($defaultfavicon)) { - self::$defaultfavicon = $defaultfavicon; - } - } - - public static function setdefaultpage($defaultpage) - { - if(is_string($defaultpage)) { - self::$defaultpage = idclean($defaultpage); - } - } - - public static function setanalytics($analytics) - { - if(is_string($analytics) && strlen($analytics) < 25) { - self::$analytics = $analytics; - } - } - - public static function setexternallinkblank($externallinkblank) - { - self::$externallinkblank = boolval($externallinkblank); - } - - public static function setinternallinkblank($internallinkblank) - { - self::$internallinkblank = boolval($internallinkblank); - } - - public static function setreccursiverender($reccursiverender) - { - self::$reccursiverender = boolval($reccursiverender); - } - - public static function setdefaultprivacy($defaultprivacy) - { - $defaultprivacy = intval($defaultprivacy); - if($defaultprivacy >= 0 && $defaultprivacy <= 2) { - self::$defaultprivacy = $defaultprivacy; - } - } - - public static function sethomepage($homepage) - { - if(in_array($homepage, Model::HOMEPAGE)) { - self::$homepage = $homepage; - } - } - - public static function sethomeredirect($homeredirect) - { - if(is_string($homeredirect) && strlen($homeredirect) > 0) { - self::$homeredirect = idclean($homeredirect); - } else { - self::$homeredirect = null; - } - } - - public static function setinterfacecss($interfacecss) - { - if(is_string($interfacecss) && file_exists(Model::CSS_DIR . $interfacecss)) { - self::$interfacecss = $interfacecss; - } else { - self::$interfacecss = null; - } - } - - public static function setbookmark($bookmark) - { - if(is_array($bookmark)) { - self::$bookmark = $bookmark; - } - } - - - - - - - // ______________________________________ F U N _________________________________________ - - public static function addbookmark(string $id, string $query) - { - if(!empty($id) && !empty($query)) { - $id = idclean($id); - $id = substr($id, 0, 16); - self::$bookmark[$id] = $query; - } - } - - public static function deletebookmark(string $id) - { - if(key_exists($id, self::$bookmark)) { - unset(self::$bookmark[$id]); - } - } - - - - -} - - - - - - - - - -?> \ No newline at end of file diff --git a/app/class/controller.php b/app/class/controller.php deleted file mode 100644 index a5bd33b..0000000 --- a/app/class/controller.php +++ /dev/null @@ -1,100 +0,0 @@ -setuser(); - $this->router = $router; - $this->pagemanager = new Modelpage(); - $this->initplates(); - $this->now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - } - - public function setuser() - { - $this->usermanager = new Modeluser; - $this->user = $this->usermanager->readsession(); - } - - public function initplates() - { - $router = $this->router; - $this->plates = new League\Plates\Engine(Model::TEMPLATES_DIR); - $this->plates->registerFunction('url', function (string $string, array $vars = []) use ($router) { - return $router->generate($string, $vars); - }); - $this->plates->registerFunction('upage', function (string $string, string $id) use ($router) { - return $router->generate($string, ['page' => $id]); - }); - } - - public function showtemplate($template, $params) - { - $params = array_merge($this->commonsparams(), $params); - echo $this->plates->render($template, $params); - } - - public function commonsparams() - { - $commonsparams = []; - $commonsparams['router'] = $this->router; - $commonsparams['user'] = $this->user; - $commonsparams['pagelist'] = $this->pagemanager->list(); - $commonsparams['css'] = Model::csspath(); - return $commonsparams; - } - - - - - - public function redirect($url) - { - header('Location: ' . $url); - } - - public function routedirect(string $route, array $vars = []) - { - $this->redirect($this->router->generate($route, $vars)); - } - - public function routedirectget(string $route, array $vars = []) - { - $get = '?'; - foreach ($vars as $key => $value) { - $get .= $key .'='. $value. '&'; - } - $get = rtrim($get, '&'); - $this->redirect($this->router->generate($route, []) . $get); - } - - public function error(int $code) - { - http_response_code($code); - exit; - } - -} - - - - - -?> \ No newline at end of file diff --git a/app/class/controlleradmin.php b/app/class/controlleradmin.php deleted file mode 100644 index dda0a54..0000000 --- a/app/class/controlleradmin.php +++ /dev/null @@ -1,67 +0,0 @@ -user->isadmin()) { - $pagelist = $this->pagemanager->list(); - $this->mediamanager = new Modelmedia(); - $faviconlist = $this->mediamanager->listfavicon(); - $interfacecsslist = $this->mediamanager->listinterfacecss(); - if(in_array(Config::defaultpage(), $pagelist)) { - $defaultpageexist = true; - } else { - $defaultpageexist = true; - } - - $globalcssfile = Model::GLOBAL_DIR . 'global.css'; - - if(is_file($globalcssfile)) { - $globalcss = file_get_contents($globalcssfile); - } else { - $globalcss = ""; - } - - $admin = ['pagelist' => $pagelist, 'defaultpageexist' => $defaultpageexist, 'globalcss' => $globalcss, 'faviconlist' => $faviconlist, 'interfacecsslist' => $interfacecsslist]; - $this->showtemplate('admin', $admin); - } else { - $this->routedirect('home'); - } - } - - public function update() - { - $this->globaldircheck(); - - $globalcss = file_put_contents(Model::GLOBAL_DIR . 'global.css', $_POST['globalcss']); - - Config::hydrate($_POST); - if(Config::savejson() !== false && $globalcss !== false) { - $this->routedirect('admin'); - } else { - echo 'Can\'t write config file or global css file'; - } - } - - - public function globaldircheck() - { - if(!is_dir(Model::GLOBAL_DIR)) { - return mkdir(Model::GLOBAL_DIR); - } else { - return true; - } - } - - -} - - - - -?> \ No newline at end of file diff --git a/app/class/controllerconnect.php b/app/class/controllerconnect.php deleted file mode 100644 index 1bd0a5a..0000000 --- a/app/class/controllerconnect.php +++ /dev/null @@ -1,76 +0,0 @@ -login($route, $id); - } elseif ($_POST['log'] === 'logout') { - $this->logout($route, $id); - } - } - } - - - public function connect() - { - if(isset($_SESSION['pageupdate'])) { - $pageupdate['route'] = 'pageedit'; - $pageupdate['id'] = $_SESSION['pageupdate']['id']; - } else { - $pageupdate = ['route' => 'home']; - } - $this->showtemplate('connect', $pageupdate); - } - - - - - - public function login($route, $id = null) - { - if (isset($_POST['pass'])) { - $this->user = $this->usermanager->passwordcheck($_POST['pass']); - if($this->user != false) { - if($this->user->expiredate() === false || $this->user->level() === 10 || $this->user->expiredate('date') > $this->now) { - $this->user->connectcounter(); - $this->usermanager->add($this->user); - $this->usermanager->writesession($this->user); - $_SESSION['workspace']['showleftpanel'] = true; - $_SESSION['workspace']['showrightpanel'] = false; - } - } - } - if ($id !== null) { - $this->routedirect($route, ['page' => $id]); - } else { - $this->routedirect($route); - } - } - - public function logout($route, $id = null) - { - $this->user = $this->usermanager->logout(); - $this->usermanager->writesession($this->user); - if ($id !== null && $route !== 'home') { - $this->routedirect($route, ['page' => $id]); - } else { - $this->routedirect($route); - } - } - - - -} - - - - - - -?> \ No newline at end of file diff --git a/app/class/controllerfont.php b/app/class/controllerfont.php deleted file mode 100644 index 8f87e3a..0000000 --- a/app/class/controllerfont.php +++ /dev/null @@ -1,54 +0,0 @@ -fontmanager = new Modelfont(); - - } - - public function desktop() - { - if($this->user->iseditor()) { - - $this->fontmanager->fontdircheck(); - - $fontlist = $this->fontmanager->getfontlist(); - - $this->showtemplate('font', ['fontlist' => $fontlist, 'fonttypes' => $this->fontmanager->getfonttypes(), 'fontfile' => Model::globalpath().'fonts.css']); - } else { - $this->routedirect('home'); - } - } - - public function render() - { - $this->fontmanager->renderfontface(); - $this->routedirect('font'); - } - - public function add() - { - if(isset($_POST['fontname'])) { - $fontname = $_POST['fontname']; - } else { - $fontname = ''; - } - $message = $this->fontmanager->upload($_FILES, 2 ** 16, $fontname); - if($message !== true) { - echo $message; - } else { - $this->render(); - } - } -} - - -?> \ No newline at end of file diff --git a/app/class/controllerhome.php b/app/class/controllerhome.php deleted file mode 100644 index d263611..0000000 --- a/app/class/controllerhome.php +++ /dev/null @@ -1,128 +0,0 @@ -modelhome = new Modelhome; - } - - - - - public function desktop() - { - if ($this->user->isvisitor() && Config::homepage() === 'redirect' && Config::homeredirect() !== null) { - $this->routedirect('pageread/', ['page' => Config::homeredirect()]); - } else { - - - - - $table = $this->modelhome->getlister(); - $this->opt = $this->modelhome->optinit($table); - - $table2 = $this->modelhome->table2($table, $this->opt); - - $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::pagetable()]; - - if (isset($_POST['query']) && $this->user->iseditor()) { - $datas = array_merge($_POST, $_SESSION['opt']); - $this->optlist = $this->modelhome->Optlistinit($table); - $this->optlist->hydrate($datas); - $vars['optlist'] = $this->optlist; - } - - $this->showtemplate('home', $vars); - } - } - - public function columns() - { - if (isset($_POST['columns']) && $this->user->iseditor()) { - $user = $this->usermanager->get($this->user->id()); - $user->hydrate($_POST); - $this->usermanager->add($user); - $this->usermanager->writesession($user); - } - $this->routedirect('home'); - } - - public function search() - { - if (isset($_POST['id']) && !empty($_POST['id'])) { - if (isset($_POST['action'])) { - switch ($_POST['action']) { - case 'read': - $this->routedirect('pageread/', ['page' => $_POST['id']]); - break; - - case 'edit': - $this->routedirect('pageedit', ['page' => $_POST['id']]); - break; - } - } - } else { - $this->routedirect('home'); - } - } - - /** - * Render every pages in the database - */ - public function renderall() - { - if ($this->user->iseditor()) { - $pagelist = $this->modelhome->getlister(); - foreach ($pagelist as $page) { - $this->renderpage($page); - $this->pagemanager->update($page); - } - } - $this->routedirect('home'); - } - - public function bookmark() - { - if ($this->user->iseditor() && isset($_POST['action']) && isset($_POST['id']) && !empty($_POST['id'])) { - if ($_POST['action'] == 'add' && isset($_POST['query'])) { - if (isset($_POST['user']) && $_POST['user'] == $this->user->id()) { - $usermanager = new Modeluser(); - $user = $usermanager->get($_POST['user']); - $user->addbookmark($_POST['id'], $_POST['query']); - $usermanager->add($user); - } else { - Config::addbookmark($_POST['id'], $_POST['query']); - Config::savejson(); - } - } elseif ($_POST['action'] == 'del') { - if(isset($_POST['user']) && $_POST['user'] == $this->user->id()) { - $usermanager = new Modeluser(); - $user = $usermanager->get($_POST['user']); - foreach ($_POST['id'] as $id) { - $user->deletebookmark($id); - } - $usermanager->add($user); - } else { - foreach ($_POST['id'] as $id) { - Config::deletebookmark($id); - } - Config::savejson(); - } - } - } - $this->routedirect('home'); - } -} - -?> diff --git a/app/class/controllerinfo.php b/app/class/controllerinfo.php deleted file mode 100644 index 82d247d..0000000 --- a/app/class/controllerinfo.php +++ /dev/null @@ -1,25 +0,0 @@ -user->iseditor()) { - $this->showtemplate('info', ['version' => getversion()]); - } - } - - - - - - -} - - -?> \ No newline at end of file diff --git a/app/class/controllermedia.php b/app/class/controllermedia.php deleted file mode 100644 index 6cde0ce..0000000 --- a/app/class/controllermedia.php +++ /dev/null @@ -1,113 +0,0 @@ -mediamanager = new Modelmedia; - - } - - public function desktop() - { - if ($this->user->iseditor()) { - - if (!$this->mediamanager->dircheck(Model::MEDIA_DIR)) { - throw new Exception("Media error : Cant create /media folder"); - } - if (!$this->mediamanager->dircheck(Model::FAVICON_DIR)) { - throw new Exception("Media error : Cant create /media/favicon folder"); - } - if (!$this->mediamanager->dircheck(Model::THUMBNAIL_DIR)) { - throw new Exception("Media error : Cant create /media/thumbnail folder"); - } - - - $dir = rtrim($_GET['path'] ?? Model::MEDIA_DIR, DIRECTORY_SEPARATOR); - $sortby = isset($_GET['sortby']) ? $_GET['sortby'] : 'id'; - $order = isset($_GET['order']) ? $_GET['order'] : '1'; - $opt = ['dir' => $dir, 'sortby' => $sortby, 'order' => $order]; - - if(is_dir($dir)) { - $medialist = $this->mediamanager->getlistermedia($dir . DIRECTORY_SEPARATOR); - $faviconlist = $this->mediamanager->getlistermedia(Model::FAVICON_DIR); - - $dirlist = $this->mediamanager->listdir(Model::MEDIA_DIR); - - $pathlist = []; - - $this->mediamanager->listpath($dirlist, '', $pathlist); - - $this->mediamanager->medialistsort($medialist, $sortby, $order); - - $this->showtemplate('media', ['medialist' => $medialist, 'faviconlist' => $faviconlist, 'dirlist' => $dirlist, 'pathlist' =>$pathlist, 'dir' => $dir, 'opt' => $opt]); - } else { - $this->routedirect('media'); - } - - } else { - $this->routedirect('home'); - } - } - - public function upload() - { - if ($this->user->iseditor()) { - $target = $_POST['dir'] ?? Model::MEDIA_DIR; - if (!empty($_FILES['file']['name'][0])) { - $this->mediamanager->multiupload('file', $target); - } - $this->redirect($this->router->generate('media') . '?path=' . $target); - } else { - $this->routedirect('home'); - } - } - - public function folderadd() - { - if ($this->user->iseditor()) { - $dir = $_POST['dir'] ?? Model::MEDIA_DIR; - $name = idclean($_POST['foldername']) ?? 'new-folder'; - $this->mediamanager->adddir($dir, $name); - } - $this->redirect($this->router->generate('media') . '?path=' . $dir . DIRECTORY_SEPARATOR . $name); - - } - - public function folderdelete() - { - if(isset($_POST['dir'])) { - if(isset($_POST['deletefolder']) && intval($_POST['deletefolder']) && $this->user->issupereditor()) { - $this->mediamanager->deletedir($_POST['dir']); - } else { - $this->redirect($this->router->generate('media') . '?path=' . $_POST['dir']); - exit; - } - } - $this->redirect($this->router->generate('media')); - } - - public function edit() - { - if($this->user->issupereditor() && isset($_POST['action']) && isset($_POST['id'])) { - if($_POST['action'] == 'delete') { - $this->mediamanager->multifiledelete($_POST['id']); - } elseif ($_POST['action'] == 'move' && isset($_POST['dir'])) { - $this->mediamanager->multimovefile($_POST['id'], $_POST['dir']); - } - } - $this->redirect($this->router->generate('media') . '?path=' . $_POST['path']); - } - - -} - - -?> \ No newline at end of file diff --git a/app/class/controllerpage.php b/app/class/controllerpage.php deleted file mode 100644 index 86aecba..0000000 --- a/app/class/controllerpage.php +++ /dev/null @@ -1,412 +0,0 @@ -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 - If(isset($_FILES)) { - $this->mediamanager->dircheck(Model::THUMBNAIL_DIR); - $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/controllertimeline.php b/app/class/controllertimeline.php deleted file mode 100644 index 7e617e1..0000000 --- a/app/class/controllertimeline.php +++ /dev/null @@ -1,56 +0,0 @@ -eventmanager = new Modeltimeline; - } - - public function desktop() - { - $eventlist = $this->eventmanager->showlast(['message'], 100, 0); - - $groupedeventlist = $this->eventmanager->group($eventlist); - - $this->showtemplate('timeline', ['eventlist' => $eventlist, 'groupedeventlist' => $groupedeventlist]); - - } - - public function add() - { - if($this->user->level() >= Modeluser::EDITOR && !empty($_POST['message'])) { - - $event = new Event($_POST); - $event->stamp(); - $event->setid($this->eventmanager->getlastfreeid()); - $this->eventmanager->add($event); - } - $this->routedirect('timeline'); - } - - public function clap() - { - if(isset($_POST['id']) && isset($_POST['clap'])) { - $event = $this->eventmanager->get(intval($_POST['id'])); - $event->addclap(); - $this->eventmanager->add($event); - } - $this->routedirect('timeline'); - - } -} - - - - - - - - -?> \ No newline at end of file diff --git a/app/class/controlleruser.php b/app/class/controlleruser.php deleted file mode 100644 index d56d999..0000000 --- a/app/class/controlleruser.php +++ /dev/null @@ -1,115 +0,0 @@ -user->iseditor()) { - $getuser = $this->usermanager->get($this->user); - if($this->user->isadmin()) { - $userlist = $this->usermanager->getlister(); - $this->showtemplate('user', ['userlist' => $userlist, 'getuser' => $getuser, 'now' => $this->now->format('Y-m-d')]); - } else { - $this->showtemplate('user', ['getuser' => $getuser]); - } - } else { - $this->routedirect('home'); - } - } - - - public function pref() - { - if($this->user->iseditor()) { - $user = $this->usermanager->get($this->user); - $user->hydrate($_POST); - $this->usermanager->add($user); - $this->routedirect('user'); - } else { - $this->routedirect('home'); - } - } - - - - - - public function add() - { - if(isset($_POST['id'])) { - $user = new User($_POST); - if(empty($user->id()) || $this->usermanager->get($user)) { - $this->routedirectget('user', ['error' => 'wrong_id']); - } elseif(empty($user->password()) || $this->usermanager->passwordexist($user->password()) || !$user->validpassword()) { - $this->routedirectget('user', ['error' => 'change_password']); - } else { - if($user->passwordhashed()) { - $user->hashpassword(); - } - $this->usermanager->add($user); - $this->routedirect('user'); - } - } - } - - public function update() - { - if($this->user->isadmin() && isset($_POST['action'])) { - switch ($_POST['action']) { - case 'delete': - $user = new User($_POST); - $user = $this->usermanager->get($user); - if($user !== false) { - if($user->id() === $this->user->id()) { - $this->showtemplate('userconfirmdelete', ['userdelete' => $user, 'candelete' => false]); - } else { - $this->showtemplate('userconfirmdelete', ['userdelete' => $user, 'candelete' => true]); - } - } else { - $this->routedirect('user'); - } - break; - - case 'confirmdelete': - $user = new User($_POST); - $this->usermanager->delete($user); - $this->routedirect('user'); - break; - - case 'update': - $user = $this->usermanager->get($_POST['id']); - $userupdate = clone $user; - $userupdate->hydrate($_POST); - if(empty($userupdate->id())) { - $this->routedirectget('user', ['error' => 'wrong_id']); - } elseif (!empty($_POST['password']) && (empty($userupdate->password()) || $this->usermanager->passwordexist($userupdate->password()) || !$userupdate->validpassword())) { - $this->routedirectget('user', ['error' => 'password_unvalid']); - } elseif (empty($userupdate->level())) { - $this->routedirectget('user', ['error' => 'wrong_level']); - } elseif ($user->level() === 10 && $userupdate->level() !== 10 && $this->user->id() === $user->id()) { - $this->routedirectget('user', ['error' => 'cant_edit_yourself']); - } else { - if($userupdate->password() !== $user->password() && $user->passwordhashed()) { - $userupdate->setpasswordhashed(false); - } - if($userupdate->passwordhashed() && !$user->passwordhashed()) { - $userupdate->hashpassword(); - } - $this->usermanager->add($userupdate); - $this->routedirect('user'); - } - } - } else { - $this->routedirect('home'); - } - } -} - - - -?> \ No newline at end of file diff --git a/app/class/dbitem.php b/app/class/dbitem.php deleted file mode 100644 index 2035316..0000000 --- a/app/class/dbitem.php +++ /dev/null @@ -1,32 +0,0 @@ - $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - - } - - public function dry() - { - $array = []; - foreach (get_object_vars($this) as $var => $value) { - if (in_array($var, $this::VAR_DATE)) { - $array[$var] = $this->$var('string'); - } else { - $array[$var] = $this->$var(); - } - } - return $array; - } -} - - -?> \ No newline at end of file diff --git a/app/class/element.php b/app/class/element.php deleted file mode 100644 index 113daad..0000000 --- a/app/class/element.php +++ /dev/null @@ -1,202 +0,0 @@ -hydrate($datas); - $this->analyse($pageid); - } - - public function hydrate($datas) - { - foreach ($datas as $key => $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - private function analyse(string $pageid) - { - if(!empty($this->options)) { - - // Replace "!" by the real page name - $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[] = $pageid; - } - if(isset($matches[4])) { - $this->params = explode(',', $matches[4]); - } - - $this->readoptions(); - - } else { - $this->sources[] = $pageid; - } - } - - private function readoptions() - { - if(!empty($this->params)) { - foreach ($this->params as $param ) { - preg_match('~([a-z0-9-_]+)(=(-?[0-9]+))?~', $param, $optionmatch); - if(isset($optionmatch[1])) { - $key = $optionmatch[1]; - } - if(isset($optionmatch[3])) { - $value = $optionmatch[3]; - } else { - $read = '

    Rendering error :

    Paramaters must have a value like : /' . $key . '=__value__ for parameter : ' . $key . '

    '; - //throw new Exception($read); - } - $method = 'set' . $key; - if (in_array($key, self::OPTIONS)) { - if (!$this->$method($value)) { - $read = '

    Rendering error :

    Invalid value input : ' . $value . ' for parameter : ' . $key . '

    '; - //throw new Exception($read); - - } - } else { - $read = '

    Rendering error :

    Parameter name : ' . $optionmatch[1] . ' does not exist

    '; - //throw new Exception($read); - } - } - } - } - - public function addtags() - { - $this->content = PHP_EOL . '<' . $this->type() . '>' . PHP_EOL . $this->content() . PHP_EOL . 'type() . '>' . PHP_EOL; - } - - - - - - // __________________________________________________ G E T ____________________________________________________________ - - - public function fullmatch() - { - return $this->fullmatch; - } - - public function type() - { - return $this->type; - } - - public function options() - { - return $this->options; - } - - public function params() - { - return $this->params; - } - - public function sources() - { - return $this->sources; - } - - public function autolink() - { - return $this->autolink; - } - - public function markdown() - { - return $this->markdown; - } - - public function content() - { - return $this->content; - } - - - - - - - // __________________________________________________ S E T ____________________________________________________________ - - - public function setfullmatch(string $fullmatch) - { - $this->fullmatch = $fullmatch; - } - - public function settype(string $type) - { - $type = strtolower($type); - if(in_array($type, Model::TEXT_ELEMENTS)) { - $this->type = $type; - } - } - - public function setoptions(string $options) - { - if(!empty($options)) { - $this->options = $options; - } - } - - public function setautolink(int $level) - { - if($level >= 0 && $level <= 16) { - $this->autolink = $level; - return true; - } else { - return false; - } - } - - public function setmarkdown(int $level) - { - if($level >= 0 && $level <= 1) { - $this->markdown = $level; - return true; - } else { - return false; - } - } - - public function setcontent(string $content) - { - $this->content = $content; - } - -} - - - - -?> \ No newline at end of file diff --git a/app/class/event.php b/app/class/event.php deleted file mode 100644 index ddf177b..0000000 --- a/app/class/event.php +++ /dev/null @@ -1,156 +0,0 @@ -hydrate($datas); - } - - public function stamp() - { - $this->date = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - $this->user = idclean($this->user); - if (in_array($this->type, self::EVENT_ART)) { - $this->target = idclean($this->target); - } elseif ($this->type === 'message') { - $this->message = htmlspecialchars($this->message); - } - } - - public function addclap() - { - $this->clap ++; - } - - // _____________________ G E T __________________________ - - public function id() - { - return $this->id; - } - - public function date($type = 'datetime') - { - switch ($type) { - case 'datetime': - return $this->date; - break; - - case 'string': - return $this->date->format(DateTime::ISO8601); - break; - - case 'hrdi': - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->date->diff($now)); - break; - - } - } - - public function type() - { - return $this->type; - } - - public function user() - { - return $this->user; - } - - public function target() - { - return $this->target; - } - - public function message() - { - return $this->message; - } - - public function clap() - { - return $this->clap; - } - - - - // ________________________ S E T ____________________ - - public function setid($id) - { - if (is_int($id)) { - $this->id = $id; - } - } - - public function setdate($date) - { - if ($date instanceof DateTimeImmutable) { - $this->date = $date; - } elseif (is_string($date)) { - $this->date = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $date, new DateTimeZone('Europe/Paris')); - } - } - - public function settype($type) - { - if (in_array($type, self::EVENT_TYPES)) { - $this->type = $type; - } - } - - public function setuser($user) - { - if (is_string($user) && strlen($user) < Model::MAX_ID_LENGTH) { - $this->user = $user; - } - } - - public function settarget($target) - { - if (is_string($target) && strlen($target) < Model::MAX_ID_LENGTH) { - $this->target = $target; - } - } - - public function setmessage($message) - { - if (is_string($message) && strlen($message) < self::MESSAGE_MAX_LENGTH) { - $this->message = $message; - } - } - - public function setclap($clap) - { - if(is_int($clap)) { - $this->clap = $clap; - } - } - - - - - -} - - -?> \ No newline at end of file diff --git a/app/class/media.php b/app/class/media.php deleted file mode 100644 index d458a33..0000000 --- a/app/class/media.php +++ /dev/null @@ -1,231 +0,0 @@ -hydrate($donnees); - } - - public function hydrate(array $donnees) - { - foreach ($donnees as $key => $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - - public function analyse() - { - $this->settype(); - - $filepath = $this->path . $this->id . '.' . $this->extension; - - $this->size = filesize($filepath); - - if ($this->type == 'image') { - list($width, $height, $type, $attr) = getimagesize($filepath); - $this->width = $width; - $this->height = $height; - } - - - } - - - public function getfullpath() - { - if(!empty(Config::basepath())) { - $base = '/' . Config::basepath(); - } else { - $base = ''; - } - $fullpath = $base . '/'. $this->path() . $this->id() . '.' . $this->extension(); - $fullpath = str_replace('\\', '/', $fullpath); - return $fullpath; - } - - public function getincludepath() - { - $includepath = $this->path() . $this->id() . '.' . $this->extension(); - $includepath = str_replace('\\', '/', $includepath); - $includepath = substr($includepath, 6); - return $includepath; - } - - public function getfulldir() - { - return $this->path . $this->id . '.' . $this->extension; - } - - /** - * Generate html code depending on media type - * - * @return string html code - */ - public function getcode() : string - { - switch ($this->type) { - case 'image': - $code = '![' . $this->id . '](' . $this->getincludepath() . ')'; - break; - - case 'other': - $code = '[' . $this->id . '](' . $this->getincludepath() . ')'; - break; - - case 'sound': - $code = '<audio controls src="' . $this->getincludepath() . '"></audio>'; - break; - - case 'video': - $code = '<video controls=""><source src="' . $this->getincludepath() . '" type="video/' . $this->extension . '"></video>'; - break; - - } - - return $code; - - } - - - -// _________________________________________________ G E T ____________________________________________________ - - public function id() - { - return $this->id; - } - - public function path() - { - return $this->path; - } - - public function extension() - { - return $this->extension; - } - - public function type() - { - return $this->type; - } - - public function size($display = 'binary') - { - if($display == 'hr') { - return readablesize($this->size); - } else { - return $this->size; - } - } - - public function width() - { - return $this->width; - } - - public function height() - { - return $this->height; - } - - public function length() - { - return $this->length; - } - -// ___________________________________________________ S E T __________________________________________________ - - public function setid($id) - { - if (is_string($id)) { - $this->id = $id; - } - } - - public function setpath($path) - { - if (strlen($path) < 40 and is_string($path)) { - $this->path = strip_tags(strtolower($path)); - } - } - - public function setextension($extension) - { - if (strlen($extension) < 7 and is_string($extension)) { - $this->extension = strip_tags(strtolower($extension)); - } - } - - public function settype() - { - if (isset($this->extension)) { - if (in_array($this->extension, $this::IMAGE)) { - $this->type = "image"; - } elseif (in_array($this->extension, $this::SOUND)) { - $this->type = "sound"; - } elseif (in_array($this->extension, $this::VIDEO)) { - $this->type = "video"; - } else { - $this->type = "other"; - } - } - } - - public function setsize($size) - { - if (40 and is_int($size)) { - $this->size = strip_tags(strtolower($size)); - } - } - - public function setwidth($width) - { - if (is_int($width)) { - $this->width = strip_tags(strtolower($width)); - } - } - - public function setheight($height) - { - if (is_int($height)) { - $this->height = strip_tags(strtolower($height)); - } - } - - public function setlength($length) - { - if ($this->type == 'sound') { - $this->length = $length; - } - } - - - - - - -} diff --git a/app/class/medialist.php b/app/class/medialist.php deleted file mode 100644 index 156ee2e..0000000 --- a/app/class/medialist.php +++ /dev/null @@ -1,153 +0,0 @@ -hydrate($datas); - $this->readoptions(); - $this->generatecontent(); - } - - public function hydrate($datas) - { - foreach ($datas as $key => $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - public function readoptions() - { - parse_str($this->options, $datas); - $this->hydrate($datas); - } - - public function generatecontent() - { - $mediamanager = new Modelmedia(); - $medialist = $mediamanager->getlistermedia(Model::MEDIA_DIR . $this->path . '/'); - if (!$medialist) { - $this->content = 'RENDERING ERROR : path : ' . Model::MEDIA_DIR . $this->path . '/ does not exist'; - return false; - } else { - - $mediamanager->medialistsort($medialist, $this->sortby, $this->order); - - $dirid = str_replace('/', '-', $this->path); - - $div = '

    ' . PHP_EOL; - - foreach ($medialist as $media) { - $div .= '
    '; - if ($media->type() == 'image') { - $div .= '' . $media->id() . ''; - } elseif ($media->type() == 'sound') { - $div .= '
    ' . PHP_EOL; - } - - $div .= '
    ' . PHP_EOL; - - $this->content = $div; - - return true; - } - } - - - // __________________________________________________ G E T ____________________________________________________________ - - - public function fullmatch() - { - return $this->fullmatch; - } - - public function options() - { - return $this->options; - } - - public function content() - { - return $this->content; - } - - - - // __________________________________________________ S E T ____________________________________________________________ - - - public function setfullmatch(string $fullmatch) - { - $this->fullmatch = $fullmatch; - } - - - public function setoptions(string $options) - { - if (!empty($options)) { - $this->options = $options; - } - } - - public function setpath(string $path) - { - $this->path = $path; - } - - public function setsortby(string $sortby) - { - if (in_array($sortby, self::SORT_BY_OPTIONS)) { - $this->sortby = $sortby; - } - } - - public function setorder(int $order) - { - if ($order === -1 || $order === 1) { - $this->order = $order; - } - } -} diff --git a/app/class/model.php b/app/class/model.php deleted file mode 100644 index 45ac2d1..0000000 --- a/app/class/model.php +++ /dev/null @@ -1,112 +0,0 @@ -getlister(); - - $pagelist2 = []; - foreach ($pagelist as $page) { - $page->setlinkfrom($this->analyselinkfrom($page)); - $pagelist2[] = $page; - } - foreach ($pagelist2 as $page) { - $page->setlinkto($this->analyselinkto($page->id(), $pagelist)); - $this->update($page); - } - } - - - public function analyse(Page $page) - { - $page->setlinkfrom($this->analyselinkfrom($page)); - - $pagelist = $this->getlister(); - $page->setlinkto($this->analyselinkto($page->id(), $pagelist)); - - return $page; - } - - - - - public function analyselinkto($id, $pagelist) - { - //analyse les liens vers cet pageicle en fouillant tout les linkfrom de la bdd, génere un tableau à stocker dans l'pageicle - $linkto = []; - foreach ($pagelist as $link) { - if (in_array($id, $link->linkfrom('array')) && $id != $link->id()) { - $linkto[] = $link->id(); - } - } - return $linkto; - } - - public function analyselinkfrom(Page $page) - { - $linkfrom = []; - foreach (self::TEXT_ELEMENTS as $element) { - preg_match_all('#\]\((\?id=|=)(\w+)\)#', $page->$element(), $out); - $linkfrom = array_merge($linkfrom, $out[2]); - } - return array_unique($linkfrom); - - } - -} - - - - - - - -?> \ No newline at end of file diff --git a/app/class/modelconfig.php b/app/class/modelconfig.php deleted file mode 100644 index 7c5fc18..0000000 --- a/app/class/modelconfig.php +++ /dev/null @@ -1,39 +0,0 @@ - \ No newline at end of file diff --git a/app/class/modeldb.php b/app/class/modeldb.php deleted file mode 100644 index ef1d351..0000000 --- a/app/class/modeldb.php +++ /dev/null @@ -1,37 +0,0 @@ -dbinit(); - } - - - public function dbinit() - { - $this->database = new \JamesMoss\Flywheel\Config(Model::DATABASE_DIR, [ - 'query_class' => "\WFlywheel\Query", - 'formatter' => new \WFlywheel\Formatter\JSON, - ]); - } - - public function storeinit(string $repo) - { - $this->repo = new \WFlywheel\Repository($repo, $this->database); - } - - public function list() - { - return $this->repo->getAllIds(); - } - - - - - -} diff --git a/app/class/modelfont.php b/app/class/modelfont.php deleted file mode 100644 index 8e7645e..0000000 --- a/app/class/modelfont.php +++ /dev/null @@ -1,130 +0,0 @@ -fontlist($this->list()); - } - - public function getfonttypes() - { - $fonttypes = array_map(function ($ext) { - return '.' . $ext; - }, $this::FONT_TYPES); - return implode(', ', $fonttypes); - } - - public function renderfontface() - { - $list = $this->list(); - $fontlist = $this->fontlist($list); - $fontface = $this->fontface($fontlist); - $this->write($fontface); - } - - - public function list() - { - if ($handle = opendir(Model::FONT_DIR)) { - $list = []; - while (false !== ($entry = readdir($handle))) { - if ($entry != "." && $entry != "..") { - - $list[] = $entry; - - } - } - } - - return $list; - - } - - public function fontlist(array $list) - { - $fontlist = []; - $fonttypes = implode('|', $this::FONT_TYPES); - $regex = '#(.+)\.(' . $fonttypes . ')#'; - foreach ($list as $font) { - if (preg_match($regex, $font, $out)) { - $fontlist[] = ['id' => $out[1], 'ext' => $out[2], 'size' => filesize(Model::FONT_DIR . $font)]; - } - } - return $fontlist; - } - - public function fontface(array $fontlist) - { - $fontface = ''; - foreach ($fontlist as $font) { - $fontface .= '@font-face {' . PHP_EOL . 'font-family: ' . $font['id'] . ';' . PHP_EOL . ' src: url( ' . Model::fontpath() . $font['id'] . '.' . $font['ext'] . ');' . PHP_EOL . '}' . PHP_EOL . PHP_EOL; - } - return $fontface; - } - - - public function write(string $fontface) - { - $write = file_put_contents(Model::GLOBAL_DIR . 'fonts.css', $fontface); - if ($write !== false) { - - } - } - - public function upload(array $file, $maxsize = 2 ** 24, $id = null) - { - $message = 'runing'; - if (isset($file) and $file['font']['error'] == 0 and $file['font']['size'] < $maxsize) { - $infosfichier = pathinfo($file['font']['name']); - $extension_upload = $infosfichier['extension']; - $extensions_autorisees = $this::FONT_TYPES; - if (in_array($extension_upload, $extensions_autorisees)) { - if (!empty($id)) { - $id = strtolower(strip_tags($id)); - $id = str_replace(' ', '_', $id); - } else { - $id = $infosfichier['filename']; - } - if (!file_exists($this::FONT_DIR . $id . '.' . $extension_upload)) { - - $extension_upload = strtolower($extension_upload); - $uploadok = move_uploaded_file($file['font']['tmp_name'], $this::FONT_DIR . $id . '.' . $extension_upload); - if ($uploadok) { - $message = true; - } else { - $message = 'uploaderror'; - } - } else { - $message = 'filealreadyexist'; - - } - } - } else { - $message = 'filetoobig'; - - } - return $message; - } - - - - -} - - - - -?> \ No newline at end of file diff --git a/app/class/modelhome.php b/app/class/modelhome.php deleted file mode 100644 index d90a3d3..0000000 --- a/app/class/modelhome.php +++ /dev/null @@ -1,105 +0,0 @@ -setcol(['id', 'tag', 'linkfrom', 'linkto', 'description', 'title', 'datemodif', 'datecreation', 'date', 'secure', 'visitcount', 'editcount', 'affcount']); - $opt->settaglist($table); - $opt->setauthorlist($table); - $opt->submit(); - - return $opt; - } - - /** - * Initialise Optlist object using - * - * @param array $table the list of all pages objects - * - * @return Optlist Object initialized - */ - public function Optlistinit(array $table) - { - $optlist = new Optlist(Page::classvarlist()); - $optlist->settaglist($table); - $optlist->setauthorlist($table); - - return $optlist; - } - - - - - /** - * @param array $table - * @param Opt $opt - */ - public function table2($table, $opt) - { - - - $filtertagfilter = $this->filtertagfilter($table, $opt->tagfilter(), $opt->tagcompare()); - $filterauthorfilter = $this->filterauthorfilter($table, $opt->authorfilter(), $opt->authorcompare()); - $filtersecure = $this->filtersecure($table, $opt->secure()); - - $filter = array_intersect($filtertagfilter, $filtersecure, $filterauthorfilter); - $table2 = []; - $table2invert = []; - foreach ($table as $page) { - if (in_array($page->id(), $filter)) { - $table2[] = $page; - } else { - $table2invert[] = $page; - } - - - } - - if (!empty($opt->invert())) { - $table2 = $table2invert; - } - - $this->pagelistsort($table2, $opt->sortby(), $opt->order()); - - if($opt->limit() !== 0) { - $table2 = array_slice($table2, 0, $opt->limit()); - } - - - return $table2; - } - - /** - * @param array array of the columns to show from the user - * - * @return array assoc each key columns to a boolean value to show or not - */ - public function setcolumns(array $columns) : array - { - foreach (Model::COLUMNS as $col) { - if(in_array($col, $columns)) { - $showcols[$col] = true; - } else { - $showcols[$col] = false; - } - } - return $showcols; - } -} - - - - - - - - -?> \ No newline at end of file diff --git a/app/class/modelmassedit.php b/app/class/modelmassedit.php deleted file mode 100644 index e69de29..0000000 diff --git a/app/class/modelmedia.php b/app/class/modelmedia.php deleted file mode 100644 index 8cd0224..0000000 --- a/app/class/modelmedia.php +++ /dev/null @@ -1,318 +0,0 @@ - str_replace('.' . $fileinfo['extension'], '', $fileinfo['filename']), - 'path' => $dir, - 'extension' => $fileinfo['extension'] - ); - return new Media($datas); - } else { - return false; - } - } - - /** - * Display a list of media - * - * @param string $path - * @param string $sortby - * @param string $order - * - * @return array of Media objects - */ - public function getlistermedia($dir, $type = "all") - { - if (is_dir($dir)) { - if ($handle = opendir($dir)) { - $list = []; - while (false !== ($entry = readdir($handle))) { - if ($entry != "." && $entry != "..") { - - $media = $this->getmedia($entry, $dir); - - if ($media != false) { - - $media->analyse(); - - if (in_array($type, self::MEDIA_TYPES)) { - if ($media->type() == $type) { - $list[] = $media; - } - } else { - $list[] = $media; - } - } - } - } - return $list; - } - } else { - return false; - } - } - - - - public function mediacompare($media1, $media2, $method = 'id', $order = 1) - { - $result = ($media1->$method() <=> $media2->$method()); - return $result * $order; - } - - public function buildsorter($sortby, $order) - { - return function ($media1, $media2) use ($sortby, $order) { - $result = $this->mediacompare($media1, $media2, $sortby, $order); - return $result; - }; - } - - - /** - * Sort an array of media - * - * @param array $medialist - * @param string $sortby - * @param int order Can be 1 or -1 - */ - public function medialistsort(array &$medialist, string $sortby = 'id', int $order = 1): bool - { - $sortby = (in_array($sortby, self::MEDIA_SORTBY)) ? $sortby : 'id'; - $order = ($order === 1 || $order === -1) ? $order : 1; - return usort($medialist, $this->buildsorter($sortby, $order)); - } - - - - - public function listfavicon() - { - $glob = Model::FAVICON_DIR . '*.png'; - $faviconlist = glob($glob); - $faviconlist = array_map(function ($input){ - return basename($input); - }, $faviconlist); - return $faviconlist; - } - - - public function listinterfacecss() - { - $glob = Model::CSS_DIR . '*.css'; - $listinterfacecss = glob($glob); - $listinterfacecss = array_map(function ($input) { - return basename($input); - }, $listinterfacecss); - $listinterfacecss = array_diff($listinterfacecss, ['edit.css', 'home.css']); - return $listinterfacecss; - } - - - /** - * Generate an reccursive array where each folder is a array and containing a filecount in each folder - */ - public function listdir(string $dir) : array - { - $result = array(); - - $cdir = scandir($dir); - $result['dirfilecount'] = 0; - foreach ($cdir as $key => $value) { - if (!in_array($value, array(".", ".."))) { - if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) { - $result[$value] = $this->listdir($dir . DIRECTORY_SEPARATOR . $value); - } else { - $result['dirfilecount']++; - } - } - } - - return $result; - } - - /** - * Analyse reccursive array of content to generate list of path - * - * @param array $dirlist Array generated by the listdir function - * @param string $parent used to create the strings - * @param array $pathlist used by reference, must be an empty array - * - * @return array list of path as string - */ - public function listpath(array $dirlist, string $parent = '', array &$pathlist = []) - { - foreach ($dirlist as $dir => $content) { - if(is_array($content)) { - $pathlist[] = $parent . $dir . DIRECTORY_SEPARATOR; - $this->listpath($content, $parent . $dir . DIRECTORY_SEPARATOR, $pathlist); - } - } - } - - /** - * Upload single file - * - * @param string $index The file id - * @param string $destination File final destination - * @param bool|int $maxsize Max file size in octets - * @param bool|array $extensions List of authorized extensions - * @param bool $jpgrename Change the file exentension to .jpg - * - * @return bool If upload process is a succes or not - */ - function simpleupload(string $index, string $destination, $maxsize = false, $extensions = false, bool $jpgrename = false): bool - { - //Test1: if the file is corectly uploaded - if (!isset($_FILES[$index]) || $_FILES[$index]['error'] > 0) return false; - //Test2: check file size - if ($maxsize !== false && $_FILES[$index]['size'] > $maxsize) return false; - //Test3: check extension - $ext = substr(strrchr($_FILES[$index]['name'], '.'), 1); - if ($extensions !== false && !in_array($ext, $extensions)) return false; - if ($jpgrename !== false) { - $destination .= '.jpg'; - } else { - $destination .= '.' . $ext; - } - //Move to dir - return move_uploaded_file($_FILES[$index]['tmp_name'], $destination); - } - - /** - * Upload multiple files - * - * @param string $index Id of the file input - * @param string $target direction to save the files - */ - public function multiupload(string $index, string $target) - { - if ($target[strlen($target) - 1] != DIRECTORY_SEPARATOR) - $target .= DIRECTORY_SEPARATOR; - $count = 0; - foreach ($_FILES[$index]['name'] as $filename) { - $fileinfo = pathinfo($filename); - $extension = idclean($fileinfo['extension']); - $id = idclean($fileinfo['filename']); - - $tmp = $_FILES['file']['tmp_name'][$count]; - $count = $count + 1; - $temp = $target . $id . '.' . $extension; - move_uploaded_file($tmp, $temp); - $temp = ''; - $tmp = ''; - } - } - - public function adddir($dir, $name) - { - $newdir = $dir . DIRECTORY_SEPARATOR . $name; - if (!is_dir($newdir)) { - return mkdir($newdir); - } else { - return false; - } - } - - /** - * Completely delete dir and it's content - * - * @param string $dir Directory to destroy - * - * @return bool depending on operation success - */ - public function deletedir(string $dir) : bool - { - if(substr($dir, -1) !== '/') { - $dir .= '/'; - } - if(is_dir($dir)) { - return $this->deltree($dir); - } else { - return false; - } - } - - /** - * Function do reccursively delete a directory - */ - public function deltree(string $dir) - { - $files = array_diff(scandir($dir), array('.','..')); - foreach ($files as $file) { - (is_dir("$dir/$file")) ? $this->deltree("$dir/$file") : unlink("$dir/$file"); - } - return rmdir($dir); - } - - /** - * Delete a file - */ - public function deletefile(string $filedir) - { - if(is_file($filedir)) { - return unlink($filedir); - } else { - return false; - } - } - - public function multifiledelete(array $filelist) - { - foreach ($filelist as $filedir ) { - if(is_string($filedir)) { - $this->deletefile($filedir); - } - } - } - - public function movefile(string $filedir, string $dir) - { - if(substr($dir, -1) !== '/') { - $dir .= '/'; - } - if(is_file($filedir)) { - $newdir = $dir . basename($filedir); - return rename($filedir, $newdir); - } else { - return false; - } - } - - public function multimovefile(array $filedirlist, string $dir) - { - $success = []; - foreach ($filedirlist as $filedir ) { - if(is_string($filedir)) { - $success[] = $this->movefile($filedir, $dir); - } - } - if(in_array(false, $success)) { - return false; - } else { - return true; - } - } - - - -} diff --git a/app/class/modelpage.php b/app/class/modelpage.php deleted file mode 100644 index 68ccf23..0000000 --- a/app/class/modelpage.php +++ /dev/null @@ -1,320 +0,0 @@ -storeinit(Config::pagetable()); - if(!$this->dircheck(Model::HTML_RENDER_DIR)) { - throw new Exception("Media error : Cant create /render 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; - } - - - /** - * Scan database for specific pages IDs and return array of Pages objects - * - * @param array $idlist list of ID strings - * - * @return array of Page objects - */ - public function getlisterid(array $idlist = []) : array - { - $pagedatalist = $this->repo->query() - ->where('__id', 'IN', $idlist) - ->execute(); - - $pagelist = []; - foreach ($pagedatalist as $id => $pagedata) { - $pagelist[$id] = new Page($pagedata); - } - return $pagelist; - } - - /** - * Store new page in the database - * - * @param Page $page object - */ - 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 deleted file mode 100644 index 237d9b5..0000000 --- a/app/class/modelrender.php +++ /dev/null @@ -1,691 +0,0 @@ -router = $router; - $this->pagelist = $this->getlister(); - - if(Config::internallinkblank()) { - $this->internallinkblank = ' target="_blank" '; - } - - if(Config::externallinkblank()) { - $this->externallinkblank = ' target="_blank" '; - } - } - - public function upage($id) - { - return $this->router->generate('pageread/', ['page' => $id]); - } - - - /** - * Main function - * - * @param Page $page page to render - */ - public function render(Page $page) - { - $this->page = $page; - - $this->write($this->gethmtl()); - } - - /** - * Combine body and head to create html file - * - * @return string html string - */ - public function gethmtl() - { - - $head = $this->gethead(); - $body = $this->getbody($this->readbody()); - $parsebody = $this->parser($body); - - $html = '' . PHP_EOL . '' . PHP_EOL . '' . PHP_EOL . $head . PHP_EOL . '' . PHP_EOL . $parsebody . PHP_EOL . ''; - - return $html; - } - - - public function readbody() - { - if (!empty($this->page->templatebody())) { - $templateid = $this->page->templatebody(); - $templatepage = $this->get($templateid); - if($templatepage !== false) { - $body = $templatepage->body(); - } else { - $body = $this->page->body(); - $this->page->settemplatebody(''); - } - } else { - $body = $this->page->body(); - } - $body = $this->article($body); - $body = $this->automedialist($body); - $body = $this->autotaglistupdate($body); - return $body; - } - - - /** - * Analyse BODY, call the corresponding CONTENTs and render everything - * - * @param string $body as the string BODY of the page - * - * @return string as the full rendered BODY of the page - */ - public function getbody(string $body) : string - { - // Elements that can be detected - $types = ['HEADER', 'NAV', 'MAIN', 'ASIDE', 'FOOTER']; - - // First level regex - $regex = '~\%(' . implode("|", $types) . ')(\S*)\%~'; - - // Match the first level regex - preg_match_all($regex, $body, $out); - - // Create a list of all the elements that passed through the first level regex - foreach ($out[0] as $key => $match) { - $matches[$key] = ['fullmatch' => $match, 'type' => $out[1][$key], 'options' => $out[2][$key]]; - } - - - // First, analyse the synthax and call the corresponding methods - if(isset($matches)) { - foreach ($matches as $key => $match) { - $element = new Element($match, $this->page->id()); - $element->setcontent($this->getelementcontent($element)); - $element->setcontent($this->elementparser($element)); - $element->addtags(); - $body = str_replace($element->fullmatch(), $element->content(), $body); - - } - } - - - - return $body; - - } - - public function getelementcontent(Element $element) - { - $content = ''; - $subseparator = PHP_EOL . PHP_EOL; - foreach($element->sources() as $source) - { - 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; - } - } else { - $read = '

    Rendering error :

    The page ' . $source . ', called in '. $element->fullmatch() . ', does not exist yet.

    '; - //throw new Exception($read); - } - - } else { - $type = $element->type(); - $subcontent = $this->page->$type(); - } - $content .= $subseparator . $subcontent; - } - return $content . $subseparator; - } - - public function elementparser(Element $element) - { - $content = $this->article($element->content()); - $content = $this->automedialist($content); - $content = $this->pagelist($content); - $content = $this->autotaglistupdate($content); - $content = $this->date($content); - $content = $this->thumbnail($content); - if($element->autolink()) { - $content = str_replace('%LINK%', '' ,$content); - $content = $this->everylink($content, $element->autolink()); - } else { - $content = $this->taglink($content); - } - if($element->markdown()) { - $content = $this->markdown($content); - } - - return $content; - } - - - /** - * Write css javascript and html as files in the assets folder - */ - public function write(string $html) - { - 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->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->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->page->template('array'))) { - $templatejspage = $this->get($this->page->template('array')['javascript']); - file_put_contents(Model::RENDER_DIR . $templatejspage->id() . '.js', $templatejspage->javascript()); - } - } - - - - - public function gethead() - { - - $head = ''; - - $head .= '' . PHP_EOL; - $head .= '' . $this->page->title() . '' . PHP_EOL; - if (!empty($this->page->favicon())) { - $head .= ''; - } elseif (!empty(Config::defaultfavicon())) { - $head .= ''; - } - $head .= '' . PHP_EOL; - $head .= '' . PHP_EOL; - - - $head .= '' . PHP_EOL; - $head .= '' . PHP_EOL; - - if($this->page->thumbnailexist()) { - $head .= '' . PHP_EOL; - } - - $head .= '' . PHP_EOL; - - - foreach ($this->page->externalcss() as $externalcss) { - $head .= '' . PHP_EOL; - } - - 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) { - $head .= '' . PHP_EOL; - } - } - } - - $head .= PHP_EOL . $this->page->customhead() . PHP_EOL; - - - $head .= '' . PHP_EOL; - $head .= '' . PHP_EOL; - - if (!empty($this->page->templatecss())) { - $tempaltecsspage = $this->page->templatecss(); - $head .= '' . PHP_EOL; - } - $head .= '' . PHP_EOL; - - if (!empty($this->page->templatejavascript())) { - $templatejspage = $this->page->templatejavascript(); - $head .= '' . PHP_EOL; - } - if (!empty($this->page->javascript())) { - $head .= '' . PHP_EOL; - } - - if (!empty(Config::analytics())) { - - $head .= PHP_EOL . ' - - - - ' . PHP_EOL; - } - - - return $head; - } - - public function desctitle($text, $desc, $title) - { - $text = str_replace('%TITLE%', $title, $text); - $text = str_replace('%DESCRIPTION%', $desc, $text); - return $text; - } - - - public function parser(string $text) - { - $text = $this->media($text); - - $text = $this->headerid($text); - - $text = str_replace(self::SUMMARY, $this->sumparser($text), $text); - - $text = $this->wurl($text); - $text = $this->wikiurl($text); - - $text = $this->desctitle($text, $this->page->description(), $this->page->title()); - - - $text = str_replace('href="http', ' class="external" target="_blank" href="http', $text); - - $text = $this->autourl($text); - - $text = $this->authenticate($text); - - return $text; - } - - public function media(string $text) : string - { - $text = preg_replace('%(src|href)="([\w-_]+(\/([\w-_])+)*\.[a-z0-9]{1,5})"%', '$1="' . Model::mediapath() . '$2" target="_blank" class="media"', $text); - if (!is_string($text)) { - //throw new Exception('Rendering error -> media module'); - } - return $text; - } - - - public function autourl($text) - { - $text = preg_replace('#( |\R|>)(https?:\/\/((\S+)\.([^< ]+)))#', '$1externallinkblank .'>$3', $text); - return $text; - } - - public function wurl(string $text) - { - $linkfrom = []; - $rend = $this; - $text = preg_replace_callback( - '%href="([\w-]+)\/?(#?[a-z-_]*)"%', - function ($matches) use ($rend, &$linkfrom) { - $matchpage = $rend->get($matches[1]); - if (!$matchpage) { - $link = 'href="' . $rend->upage($matches[1]) . '"" title="' . Config::existnot() . '" class="internal existnot"' . $this->internallinkblank; - } else { - $linkfrom[] = $matchpage->id(); - $link = 'href="' . $rend->upage($matches[1]) . $matches[2] . '" title="' . $matchpage->description() . '" class="internal exist '. $matchpage->secure('string') .'"' . $this->internallinkblank; - } - return $link; - }, - $text - ); - $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom)); - return $text; - } - - public function wikiurl(string $text) - { - $linkfrom = []; - $rend = $this; - $text = preg_replace_callback( - '%\[([\w-]+)\/?#?([a-z-_]*)\]%', - function ($matches) use ($rend, &$linkfrom) { - $matchpage = $rend->get($matches[1]); - if (!$matchpage) { - return 'internallinkblank .' >' . $matches[1] . ''; - } else { - $linkfrom[] = $matchpage->id(); - return 'internallinkblank .' >' . $matchpage->title() . ''; - } - }, - $text - ); - $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom)); - return $text; - } - - public function headerid($text) - { - $sum = []; - $text = preg_replace_callback( - '/(.+)<\/h[1-6]>/mU', - function ($matches) use (&$sum) { - $cleanid = idclean($matches[4]); - $sum[$cleanid][$matches[1]] = $matches[4]; - return '' . $matches[4] . ''; - }, - $text - ); - $this->sum = $sum; - return $text; - } - - public function markdown($text) - { - //use Michelf\MarkdownExtra; - $fortin = new Michelf\MarkdownExtra; - // id in headers - // $fortin->header_id_func = function ($header) { - // return preg_replace('/[^\w]/', '', strtolower($header)); - // }; - $fortin->hard_wrap = true; - $text = $fortin->transform($text); - return $text; - } - - - - public function article($text) - { - $pattern = '/(\R\R|^\R|^)[=]{3,}([\w-]*)\R\R(.*)(?=\R\R[=]{3,}[\w-]*\R)/sUm'; - $text = preg_replace_callback($pattern, function ($matches) { - if (!empty($matches[2])) { - $id = ' id="' . $matches[2] . '" '; - } else { - $id = ' '; - } - return '
    ' . PHP_EOL . PHP_EOL . $matches[3] . PHP_EOL . PHP_EOL . '
    ' . PHP_EOL . PHP_EOL; - }, $text); - $text = preg_replace('/\R\R[=]{3,}([\w-]*)\R/', '', $text); - return $text; - } - - /** - * Check for media list call in the text and insert media list - * @param string $text Text to scan and replace - * - * @return string Output text - */ - public function automedialist(string $text) - { - preg_match_all('~\%MEDIA\?([a-zA-Z0-9\&=\-\/\%]*)\%~', $text, $out); - - foreach ($out[0] as $key => $match) { - $matches[$key] = ['fullmatch' => $match, 'options' => $out[1][$key]]; - } - - if(isset($matches)) { - foreach ($matches as $match) { - $medialist = new Medialist($match); - $text = str_replace($medialist->fullmatch(), $medialist->content(), $text); - } - } - return $text; - } - - - function sumparser($text) - { - preg_match_all('#(.+)#iU', $text, $out); - - - $sum = $this->sum; - - - - $sumstring = ''; - $last = 0; - foreach ($sum as $title => $list) { - foreach ($list as $h => $link) { - if ($h > $last) { - for ($i = 1; $i <= ($h - $last); $i++) { - $sumstring .= '
      '; - } - $sumstring .= '
    • ' . $link . '
    • '; - } elseif ($h < $last) { - for ($i = 1; $i <= ($last - $h); $i++) { - $sumstring .= '
    '; - } - $sumstring .= '
  • ' . $link . '
  • '; - } elseif ($h = $last) { - $sumstring .= '
  • ' . $link . '
  • '; - } - $last = $h; - } - } - for ($i = 1; $i <= ($last); $i++) { - $sumstring .= ''; - } - return $sumstring; - } - - - - public function autotaglist($text) - { - $pattern = "/\%TAG:([a-z0-9_-]+)\%/"; - preg_match_all($pattern, $text, $out); - return $out[1]; - - } - - public function autotaglistupdate($text) - { - $taglist = $this->autotaglist($text); - foreach ($taglist as $tag) { - $li = []; - foreach ($this->pagelist as $item) { - if (in_array($tag, $item->tag('array'))) { - $li[] = $item; - } - - } - $ul = '
      ' . PHP_EOL; - $this->pagelistsort($li, 'date', -1); - foreach ($li as $item) { - if ($item->id() === $this->page->id()) { - $actual = ' actualpage'; - } else { - $actual = ''; - } - $ul .= '
    • internallinkblank .' >' . $item->title() . '
    • ' . PHP_EOL; - } - $ul .= '
    ' . PHP_EOL; - - - $text = str_replace('%TAG:' . $tag . '%', $ul, $text); - - $li = array_map(function ($item) { - return $item->id(); - }, $li); - $this->linkfrom = array_unique(array_merge($this->linkfrom, $li)); - } - return $text; - } - - - public function date(string $text) - { - $page = $this->page; - $text = preg_replace_callback('~\%DATE\%~', function ($matches) use ($page) { - return ''; - }, $text); - $text = preg_replace_callback('~\%TIME\%~', function ($matches) use ($page) { - return ''; - }, $text); - - return $text; - } - - /** - * Render thumbnail of the page - * - * @param string $text Text to analyse - * - * @return string The rendered output - */ - public function thumbnail(string $text) : string - { - $img = '' . $this->page->title() . ''; - $img = PHP_EOL . $img . PHP_EOL; - $text = str_replace('%THUMBNAIL%', $img, $text); - - return $text; - } - - public function taglink($text) - { - $rend = $this; - $text = preg_replace_callback('/\%LINK\%(.*)\%LINK\%/msU', function ($matches) use ($rend) { - return $rend->everylink($matches[1], 1); - }, $text); - return $text; - } - - /** - * Autolink Function : transform every word of more than $limit characters in internal link - * - * @param string $text The input text to be converted - * - * @return string Conversion output - */ - public function everylink(string $text, int $limit) : string - { - $regex = '~([\w-_éêèùïüîçà]{' . $limit . ',})(?![^<]*>|[^<>]*<\/)~'; - $text = preg_replace_callback($regex , function ($matches) { - return '' . $matches[1] . ''; - }, $text); - return $text; - } - - - - /** - * @param string $text content to analyse and replace - * - * @return string text ouput - */ - public function authenticate(string $text) - { - $id = $this->page->id(); - $regex = '~\%CONNECT(\?dir=([a-zA-Z0-9-_]+))?\%~'; - $text = preg_replace_callback($regex, function ($matches) use ($id) { - if(isset($matches[2])) { - $id = $matches[2]; - } - $form = '
    - - - - -
    '; - return $form; - - }, $text); - return $text; - } - - /** - * Render pages list - */ - public function pagelist(string $text) : string - { - preg_match_all('~\%LIST\?([a-zA-Z0-9\]\[\&=\-\/\%]*)\%~', $text, $out); - - foreach ($out[0] as $key => $match) { - $matches[$key] = ['fullmatch' => $match, 'options' => $out[1][$key]]; - } - - $modelhome = new Modelhome(); - - if(isset($matches)) { - foreach ($matches as $match) { - $optlist = $modelhome->Optlistinit($this->pagelist); - $optlist->parsehydrate($match['options']); - $table2 = $modelhome->table2($this->pagelist, $optlist); - - $content = '
      ' . PHP_EOL ; - foreach ($table2 as $page ) { - $content .= '
    • ' . PHP_EOL; - $content .= '' . $page->title() . '' . PHP_EOL; - if($optlist->description()) { - $content .= '' . $page->description() . '' . PHP_EOL; - } - if($optlist->date()) { - $content .= '' . $page->date('pdate') . '' . PHP_EOL; - } - if($optlist->time()) { - $content .= '' . $page->date('ptime') . '' . PHP_EOL; - } - if($optlist->author()) { - $content .= $page->authors('string') . PHP_EOL; - } - $content .= '
    • '; - } - $content .= '
    '; - - $text = str_replace($match['fullmatch'], $content, $text); - } - } - return $text; - } - - - - - - - - - public function linkfrom() - { - sort($this->linkfrom); - $linkfrom = $this->linkfrom; - $this->linkfrom = []; - return $linkfrom; - } - - public function linkto() - { - $linkto = []; - foreach ($this->pagelist as $page) { - if (in_array($this->page->id(), $page->linkfrom())) { - $linkto[] = $page->id(); - } - } - return $linkto; - } - - - - -} - - - -?> \ No newline at end of file diff --git a/app/class/modeltimeline.php b/app/class/modeltimeline.php deleted file mode 100644 index fa4f709..0000000 --- a/app/class/modeltimeline.php +++ /dev/null @@ -1,139 +0,0 @@ -storeinit('timeline'); - } - - public function get(int $id) - { - $eventdata = $this->repo->findById($id); - if ($eventdata !== false) { - return new Event($eventdata); - } else { - return false; - } - } - - /** - * Retrun a list of Event objects - * - * @return array array of Event where the key is the Event id. - */ - public function getlister() : array - { - $eventlist = []; - $datalist = $this->repo->findAll(); - foreach ($datalist as $eventdata) { - $event = new Event($eventdata); - $id = intval($event->id()); - $eventlist[$id] = $event; - } - return $eventlist; - } - - - public function getlisterid(array $idlist = []) : array - { - $eventdatalist = $this->repo->query() - ->where('__id', 'IN', $idlist) - ->execute(); - - $eventlist = []; - foreach ($eventdatalist as $id => $eventdata) { - $eventlist[$id] = new Event($eventdata); - } - return $eventlist; - } - - - /** - * Store event - * - * @param Event The event to be stored in the repositery - * - * @return bool retrun true if it works, false if it fails - */ - public function add(Event $event) : bool - { - $eventdata = new \JamesMoss\Flywheel\Document($event->dry()); - $eventdata->setId($event->id()); - $result = $this->repo->store($eventdata); - return $result; - } - - /** - * Return last free id - * - * @return int id - */ - public function getlastfreeid() : int - { - $idlist = $this->list(); - - if (!empty($idlist)) { - $id = max($idlist); - $id++; - } else { - $id = 1; - } - return $id; - } - - public function group(array $events) - { - $id = 0; - $subid = 0; - $lastuser = null; - foreach ($events as $event) { - if($event->user() !== $lastuser) { - $subid = 0; - $id ++; - $groupedevents[$id]['user'] = $event->user(); - } else { - $subid ++; - } - $groupedevents[$id][$subid] = $event; - $lastuser = $event->user(); - } - return $groupedevents; - } - - public function showlast(array $types, int $qty = 25, int $offset = 0) - { - $types = array_intersect($types, $this->types()); - - $eventdatalist = $this->repo->query() - ->where('type', 'IN', $types) - ->orderBy('date DESC') - ->limit($qty, $offset) - ->execute(); - - $eventlist = []; - foreach ($eventdatalist as $id => $eventdata) { - $eventlist[] = new Event($eventdata); - } - - $eventlist = array_reverse($eventlist); - return $eventlist; - } - - - public function types() - { - return array_merge(self::EVENT_ART, self::EVENT_BASE, self::EVENT_MEDIA, self::EVENT_MEDIA); - } - - -} - - -?> \ No newline at end of file diff --git a/app/class/modeluser.php b/app/class/modeluser.php deleted file mode 100644 index 893a608..0000000 --- a/app/class/modeluser.php +++ /dev/null @@ -1,192 +0,0 @@ -storeinit(self::USER_REPO_NAME); - } - - public function writesession(User $user) - { - $_SESSION['user' . Config::basepath()] = ['level' => $user->level(), 'id' => $user->id(), 'columns' =>$user->columns()]; - } - - public function writecookie(User $user) - { - $cookiehash = - $cookie = ['level' => $user->level(), 'id' => $user->id()]; - setcookie('user ' . Config::basepath(), $cookie, time() + $user->cookie()*24*3600, null, null, false, true); - } - - public function readsession() - { - $userdatas = []; - if (array_key_exists('user' . Config::basepath(), $_SESSION) && isset($_SESSION['user' . Config::basepath()]['id'])) { - $userdatas = $_SESSION['user' . Config::basepath()]; - $user = new User($userdatas); - $user = $this->get($user); - return $user; - } else { - return new User(['id' => '', 'level' => 0]); - } - } - - - public function logout() - { - $user = new User(['level' => self::FREE]); - return $user; - } - - - - /** - * @return array list of User objects - */ - public function getlister() - { - $userlist = []; - $list = $this->repo->findAll(); - foreach ($list as $userdata) { - $userlist[$userdata->id] = new User($userdata); - } - return $userlist; - } - - - public function getlisterid(array $idlist = []) - { - $userdatalist = $this->repo->query() - ->where('__id', 'IN', $idlist) - ->execute(); - - $userlist = []; - foreach ($userdatalist as $id => $userdata) { - $userlist[$id] = new User($userdata); - } - return $userlist; - } - - public function admincount() - { - $userdatalist = $this->repo->query() - ->where('level', '==', 10) - ->execute(); - - return $userdatalist->total(); - } - - public function getlisterbylevel(int $level, $comp = '==') - { - $userdatalist = $this->repo->query() - ->where('level', $comp, $level) - ->execute(); - - $userlist = []; - foreach ($userdatalist as $user) { - $userlist[] = $user->id; - } - - return $userlist; - } - - /** - * Check if the password is used, and return by who - * - * @param string $pass password clear - * - * @return mixed User or false - */ - public function passwordcheck(string $pass) - { - $userdatalist = $this->getlister(); - foreach ($userdatalist as $user) { - if ($user->passwordhashed()) { - if (password_verify($pass, $user->password())) { - return $user; - } - } else { - if ($user->password() === $pass) { - return $user; - } - } - } - return false; - } - - /** - * Return information if the password is already used or not - * - * @param string $pass password clear - * - * @return bool password exist or not - */ - public function passwordexist(string $pass) : bool - { - if ($this->passwordcheck($pass) !== false) { - return true; - } else { - return false; - } - } - - /** - * @param User $user - * - * @return bool depending on success - */ - public function add(User $user) : bool - { - $userdata = new \JamesMoss\Flywheel\Document($user->dry()); - $userdata->setId($user->id()); - return $this->repo->store($userdata); - } - - - /** - * @param string|User $id - * - * @return User|false User object or false in case of error - */ - public function get($id) - { - if ($id instanceof User) { - $id = $id->id(); - } - if (is_string($id)) { - $userdata = $this->repo->findById($id); - if ($userdata !== false) { - return new User($userdata); - } else { - return false; - } - } else { - return false; - } - } - - public function delete(User $user) - { - $this->repo->delete($user->id()); - } - - -} - - - - - - -?> \ No newline at end of file diff --git a/app/class/opt.php b/app/class/opt.php deleted file mode 100644 index bf732c5..0000000 --- a/app/class/opt.php +++ /dev/null @@ -1,385 +0,0 @@ - '0', 'max' => '0']; - protected $linkfrom = ['min' => '0', 'max' => '0']; - protected $col = ['id']; - protected $taglist = []; - protected $authorlist = []; - protected $invert = 0; - protected $limit= 0; - - protected $pagevarlist; - - public function __construct(array $donnees = []) - { - $this->hydrate($donnees); - } - - public function hydrate(array $donnees) - { - foreach ($donnees as $key => $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - - public function resetall() - { - $varlist = get_class_vars(__class__); - - foreach ($varlist as $var => $default) { - $method = 'set' . $var; - $this->$method($default); - } - } - - public function reset($var) - { - $varlist = get_class_vars(__class__); - if (in_array($var, $varlist)) { - $this->$var = $varlist[$var]; - } - } - - public function submit() - { - if (isset($_GET['submit'])) { - if ($_GET['submit'] == 'reset') { - $_SESSION['opt'] = []; - } elseif ($_GET['submit'] == 'filter') { - $this->getall(); - } - } else { - $this->sessionall(); - } - } - - public function getall() - { - $optlist = ['sortby', 'order', 'secure', 'tagcompare', 'tagfilter', 'authorcompare', 'authorfilter', 'limit','invert']; - - foreach ($optlist as $method) { - if (method_exists($this, $method)) { - if (isset($_GET[$method])) { - $setmethod = 'set' . $method; - $this->$setmethod($_GET[$method]); - } else { - $this->reset($method); - } - $_SESSION['opt'][$method] = $this->$method(); - } - } - } - - public function sessionall() - { - if (isset($_SESSION['opt'])) { - $this->hydrate($_SESSION['opt']); - } - } - - public function getadress(string $sortby = '') - { - if ($this->sortby === $sortby) { - $order = $this->order * -1; - } else { - $order = $this->order; - } - if(empty($sortby)) { - $sortby = $this->sortby; - } - $adress = '?sortby=' . $sortby; - $adress .= '&order=' . $order; - $adress .= '&secure=' . $this->secure; - $adress .= '&tagcompare=' . $this->tagcompare; - foreach ($this->tagfilter as $tag) { - $adress .= '&tagfilter[]=' . $tag; - } - $adress .= '&authorcompare=' . $this->authorcompare; - foreach ($this->authorfilter as $author) { - $adress .= '&authorfilter[]=' . $author; - } - if ($this->invert == 1) { - $adress .= '&invert=1'; - } - $adress.= '&limit=' .$this->limit; - $adress .= '&submit=filter'; - - return $adress; - } - - - - /** - * Get the query as http string - * - * @return string The resulted query - */ - public function getquery(): string - { - $class = get_class_vars(get_class($this)); - $object = get_object_vars($this); - $class['pagevarlist'] = $object['pagevarlist']; - $class['taglist'] = $object['taglist']; - $class['authorlist'] = $object['authorlist']; - $query = array_diff_assoc_recursive($object, $class); - - return urldecode(http_build_query($query)); - } - - - - - // _______________________________________________ G E T _______________________________________________ - - public function sortby() - { - return $this->sortby; - } - - public function order() - { - return $this->order; - } - - public function secure() - { - return $this->secure; - } - - public function tagfilter($type = 'array') - { - return $this->tagfilter; - } - - public function tagcompare() - { - return $this->tagcompare; - } - - public function authorfilter($type = 'array') - { - return $this->authorfilter; - } - - public function authorcompare() - { - return $this->authorcompare; - } - - public function linkto($type = 'array') - { - return $this->linkto; - } - - public function linkfrom($type = 'array') - { - return $this->linkfrom; - } - - public function col($type = 'array') - { - if ($type == 'string') { - return implode(', ', $this->col); - } else { - return ($this->col); - } - } - - public function taglist() - { - return $this->taglist; - } - - public function authorlist() - { - return $this->authorlist; - } - - public function invert() - { - return $this->invert; - } - - public function pagevarlist() - { - return $this->pagevarlist; - } - - public function limit() - { - return $this->limit; - } - - - // __________________________________________________ S E T _____________________________________________ - - public function setsortby($sortby) - { - if (is_string($sortby) && in_array($sortby, $this->pagevarlist)) { - $this->sortby = strtolower(strip_tags($sortby)); - } - } - - public function setorder($order) - { - $order = intval($order); - if (in_array($order, [-1, 0, 1])) { - $this->order = $order; - } - } - - public function settagfilter($tagfilter) - { - if (!empty($tagfilter) && is_array($tagfilter)) { - $tagfilterverif = []; - foreach ($tagfilter as $tag) { - if (array_key_exists($tag, $this->taglist)) { - $tagfilterverif[] = $tag; - } - } - $this->tagfilter = $tagfilterverif; - } - } - - public function settagcompare($tagcompare) - { - if (in_array($tagcompare, ['OR', 'AND'])) { - $this->tagcompare = $tagcompare; - } - } - - public function setauthorfilter($authorfilter) - { - if (!empty($authorfilter) && is_array($authorfilter)) { - $authorfilterverif = []; - foreach ($authorfilter as $author) { - if (array_key_exists($author, $this->authorlist)) { - $authorfilterverif[] = $author; - } - } - $this->authorfilter = $authorfilterverif; - } - } - - public function setauthorcompare($authorcompare) - { - if (in_array($authorcompare, ['OR', 'AND'])) { - $this->authorcompare = $authorcompare; - } - } - - public function setsecure($secure) - { - if ($secure >= 0 && $secure <= 5) { - $this->secure = intval($secure); - } - } - - public function setlinkto($range) - { - $this->linkto = $range; - } - - public function setlinkfrom($range) - { - $this->linkfrom = $range; - } - - public function setlinktomin($min) - { - $this->linkto['min'] = intval($min); - } - - public function setlinktomax($max) - { - $this->linkto['max'] = intval($max); - } - - public function setlinkfrommin($min) - { - $this->linkfrom['min'] = intval($min); - } - - public function setlinkfrommax($max) - { - $this->linkfrom['max'] = intval($max); - } - - public function setcol($col) - { - if (is_array($col)) { - $this->col = array_intersect($this->pagevarlist(), $col); - } - } - - public function settaglist(array $pagelist) - { - $taglist = []; - foreach ($pagelist as $page) { - foreach ($page->tag('array') as $tag) { - if (!array_key_exists($tag, $taglist)) { - $taglist[$tag] = 1; - } else { - $taglist[$tag]++; - } - } - } - $taglistsorted = arsort($taglist); - $this->taglist = $taglist; - } - - public function setauthorlist(array $pagelist) - { - $authorlist = []; - foreach ($pagelist as $page) { - foreach ($page->authors('array') as $author) { - if (!array_key_exists($author, $authorlist)) { - $authorlist[$author] = 1; - } else { - $authorlist[$author]++; - } - } - } - $authorlistsorted = arsort($authorlist); - $this->authorlist = $authorlist; - } - - public function setinvert(int $invert) - { - if ($invert == 0 || $invert == 1) { - $this->invert = $invert; - } else { - $this->invert = 0; - } - } - - public function setlimit($limit) - { - $limit = intval($limit); - if($limit < 0) { - $limit = 0; - } elseif ($limit >= 10000) { - $limit = 9999; - } - $this->limit = $limit; - } - - - public function setpagevarlist(array $pagevarlist) - { - $this->pagevarlist = $pagevarlist; - } -} diff --git a/app/class/optlist.php b/app/class/optlist.php deleted file mode 100644 index e21e421..0000000 --- a/app/class/optlist.php +++ /dev/null @@ -1,113 +0,0 @@ -hydrate($datas); - } - } - - /** - * Get the code to insert directly - */ - public function getcode() : string - { - return '%LIST?' . $this->getquery() . '%'; - } - - - - - // _______________________________________ G E T _____________________________________ - - - public function title() - { - return $this->title; - } - - public function description() - { - return $this->description; - } - - public function thumbnail() - { - return $this->thumbnail; - } - - public function date() - { - return $this->date; - } - - public function time() - { - return $this->time; - } - - public function author() - { - return $this->author; - } - - public function style() - { - return $this->style; - } - - - // _______________________________________ S E T _____________________________________ - - public function settitle($title) - { - $this->title = intval($title); - } - - public function setdescription($description) - { - $this->description = intval($description); - } - - public function setthumbnail($thumbnail) - { - $this->thumbnail = intval($thumbnail); - } - - public function setdate($date) - { - $this->date = intval($date); - } - - public function settime($time) - { - $this->time = intval($time); - } - - public function setauthor($author) - { - $this->author = intval($author); - } - - public function setstyle($style) - { - $this->style = intval($style); - } -} - - - -?> \ No newline at end of file diff --git a/app/class/page.php b/app/class/page.php deleted file mode 100644 index a55e7cb..0000000 --- a/app/class/page.php +++ /dev/null @@ -1,814 +0,0 @@ -reset(); - $this->hydrate($datas); - } - - public function hydrate($datas) - { - foreach ($datas as $key => $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - public function reset() - { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - - $this->settitle($this->id()); - $this->setdescription(''); - $this->settag([]); - $this->setdate($now); - $this->setdatecreation($now); - $this->setdatecreation($now); - $this->setdatemodif($now); - $this->setdaterender($now); - $this->setcss(''); - $this->setquickcss([]); - $this->setjavascript(''); - $this->setbody(''); - $this->setheader(''); - $this->setmain(''); - $this->setnav(''); - $this->setaside(''); - $this->setfooter(''); - $this->setexternalcss([]); - $this->setcustomhead(''); - $this->setsecure(Config::defaultprivacy()); - $this->setinterface('main'); - $this->setlinkfrom([]); - $this->setlinkto([]); - $this->settemplatebody(''); - $this->settemplatecss(''); - $this->settemplatejavascript(''); - $this->settemplateoptions(['externalcss', 'externaljavascript', 'favicon', 'reccursivecss', 'quickcss']); - $this->setfavicon(''); - $this->setauthors([]); - $this->setinvites([]); - $this->setreaders([]); - $this->setaffcount(0); - $this->setvisitcount(0); - $this->seteditcount(0); - $this->seteditby([]); - } - - - - public static function classvarlist() - { - $classvarlist = []; - foreach (get_class_vars(__class__) as $var => $default) { - $classvarlist[] = $var; - } - return ['pagevarlist' => $classvarlist]; - } - - public function dry() - { - $array = []; - foreach (get_class_vars(__class__) as $var => $value) { - if (in_array($var, self::VAR_DATE)) { - $array[$var] = $this->$var('string'); - } else { - $array[$var] = $this->$var(); - } - } - return $array; - } - - /** - * Check if page have a thumbnail - * @return bool true if the page have a thumbnail otherwise return false. - */ - public function thumbnailexist() : bool - { - $thumbnaillink = Model::THUMBNAIL_DIR . $this->id . '.jpg'; - - $test = file_exists($thumbnaillink); - - $exist = file_exists(Model::THUMBNAIL_DIR . $this->id . '.jpg'); - - return $exist; - } - - - // _____________________________________________________ G E T ____________________________________________________ - - public function id($type = 'string') - { - return $this->id; - } - - public function title($type = 'string') - { - if($type == 'sort') { - return strtolower($this->title); - } else { - return $this->title; - } - } - - public function description($type = 'string') - { - if($type == 'short' && strlen($this->description) > 15 ) { - return substr($this->description, 0, 20) . '...'; - } else { - return $this->description; - } - } - - public function tag($option = 'array') - { - if ($option == 'string') { - return implode(", ", $this->tag); - } elseif ($option == 'array') { - return $this->tag; - } elseif ($option == 'sort') { - return count($this->tag); - } - } - - public function date($option = 'date') - { - if ($option == 'string') { - return $this->date->format(DateTime::ISO8601); - } elseif ($option == 'date' || $option == 'sort') { - return $this->date; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->date->diff($now)); - } elseif ($option == 'pdate') { - return $this->date->format('Y-m-d'); - } elseif ($option == 'ptime') { - return $this->date->format('H:i'); - } elseif ($option = 'dmy') { - return $this->date->format('d/m/Y'); - } - - - } - - public function datecreation($option = 'date') - { - if ($option == 'string') { - return $this->datecreation->format(DateTime::ISO8601); - } elseif ($option == 'date' || $option == 'sort') { - return $this->datecreation; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->datecreation->diff($now)); - } - } - - - public function datemodif($option = 'date') - { - if ($option == 'string') { - return $this->datemodif->format(DateTime::ISO8601); - } elseif ($option == 'date' || $option == 'sort') { - return $this->datemodif; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->datemodif->diff($now)); - } - } - - public function daterender($option = 'date') - { - if ($option == 'string') { - return $this->daterender->format(DateTime::ISO8601); - } elseif ($option == 'date' || $option == 'sort') { - return $this->daterender; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->daterender->diff($now)); - } - } - - public function css($type = 'string') - { - return $this->css; - } - - public function quickcss($type = 'array') - { - if ($type == 'json') { - return json_encode($this->quickcss); - } elseif ($type == 'array') { - return $this->quickcss; - } - } - - public function javascript($type = 'string') - { - return $this->javascript; - } - - public function body($type = 'string') - { - return $this->body; - } - - public function header($type = 'string') - { - return $this->header; - } - - public function main($type = 'string') - { - return $this->main; - } - - public function nav($type = "string") - { - return $this->nav; - } - - public function aside($type = "string") - { - return $this->aside; - } - - public function externalcss($type = "array") - { - return $this->externalcss; - } - - public function customhead($type = "string") - { - if($type === 'string') { - return $this->customhead; - } elseif($type === 'int') { - return substr_count($this->customhead, PHP_EOL) + 1; - } - } - - public function footer($type = "string") - { - return $this->footer; - } - - public function secure($type = 'int') - { - if ($type == 'string') { - if ($this->secure == 0) $secure = 'public'; - if ($this->secure == 1) $secure = 'private'; - if ($this->secure == 2) $secure = 'not_published'; - return $secure; - } else { - return $this->secure; - } - } - - public function invitepassword($type = 'string') - { - return $this->invitepassword; - } - - public function readpassword($type = 'string') - { - return $this->readpassword; - } - - public function interface($type = 'string') - { - return $this->interface; - } - - public function linkfrom($option = 'array') - { - if ($option == 'json') { - $linkfrom = json_encode($this->linkfrom); - } elseif ($option == 'array') { - $linkfrom = $this->linkfrom; - } elseif ($option == 'sort') { - return count($this->linkfrom); - } elseif ($option == 'string') { - return implode(', ', $this->linkfrom); - } - return $linkfrom; - - } - - public function linkto($option = 'array') - { - if ($option == 'json') { - $linkto = json_encode($this->linkto); - } elseif ($option == 'array') { - $linkto = $this->linkto; - } elseif ($option == 'sort') { - return count($this->linkto); - } elseif ($option == 'string') { - return implode(', ', $this->linkto); - } - return $linkto; - - } - - public function templatebody($type = 'string') - { - return $this->templatebody; - } - - public function templatecss($type = 'string') - { - return $this->templatecss; - } - - public function templatejavascript($type = 'string') - { - return $this->templatejavascript; - } - - public function template() - { - $template['body'] = $this->templatebody; - $template['css'] = $this->templatecss; - $template['javascript'] = $this->templatejavascript; - - $template['cssreccursive'] = $this->checkoption('reccursive'); - $template['cssquickcss'] = $this->checkoption('quickcss'); - $template['externalcss'] = $this->checkoption('externalcss'); - $template['cssfavicon'] = $this->checkoption('favicon'); - - $template['externaljavascript'] = $this->checkoption('externaljavascript'); - - return $template; - } - - public function templateoptions($type = 'array') - { - return $this->templateoptions; - } - - function checkoption($option) - { - if (in_array('reccursive', $this->templateoptions)) { - return true; - } else { - return false; - } - } - - public function favicon($type = 'string') - { - return $this->favicon; - } - - public function authors($type = 'array') - { - if($type == 'string') { - return implode(', ', $this->authors); - } elseif ($type == 'array') { - return $this->authors; - } - } - - public function invites($type = 'array') - { - return $this->invites; - } - - public function readers($type = 'array') - { - return $this->invites; - } - - public function affcount($type = 'int') - { - return $this->affcount; - } - - public function visitcount($type = 'int') - { - return $this->visitcount; - } - - public function editcount($type = 'int') - { - return $this->editcount; - } - - public function editby($type = 'array') - { - return $this->editby; - } - - - - - // _____________________________________________________ S E T ____________________________________________________ - - public function setid($id) - { - if (strlen($id) <= Model::MAX_ID_LENGTH and is_string($id)) { - $this->id = strip_tags(strtolower(str_replace(" ", "", $id))); - } - } - - public function settitle($title) - { - if (strlen($title) < self::LEN and is_string($title)) { - $this->title = strip_tags(trim($title)); - } - } - - public function setdescription($description) - { - if (strlen($description) < self::LEN and is_string($description)) { - $this->description = strip_tags(trim($description)); - } - } - - public function settag($tag) - { - if (is_string($tag)) { - - if (strlen($tag) < self::LEN) { - $tag = strip_tags(trim(strtolower($tag))); - $tag = str_replace('*', '', $tag); - $tag = str_replace(' ', '', $tag); - - $taglist = explode(",", $tag); - $taglist = array_filter($taglist); - $this->tag = $taglist; - } - } elseif (is_array($tag)) { - $this->tag = $tag; - } - } - - public function setdate($date) - { - if ($date instanceof DateTimeImmutable) { - $this->date = $date; - } else { - $this->date = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $date, new DateTimeZone('Europe/Paris')); - } - } - - public function setdatecreation($datecreation) - { - if ($datecreation instanceof DateTimeImmutable) { - $this->datecreation = $datecreation; - } else { - $this->datecreation = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $datecreation, new DateTimeZone('Europe/Paris')); - } - } - - public function setdatemodif($datemodif) - { - if ($datemodif instanceof DateTimeImmutable) { - $this->datemodif = $datemodif; - } else { - $this->datemodif = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $datemodif, new DateTimeZone('Europe/Paris')); - } - } - - public function setdaterender($daterender) - { - if ($daterender instanceof DateTimeImmutable) { - $this->daterender = $daterender; - } else { - $this->daterender = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $daterender, new DateTimeZone('Europe/Paris')); - } - } - - - public function setcss($css) - { - if (strlen($css) < self::LENTEXT and is_string($css)) { - $this->css = trim(strtolower($css)); - } - } - - - public function setquickcss($quickcss) - { - if (is_string($quickcss)) { - $quickcss = json_decode($quickcss, true); - } - if (is_array($quickcss)) { - $this->quickcss = $quickcss; - } - } - - public function setjavascript($javascript) - { - if (strlen($javascript < self::LENTEXT && is_string($javascript))) { - $this->javascript = $javascript; - } - } - - - public function setbody($body) - { - if (strlen($body < self::LENTEXT && is_string($body))) { - $this->body = $body; - } - } - - public function setheader($header) - { - if (strlen($header < self::LENTEXT && is_string($header))) { - $this->header = $header; - } - } - - public function setmain($main) - { - if (strlen($main) < self::LENTEXT and is_string($main)) { - $this->main = $main; - } - } - - public function setnav($nav) - { - if (strlen($nav) < self::LENTEXT and is_string($nav)) { - $this->nav = $nav; - } - } - - public function setaside($aside) - { - if (strlen($aside) < self::LENTEXT and is_string($aside)) { - $this->aside = $aside; - } - } - - public function setexternalcss($externalcss) - { - if(is_array($externalcss)) { - $this->externalcss = array_values(array_filter($externalcss)); - } - } - - public function setcustomhead(string $customhead) - { - if(is_string($customhead)) { - $this->customhead = $customhead; - } - } - - public function setfooter($footer) - { - if (strlen($footer) < self::LENTEXT and is_string($footer)) { - $this->footer = $footer; - } - } - - public function setsecure($secure) - { - if ($secure >= 0 and $secure <= self::SECUREMAX) { - $this->secure = intval($secure); - } - } - - public function setinvitepassword($invitepassword) - { - if (is_string($invitepassword) && strlen($invitepassword) < self::LEN) { - $this->invitepassword = $invitepassword; - } - } - - public function setreadpassword($readpassword) - { - if (is_string($readpassword) && strlen($readpassword) < self::LEN) { - $this->readpassword = $readpassword; - } - } - - public function setinterface($interface) - { - if (in_array($interface, self::TABS)) { - $this->interface = $interface; - } - } - - public function setlinkfrom($linkfrom) - { - if (is_array($linkfrom)) { - $this->linkfrom = $linkfrom; - } elseif (is_string($linkfrom)) { - $linkfromjson = json_decode($linkfrom); - if (is_array($linkfromjson)) { - $this->linkfrom = $linkfromjson; - } - } elseif ($linkfrom === null) { - $this->linkfrom = []; - } - } - - public function setlinkto($linkto) - { - if (is_array($linkto)) { - $this->linkto = $linkto; - } elseif (is_string($linkto)) { - $linktojson = json_decode($linkto); - if (is_array($linktojson)) { - $this->linkto = $linktojson; - } - } elseif ($linkto === null) { - $this->linkto = []; - } - } - - public function settemplatebody($templatebody) - { - if (is_string($templatebody)) { - $this->templatebody = $templatebody; - } - } - - public function settemplatecss($templatecss) - { - if (is_string($templatecss)) { - $this->templatecss = $templatecss; - } - } - - public function settemplatejavascript($templatejavascript) - { - if (is_string($templatejavascript)) { - $this->templatejavascript = $templatejavascript; - } - } - - public function settemplateoptions($templateoptions) - { - if(is_array($templateoptions)) { - $this->templateoptions = array_values(array_filter($templateoptions)); - } - } - - public function setfavicon($favicon) - { - if (is_string($favicon)) { - $this->favicon = $favicon; - } - } - - public function setauthors($authors) - { - if(is_array($authors)) { - $this->authors = array_values(array_filter($authors)); - } - } - - public function setinvites($invites) - { - if(is_array($invites)) { - $this->invites = array_values(array_filter($invites)); - } - } - - public function setreaders($readers) - { - if(is_array($readers)) { - $this->readers = array_values(array_filter($readers)); - } - } - - public function setaffcount($affcount) - { - if (is_int($affcount)) { - $this->affcount = $affcount; - } elseif (is_numeric($affcount)) { - $this->affcount = intval($affcount); - } - } - - public function setvisitcount($visitcount) - { - if (is_int($visitcount)) { - $this->visitcount = $visitcount; - } elseif (is_numeric($visitcount)) { - $this->visitcount = intval($visitcount); - } - } - - public function seteditcount($editcount) - { - if (is_int($editcount)) { - $this->editcount = $editcount; - } elseif (is_numeric($editcount)) { - $this->editcount = intval($editcount); - } - } - - public function seteditby($editby) - { - if(is_array($editby)) { - $this->editby = $editby; - } - } - - - // __________________________________ C O U N T E R S ______________________________ - - - public function addeditcount() - { - $this->editcount++; - } - - public function addaffcount() - { - $this->affcount++; - } - - public function addvisitcount() - { - $this->visitcount++; - } - - public function updateedited() - { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - $this->setdatemodif($now); - $this->addeditcount(); - } - - public function addauthor(string $id) - { - if(!in_array($id, $this->authors)) { - $this->authors[] = $id; - } - } - - public function addeditby(string $id) - { - $this->editby[$id] = true; - } - - public function removeeditby(string $id) - { - unset($this->editby[$id]); - } - - public function iseditedby() - { - return count($this->editby) > 0; - } - - -} - - -?> \ No newline at end of file diff --git a/app/class/quickcss.php b/app/class/quickcss.php deleted file mode 100644 index dc7dbac..0000000 --- a/app/class/quickcss.php +++ /dev/null @@ -1,291 +0,0 @@ - ['left', 'right', 'center', 'justify'], - 'border-style' => ['solid', 'double', 'outset', 'ridge'], - 'font-family' => ['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy'], - 'text-decoration-line' => ['none', 'underline', 'overline', 'line-through', 'underline overline'], - 'display' => ['none', ] - ]; - - - private static function getselect() - { - return array_keys(self::OPTIONS); - } - - private static function getparams() - { - $params = array_merge(self::COLOR, self::SIZE, self::getselect(), self::UNIQUE); - sort($params, SORT_STRING ); - return $params; - } - - public function __construct($data) - { - $this->hydrate($data); } - - public function hydrate($data) - { - foreach ($data as $key => $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - public function calc() - { - $quickcss = $this->intersect($this->values,$this->active); - $quickcss = $this->merge($quickcss, $this->new); - $quickcss = $this->addunits($quickcss, $this->units); - $quickcss = $this->merge($this->jsoncss, $quickcss); - - $this->quickcss = $quickcss; - } - - - - // _________________________________________ P O S T __________________________________________________ - - public function setvalues($data) - { - if(is_array($data)) { - $this->values = $data; - } - } - - public function setunits($data) - { - if(is_array($data)) { - $this->units = $data; - } - } - - public function setactive($data) - { - if(is_array($data)) { - $this->active = $data; - } - } - - public function setnew($data) - { - if (!empty($data['element']) && !empty($data['param']) && in_array($data['param'], self::getparams())) { - $new = array($data['element'] => array($data['param'] => '')); - $this->new = $new; - } - } - - - public function setjson($jsoncss) - { - if(!empty($jsoncss) && is_string($jsoncss)) { - $jsoncss = json_decode($jsoncss); - if(is_array($jsoncss)) { - $this->jsoncss = $jsoncss; - } else { - $this->jsoncss = []; - } - } - } - - - // _______________________________________ C A L C ___________________________________________________ - - public function intersect($values, $active) - { - $intersect = array_intersect_key($values, $active); - - foreach ($intersect as $element => $css) { - $intersect[$element] = array_intersect_key($values[$element], $active[$element]); - } - return $intersect; - } - - public function merge($quickcss, $new) - { - $quickcss = array_merge_recursive($quickcss, $new); - return $quickcss; - } - - public function addunits($quickcss, $units) - { - foreach ($units as $element => $css) { - foreach ($css as $param => $unit) { - if (array_key_exists($element, $quickcss) && array_key_exists($param, $quickcss[$element])) { - $quickcss[$element][$param] = $quickcss[$element][$param] . $unit; - } - } - } - return $quickcss; - } - - - - // __________________________________________ C O M _________________________________________ - - public function tocss() - { - $string = ''; - foreach ($this->quickcss as $element => $css) { - $string .= PHP_EOL . $element . ' {'; - foreach ($css as $param => $value) { - $string .= PHP_EOL . ' ' . $param . ': ' . $value . ';'; - } - $string .= PHP_EOL . '}' . PHP_EOL; - } - return $string; - } - - public function tojson() - { - return json_encode($this->quickcss); - } - - - - - // _____________________________________________ F O R M ____________________________________________ - - public function form($action) - { - echo '
    '; - echo '
    '; - $this->inputs($this->quickcss); - echo '
    '; - echo '
    '; - - } - - public function inputs($quickcss) - { - echo '

    Add element

    '; - - echo ''; - echo ''; - foreach (array_keys($quickcss) as $element) { - echo ''; - - echo ''; - - foreach ($quickcss as $element => $css) { - echo '

    ' . $element . '

    '; - foreach ($css as $param => $value) { - - echo '
    '; - echo ''; - echo ''; - echo '
    '; - - echo '
    '; - - if (in_array($param, self::COLOR)) { - echo ''; - } - - if (in_array($param, self::SIZE)) { - $this->sizeinput($element, $param, $value); - } - - if (in_array($param, self::getselect())) { - $this->selectinput($element, $param, $value); - } - - if (in_array($param, self::UNIQUE)) { - $method = str_replace('-', '', $param) . 'input'; - if (method_exists($this, $method)) { - $this->$method($element, $param, $value); - } - } - - echo '
    '; - } - } - - - } - - - - - - - // ____________________________________ I N P U T __________________________________ - - public function sizeinput($element, $param, $value) - { - echo ''; - - $unit = preg_replace('/\d/', '', $value); - ?> - - '; - - $unit = preg_replace('/\d/', '', $value); - ?> - - '; - } - - public function selectinput($element, $param, $value) - { - echo ''; - } - - -} - - - -?> \ No newline at end of file diff --git a/app/class/record.php b/app/class/record.php deleted file mode 100644 index e488383..0000000 --- a/app/class/record.php +++ /dev/null @@ -1,116 +0,0 @@ -hydrate($donnees); - } - - public function hydrate(array $donnees) - { - foreach ($donnees as $key => $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - - -// _________________________________________________ G E T ____________________________________________________ - - public function id() - { - return $this->id; - } - - public function path() - { - return $this->path; - } - - public function extension() - { - return $this->extension; - } - - public function size() - { - return $this->size; - } - - public function datetime() - { - return $this->datetime; - } - - public function number() - { - return $this->number; - } - -// ___________________________________________________ S E T __________________________________________________ - - public function setid($id) - { - if (strlen($id) < 100 and is_string($id)) { - $this->id = strip_tags(strtolower($id)); - } - } - - public function setpath($path) - { - if (strlen($path) < 40 and is_string($path)) { - $this->path = strip_tags(strtolower($path)); - } - } - - public function setextension($extension) - { - if (strlen($extension) < 7 and is_string($extension)) { - $this->extension = strip_tags(strtolower($extension)); - } - } - - public function setsize($size) - { - if (40 and is_int($size)) { - $this->size = strip_tags(strtolower($size)); - } - } - - public function setdatetime($datetime) - { - if (is_int($datetime)) { - $this->datetime = strip_tags(strtolower($datetime)); - } - } - - public function setnumber($number) - { - if (is_int($number)) { - $this->number = strip_tags(strtolower($number)); - } - } - - - - - -} - -?> \ No newline at end of file diff --git a/app/class/route.php b/app/class/route.php deleted file mode 100644 index 8e58945..0000000 --- a/app/class/route.php +++ /dev/null @@ -1,84 +0,0 @@ -hydrate($vars); - } - - public function hydrate($vars) - { - foreach ($vars as $var => $value) { - $method = 'set' . $var; - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - public function toarray() - { - $array = []; - if (!empty($this->id)) { - $array[] = 'page'; - } - if (!empty($this->aff)) { - $array[] = 'aff='.$this->aff; - } - if (!empty($this->action)) { - $array[] = 'action=' . $this->action; - } - if (!empty($this->redirect)) { - $array[] = $this->redirect; - } - - - return $array; - } - - function tostring() - { - return implode(' ', $this->toarray()); - } - - - - public function setid($id) - { - $this->id = $id; - } - - public function setaff($aff) - { - $this->aff = $aff; - - } - - public function setaction($action) - { - $this->action = $action; - } - - public function setredirect($redirect) - { - $this->redirect = $redirect; - } - - public function id() - { - return $this->id; - } -} - - - - -?> \ No newline at end of file diff --git a/app/class/routes.php b/app/class/routes.php deleted file mode 100644 index 44f30bd..0000000 --- a/app/class/routes.php +++ /dev/null @@ -1,79 +0,0 @@ -setBasePath('/' . Config::basepath()); - } - $router->addMatchTypes(array('cid' => '[a-zA-Z0-9-_+,\'!%@&.$€=\(\|\)]+')); - $router->addRoutes([ - ['GET', '/', 'Controllerhome#desktop', 'home'], - ['POST', '/', 'Controllerhome#desktop', 'homequery'], - ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], - ['GET', '//renderall', 'Controllerhome#renderall', 'homerenderall'], - ['POST', '/bookmark', 'Controllerhome#bookmark', 'homebookmark'], - ['POST', '/upload', 'Controllerpage#upload', 'pageupload'], - ['POST', '/!co', 'Controllerconnect#log', 'log'], - ['GET', '/!co', 'Controllerconnect#connect', 'connect'], - ['POST', '/!search', 'Controllerhome#search', 'search'], - ['GET', '/!media', 'Controllermedia#desktop', 'media'], - ['POST', '/!media/upload', 'Controllermedia#upload', 'mediaupload'], - ['POST', '/!media/folderadd', 'Controllermedia#folderadd', 'mediafolderadd'], - ['POST', '/!media/folderdelete', 'Controllermedia#folderdelete', 'mediafolderdelete'], - ['POST', '/!media/edit', 'Controllermedia#edit', 'mediaedit'], - ['GET', '/!font', 'Controllerfont#desktop', 'font'], - ['GET', '/!font/render', 'Controllerfont#render', 'fontrender'], - ['POST', '/!font/add', 'Controllerfont#add', 'fontadd'], - ['POST', '/!admin', 'Controlleradmin#update', 'adminupdate'], - ['GET', '/!admin', 'Controlleradmin#desktop', 'admin'], - ['GET', '/!user', 'Controlleruser#desktop', 'user'], - ['POST', '/!user/add', 'Controlleruser#add', 'useradd'], - ['POST', '/!user/update', 'Controlleruser#update', 'userupdate'], - ['POST', '/!user/pref', 'Controlleruser#pref', 'userpref'], - ['GET', '/!info', 'Controllerinfo#desktop', 'info'], - ['GET', '/!timeline', 'Controllertimeline#desktop', 'timeline'], - ['POST', '/!timeline/add', 'Controllertimeline#add', 'timelineadd'], - ['POST', '/!timeline/clap', 'Controllertimeline#clap', 'timelineclap'], - ['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(); - if ($match) { - $callableParts = explode('#', $match['target']); - $controllerName = $callableParts[0]; - $methodName = $callableParts[1]; - - $controller = new $controllerName($router); - - call_user_func_array(array($controller, $methodName), $match['params']); - } - //404 - else { - if(!empty(Config::route404())) { - $controller = new Controller($router); - $controller->routedirect('pageread/', ['page' => Config::route404()]); - } else { - header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); - } - } - } -} \ No newline at end of file diff --git a/app/class/user.php b/app/class/user.php deleted file mode 100644 index 3f9c19a..0000000 --- a/app/class/user.php +++ /dev/null @@ -1,298 +0,0 @@ - false]; - - public function __construct($datas = []) - { - if (!empty($datas)) { - $this->hydrate($datas); - } - } - - public function hydrate($datas = []) - { - foreach ($datas as $key => $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - public function dry() - { - $array = []; - foreach (get_class_vars(__class__) as $var => $value) { - $array[$var] = $this->$var(); - } - return $array; - } - - - // _________________________ G E T _______________________ - - public function id() - { - return $this->id; - } - - public function level() - { - return $this->level; - } - - public function password($type = 'string') - { - if ($type === 'int') { - return strlen($this->password); - } elseif ($type = 'string') { - return $this->password; - } - } - - public function signature() - { - return $this->signature; - } - - public function passwordhashed() - { - return $this->passwordhashed; - } - - public function cookie() - { - return $this->cookie; - } - - public function columns() - { - return $this->columns; - } - - public function connectcount() - { - return $this->connectcount; - } - - public function expiredate(string $type = 'string') - { - if ($type == 'string') { - if(!empty($this->expiredate)) { - return $this->expiredate->format('Y-m-d'); - } else { - return false; - } - } elseif ($type == 'date') { - if(!empty($this->expiredate)) { - return $this->expiredate; - } else { - return false; - } - } elseif ($type == 'hrdi') { - if(empty($this->expiredate)) { - return 'never'; - } else { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - if($this->expiredate < $now) { - return 'expired'; - } else { - return hrdi($this->expiredate->diff($now)); - } - } - } - } - - public function bookmark() - { - return $this->bookmark; - } - - public function display() - { - return $this->display; - } - - - // _______________________ S E T _______________________ - - public function setid($id) - { - $id = idclean($id); - if (strlen($id) < Model::MAX_ID_LENGTH and is_string($id)) { - $this->id = $id; - } - } - - public function setlevel($level) - { - $level = intval($level); - if ($level >= 0 && $level <= 10) { - $this->level = $level; - } - } - - public function setpassword($password) - { - if (!empty($password) && is_string($password)) { - $this->password = $password; - } - - } - - public function setsignature(string $signature) - { - if (strlen($signature) <= 128) { - $this->signature = $signature; - } - } - - public function setpasswordhashed($passwordhashed) - { - $this->passwordhashed = boolval($passwordhashed); - - } - - public function setcookie($cookie) - { - $cookie = abs(intval($cookie)); - if($cookie >= 365) {$cookie = 365;} - $this->cookie = $cookie; - } - - public function setcolumns($columns) - { - if(is_array($columns)) { - $columns = array_filter(array_intersect(array_unique($columns), Model::COLUMNS)); - $this->columns = $columns; - } - } - - public function setconnectcount($connectcount) - { - if(is_int($connectcount) && $connectcount >= 0) { - $this->connectcount = $connectcount; - } - } - - public function setexpiredate($expiredate) - { - if ($expiredate instanceof DateTimeImmutable) { - $this->expiredate = $expiredate; - } else { - $this->expiredate = DateTimeImmutable::createFromFormat('Y-m-d', $expiredate, new DateTimeZone('Europe/Paris')); - } - } - - public function setbookmark($bookmark) - { - if(is_array($bookmark)) { - $this->bookmark = $bookmark; - } - } - - public function setdisplay($display) - { - if(is_array($display)) { - $this->display = $display; - } - } - - - - - - - - //____________________________________________________ F U N ____________________________________________________ - - - - - - - - public function hashpassword() - { - $this->password = password_hash($this->password, PASSWORD_DEFAULT); - $this->passwordhashed = true; - } - - public function validpassword() - { - if(is_string($this->password)) { - if(strlen($this->password) >= Model::PASSWORD_MIN_LENGTH && strlen($this->password) <= Model::PASSWORD_MAX_LENGTH) { - return true; - } - } - return false; - } - - - - public function isvisitor() - { - return $this->level === Modeluser::FREE; - } - - public function iseditor() - { - return $this->level >= Modeluser::EDITOR; - } - - public function issupereditor() - { - return $this->level >= Modeluser::SUPEREDITOR; - } - - public function isinvite() - { - return $this->level >= Modeluser::INVITE; - } - - public function isadmin() - { - return $this->level === Modeluser::ADMIN; - } - - - public function connectcounter() - { - $this->connectcount ++; - } - - public function addbookmark(string $id, string $query) - { - if(!empty($id) && !empty($query)) { - $id = idclean($id); - $id = substr($id, 0, 16); - $this->bookmark[$id] = $query; - } - } - - public function deletebookmark(string $id) - { - if(key_exists($id, $this->bookmark)) { - unset($this->bookmark[$id]); - } - } - - -} - - - -?> \ No newline at end of file diff --git a/app/class/wflywheel/formatter/json.php b/app/class/wflywheel/formatter/json.php deleted file mode 100644 index d015cc1..0000000 --- a/app/class/wflywheel/formatter/json.php +++ /dev/null @@ -1,21 +0,0 @@ -operators = array( - '>', '>=', '<', '<=', '==', '===', '!=', '!==', 'IN' - ); - } -} diff --git a/app/class/wflywheel/query.php b/app/class/wflywheel/query.php deleted file mode 100644 index 49aff16..0000000 --- a/app/class/wflywheel/query.php +++ /dev/null @@ -1,16 +0,0 @@ -predicate = new Predicate(); - } -} diff --git a/app/class/wflywheel/repository.php b/app/class/wflywheel/repository.php deleted file mode 100644 index baad42e..0000000 --- a/app/class/wflywheel/repository.php +++ /dev/null @@ -1,30 +0,0 @@ -formatter->getFileExtension(); - $files = glob($this->path . DIRECTORY_SEPARATOR . '*.' . $ext); - return $files; - } - - /** - * Get an array containing the id of all files in this repository - * - * @return array An array, item is a id - */ - public function getAllIds() - { - $ext = $this->formatter->getFileExtension(); - return array_map(function($path) use ($ext) { - return $this->getIdFromPath($path, $ext); - }, $this->getAllFiles()); - } -} diff --git a/app/fn/fn.php b/app/fn/fn.php index 9c011ef..f462d2d 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -1,14 +1,5 @@ Here you can set the home-page view for visitors.

    - > + >
    - > + >
    - > + >
    - - - + + + @@ -78,20 +78,20 @@ - + @@ -107,23 +107,23 @@

    Common options

    - + - + @@ -131,33 +131,33 @@ This will also be shown as a tooltip over links. - +
    - > + >

    Private

    - +
    - > + >

    Not published

    - +
    - > + >
    @@ -165,7 +165,7 @@
    - > + >
    @@ -183,7 +183,7 @@
    - > + >
    @@ -192,13 +192,13 @@
    - > + >
    - > + >
    @@ -224,7 +224,7 @@ - + @@ -249,7 +249,7 @@ - + @@ -266,7 +266,7 @@

    Tracking

    - + (Need rendering to work) diff --git a/app/view/templates/alert.php b/app/view/templates/alert.php index c4a54b1..bab6410 100644 --- a/app/view/templates/alert.php +++ b/app/view/templates/alert.php @@ -7,7 +7,7 @@ $this->start('head'); ?> - ' : '' ?> + ' : '' ?> @@ -28,7 +28,7 @@ $this->stop(); - ' . Config::alerttitle() . '' : '' ?> + ' . Wcms\Config::alerttitle() . '' : '' ?> stop(); if(!$pageexist) { - if(!empty(Config::existnot())) { - echo '

    ' . Config::existnot() . '

    '; + if(!empty(Wcms\Config::existnot())) { + echo '

    ' . Wcms\Config::existnot() . '

    '; } - if(Config::existnotpass() && !$canedit) { + if(Wcms\Config::existnotpass() && !$canedit) { echo $form; } } else { @@ -55,19 +55,19 @@ $this->stop(); switch ($page->secure()) { case 1: - if(!empty(Config::private())) { - echo '

    ' . Config::private() . '

    '; + if(!empty(Wcms\Config::private())) { + echo '

    ' . Wcms\Config::private() . '

    '; } - if(Config::privatepass()) { + if(Wcms\Config::privatepass()) { echo $form; } break; case 2: - if(!empty(Config::notpublished())) { - echo '

    ' . Config::notpublished() . '

    '; + if(!empty(Wcms\Config::notpublished())) { + echo '

    ' . Wcms\Config::notpublished() . '

    '; } - if(Config::notpublishedpass()) { + if(Wcms\Config::notpublishedpass()) { echo $form; } break; @@ -80,9 +80,9 @@ $this->stop(); ?>

    ⭐ Create

    -

    +

    > - + home > - + media > - + font isadmin()) { ?> > - + admin @@ -46,7 +46,7 @@ if($user->isadmin()) { } ?> > - + info @@ -75,11 +75,11 @@ if($user->isadmin()) { > - + timeline > - + id() ?> level() ?> diff --git a/app/view/templates/edit.php b/app/view/templates/edit.php index 28e245f..2de0c9b 100644 --- a/app/view/templates/edit.php +++ b/app/view/templates/edit.php @@ -5,7 +5,7 @@ start('page') ?> - +
    @@ -30,7 +30,7 @@ - + stop('page') ?> \ No newline at end of file diff --git a/app/view/templates/editleftbar.php b/app/view/templates/editleftbar.php index d169473..c901c14 100644 --- a/app/view/templates/editleftbar.php +++ b/app/view/templates/editleftbar.php @@ -46,7 +46,7 @@
    - no-thumbnail + no-thumbnail
    diff --git a/app/view/templates/edittopbar.php b/app/view/templates/edittopbar.php index 13cef96..5aa13ba 100644 --- a/app/view/templates/edittopbar.php +++ b/app/view/templates/edittopbar.php @@ -18,7 +18,7 @@ - + display id() ?> @@ -27,11 +27,11 @@ - + - download + download diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 2ee791a..9758c95 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -87,11 +87,11 @@ - - + + issupereditor()) { ?> - + tag('sort') ?> @@ -141,7 +141,7 @@ - display()['bookmark'] && (!empty(Config::bookmark()) || !empty($user->bookmark()))) { ?> + display()['bookmark'] && (!empty(Wcms\Config::bookmark()) || !empty($user->bookmark()))) { ?>
    @@ -149,7 +149,7 @@
    Public
      - $query) { ?> + $query) { ?>
    • @@ -176,7 +176,7 @@ - + diff --git a/app/view/templates/homemenu.php b/app/view/templates/homemenu.php index f807f7c..838ca81 100644 --- a/app/view/templates/homemenu.php +++ b/app/view/templates/homemenu.php @@ -159,10 +159,10 @@ Bookmarks