From 8ccc4ac00c974ba3659762e6c67f75ed82020e37 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Tue, 14 Apr 2020 16:36:45 +0200 Subject: finish flashmessages implementation + clean css --- app/class/Controller.php | 14 ++ app/class/Controllerhome.php | 67 ++++--- app/class/Controllerpage.php | 36 ++-- app/class/Controlleruser.php | 6 +- app/class/Item.php | 12 +- app/class/Model.php | 1 + app/class/Modelmedia.php | 14 +- app/class/Modelpage.php | 13 +- app/class/User.php | 20 +- app/view/templates/admin.php | 395 ++++++++++++++++++++-------------------- app/view/templates/edit.php | 2 - app/view/templates/home.php | 392 ++++++++++++++++++++------------------- app/view/templates/homemenu.php | 33 ++-- app/view/templates/info.php | 2 - app/view/templates/layout.php | 14 +- app/view/templates/media.php | 6 +- app/view/templates/timeline.php | 4 +- app/view/templates/user.php | 36 ++-- 18 files changed, 558 insertions(+), 509 deletions(-) (limited to 'app') diff --git a/app/class/Controller.php b/app/class/Controller.php index ccf31fa..bcfcdba 100644 --- a/app/class/Controller.php +++ b/app/class/Controller.php @@ -99,6 +99,20 @@ class Controller exit; } + /** + * + */ + public function sendstatflashmessage(int $count, int $total, string $message) + { + if ($count === $total) { + Model::sendflashmessage($count . ' / ' . $total . ' ' . $message, 'success'); + } elseif ($count > 0) { + Model::sendflashmessage($count . ' / ' . $total . ' ' . $message, 'warning'); + } else { + Model::sendflashmessage($count . ' / ' . $total . ' ' . $message, 'error'); + } + } + } diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index dae7030..d024a19 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -146,11 +146,15 @@ class Controllerhome extends Controllerpage { if ($this->user->iseditor()) { $pagelist = $this->modelhome->pagelist(); + $count = 0; foreach ($pagelist as $page) { - $this->renderpage($page); - $this->pagemanager->update($page); + $page = $this->renderpage($page); + if ($this->pagemanager->update($page)) { + $count ++; + } } - Model::sendflashmessage('All pages have been rendered', 'success'); + $total = count($pagelist); + $this->sendstatflashmessage($count, $total, 'pages have been rendered'); } $this->routedirect('home'); } @@ -203,36 +207,45 @@ class Controllerhome extends Controllerpage $this->multidelete(); break; } + } else { + $action = $_POST['action'] ?? 'edit'; + Model::sendflashmessage('Please select some pages to ' . $action, 'warning'); } $this->routedirect('home'); } public function multiedit() { - if (isset($_POST['pagesid'])) { - $datas = $_POST['datas']?? []; - $datas = array_filter($datas, function ($var) { - return $var !== ""; - }); - $datas = array_map(function ($value) { - if($value === "!") { - return ""; - } else { - return $value; - } - }, $datas); - $reset = $_POST['reset'] ?? []; - $addtag = $_POST['addtag'] ?? ''; - $addauthor = $_POST['addauthor'] ?? ''; - foreach ($_POST['pagesid'] as $id) { - $this->pagemanager->pageedit($id, $datas, $reset, $addtag, $addauthor); + $pagelist = $_POST['pagesid'] ?? []; + $datas = $_POST['datas']?? []; + $datas = array_filter($datas, function ($var) { + return $var !== ""; + }); + $datas = array_map(function ($value) { + if($value === "!") { + return ""; + } else { + return $value; + } + }, $datas); + $reset = $_POST['reset'] ?? []; + $addtag = $_POST['addtag'] ?? ''; + $addauthor = $_POST['addauthor'] ?? ''; + $count = 0; + $total = 0; + foreach ($pagelist as $id) { + $total ++; + if($this->pagemanager->pageedit($id, $datas, $reset, $addtag, $addauthor)) { + $count ++; } } + $this->sendstatflashmessage($count, $total, 'pages have been edited'); } public function multirender() { $pagelist = $_POST['pagesid'] ?? []; + $total = count($pagelist); $pagelist = $this->pagemanager->pagelistbyid($pagelist); $count = 0; foreach ($pagelist as $page) { @@ -240,19 +253,25 @@ class Controllerhome extends Controllerpage if($this->pagemanager->update($page)) { $count ++; } - } - Model::sendflashmessage($count . ' pages have been rendered', 'success'); + $this->sendstatflashmessage($count, $total, 'pages have been rendered'); } public function multidelete() { if(isset($_POST['confirmdelete']) && $_POST['confirmdelete']) { $pagelist = $_POST['pagesid'] ?? []; + $total = count($pagelist); + $count = 0; foreach ($pagelist as $id) { - $this->pagemanager->delete($id); + if ($this->pagemanager->delete($id)) { + $count ++; + } } - } + $this->sendstatflashmessage($count, $total, 'pages have been deleted'); + } else { + Model::sendflashmessage('Confirm delete has not been cheked', 'warning'); + } } } diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index 909a2c2..990f0b7 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -279,25 +279,31 @@ class Controllerpage extends Controller { $page = $this->pagemanager->getfromfile(); + if($page !== false) { - if(!empty($_POST['id'])) { - $page->setid(idclean($_POST['id'])); - } - - if($_POST['datecreation']) { - $page->setdatecreation($this->now); - } - - if($_POST['author']) { - $page->setauthors([$this->user->id()]); - } - - $page->setdaterender($page->datecreation('date')); + if(!empty($_POST['id'])) { + $page->setid(idclean($_POST['id'])); + } + + if($_POST['datecreation']) { + $page->setdatecreation($this->now); + } + + if($_POST['author']) { + $page->setauthors([$this->user->id()]); + } + + $page->setdaterender($page->datecreation('date')); - if($page !== false) { if($_POST['erase'] || $this->pagemanager->get($page) === false) { - $this->pagemanager->add($page); + if($this->pagemanager->add($page)) { + Model::sendflashmessage('Page successfully uploaded', 'success'); + } + } else { + Model::sendflashmessage('Page ID already exist, check remplace if you want to erase it', 'warning'); } + } else { + Model::sendflashmessage('Error while importing page JSON', 'error'); } $this->routedirect('home'); } diff --git a/app/class/Controlleruser.php b/app/class/Controlleruser.php index 1586679..1f53f76 100644 --- a/app/class/Controlleruser.php +++ b/app/class/Controlleruser.php @@ -32,7 +32,11 @@ class Controlleruser extends Controller { if($this->user->iseditor()) { $user = $this->usermanager->get($this->user); - $user->hydrate($_POST); + if ($user->hydrate($_POST)) { + Model::sendflashmessage('User preferences have been successfully updated', 'success'); + } else { + Model::sendflashmessage('There was a problem when updating preferences', 'warning'); + } if ($_POST['passwordhash']) { $user->hashpassword(); } diff --git a/app/class/Item.php b/app/class/Item.php index 8bd62d1..10d35d7 100644 --- a/app/class/Item.php +++ b/app/class/Item.php @@ -12,13 +12,21 @@ abstract class Item public function hydrate($datas = []) { + $error = 0; foreach ($datas as $key => $value) { $method = 'set' . $key; if (method_exists($this, $method)) { - $this->$method($value); + if($this->$method($value) === false) { + $error ++; + } } - } + } + if ($error > 0) { + return false; + } else { + return true; + } } diff --git a/app/class/Model.php b/app/class/Model.php index e26a006..73a800d 100644 --- a/app/class/Model.php +++ b/app/class/Model.php @@ -97,6 +97,7 @@ abstract class Model const MAX_ID_LENGTH = 64; const PASSWORD_MIN_LENGTH = 4; const PASSWORD_MAX_LENGTH = 32; + const MAX_COOKIE_CONSERVATION = 365; /** RENDER OPTIONS */ // add class in html element indicating from witch page the content come. diff --git a/app/class/Modelmedia.php b/app/class/Modelmedia.php index a7ade6c..038f49e 100644 --- a/app/class/Modelmedia.php +++ b/app/class/Modelmedia.php @@ -303,7 +303,7 @@ class Modelmedia extends Model $success[] = $this->deletefile($filedir); } } - Model::sendflashmessage(array_count_values($success) . ' / ' . count($filelist) . ' files have been deleted', 'success'); + Model::sendflashmessage(count(array_filter($success)) . ' / ' . count($filelist) . ' files have been deleted', 'success'); if(in_array(false, $success)) { return false; } else { @@ -338,16 +338,20 @@ class Modelmedia extends Model */ public function multimovefile(array $filedirlist, string $dir) : bool { - $success = []; + $count = 0; foreach ($filedirlist as $filedir ) { if(is_string($filedir)) { - $success[] = $this->movefile($filedir, $dir); + if($this->movefile($filedir, $dir)) { + $count ++; + } } } - Model::sendflashmessage(count($success) . ' / ' . count($filedirlist) . ' files have been moved', 'success'); - if(in_array(false, $success)) { + $total = count($filedirlist); + if($count !== $total) { + Model::sendflashmessage($count . ' / ' . $total . ' files have been moved', 'error'); return false; } else { + Model::sendflashmessage($count . ' / ' . $total . ' files have been moved', 'success'); return true; } } diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 492f03e..cf07c2b 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -46,7 +46,7 @@ class Modelpage extends Modeldb * * @param array $idlist list of ID strings * - * @return array of Page objects + * @return Page[] array of Page objects */ public function pagelistbyid(array $idlist = []) : array { @@ -65,13 +65,14 @@ class Modelpage extends Modeldb * Store new page in the database * * @param Page $page object + * @return bool depending on database storing */ - public function add(Page $page) + public function add(Page $page) : bool { $pagedata = new Document($page->dry()); $pagedata->setId($page->id()); - $this->repo->store($pagedata); + return $this->repo->store($pagedata); } /** @@ -395,15 +396,17 @@ class Modelpage extends Modeldb * @param array $reset * @param string $addtag * @param string $addauthor + * + * @return bool Depending on update success */ - public function pageedit($pageid, $datas, $reset, $addtag, $addauthor) + public function pageedit($pageid, $datas, $reset, $addtag, $addauthor) : bool { $page = $this->get($pageid); $page = $this->reset($page, $reset); $page->hydrate($datas); $page->addtag($addtag); $page->addauthor($addauthor); - $this->update($page); + return $this->update($page); } /** diff --git a/app/class/User.php b/app/class/User.php index 518b096..dba43e8 100644 --- a/app/class/User.php +++ b/app/class/User.php @@ -118,6 +118,9 @@ class User extends Item $id = idclean($id); if (strlen($id) < Model::MAX_ID_LENGTH and is_string($id)) { $this->id = $id; + return true; + } else { + return false; } } @@ -132,7 +135,12 @@ class User extends Item public function setpassword($password) { if (!empty($password) && is_string($password)) { - $this->password = $password; + if (strlen($password) >= Model::PASSWORD_MIN_LENGTH && strlen($password) <= Model::PASSWORD_MAX_LENGTH) { + $this->password = $password; + return true; + } else { + return false; + } } } @@ -152,9 +160,13 @@ class User extends Item public function setcookie($cookie) { - $cookie = abs(intval($cookie)); - if($cookie >= 365) {$cookie = 365;} - $this->cookie = $cookie; + $cookie = intval($cookie); + if($cookie <= Model::MAX_COOKIE_CONSERVATION && $cookie >= 0) { + $this->cookie = $cookie; + return true; + } else { + return false; + } } public function setcolumns($columns) diff --git a/app/view/templates/admin.php b/app/view/templates/admin.php index 3ae8036..ab35bd0 100644 --- a/app/view/templates/admin.php +++ b/app/view/templates/admin.php @@ -3,298 +3,295 @@ start('page') ?> - +insert('backtopbar', ['user' => $user, 'tab' => 'admin', 'pagelist' => $pagelist]) ?> - insert('backtopbar', ['user' => $user, 'tab' => 'admin', 'pagelist' => $pagelist]) ?> +
-
+ -
+
-
+
-

configuration

+

configuration

-
+
-

Home page

+

Home page

-

Here you can set the home-page view for visitors.

+

Here you can set the home-page view for visitors.

-
- form="admin"> - -
+
+ form="admin"> + +
-
- form="admin"> - -
+
+ form="admin"> + +
- + - - - + + - + ?> + -

Page creation

+

Page creation

-

What really happend when you create a new page

+

What really happend when you create a new page

- - + + - - + + -

Alert pages

+

Alert pages

-

Set the style and text to show when a page does not exist, or when a visitor don't have access to it.

+

Set the style and text to show when a page does not exist, or when a visitor don't have access to it.

-

Common options

+

Common options

- - + + - - - + + - - + + -

Un-existing

- - This will also be shown as a tooltip over links. - +

Un-existing

-
- - form="admin"> - -
+ + This will also be shown as a tooltip over links. + -

Private

+
+ + form="admin"> + +
- - +

Private

-
- - form="admin"> - -
+ + -

Not published

+
+ + form="admin"> + +
- - +

Not published

-
- - form="admin"> - -
+ + -

CSS

+
+ + form="admin"> + +
-
- - form="admin"> - -
+

CSS

-

- You can use body.alert class to specify style. -

+
+ + form="admin"> + +
+

+ You can use body.alert class to specify style. +

-

Render

-
- - form="admin"> - -
+

Render

+
+ + form="admin"> + +
-

Links

-
- - form="admin"> - -
+

Links

-
- - form="admin"> - -
+
+ + form="admin"> + +
- (This modifications need re-rendering) +
+ + form="admin"> + +
+ (This modifications need re-rendering) -

CSS

- - +

CSS

- - + + - - + + -

Interface

+ + -

Set interface Style

+

Interface

- +

Set interface Style

+ -

Tracking

- - +

Tracking

- (Need rendering to work) + + + (Need rendering to work) -
+
-
-
-
-

Databases

-
+
-
+
+
+

Databases

+
+ + + + + -
usingdatabasespages
- - - -
usingdatabasespages
+ + - - + + - + -

Duplicate Database

+

Duplicate Database

-
+ - - + - + + + - - - -
+ + + + -
-
+ +
-
- +
stop('page') ?> \ No newline at end of file diff --git a/app/view/templates/edit.php b/app/view/templates/edit.php index a27171a..22dda20 100644 --- a/app/view/templates/edit.php +++ b/app/view/templates/edit.php @@ -7,7 +7,6 @@ -
insert('backtopbar', ['user' => $user, 'tab' => 'edit', 'pagelist' => $pagelist, 'pageid' => $page->id()]) ?> @@ -32,6 +31,5 @@ let pagetitle = 'title() ?>'; - stop('page') ?> \ No newline at end of file diff --git a/app/view/templates/home.php b/app/view/templates/home.php index d6d1f51..387ef0c 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -6,243 +6,239 @@ start('page') ?> - - insert('backtopbar', ['user' => $user, 'tab' => 'home', 'pagelist' => $pagelist]) ?> +insert('backtopbar', ['user' => $user, 'tab' => 'home', 'pagelist' => $pagelist]) ?> - iseditor()) { ?> +iseditor()) { ?> - insert('homemenu', ['user' => $user, 'opt' => $opt, 'optlist' => $optlist, 'pagelist' => $pagelist, 'faviconlist' => $faviconlist, 'thumbnaillist' => $thumbnaillist, 'editorlist' => $editorlist, 'colors' => $colors]); - ?> +insert('homemenu', ['user' => $user, 'opt' => $opt, 'optlist' => $optlist, 'pagelist' => $pagelist, 'faviconlist' => $faviconlist, 'thumbnaillist' => $thumbnaillist, 'editorlist' => $editorlist, 'colors' => $colors]); +?> -
+
- insert('homeopt', ['opt' => $opt, 'user' => $user, 'display' => $display]) ?> + insert('homeopt', ['opt' => $opt, 'user' => $user, 'display' => $display]) ?> -
+
-
+
-

Pages () >list / >map

+

Pages () >list / >map

- + - + -
-
- - > - - > - - - - -
-
- -
- - - - - - - - - -
-
- - > - - > - - > - - > - - > - - > - - -
-
- - - +
+
+ + > + + > + + + + +
+
+
+ + + + + + + + + +
+
+ + > + + > + + > + + > + + > + + > + + +
+
-
- - - - issupereditor()) { ?> - - - - - - - - issupereditor()) { ?> - - + + +
+ +
x icoideditseedeldl
+ + + issupereditor()) { ?> + + + + + + + + issupereditor()) { ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + issupereditor()) { ?> + + + + + + + + issupereditor()) { ?> + + - - taglinks($item->tag('array')) ?> + - - title() ?>"> + - - description() ?>">description('short') ?> + - - linktolink($item->linkto('array')) ?> + - - datemodif('dmy') ?> datemodif('ptime') ?>> + - - datecreation('dmy') ?> datecreation('ptime') ?>> + - - date('dmy') ?> date('ptime') ?>> + - - securelink($item->secure('int') , $item->secure('string')) ?> + - - authorlinks($item->authors('array')) ?> + - - visitcount() ?> + - - editcount() ?> + - - - - - - - - issupereditor()) { ?> - - - - - - - - issupereditor()) { ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x icoideditseedeldltagtitlesummarylinktolast modificationdate of creationdateprivacyauthorsvisiteditaff
<?= $item->favicon() ?>issupereditor() || in_array($user->id(), $item->authors())) { ?>issupereditor() || $item->authors() === [$user->id()]) { ?>tagtitlesummarylinktolast modificationdate of creationdateprivacyauthorsvisiteditaff
<?= $item->favicon() ?>issupereditor() || in_array($user->id(), $item->authors())) { ?>issupereditor() || $item->authors() === [$user->id()]) { ?>taglinks($item->tag('array')) ?>description('short') ?>linktolink($item->linkto('array')) ?>datemodif('dmy') ?> datemodif('ptime') ?>>datecreation('dmy') ?> datecreation('ptime') ?>>date('dmy') ?> date('ptime') ?>>securelink($item->secure('int') , $item->secure('string')) ?>authorlinks($item->authors('array')) ?>visitcount() ?>editcount() ?>affcount() ?>
-
- - - -
+ affcount() ?> + + -
- - - display()['bookmark'] && (!empty(Wcms\Config::bookmark()) || !empty($user->bookmark()))) { ?> - -
-
-

Bookmarks

-
- Public -
    - $query) { ?> -
  • - -
  • - -
- id() ?> -
    - bookmark() as $id => $query) { ?> -
  • - -
  • - -
-
+ + + - - + + + + +
+ + + display()['bookmark'] && (!empty(Wcms\Config::bookmark()) || !empty($user->bookmark()))) { ?> + +
+
+

Bookmarks

+
+ Public +
    + $query) { ?> +
  • + +
  • + +
+ id() ?> +
    + bookmark() as $id => $query) { ?> +
  • + +
  • + +
+
+ + -
- - insert('footer', ['footer' => $footer]) ?> + - +
- +insert('footer', ['footer' => $footer]) ?> - + + stop() ?> \ No newline at end of file diff --git a/app/view/templates/homemenu.php b/app/view/templates/homemenu.php index 9d28ffa..ff39f1c 100644 --- a/app/view/templates/homemenu.php +++ b/app/view/templates/homemenu.php @@ -7,7 +7,7 @@
- stop('page') ?> \ No newline at end of file diff --git a/app/view/templates/layout.php b/app/view/templates/layout.php index c96c61f..7b8ef13 100644 --- a/app/view/templates/layout.php +++ b/app/view/templates/layout.php @@ -38,19 +38,23 @@ -
+ +
  • - -
-
+ + +
+ + + section('page') ?> + -section('page') ?> \ No newline at end of file diff --git a/app/view/templates/media.php b/app/view/templates/media.php index 9f56116..9901b8e 100644 --- a/app/view/templates/media.php +++ b/app/view/templates/media.php @@ -7,11 +7,10 @@ $this->layout('layout', ['title' => 'media', 'stylesheets' => [$css . 'home.css' start('page') ?> - - insert('backtopbar', ['user' => $user, 'tab' => 'media', 'pagelist' => $pagelist]) ?> +insert('backtopbar', ['user' => $user, 'tab' => 'media', 'pagelist' => $pagelist]) ?> - insert('mediamenu', ['user' => $user, 'pathlist' => $pathlist, 'mediaopt' => $mediaopt]) ?> +insert('mediamenu', ['user' => $user, 'pathlist' => $pathlist, 'mediaopt' => $mediaopt]) ?>
@@ -116,6 +115,5 @@ $this->layout('layout', ['title' => 'media', 'stylesheets' => [$css . 'home.css' - stop('page') ?> \ No newline at end of file diff --git a/app/view/templates/timeline.php b/app/view/templates/timeline.php index f06180e..e3c6438 100644 --- a/app/view/templates/timeline.php +++ b/app/view/templates/timeline.php @@ -6,9 +6,8 @@ start('page') ?> - - insert('backtopbar', ['user' => $user, 'tab' => 'timeline', 'pagelist' => $pagelist]) ?> +insert('backtopbar', ['user' => $user, 'tab' => 'timeline', 'pagelist' => $pagelist]) ?> iseditor()) { ?> @@ -97,7 +96,6 @@ foreach ($groupedeventlist as $eventuser) { - diff --git a/app/view/templates/user.php b/app/view/templates/user.php index f77699d..faa44aa 100644 --- a/app/view/templates/user.php +++ b/app/view/templates/user.php @@ -7,14 +7,12 @@ $this->layout('layout', ['title' => 'user', 'stylesheets' => [$css . 'home.css'] start('page') ?> - - - insert('backtopbar', ['user' => $user, 'tab' => 'user', 'pagelist' => $pagelist]) ?> +insert('backtopbar', ['user' => $user, 'tab' => 'user', 'pagelist' => $pagelist]) ?>
-
+
@@ -34,25 +32,26 @@ $this->layout('layout', ['title' => 'user', 'stylesheets' => [$css . 'home.css']

Preferences

+
- + -

- - -

When you tick the remember-me checkbox during login, you can choose how much time W will remember you.

+ + +

When you tick the remember-me checkbox during login, you can choose how much time W will remember you.

- - - - + + + + -
- -

- - +

Password have to be between and characters long.

+ + + + +
@@ -215,6 +214,5 @@ $this->layout('layout', ['title' => 'user', 'stylesheets' => [$css . 'home.css']
- stop('page') ?> \ No newline at end of file -- cgit v1.2.3