From c832f91ca41490f69f478045c86038f9ef4a5cb5 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 27 Apr 2020 10:56:24 +0200 Subject: move fonts into media move global css into media --- .gitignore | 1 - app/class/Colors.php | 2 +- app/class/Config.php | 2 +- app/class/Controller.php | 2 +- app/class/Controlleradmin.php | 2 +- app/class/Controllerfont.php | 2 +- app/class/Controllermedia.php | 18 +++++++------- app/class/Model.php | 38 ++++++++++------------------- app/class/Modelmedia.php | 2 +- app/class/Modelpage.php | 2 +- app/fn/fn.php | 56 ++++++++++++++++++++++++++++++++----------- app/view/templates/layout.php | 2 +- fonts/README.md | 2 -- 13 files changed, 72 insertions(+), 59 deletions(-) delete mode 100644 fonts/README.md diff --git a/.gitignore b/.gitignore index 98ddd57..466b752 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ assets/render/* assets/global/* assets/css/tagcolors.css database/* -fonts/* media/* render/ build/ diff --git a/app/class/Colors.php b/app/class/Colors.php index bdea98e..731fbac 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::ASSETS_CSS_DIR . 'tagcolors.css'; protected $rawcss = ""; diff --git a/app/class/Config.php b/app/class/Config.php index 45ba86f..c982827 100644 --- a/app/class/Config.php +++ b/app/class/Config.php @@ -435,7 +435,7 @@ abstract class Config public static function setinterfacecss($interfacecss) { - if (is_string($interfacecss) && file_exists(Model::CSS_DIR . $interfacecss)) { + if (is_string($interfacecss) && file_exists(Model::ASSETS_CSS_DIR . $interfacecss)) { self::$interfacecss = $interfacecss; } else { self::$interfacecss = null; diff --git a/app/class/Controller.php b/app/class/Controller.php index 46c9ee0..7bfa3a2 100644 --- a/app/class/Controller.php +++ b/app/class/Controller.php @@ -67,7 +67,7 @@ class Controller $commonsparams['router'] = $this->router; $commonsparams['user'] = $this->user; $commonsparams['pagelist'] = $this->pagemanager->list(); - $commonsparams['css'] = Model::csspath(); + $commonsparams['css'] = Model::assetscsspath(); $commonsparams['now'] = new DateTimeImmutable(); return $commonsparams; } diff --git a/app/class/Controlleradmin.php b/app/class/Controlleradmin.php index ec437fa..d87427b 100644 --- a/app/class/Controlleradmin.php +++ b/app/class/Controlleradmin.php @@ -45,7 +45,7 @@ class Controlleradmin extends Controller public function update() { - accessfile(Model::GLOBAL_CSS_FILE); + accessfile(Model::GLOBAL_CSS_FILE, true); $globalcss = file_put_contents(Model::GLOBAL_CSS_FILE, $_POST['globalcss']); diff --git a/app/class/Controllerfont.php b/app/class/Controllerfont.php index 7df1a2f..eb8caa2 100644 --- a/app/class/Controllerfont.php +++ b/app/class/Controllerfont.php @@ -18,7 +18,7 @@ class Controllerfont extends Controller public function desktop() { if ($this->user->iseditor()) { - Model::dircheck(Model::FONT_DIR); + dircheck(Model::FONT_DIR); $fontlist = $this->fontmanager->getfontlist(); diff --git a/app/class/Controllermedia.php b/app/class/Controllermedia.php index 95b4f9b..6a585eb 100644 --- a/app/class/Controllermedia.php +++ b/app/class/Controllermedia.php @@ -2,7 +2,8 @@ namespace Wcms; -use Exception; +use \Exception; +use \LogicException; class Controllermedia extends Controller { @@ -24,14 +25,13 @@ class Controllermedia extends Controller public function desktop() { if ($this->user->iseditor()) { - if (!$this->mediamanager->dircheck(Model::MEDIA_DIR)) { - throw new Exception("Media error : Cant create /media folder"); - } - if (!$this->mediamanager->dircheck(Model::FAVICON_DIR)) { - throw new Exception("Media error : Cant create /media/favicon folder"); - } - if (!$this->mediamanager->dircheck(Model::THUMBNAIL_DIR)) { - throw new Exception("Media error : Cant create /media/thumbnail folder"); + try { + dircheck(Model::FONT_DIR); + dircheck(Model::THUMBNAIL_DIR); + dircheck(Model::FAVICON_DIR); + dircheck(Model::CSS_DIR); + } catch (\InvalidArgumentException $exception) { + throw new LogicException($exception->getMessage()); } $mediaopt = new Medialist($_GET); diff --git a/app/class/Model.php b/app/class/Model.php index 7e891f1..60983bc 100644 --- a/app/class/Model.php +++ b/app/class/Model.php @@ -7,19 +7,19 @@ abstract class Model public const CONFIG_FILE = 'config.json'; public const MAN_FILE = 'MANUAL.md'; - public const CSS_DIR = 'assets/css/'; - public const COLORS_FILE = self::CSS_DIR . 'tagcolors.css'; + public const ASSETS_CSS_DIR = 'assets/css/'; + public const COLORS_FILE = self::ASSETS_CSS_DIR . 'tagcolors.css'; public const JS_DIR = 'assets/js/'; public const ICONS_DIR = 'assets/icons/'; - public const FONT_DIR = 'fonts/'; public const MEDIA_DIR = 'media/'; public const FAVICON_DIR = self::MEDIA_DIR . 'favicon/'; public const THUMBNAIL_DIR = self::MEDIA_DIR . 'thumbnail/'; + public const FONT_DIR = self::MEDIA_DIR . 'fonts/'; + public const CSS_DIR = self::MEDIA_DIR . 'css/'; public const TEMPLATES_DIR = './app/view/templates/'; public const RENDER_DIR = 'assets/render/'; public const HTML_RENDER_DIR = 'render/'; - public const GLOBAL_DIR = 'assets/global/'; - public const GLOBAL_CSS_FILE = self::GLOBAL_DIR . 'global.css'; + public const GLOBAL_CSS_FILE = self::CSS_DIR . 'global.css'; public const DATABASE_DIR = './database/'; public const PAGES_DIR = self::DATABASE_DIR . 'pages/'; @@ -81,9 +81,9 @@ abstract class Model ]; public const BOOKMARK_ICONS = [ - '🌘', '☂️', '⭐️', '✈️', '🚲', '💡', '💾', '💿', '💎', '🎞', ' ⚒', '💊', '📜', '📌', '🔍', '📦', '🔒', - '📒', '🔓', '🌡', '☎️', '🖤', '✝️', '☢️', '✅', '🌐', '🌍', '✳️', '🏴', '😎', '👻', '💩', '👍', '⚡️', '🍸', - '🍴', '⚽️', '🏭', '🚀', '⚓️' + '⭐️', '🖤', '🏴', '👍', '📌', '💡', '🌘', '☂️', '✈️', '🚲', '💾', '💿', '💎', '🎞', ' ⚒', '💊', '📜', + '📒', '🔓', '🌡', '☎️', '✝️', '☢️', '✅', '🌐', '🌍', '✳️', '🏴', '😎', '👻', '💩', '⚡️', '🍸', '🔍', '📦', + '🍴', '⚽️', '🏭', '🚀', '⚓️', '🔒' ]; public const LIST_STYLES = [ @@ -158,6 +158,11 @@ abstract class Model return self::dirtopath(Model::CSS_DIR); } + public static function assetscsspath() + { + return self::dirtopath(Model::ASSETS_CSS_DIR); + } + public static function jspath() { return self::dirtopath(Model::JS_DIR); @@ -188,23 +193,6 @@ abstract class Model return self::dirtopath(Model::ICONS_DIR); } - /** - * Check if dir exist. If not, create it - * - * @param string $dir Directory to check - * @return bool return true if the dir already exist or was created succesfullt. Otherwise return false - * @throws \InvalidArgumentException If folder creation is impossible - */ - public static function dircheck(string $dir): bool - { - if (!is_dir($dir)) { - if (!mkdir($dir)) { - throw new \InvalidArgumentException("Cannot create directory : $dir"); - } - } - return true; - } - /** * */ diff --git a/app/class/Modelmedia.php b/app/class/Modelmedia.php index bd0ff03..2894783 100644 --- a/app/class/Modelmedia.php +++ b/app/class/Modelmedia.php @@ -117,7 +117,7 @@ class Modelmedia extends Model public function listinterfacecss() { - $listinterfacecss = $this->globlist(self::CSS_DIR, ['css']); + $listinterfacecss = $this->globlist(self::ASSETS_CSS_DIR, ['css']); $listinterfacecss = array_diff($listinterfacecss, ['edit.css', 'home.css', 'tagcolors.css']); return $listinterfacecss; } diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 5968248..834ba01 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -17,7 +17,7 @@ class Modelpage extends Modeldb { $this->dbinit(Model::PAGES_DIR); $this->storeinit(Config::pagetable()); - $this->dircheck(Model::HTML_RENDER_DIR); + dircheck($this::HTML_RENDER_DIR); } /** diff --git a/app/fn/fn.php b/app/fn/fn.php index 4ad0c6b..f20c8c6 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -377,28 +377,56 @@ function secrethash(string $token): string /** - * Check if a file is accessible or can be writen - * @param string $path file path to check - * @param bool $createdir create directory if does not exist - * @throws \InvalidArgumentException if : - * parent directory does not exist | is not writable | file exist and not writable + * Check if dir exist. If not, create it + * + * @param string $dir Directory to check + * @param bool $createdir create dir in case of non existence default is true + * @return bool return true if the dir already exist or was created succesfullt. Otherwise return false + * @throws \InvalidArgumentException If folder creation is impossible or if directory doeas not exist */ -function accessfile(string $path, bool $createdir = false) +function dircheck(string $dir, bool $createdir = true): bool { - $dir = dirname($path); if (!is_dir($dir)) { if ($createdir) { - if (!mkdir($dir)) { - throw new \InvalidArgumentException("Cannot create directory : $dir"); + $parent = dirname($dir); + if (dircheck($parent)) { + if (mkdir($dir)) { + return true; + } else { + throw new \InvalidArgumentException("Cannot create directory : $dir"); + } + } else { + return false; } } else { throw new \InvalidArgumentException("Directory '$dir' does not exist."); } + } else { + return true; } - if (!is_writable($dir)) { - throw new \InvalidArgumentException("Directory '$dir' is not writable."); - } - if (is_file($path) && !is_writable($path)) { - throw new \InvalidArgumentException("The file '$path' is not writable."); +} + + +/** + * Check if a file is accessible or can be writen + * @param string $path file path to check + * @param bool $createdir create directory if does not exist + * @return bool If no error occured + * @throws \InvalidArgumentException if : + * parent directory does not exist | is not writable | file exist and not writable + */ +function accessfile(string $path, bool $createdir = false): bool +{ + $dir = dirname($path); + if (dircheck($dir, $createdir)) { + if (!is_writable($dir)) { + throw new \InvalidArgumentException("Directory '$dir' is not writable."); + } + if (is_file($path) && !is_writable($path)) { + throw new \InvalidArgumentException("The file '$path' is not writable."); + } + return true; + } else { + return false; } } diff --git a/app/view/templates/layout.php b/app/view/templates/layout.php index 7b8ef13..c9dae0d 100644 --- a/app/view/templates/layout.php +++ b/app/view/templates/layout.php @@ -19,7 +19,7 @@ '; + echo ''; } if (isreportingerrors()) { ?> diff --git a/fonts/README.md b/fonts/README.md deleted file mode 100644 index cdfc91d..0000000 --- a/fonts/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Font directory - -- cgit v1.2.3