diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-01-29 20:34:08 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-01-29 20:34:08 +0100 |
commit | b28f1a4a516f93044c632b254670dd21f52e625c (patch) | |
tree | aa2661016383e51fe26d564d208ac302f6e48926 /app | |
parent | a30e115d62f10183acb7ff946821aaf066d4a61e (diff) | |
download | wcms-b28f1a4a516f93044c632b254670dd21f52e625c.tar.gz wcms-b28f1a4a516f93044c632b254670dd21f52e625c.zip |
new feature : colored tags
Diffstat (limited to 'app')
-rw-r--r-- | app/class/Colors.php | 96 | ||||
-rw-r--r-- | app/class/Controllerhome.php | 3 | ||||
-rw-r--r-- | app/class/Model.php | 2 | ||||
-rw-r--r-- | app/view/templates/admin.php | 2 | ||||
-rw-r--r-- | app/view/templates/arthead.php | 6 | ||||
-rw-r--r-- | app/view/templates/confirmdelete.php | 2 | ||||
-rw-r--r-- | app/view/templates/connect.php | 2 | ||||
-rw-r--r-- | app/view/templates/edit.php | 2 | ||||
-rw-r--r-- | app/view/templates/font.php | 2 | ||||
-rw-r--r-- | app/view/templates/home.php | 2 | ||||
-rw-r--r-- | app/view/templates/homeopt.php | 4 | ||||
-rw-r--r-- | app/view/templates/info.php | 2 | ||||
-rw-r--r-- | app/view/templates/layout.php | 6 | ||||
-rw-r--r-- | app/view/templates/media.php | 2 | ||||
-rw-r--r-- | app/view/templates/timeline.php | 2 | ||||
-rw-r--r-- | app/view/templates/user.php | 2 |
16 files changed, 115 insertions, 22 deletions
diff --git a/app/class/Colors.php b/app/class/Colors.php new file mode 100644 index 0000000..ce37d62 --- /dev/null +++ b/app/class/Colors.php @@ -0,0 +1,96 @@ +<?php + +namespace Wcms; + +class Colors +{ + + protected $file = MODEL::CSS_DIR . 'tagcolors.css'; + + + protected $rawcss = ""; + protected $tagcolor = []; + + + + public function __construct(array $taglist = []) + { + if ($this->readcssfile()) { + $this->parsetagcss(); + } + if (!empty($taglist)) { + $this->removeaddtags($taglist); + $this->tocss(); + $this->writecssfile(); + } + } + + public function readcssfile(): bool + { + if (MODEL::dircheck(MODEL::CSS_DIR) && file_exists($this->file)) { + $this->rawcss = file_get_contents($this->file); + return true; + } else { + return false; + } + } + + public function removeaddtags(array $taglist = []) + { + $tagcolor = []; + foreach ($taglist as $tag => $tagcount) { + if (key_exists($tag, $this->tagcolor)) { + $tagcolor[$tag] = $this->tagcolor[$tag]; + } else { + $tagcolor[$tag] = '#' . dechex(rand(100, 255)) . dechex(rand(100, 255)) . dechex(rand(100, 255)); + } + } + $this->tagcolor = $tagcolor; + } + + + + /** + * Transform a CSS string in a array of `tag => background-color` + * + * @return array Ouput array using TAG as key and Hex Color as value + */ + public function parsetagcss() + { + $pattern = '%.tag\_([a-z0-9\-\_]*)\s*\{\s*background-color:\s*(#[A-Fa-f0-9]{6})\;\s*\}%'; + preg_match_all($pattern, $this->rawcss, $matches); + $tagcolor = array_combine($matches[1], $matches[2]); + if ($tagcolor !== false) { + $this->tagcolor = $tagcolor; + return true; + } else { + return false; + } + } + + public function tocss() + { + $css = ""; + foreach ($this->tagcolor as $tag => $color) { + $css .= PHP_EOL . '.tag_' . $tag . ' { background-color: ' . $color . '; }'; + } + $this->rawcss = $css; + } + + public function writecssfile() + { + if (MODEL::dircheck(MODEL::CSS_DIR)) { + return file_put_contents($this->file, $this->rawcss); + } + } + + public function htmlcolorpicker(array $csstagcolor): string + { + $html = '<ul>'; + foreach ($csstagcolor as $tag => $color) { + $html .= PHP_EOL . '<li><input type="color" name="colors[' . $tag . ']" value="' . $color . '"></li>'; + } + $html .= PHP_EOL . '</ul>'; + return $html; + } +} diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 81e4300..9f8896c 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -30,8 +30,7 @@ class Controllerhome extends Controllerpage $table = $this->modelhome->getlister(); $this->opt = $this->modelhome->optinit($table); - $css = 'a.tag_bgg-fds_gd { background-color: #FF0021; } '; - $this->opt->parsetagcss($css); + $colors = new Colors($this->opt->taglist()); $table2 = $this->modelhome->table2($table, $this->opt); diff --git a/app/class/Model.php b/app/class/Model.php index 655de9f..40e3a2e 100644 --- a/app/class/Model.php +++ b/app/class/Model.php @@ -139,7 +139,7 @@ abstract class Model * * @return bool return true if the dir already exist or was created succesfullt. Otherwise return false */ - public function dircheck(string $dir) : bool + public static function dircheck(string $dir) : bool { if (!is_dir($dir)) { return mkdir($dir); diff --git a/app/view/templates/admin.php b/app/view/templates/admin.php index c201d90..f7d25b3 100644 --- a/app/view/templates/admin.php +++ b/app/view/templates/admin.php @@ -1,4 +1,4 @@ -<?php $this->layout('layout', ['title' => 'admin', 'css' => $css . 'home.css']) ?> +<?php $this->layout('layout', ['title' => 'admin', 'stylesheets' => [$css . 'home.css']]) ?> <?php $this->start('page') ?> diff --git a/app/view/templates/arthead.php b/app/view/templates/arthead.php deleted file mode 100644 index b137c7f..0000000 --- a/app/view/templates/arthead.php +++ /dev/null @@ -1,6 +0,0 @@ -<meta charset="utf8" /> -<meta name="viewport" content="width=device-width" /> -<link rel="shortcut icon" href="./media/logo.png" type="image/x-icon"> -<title><?= $title ?></title> -<meta name="description" content="<?= $description ?>"> -<link rel="stylesheet" href="./css/soft.css">
\ No newline at end of file diff --git a/app/view/templates/confirmdelete.php b/app/view/templates/confirmdelete.php index 133f32b..24de454 100644 --- a/app/view/templates/confirmdelete.php +++ b/app/view/templates/confirmdelete.php @@ -1,4 +1,4 @@ -<?php $this->layout('layout', ['title' => 'delete', 'description' => 'delete', 'css' => $css . 'delete.css']) ?> +<?php $this->layout('layout', ['title' => 'delete', 'description' => 'delete', 'stylesheets' => [$css . 'home.css']]) ?> <?php $this->start('page') ?> diff --git a/app/view/templates/connect.php b/app/view/templates/connect.php index dca4303..e21b360 100644 --- a/app/view/templates/connect.php +++ b/app/view/templates/connect.php @@ -1,4 +1,4 @@ -<?php $this->layout('layout', ['title' => 'Connect', 'description' => 'connect', 'css' => $css . 'connect.css']) ?> +<?php $this->layout('layout', ['title' => 'Connect', 'description' => 'connect', 'stylesheets' => [$css . 'home.css']]) ?> diff --git a/app/view/templates/edit.php b/app/view/templates/edit.php index 5507583..d0125f2 100644 --- a/app/view/templates/edit.php +++ b/app/view/templates/edit.php @@ -1,4 +1,4 @@ -<?php $this->layout('layout', ['title' => '✏ '.$page->title(), 'css' => $css . 'edit.css', 'favicon' => $page->favicon()]) ?> +<?php $this->layout('layout', ['title' => '✏ '.$page->title(), 'stylesheets' => [$css . 'edit.css'], 'favicon' => $page->favicon()]) ?> diff --git a/app/view/templates/font.php b/app/view/templates/font.php index 8fcf149..cf6d309 100644 --- a/app/view/templates/font.php +++ b/app/view/templates/font.php @@ -1,4 +1,4 @@ -<?php $this->layout('layout', ['title' => 'font', 'css' => $css . 'home.css']) ?> +<?php $this->layout('layout', ['title' => 'font', 'stylesheets' => [$css . 'home.css']]) ?> <?php $this->start('page') ?> diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 9c71b53..0c1cc86 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', 'favicon' => '']) ?> +<?php $this->layout('layout', ['title' => 'home', 'stylesheets' => [$css . 'home.css', $css . 'tagcolors.css'], 'favicon' => '']) ?> diff --git a/app/view/templates/homeopt.php b/app/view/templates/homeopt.php index 7f42c8e..05f8d27 100644 --- a/app/view/templates/homeopt.php +++ b/app/view/templates/homeopt.php @@ -63,9 +63,9 @@ if (in_array($tagfilter, $opt->tagfilter())) { - echo '<li><input type="checkbox" name="tagfilter[]" id="tag_' . $tagfilter . '" value="' . $tagfilter . '" checked /><label for="tag_' . $tagfilter . '">' . $tagfilter . ' (' . $count . ')</label></li>'; + echo '<li><input type="checkbox" name="tagfilter[]" id="tag_' . $tagfilter . '" value="' . $tagfilter . '" checked /><label for="tag_' . $tagfilter . '">' . $tagfilter . ' <span class="counter tag_' . $tagfilter . '">' . $count . '</span></label></li>'; } else { - echo '<li><input type="checkbox" name="tagfilter[]" id="tag_' . $tagfilter . '" value="' . $tagfilter . '" /><label for="tag_' . $tagfilter . '">' . $tagfilter . ' (' . $count . ')</label></li>'; + echo '<li><input type="checkbox" name="tagfilter[]" id="tag_' . $tagfilter . '" value="' . $tagfilter . '" /><label for="tag_' . $tagfilter . '">' . $tagfilter . ' <span class="counter tag_' . $tagfilter . '">' . $count . '</span></label></li>'; } } if ($in = true || $out = true) { diff --git a/app/view/templates/info.php b/app/view/templates/info.php index 9a5357e..a5a5213 100644 --- a/app/view/templates/info.php +++ b/app/view/templates/info.php @@ -1,4 +1,4 @@ -<?php $this->layout('layout', ['title' => 'info', 'css' => $css . 'home.css']) ?> +<?php $this->layout('layout', ['title' => 'info', 'stylesheets' => [$css . 'home.css']]) ?> <?php $this->start('page') ?> diff --git a/app/view/templates/layout.php b/app/view/templates/layout.php index 9259fda..b255738 100644 --- a/app/view/templates/layout.php +++ b/app/view/templates/layout.php @@ -12,7 +12,11 @@ <link rel="shortcut icon" href="<?= Wcms\Model::faviconpath() . Wcms\Config::defaultfavicon() ?>" type="image/x-icon"> <?php } ?> <title><?= $title ?></title> - <link rel="stylesheet" href="<?= $css ?>"> + + <?php foreach ($stylesheets as $stylsheet) { ?> + <link rel="stylesheet" href="<?= $stylsheet ?>"> + <?php } ?> + <?php if (!empty(Wcms\Config::interfacecss())) { echo '<link rel="stylesheet" href="' . Wcms\Model::csspath() . Wcms\Config::interfacecss() . '">'; diff --git a/app/view/templates/media.php b/app/view/templates/media.php index ba385cb..7e20f48 100644 --- a/app/view/templates/media.php +++ b/app/view/templates/media.php @@ -2,7 +2,7 @@ use Wcms\Model; -$this->layout('layout', ['title' => 'media', 'css' => $css . 'home.css']) ?> +$this->layout('layout', ['title' => 'media', 'stylesheets' => [$css . 'home.css']]) ?> <?php $this->start('page') ?> diff --git a/app/view/templates/timeline.php b/app/view/templates/timeline.php index 2db861c..f06180e 100644 --- a/app/view/templates/timeline.php +++ b/app/view/templates/timeline.php @@ -1,4 +1,4 @@ -<?php $this->layout('layout', ['title' => 'timeline', 'css' => $css . 'home.css', 'favicon' => '']) ?> +<?php $this->layout('layout', ['title' => 'timeline', 'stylesheets' => [$css . 'home.css'], 'favicon' => '']) ?> diff --git a/app/view/templates/user.php b/app/view/templates/user.php index f281c93..f7b2b25 100644 --- a/app/view/templates/user.php +++ b/app/view/templates/user.php @@ -1,4 +1,4 @@ -<?php $this->layout('layout', ['title' => 'user', 'css' => $css . 'home.css']) ?> +<?php $this->layout('layout', ['title' => 'user', 'stylesheets' => [$css . 'home.css']]) ?> <?php $this->start('page') ?> |