diff options
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/art2.php | 92 | ||||
-rw-r--r-- | app/class/controlleradmin.php | 11 | ||||
-rw-r--r-- | app/class/controllerart.php | 11 | ||||
-rw-r--r-- | app/class/modelart.php | 34 | ||||
-rw-r--r-- | app/class/modelrender.php | 42 |
5 files changed, 111 insertions, 79 deletions
diff --git a/app/class/art2.php b/app/class/art2.php index 000c391..0023989 100644 --- a/app/class/art2.php +++ b/app/class/art2.php @@ -26,7 +26,9 @@ class Art2 protected $interface; protected $linkfrom; protected $linkto; - protected $template; + protected $templatebody; + protected $templatecss; + protected $templatejavascript; protected $affcount; protected $editcount; @@ -90,7 +92,9 @@ class Art2 $this->setinterface('section'); $this->setlinkfrom([]); $this->setlinkto([]); - $this->settemplate([]); + $this->settemplatebody(''); + $this->settemplatecss(''); + $this->settemplatejavascript(''); $this->setaffcount(0); $this->seteditcount(0); } @@ -217,25 +221,6 @@ class Art2 } } - - public function csstemplate(App $app) - { - $data = []; - $temp = ''; - if (!empty($this->template())) { - if ($app->exist($this->template()) and !in_array($this->template(), $data)) { - $template = $app->get($this->template()); - $temp = $temp . $template->css($app); - $data[] = $template->id(); - - } - - } - $cssprint = str_replace('url(/', 'url(' . $app::MEDIA_DIR, $temp . $this->css); - return $cssprint; - } - - public function javascript($type = 'string') { return $this->javascript; @@ -251,16 +236,6 @@ class Art2 return $this->header; } - public function md($expand = false) - { - if ($expand == true) { - $md = str_replace('](=', '](?id=', $this->section); - } else { - $md = $this->section; - } - return $md; - } - public function section($type = 'string') { return $this->section; @@ -345,13 +320,27 @@ class Art2 } - public function template($type = 'array') + public function templatebody($type = 'string') { - if ($type == 'json') { - return json_encode($this->template); - } elseif ($type = 'array') { - return $this->template; - } + return $this->templatebody; + } + + public function templatecss($type = 'string') + { + return $this->templatecss; + } + + public function templatejavascript($type = 'string') + { + return $this->templatejavascript; + } + + function template() + { + $template['body'] = $this->templatebody; + $template['css'] = $this->templatecss; + $template['javascript'] = $this->templatejavascript; + return $template; } public function affcount($type = 'int') @@ -573,24 +562,25 @@ class Art2 } } - public function settemplate($template) + public function settemplatebody($templatebody) { - if (is_string($template)) { - $templatearray = json_decode($template, true); + if(is_string($templatebody)) { + $this->templatebody = $templatebody; } - if (is_array($template)) { - $templatearray = $template; + } + + public function settemplatecss($templatecss) + { + if(is_string($templatecss)) { + $this->templatecss = $templatecss; } - if(is_object($template)) { - $templatearray = (array) $template; + } + + public function settemplatejavascript($templatejavascript) + { + if(is_string($templatejavascript)) { + $this->templatejavascript = $templatejavascript; } - $this->template = array_map(function ($value) { - if(empty($value)) { - return null; - } else { - return $value; - } - }, $templatearray); } public function setaffcount($affcount) diff --git a/app/class/controlleradmin.php b/app/class/controlleradmin.php index 0829916..86d6db1 100644 --- a/app/class/controlleradmin.php +++ b/app/class/controlleradmin.php @@ -15,7 +15,10 @@ class Controlleradmin extends Controller } else { $defaultartexist = true; } - $admin = ['artlist' => $artlist, 'defaultartexist' => $defaultartexist]; + + $globalcss = file_get_contents(Model::GLOBAL_DIR . 'global.css'); + + $admin = ['artlist' => $artlist, 'defaultartexist' => $defaultartexist, 'globalcss' => $globalcss]; $this->showtemplate('admin', $admin); } } @@ -25,11 +28,13 @@ class Controlleradmin extends Controller if(!isset($_POST['showeditmenu'])) { $_POST['showeditmenu'] = false; } + $globalcss = file_put_contents(Model::GLOBAL_DIR . 'global.css', $_POST['globalcss']); + Config::hydrate($_POST); - if(Config::savejson() !== false) { + if(Config::savejson() !== false && $globalcss !== false) { $this->routedirect('admin'); } else { - echo 'Can\'t write config file'; + echo 'Can\'t write config file or global css file'; } } diff --git a/app/class/controllerart.php b/app/class/controllerart.php index 0dee8e7..f64cda8 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -116,9 +116,14 @@ class Controllerart extends Controller if ($this->importart() && $this->canedit()) { - $tablist = ['section' => $this->art->md(), '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()]; + $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()]; - $artlist = $this->artmanager->list(); + $idlist = $this->artmanager->list(); + + + $artlist = $this->artmanager->getlister(); + $tagartlist = $this->artmanager->tagartlist($this->art->tag('array'), $artlist); + $lasteditedartlist = $this->artmanager->lasteditedartlist(5, $artlist); if (isset($_SESSION['workspace'])) { $showleftpanel = $_SESSION['workspace']['showleftpanel']; @@ -129,7 +134,7 @@ class Controllerart extends Controller } $fonts = []; - $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts]); + $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true, 'tablist' => $tablist, 'artlist' => $idlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts, 'tagartlist' => $tagartlist, 'lasteditedartlist' => $lasteditedartlist]); } else { $this->routedirect('artread/', ['art' => $this->art->id()]); } diff --git a/app/class/modelart.php b/app/class/modelart.php index e9f6ec3..54a6613 100644 --- a/app/class/modelart.php +++ b/app/class/modelart.php @@ -107,9 +107,12 @@ class Modelart extends Modeldb } - - - + /** + * @param array $artlist List of Art2 + * @param array $tagchecked list of tags + * @param string $tagcompare string, can be 'OR' or 'AND', set the tag filter method + * @return array $array + */ public function filtertagfilter(array $artlist, array $tagchecked, $tagcompare = 'OR') { @@ -168,9 +171,30 @@ class Modelart extends Modeldb return $taglist; } - public function count() + /** + * @param array $taglist list of tags + * @param array $artlist list of Art2 + * @return array list of tags each containing list of id + */ + + public function tagartlist(array $taglist, array $artlist) { - return $this->bdd->query(' SELECT COUNT(*) FROM ' . $this->arttable . ' ')->fetchColumn(); + $tagartlist = []; + foreach ($taglist as $tag) { + $tagartlist[$tag] = $this->filtertagfilter($artlist, [$tag]); + } + return $tagartlist; + } + + public function lasteditedartlist(int $last , array $artlist) + { + $this->artlistsort($artlist, 'datemodif', -1); + $artlist = array_slice($artlist, 0, $last); + $idlist = []; + foreach ($artlist as $art) { + $idlist[] = $art->id(); + } + return $idlist; } } diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 43e40a9..484fae3 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -9,6 +9,7 @@ class Modelrender extends Modelart protected $sum = []; const SUMMARY = '%SUMMARY%'; + const REMPLACE_SELF_ELEMENT = false; public function __construct($router) @@ -45,10 +46,17 @@ class Modelrender extends Modelart public function readbody() { - if (isset($this->art->template('array')['body'])) { - $templateid = $this->art->template('array')['body']; - $tempalteart = $this->get($templateid); - $body = $tempalteart->body() . PHP_EOL . $this->art->body(); + if (!empty($this->art->templatebody())) { + $templateid = $this->art->templatebody(); + $templateart = $this->get($templateid); + if(self::REMPLACE_SELF_ELEMENT) { + $templatebody = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)!\%~', function ($match) use ($templateid) { + return '%'. $match[1] . '.' . $templateid . '%'; + }, $templateart->body()); + } else { + $templatebody = $templateart->body(); + } + $body = $templatebody . PHP_EOL . $this->art->body(); } else { $body = $this->art->body(); } @@ -58,11 +66,11 @@ class Modelrender extends Modelart public function getbody(string $body) { $rend = $this; - $body = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)(:(((\.|)?([\w-_]+|\!))*))?\%~', function ($match) use ($rend) { + $body = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)((\.([a-z0-9-_]+|!))*|!)?\%~', function ($match) use ($rend) { $element = strtolower($match[1]); $getelement = ''; - if (isset($match[3]) && !empty($match[3])) { - $templatelist = str_replace('!', $this->art->id(), explode('.', $match[3])); + if (isset($match[2]) && !empty($match[2])) { + $templatelist = str_replace('!', $this->art->id(), explode('.', ltrim($match[2], '.'))); foreach ($templatelist as $template) { if ($template === $rend->art->id()) { $templateelement = $rend->art->$element(); @@ -96,7 +104,7 @@ class Modelrender extends Modelart public function write() { file_put_contents(Model::RENDER_DIR . $this->art->id() . '.css', $this->art->css()); - file_put_contents(Model::RENDER_DIR . $this->art->id() . '.quick.css', $this->art->quickcss()); + //file_put_contents(Model::RENDER_DIR . $this->art->id() . '.quick.css', $this->art->quickcss()); file_put_contents(Model::RENDER_DIR . $this->art->id() . '.js', $this->art->javascript()); } @@ -133,20 +141,20 @@ class Modelrender extends Modelart $head .= '<link href="' . Model::globalpath() . 'fonts.css" rel="stylesheet" />' . PHP_EOL; $head .= '<link href="' . Model::globalpath() . 'global.css" rel="stylesheet" />' . PHP_EOL; - if (isset($this->art->template('array')['quickcss'])) { - $tempaltequickcssart = $this->art->template('array')['quickcss']; - $head .= '<link href="' . Model::renderpath() . $tempaltequickcssart . '.quick.css" rel="stylesheet" />' . PHP_EOL; - } - $head .= '<link href="' . Model::renderpath() . $this->art->id() . '.quick.css" rel="stylesheet" />' . PHP_EOL; + // if (!empty($this->art->templatecss())) { + // $tempaltequickcssart = $this->art->templatecss(); + // $head .= '<link href="' . Model::renderpath() . $tempaltequickcssart . '.quick.css" rel="stylesheet" />' . PHP_EOL; + // } + // $head .= '<link href="' . Model::renderpath() . $this->art->id() . '.quick.css" rel="stylesheet" />' . PHP_EOL; - if (isset($this->art->template('array')['css'])) { - $tempaltecssart = $this->art->template('array')['css']; + if (!empty($this->art->templatecss())) { + $tempaltecssart = $this->art->templatecss(); $head .= '<link href="' . Model::renderpath() . $tempaltecssart . '.css" rel="stylesheet" />' . PHP_EOL; } $head .= '<link href="' . Model::renderpath() . $this->art->id() . '.css" rel="stylesheet" />' . PHP_EOL; - if (isset($this->art->template('array')['javascript'])) { - $templatejsart = $this->art->template('array')['javascript']; + if (!empty($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; |