aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2019-01-22 02:04:53 +0100
committervincent-peugnet <v.peugnet@free.fr>2019-01-22 02:04:53 +0100
commit695908c7ab2a5d5f011f616d2af3368da7131a6f (patch)
treecbd6c2a43495e77863d3611e2f6b12985b1111d8 /app/class
parenta8ed9070e7773f3147a33dbee7d45ce24bd8959d (diff)
downloadwcms-695908c7ab2a5d5f011f616d2af3368da7131a6f.tar.gz
wcms-695908c7ab2a5d5f011f616d2af3368da7131a6f.zip
home columns and download function added
Diffstat (limited to 'app/class')
-rw-r--r--app/class/controllerart.php22
-rw-r--r--app/class/controllerhome.php15
-rw-r--r--app/class/controlleruser.php32
-rw-r--r--app/class/model.php2
-rw-r--r--app/class/modelhome.php17
-rw-r--r--app/class/modeluser.php9
-rw-r--r--app/class/opt.php4
-rw-r--r--app/class/routes.php4
-rw-r--r--app/class/user.php38
9 files changed, 128 insertions, 15 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;
+ }
+ }
+