aboutsummaryrefslogtreecommitdiff
path: root/app/class/Model.php
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2019-11-04 23:31:31 +0100
committern-peugnet <n.peugnet@free.fr>2019-11-05 19:06:40 +0100
commite802d5204b96d645ec3d40b81b4a8bdc6e0ee675 (patch)
tree8e6db5e36ad8f247b442583e1e9e5da2934f4b52 /app/class/Model.php
parentf1f63f556c41c99d45cd610186b0982383eff375 (diff)
downloadwcms-e802d5204b96d645ec3d40b81b4a8bdc6e0ee675.tar.gz
wcms-e802d5204b96d645ec3d40b81b4a8bdc6e0ee675.zip
refactor: switch to psr-4 autoloading
Diffstat (limited to 'app/class/Model.php')
-rw-r--r--app/class/Model.php115
1 files changed, 115 insertions, 0 deletions
diff --git a/app/class/Model.php b/app/class/Model.php
new file mode 100644
index 0000000..81ad626
--- /dev/null
+++ b/app/class/Model.php
@@ -0,0 +1,115 @@
+<?php
+
+namespace Wcms;
+
+abstract class Model
+{
+
+ const CONFIG_FILE = 'config.json';
+ const CSS_DIR = 'assets' . DIRECTORY_SEPARATOR .'css' . DIRECTORY_SEPARATOR;
+ const JS_DIR = 'assets' . DIRECTORY_SEPARATOR .'js' . DIRECTORY_SEPARATOR;
+ const ICONS_DIR = 'assets' . DIRECTORY_SEPARATOR .'icons' . DIRECTORY_SEPARATOR;
+ const FONT_DIR = 'fonts' . DIRECTORY_SEPARATOR;
+ const MEDIA_DIR = 'media' . DIRECTORY_SEPARATOR;
+ const FAVICON_DIR = 'media' . DIRECTORY_SEPARATOR . 'favicon' . DIRECTORY_SEPARATOR;
+ const THUMBNAIL_DIR = 'media' . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR;
+ const TEMPLATES_DIR = '.'. DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
+ const RENDER_DIR = 'assets'. DIRECTORY_SEPARATOR . 'render' . DIRECTORY_SEPARATOR;
+ const HTML_RENDER_DIR = 'render' . DIRECTORY_SEPARATOR;
+ const GLOBAL_DIR = 'assets'. DIRECTORY_SEPARATOR . 'global' . DIRECTORY_SEPARATOR;
+ const DATABASE_DIR = '.' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR;
+
+ const MEDIA_EXTENSIONS = array('jpeg', 'jpg', 'JPG', 'png', 'gif', 'mp3', 'mp4', 'mov', 'wav', 'flac', 'pdf');
+ const MEDIA_TYPES = ['image', 'video', 'sound', 'other'];
+
+ const COLUMNS = ['id', 'title', 'description', 'tag', 'date', 'datemodif', 'datecreation', 'secure', 'linkfrom', 'linkto', 'visitcount', 'affcount', 'editcount'];
+
+ const TEXT_ELEMENTS = ['header', 'nav', 'main', 'aside', 'footer'];
+
+ const MAX_ID_LENGTH = 64;
+ const PASSWORD_HASH = true;
+ const PASSWORD_MIN_LENGTH = 4;
+ const PASSWORD_MAX_LENGTH = 32;
+
+ /** RENDER OPTIONS */
+ // add class in html element indicating from witch page the content come.
+ const RENDER_CLASS_ORIGIN = false;
+ // render empty CONTENT element as empty html element, if set to false, render html comment
+ const RENDER_EMPTY_ELEMENT = false;
+
+
+ /** CONFIG OPTIONS */
+ const HOMEPAGE = ['default', 'search', 'redirect'];
+
+ public static function dirtopath($dir)
+ {
+ $basepath = '';
+ if(!empty(Config::basepath())) {
+ $basepath = Config::basepath() . '/' ;
+ }
+ $dir = str_replace('\\', '/', $dir);
+ return '/' . $basepath . $dir;
+ }
+
+ public static function renderpath()
+ {
+ return self::dirtopath(Model::RENDER_DIR);
+ }
+
+ public static function globalpath()
+ {
+ return self::dirtopath(Model::GLOBAL_DIR);
+ }
+
+ public static function csspath()
+ {
+ return self::dirtopath(Model::CSS_DIR);
+ }
+
+ public static function jspath()
+ {
+ return self::dirtopath(Model::JS_DIR);
+ }
+
+ public static function mediapath()
+ {
+ return self::dirtopath(Model::MEDIA_DIR);
+ }
+
+ public static function faviconpath()
+ {
+ return self::dirtopath(Model::FAVICON_DIR);
+ }
+
+ public static function thumbnailpath()
+ {
+ return self::dirtopath(Model::THUMBNAIL_DIR);
+ }
+
+ public static function fontpath()
+ {
+ return self::dirtopath(Model::FONT_DIR);
+ }
+
+ public static function iconpath()
+ {
+ 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
+ */
+ public function dircheck(string $dir) : bool
+ {
+ if (!is_dir($dir)) {
+ return mkdir($dir);
+ } else {
+ return true;
+ }
+ }
+
+}