aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2018-12-05 02:40:16 +0100
committervincent-peugnet <v.peugnet@free.fr>2018-12-05 02:40:16 +0100
commitad3aed389f2e0d69802641f5a5b7c6add73f1ce5 (patch)
tree1e4abd614799be623a2ae696fa960d3fba93a5a6 /app
parentfc56b60be55b4340d647d2017fdeb24b81eb84b6 (diff)
downloadwcms-ad3aed389f2e0d69802641f5a5b7c6add73f1ce5.tar.gz
wcms-ad3aed389f2e0d69802641f5a5b7c6add73f1ce5.zip
templateoption
Diffstat (limited to 'app')
-rw-r--r--app/class/art2.php75
-rw-r--r--app/class/config.php13
-rw-r--r--app/class/controlleradmin.php5
-rw-r--r--app/class/controllerart.php5
-rw-r--r--app/class/model.php40
-rw-r--r--app/class/modelart.php17
-rw-r--r--app/class/modelmedia.php14
-rw-r--r--app/class/modelrender.php7
-rw-r--r--app/view/templates/admin.php12
-rw-r--r--app/view/templates/edit.php4
-rw-r--r--app/view/templates/editleftbar.php46
-rw-r--r--app/view/templates/editrightbar.php2
-rw-r--r--app/view/templates/home.php2
-rw-r--r--app/view/templates/layout.php7
14 files changed, 188 insertions, 61 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;
diff --git a/app/view/templates/admin.php b/app/view/templates/admin.php
index 7f94833..5edf262 100644
--- a/app/view/templates/admin.php
+++ b/app/view/templates/admin.php
@@ -73,6 +73,18 @@
<label for="globalcss">Edit global css that will apply to every pages</label>
<textarea name="globalcss" id="globalcss" cols="30" rows="10"><?= $globalcss ?></textarea>
+ <label for="defaultfavicon">Favicon</label>
+ <select name="defaultfavicon" id="defaultfavicon">
+ <option value="">--no favicon--</option>
+ <?php
+ foreach ($faviconlist as $favicon) {
+ ?>
+ <option value="<?= $favicon ?>" <?= Config::defaultfavicon() === $favicon ? 'selected' : '' ?>><?= $favicon ?></option>
+ <?php
+ }
+ ?>
+ </select>
+
<input type="submit" value="Update configuration">
</form>
diff --git a/app/view/templates/edit.php b/app/view/templates/edit.php
index 18940ff..973317a 100644
--- a/app/view/templates/edit.php
+++ b/app/view/templates/edit.php
@@ -1,4 +1,4 @@
-<?php $this->layout('layout', ['title' => '✏ '.$art->title(), 'css' => $css . 'edit.css']) ?>
+<?php $this->layout('layout', ['title' => '✏ '.$art->title(), 'css' => $css . 'edit.css', 'favicon' => $art->favicon()]) ?>
@@ -18,7 +18,7 @@
<div id="workspace">
- <?php $this->insert('editleftbar', ['art' => $art, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel]) ?>
+ <?php $this->insert('editleftbar', ['art' => $art, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel, 'faviconlist' => $faviconlist]) ?>
<?php $this->insert('edittabs', ['tablist' => $tablist, 'opentab' => $art->interface(), 'templates' => $art->template()]) ?>
<?php $this->insert('editrightbar', ['art' => $art, 'artlist' => $artlist, 'showrightpanel' => $showrightpanel, 'templates' => $art->template(), 'tagartlist' => $tagartlist, 'lasteditedartlist' => $lasteditedartlist]) ?>
diff --git a/app/view/templates/editleftbar.php b/app/view/templates/editleftbar.php
index 73468bf..09c13f9 100644
--- a/app/view/templates/editleftbar.php
+++ b/app/view/templates/editleftbar.php
@@ -25,9 +25,8 @@
</fieldset>
</details>
<details open>
- <summary>Advanced</summary>
+ <summary>Tempalte</summary>
<fieldset>
- <h3>Template options</h3>
<label for="templatebody">BODY template</label>
<select name="templatebody" id="templatebody">
<option value="" <?= empty($art->templatebody()) ? 'selected' : '' ?>>--no template--</option>
@@ -57,16 +56,20 @@
if(!empty($art->templatecss())) {
?>
<div class="subtemplate">
- <input type="checkbox" name="iquickcss" id="iquickcss">
+ <input type="checkbox" name="ireccursivecss" id="ireccursivecss" <?= $art->template()['cssreccursive'] === true ? 'checked' : '' ?>>
+ <label for="ireccursivecss">Reccursive template</label>
+ </div>
+ <div class="subtemplate">
+ <input type="checkbox" name="iquickcss" id="iquickcss" <?= $art->template()['cssquickcss'] === true ? 'checked' : '' ?>>
<label for="iquickcss">Quickcss</label>
</div>
<div class="subtemplate">
- <input type="checkbox" name="iexternalcss" id="iexternalcss">
+ <input type="checkbox" name="iexternalcss" id="iexternalcss" <?= $art->template()['externalcss'] === true ? 'checked' : '' ?>>
<label for="iexternalcss">External CSS</label>
</div>
<div class="subtemplate">
- <input type="checkbox" name="iicon" id="iicon">
- <label for="iicon">Page Icon</label>
+ <input type="checkbox" name="ifavicon" id="ifavicon" <?= $art->template()['cssfavicon'] === true ? 'checked' : '' ?>>
+ <label for="ifavicon">Favicon</label>
</div>
<?php
}
@@ -93,9 +96,34 @@
</fieldset>
</details>
- <details id="editcss" open>
- <summary>Quick CSS</summary>
-
+ <details id="advanced" open>
+ <summary>Advanced</summary>
+
+ <fieldset>
+
+ <?php
+
+ ?>
+
+ <label for="favicon">Favicon</label>
+ <select name="favicon" id="favicon">
+ <?php
+ if(!empty($art->templatecss()) && $art->template()['cssfavicon']) {
+ ?>
+ <option value="<?= $art->favicon() ?>">--using template favicon--</option>
+ <?php
+ } else {
+ echo '<option value="">--no favicon--</option>';
+ foreach ($faviconlist as $favicon) {
+ ?>
+ <option value="<?= $favicon ?>" <?= $art->favicon() === $favicon ? 'selected' : '' ?>><?= $favicon ?></option>
+ <?php
+ }
+ }
+ ?>
+ </select>
+ </fieldset>
+
</details>
<details>
<summary>Help</summary>
diff --git a/app/view/templates/editrightbar.php b/app/view/templates/editrightbar.php
index 26976e8..80a0b02 100644
--- a/app/view/templates/editrightbar.php
+++ b/app/view/templates/editrightbar.php
@@ -52,7 +52,7 @@
<ul>
<?php
foreach ($templates as $template => $id) {
- if(!empty($id)) {
+ if(!empty($id) && !is_bool($id)) {
?>
<li><?= $template ?> : <?= $id ?> <a href="<?= $this->uart('artedit', $id) ?>">✎</a></li>
<?php
diff --git a/app/view/templates/home.php b/app/view/templates/home.php
index 24e378b..a83361d 100644
--- a/app/view/templates/home.php
+++ b/app/view/templates/home.php
@@ -1,4 +1,4 @@
-<?php $this->layout('layout', ['title' => 'home', 'css' => $css . 'home.css']) ?>
+<?php $this->layout('layout', ['title' => 'home', 'css' => $css . 'home.css', 'favicon' => '']) ?>
diff --git a/app/view/templates/layout.php b/app/view/templates/layout.php
index 4131350..e0b2e1c 100644
--- a/app/view/templates/layout.php
+++ b/app/view/templates/layout.php
@@ -4,7 +4,12 @@
<meta charset="utf8" />
<meta name="viewport" content="width=device-width" />
- <link rel="shortcut icon" href="./media/logo.png" type="image/x-icon">
+ <?php if(!empty($favicon)) {
+ ?>
+ <link rel="shortcut icon" href="<?= Model::faviconpath() . $favicon ?>" type="image/x-icon">
+ <?php } elseif(!empty(Config::defaultfavicon())) { ?>
+ <link rel="shortcut icon" href="<?= Model::faviconpath() . Config::defaultfavicon() ?>" type="image/x-icon">
+ <?php } ?>
<title><?= $title ?></title>
<link rel="stylesheet" href="<?= $css ?>">