diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-10-28 19:56:27 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-10-28 19:56:27 +0100 |
commit | e17392e46259e6f2e012017987cf7c31c171488f (patch) | |
tree | 72b61b63e32819e81433e8df6f14dc92b0e3a604 | |
parent | a91c916248f967da2d4218b575e665242b7c975b (diff) | |
download | wcms-e17392e46259e6f2e012017987cf7c31c171488f.tar.gz wcms-e17392e46259e6f2e012017987cf7c31c171488f.zip |
abstract config NWY
45 files changed, 1461 insertions, 556 deletions
diff --git a/public/css/soft.css b/public/css/soft.css new file mode 100644 index 0000000..108f44e --- /dev/null +++ b/public/css/soft.css @@ -0,0 +1,13 @@ +div#options { + display: inline-block; + float: left; +} + +div#main { + display: inline-block; +} + +.menu { + position: fixed; + right: 0; +}
\ No newline at end of file diff --git a/public/test.php b/public/test.php index 0544502..7af0a01 100644 --- a/public/test.php +++ b/public/test.php @@ -1,19 +1,15 @@ <?php - -$data = ['id' => 'cool', 'redirect' => 'edit']; - -require('../w/class/route.php'); - -$route = new Route($data); - -var_dump($route); - -var_dump($route->toarray()); -var_dump($route->tostring()); - -$array = []; - -var_dump(implode(' ', $array)); - - +function test() +{ + static $count = 0; + + $count++; + echo $count; + if ($count < 10) { + test(); + } + $count--; +} + +test(); ?>
\ No newline at end of file diff --git a/public/test2.php b/public/test2.php index a0cbafa..3e5fb1b 100644 --- a/public/test2.php +++ b/public/test2.php @@ -13,7 +13,7 @@ session_start(); <?php -require('../w/class/class.w.quickcss.php'); +require('../w/class/quickcss.php'); $quick = new Quickcss($_POST); diff --git a/public/test3.php b/public/test3.php new file mode 100644 index 0000000..dcdb979 --- /dev/null +++ b/public/test3.php @@ -0,0 +1,8 @@ +<?php + + + + + + +?>
\ No newline at end of file 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 @@ <?php -use Michelf\MarkdownExtra; - - class Art2 { private $id; @@ -88,6 +85,7 @@ class Art2 $this->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 @@ +<?php + + + +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; + + +// _______________________________________ F U N _______________________________________ + + 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 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 @@ +<?php + +abstract class Configtest +{ + protected static $info; + + public static function setinfo($info) + { + self::$info = $info; + } + + public static function info() + { + return self::$info; + } +} + + + + + +?>
\ 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 @@ <?php -class Controller extends Application +class Controller { protected $user; protected $usermanager; - protected $templates; + protected $plates; public function __construct() { - parent::__construct(); $this->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 '<h1>Admin</h1>'; + } + 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 '<h1>Article</h1>'; - //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 '<h3>Article does not exist yet.</h3>'; 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 '<h3>Not enought right to see the article</h3>'; - } + $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 '<h2>Edit</h2>'; - 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 '<h2>Add</h2>'; @@ -70,15 +69,20 @@ class Controllerart extends Controllerdb $this->artmanager->delete($this->art); } - public function update($id, $redir= "home") + public function update() { - echo '<h2>Update</h2>'; - $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 '<h1>Desktop</h1>'; - - echo '<h2>Menu Bar</h2>'; $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 '<h2>Mass Edit</h2>'; 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 @@ <?php -class Model extends Application +class Model { const CONFIG_FILE = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'w.config.json'; @@ -9,9 +9,8 @@ class Model extends Application const MEDIA_EXTENSIONS = array('jpeg', 'jpg', 'JPG', 'png', 'gif', 'mp3', 'mp4', 'mov', 'wav', 'flac', 'pdf'); const MEDIA_TYPES = ['image', 'video', 'sound', 'other']; - public function __construct() { - parent::__construct(); - } + const TEXT_ELEMENTS = ['section', 'header', 'nav', 'aside', 'footer']; + } diff --git a/w/class/modelanalyse.php b/w/class/modelanalyse.php new file mode 100644 index 0000000..b7819aa --- /dev/null +++ b/w/class/modelanalyse.php @@ -0,0 +1,73 @@ +<?php + + + +class Modelanalyse extends Modelart +{ + + + public function __construct() { + parent::__construct(); + } + + public function analyseall() + { + $artlist = $this->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 '<span class="alert">idalreadyexist</span>'; } 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 @@ -<?php - -class Modelartlist extends Modeldb -{ - - - public function getlister(array $selection = ['id'], array $opt = []) - { - // give an array using SELECTION columns and sort and desc OPTIONS - - $default = ['tri' => '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 @@ <?php -class Modelconfig extends Model +abstract class Modelconfig extends Model { - public function readconfig() + public static function readconfig() { if (file_exists(self::CONFIG_FILE)) { $current = file_get_contents(self::CONFIG_FILE); @@ -14,13 +14,13 @@ class Modelconfig extends Model } - public function createconfig(array $donnees) + public static function createconfig(array $donnees) { return new Config($donnees); } - public function savejson(string $json) + public static function savejson(string $json) { file_put_contents(self::CONFIG_FILE, $json); } diff --git a/w/class/modeldb.php b/w/class/modeldb.php index 7814acd..346a275 100644 --- a/w/class/modeldb.php +++ b/w/class/modeldb.php @@ -1,14 +1,18 @@ <?php class Modeldb extends Model { + /** @var PDO */ protected $bdd; - protected $arttable; + protected $arttable; + + protected static $db; public function __construct() { - parent::__construct(); - $this->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 '<h1>Error 500, database offline</h1>'; + if ($this->session() >= self::EDITOR) { + echo '<p>Error : ' . $e->getMessage() . '</p>'; + if ($this->session() == self::ADMIN) { + echo '<p>Go to the <a href="?aff=admin">Admin Panel</a> to edit your database credentials</p>'; + } else { + echo '<p>Logout and and come back with an <strong>admin password</strong> to edit the database connexions settings.</p>'; + } + } else { + echo '<p><a href=".">Homepage for admin login</a> (connect on the top right side)</p>'; + } + 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 '<h1>Table Error</h1>'; @@ -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 '<h3>Options</h3>'; + 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 @@ +<?php + +class Modelrender extends Modelart +{ + const SUMMARY = '%SUMMARY%'; + + + public function __construct() { + parent::__construct(); + } + + + + public function getelements(Art2 $art) + { + $templates = []; + foreach ($art->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('<img src="/', '<img src="./media/', $section); + $section = str_replace('<iframe', '<div class="iframe"><div class="container"><iframe class="video" ', $section); + $section = str_replace('</iframe>', '</iframe></div></div>', $section); + return $section; + + } + + + + + function sumparser($text) + { + preg_match_all('#<h([1-6]) id="(\w+)">(.+)</h[1-6]>#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 .= '<ul>'; + } + $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; + } elseif ($h < $last) { + for ($i = 1; $i <= ($last - $h); $i++) { + $sumstring .= '</ul>'; + } + $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; + } elseif ($h = $last) { + $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; + } + $last = $h; + } + } + for ($i = 1; $i <= ($last); $i++) { + $sumstring .= '</ul>'; + } + 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('#<h([1-6]) id="(\w+)">(.+)</h[1-6]>#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 .= '<ul>'; - } - $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; - } elseif ($h < $last) { - for ($i = 1; $i <= ($last - $h); $i++) { - $sumstring .= '</ul>'; - } - $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; - } elseif ($h = $last) { - $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; - } - $last = $h; - } - } - for ($i = 1; $i <= ($last); $i++) { - $sumstring .= '</ul>'; - } - 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 @@ -<html> -<head> - <title><?=$this->e($title)?></title> -</head> -<body> - -<?=$this->section('content')?> - -</body> -</html>
\ 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 --- /dev/null +++ b/w/view/templates/body.php 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 @@ +<?php $this->layout('layout', ['title' => '✏ '.$art->title()]) ?> + + + + + +<?php $this->start('customhead') ?> + <script src="./rsc/js/app.js"></script> +<?php $this->stop() ?> + + + + + + +<?php $this->start('page') ?> + +<body> + + <?php $this->insert('navart', ['user' => $user, 'art' => $art, 'artexist' => $artexist]) ?> + + +<form action="?id=<?= $art->id() ?>&action=update" method="post" id="artedit"> + + + + <?php $this->insert('edittopbar', ['config' => $config, 'art' => $art]) ?> + <?php $this->insert('editsidebar', ['config' => $config, 'art' => $art]) ?> + + +<style>textarea{font-size: <?= Config::fontsize() ?>px}</style> + + <?php + $tablist = ['section' => $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()]) + ?> + + + + +<input type="hidden" name="id" value="<?= $art->id() ?>"> + +</form> + +</body> + +<?php $this->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 @@ + + <h2>Help !</h2> + <p>To save your article, press the HOME, UPDATE, or DISPLAY buttons. You can use the keyboard shortcuts as well.</p> + <pre><span class="i">ALT + W</span> : home</pre> + <pre><span class="i">ALT + X</span> : update</pre> + <pre><span class="i">ALT + C</span> : display</pre> + <h3>Markdown</h3> + <p>The html section use <a href="https://daringfireball.net/projects/markdown/syntax" target="_blank">Markdown encoding</a>. Actualy, W is using Michel Fortin's <a href="https://michelf.ca/projects/php-markdown/extra/" target="_blank">Markdown Extra</a>.</p> + <h3>Links</h3> + <pre>[text](=<span class="i">article_id</span>)</pre> + <p>where article_id is the article's id you want to point to.</p> + <h3>Images</h3> + <pre>[altimage](/<span class="i">img_id.extension</span>)</pre> + <p>Where img_id is the id of your image and its extension.</p> + <h3>Shortcuts</h3> + <pre>%TITLE%</pre> + <p>Show the title of your article.</p> + <pre>%DESCRIPTION%</pre> + <p>Show the description of your article.</p> + <pre>%SUMMARY%</pre> + <p>Generate a <strong>summary</strong>, the list of all your head titles using #, ##, ###...</p> + <pre>%%<span class="i">tag_name</span>%%</pre> + <p>Generate a <strong>menu</strong>, a list of links to all articles under this tag.</p> + <p>vv</p> + <p>vv</p> + <p>vv</p> + <p></p>
\ 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 @@ +<div class="sidebar"> + <details id="editinfo" open> + <summary>Infos</summary> + <fieldset> + <label for="title">title :</label> + <input type="text" name="title" id="title" value="<?= $art->title(); ?>"> + <label for="description">Description :</label> + <input type="text" name="description" id="description" value="<?= $art->description(); ?>"> + <label for="tag">Tag(s) :</label> + <input type="text" name="tag" id="tag" value="<?= $art->tag('string'); ?>"> + <label for="secure">Privacy level :</label> + <select name="secure" id="secure"> + <option value="0" <?= $art->secure() == 0 ? 'selected' : '' ?>>0</option> + <option value="1" <?= $art->secure() == 1 ? 'selected' : '' ?>>1</option> + <option value="2" <?= $art->secure() == 2 ? 'selected' : '' ?>>2</option> + <option value="3" <?= $art->secure() == 3 ? 'selected' : '' ?>>3</option> + </select> + </fieldset> + </details> + <details> + <summary>Advanced</summary> + <fieldset> + <h3>Template options</h3> + <p>NOT WORKING</p> + </fieldset> + </details> + <details id="editcss" open> + <summary>Quick CSS</summary> + + </details> + <details> + <summary>Help</summary> + <div id="help"> + <?php $this->insert('edithelp') ?> + + </div> + </details> + + +</div>
\ 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 @@ +<div class="tabs"> + +<?php +foreach ($tablist as $key => $value) { + echo '<div class="tab">'; + if ($key == $opentab) { + echo '<input name="interface" type="radio" value="'.$key.'" id="tab' . $key . '" class="checkboxtab" checked>'; + } else { + echo '<input name="interface" type="radio" value="'.$key.'" id="tab' . $key . '" class="checkboxtab">'; + } + echo '<label for="tab' . $key . '">' . $key . '</label>'; + echo '<div class="content">'; + echo '<textarea name="' . $key . '" id="' . $key . '" >' . $value . '</textarea>'; + echo '</div>'; + echo '</div>'; +} +?> + +</div>
\ 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 @@ +<div id="submit"> + <!-- <input type="submit" name="action" value="home" accesskey="w" onclick="document.getElementById('artedit').submit();" form="artedit"> --> + <input type="submit" name="action" value="update" accesskey="x" onclick="document.getElementById('artedit').submit();" form="artedit"> + <!-- <input type="submit" name="action" value="display" accesskey="c" onclick="document.getElementById('artedit').submit();" form="artedit"> --> + <!-- <input type="submit" name="action" value="delete" onclick="confirmSubmit(event, 'Delete this article', 'artedit')" form="artedit"> --> + <a href="?id=<?= $art->id() ?>" target="_blank">👁</a> + + <span id="headid"><?= $art->id() ?></span> + + <label for="fontsize">Font-size</label> + <input type="number" name="fontsize" value="<?= Config::fontsize() ?>" id="fontsize"> +</div>
\ 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 @@ +<?php $this->layout('layout', ['title' => 'home']) ?> + + + + +<?php $this->start('page') ?> + + +<body> + + <?php $this->insert('navback', ['user' => $user]) ?> + + +<section> +<div id="flex"> + + + <?php $this->insert('homeopt', ['opt' => $opt]) ?> + + + +<div id="main"> +<h2>Articles</h2> +<form action="./" method="post"> + + + <div id="massedit"> + <h3>Mass Edit</h3> + <select name="massedit" required> + <option value="public">set as public</option> + <option value="private">set as private</option> + <option value="not published">set as not published</option> + <option value="erasetag">erase all tags</option> + <option value="erasetemplate">erase template</option> + <option value="delete">delete</option> + </select> + + <input type="submit" name="massaction" value="do" onclick="confirmSubmit(event, 'Are you sure')" > + + <input type="text" name="targettag" placeholder="add tag"> + <input type="submit" name="massaction" value="add tag" onclick="confirmSubmit(event, 'Are you sure')" > + + <select name="masstemplate"> + <?php + foreach ($table2 as $art) { + echo '<option value="' . $art->id() . '">' . $art->id() . '</option>'; + } + ?> + </select> + + <input type="submit" name="massaction" value="set template" onclick="confirmSubmit(event, 'Are you sure')" > + + <input type="hidden" name="action" value="massedit"> + </div> + + + <table id="home2table"> + <tr><th>x</th><th>id</th><th>edit</th><th>see</th><th>log</th><th>tag</th><th>summary</th><th>↘ to</th><th>↗ from</th><th>last modification</th><th>date of creation</th><th>privacy</th></tr> + <?php foreach ($table2 as $item) { ?> + <tr> + <td><input type="checkbox" name="id[]" value="<?= $item->id() ?>" id="<?= $item->id() ?>"></td> + <td><label title="<?= $item->title() ?>" for="<?= $item->id() ?>"><?= $item->id() ?></label></td> + <td><a href="?id=<?= $item->id() ?>&aff=edit">✏</a></td> + <td><a href="?id=<?= $item->id() ?>" target="_blank">👁</a></td> + <td><a href="?id=<?= $item->id() ?>&aff=log" target="_blank">¶</a></td> + <td><?= $item->tag('sort') ?></td> + <td><?= $item->description() ?></td> + <td><?= $item->linkto('sort') ?></td> + <td><?= $item->linkfrom('sort') ?></td> + <td><?= $item->datemodif('hrdi') ?></td> + <td><?= $item->datecreation('hrdi') ?></td> + <td><?= $item->secure('string') ?></td> + </tr> + + <?php }?> + </table> +</form> +</div> +</div> +</section> +</body> + + + +<?php $this->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 @@ +<div id="options"> +<h2>Options</h2> +<form action="./" method="get" > +<input type="submit" name="submit" value="filter"> +⬅<input type="submit" name="submit" value="reset"> + + + <!-- $this->optionsort($opt); + $this->optionprivacy($opt); + $this->optiontag($opt); --> + +<fieldset><legend>Sort</legend> +<select name="sortby" id="sortby"> +<?php +foreach ($opt->col('array') as $key => $col) { + echo '<option value="' . $col . '" ' . ($opt->sortby() == $col ? "selected" : "") . '>' . $col . '</option>'; +} +?> +</select> +</br> +<input type="radio" id="asc" name="order" value="1" <?= $opt->order() == '1' ? "checked" : "" ?>/><label for="asc">ascending</label> +</br> +<input type="radio" id="desc" name="order" value="-1" <?= $opt->order() == '-1' ? "checked" : "" ?>/><label for="desc">descending</label> + +</fieldset> + +<fieldset><legend>Privacy</legend><ul> +<li><input type="radio" id="4" name="secure" value="4"<?= $opt->secure() == 4 ? "checked" : "" ?>/><label for="4">all</label></li> +<li><input type="radio" id="3" name="secure" value="3"<?= $opt->secure() == 3 ? "checked" : "" ?>/><label for="3">editor</label></li> +<li><input type="radio" id="2" name="secure" value="2"<?= $opt->secure() == 2 ? "checked" : "" ?>/><label for="2">invite only</label></li> +<li><input type="radio" id="1" name="secure" value="1"<?= $opt->secure() == 1 ? "checked" : "" ?>/><label for="1">private</label></li> +<li><input type="radio" id="0" name="secure" value="0"<?= $opt->secure() == 0 ? "checked" : "" ?>/><label for="0">public</label></li> +</ul></fieldset> + + <fieldset><legend>Tag</legend><ul> + + +<input type="radio" id="OR" name="tagcompare" value="OR" ' . <?= $opt->tagcompare() == "OR" ? "checked" : "" ?> ><label for="OR">OR</label> +<input type="radio" id="AND" name="tagcompare" value="AND" <?= $opt->tagcompare() == "AND" ? "checked" : "" ?>><label for="AND">AND</label> + +<?php +$in = false; +$out = false; +$limit = 1; +foreach ($opt->taglist() as $tagfilter => $count) { + + if ($count > $limit && $in == false) { + echo '<details open><summary>>' . $limit . '</summary>'; + $in = true; + } + if ($count == $limit && $in == true && $out == false) { + echo '</details><details><summary>' . $limit . '</summary>'; + $out = true; + } + + if (in_array($tagfilter, $opt->tagfilter())) { + + echo '<li><input type="checkbox" name="tagfilter[]" id="' . $tagfilter . '" value="' . $tagfilter . '" checked /><label for="' . $tagfilter . '">' . $tagfilter . ' (' . $count . ')</label></li>'; + } else { + echo '<li><input type="checkbox" name="tagfilter[]" id="' . $tagfilter . '" value="' . $tagfilter . '" /><label for="' . $tagfilter . '">' . $tagfilter . ' (' . $count . ')</label></li>'; + } +} +if ($in = true || $out = true) { + echo '</details>'; +} +?> + +</ul></fieldset> + + <?php + if ($opt->invert() == 1) { + echo '<input type="checkbox" name="invert" value="1" id="invert" checked>'; + } else { + echo '<input type="checkbox" name="invert" value="1" id="invert">'; + } + echo '<label for="invert">invert</></br>'; + ?> + + +<input type="submit" name="submit" value="filter"> +⬅<input type="submit" name="submit" value="reset"> + +</form> +</div> 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 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf8" /> + + <meta name="viewport" content="width=device-width" /> + <link rel="shortcut icon" href="./media/logo.png" type="image/x-icon"> + <title><?= $title ?></title> + <link rel="stylesheet" href="./css/soft.css"> + <?=$this->section('customhead')?> + <?=$this->section('arthead')?> + +</head> + + + +<?=$this->section('page')?> + + +</html>
\ 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 @@ -<div class="menu"> - <?= $this->e($level) ?> - <div id="dropmenu"> - - <a class="button" href="?">home</a> - - <!-- id if level == 0 --> - <form action="./?action=login<?= isset($this->e($id)) ? '&id=' . $this->e($id) : '' ?>" method="post"> - <input type="password" name="pass" id="loginpass" placeholder="password"> - <input type="submit" value="login"> - </form> - - - <!-- id if level > 0 --> - <form action="./?action=logout<?= isset($this->e($id)) ? '&id=' . $this->e($id) : '' ?>" method="post"> - <input type="submit" value="logout"> - </form> - - - <!-- display / edit --> - - - if ($app->session() >= $app::EDITOR && isset($_GET['id']) && $app->exist($_GET['id'])) { - if (isset($_GET['edit']) && $_GET['edit'] == 1) { - echo '<a class="button" href="?id=' . $_GET['id'] . '" target="_blank">display</a>'; - } else { - echo '<a class="button" href="?id=' . $_GET['id'] . '&edit=1" >edit</a>'; - } - } - if ($app->session() >= $app::EDITOR) { - echo '<a class="button" href="?aff=media" >Media</a>'; - echo '<a class="button" href="?aff=record" >Record</a>'; - if ($app->session() >= $app::ADMIN) { - echo '<a class="button" href="?aff=admin" >Admin</a>'; - } - } - - - - -</div> -</dav>
\ No newline at end of file diff --git a/w/view/templates/navart.php b/w/view/templates/navart.php new file mode 100644 index 0000000..0ddba17 --- /dev/null +++ b/w/view/templates/navart.php @@ -0,0 +1,64 @@ +<div class="menu"> + <?= $user->level() ?> + <div id="dropmenu"> + + <ul> + + <li> + <a class="button" href="./">home</a> + </li> + + +<?php if($user->isvisitor()) { ?> + + <li> + <form action="./?action=login<?= $art->id() !== null ? '&id=' . $art->id() : '' ?>" method="post"> + <input type="password" name="pass" id="loginpass" placeholder="password"> + <input type="submit" value="login"> + </form> + </li> + +<?php } else { ?> + + <li> + <form action="./?action=logout<?= $art->id() !== null ? '&id=' . $art->id() : '' ?>" method="post"> + <input type="submit" value="logout"> + </form> + </li> + +<?php } ?> + + +<?php if($user->canedit() && $artexist) { ?> + + <li> + <a class="button" href="?id=<?=$art->id() ?>" target="_blank">display</a> + </li> + <li> + <a class="button" href="?id=<?=$art->id() ?>&aff=edit" >edit</a> + </li> + +<?php } ?> + + +<?php if ($user->canedit()) { ?> + + <li> + <a class="button" href="?aff=media" >Media</a> + </li> + +<?php } ?> + +<?php if($user->isadmin()) { ?> + + <li> + <a class="button" href="?aff=admin" >Admin</a> + </li> + +<?php } ?> + + + + + </div> +</div>
\ No newline at end of file diff --git a/w/view/templates/navback.php b/w/view/templates/navback.php new file mode 100644 index 0000000..ab8a4d4 --- /dev/null +++ b/w/view/templates/navback.php @@ -0,0 +1,54 @@ +<div class="menu"> + <?= $user->level() ?> + <div id="dropmenu"> + + <ul> + + <li> + <a class="button" href="./">home</a> + </li> + + +<?php if($user->isvisitor()) { ?> + + <li> + <form action="./?action=login" method="post"> + <input type="password" name="pass" id="loginpass" placeholder="password"> + <input type="submit" value="login"> + </form> + </li> + +<?php } else { ?> + + <li> + <form action="./?action=logout" method="post"> + <input type="submit" value="logout"> + </form> + </li> + +<?php } ?> + + + + +<?php if ($user->canedit()) { ?> + + <li> + <a class="button" href="?aff=media" >Media</a> + </li> + +<?php } ?> + +<?php if($user->isadmin()) { ?> + + <li> + <a class="button" href="?aff=admin" >Admin</a> + </li> + +<?php } ?> + + + </ul> + + </div> +</div>
\ No newline at end of file diff --git a/w/view/templates/read.php b/w/view/templates/read.php index 4d9a58f..5c544b3 100644 --- a/w/view/templates/read.php +++ b/w/view/templates/read.php @@ -1,20 +1,47 @@ -<html> +<?php $this->layout('layout', ['title' => $art->title()]) ?> -<head> - <meta charset="utf8" /> - <meta name="description" content="<?= $art->description() ?>" /> - <meta name="viewport" content="width=device-width" /> - <link rel="shortcut icon" href="./media/logo.png" type="image/x-icon"> - <link href="<?= $globalcss ?>" rel="stylesheet" /> - <?= $edit == 0 ? '<link href="' . $globalcss . '" rel="stylesheet" />' : '<link href="./rsc/css/styleedit.css" rel="stylesheet" />' ?> - <title><?= $edit == 1 ? '✏' : '' ?> <?= $art->title() ?></title> - <script src="./rsc/js/app.js"></script> -</head> - -<?= $html ?> -</html>
\ No newline at end of file + + + + + +<?php $this->start('page') ?> + + <body> + + + + <?php $this->insert('navart', ['user' => $user, 'art' => $art, 'artexist' => $artexist]) ?> + + + + <?php + + if($artexist) { + + if($display) { + $this->insert('readart', ['art' => $art]); + } else { + echo '<h1>You dont have enought rights to see this article</h1>'; + } + + } else { + echo '<h1>This article does not exist yet</h1>'; + if ($cancreate) { + $this->insert('readcreate', ['id' => $art->id()]); + } + } + + + + ?> + + + </body> + +<?php $this->stop() ?>
\ No newline at end of file diff --git a/w/view/templates/readart.php b/w/view/templates/readart.php new file mode 100644 index 0000000..e44877d --- /dev/null +++ b/w/view/templates/readart.php @@ -0,0 +1,25 @@ +<script> +<?=$art->javascript() ?> +</script> + +<body> + +<header> +<?=$art->header()?> +</header> + +<nav> +<?=$art->nav()?> +</nav> + +<aside> +<?=$art->aside()?> +</aside> + +<section> +<?=$art->section()?> +</section> + +<footer> +<?=$art->footer()?> +</footer> diff --git a/w/view/templates/readcreate.php b/w/view/templates/readcreate.php new file mode 100644 index 0000000..fd5df18 --- /dev/null +++ b/w/view/templates/readcreate.php @@ -0,0 +1,3 @@ +<form action="/?id=<?= $id ?>&action=add"> +<input type="submit" value="create"> +</form>
\ No newline at end of file diff --git a/w/view/templates/reader.php b/w/view/templates/reader.php deleted file mode 100644 index 7561ae3..0000000 --- a/w/view/templates/reader.php +++ /dev/null @@ -1,38 +0,0 @@ -<html> -<head> - <meta charset="utf8" /> - <meta name="description" content="<?=$this->e($description)?>" /> - <link href="<?=$this->e($id)?>quickcss" rel="stylesheet" /> - <link href="<?=$this->e($id)?>" rel="stylesheet" /> - <title><?=$this->e($title)?></title> - -</head> - -<script> -<?=$this->e($javascript)?> -</script> - -<body> - -<header> -<?=$this->e($header)?> -</header> - -<nav> -<?=$this->e($nav)?> -</nav> - -<aside> -<?=$this->e($aside)?> -</aside> - -<section> -<?=$this->e($section)?> -</section> - -<footer> -<?=$this->e($footer)?> -</footer> - -</body> -</html>
\ No newline at end of file diff --git a/w/w.index.php b/w/w.index.php index a2f0ea7..2ab4880 100644 --- a/w/w.index.php +++ b/w/w.index.php @@ -23,7 +23,17 @@ require(__DIR__.'/../vendor/autoload.php'); spl_autoload_register('class_autoloader'); -$_SESSION['user'] = ['level' => 10]; + + + +//$text = 'blabla il fait un temps vraiment [dégeu](=degeulasse) parce quil pleut [baucoup](?id=orthographe), en amazonie la [vie](?id=prout) et la [mort](?id=prout) sont des notions très proches.'; + +//$artmanager = new Modelart; + +// var_dump($artmanager->getlisterwhere(['id', 'description'], ['55', '44', 'lol'])); + + +Configtest::setinfo('coucou'); $router = new Router; |