diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2019-01-22 02:04:53 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2019-01-22 02:04:53 +0100 |
commit | 695908c7ab2a5d5f011f616d2af3368da7131a6f (patch) | |
tree | cbd6c2a43495e77863d3611e2f6b12985b1111d8 /app | |
parent | a8ed9070e7773f3147a33dbee7d45ce24bd8959d (diff) | |
download | wcms-695908c7ab2a5d5f011f616d2af3368da7131a6f.tar.gz wcms-695908c7ab2a5d5f011f616d2af3368da7131a6f.zip |
home columns and download function added
Diffstat (limited to 'app')
-rw-r--r-- | app/class/controllerart.php | 22 | ||||
-rw-r--r-- | app/class/controllerhome.php | 15 | ||||
-rw-r--r-- | app/class/controlleruser.php | 32 | ||||
-rw-r--r-- | app/class/model.php | 2 | ||||
-rw-r--r-- | app/class/modelhome.php | 17 | ||||
-rw-r--r-- | app/class/modeluser.php | 9 | ||||
-rw-r--r-- | app/class/opt.php | 4 | ||||
-rw-r--r-- | app/class/routes.php | 4 | ||||
-rw-r--r-- | app/class/user.php | 38 | ||||
-rw-r--r-- | app/view/templates/home.php | 43 | ||||
-rw-r--r-- | app/view/templates/homeopt.php | 8 | ||||
-rw-r--r-- | app/view/templates/user.php | 9 |
12 files changed, 182 insertions, 21 deletions
diff --git a/app/class/controllerart.php b/app/class/controllerart.php index 20ef634..ace7e82 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -201,6 +201,28 @@ class Controllerart extends Controller } } + public function download($id) + { + if($this->user->isadmin()) { + + $file = Model::DATABASE_DIR . Config::arttable() . DIRECTORY_SEPARATOR . $id . '.json'; + + if (file_exists($file)) { + header('Content-Description: File Transfer'); + header('Content-Type: application/json; charset=utf-8'); + header('Content-Disposition: attachment; filename="'.basename($file).'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . filesize($file)); + readfile($file); + exit; + } + } else { + $this->routedirect('artread/', ['art' => $id]); + } + } + public function delete($id) { $this->setart($id, 'artdelete'); diff --git a/app/class/controllerhome.php b/app/class/controllerhome.php index f5b3068..cc2850f 100644 --- a/app/class/controllerhome.php +++ b/app/class/controllerhome.php @@ -22,15 +22,22 @@ class Controllerhome extends Controller $table2 = $this->modelhome->table2($table, $this->opt); - $this->showtemplate('home', ['user' => $this->user, 'table2' => $table2, 'opt' =>$this->opt]); + $columns = $this->modelhome->setcolumns($this->user->columns()); + + $this->showtemplate('home', ['user' => $this->user, 'table2' => $table2, 'opt' =>$this->opt, 'columns' => $columns]); } - public function massedit() + public function columns() { - echo '<h2>Mass Edit</h2>'; - + if(isset($_POST['columns']) && $this->user->iseditor()) { + $user =$this->usermanager->get($this->user->id()); + $user->hydrate($_POST); + $this->usermanager->add($user); + $this->usermanager->writesession($user); + } + $this->routedirect('home'); } public function search() diff --git a/app/class/controlleruser.php b/app/class/controlleruser.php index 65fb2bc..78daa04 100644 --- a/app/class/controlleruser.php +++ b/app/class/controlleruser.php @@ -3,20 +3,42 @@ class Controlleruser extends Controller { - public function __construct($render) { - parent::__construct($render); + public function __construct($router) { + parent::__construct($router); } public function desktop() { - if($this->user->isadmin()) { - $userlist = $this->usermanager->getlister(); - $this->showtemplate('user', ['userlist' => $userlist]); + if($this->user->iseditor()) { + $getuser = $this->usermanager->get($this->user); + if($this->user->isadmin()) { + $userlist = $this->usermanager->getlister(); + $this->showtemplate('user', ['userlist' => $userlist, 'getuser' => $getuser]); + } else { + $this->showtemplate('user', ['getuser' => $getuser]); + } } else { $this->routedirect('home'); } } + + public function pref() + { + if($this->user->iseditor()) { + $user = $this->usermanager->get($this->user); + $user->hydrate($_POST); + $this->usermanager->add($user); + $this->routedirect('user'); + } else { + $this->routedirect('home'); + } + } + + + + + public function add() { if(isset($_POST['id'])) { diff --git a/app/class/model.php b/app/class/model.php index 88a1bb3..779fb46 100644 --- a/app/class/model.php +++ b/app/class/model.php @@ -16,6 +16,8 @@ abstract class Model const MEDIA_EXTENSIONS = array('jpeg', 'jpg', 'JPG', 'png', 'gif', 'mp3', 'mp4', 'mov', 'wav', 'flac', 'pdf'); const MEDIA_TYPES = ['image', 'video', 'sound', 'other']; + const COLUMNS = ['title', 'description', 'tag', 'date', 'datemodif', 'datecreation', 'secure', 'linkfrom', 'linkto', 'visitcount', 'affcount', 'editcount']; + const TEXT_ELEMENTS = ['header', 'nav', 'main', 'aside', 'footer']; const EDIT_SYMBOLS = ['pen', 'tool', 'none']; diff --git a/app/class/modelhome.php b/app/class/modelhome.php index 2efdef4..78e51ba 100644 --- a/app/class/modelhome.php +++ b/app/class/modelhome.php @@ -51,6 +51,23 @@ class Modelhome extends Modelart return $table2; } + + /** + * @var array array of the columns to show from the user + * + * @return array assoc each key columns to a boolean value to show or not + */ + public function setcolumns(array $columns) : array + { + foreach (Model::COLUMNS as $col) { + if(in_array($col, $columns)) { + $showcols[$col] = true; + } else { + $showcols[$col] = false; + } + } + return $showcols; + } } diff --git a/app/class/modeluser.php b/app/class/modeluser.php index 74f1e13..6e39702 100644 --- a/app/class/modeluser.php +++ b/app/class/modeluser.php @@ -18,7 +18,14 @@ class Modeluser extends Modeldb public function writesession(User $user) { - $_SESSION['user' . Config::basepath()] = ['level' => $user->level(), 'id' => $user->id()]; + $_SESSION['user' . Config::basepath()] = ['level' => $user->level(), 'id' => $user->id(), 'columns' =>$user->columns()]; + } + + public function writecookie(User $user) + { + $cookiehash = + $cookie = ['level' => $user->level(), 'id' => $user->id()]; + setcookie('user ' . Config::basepath(), $cookie, time() + $user->cookie()*24*3600, null, null, false, true); } public function readsession() diff --git a/app/class/opt.php b/app/class/opt.php index 9d23c3f..6ea3e7e 100644 --- a/app/class/opt.php +++ b/app/class/opt.php @@ -88,7 +88,7 @@ class Opt public function getadress($sortby) { - if(in_array($sortby, $this->col)) { + if(in_array($sortby, Model::COLUMNS)) { if($this->sortby() === $sortby) { $order = $this->order * -1; } else { @@ -108,7 +108,7 @@ class Opt return $adress; } else { - returnfalse; + return false; } } diff --git a/app/class/routes.php b/app/class/routes.php index db57b77..9f3ce37 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -14,7 +14,8 @@ class Routes } $router->addMatchTypes(array('cid' => '[a-zA-Z0-9-_+,\'!%@&.$€=\(\|\)]+')); $router->addRoutes([ - ['GET|POST', '/', 'Controllerhome#desktop', 'home'], + ['GET', '/', 'Controllerhome#desktop', 'home'], + ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], ['POST', '/!co', 'Controllerconnect#log', 'log'], ['GET', '/!co', 'Controllerconnect#connect', 'connect'], ['POST', '/!search', 'Controllerhome#search', 'search'], @@ -40,6 +41,7 @@ class Routes ['GET', '/[cid:art]/edit', 'Controllerart#edit', 'artedit'], ['GET', '/[cid:art]/render', 'Controllerart#render', 'artrender'], ['GET', '/[cid:art]/log', 'Controllerart#log', 'artlog'], + ['GET', '/[cid:art]/download', 'Controllerart#download', 'artdownload'], ['POST', '/[cid:art]/edit', 'Controllerart#update', 'artupdate'], ['GET', '/[cid:art]/delete', 'Controllerart#confirmdelete', 'artconfirmdelete'], ['POST', '/[cid:art]/delete', 'Controllerart#delete', 'artdelete'], diff --git a/app/class/user.php b/app/class/user.php index 9bfc071..2e451a9 100644 --- a/app/class/user.php +++ b/app/class/user.php @@ -7,6 +7,8 @@ class User protected $signature = ''; protected $password; protected $passwordhashed = false; + protected $cookie = 0; + protected $columns = ['title', 'datemodif', 'datecreation', 'secure', 'visitcount']; public function __construct($datas = []) { @@ -35,6 +37,9 @@ class User return $array; } + + // _________________________ G E T _______________________ + public function id() { return $this->id; @@ -64,6 +69,20 @@ class User return $this->passwordhashed; } + public function cookie() + { + return $this->cookie; + } + + public function columns() + { + return $this->columns; + } + + + + // _______________________ S E T _______________________ + public function setid($id) { $id = idclean($id); @@ -80,9 +99,9 @@ class User } } - public function setpassword(string $password) + public function setpassword($password) { - if (is_string($password) && !empty($password)) { + if (!empty($password) && is_string($password)) { $this->password = $password; } @@ -101,6 +120,21 @@ class User } + public function setcookie($cookie) + { + $cookie = abs(intval($cookie)); + if($cookie >= 365) {$cookie = 365;} + $this->cookie = $cookie; + } + + public function setcolumns($columns) + { + if(is_array($columns)) { + $columns = array_filter(array_intersect(array_unique($columns), Model::COLUMNS)); + $this->columns = $columns; + } + } + diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 5860975..9636d7e 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -44,6 +44,17 @@ <input type="submit" name="massaction" value="do" onclick="confirmSubmit(event, 'Are you sure')" > + + <?php + + $array = ['id' => [ 'getadress' => true, + 'label' => 'id', + 'show' => true] + ] + + + ?> + <input type="hidden" name="action" value="massedit"> </div> @@ -55,15 +66,31 @@ <th>edit</th> <th>see</th> <th class="delete">del</th> + <?php if($user->isadmin()) { ?> + <th class="download">dl</th> + <?php } if($columns['tag']) { ?> <th class="tag"><a href="<?= $opt->getadress('tag') ?>">tag</a></th> + <?php } if($columns['description']) { ?> <th class="summary">summary</th> + <?php } if($columns['linkto']) { ?> <th class="linkto"><a href="<?= $opt->getadress('linkto') ?>">to</a></th> + <?php } if($columns['linkfrom']) { ?> <th class="linkfrom"><a href="<?= $opt->getadress('linkfrom') ?>">from</a></th> + <?php } if($columns['datemodif']) { ?> <th class="datemodif"><a href="<?= $opt->getadress('datemodif') ?>">last modification</a></th> + <?php } if($columns['datecreation']) { ?> <th class="datecreation"><a href="<?= $opt->getadress('datecreation') ?>">date of creation</a></th> + <?php } if($columns['date']) { ?> <th class="date"><a href="<?= $opt->getadress('date') ?>">date</a></th> + <?php } if($columns['secure']) { ?> <th class="secure"><a href="<?= $opt->getadress('secure') ?>">privacy</a></th> + <?php } if($columns['visitcount']) { ?> <th class="visitcount"><a href="<?= $opt->getadress('visitcount') ?>">visit</a></th> + <?php } if($columns['editcount']) { ?> + <th class="editcount"><a href="<?= $opt->getadress('editcount') ?>">edit</a></th> + <?php } if($columns['affcount']) { ?> + <th class="affcount"><a href="<?= $opt->getadress('affcount') ?>">aff</a></th> + <?php } ?> </tr> <?php foreach ($table2 as $item) { ?> <tr> @@ -72,15 +99,31 @@ <td><a href="<?= $this->uart('artedit', $item->id()) ?>">✏</a></td> <td><a href="<?= $this->uart('artread/', $item->id()) ?>" target="_blank">👁</a></td> <td class="delete"><a href="<?= $this->uart('artdelete', $item->id()) ?>" >✖</a></td> + <?php if($user->isadmin()) { ?> + <td><a href="<?= $this->uart('artdownload', $item->id()) ?>" download>↓</a></td> + <?php } if($columns['tag']) { ?> <td class="tag"><a title="<?= $item->tag('string') ?>"><?= $item->tag('sort') ?></a></td> + <?php } if($columns['description']) { ?> <td class="summary" title="<?= $item->description() ?>"><?= $item->description('short') ?></td> + <?php } if($columns['linkto']) { ?> <td class="linkto"><a title="<?= $item->linkto('string') ?>" ><?= $item->linkto('sort') ?></a></td> + <?php } if($columns['linkfrom']) { ?> <td class="linkfrom"><a title="<?= $item->linkfrom('string') ?>" ><?= $item->linkfrom('sort') ?></a></td> + <?php } if($columns['datemodif']) { ?> <td class="datemodif"><?= $item->datemodif('hrdi') ?></td> + <?php } if($columns['datecreation']) { ?> <td class="datecreation"><?= $item->datecreation('hrdi') ?></td> + <?php } if($columns['date']) { ?> <td class="date"><?= $item->date('dmy') ?></td> + <?php } if($columns['secure']) { ?> <td class="secure"><?= $item->secure('string') ?></td> + <?php } if($columns['visitcount']) { ?> <td class="visitcount"><?= $item->visitcount() ?></td> + <?php } if($columns['editcount']) { ?> + <td class="editcount"><?= $item->editcount() ?></td> + <?php } if($columns['affcount']) { ?> + <td class="affcount"><?= $item->affcount() ?></td> + <?php } ?> </tr> <?php }?> diff --git a/app/view/templates/homeopt.php b/app/view/templates/homeopt.php index 5dab881..4008a71 100644 --- a/app/view/templates/homeopt.php +++ b/app/view/templates/homeopt.php @@ -84,16 +84,16 @@ if ($in = true || $out = true) { <h2>Columns</h2> -<form action="" method="post"> +<form action="<?= $this->url('homecolumns') ?>" method="post"> <ul> <?php -foreach ($opt->col() as $col) { +foreach (Model::COLUMNS as $col) { ?> <li> - <input type="checkbox" name="col[]" id="col_<?= $col ?>"> + <input type="checkbox" name="columns[]" value="<?= $col ?>" id="col_<?= $col ?>" <?= in_array($col, $user->columns()) ? 'checked' : '' ?>> <label for="col_<?= $col ?>"><?= $col ?></label> </li> <?php @@ -103,6 +103,8 @@ foreach ($opt->col() as $col) { </ul> +<input type="submit" value="update columns"> + </form> <?php } ?> diff --git a/app/view/templates/user.php b/app/view/templates/user.php index 451d3ce..0f9ac7b 100644 --- a/app/view/templates/user.php +++ b/app/view/templates/user.php @@ -15,17 +15,19 @@ -<form action="" method="post"> +<form action="<?= $this->url('userpref') ?>" method="post"> -<h2>Connexion Options</h2> +<h2>Preferences</h2> -<input type="number" name="cookie" id="cookie"> +<input type="number" name="cookie" value="<?= $getuser->cookie() ?>" id="cookie" min="0" max="365"> <label for="cookie">Cookie conservation time <i>(In days)</i></label> <input type="submit" value="submit"> </form> +<?php if($user->isadmin()) { ?> + <h1>Admin panel</h1> <table> @@ -108,6 +110,7 @@ foreach ($userlist as $user ) { </table> +<?php } ?> </main> |