diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2019-08-21 11:35:40 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2019-08-21 11:35:40 +0200 |
commit | 63202efc75a63ef30e58c12d602ea95a960a0976 (patch) | |
tree | 1c8bc40941ab8abdb18f68066d6ab64674f465d5 /app | |
parent | 388bd7c3aff8b440febd83598003f96d5a746505 (diff) | |
download | wcms-63202efc75a63ef30e58c12d602ea95a960a0976.tar.gz wcms-63202efc75a63ef30e58c12d602ea95a960a0976.zip |
New feature : bookmarks
- public bookmarks stored in config.json
- personnal bookmarks stored in user data
Diffstat (limited to 'app')
-rw-r--r-- | app/class/config.php | 33 | ||||
-rw-r--r-- | app/class/controllerhome.php | 79 | ||||
-rw-r--r-- | app/class/modelrender.php | 7 | ||||
-rw-r--r-- | app/class/modeluser.php | 1 | ||||
-rw-r--r-- | app/class/opt.php | 153 | ||||
-rw-r--r-- | app/class/optlist.php | 29 | ||||
-rw-r--r-- | app/class/routes.php | 1 | ||||
-rw-r--r-- | app/class/user.php | 29 | ||||
-rw-r--r-- | app/view/templates/home.php | 2 | ||||
-rw-r--r-- | app/view/templates/homemenu.php | 77 |
10 files changed, 279 insertions, 132 deletions
diff --git a/app/class/config.php b/app/class/config.php index 59d80eb..5c05657 100644 --- a/app/class/config.php +++ b/app/class/config.php @@ -32,6 +32,7 @@ abstract class Config protected static $homepage = 'default'; protected static $homeredirect = null; protected static $interfacecss = null; + protected static $bookmark = []; // _______________________________________ F U N _______________________________________ @@ -253,6 +254,11 @@ abstract class Config return self::$interfacecss; } + public static function bookmark() + { + return self::$bookmark; + } + // __________________________________________ S E T ______________________________________ @@ -442,6 +448,33 @@ abstract class Config self::$interfacecss = null; } } + + public static function setbookmark($bookmark) + { + if(is_array($bookmark)) { + self::$bookmark = $bookmark; + } + } + + + + + + + // ______________________________________ F U N _________________________________________ + + public static function addbookmark(string $id, string $query) + { + $id = idclean($id); + self::$bookmark[$id] = $query; + } + + public static function deletebookmark(string $id) + { + if(key_exists($id, self::$bookmark)) { + unset(self::$bookmark[$id]); + } + } diff --git a/app/class/controllerhome.php b/app/class/controllerhome.php index afbde7a..6932dfb 100644 --- a/app/class/controllerhome.php +++ b/app/class/controllerhome.php @@ -8,7 +8,8 @@ class Controllerhome extends Controllerart /** @var Optlist */ protected $optlist; - public function __construct($render) { + public function __construct($render) + { parent::__construct($render); $this->modelhome = new Modelhome; } @@ -18,39 +19,37 @@ class Controllerhome extends Controllerart public function desktop() { - if($this->user->isvisitor() && Config::homepage() === 'redirect' && Config::homeredirect() !== null) { + if ($this->user->isvisitor() && Config::homepage() === 'redirect' && Config::homeredirect() !== null) { $this->routedirect('artread/', ['art' => Config::homeredirect()]); } else { - + $table = $this->modelhome->getlister(); $this->opt = $this->modelhome->optinit($table); - + $table2 = $this->modelhome->table2($table, $this->opt); - + $columns = $this->modelhome->setcolumns($this->user->columns()); $vars = ['user' => $this->user, 'table2' => $table2, 'opt' => $this->opt, 'columns' => $columns]; $vars['footer'] = ['version' => getversion(), 'total' => count($table), 'database' => Config::arttable()]; - if(isset($_POST['query']) && $this->user->iseditor()) { + if (isset($_POST['query']) && $this->user->iseditor()) { $datas = array_merge($_POST, $_SESSION['opt']); $this->optlist = $this->modelhome->Optlistinit($table); $this->optlist->hydrate($datas); - $vars['optlist'] = $this->optlist; + $vars['optlist'] = $this->optlist; } - + $this->showtemplate('home', $vars); - - } } public function columns() { - if(isset($_POST['columns']) && $this->user->iseditor()) { + if (isset($_POST['columns']) && $this->user->iseditor()) { $user = $this->usermanager->get($this->user->id()); $user->hydrate($_POST); $this->usermanager->add($user); @@ -61,16 +60,16 @@ class Controllerhome extends Controllerart public function search() { - if(isset($_POST['id']) && !empty($_POST['id'])) { - if(isset($_POST['action'])) { + if (isset($_POST['id']) && !empty($_POST['id'])) { + if (isset($_POST['action'])) { switch ($_POST['action']) { case 'read': $this->routedirect('artread/', ['art' => $_POST['id']]); - break; - + break; + case 'edit': $this->routedirect('artedit', ['art' => $_POST['id']]); - break; + break; } } } else { @@ -80,7 +79,7 @@ class Controllerhome extends Controllerart public function renderall() { - if($this->user->iseditor()) { + if ($this->user->iseditor()) { $pagelist = $this->modelhome->getlister(); foreach ($pagelist as $page) { $this->renderart($page); @@ -90,19 +89,37 @@ class Controllerhome extends Controllerart $this->routedirect('home'); } - - - - - - + public function bookmark() + { + if ($this->user->iseditor() && isset($_POST['action']) && isset($_POST['id']) && !empty($_POST['id'])) { + if ($_POST['action'] == 'add' && isset($_POST['query'])) { + if (isset($_POST['user']) && $_POST['user'] == $this->user->id()) { + $usermanager = new Modeluser(); + $user = $usermanager->get($_POST['user']); + $user->addbookmark($_POST['id'], $_POST['query']); + $usermanager->add($user); + } else { + Config::addbookmark($_POST['id'], $_POST['query']); + Config::savejson(); + } + } elseif ($_POST['action'] == 'del') { + if(isset($_POST['user']) && $_POST['user'] == $this->user->id()) { + $usermanager = new Modeluser(); + $user = $usermanager->get($_POST['user']); + foreach ($_POST['id'] as $id) { + $user->deletebookmark($id); + } + $usermanager->add($user); + } else { + foreach ($_POST['id'] as $id) { + Config::deletebookmark($id); + } + Config::savejson(); + } + } + } + $this->routedirect('home'); + } } - - - - - - - -?>
\ No newline at end of file +?> diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 3736888..f76a922 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -60,7 +60,12 @@ class Modelrender extends Modelart if (!empty($this->art->templatebody())) { $templateid = $this->art->templatebody(); $templateart = $this->get($templateid); - $body = $templateart->body(); + if($templateart !== false) { + $body = $templateart->body(); + } else { + $body = $this->art->body(); + $this->art->settemplatebody(''); + } } else { $body = $this->art->body(); } diff --git a/app/class/modeluser.php b/app/class/modeluser.php index 7d14f95..893a608 100644 --- a/app/class/modeluser.php +++ b/app/class/modeluser.php @@ -35,6 +35,7 @@ class Modeluser extends Modeldb if (array_key_exists('user' . Config::basepath(), $_SESSION) && isset($_SESSION['user' . Config::basepath()]['id'])) { $userdatas = $_SESSION['user' . Config::basepath()]; $user = new User($userdatas); + $user = $this->get($user); return $user; } else { return new User(['id' => '', 'level' => 0]); diff --git a/app/class/opt.php b/app/class/opt.php index 0761782..39e2ab8 100644 --- a/app/class/opt.php +++ b/app/class/opt.php @@ -45,16 +45,16 @@ class Opt } public function reset($var) - { + { $varlist = get_class_vars(__class__); - if(in_array($var, $varlist)) { + if (in_array($var, $varlist)) { $this->$var = $varlist[$var]; - } + } } public function submit() { - if(isset($_GET['submit'])) { + if (isset($_GET['submit'])) { if ($_GET['submit'] == 'reset') { $_SESSION['opt'] = []; } elseif ($_GET['submit'] == 'filter') { @@ -69,58 +69,74 @@ class Opt { $optlist = ['sortby', 'order', 'secure', 'tagcompare', 'tagfilter', 'authorcompare', 'authorfilter', 'invert']; - foreach ($optlist as $method) { - if (method_exists($this, $method)) { - if(isset($_GET[$method])) { - $setmethod = 'set'. $method; - $this->$setmethod($_GET[$method]); - } else { - $this->reset($method); - } - $_SESSION['opt'][$method] = $this->$method(); - } - } + foreach ($optlist as $method) { + if (method_exists($this, $method)) { + if (isset($_GET[$method])) { + $setmethod = 'set' . $method; + $this->$setmethod($_GET[$method]); + } else { + $this->reset($method); + } + $_SESSION['opt'][$method] = $this->$method(); + } + } } public function sessionall() { - if(isset($_SESSION['opt'])) { - $this->hydrate($_SESSION['opt']); - } + if (isset($_SESSION['opt'])) { + $this->hydrate($_SESSION['opt']); + } } - public function getadress($sortby) + public function getadress(string $sortby = '') { - if(in_array($sortby, Model::COLUMNS)) { - if($this->sortby() === $sortby) { - $order = $this->order * -1; - } else { - $order = $this->order; - } - $adress = '?sortby=' . $sortby; - $adress .= '&order=' . $order; - $adress .= '&secure=' . $this->secure; - $adress .= '&tagcompare=' . $this->tagcompare; - foreach ($this->tagfilter as $tag) { - $adress .= '&tagfilter[]=' . $tag; - } - $adress .= '&authorcompare=' . $this->authorcompare; - foreach ($this->authorfilter as $author) { - $adress .= '&authorfilter[]=' . $author; - } - if($this->invert == 1) { - $adress .= '&invert=1'; - } - $adress .= '&submit=filter'; - - return $adress; + if ($this->sortby() === $sortby) { + $order = $this->order * -1; } else { - return false; + $order = $this->order; } + $adress = '?sortby=' . $sortby; + $adress .= '&order=' . $order; + $adress .= '&secure=' . $this->secure; + $adress .= '&tagcompare=' . $this->tagcompare; + foreach ($this->tagfilter as $tag) { + $adress .= '&tagfilter[]=' . $tag; + } + $adress .= '&authorcompare=' . $this->authorcompare; + foreach ($this->authorfilter as $author) { + $adress .= '&authorfilter[]=' . $author; + } + if ($this->invert == 1) { + $adress .= '&invert=1'; + } + $adress .= '&submit=filter'; + + return $adress; } + /** + * Get the query as http string + * + * @return string The resulted query + */ + public function getquery(): string + { + $class = get_class_vars(get_class($this)); + $object = get_object_vars($this); + $class['artvarlist'] = $object['artvarlist']; + $class['taglist'] = $object['taglist']; + $class['authorlist'] = $object['authorlist']; + $query = array_diff_assoc_recursive($object, $class); + + return urldecode(http_build_query($query)); + } + + + + // _______________________________________________ G E T _______________________________________________ public function sortby() @@ -220,7 +236,7 @@ class Opt if (!empty($tagfilter) && is_array($tagfilter)) { $tagfilterverif = []; foreach ($tagfilter as $tag) { - if(array_key_exists($tag, $this->taglist)) { + if (array_key_exists($tag, $this->taglist)) { $tagfilterverif[] = $tag; } } @@ -240,7 +256,7 @@ class Opt if (!empty($authorfilter) && is_array($authorfilter)) { $authorfilterverif = []; foreach ($authorfilter as $author) { - if(array_key_exists($author, $this->authorlist)) { + if (array_key_exists($author, $this->authorlist)) { $authorfilterverif[] = $author; } } @@ -301,34 +317,34 @@ class Opt public function settaglist(array $artlist) { - $taglist = []; - foreach ($artlist as $art) { - foreach ($art->tag('array') as $tag) { - if (!array_key_exists($tag, $taglist)) { - $taglist[$tag] = 1; - } else { - $taglist[$tag]++; - } + $taglist = []; + foreach ($artlist as $art) { + foreach ($art->tag('array') as $tag) { + if (!array_key_exists($tag, $taglist)) { + $taglist[$tag] = 1; + } else { + $taglist[$tag]++; } } - $taglistsorted = arsort($taglist); - $this->taglist = $taglist; + } + $taglistsorted = arsort($taglist); + $this->taglist = $taglist; } public function setauthorlist(array $artlist) { - $authorlist = []; - foreach ($artlist as $art) { - foreach ($art->authors('array') as $author) { - if (!array_key_exists($author, $authorlist)) { - $authorlist[$author] = 1; - } else { - $authorlist[$author]++; - } + $authorlist = []; + foreach ($artlist as $art) { + foreach ($art->authors('array') as $author) { + if (!array_key_exists($author, $authorlist)) { + $authorlist[$author] = 1; + } else { + $authorlist[$author]++; } } - $authorlistsorted = arsort($authorlist); - $this->authorlist = $authorlist; + } + $authorlistsorted = arsort($authorlist); + $this->authorlist = $authorlist; } public function setinvert(int $invert) @@ -345,11 +361,4 @@ class Opt { $this->artvarlist = $artvarlist; } - - } - - - - -?>
\ No newline at end of file diff --git a/app/class/optlist.php b/app/class/optlist.php index 5190596..11e6f72 100644 --- a/app/class/optlist.php +++ b/app/class/optlist.php @@ -2,11 +2,11 @@ class Optlist extends Opt { - private $description = 0; - private $thumbnail = 0; - private $date = 0; - private $author = 0; - private $style = 0; + protected $description = 0; + protected $thumbnail = 0; + protected $date = 0; + protected $author = 0; + protected $style = 0; @@ -18,24 +18,6 @@ class Optlist extends Opt } } - - /** - * Get the query as http string - * - * @return string The resulted query - */ - public function getquery() : string - { - $class = get_class_vars(get_class($this)); - $object = get_object_vars($this); - $class['artvarlist'] = $object['artvarlist']; - $class['taglist'] = $object['taglist']; - $class['authorlist'] = $object['authorlist']; - $query = array_diff_assoc_recursive($object, $class); - - return urldecode(http_build_query($query)); - } - /** * Get the code to insert directly */ @@ -46,6 +28,7 @@ class Optlist extends Opt + // _______________________________________ G E T _____________________________________ diff --git a/app/class/routes.php b/app/class/routes.php index c0b686b..13444fd 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -18,6 +18,7 @@ class Routes ['POST', '/', 'Controllerhome#desktop', 'homequery'], ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], ['POST', '/renderall', 'Controllerhome#renderall', 'homerenderall'], + ['POST', '/bookmark', 'Controllerhome#bookmark', 'homebookmark'], ['POST', '/upload', 'Controllerart#upload', 'artupload'], ['POST', '/!co', 'Controllerconnect#log', 'log'], ['GET', '/!co', 'Controllerconnect#connect', 'connect'], diff --git a/app/class/user.php b/app/class/user.php index ba3dfea..68eed91 100644 --- a/app/class/user.php +++ b/app/class/user.php @@ -11,6 +11,7 @@ class User protected $columns = ['title', 'datemodif', 'datecreation', 'secure', 'visitcount']; protected $connectcount = 0; protected $expiredate = false; + protected $bookmark = []; public function __construct($datas = []) { @@ -114,6 +115,11 @@ class User } } + public function bookmark() + { + return $this->bookmark; + } + // _______________________ S E T _______________________ @@ -185,6 +191,15 @@ class User } } + public function setbookmark($bookmark) + { + if(is_array($bookmark)) { + $this->bookmark = $bookmark; + } + } + + + @@ -246,6 +261,20 @@ class User $this->connectcount ++; } + public function addbookmark(string $id, string $query) + { + $id = idclean($id); + $this->bookmark[$id] = $query; + } + + public function deletebookmark(string $id) + { + if(key_exists($id, $this->bookmark)) { + unset($this->bookmark[$id]); + } + } + + } diff --git a/app/view/templates/home.php b/app/view/templates/home.php index f2d2668..824d9f3 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -14,7 +14,7 @@ - <?php $this->insert('homemenu', ['user' => $user]) ?> + <?php $this->insert('homemenu', ['user' => $user, 'opt' => $opt]) ?> <main class="home"> diff --git a/app/view/templates/homemenu.php b/app/view/templates/homemenu.php index f81933f..3ad57ef 100644 --- a/app/view/templates/homemenu.php +++ b/app/view/templates/homemenu.php @@ -1,6 +1,8 @@ <aside class="home"> - <details class="hidephone"> - <summary>Import page as file</summary> + <details class="hidephone" id="json"> + <summary>File</summary> + <div class="submenu"> + <h2>Import page as file</h2> <form action="<?= $this->url('artupload') ?>" method="post" enctype="multipart/form-data"> <input type="file" name="pagefile" id="pagefile" accept=".json"> <label for="pagefile">JSON Page file</label> @@ -21,12 +23,15 @@ </br> <input type="submit" value="upload"> </form> + </div> </details> - <details class="hidephone"> + <details class="hidephone" id="columns"> <summary>Columns</summary> + <div class="submenu"> + <h2>Columns</h2> <form action="<?= $this->url('homecolumns') ?>" method="post"> <ul> <?php @@ -39,16 +44,80 @@ </ul> <input type="submit" value="update columns"> </form> + </div> </details> - <details class="hidephone"> + <details class="hidephone" id="actions"> <summary>Actions</summary> + <div class="submenu"> + <h2>Rendering</h2> <form action="<?= $this->url('homerenderall') ?>" method="post"> Render all pages </br> <input type="submit" value="renderall"> </form> + </div> </details> + <details class="hidephone" id="bookmarks"> + <summary>Bookmarks</summary> + <div class="submenu"> + <h2>Public</h2> + <?php if(!empty(Config::bookmark())) { ?> + <form action="<?= $this->url('homebookmark') ?>" method="post"> + <ul> + <?php foreach (Config::bookmark() as $id => $query) { ?> + <li> + <label for="public-bookmark_<?= $id ?>"> + <a href="<?= $query ?>" title="<?= $query ?>"><?= $id ?></a> + </label> + <?php if($user->issupereditor()) { ?> + <input type="checkbox" name="id[]" value="<?= $id ?>" id="public-bookmark_<?= $id ?>"> + <?php } ?> + </li> + <?php } ?> + </ul> + <input type="hidden" name="action" value="del"> + <input type="submit" value="delete selected" class="floatright"> + </form> + <?php } elseif($user->issupereditor()) { ?> + <p>This will store your filters settings as a Bookmark that every editors users can use.</p> + <?php } else { ?> + <p>No public Bookmarks yet</p> + <?php } ?> + <?php if($user->issupereditor()) { ?> + <form action="<?= $this->url('homebookmark') ?>" method="post"> + <input type="text" name="id" placeholder="bookmark id"> + <input type="hidden" name="query" value="<?= $opt->getadress() ?>"> + <input type="submit" name="action" value="add"> + </form> + <?php } ?> + <h2>Personnal</h2> + <?php if(!empty($user->bookmark())) { ?> + <form action="<?= $this->url('homebookmark') ?>" method="post"> + <ul> + <?php foreach ($user->bookmark() as $id => $query) { ?> + <li> + <a href="<?= $query ?>" title="<?= $query ?>"><?= $id ?></a> + <input type="checkbox" name="id[]" value="<?= $id ?>"> + </li> + <?php } ?> + </ul> + <input type="hidden" name="action" value="del"> + <input type="hidden" name="user" value="<?= $user->id() ?>"> + <input type="submit" value="delete selected" class="floatright"> + </form> + <?php } else { ?> + <p>This will store your filters settings as a Bookmark that only you can use.</p> + <?php } ?> + <form action="<?= $this->url('homebookmark') ?>" method="post"> + <input type="text" name="id" placeholder="bookmark id"> + <input type="hidden" name="query" value="<?= $opt->getadress() ?>"> + <input type="hidden" name="user" value="<?= $user->id() ?>"> + <input type="submit" name="action" value="add"> + </form> + </div> + </details> + </aside>
\ No newline at end of file |