diff options
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/art2.php | 75 | ||||
-rw-r--r-- | app/class/config.php | 13 | ||||
-rw-r--r-- | app/class/controlleradmin.php | 5 | ||||
-rw-r--r-- | app/class/controllerart.php | 5 | ||||
-rw-r--r-- | app/class/model.php | 40 | ||||
-rw-r--r-- | app/class/modelart.php | 17 | ||||
-rw-r--r-- | app/class/modelmedia.php | 14 | ||||
-rw-r--r-- | app/class/modelrender.php | 7 |
8 files changed, 129 insertions, 47 deletions
diff --git a/app/class/art2.php b/app/class/art2.php index 0023989..6a61687 100644 --- a/app/class/art2.php +++ b/app/class/art2.php @@ -29,6 +29,8 @@ class Art2 protected $templatebody; protected $templatecss; protected $templatejavascript; + protected $templateoptions; + protected $favicon; protected $affcount; protected $editcount; @@ -95,6 +97,8 @@ class Art2 $this->settemplatebody(''); $this->settemplatecss(''); $this->settemplatejavascript(''); + $this->settemplateoptions(['externalcss', 'externaljavascript', 'favicon', 'reccursive', 'quickcss']); + $this->setfavicon(''); $this->setaffcount(0); $this->seteditcount(0); } @@ -114,7 +118,7 @@ class Art2 { $array = []; foreach (get_class_vars(__class__) as $var => $value) { - if(in_array($var, self::VAR_DATE)) { + if (in_array($var, self::VAR_DATE)) { $array[$var] = $this->$var('string'); } else { $array[$var] = $this->$var(); @@ -258,14 +262,14 @@ class Art2 public function renderhead($type = 'string') { - if($type == 'string') { + if ($type == 'string') { return $this->renderhead; } } public function renderbody($type = 'string') { - if($type == 'string') { + if ($type == 'string') { return $this->renderbody; } } @@ -335,14 +339,41 @@ class Art2 return $this->templatejavascript; } - function template() + public function template() { $template['body'] = $this->templatebody; $template['css'] = $this->templatecss; $template['javascript'] = $this->templatejavascript; + + $template['cssreccursive'] = $this->checkoption('reccursive'); + $template['cssquickcss'] = $this->checkoption('quickcss'); + $template['externalcss'] = $this->checkoption('externalcss'); + $template['cssfavicon'] = $this->checkoption('favicon'); + + $template['externaljavascript'] = $this->checkoption('externaljavascript'); + return $template; } + public function templateoptions($type = 'array') + { + return $this->templateoptions; + } + + function checkoption($option) + { + if (in_array('reccursive', $this->templateoptions)) { + return true; + } else { + return false; + } + } + + public function favicon($type = 'string') + { + return $this->favicon; + } + public function affcount($type = 'int') { return $this->affcount; @@ -536,11 +567,11 @@ class Art2 public function setlinkfrom($linkfrom) { - if(is_array($linkfrom)) { + if (is_array($linkfrom)) { $this->linkfrom = $linkfrom; - } elseif(is_string($linkfrom)) { + } elseif (is_string($linkfrom)) { $linkfromjson = json_decode($linkfrom); - if(is_array($linkfromjson)) { + if (is_array($linkfromjson)) { $this->linkfrom = $linkfromjson; } } elseif ($linkfrom === null) { @@ -550,11 +581,11 @@ class Art2 public function setlinkto($linkto) { - if(is_array($linkto)) { + if (is_array($linkto)) { $this->linkto = $linkto; - } elseif(is_string($linkto)) { + } elseif (is_string($linkto)) { $linktojson = json_decode($linkto); - if(is_array($linktojson)) { + if (is_array($linktojson)) { $this->linkto = $linktojson; } } elseif ($linkto === null) { @@ -564,25 +595,39 @@ class Art2 public function settemplatebody($templatebody) { - if(is_string($templatebody)) { + if (is_string($templatebody)) { $this->templatebody = $templatebody; } } public function settemplatecss($templatecss) { - if(is_string($templatecss)) { + if (is_string($templatecss)) { $this->templatecss = $templatecss; } } public function settemplatejavascript($templatejavascript) { - if(is_string($templatejavascript)) { + if (is_string($templatejavascript)) { $this->templatejavascript = $templatejavascript; } } + public function settemplateoptions($templateoptions) + { + if(is_array($templateoptions)) { + $this->templateoptions = $templateoptions; + } + } + + public function setfavicon($favicon) + { + if (is_string($favicon)) { + $this->favicon = $favicon; + } + } + public function setaffcount($affcount) { if (is_int($affcount)) { @@ -607,12 +652,12 @@ class Art2 public function addeditcount() { - $this->editcount ++; + $this->editcount++; } public function addaffcount() { - $this->affcount ++; + $this->affcount++; } public function updateedited() diff --git a/app/class/config.php b/app/class/config.php index d6904df..7d2320e 100644 --- a/app/class/config.php +++ b/app/class/config.php @@ -17,6 +17,7 @@ abstract class Config protected static $existnot = 'This page does not exist yet'; protected static $defaultbody = '%HEADER%'. PHP_EOL .PHP_EOL . '%NAV%'. PHP_EOL .PHP_EOL . '%ASIDE%'. PHP_EOL .PHP_EOL . '%SECTION%'. PHP_EOL .PHP_EOL . '%FOOTER%'; protected static $defaultart = ''; + protected static $defaultfavicon = ''; protected static $showeditmenu = true; protected static $editsymbol = 'pen'; @@ -141,6 +142,11 @@ abstract class Config return self::$defaultart; } + public static function defaultfavicon() + { + return self::$defaultfavicon; + } + public static function showeditmenu() { return self::$showeditmenu; @@ -228,6 +234,13 @@ abstract class Config } } + public static function setdefaultfavicon($defaultfavicon) + { + if(is_string($defaultfavicon)) { + self::$defaultfavicon = $defaultfavicon; + } + } + public static function setdefaultart($defaultart) { if(is_string($defaultart)) { diff --git a/app/class/controlleradmin.php b/app/class/controlleradmin.php index 86d6db1..fd33158 100644 --- a/app/class/controlleradmin.php +++ b/app/class/controlleradmin.php @@ -4,12 +4,15 @@ class Controlleradmin extends Controller { protected $artmanager; + protected $mediamanager; public function desktop() { if($this->user->isadmin()) { $this->artmanager = new Modelart(); $artlist = $this->artmanager->list(); + $this->mediamanager = new Modelmedia(); + $faviconlist = $this->mediamanager->listfavicon(); if(in_array(Config::defaultart(), $artlist)) { $defaultartexist = true; } else { @@ -18,7 +21,7 @@ class Controlleradmin extends Controller $globalcss = file_get_contents(Model::GLOBAL_DIR . 'global.css'); - $admin = ['artlist' => $artlist, 'defaultartexist' => $defaultartexist, 'globalcss' => $globalcss]; + $admin = ['artlist' => $artlist, 'defaultartexist' => $defaultartexist, 'globalcss' => $globalcss, 'faviconlist' => $faviconlist]; $this->showtemplate('admin', $admin); } } diff --git a/app/class/controllerart.php b/app/class/controllerart.php index be82e6f..3ada9d1 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -7,6 +7,7 @@ class Controllerart extends Controller protected $artmanager; protected $renderengine; protected $fontmanager; + protected $mediamanager; public function __construct($router) { @@ -14,6 +15,7 @@ class Controllerart extends Controller $this->artmanager = new Modelart(); $this->fontmanager = new Modelfont(); + $this->mediamanager = new Modelmedia(); } @@ -118,6 +120,7 @@ class Controllerart extends Controller if ($this->importart() && $this->canedit()) { $tablist = ['section' => $this->art->section(), 'css' => $this->art->css(), 'header' => $this->art->header(), 'nav' => $this->art->nav(), 'aside' => $this->art->aside(), 'footer' => $this->art->footer(), 'body' => $this->art->body(), 'javascript' => $this->art->javascript()]; + $faviconlist = $this->mediamanager->listfavicon(); $idlist = $this->artmanager->list(); @@ -134,7 +137,7 @@ class Controllerart extends Controller } $fonts = []; - $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true, 'tablist' => $tablist, 'artlist' => $idlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts, 'tagartlist' => $tagartlist, 'lasteditedartlist' => $lasteditedartlist]); + $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true, 'tablist' => $tablist, 'artlist' => $idlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts, 'tagartlist' => $tagartlist, 'lasteditedartlist' => $lasteditedartlist, 'faviconlist' => $faviconlist]); } else { $this->routedirect('artread/', ['art' => $this->art->id()]); } diff --git a/app/class/model.php b/app/class/model.php index 4024f62..78abbfa 100644 --- a/app/class/model.php +++ b/app/class/model.php @@ -6,6 +6,7 @@ abstract class Model const CSS_DIR = 'assets' . DIRECTORY_SEPARATOR .'css' . DIRECTORY_SEPARATOR; const FONT_DIR = 'fonts' . DIRECTORY_SEPARATOR; const MEDIA_DIR = 'media' . DIRECTORY_SEPARATOR; + const FAVICON_DIR = 'media' . DIRECTORY_SEPARATOR . 'favicon' . 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 GLOBAL_DIR = 'assets'. DIRECTORY_SEPARATOR . 'global' . DIRECTORY_SEPARATOR; @@ -16,49 +17,44 @@ abstract class Model const TEXT_ELEMENTS = ['header', 'nav', 'section', 'aside', 'footer']; const EDIT_SYMBOLS = ['pen', 'tool', 'none']; - public static function renderpath() + public static function dirtopath($dir) { $basepath = ''; if(!empty(Config::basepath())) { $basepath = Config::basepath() . '/' ; } - return '/' . $basepath . Model::RENDER_DIR; + $dir = str_replace('\\', '/', $dir); + return '/' . $basepath . $dir; + } + + public static function renderpath() + { + return self::dirtopath(Model::RENDER_DIR); } public static function globalpath() { - $basepath = ''; - if(!empty(Config::basepath())) { - $basepath = Config::basepath() . '/' ; - } - return '/' . $basepath . Model::GLOBAL_DIR; + return self::dirtopath(Model::GLOBAL_DIR); } public static function csspath() { - $basepath = ''; - if(!empty(Config::basepath())) { - $basepath = Config::basepath() . '/' ; - } - return '/' . $basepath . Model::CSS_DIR; + return self::dirtopath(Model::CSS_DIR); } public static function mediapath() { - $basepath = ''; - if(!empty(Config::basepath())) { - $basepath = Config::basepath() . '/' ; - } - return '/' . $basepath . Model::MEDIA_DIR; + return self::dirtopath(Model::MEDIA_DIR); + } + + public static function faviconpath() + { + return self::dirtopath(Model::FAVICON_DIR); } public static function fontpath() { - $basepath = ''; - if(!empty(Config::basepath())) { - $basepath = Config::basepath() . '/' ; - } - return '/' . $basepath . str_replace('\\', '/',Model::FONT_DIR); + return self::dirtopath(Model::FONT_DIR); } } diff --git a/app/class/modelart.php b/app/class/modelart.php index 54a6613..03163e3 100644 --- a/app/class/modelart.php +++ b/app/class/modelart.php @@ -54,9 +54,9 @@ class Modelart extends Modeldb public function getartelement($id, $element) { - if(in_array($element, Model::TEXT_ELEMENTS)) { + if (in_array($element, Model::TEXT_ELEMENTS)) { $art = $this->get($id); - if($art !== false) { + if ($art !== false) { return $art->$element(); } else { return ''; @@ -73,9 +73,12 @@ class Modelart extends Modeldb public function unlink(string $artid) { - unlink(Model::RENDER_DIR . $artid . '.css'); - unlink(Model::RENDER_DIR . $artid . '.quick.css'); - unlink(Model::RENDER_DIR . $artid . '.js'); + $files = ['.css', '.quick.css', '.js']; + foreach ($files as $file) { + if (file_exists(Model::RENDER_DIR . $artid . $file)) { + unlink(Model::RENDER_DIR . $artid . $file); + } + } } public function update(Art2 $art) @@ -176,7 +179,7 @@ class Modelart extends Modeldb * @param array $artlist list of Art2 * @return array list of tags each containing list of id */ - + public function tagartlist(array $taglist, array $artlist) { $tagartlist = []; @@ -186,7 +189,7 @@ class Modelart extends Modeldb return $tagartlist; } - public function lasteditedartlist(int $last , array $artlist) + public function lasteditedartlist(int $last, array $artlist) { $this->artlistsort($artlist, 'datemodif', -1); $artlist = array_slice($artlist, 0, $last); diff --git a/app/class/modelmedia.php b/app/class/modelmedia.php index 14a1c4e..a5c48fe 100644 --- a/app/class/modelmedia.php +++ b/app/class/modelmedia.php @@ -86,6 +86,20 @@ class Modelmedia extends Model + public function listfavicon() + { + $glob = Model::FAVICON_DIR . '*.png'; + $faviconlist = glob($glob); + $count = strlen(Model::FAVICON_DIR); + $faviconlist = array_map(function($input) use($count) { + return substr($input, $count); + }, $faviconlist); + return $faviconlist; + + } + + + } diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 484fae3..d2cdbb4 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -136,6 +136,11 @@ class Modelrender extends Modelart $head .= '<meta charset="utf8" />' . PHP_EOL; $head .= '<title>' . $this->art->title() . '</title>' . PHP_EOL; + if(!empty($this->art->favicon())) { + $head .= '<link rel="shortcut icon" href="'.Model::faviconpath(). $this->art->favicon(). '" type="image/x-icon">'; + } elseif(!empty(Config::defaultfavicon())) { + $head .= '<link rel="shortcut icon" href="'.Model::faviconpath(). Config::defaultfavicon(). '" type="image/x-icon">'; + } $head .= '<meta name="description" content="' . $this->art->description() . '" />' . PHP_EOL; $head .= '<meta name="viewport" content="width=device-width" />' . PHP_EOL; $head .= '<link href="' . Model::globalpath() . 'fonts.css" rel="stylesheet" />' . PHP_EOL; @@ -154,7 +159,7 @@ class Modelrender extends Modelart $head .= '<link href="' . Model::renderpath() . $this->art->id() . '.css" rel="stylesheet" />' . PHP_EOL; if (!empty($this->art->templatejavascript())) { - $templatejsart = $this->art->templatejavascript; + $templatejsart = $this->art->templatejavascript(); $head .= '<script src="' . Model::renderpath() . $templatejsart . '.js" async/></script>' . PHP_EOL; } $head .= '<script src="' . Model::renderpath() . $this->art->id() . '.js" async/></script>' . PHP_EOL; |