From e17392e46259e6f2e012017987cf7c31c171488f Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sun, 28 Oct 2018 19:56:27 +0100 Subject: abstract config NWY --- w/class/application.php | 15 ---- w/class/art2.php | 111 ++++++++++++----------- w/class/config.1.php | 188 +++++++++++++++++++++++++++++++++++++++ w/class/config.php | 157 ++++++++++++++++++-------------- w/class/configtest.php | 22 +++++ w/class/controller.php | 53 +++++++++-- w/class/controlleradmin.php | 5 ++ w/class/controllerart.php | 46 +++++----- w/class/controllerhome.php | 25 ++++-- w/class/controllermedia.php | 1 - w/class/model.php | 7 +- w/class/modelanalyse.php | 73 +++++++++++++++ w/class/modelart.php | 97 +++++++++++++++----- w/class/modelartlist.php | 159 --------------------------------- w/class/modelconfig.php | 8 +- w/class/modeldb.php | 47 ++++++++-- w/class/modelhome.php | 33 ++++--- w/class/modelmedia.php | 3 - w/class/modelrender.php | 187 ++++++++++++++++++++++++++++++++++++++ w/class/modeluser.php | 18 ++-- w/class/router.php | 14 ++- w/class/user.php | 21 +++++ w/fn/w.fn.php | 37 +------- w/view/templates/base.php | 10 --- w/view/templates/body.php | 0 w/view/templates/edit.php | 47 ++++++++++ w/view/templates/edithelp.php | 27 ++++++ w/view/templates/editsidebar.php | 40 +++++++++ w/view/templates/edittabs.php | 19 ++++ w/view/templates/edittopbar.php | 12 +++ w/view/templates/home.php | 85 ++++++++++++++++++ w/view/templates/homeopt.php | 84 +++++++++++++++++ w/view/templates/layout.php | 20 +++++ w/view/templates/nav.php | 42 --------- w/view/templates/navart.php | 64 +++++++++++++ w/view/templates/navback.php | 54 +++++++++++ w/view/templates/read.php | 55 +++++++++--- w/view/templates/readart.php | 25 ++++++ w/view/templates/readcreate.php | 3 + w/view/templates/reader.php | 38 -------- w/w.index.php | 12 ++- 41 files changed, 1426 insertions(+), 538 deletions(-) create mode 100644 w/class/config.1.php create mode 100644 w/class/configtest.php create mode 100644 w/class/modelanalyse.php delete mode 100644 w/class/modelartlist.php create mode 100644 w/class/modelrender.php delete mode 100644 w/view/templates/base.php create mode 100644 w/view/templates/body.php create mode 100644 w/view/templates/edit.php create mode 100644 w/view/templates/edithelp.php create mode 100644 w/view/templates/editsidebar.php create mode 100644 w/view/templates/edittabs.php create mode 100644 w/view/templates/edittopbar.php create mode 100644 w/view/templates/home.php create mode 100644 w/view/templates/homeopt.php create mode 100644 w/view/templates/layout.php delete mode 100644 w/view/templates/nav.php create mode 100644 w/view/templates/navart.php create mode 100644 w/view/templates/navback.php create mode 100644 w/view/templates/readart.php create mode 100644 w/view/templates/readcreate.php delete mode 100644 w/view/templates/reader.php (limited to 'w') diff --git a/w/class/application.php b/w/class/application.php index 77599d5..4492aad 100644 --- a/w/class/application.php +++ b/w/class/application.php @@ -4,21 +4,6 @@ class Application { - protected $config; - - - public function __construct() - { - $this->setconfig(); - - } - - - public function setconfig() - { - $this->config = Modelconfig::readconfig(); - } - diff --git a/w/class/art2.php b/w/class/art2.php index 88c0321..b6c7125 100644 --- a/w/class/art2.php +++ b/w/class/art2.php @@ -1,8 +1,5 @@ setinvitepassword('invitepassword'); $this->setinterface('section'); $this->setlinkfrom([]); + $this->setlinkto([]); $this->settemplate([]); $this->setaffcount(0); $this->seteditcount(0); @@ -115,7 +113,7 @@ class Art2 public function calclinkto($getlist) { $linkto = []; - if(!empty($getlist)) { + if (!empty($getlist)) { foreach ($getlist as $link) { if (in_array($this->id(), $link->linkfrom('array'))) { $linkto[] = $link->id(); @@ -160,9 +158,9 @@ class Art2 public function templaterender(array $vars) { $datas = []; - foreach($vars as $var) { + foreach ($vars as $var) { if (method_exists($this, $var)) - $datas[$var] = $this->$var(); + $datas[$var] = $this->$var(); } return $datas; } @@ -185,7 +183,7 @@ class Art2 return $this->description; } - public function tag($option) + public function tag($option = 'array') { if ($option == 'string') { return implode(", ", $this->tag); @@ -196,7 +194,7 @@ class Art2 } } - public function date($option) + public function date($option = 'date') { if ($option == 'string') { return $this->date->format('Y-m-d H:i:s'); @@ -206,9 +204,11 @@ class Art2 $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); return hrdi($this->date->diff($now)); } + + } - public function datecreation($option) + public function datecreation($option = 'date') { if ($option == 'string') { return $this->datecreation->format('Y-m-d H:i:s'); @@ -221,7 +221,7 @@ class Art2 } - public function datemodif($option) + public function datemodif($option = 'date') { if ($option == 'string') { return $this->datemodif->format('Y-m-d H:i:s'); @@ -233,7 +233,7 @@ class Art2 } } - public function daterender($option) + public function daterender($option = 'date') { if ($option == 'string') { return $this->daterender->format('Y-m-d H:i:s'); @@ -259,7 +259,7 @@ class Art2 } } - + public function csstemplate(App $app) { $data = []; @@ -303,7 +303,7 @@ class Art2 return $md; } - public function section() + public function section($type = 'string') { return $this->section; } @@ -358,17 +358,17 @@ class Art2 } - public function nav($type="string") + public function nav($type = "string") { return $this->nav; } - public function aside($type="string") + public function aside($type = "string") { return $this->aside; } - public function footer($type="string") + public function footer($type = "string") { return $this->footer; } @@ -390,12 +390,12 @@ class Art2 } } - public function invitepassword($type = 'int') + public function invitepassword($type = 'string') { return $this->invitepassword; } - public function interface($type = 'secton') + public function interface($type = 'string') { return $this->interface; } @@ -413,10 +413,10 @@ class Art2 } - public function linkto($option) + public function linkto($option = 'json') { - if ($option == 'string') { - $linkto = implode(", ", $this->linkto); + if ($option == 'json') { + $linkto = json_encode($this->linkto); } elseif ($option == 'array') { $linkto = $this->linkto; } elseif ($option == 'sort') { @@ -428,7 +428,7 @@ class Art2 public function template($type = 'json') { - if($type == 'json') { + if ($type == 'json') { return json_encode($this->template); } elseif ($type = 'array') { return $this->template; @@ -534,53 +534,53 @@ class Art2 } } - + public function setquickcss($quickcss) { - if(is_string($quickcss)) { + if (is_string($quickcss)) { $quickcss = json_decode($quickcss, true); } - if(is_array($quickcss)) { + if (is_array($quickcss)) { $this->quickcss = $quickcss; } } public function setjavascript($javascript) { - if(strlen($javascript < self::LENTEXT && is_string($javascript))) { + if (strlen($javascript < self::LENTEXT && is_string($javascript))) { $this->javascript = $javascript; } } - + public function sethtml($html) { - if(strlen($html < self::LENTEXT && is_string($html))) { + if (strlen($html < self::LENTEXT && is_string($html))) { $this->html = $html; } } public function setheader($header) { - if(strlen($header < self::LENTEXT && is_string($header))) { + if (strlen($header < self::LENTEXT && is_string($header))) { $this->header = $header; } } - + public function setsection($section) { if (strlen($section) < self::LENTEXT and is_string($section)) { $this->section = $section; } } - + 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)) { @@ -599,7 +599,7 @@ class Art2 { $this->render = $render; } - + public function setsecure($secure) { if ($secure >= 0 and $secure <= self::SECUREMAX) { @@ -609,65 +609,72 @@ class Art2 public function setinvitepassword($invitepassword) { - if(is_string($invitepassword) && strlen($invitepassword) < self::LEN) { + if (is_string($invitepassword) && strlen($invitepassword) < self::LEN) { $this->invitepassword = $invitepassword; } } public function setinterface($interface) { - if(in_array($interface, self::TABS)) - { + if (in_array($interface, self::TABS)) { $this->interface = $interface; } } public function setlinkfrom($linkfrom) { - if (!empty($linkfrom) && strlen($linkfrom) < self::LEN && is_string($linkfrom)) { - $linkfrom = strip_tags(trim(strtolower($linkfrom))); - $linkfromlist = explode(", ", $linkfrom); - $this->linkfrom = $linkfromlist; - } else { + 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)) { + 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 settemplate($template) { - if(is_string($template)) { + if (is_string($template)) { $template = json_decode($template, true); } - if(is_array($template)) { + if (is_array($template)) { $this->template = $template; } } public function setaffcount($affcount) { - if(is_int($affcount)) { + if (is_int($affcount)) { $this->affcount = $affcount; - } elseif(is_numeric($affcount)) { + } elseif (is_numeric($affcount)) { $this->affcount = intval($affcount); - } + } } public function seteditcount($editcount) { - if(is_int($editcount)) { + if (is_int($editcount)) { $this->editcount = $editcount; - } elseif(is_numeric($editcount)) { + } elseif (is_numeric($editcount)) { $this->editcount = intval($editcount); - } + } } diff --git a/w/class/config.1.php b/w/class/config.1.php new file mode 100644 index 0000000..3b4cde0 --- /dev/null +++ b/w/class/config.1.php @@ -0,0 +1,188 @@ +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 tojson() + { + $arr = get_object_vars($this); + $json = json_encode($arr, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT); + return $json; + } + +// ________________________________________ G E T _______________________________________ + + public function host() + { + return $this->host; + } + + public function dbname() + { + return $this->dbname; + } + + public function user() + { + return $this->user; + } + + public function password() + { + return $this->password; + } + + public function arttable() + { + return $this->arttable; + } + + public function domain() + { + return $this->domain; + } + + public function admin() + { + return $this->admin; + } + + public function editor() + { + return $this->editor; + } + + public function invite() + { + return $this->invite; + } + + public function read() + { + return $this->read; + } + + public function color4() + { + return $this->color4; + } + + public function fontsize() + { + return $this->fontsize; + } + + + +// __________________________________________ S E T ______________________________________ + + public function sethost($host) + { + $this->host = strip_tags($host); + } + + public function setdbname($dbname) + { + $this->dbname = strip_tags($dbname); + } + + public function setuser($user) + { + $this->user = strip_tags($user); + } + + public function setpassword($password) + { + $this->password = strip_tags($password); + } + + public function setarttable($arttable) + { + $this->arttable = strip_tags($arttable); + } + + public function setdomain($domain) + { + $this->domain = strip_tags($domain); + } + + public function setadmin($admin) + { + $this->admin = strip_tags($admin); + } + + public function seteditor($editor) + { + $this->editor = strip_tags($editor); + } + + public function setinvite($invite) + { + $this->invite = strip_tags($invite); + } + + public function setread($read) + { + $this->read = strip_tags($read); + } + + public function setcolor4($color4) + { + if(strlen($color4) <= 8) { + $this->color4 = $color4; + } + } + + public function setfontsize($fontsize) + { + $fontsize = intval($fontsize); + if($fontsize > 1) { + $this->fontsize = $fontsize; + } + } + + +} + + + + + + + + + +?> \ No newline at end of file diff --git a/w/class/config.php b/w/class/config.php index 3b4cde0..674aa66 100644 --- a/w/class/config.php +++ b/w/class/config.php @@ -2,41 +2,60 @@ -class Config +abstract class Config { - private $host; - private $dbname; - private $user; - private $password; - private $arttable; - private $domain; - private $admin; - private $editor; - private $invite; - private $read; - private $color4; - private $fontsize = 6; + protected static $host; + protected static $dbname; + protected static $user; + protected static $password; + protected static $arttable; + protected static $domain; + protected static $admin; + protected static $editor; + protected static $invite; + protected static $read; + protected static $color4; + protected static $fontsize = 6; // _______________________________________ F U N _______________________________________ - public function __construct(array $donnees) - { - $this->hydrate($donnees); - } - public function hydrate(array $donnees) + + public static function hydrate(array $donnees) { foreach ($donnees as $key => $value) { $method = 'set' . $key; - if (method_exists($this, $method)) { - $this->$method($value); + if (method_exists(get_called_class(), $method)) { + self::$method($value); } } } - public function tojson() + 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); + } + } + + public static function createconfig(array $datas) + { + self::hydrate($datas); + } + + + public static function savejson() + { + $json = self::tojson(); + file_put_contents(self::CONFIG_FILE, $json); + } + + + public static function tojson() { $arr = get_object_vars($this); $json = json_encode($arr, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT); @@ -45,132 +64,132 @@ class Config // ________________________________________ G E T _______________________________________ - public function host() + public static function host() { - return $this->host; + return self::$host; } - public function dbname() + public static function dbname() { - return $this->dbname; + return self::$dbname; } - public function user() + public static function user() { - return $this->user; + return self::$user; } - public function password() + public static function password() { - return $this->password; + return self::$password; } - public function arttable() + public static function arttable() { - return $this->arttable; + return self::$arttable; } - public function domain() + public static function domain() { - return $this->domain; + return self::$domain; } - public function admin() + public static function admin() { - return $this->admin; + return self::$admin; } - public function editor() + public static function editor() { - return $this->editor; + return self::$editor; } - public function invite() + public static function invite() { - return $this->invite; + return self::$invite; } - public function read() + public static function read() { - return $this->read; + return self::$read; } - public function color4() + public static function color4() { - return $this->color4; + return self::$color4; } - public function fontsize() + public static function fontsize() { - return $this->fontsize; + return self::$fontsize; } // __________________________________________ S E T ______________________________________ - public function sethost($host) + public static function sethost($host) { - $this->host = strip_tags($host); + self::$host = strip_tags($host); } - public function setdbname($dbname) + public static function setdbname($dbname) { - $this->dbname = strip_tags($dbname); + self::$dbname = strip_tags($dbname); } - public function setuser($user) + public static function setuser($user) { - $this->user = strip_tags($user); + self::$user = strip_tags($user); } - public function setpassword($password) + public static function setpassword($password) { - $this->password = strip_tags($password); + self::$password = strip_tags($password); } - public function setarttable($arttable) + public static function setarttable($arttable) { - $this->arttable = strip_tags($arttable); + self::$arttable = strip_tags($arttable); } - public function setdomain($domain) + public static function setdomain($domain) { - $this->domain = strip_tags($domain); + self::$domain = strip_tags($domain); } - public function setadmin($admin) + public static function setadmin($admin) { - $this->admin = strip_tags($admin); + self::$admin = strip_tags($admin); } - public function seteditor($editor) + public static function seteditor($editor) { - $this->editor = strip_tags($editor); + self::$editor = strip_tags($editor); } - public function setinvite($invite) + public static function setinvite($invite) { - $this->invite = strip_tags($invite); + self::$invite = strip_tags($invite); } - public function setread($read) + public static function setread($read) { - $this->read = strip_tags($read); + self::$read = strip_tags($read); } - public function setcolor4($color4) + public static function setcolor4($color4) { if(strlen($color4) <= 8) { - $this->color4 = $color4; + self::$color4 = $color4; } } - public function setfontsize($fontsize) + public static function setfontsize($fontsize) { $fontsize = intval($fontsize); if($fontsize > 1) { - $this->fontsize = $fontsize; + self::$fontsize = $fontsize; } } diff --git a/w/class/configtest.php b/w/class/configtest.php new file mode 100644 index 0000000..cd72753 --- /dev/null +++ b/w/class/configtest.php @@ -0,0 +1,22 @@ + \ No newline at end of file diff --git a/w/class/controller.php b/w/class/controller.php index 6eab6e4..62b1f49 100644 --- a/w/class/controller.php +++ b/w/class/controller.php @@ -1,16 +1,16 @@ setuser(); - $this->settemplate(); + $this->initplates(); + $this->initconfig(); } @@ -21,9 +21,9 @@ class Controller extends Application $this->user = $this->usermanager->readsession(); } - public function settemplate() + public function initplates() { - $this->templates = new League\Plates\Engine(Model::TEMPLATES_DIR); + $this->plates = new League\Plates\Engine(Model::TEMPLATES_DIR); } public function useriseditor() @@ -37,6 +37,47 @@ class Controller extends Application } } + public function initconfig() + { + Config::readconfig(); + } + + public function showtemplate($template, $params) + { + $params = array_merge($this->commonsparams(), $params); + echo $this->plates->render($template, $params); + } + + public function commonsparams() + { + $commonsparams = []; + $commonsparams['user'] = $this->user; + return $commonsparams; + } + + public function login($redirect = 'home') + { + if(isset($_POST['pass'])) { + $this->user = $this->usermanager->login($_POST['pass']); + $this->usermanager->writesession($this->user); + } + if($redirect == 'art') { + $this->redirect('?id=' . $this->art->id()); + } else { + $this->redirect('?aff=' . $redirect); + } + } + + public function logout($redirect = 'home') + { + $this->user = $this->usermanager->logout(); + $this->usermanager->writesession($this->user); + if($redirect == 'art') { + $this->redirect('?id=' . $this->art->id()); + } else { + $this->redirect('?aff=' . $redirect); + } + } diff --git a/w/class/controlleradmin.php b/w/class/controlleradmin.php index da7d926..42a0f65 100644 --- a/w/class/controlleradmin.php +++ b/w/class/controlleradmin.php @@ -3,6 +3,11 @@ class Controlleradmin extends Controllerdb { + public function desktop() + { + echo '

Admin

'; + } + public function addtable() { diff --git a/w/class/controllerart.php b/w/class/controllerart.php index 8754a20..301c9ab 100644 --- a/w/class/controllerart.php +++ b/w/class/controllerart.php @@ -9,9 +9,6 @@ class Controllerart extends Controllerdb public function __construct($id) { parent::__construct(); - - //echo '

Article

'; - //echo $id; $this->art = new Art2(['id' => $id]); } @@ -20,12 +17,10 @@ class Controllerart extends Controllerdb { if($this->artmanager->exist($this->art->id())) { $this->art = $this->artmanager->get($this->art); - //var_dump($this->art); $this->art->autotaglistupdate($this->artmanager->taglist($this->artmanager->getlister(['id', 'title', 'description', 'tag']), $this->art->autotaglist())); return true; } else { - echo '

Article does not exist yet.

'; return false; } } @@ -33,28 +28,32 @@ class Controllerart extends Controllerdb public function read() { - if($this->importart()) { - if($this->user->level() >= $this->art->secure()) { - $datas = $this->art->templaterender(['id', 'title', 'description', 'javascript', 'html', 'header', 'nav', 'aside', 'section', 'footer']); - echo $this->templates->render('reader', $datas); - } else { - echo '

Not enought right to see the article

'; - } + $artexist = $this->importart(); + $display = $this->user->level() >= $this->art->secure(); + $cancreate = $this->user->cancreate(); - } + $this->showtemplate('read', ['art' => $this->art, 'artexist' => $artexist, 'display' => $display, 'cancreate' => $cancreate]); + } public function edit() { - echo '

Edit

'; - if($this->importart()) { - // vue edit art + if($this->importart() && $this->user->canedit()) { + $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true]); + } else { + $this->redirect('?id=' . $this->art->id()); } } + public function log() + { + $this->importart(); + var_dump($this->art); + } + public function add() { echo '

Add

'; @@ -70,15 +69,20 @@ class Controllerart extends Controllerdb $this->artmanager->delete($this->art); } - public function update($id, $redir= "home") + public function update() { - echo '

Update

'; - $this->art = new Art2($_POST); - $this->art->updatelinkfrom(); - $this->art->autotaglistcalc($this->artmanager->taglist($this->artmanagergetlister(['id', 'title', 'tag']), $this->art->autotaglist())); + + if($this->importart()) { + $this->art->hydrate($_POST); + } + + // $this->art->updatelinkfrom(); + // $this->art->autotaglistcalc($this->artmanager->taglist($this->artmanager->getlister(['id', 'title', 'tag']), $this->art->autotaglist())); $this->artmanager->update($this->art); + $this->redirect('?id=' . $this->art->id() . '&aff=edit'); + } diff --git a/w/class/controllerhome.php b/w/class/controllerhome.php index ecbc3c7..8c98949 100644 --- a/w/class/controllerhome.php +++ b/w/class/controllerhome.php @@ -4,6 +4,7 @@ class Controllerhome extends Controllerdb { protected $modelhome; + protected $opt; public function __construct() { parent::__construct(); @@ -15,24 +16,32 @@ class Controllerhome extends Controllerdb public function desktop() { - echo '

Desktop

'; - - echo '

Menu Bar

'; $this->table2(); } public function table2() { - if ($this->useriseditor()) { - $datas = $this->modelhome->table2(); + $table = $this->artmanager->getlister(['id', 'tag', 'linkfrom', 'linkto', 'description', 'title', 'datemodif', 'datecreation', 'secure']); + $this->opt = $this->modelhome->optinit($table); + + $table2 = $this->modelhome->table2($table, $this->opt); + + $this->showtemplate('home', ['user' => $this->user, 'table2' => $table2, 'opt' =>$this->opt]); - var_dump($datas); - - } } + public function analyseall() + { + if($this->user->level() >= Modeluser::EDITOR) { + $scan = new Modelanalyse; + $scan->analyseall(); + + $this->table2(); + } + } + public function massedit() { echo '

Mass Edit

'; diff --git a/w/class/controllermedia.php b/w/class/controllermedia.php index 8557e74..6bd22cd 100644 --- a/w/class/controllermedia.php +++ b/w/class/controllermedia.php @@ -18,7 +18,6 @@ class Controllermedia extends Controller if($this->useriseditor()) { - echo $this->templates->render('media', ['interface' => 'desktop']); } } diff --git a/w/class/model.php b/w/class/model.php index 8ff7478..0eb3a2f 100644 --- a/w/class/model.php +++ b/w/class/model.php @@ -1,5 +1,5 @@ getlister(['*']); + + $artlist2 = []; + foreach ($artlist as $art) { + $art->setlinkfrom($this->analyselinkfrom($art)); + $artlist2[] = $art; + } + foreach ($artlist2 as $art) { + $art->setlinkto($this->analyselinkto($art->id(), $artlist)); + $this->update($art); + } + } + + + public function analyse(Art2 $art) + { + $art->setlinkfrom($this->analyselinkfrom($art)); + + $artlist = $this->getlister(['id', 'linkfrom']); + $art->setlinkto($this->analyselinkto($art->id(), $artlist)); + + return $art; + } + + + + + public function analyselinkto($id, $artlist) + { + //analyse les liens vers cet article en fouillant tout les linkfrom de la bdd, génere un tableau à stocker dans l'article + $linkto = []; + foreach ($artlist as $link) { + if (in_array($id, $link->linkfrom('array')) && $id != $link->id()) { + $linkto[] = $link->id(); + } + } + return $linkto; + } + + public function analyselinkfrom(Art2 $art) + { + $linkfrom = []; + foreach (self::TEXT_ELEMENTS as $element) { + preg_match_all('#\]\((\?id=|=)(\w+)\)#', $art->$element(), $out); + $linkfrom = array_merge($linkfrom, $out[2]); + } + return array_unique($linkfrom); + + } + +} + + + + + + + +?> \ No newline at end of file diff --git a/w/class/modelart.php b/w/class/modelart.php index 9763a53..ec68eb4 100644 --- a/w/class/modelart.php +++ b/w/class/modelart.php @@ -2,17 +2,22 @@ class Modelart extends Modeldb { - - public function __construct() { + const SELECT = ['title', 'id', 'description', 'tag', 'date', 'datecreation', 'datemodif', 'daterender', 'css', 'quickcss', 'javascript', 'html', 'header', 'section', 'nav', 'aside', 'footer', 'render', 'secure', 'invitepassword', 'interface', 'linkfrom', 'linkto', 'template', 'affcount', 'editcount']; + const BY = ['datecreation', 'title', 'id', 'description', 'datemodif', 'secure']; + const ORDER = ['DESC', 'ASC']; + + + public function __construct() + { parent::__construct(); } - + public function exist($id) { - $req = $this->bdd->prepare(' SELECT COUNT(*) FROM ' . $this->config->arttable() . ' WHERE id = :id '); + $req = $this->bdd->prepare(' SELECT COUNT(*) FROM ' . Config::arttable() . ' WHERE id = :id '); $req->execute(array('id' => $id)); $donnees = $req->fetch(PDO::FETCH_ASSOC); @@ -23,19 +28,18 @@ class Modelart extends Modeldb - public function add(Art2 $art) + public function add(Art2 $art) { if ($this->exist($art->id())) { echo 'idalreadyexist'; } else { - var_dump($art); - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - $request = 'INSERT INTO ' . $this->config->arttable() . '(id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, template, affcount, editcount) - VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :template, :affcount, :editcount)'; + $table = Config::arttable(); + $request = "INSERT INTO $table (id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, linkto, template, affcount, editcount) + VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :linkto, :template, :affcount, :editcount)"; $q = $this->bdd->prepare($request); @@ -61,18 +65,19 @@ class Modelart extends Modeldb $q->bindValue(':invitepassword', $art->invitepassword()); $q->bindValue(':interface', $art->interface()); $q->bindValue(':linkfrom', $art->linkfrom('json')); + $q->bindValue(':linkto', $art->linkto('json')); $q->bindValue(':template', $art->template('json')); $q->bindValue(':affcount', $art->affcount()); $q->bindValue(':editcount', $art->editcount()); $q->execute(); } - } - + } + - public function delete(Art2 $art) + public function delete(Art2 $art) { - $req = $this->bdd->prepare('DELETE FROM ' . $this->config->arttable() . ' WHERE id = :id '); + $req = $this->bdd->prepare('DELETE FROM ' . Config::arttable() . ' WHERE id = :id '); $req->execute(array('id' => $art->id())); $req->closeCursor(); } @@ -80,7 +85,7 @@ class Modelart extends Modeldb public function get(Art2 $art) { - $req = $this->bdd->prepare('SELECT * FROM ' . $this->config->arttable() . ' WHERE id = :id '); + $req = $this->bdd->prepare('SELECT * FROM ' . Config::arttable() . ' WHERE id = :id '); $req->execute(array('id' => $art->id())); $donnees = $req->fetch(PDO::FETCH_ASSOC); @@ -93,14 +98,13 @@ class Modelart extends Modeldb - public function update(Art2 $art) { $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); //$request = 'UPDATE ' . $this->arttable . '(id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, template, affcount, editcount) VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :template, :affcount, :editcount) WHERE id = :id'; - - $request = 'UPDATE ' . $this->arttable . ' SET id = :id, title = :title, description = :description, tag = :tag, date = :date, datecreation = :datecreation, datemodif = :datemodif, daterender = :daterender, css = :css, quickcss = :quickcss, javascript = :javascript, html = :html, header = :header, section = :section, nav = :nav, aside = :aside, footer = :footer, render = :footer, secure = :secure, invitepassword = :invitepassword, interface = :interface, linkfrom = :linkfrom, template = :template, affcount = :affcount, editcount = :editcount WHERE id = :id'; + $table = Config::arttable(); + $request = "UPDATE $table SET id = :id, title = :title, description = :description, tag = :tag, date = :date, datecreation = :datecreation, datemodif = :datemodif, daterender = :daterender, css = :css, quickcss = :quickcss, javascript = :javascript, html = :html, header = :header, section = :section, nav = :nav, aside = :aside, footer = :footer, render = :footer, secure = :secure, invitepassword = :invitepassword, interface = :interface, linkfrom = :linkfrom, linkto = :linkto, template = :template, affcount = :affcount, editcount = :editcount WHERE id = :id"; $q = $this->bdd->prepare($request); @@ -108,10 +112,10 @@ class Modelart extends Modeldb $q->bindValue(':title', $art->title()); $q->bindValue(':description', $art->description()); $q->bindValue(':tag', $art->tag('string')); - $q->bindValue(':date', $now->format('Y-m-d H:i:s')); - $q->bindValue(':datecreation', $now->format('Y-m-d H:i:s')); + $q->bindValue(':date', $art->date('string')); + $q->bindValue(':datecreation', $art->datecreation('string')); $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); - $q->bindValue(':daterender', $now->format('Y-m-d H:i:s')); + $q->bindValue(':daterender', $art->daterender('string')); $q->bindValue(':css', $art->css()); $q->bindValue(':quickcss', $art->quickcss('json')); $q->bindValue(':javascript', $art->javascript()); @@ -126,6 +130,7 @@ class Modelart extends Modeldb $q->bindValue(':invitepassword', $art->invitepassword()); $q->bindValue(':interface', $art->interface()); $q->bindValue(':linkfrom', $art->linkfrom('json')); + $q->bindValue(':linkto', $art->linkto('json')); $q->bindValue(':template', $art->template('json')); $q->bindValue(':affcount', $art->affcount()); $q->bindValue(':editcount', $art->editcount()); @@ -147,7 +152,8 @@ class Modelart extends Modeldb $selection = implode(", ", $selection); - $select = 'SELECT ' . $selection . ' FROM ' . $this->config->arttable() . ' ORDER BY ' . $opt['tri'] . ' ' . $opt['desc']; + + $select = 'SELECT ' . $selection . ' FROM ' . Config::arttable() . ' ORDER BY ' . $opt['tri'] . ' ' . $opt['desc']; $req = $this->bdd->query($select); while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { $list[] = new Art2($donnees); @@ -156,6 +162,51 @@ class Modelart extends Modeldb } } + public function getlisterwhere(array $select = ['id'], array $whereid = [], $by = 'id', $order = 'DESC') + { + // give an array using SELECTION columns and sort and desc OPTIONS + + + $select = array_intersect(array_unique($select), self::SELECT); + if (empty($select)) { + $select = ' * '; + } else { + $select = implode(", ", $select); + } + + + $whereid = array_unique($whereid); + + $list = []; + + if (!in_array($by, self::BY)) { + $by = 'id'; + } + if (!in_array($order, self::ORDER)) { + $order = 'DESC'; + } + + + if (!empty($whereid)) { + $wherestatements = array_map(function ($element) { + return ' id= ?'; + }, $whereid); + $where = 'WHERE ' . implode(' OR ', $wherestatements); + } else { + $where = ''; + } + + $table = Config::arttable(); + $prepare = "SELECT $select FROM $table $where ORDER BY $by $order"; + $req = $this->bdd->prepare($prepare); + $req->execute($whereid); + while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { + $list[] = new Art2($donnees); + } + + return $list; + } + @@ -166,7 +217,7 @@ class Modelart extends Modeldb $artlist = []; - $select = 'SELECT ' . $opt->col('string') . ' FROM ' . $this->config->arttable(); + $select = 'SELECT ' . $opt->col('string') . ' FROM ' . Config::arttable(); $req = $this->bdd->query($select); while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { $artlist[] = new Art2($donnees); @@ -248,7 +299,7 @@ class Modelart extends Modeldb public function lister() { - $req = $this->bdd->query(' SELECT * FROM ' . $this->arttable . ' ORDER BY id '); + $req = $this->bdd->query(' SELECT * FROM ' . Config::arttable() . ' ORDER BY id '); $donnees = $req->fetchAll(PDO::FETCH_ASSOC); $req->closeCursor(); return $donnees; diff --git a/w/class/modelartlist.php b/w/class/modelartlist.php deleted file mode 100644 index acbdce5..0000000 --- a/w/class/modelartlist.php +++ /dev/null @@ -1,159 +0,0 @@ - 'id', 'desc' => 'DESC']; - $opt = array_update($default, $opt); - - $list = []; - $option = ['datecreation', 'title', 'id', 'description', 'datemodif', 'tag', 'secure']; - if (is_array($selection) && is_string($opt['tri']) && strlen($opt['tri']) < 16 && is_string($opt['desc']) && strlen($opt['desc']) < 5 && in_array($opt['tri'], $option)) { - - $selection = implode(", ", $selection); - - $select = 'SELECT ' . $selection . ' FROM ' . $this->arttable . ' ORDER BY ' . $opt['tri'] . ' ' . $opt['desc']; - $req = $this->bdd->query($select); - while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { - $list[] = new Art2($donnees); - } - return $list; - } - } - - - - - - - public function getlisteropt(Opt $opt) - { - - $artlist = []; - - $select = 'SELECT ' . $opt->col('string') . ' FROM ' . $this->arttable; - $req = $this->bdd->query($select); - while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { - $artlist[] = new Art2($donnees); - } - return $artlist; - - } - - public function listcalclinkfrom(&$artlist) - { - foreach ($artlist as $art) { - $art->calclinkto($artlist); - } - } - - public function artcompare($art1, $art2, $method = 'id', $order = 1) - { - $result = ($art1->$method('sort') <=> $art2->$method('sort')); - return $result * $order; - - } - - public function buildsorter($sortby, $order) - { - return function ($art1, $art2) use ($sortby, $order) { - $result = $this->artcompare($art1, $art2, $sortby, $order); - return $result; - }; - } - - - - public function artlistsort(&$artlist, $sortby, $order = 1) - { - return usort($artlist, $this->buildsorter($sortby, $order)); - } - - - - - - - public function filtertagfilter(array $artlist, array $tagchecked, $tagcompare = 'OR') - { - - $filteredlist = []; - foreach ($artlist as $art) { - if (empty($tagchecked)) { - $filteredlist[] = $art->id(); - } else { - $inter = (array_intersect($art->tag('array'), $tagchecked)); - if ($tagcompare == 'OR') { - if (!empty($inter)) { - $filteredlist[] = $art->id(); - } - } elseif ($tagcompare == 'AND') { - if (!array_diff($tagchecked, $art->tag('array'))) { - $filteredlist[] = $art->id(); - } - } - } - } - return $filteredlist; - } - - public function filtersecure(array $artlist, $secure) - { - $filteredlist = []; - foreach ($artlist as $art) { - if ($art->secure() == intval($secure)) { - $filteredlist[] = $art->id(); - } elseif (intval($secure) >= 4) { - $filteredlist[] = $art->id(); - } - } - return $filteredlist; - } - - - public function lister() - { - $req = $this->bdd->query(' SELECT * FROM ' . $this->arttable . ' ORDER BY id '); - $donnees = $req->fetchAll(PDO::FETCH_ASSOC); - $req->closeCursor(); - return $donnees; - - } - - public function tag(array $artlist, $tagchecked) - { - $artcheckedlist = []; - foreach ($artlist as $art) { - if (in_array($tagchecked, $art->tag('array'))) { - $artcheckedlist[] = $art; - } - } - return $artcheckedlist; - } - - public function taglist(array $artlist, array $tagcheckedlist) - { - $taglist = []; - foreach ($tagcheckedlist as $tag) { - $taglist[$tag] = $this->tag($artlist, $tag); - } - return $taglist; - } - - public function count() - { - return $this->bdd->query(' SELECT COUNT(*) FROM ' . $this->arttable . ' ')->fetchColumn(); - } - -} - - - - - -?> \ No newline at end of file diff --git a/w/class/modelconfig.php b/w/class/modelconfig.php index 748edb1..7c5fc18 100644 --- a/w/class/modelconfig.php +++ b/w/class/modelconfig.php @@ -1,8 +1,8 @@ setbdd(); - } + $this->setbdd(); + //self::setdb(); + } + public function setbdd() @@ -16,7 +20,35 @@ class Modeldb extends Model $caught = true; try { - $this->bdd = new PDO('mysql:host=' . $this->config->host() . ';dbname=' . $this->config->dbname() . ';charset=utf8', $this->config->user(), $this->config->password(), array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT)); + $this->bdd = new PDO('mysql:host=' . Config::host() . ';dbname=' . Config::dbname() . ';charset=utf8', Config::user(), Config::password(), array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT)); + //$this->bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } catch (PDOException $e) { + $caught = false; + echo '

Error 500, database offline

'; + if ($this->session() >= self::EDITOR) { + echo '

Error : ' . $e->getMessage() . '

'; + if ($this->session() == self::ADMIN) { + echo '

Go to the Admin Panel to edit your database credentials

'; + } else { + echo '

Logout and and come back with an admin password to edit the database connexions settings.

'; + } + } else { + echo '

Homepage for admin login (connect on the top right side)

'; + } + exit; + } + + return $caught; + + } + + + public static function setdb() + { + $caught = true; + + try { + self::$db = new PDO('mysql:host=' . Config::host() . ';dbname=' . Config::dbname() . ';charset=utf8', Config::user(), Config::password(), array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT)); //$this->bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { $caught = false; @@ -40,8 +72,8 @@ class Modeldb extends Model public function settable(Config $config) { - if (!empty($config->arttable())) { - $this->arttable = $config->arttable(); + if (!empty(Config::arttable())) { + $this->arttable = Config::arttable(); } else { echo '

Table Error

'; @@ -87,7 +119,6 @@ class Modeldb extends Model - } public function tablelist($dbname) diff --git a/w/class/modelhome.php b/w/class/modelhome.php index 660352f..3ff72c7 100644 --- a/w/class/modelhome.php +++ b/w/class/modelhome.php @@ -2,28 +2,39 @@ class Modelhome extends Modeldb { - public function table2() + + public function __construct() { + parent::__construct(); + } + + public function optinit($table) { - $artmanager = new Modelart; $opt = new Opt(Art2::classvarlist()); - $opt->setcol(['id', 'tag', 'linkfrom', 'contenu', 'description', 'title', 'datemodif', 'datecreation', 'secure']); - $table = $artmanager->getlisteropt($opt); - $artmanager->listcalclinkfrom($table); + $opt->setcol(['id', 'tag', 'linkfrom', 'linkto', 'description', 'title', 'datemodif', 'datecreation', 'secure']); + //$table = $listmanager->getlisteropt($opt); + //$listmanager->listcalclinkfrom($table); $opt->settaglist($table); $opt->submit(); - $opt->setcol(['id', 'tag', 'linkfrom', 'contenu', 'description', 'title', 'datemodif', 'datecreation', 'secure', 'linkto']); + return $opt; + } + + public function optupdate() + { + + } - //$aff->option($app, $opt); - echo '

Options

'; + public function table2($table, $opt) + { + $listmanager = new Modelart; - $filtertagfilter = $artmanager->filtertagfilter($table, $opt->tagfilter(), $opt->tagcompare()); - $filtersecure = $artmanager->filtersecure($table, $opt->secure()); + $filtertagfilter = $listmanager->filtertagfilter($table, $opt->tagfilter(), $opt->tagcompare()); + $filtersecure = $listmanager->filtersecure($table, $opt->secure()); $filter = array_intersect($filtertagfilter, $filtersecure); $table2 = []; @@ -42,7 +53,7 @@ class Modelhome extends Modeldb $table2 = $table2invert; } - $artmanager->artlistsort($table2, $opt->sortby(), $opt->order()); + $listmanager->artlistsort($table2, $opt->sortby(), $opt->order()); return $table2; diff --git a/w/class/modelmedia.php b/w/class/modelmedia.php index 9f61609..14a1c4e 100644 --- a/w/class/modelmedia.php +++ b/w/class/modelmedia.php @@ -2,9 +2,6 @@ class Modelmedia extends Model { - public function __construct() { - - } public function addmedia(array $file, $maxsize = 2 ** 24, $id) { diff --git a/w/class/modelrender.php b/w/class/modelrender.php new file mode 100644 index 0000000..219e88e --- /dev/null +++ b/w/class/modelrender.php @@ -0,0 +1,187 @@ +template('array') as $element => $tempalteid) { + if(isset($tempalteid) && $tempalteid != $art->id()) { + $templateart = new Art2(['id' => $templateid]); + $templateart = $this->get($templateart); + $templates[$element] = $templateart->$element(); + } + } + + $elements = []; + foreach ($art->template('array') as $element) { + if(array_key_exists($element, $templates)) { + $elements[$element] = $templates[$element] . PHP_EOL . $art->$element(); + } else { + $elements[$element] = $art->$element(); + } + } + return $elements; + } + + public function elementsrender(array $elements) + { + foreach ($elements as $element => $text) { + if(in_array($element, self::TEXT_ELEMENTS)) { + $elements[$element] = $this->textrender($text); + } + } + return $elements; + } + + + + public function textrender($text) + { + + } + + + public function parser($text) + { + $text = str_replace('%TITLE%', $this->title(), $this->text); + $text = str_replace('%DESCRIPTION%', $this->description(), $text); + + $text = $this->markdown($text); + + $text = str_replace('%SUMMARY%', sumparser($text), $text); + + $text = str_replace('href="=', 'href="?id=', $text); + + 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)); + }; + $text = $fortin->transform($text); + return $text; + } + + + + + public function tooltip($linkfrom, $text) + { + $descriptions = []; + $artlist = $app->getlisterwhere(['id', 'description'], $linkfrom); + foreach ($artlist as $art) { + $descriptions[$art->id()] = $art->description(); + } + + + + foreach ($linkfrom as $id) { + if(isset($descriptions[$id])) { + $title = $descriptions[$id]; + } else { + $title = "This page does not exist yet"; + } + $linkfrom = 'href="?id=' . $id . '"'; + $titlelinkfrom = ' title="' . $title . '" ' . $linkfrom; + $text = str_replace($linkfrom, $titlelinkfrom, $text); + } + } + + public function parserff($text) + { + $section = str_replace('%TITLE%', $this->title(), $this->section); + $section = str_replace('%DESCRIPTION%', $this->description(), $section); + + + + // replace = > ?id= + $section = str_replace('href="=', 'href="?id=', $section); + + + // infobulles tooltip + + + + + if (!empty(strstr($section, '%SUMMARY%'))) { + + + + + } + + + $section = str_replace('href="./media/', ' class="file" target="_blank" href="./media/', $section); + $section = str_replace('href="http', ' class="external" target="_blank" href="http', $section); + $section = str_replace('
', $section); + return $section; + + } + + + + + function sumparser($text) + { + preg_match_all('#(.+)#iU', $text, $out); + + + $sum = []; + foreach ($out[2] as $key => $value) { + $sum[$value][$out[1][$key]] = $out[3][$key]; + } + + + $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) { + $sumstring .= '
  • '.$link.'
  • ' ; + } + $last = $h; + } + } + for ($i = 1; $i <= ($last); $i++) { + $sumstring .= ''; + } + return $sumstring; + } + + + + + +} + + + +?> \ No newline at end of file diff --git a/w/class/modeluser.php b/w/class/modeluser.php index adce383..899d1cc 100644 --- a/w/class/modeluser.php +++ b/w/class/modeluser.php @@ -9,14 +9,10 @@ class Modeluser extends Model const READ = 1; const FREE = 0; - public function __construct() - { - parent::__construct(); - } public function writesession(User $user) { - $_SESSION['user'] = (array) $user; + $_SESSION['user'] = ['level' => $user->level()]; } public function readsession() @@ -37,20 +33,22 @@ class Modeluser extends Model public function passlevel($pass) { - if (strip_tags($pass) == $this->config->admin()) { + if (strip_tags($pass) == Config::admin()) { return $level = self::ADMIN; - } elseif (strip_tags($pass) == $this->config->read()) { + } elseif (strip_tags($pass) == Config::read()) { return $level = self::READ; - } elseif (strip_tags($pass) == $this->config->editor()) { + } elseif (strip_tags($pass) == Config::editor()) { return $level = self::EDITOR; - } elseif (strip_tags($pass) == $this->config->invite()) { + } elseif (strip_tags($pass) == Config::invite()) { return $level = self::INVITE; + } else { + return $level = self::FREE; } } public function logout() { - $user = new User(['level' => 0]); + $user = new User(['level' => self::FREE]); return $user; } } diff --git a/w/class/router.php b/w/class/router.php index 4d9d718..32a4c96 100644 --- a/w/class/router.php +++ b/w/class/router.php @@ -9,6 +9,8 @@ class Router 'art' => ['art', 'read'], 'art aff=read' => ['art', 'read'], 'art aff=edit' => ['art', 'edit'], + 'art aff=log' => ['art', 'log'], + 'art action=update' => ['art', 'update'], 'art action=update home' => ['art', 'update', 'home'], 'art action=add' => ['art', 'add'], 'art action=delete' => ['art', 'delete'], @@ -17,11 +19,17 @@ class Router '' => ['home', 'desktop'], 'aff=home action=massedit' => ['home', 'massedit'], 'action=massedit' => ['home', 'massedit'], - 'art action=login' => ['art', 'login'], - 'home action=login' => ['home', 'login'], + 'action=analyseall' => ['home', 'analyseall'], + 'aff=home action=analyseall' => ['home', 'analyseall'], + 'art action=login' => ['art', 'login', 'art'], + 'home action=login' => ['home', 'login', 'home'], 'action=login' => ['home', 'login'], + 'art action=logout' => ['art', 'logout', 'art'], + 'home action=logout' => ['home', 'logout', 'home'], + 'action=logout' => ['home', 'logout'], 'aff=media' => ['media', 'desktop'], 'aff=media action=addmedia' => ['media', 'addmedia'], + 'aff=admin' => ['admin', 'desktop'], ]; public function __construct() { @@ -46,7 +54,7 @@ class Router $class = 'controller' . $method[0]; $function = $method[1]; - $controller = new $class($this->route->artid()); + $controller = new $class($this->route->id()); $params = array_slice($method, 2); $controller->$function(...$params); } diff --git a/w/class/user.php b/w/class/user.php index 3ed831d..77d6ba2 100644 --- a/w/class/user.php +++ b/w/class/user.php @@ -30,6 +30,27 @@ class User { return $this->level; } + + public function isvisitor() + { + return $this->level === Modeluser::FREE; + } + + public function canedit() + { + // a modifier en prenant compte du code invitation de l'article + return $this->level >= Modeluser::EDITOR; + } + + public function cancreate() + { + return $this->level >=Modeluser::EDITOR; + } + + public function isadmin() + { + return $this->level === Modeluser::ADMIN; + } } diff --git a/w/fn/w.fn.php b/w/fn/w.fn.php index fe3ea48..558ae67 100644 --- a/w/fn/w.fn.php +++ b/w/fn/w.fn.php @@ -135,42 +135,7 @@ function str_clean(string $string) return str_replace(' ', '_', strtolower(strip_tags($string))); } -function sumparser($text) -{ - preg_match_all('#(.+)#iU', $text, $out); - - - $sum = []; - foreach ($out[2] as $key => $value) { - $sum[$value][$out[1][$key]] = $out[3][$key]; - } - - - $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; -} + ?> \ No newline at end of file diff --git a/w/view/templates/base.php b/w/view/templates/base.php deleted file mode 100644 index aaca8e1..0000000 --- a/w/view/templates/base.php +++ /dev/null @@ -1,10 +0,0 @@ - - - <?=$this->e($title)?> - - - -section('content')?> - - - \ No newline at end of file diff --git a/w/view/templates/body.php b/w/view/templates/body.php new file mode 100644 index 0000000..e69de29 diff --git a/w/view/templates/edit.php b/w/view/templates/edit.php new file mode 100644 index 0000000..39c2104 --- /dev/null +++ b/w/view/templates/edit.php @@ -0,0 +1,47 @@ +layout('layout', ['title' => '✏ '.$art->title()]) ?> + + + + + +start('customhead') ?> + +stop() ?> + + + + + + +start('page') ?> + + + + insert('navart', ['user' => $user, 'art' => $art, 'artexist' => $artexist]) ?> + + +
    + + + + insert('edittopbar', ['config' => $config, 'art' => $art]) ?> + insert('editsidebar', ['config' => $config, 'art' => $art]) ?> + + + + + $art->md(), 'css' => $art->css(), 'header' => $art->header(), 'nav' => $art->nav(), 'aside' => $art->aside(), 'footer' => $art->footer(), 'html' => $art->html(), 'javascript' => $art->javascript()]; + $this->insert('edittabs', ['tablist' => $tablist, 'opentab' => $art->interface()]) + ?> + + + + + + +
    + + + +stop() ?> \ No newline at end of file diff --git a/w/view/templates/edithelp.php b/w/view/templates/edithelp.php new file mode 100644 index 0000000..fee94c7 --- /dev/null +++ b/w/view/templates/edithelp.php @@ -0,0 +1,27 @@ + +

    Help !

    +

    To save your article, press the HOME, UPDATE, or DISPLAY buttons. You can use the keyboard shortcuts as well.

    +
    ALT + W : home
    +
    ALT + X : update
    +
    ALT + C : display
    +

    Markdown

    +

    The html section use Markdown encoding. Actualy, W is using Michel Fortin's Markdown Extra.

    +

    Links

    +
    [text](=article_id)
    +

    where article_id is the article's id you want to point to.

    +

    Images

    +
    [altimage](/img_id.extension)
    +

    Where img_id is the id of your image and its extension.

    +

    Shortcuts

    +
    %TITLE%
    +

    Show the title of your article.

    +
    %DESCRIPTION%
    +

    Show the description of your article.

    +
    %SUMMARY%
    +

    Generate a summary, the list of all your head titles using #, ##, ###...

    +
    %%tag_name%%
    +

    Generate a menu, a list of links to all articles under this tag.

    +

    vv

    +

    vv

    +

    vv

    +

    \ No newline at end of file diff --git a/w/view/templates/editsidebar.php b/w/view/templates/editsidebar.php new file mode 100644 index 0000000..99612dd --- /dev/null +++ b/w/view/templates/editsidebar.php @@ -0,0 +1,40 @@ + \ No newline at end of file diff --git a/w/view/templates/edittabs.php b/w/view/templates/edittabs.php new file mode 100644 index 0000000..c65a7c7 --- /dev/null +++ b/w/view/templates/edittabs.php @@ -0,0 +1,19 @@ +
    + + $value) { + echo '
    '; + if ($key == $opentab) { + echo ''; + } else { + echo ''; + } + echo ''; + echo '
    '; + echo ''; + echo '
    '; + echo '
    '; +} +?> + +
    \ No newline at end of file diff --git a/w/view/templates/edittopbar.php b/w/view/templates/edittopbar.php new file mode 100644 index 0000000..7e7f9e8 --- /dev/null +++ b/w/view/templates/edittopbar.php @@ -0,0 +1,12 @@ +
    + + + + + 👁 + + id() ?> + + + +
    \ No newline at end of file diff --git a/w/view/templates/home.php b/w/view/templates/home.php new file mode 100644 index 0000000..34bac1a --- /dev/null +++ b/w/view/templates/home.php @@ -0,0 +1,85 @@ +layout('layout', ['title' => 'home']) ?> + + + + +start('page') ?> + + + + + insert('navback', ['user' => $user]) ?> + + +
    +
    + + + insert('homeopt', ['opt' => $opt]) ?> + + + +
    +

    Articles

    +
    + + +
    +

    Mass Edit

    + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +
    xideditseelogtagsummary↘ to↗ fromlast modificationdate of creationprivacy
    👁tag('sort') ?>description() ?>linkto('sort') ?>linkfrom('sort') ?>datemodif('hrdi') ?>datecreation('hrdi') ?>secure('string') ?>
    +
    +
    +
    +
    + + + + +stop() ?> \ No newline at end of file diff --git a/w/view/templates/homeopt.php b/w/view/templates/homeopt.php new file mode 100644 index 0000000..cecb79b --- /dev/null +++ b/w/view/templates/homeopt.php @@ -0,0 +1,84 @@ +
    +

    Options

    +
    + +⬅ + + + + +
    Sort + +
    +order() == '1' ? "checked" : "" ?>/> +
    +order() == '-1' ? "checked" : "" ?>/> + +
    + +
    Privacy
      +
    • secure() == 4 ? "checked" : "" ?>/>
    • +
    • secure() == 3 ? "checked" : "" ?>/>
    • +
    • secure() == 2 ? "checked" : "" ?>/>
    • +
    • secure() == 1 ? "checked" : "" ?>/>
    • +
    • secure() == 0 ? "checked" : "" ?>/>
    • +
    + +
    Tag
      + + +tagcompare() == "OR" ? "checked" : "" ?> > +tagcompare() == "AND" ? "checked" : "" ?>> + +taglist() as $tagfilter => $count) { + + if ($count > $limit && $in == false) { + echo '
      >' . $limit . ''; + $in = true; + } + if ($count == $limit && $in == true && $out == false) { + echo '
      ' . $limit . ''; + $out = true; + } + + if (in_array($tagfilter, $opt->tagfilter())) { + + echo '
    • '; + } else { + echo '
    • '; + } +} +if ($in = true || $out = true) { + echo '
      '; +} +?> + +
    + + invert() == 1) { + echo ''; + } else { + echo ''; + } + echo '
    diff --git a/w/view/templates/layout.php b/w/view/templates/layout.php new file mode 100644 index 0000000..263cca3 --- /dev/null +++ b/w/view/templates/layout.php @@ -0,0 +1,20 @@ + + + + + + + + <?= $title ?> + + section('customhead')?> + section('arthead')?> + + + + + +section('page')?> + + + \ No newline at end of file diff --git a/w/view/templates/nav.php b/w/view/templates/nav.php deleted file mode 100644 index e731673..0000000 --- a/w/view/templates/nav.php +++ /dev/null @@ -1,42 +0,0 @@ -