diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/class/Colors.php | 10 | ||||
-rw-r--r-- | app/class/Controller.php | 2 | ||||
-rw-r--r-- | app/class/Controlleradmin.php | 2 | ||||
-rw-r--r-- | app/class/Controllerconnect.php | 7 | ||||
-rw-r--r-- | app/class/Controllermedia.php | 6 | ||||
-rw-r--r-- | app/class/Controllerpage.php | 3 | ||||
-rw-r--r-- | app/class/Dbitem.php | 2 | ||||
-rw-r--r-- | app/class/Event.php | 7 | ||||
-rw-r--r-- | app/class/Flywheel/Formatter/JSON.php | 6 | ||||
-rw-r--r-- | app/class/Item.php | 6 | ||||
-rw-r--r-- | app/class/Media.php | 1 | ||||
-rw-r--r-- | app/class/Modelhome.php | 6 | ||||
-rw-r--r-- | app/class/Modelmedia.php | 2 | ||||
-rw-r--r-- | app/class/Modelpage.php | 7 | ||||
-rw-r--r-- | app/class/Modelrender.php | 13 | ||||
-rw-r--r-- | app/class/Modeltimeline.php | 5 | ||||
-rw-r--r-- | app/class/Page.php | 15 | ||||
-rw-r--r-- | app/class/User.php | 2 | ||||
-rw-r--r-- | app/fn/fn.php | 4 |
19 files changed, 56 insertions, 50 deletions
diff --git a/app/class/Colors.php b/app/class/Colors.php index 234adb2..ffa56b6 100644 --- a/app/class/Colors.php +++ b/app/class/Colors.php @@ -5,7 +5,7 @@ namespace Wcms; class Colors extends Item { - protected $file = MODEL::CSS_DIR . 'tagcolors.css'; + protected $file = Model::CSS_DIR . 'tagcolors.css'; protected $rawcss = ""; @@ -27,7 +27,7 @@ class Colors extends Item public function readcssfile(): bool { - if (MODEL::dircheck(MODEL::CSS_DIR) && file_exists($this->file)) { + if (Model::dircheck(Model::CSS_DIR) && file_exists($this->file)) { $this->rawcss = file_get_contents($this->file); return true; } else { @@ -53,7 +53,7 @@ class Colors extends Item /** * Transform a CSS string in a array of `tag => background-color` * - * @return array Ouput array using TAG as key and Hex Color as value + * @return bool Ouput array using TAG as key and Hex Color as value */ public function parsetagcss() { @@ -79,7 +79,7 @@ class Colors extends Item public function writecssfile() { - if (MODEL::dircheck(MODEL::CSS_DIR)) { + if (Model::dircheck(Model::CSS_DIR)) { return file_put_contents($this->file, $this->rawcss); } } @@ -90,7 +90,7 @@ class Colors extends Item foreach ($this->tagcolor as $tag => $color) { $i = '<input type="color" name="tagcolor[' . $tag . ']" value="' . $color . '" id="color_' . $tag . '">'; $l = '<label for="color_' . $tag . '" >' . $tag . '</label>'; - $html .= '\n<li>' . $i . $l . '</li>'; + $html .= "\n<li>" . $i . $l . '</li>'; } $html .= PHP_EOL . '</ul>'; return $html; diff --git a/app/class/Controller.php b/app/class/Controller.php index 4185be8..34b3d11 100644 --- a/app/class/Controller.php +++ b/app/class/Controller.php @@ -33,7 +33,7 @@ class Controller $this->router = $router; $this->pagemanager = new Modelpage(); $this->initplates(); - $this->now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $this->now = new DateTimeImmutable("now", timezone_open("Europe/Paris")); } public function setuser() diff --git a/app/class/Controlleradmin.php b/app/class/Controlleradmin.php index d3ceab7..f68cb82 100644 --- a/app/class/Controlleradmin.php +++ b/app/class/Controlleradmin.php @@ -45,7 +45,7 @@ class Controlleradmin extends Controller public function update() { - MODEL::dircheck(MODEL::GLOBAL_DIR); + Model::dircheck(Model::GLOBAL_DIR); $globalcss = file_put_contents(Model::GLOBAL_DIR . 'global.css', $_POST['globalcss']); diff --git a/app/class/Controllerconnect.php b/app/class/Controllerconnect.php index 24b0c3c..9dc788b 100644 --- a/app/class/Controllerconnect.php +++ b/app/class/Controllerconnect.php @@ -83,7 +83,7 @@ class Controllerconnect extends Controller /** * Create a token stored in the database and then a cookie * - * @return string|bool Token in cas of success, otherwise, false. + * @return string|false Token in cas of success, otherwise, false. */ public function createauthtoken() { @@ -95,9 +95,8 @@ class Controllerconnect extends Controller if ($cookiecreation) { return $tokenid; } - } else { - return false; } + return false; } /** @@ -112,7 +111,7 @@ class Controllerconnect extends Controller { $hash = secrethash($token); $cookie = $token . ':' . $hash; - return setcookie('authtoken', $cookie, time() + $conservation * 24 * 3600, null, null, false, true); + return setcookie('authtoken', $cookie, time() + $conservation * 24 * 3600, "", "", false, true); } /** diff --git a/app/class/Controllermedia.php b/app/class/Controllermedia.php index 06885b3..95b4f9b 100644 --- a/app/class/Controllermedia.php +++ b/app/class/Controllermedia.php @@ -18,6 +18,9 @@ class Controllermedia extends Controller $this->mediamanager = new Modelmedia(); } + /** + * @throws Exception + */ public function desktop() { if ($this->user->iseditor()) { @@ -81,8 +84,9 @@ class Controllermedia extends Controller $dir = $_POST['dir'] ?? Model::MEDIA_DIR; $name = idclean($_POST['foldername']) ?? 'new-folder'; $this->mediamanager->adddir($dir, $name); + $this->redirect($this->generate('media') . '?path=/' . $dir . DIRECTORY_SEPARATOR . $name); } - $this->redirect($this->generate('media') . '?path=/' . $dir . DIRECTORY_SEPARATOR . $name); + $this->routedirect('home'); } public function folderdelete() diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index 9d20ded..ad6bf82 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -99,7 +99,7 @@ class Controllerpage extends Controller */ public function renderpage(Page $page): Page { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $now = new DateTimeImmutable("now", timezone_open("Europe/Paris")); $renderengine = new Modelrender($this->router); @@ -128,6 +128,7 @@ class Controllerpage extends Controller $this->setpage($id, 'pageread/'); $pageexist = $this->importpage(); + $canread = false; if ($pageexist) { $canread = $this->user->level() >= $this->page->secure(); diff --git a/app/class/Dbitem.php b/app/class/Dbitem.php index 44dec2c..29f7a2c 100644 --- a/app/class/Dbitem.php +++ b/app/class/Dbitem.php @@ -11,7 +11,7 @@ abstract class Dbitem extends Item public function dry() { $array = []; - foreach ($this as $var => $value) { + foreach (get_object_vars($this) as $var => $value) { if ($value instanceof DateTime || $value instanceof DateTimeImmutable) { $array[$var] = $this->$var('string'); } else { diff --git a/app/class/Event.php b/app/class/Event.php index 3317a1b..069050a 100644 --- a/app/class/Event.php +++ b/app/class/Event.php @@ -40,7 +40,7 @@ class Event extends Dbitem public function stamp() { - $this->date = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $this->date = new DateTimeImmutable("now", timezone_open("Europe/Paris")); $this->user = idclean($this->user); if (in_array($this->type, self::EVENT_ART)) { $this->target = idclean($this->target); @@ -66,16 +66,13 @@ class Event extends Dbitem switch ($type) { case 'datetime': return $this->date; - break; case 'string': return $this->date->format(DateTime::ISO8601); - break; case 'hrdi': - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $now = new DateTimeImmutable("now", timezone_open("Europe/Paris")); return hrdi($this->date->diff($now)); - break; } } diff --git a/app/class/Flywheel/Formatter/JSON.php b/app/class/Flywheel/Formatter/JSON.php index d55c3b6..108c756 100644 --- a/app/class/Flywheel/Formatter/JSON.php +++ b/app/class/Flywheel/Formatter/JSON.php @@ -10,13 +10,11 @@ class JSON implements \JamesMoss\Flywheel\Formatter\FormatInterface } public function encode(array $data) { - $options = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; - $options .= JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE; + $options = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE : null; return json_encode($data, $options); } public function decode($data) { - $options = defined('JSON_OBJECT_AS_ARRAY') ? JSON_OBJECT_AS_ARRAY : null; - return json_decode($data, $options); + return json_decode($data, true); } } diff --git a/app/class/Item.php b/app/class/Item.php index 8a8f2d6..a76e700 100644 --- a/app/class/Item.php +++ b/app/class/Item.php @@ -33,7 +33,7 @@ abstract class Item public function dry() { $array = []; - foreach ($this as $var => $value) { + foreach (get_object_vars($this) as $var => $value) { $array[$var] = $this->$var(); } return $array; @@ -74,13 +74,13 @@ abstract class Item } elseif ($option == 'date' || $option == 'sort') { return $this->$property; } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $now = new DateTimeImmutable("now", timezone_open("Europe/Paris")); return hrdi($this->$property->diff($now)); } elseif ($option == 'pdate') { return $this->$property->format('Y-m-d'); } elseif ($option == 'ptime') { return $this->$property->format('H:i'); - } elseif ($option = 'dmy') { + } elseif ($option == 'dmy') { return $this->$property->format('d/m/Y'); } } else { diff --git a/app/class/Media.php b/app/class/Media.php index 9df2fef..b08726d 100644 --- a/app/class/Media.php +++ b/app/class/Media.php @@ -5,6 +5,7 @@ namespace Wcms; use DateTime; use DateTimeImmutable; use DateTimeZone; +use Exception; class Media extends Item { diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index b35fe6d..b798f56 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -29,7 +29,7 @@ class Modelhome extends Modelpage * @param Opt $opt * * @param string $regex Regex to match. - * @param array $options Option search, could be `content` `title` `description`. + * @param array $searchopt Option search, could be `content` `title` `description`. * * @return array associative array of `Page` objects * */ @@ -98,7 +98,7 @@ class Modelhome extends Modelpage /** * Search for regex and count occurences * - * @param array $page list Array of Pages. + * @param array $pagelist list Array of Pages. * @param string $regex Regex to match. * @param array $options Option search, could be `content` `title` `description`. * @@ -279,7 +279,7 @@ class Modelhome extends Modelpage /** - * @param array array of the columns to show from the user + * @param array $columns array of the columns to show from the user * * @return array assoc each key columns to a boolean value to show or not */ diff --git a/app/class/Modelmedia.php b/app/class/Modelmedia.php index ceb9bc7..bd0ff03 100644 --- a/app/class/Modelmedia.php +++ b/app/class/Modelmedia.php @@ -75,7 +75,7 @@ class Modelmedia extends Model * * @param array $medialist * @param string $sortby - * @param int order Can be 1 or -1 + * @param int $order Can be 1 or -1 */ public function medialistsort(array &$medialist, string $sortby = 'id', int $order = 1): bool { diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 8bfa757..e2a2718 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -5,6 +5,7 @@ namespace Wcms; use Exception; use JamesMoss\Flywheel\Document; use DateTimeImmutable; +use LogicException; class Modelpage extends Modeldb { @@ -17,7 +18,7 @@ class Modelpage extends Modeldb $this->dbinit(Model::PAGES_DIR); $this->storeinit(Config::pagetable()); if (!$this->dircheck(Model::HTML_RENDER_DIR)) { - throw new Exception("Media error : Cant create /render folder"); + throw new LogicException("Media error : Cant create /render folder"); } } @@ -143,7 +144,7 @@ class Modelpage extends Modeldb /** * Delete a page and it's linked rendered html and css files * - * @param Page|string $id could be an Page object or a id string + * @param Page|string $page could be an Page object or a id string * * @return bool true if success otherwise false */ @@ -423,7 +424,7 @@ class Modelpage extends Modeldb */ public function reset(Page $page, array $reset): Page { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $now = new DateTimeImmutable("now", timezone_open("Europe/Paris")); if ($reset['tag']) { $page->settag([]); } diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php index 553857b..7322955 100644 --- a/app/class/Modelrender.php +++ b/app/class/Modelrender.php @@ -3,6 +3,7 @@ namespace Wcms; use Exception; +use LogicException; use Michelf\MarkdownExtra; class Modelrender extends Modelpage @@ -56,7 +57,11 @@ class Modelrender extends Modelpage */ public function upage(string $id): string { - return $this->generate('pageread/', ['page' => $id]); + try { + return $this->router->generate('pageread/', ['page' => $id]); + } catch (Exception $e) { + throw new LogicException($e->getMessage(), $e->getCode(), $e); + } } @@ -128,7 +133,7 @@ class Modelrender extends Modelpage $matches = $this->match($body, $regex); // First, analyse the synthax and call the corresponding methods - if (isset($matches)) { + if (!empty($matches)) { foreach ($matches as $key => $match) { $element = new Element($this->page->id(), $match); $element->setcontent($this->getelementcontent($element->sources(), $element->type())); @@ -534,7 +539,7 @@ class Modelrender extends Modelpage { $matches = $this->match($text, 'MEDIA'); - if (isset($matches)) { + if (!empty($matches)) { foreach ($matches as $match) { $medialist = new Medialist($match); $medialist->readoptions(); @@ -575,7 +580,7 @@ class Modelrender extends Modelpage $modelhome = new Modelhome(); - if (isset($matches)) { + if (!empty($matches)) { foreach ($matches as $match) { $optlist = new Optlist(['render' => $this]); $optlist->parsehydrate($match['options']); diff --git a/app/class/Modeltimeline.php b/app/class/Modeltimeline.php index db9c4f5..be80211 100644 --- a/app/class/Modeltimeline.php +++ b/app/class/Modeltimeline.php @@ -19,7 +19,7 @@ class Modeltimeline extends Modeldb public function get(int $id) { - $eventdata = $this->repo->findById($id); + $eventdata = $this->repo->findById("$id"); if ($eventdata !== false) { return new Event($eventdata); } else { @@ -62,7 +62,7 @@ class Modeltimeline extends Modeldb /** * Store event * - * @param Event The event to be stored in the repositery + * @param Event $event The event to be stored in the repositery * * @return bool retrun true if it works, false if it fails */ @@ -97,6 +97,7 @@ class Modeltimeline extends Modeldb $id = 0; $subid = 0; $lastuser = null; + $groupedevents = []; foreach ($events as $event) { if ($event->user() !== $lastuser) { $subid = 0; diff --git a/app/class/Page.php b/app/class/Page.php index 760521b..da149f7 100644 --- a/app/class/Page.php +++ b/app/class/Page.php @@ -53,8 +53,7 @@ class Page extends Dbitem public const TABS = ['main', 'css', 'header', 'body', 'nav', 'aside', 'footer', 'javascript']; public const VAR_DATE = ['date', 'datecreation', 'datemodif', 'daterender']; - - + // _____________________________________________________ F U N ____________________________________________________ @@ -71,7 +70,7 @@ class Page extends Dbitem public function reset() { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $now = new DateTimeImmutable("now", timezone_open("Europe/Paris")); $this->settitle($this->id()); $this->setdescription(''); @@ -460,7 +459,7 @@ class Page extends Dbitem if ($datecreation instanceof DateTimeImmutable) { $this->datecreation = $datecreation; } elseif ($datecreation === true) { - $this->datecreation = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $this->datecreation = new DateTimeImmutable("now", timezone_open("Europe/Paris")); } else { $this->datecreation = DateTimeImmutable::createFromFormat( DateTime::ISO8601, @@ -508,7 +507,7 @@ class Page extends Dbitem public function setjavascript($javascript) { - if (strlen($javascript < self::LENTEXT && is_string($javascript))) { + if (strlen($javascript) < self::LENTEXT && is_string($javascript)) { $this->javascript = $javascript; } } @@ -516,14 +515,14 @@ class Page extends Dbitem public function setbody($body) { - if (strlen($body < self::LENTEXT && is_string($body))) { + if (strlen($body) < self::LENTEXT && is_string($body)) { $this->body = $body; } } public function setheader($header) { - if (strlen($header < self::LENTEXT && is_string($header))) { + if (strlen($header) < self::LENTEXT && is_string($header)) { $this->header = $header; } } @@ -756,7 +755,7 @@ class Page extends Dbitem public function updateedited() { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $now = new DateTimeImmutable("now", timezone_open("Europe/Paris")); $this->setdatemodif($now); $this->addeditcount(); } diff --git a/app/class/User.php b/app/class/User.php index ecb4507..a62091f 100644 --- a/app/class/User.php +++ b/app/class/User.php @@ -90,7 +90,7 @@ class User extends Item if (empty($this->expiredate)) { return 'never'; } else { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $now = new DateTimeImmutable("now", timezone_open("Europe/Paris")); if ($this->expiredate < $now) { return 'expired'; } else { diff --git a/app/fn/fn.php b/app/fn/fn.php index 243e056..6b312a2 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -24,7 +24,7 @@ function readablesize($bytes, $base = 2 ** 10) } elseif ($bytes < $base ** 3) { $num = round($bytes / $base ** 2, 1); $unit = 'M' . $i; - } elseif ($bytes < $base ** 4) { + } else { $num = round($bytes / $base ** 3, 1); $unit = 'G' . $i; } @@ -87,7 +87,7 @@ function arrayclean($input) return $output; } -function idclean(string $input) +function idclean(string $input): string { $input = urldecode($input); $search = ['é', 'à', 'è', 'ç', 'ù', 'ï', 'î', ' ']; |