diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-04-28 20:18:17 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-04-28 20:24:52 +0200 |
commit | 9090550d241f9f7b3246b24bfd323bd988add749 (patch) | |
tree | 2c2de66510533da53848dd876a9ab392471b38b8 /app/class | |
parent | 98514a4e0037aa0879e45bbad660aeda8837c624 (diff) | |
download | wcms-9090550d241f9f7b3246b24bfd323bd988add749.tar.gz wcms-9090550d241f9f7b3246b24bfd323bd988add749.zip |
listen to brother Stan and clean some things
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/Bookmark.php | 9 | ||||
-rw-r--r-- | app/class/Config.php | 2 | ||||
-rw-r--r-- | app/class/Controllermedia.php | 6 | ||||
-rw-r--r-- | app/class/Controllerpage.php | 40 | ||||
-rw-r--r-- | app/class/Controlleruser.php | 4 | ||||
-rw-r--r-- | app/class/Media.php | 6 | ||||
-rw-r--r-- | app/class/Mediaopt.php (renamed from app/class/Medialist.php) | 2 | ||||
-rw-r--r-- | app/class/Modelconfig.php | 28 | ||||
-rw-r--r-- | app/class/Modelfont.php | 6 | ||||
-rw-r--r-- | app/class/Modelhome.php | 2 | ||||
-rw-r--r-- | app/class/Modelmedia.php | 3 | ||||
-rw-r--r-- | app/class/Modelpage.php | 1 | ||||
-rw-r--r-- | app/class/Modelrender.php | 14 | ||||
-rw-r--r-- | app/class/Page.php | 27 | ||||
-rw-r--r-- | app/class/Session.php | 2 | ||||
-rw-r--r-- | app/class/User.php | 17 |
16 files changed, 36 insertions, 133 deletions
diff --git a/app/class/Bookmark.php b/app/class/Bookmark.php index 5c4d2fc..8b4d2f7 100644 --- a/app/class/Bookmark.php +++ b/app/class/Bookmark.php @@ -74,12 +74,11 @@ class Bookmark extends Item public function setid($id): bool { if (is_string($id)) { - try { - $this->id = idclean($id, Model::MAX_ID_LENGTH, 1); - } catch (\Throwable $th) { - return false; + $id = idclean($id); + if (!empty($id)) { + $this->id = $id; + return true; } - return true; } return false; } diff --git a/app/class/Config.php b/app/class/Config.php index b629bc5..37321e4 100644 --- a/app/class/Config.php +++ b/app/class/Config.php @@ -81,7 +81,7 @@ abstract class Config public static function tojson() { - $arr = get_class_vars(__class__); + $arr = get_class_vars(get_class()); $json = json_encode($arr, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT); return $json; } diff --git a/app/class/Controllermedia.php b/app/class/Controllermedia.php index a957df8..c6e5d6c 100644 --- a/app/class/Controllermedia.php +++ b/app/class/Controllermedia.php @@ -2,8 +2,8 @@ namespace Wcms; -use \Exception; -use \LogicException; +use Exception; +use LogicException; class Controllermedia extends Controller { @@ -34,7 +34,7 @@ class Controllermedia extends Controller throw new LogicException($exception->getMessage()); } - $mediaopt = new Medialist($_GET); + $mediaopt = new Mediaopt($_GET); if (empty($mediaopt->path())) { $mediaopt->setpath(DIRECTORY_SEPARATOR . Model::MEDIA_DIR); } diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index b5679a9..c7e1f98 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -13,8 +13,6 @@ class Controllerpage extends Controller protected $fontmanager; protected $mediamanager; - public const COMBINE = false; - public function __construct($router) { parent::__construct($router); @@ -368,9 +366,6 @@ class Controllerpage extends Controller $oldpage = clone $this->page; $this->page->hydrate($_POST); - if (self::COMBINE && $_POST['thisdatemodif'] === $oldpage->datemodif('string')) { - } - $this->page->updateedited(); $this->page->addauthor($this->user->id()); $this->page->removeeditby($this->user->id()); @@ -389,41 +384,6 @@ class Controllerpage extends Controller $this->routedirect('pageedit', ['page' => $this->page->id()]); } - /** - * This function set the actual editor of the page - * - * @param string $pageid as the page id - */ - public function editby(string $pageid) - { - $this->page = new Page(['id' => $pageid]); - if ($this->importpage($pageid)) { - $this->page->addeditby($this->user->id()); - $this->pagemanager->update($this->page); - echo json_encode(['success' => true]); - } else { - $this->error(400); - } - } - - /** - * This function remove the actual editor of the page - * - * @param string $pageid as the page id - */ - public function removeeditby(string $pageid) - { - $this->page = new Page(['id' => $pageid]); - if ($this->importpage($pageid)) { - $this->page->removeeditby($this->user->id()); - $this->pagemanager->update($this->page); - echo json_encode(['success' => true]); - } else { - $this->error(400); - } - } - - public function movepanels() { $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']); diff --git a/app/class/Controlleruser.php b/app/class/Controlleruser.php index 755b491..53cf9b9 100644 --- a/app/class/Controlleruser.php +++ b/app/class/Controlleruser.php @@ -37,9 +37,9 @@ class Controlleruser extends Controller if ($this->user->iseditor()) { $user = $this->usermanager->get($this->user); try { - $user->hydrate($_POST, true); + $user->hydrateexception($_POST); } catch (\Throwable $th) { - Model::sendflashmessage('There was a problem when updating preferences : ' . $th->getMessage(), 'error'); + Model::sendflashmessage('There was a problem when updating preference : ' . $th->getMessage(), 'error'); } if ($_POST['passwordhash']) { $user->hashpassword(); diff --git a/app/class/Media.php b/app/class/Media.php index b08726d..7105830 100644 --- a/app/class/Media.php +++ b/app/class/Media.php @@ -265,7 +265,11 @@ class Media extends Item public function setdate() { $timestamp = filemtime($this->getfulldir()); - $this->date = new DateTimeImmutable("@$timestamp"); + try { + $this->date = new DateTimeImmutable("@$timestamp"); + } catch (\Throwable $th) { + $this->date = new DateTimeImmutable(); + } } public function setwidth($width) diff --git a/app/class/Medialist.php b/app/class/Mediaopt.php index e716845..8bed1e0 100644 --- a/app/class/Medialist.php +++ b/app/class/Mediaopt.php @@ -2,7 +2,7 @@ namespace Wcms; -class Medialist extends Item +class Mediaopt extends Item { /** @var string full regex match */ protected $fullmatch; diff --git a/app/class/Modelconfig.php b/app/class/Modelconfig.php deleted file mode 100644 index 6c074eb..0000000 --- a/app/class/Modelconfig.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -namespace Wcms; - -abstract class Modelconfig extends Model -{ - public static function readconfig() - { - if (file_exists(self::CONFIG_FILE)) { - $current = file_get_contents(self::CONFIG_FILE); - $donnees = json_decode($current, true); - return new Config($donnees); - } else { - return 0; - } - } - - public static function createconfig(array $donnees) - { - return new Config($donnees); - } - - - public static function savejson(string $json) - { - file_put_contents(self::CONFIG_FILE, $json); - } -} diff --git a/app/class/Modelfont.php b/app/class/Modelfont.php index 3dac3ff..48885be 100644 --- a/app/class/Modelfont.php +++ b/app/class/Modelfont.php @@ -33,8 +33,8 @@ class Modelfont extends Model public function list() { + $list = []; if ($handle = opendir(Model::FONT_DIR)) { - $list = []; while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { $list[] = $entry; @@ -73,7 +73,7 @@ class Modelfont extends Model public function write(string $fontface) { - $write = file_put_contents(Model::GLOBAL_DIR . 'fonts.css', $fontface); + $write = file_put_contents(Model::ASSETS_CSS_DIR . 'fonts.css', $fontface); if ($write !== false) { } } @@ -81,7 +81,7 @@ class Modelfont extends Model public function upload(array $file, $maxsize = 2 ** 24, $id = null) { $message = 'runing'; - if (isset($file) and $file['font']['error'] == 0 and $file['font']['size'] < $maxsize) { + if ($file['font']['error'] == 0 && $file['font']['size'] < $maxsize) { $infosfichier = pathinfo($file['font']['name']); $extension_upload = $infosfichier['extension']; $extensions_autorisees = $this::FONT_TYPES; diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index b798f56..680cfa9 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -264,7 +264,7 @@ class Modelhome extends Modelpage $nodes = []; foreach ($pagelist as $id => $page) { - if ($showorphans || (!$showorphans && in_array($id, $notorphans))) { + if ($showorphans || in_array($id, $notorphans)) { $node['group'] = 'nodes'; $node['data']['id'] = $page->id(); $node['data']['edit'] = $page->id() . DIRECTORY_SEPARATOR . 'edit'; diff --git a/app/class/Modelmedia.php b/app/class/Modelmedia.php index 2894783..0b1d700 100644 --- a/app/class/Modelmedia.php +++ b/app/class/Modelmedia.php @@ -31,7 +31,7 @@ class Modelmedia extends Model } } - public function medialistopt(Medialist $mediaopt) + public function medialistopt(Mediaopt $mediaopt) { $medialist = $this->getlistermedia($mediaopt->dir(), $mediaopt->type()); $this->medialistsort($medialist, $mediaopt->sortby(), $mediaopt->order()); @@ -179,6 +179,7 @@ class Modelmedia extends Model $this->listpath($content, $parent . $dir . DIRECTORY_SEPARATOR, $pathlist); } } + return $pathlist; } /** diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 834ba01..f6b0c8e 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -308,7 +308,6 @@ class Modelpage extends Modeldb /** * @param array $pagelist List of Page * @param int $secure secure level - * * @return array $array of `string` page id */ diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php index 4722057..fd8531a 100644 --- a/app/class/Modelrender.php +++ b/app/class/Modelrender.php @@ -17,8 +17,6 @@ class Modelrender extends Modelpage protected $internallinkblank = ''; protected $externallinkblank = ''; - public const RENDER_VERBOSE = 1; - public function __construct(\AltoRouter $router) { parent::__construct(); @@ -162,7 +160,7 @@ class Modelrender extends Modelpage if ($source !== $this->page->id()) { $subcontent = $this->getpageelement($source, $type); if ($subcontent !== false) { - if (empty($subcontent && self::RENDER_VERBOSE > 0)) { + if (empty($subcontent)) { $message = 'The ' . strtoupper($type) . ' from page "' . $source . '" is currently empty !'; $subcontent = "\n<!-- ' . $message . ' -->\n"; } @@ -216,12 +214,12 @@ class Modelrender extends Modelpage public function writetemplates() { - if (array_key_exists('css', $this->page->template('array'))) { - $tempaltecsspage = $this->get($this->page->template('array')['css']); + if (array_key_exists('css', $this->page->template())) { + $tempaltecsspage = $this->get($this->page->template()['css']); file_put_contents(Model::RENDER_DIR . $tempaltecsspage->id() . '.css', $tempaltecsspage->css()); } - if (array_key_exists('javascript', $this->page->template('array'))) { - $templatejspage = $this->get($this->page->template('array')['javascript']); + if (array_key_exists('javascript', $this->page->template())) { + $templatejspage = $this->get($this->page->template()['javascript']); file_put_contents(Model::RENDER_DIR . $templatejspage->id() . '.js', $templatejspage->javascript()); } } @@ -547,7 +545,7 @@ class Modelrender extends Modelpage if (!empty($matches)) { foreach ($matches as $match) { - $medialist = new Medialist($match); + $medialist = new Mediaopt($match); $medialist->readoptions(); $text = str_replace($medialist->fullmatch(), $medialist->generatecontent(), $text); } diff --git a/app/class/Page.php b/app/class/Page.php index 43cf387..b1c6b49 100644 --- a/app/class/Page.php +++ b/app/class/Page.php @@ -234,22 +234,11 @@ class Page extends Dbitem if ($this->secure == 2) { $secure = 'not_published'; } - return $secure; } else { return $this->secure; } } - public function invitepassword($type = 'string') - { - return $this->invitepassword; - } - - public function readpassword($type = 'string') - { - return $this->readpassword; - } - public function interface($type = 'string') { return $this->interface; @@ -266,7 +255,7 @@ class Page extends Dbitem } elseif ($option == 'string') { return implode(', ', $this->linkto); } - return $linkto; + return $this->linkto; } public function templatebody($type = 'string') @@ -576,20 +565,6 @@ class Page extends Dbitem } } - public function setinvitepassword($invitepassword) - { - if (is_string($invitepassword) && strlen($invitepassword) < self::LEN) { - $this->invitepassword = $invitepassword; - } - } - - public function setreadpassword($readpassword) - { - if (is_string($readpassword) && strlen($readpassword) < self::LEN) { - $this->readpassword = $readpassword; - } - } - public function setinterface($interface) { if (in_array($interface, self::TABS)) { diff --git a/app/class/Session.php b/app/class/Session.php index 96a4ffd..64b6b26 100644 --- a/app/class/Session.php +++ b/app/class/Session.php @@ -78,4 +78,4 @@ class Session extends Item $this->mediadisplay = $mediadisplay; } } -}
\ No newline at end of file +} diff --git a/app/class/User.php b/app/class/User.php index 417b5f3..b2b6193 100644 --- a/app/class/User.php +++ b/app/class/User.php @@ -39,13 +39,9 @@ class User extends Item return $this->level; } - public function password($type = 'string') + public function password() { - if ($type === 'int') { - return strlen($this->password); - } elseif ($type = 'string') { - return $this->password; - } + return $this->password; } public function signature() @@ -117,12 +113,11 @@ class User extends Item public function setid($id): bool { if (is_string($id)) { - try { - $this->id = idclean($id, Model::MAX_ID_LENGTH, 1); - } catch (\Throwable $th) { - return false; + $id = idclean($id); + if (!empty($id)) { + $this->id = $id; + return true; } - return true; } return false; } |