diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-01-10 15:28:29 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-01-10 15:28:29 +0100 |
commit | 7001272f4e8b683cbc64564c5798d85a34ab9026 (patch) | |
tree | 01f52cca7f8013b3b66bfbd29c2d4a1538b097b4 /app | |
parent | 7eb6ec32c4313a7456370e47d3878ff961ec56d0 (diff) | |
download | wcms-7001272f4e8b683cbc64564c5798d85a34ab9026.tar.gz wcms-7001272f4e8b683cbc64564c5798d85a34ab9026.zip |
refact : ptime pdate added inside of page
Diffstat (limited to 'app')
-rw-r--r-- | app/class/Controllerpage.php | 8 | ||||
-rw-r--r-- | app/class/Page.php | 67 |
2 files changed, 57 insertions, 18 deletions
diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index 2a67106..d1bfca5 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -315,11 +315,10 @@ class Controllerpage extends Controller $this->movepanels(); $this->fontsize(); - $date = new DateTimeImmutable($_POST['pdate'] . $_POST['ptime'], new DateTimeZone('Europe/Paris')); - $date = ['date' => $date]; + if ($this->importpage()) { - if ($this->canedit()) { + if ($this->canedit()) { // Check if someone esle edited the page during the editing. $oldpage = clone $this->page; @@ -329,7 +328,6 @@ class Controllerpage extends Controller } - $this->page->hydrate($date); $this->page->updateedited(); $this->page->addauthor($this->user->id()); $this->page->removeeditby($this->user->id()); @@ -405,7 +403,7 @@ class Controllerpage extends Controller Config::savejson(); } } - + public function pagedirect($id) { $this->routedirect('pageread/', ['page' => idclean($id)]); diff --git a/app/class/Page.php b/app/class/Page.php index 2fa4060..1daa240 100644 --- a/app/class/Page.php +++ b/app/class/Page.php @@ -114,8 +114,6 @@ class Page $this->seteditby([]); } - - public static function classvarlist() { $classvarlist = []; @@ -484,18 +482,10 @@ class Page public function settag($tag) { - if (is_string($tag)) { - - if (strlen($tag) < self::LEN) { - $tag = strip_tags(trim(strtolower($tag))); - $tag = str_replace('*', '', $tag); - $tag = str_replace(' ', '', $tag); - - $taglist = explode(",", $tag); - $taglist = array_filter($taglist); - $this->tag = $taglist; + if (is_string($tag) && strlen($tag) < self::LEN) { + $tag = $this->tagtoarray($tag); } - } elseif (is_array($tag)) { + if (is_array($tag)) { $this->tag = $tag; } } @@ -509,6 +499,22 @@ class Page } } + public function setptime($ptime) + { + if(is_string($ptime) && DateTime::createFromFormat('H:i', $ptime) !== FALSE) { + $time = explode(':', $ptime); + $this->date = $this->date->setTime($time[0], $time[1]); + } + } + + public function setpdate($pdate) + { + if(is_string($pdate) && DateTime::createFromFormat('Y-m-d', $pdate) !== FALSE) { + $date = explode('-', $pdate); + $this->date = $this->date->setDate($date[0], $date[1], $date[2]); + } + } + public function setdatecreation($datecreation) { if ($datecreation instanceof DateTimeImmutable) { @@ -813,6 +819,41 @@ class Page return count($this->editby) > 0; } + /** + * Merge new tag with actual tags + * + * @param string|array $tag Could be tags as string or array + */ + + public function addtag($tag) + { + if (is_string($tag)) { + $tag = $this->tagtoarray($tag); + } + if(is_array($tag)) { + $this->tag = array_unique(array_merge($this->tag, $tag)); + } + } + + + // _________________________________ T O O L S ______________________________________ + + /** + * Convert a tag string to an array ready to be stored + * + * @param string $tagstring Tag as string separated by commas + * @return array Tags stored as an array + */ + + private function tagtoarray(string $tagstring) : array + { + $tag = strip_tags(trim(strtolower($tagstring))); + $tag = str_replace('*', '', $tag); + $tag = str_replace(' ', '', $tag); + $taglist = explode(",", $tag); + $taglist = array_filter($taglist); + return $taglist; + } } |