From a30e115d62f10183acb7ff946821aaf066d4a61e Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 29 Jan 2020 16:52:37 +0100 Subject: working on cssparser for tags colors --- app/class/Controllerhome.php | 5 +++-- app/class/Opt.php | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 1603511..81e4300 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -27,11 +27,12 @@ class Controllerhome extends Controllerpage } else { - - $table = $this->modelhome->getlister(); $this->opt = $this->modelhome->optinit($table); + $css = 'a.tag_bgg-fds_gd { background-color: #FF0021; } '; + $this->opt->parsetagcss($css); + $table2 = $this->modelhome->table2($table, $this->opt); $columns = $this->modelhome->setcolumns($this->user->columns()); diff --git a/app/class/Opt.php b/app/class/Opt.php index 253e4f6..e042aae 100644 --- a/app/class/Opt.php +++ b/app/class/Opt.php @@ -17,7 +17,7 @@ class Opt extends Item protected $taglist = []; protected $authorlist = []; protected $invert = 0; - protected $limit= 0; + protected $limit = 0; protected $pagevarlist; @@ -63,7 +63,7 @@ class Opt extends Item public function getall() { - $optlist = ['sortby', 'order', 'secure', 'tagcompare', 'tagfilter', 'authorcompare', 'authorfilter', 'limit','invert']; + $optlist = ['sortby', 'order', 'secure', 'tagcompare', 'tagfilter', 'authorcompare', 'authorfilter', 'limit', 'invert']; foreach ($optlist as $method) { if (method_exists($this, $method)) { @@ -96,7 +96,7 @@ class Opt extends Item public function sortbyorder($sortby = "") { $object = $this->drylist(['sortby', 'order', 'secure', 'tagfilter', 'tagcompare', 'authorfilter', 'authorcompare', 'invert', 'limit']); - if(!empty($sortby)) { + if (!empty($sortby)) { $object['sortby'] = $sortby; } $object['order'] = $object['order'] * -1; @@ -111,10 +111,10 @@ class Opt extends Item * @param array $taglist List of tag to be * @return string html code to be printed */ - public function taglinks(array $taglist = []) : string + public function taglinks(array $taglist = []): string { $tagstring = ""; - foreach ($taglist as $tag ) { + foreach ($taglist as $tag) { $tagstring .= '' . $tag . '' . PHP_EOL; } return $tagstring; @@ -126,10 +126,10 @@ class Opt extends Item * @param array $authorlist List of author to be * @return string html code to be printed */ - public function authorlinks(array $authorlist = []) : string + public function authorlinks(array $authorlist = []): string { $authorstring = ""; - foreach ($authorlist as $author ) { + foreach ($authorlist as $author) { $authorstring .= '' . $author . '' . PHP_EOL; } return $authorstring; @@ -170,7 +170,27 @@ class Opt extends Item return urldecode(http_build_query($query)); } + public function parsetagcss(string $cssstring) + { + $classprefix = 'tag'; + $pattern = '%a\.' . $classprefix . '\_([a-z0-9\-\_]*)\s*\{\s*(background-color):\s*(#[A-F0-6]{6})\;\s*\}%'; + preg_match($pattern, $cssstring, $matches); + foreach ($matches as $value) { + } + } + public function tocss($cssdatas) + { + $string = ''; + foreach ($cssdatas as $element => $css) { + $string .= PHP_EOL . $element . ' {'; + foreach ($css as $param => $value) { + $string .= PHP_EOL . ' ' . $param . ': ' . $value . ';'; + } + $string .= PHP_EOL . '}' . PHP_EOL; + } + return $string; + } // _______________________________________________ G E T _______________________________________________ @@ -400,7 +420,7 @@ class Opt extends Item public function setlimit($limit) { $limit = intval($limit); - if($limit < 0) { + if ($limit < 0) { $limit = 0; } elseif ($limit >= 10000) { $limit = 9999; -- cgit v1.2.3 From b28f1a4a516f93044c632b254670dd21f52e625c Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 29 Jan 2020 20:34:08 +0100 Subject: new feature : colored tags --- app/class/Colors.php | 96 ++++++++++++++++++++++++++++++++++++ app/class/Controllerhome.php | 3 +- app/class/Model.php | 2 +- app/view/templates/admin.php | 2 +- app/view/templates/arthead.php | 6 --- app/view/templates/confirmdelete.php | 2 +- app/view/templates/connect.php | 2 +- app/view/templates/edit.php | 2 +- app/view/templates/font.php | 2 +- app/view/templates/home.php | 2 +- app/view/templates/homeopt.php | 4 +- app/view/templates/info.php | 2 +- app/view/templates/layout.php | 6 ++- app/view/templates/media.php | 2 +- app/view/templates/timeline.php | 2 +- app/view/templates/user.php | 2 +- assets/css/home.css | 9 +++- assets/css/tagcolors.css | 16 ++++++ 18 files changed, 139 insertions(+), 23 deletions(-) create mode 100644 app/class/Colors.php delete mode 100644 app/view/templates/arthead.php create mode 100644 assets/css/tagcolors.css 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 @@ +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 = ''; + 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 @@ -layout('layout', ['title' => 'admin', 'css' => $css . 'home.css']) ?> +layout('layout', ['title' => 'admin', 'stylesheets' => [$css . 'home.css']]) ?> 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 @@ - - - -<?= $title ?> - - \ 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 @@ -layout('layout', ['title' => 'delete', 'description' => 'delete', 'css' => $css . 'delete.css']) ?> +layout('layout', ['title' => 'delete', 'description' => 'delete', 'stylesheets' => [$css . 'home.css']]) ?> 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 @@ -layout('layout', ['title' => 'Connect', 'description' => 'connect', 'css' => $css . 'connect.css']) ?> +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 @@ -layout('layout', ['title' => '✏ '.$page->title(), 'css' => $css . 'edit.css', 'favicon' => $page->favicon()]) ?> +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 @@ -layout('layout', ['title' => 'font', 'css' => $css . 'home.css']) ?> +layout('layout', ['title' => 'font', 'stylesheets' => [$css . 'home.css']]) ?> 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 @@ -layout('layout', ['title' => 'home', 'css' => $css . 'home.css', 'favicon' => '']) ?> +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 '
  • '; + echo '
  • '; } else { - echo '
  • '; + echo '
  • '; } } 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 @@ -layout('layout', ['title' => 'info', 'css' => $css . 'home.css']) ?> +layout('layout', ['title' => 'info', 'stylesheets' => [$css . 'home.css']]) ?> 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 @@ <?= $title ?> - + + + + + '; 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']]) ?> 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 @@ -layout('layout', ['title' => 'timeline', 'css' => $css . 'home.css', 'favicon' => '']) ?> +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 @@ -layout('layout', ['title' => 'user', 'css' => $css . 'home.css']) ?> +layout('layout', ['title' => 'user', 'stylesheets' => [$css . 'home.css']]) ?> start('page') ?> diff --git a/assets/css/home.css b/assets/css/home.css index a801ba8..9ee57ac 100644 --- a/assets/css/home.css +++ b/assets/css/home.css @@ -112,9 +112,16 @@ main.home table .id { font-size: medium; } +nav span.counter { + border-radius: 100%; + width: 17px; + height: 17px; + display: inline-block; + text-align: center; +} + table a.tag { - background-color: #7b97b9; border-radius: 10px; padding: 1px 4px; } diff --git a/assets/css/tagcolors.css b/assets/css/tagcolors.css new file mode 100644 index 0000000..fbeede5 --- /dev/null +++ b/assets/css/tagcolors.css @@ -0,0 +1,16 @@ + +.tag_color { background-color: #72b8e8; } +.tag_w { background-color: #b5d689; } +.tag_sans { background-color: #7be87e; } +.tag_secret { background-color: #97b495; } +.tag_salle { background-color: #d2946d; } +.tag_ab { background-color: #fbd4fd; } +.tag_template { background-color: #f4cbfe; } +.tag_tttaaaaggggeee { background-color: #75d26b; } +.tag_salle01 { background-color: #64d377; } +.tag_event { background-color: #9daa97; } +.tag_delire { background-color: #c794c0; } +.tag_phasme { background-color: #bcf2c9; } +.tag_animal { background-color: #c6f9a4; } +.tag_blague { background-color: #6a859f; } +.tag_festival { background-color: #ed65b9; } \ No newline at end of file -- cgit v1.2.3 From c3014fb7be5c54ac9d1325f33f6fe0a2624161a8 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 29 Jan 2020 21:15:38 +0100 Subject: new feature : home>display>tags colors --- app/class/Colors.php | 37 +++++++++++++++++++++++++++++++++---- app/class/Controllerhome.php | 14 +++++++++++++- app/class/Opt.php | 2 +- app/class/Routes.php | 1 + app/view/templates/home.php | 2 +- app/view/templates/homemenu.php | 7 +++++++ assets/css/home.css | 6 +++++- assets/css/tagcolors.css | 9 +++++---- 8 files changed, 66 insertions(+), 12 deletions(-) diff --git a/app/class/Colors.php b/app/class/Colors.php index ce37d62..bf11229 100644 --- a/app/class/Colors.php +++ b/app/class/Colors.php @@ -2,7 +2,7 @@ namespace Wcms; -class Colors +class Colors extends Item { protected $file = MODEL::CSS_DIR . 'tagcolors.css'; @@ -84,13 +84,42 @@ class Colors } } - public function htmlcolorpicker(array $csstagcolor): string + public function htmlcolorpicker(): string { $html = '
      '; - foreach ($csstagcolor as $tag => $color) { - $html .= PHP_EOL . '
    • '; + foreach ($this->tagcolor as $tag => $color) { + $html .= PHP_EOL . '
    • '; } $html .= PHP_EOL . '
    '; return $html; } + + + // ______________________ G E T _________________________ + + public function rawcss() + { + return $this->rawcss; + } + + public function tagcolor() + { + return $this->tagcolor; + } + + // _______________________ S E T _________________________ + + public function setrawcss($rawcss) + { + if(is_string($rawcss)) { + $this->rawcss = $rawcss; + } + } + + public function settagcolor($tagcolor) + { + if(is_array($tagcolor)) { + $this->tagcolor = $tagcolor; + } + } } diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 9f8896c..d102930 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -36,7 +36,7 @@ class Controllerhome extends Controllerpage $columns = $this->modelhome->setcolumns($this->user->columns()); - $vars = ['user' => $this->user, 'table2' => $table2, 'opt' => $this->opt, 'columns' => $columns, 'faviconlist' => $this->mediamanager->listfavicon(), 'editorlist' => $this->usermanager->getlisterbylevel(2, '>=')]; + $vars = ['user' => $this->user, 'table2' => $table2, 'opt' => $this->opt, 'columns' => $columns, 'faviconlist' => $this->mediamanager->listfavicon(), 'editorlist' => $this->usermanager->getlisterbylevel(2, '>='), 'colors' => $colors]; $vars['footer'] = ['version' => getversion(), 'total' => count($table), 'database' => Config::pagetable()]; if (isset($_POST['query']) && $this->user->iseditor()) { @@ -61,6 +61,18 @@ class Controllerhome extends Controllerpage $this->routedirect('home'); } + public function colors() + { + if (isset($_POST['tagcolor']) && $this->user->issupereditor()) { + $colors = new Colors(); + $colors->hydrate($_POST); + $colors->tocss(); + $colors->writecssfile(); + } + $this->routedirect('home'); + + } + public function search() { if (isset($_POST['id']) && !empty($_POST['id'])) { diff --git a/app/class/Opt.php b/app/class/Opt.php index e042aae..a489d5a 100644 --- a/app/class/Opt.php +++ b/app/class/Opt.php @@ -130,7 +130,7 @@ class Opt extends Item { $authorstring = ""; foreach ($authorlist as $author) { - $authorstring .= '' . $author . '' . PHP_EOL; + $authorstring .= '' . $author . '' . PHP_EOL; } return $authorstring; } diff --git a/app/class/Routes.php b/app/class/Routes.php index 4a87fc8..c4571d9 100644 --- a/app/class/Routes.php +++ b/app/class/Routes.php @@ -20,6 +20,7 @@ class Routes ['GET', '/', 'Controllerhome#desktop', 'home'], ['POST', '/', 'Controllerhome#desktop', 'homequery'], ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], + ['POST', '/colors', 'Controllerhome#colors', 'homecolors'], ['GET', '//renderall', 'Controllerhome#renderall', 'homerenderall'], ['POST', '/bookmark', 'Controllerhome#bookmark', 'homebookmark'], ['POST', '/multi', 'Controllerhome#multi', 'multi'], diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 0c1cc86..fa9ef63 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -16,7 +16,7 @@ insert('homemenu', ['user' => $user, 'opt' => $opt, 'optlist' => $optlist, 'pagelist' => $pagelist, 'faviconlist' => $faviconlist, 'editorlist' => $editorlist]); + $this->insert('homemenu', ['user' => $user, 'opt' => $opt, 'optlist' => $optlist, 'pagelist' => $pagelist, 'faviconlist' => $faviconlist, 'editorlist' => $editorlist, 'colors' => $colors]); ?> diff --git a/app/view/templates/homemenu.php b/app/view/templates/homemenu.php index 669f9f2..51a58e9 100644 --- a/app/view/templates/homemenu.php +++ b/app/view/templates/homemenu.php @@ -304,6 +304,13 @@ + issupereditor()) { ?> +

    Tag colors

    +
    + htmlcolorpicker() ?> + +
    + diff --git a/assets/css/home.css b/assets/css/home.css index 9ee57ac..62cf05d 100644 --- a/assets/css/home.css +++ b/assets/css/home.css @@ -121,11 +121,15 @@ nav span.counter { } -table a.tag { +table a.tag, table a.author { border-radius: 10px; padding: 1px 4px; } +table a.author { + background-color: darkgrey; +} + table a.secure{ padding: 1px 3px; } diff --git a/assets/css/tagcolors.css b/assets/css/tagcolors.css index fbeede5..8430eba 100644 --- a/assets/css/tagcolors.css +++ b/assets/css/tagcolors.css @@ -1,8 +1,9 @@ -.tag_color { background-color: #72b8e8; } -.tag_w { background-color: #b5d689; } -.tag_sans { background-color: #7be87e; } -.tag_secret { background-color: #97b495; } +.tag_color { background-color: #ff0000; } +.tag_w { background-color: #50e2f9; } +.tag_sans { background-color: #00ff07; } +.tag_secret { background-color: #10580b; } +.tag_fiit { background-color: #ba7db4; } .tag_salle { background-color: #d2946d; } .tag_ab { background-color: #fbd4fd; } .tag_template { background-color: #f4cbfe; } -- cgit v1.2.3 From 2211f5cbae94c09c03c95b4c4d010ddaf72738df Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 29 Jan 2020 21:44:32 +0100 Subject: fix color set for tags colors --- .gitignore | 1 + app/class/Colors.php | 2 +- assets/css/tagcolors.css | 17 ----------------- 3 files changed, 2 insertions(+), 18 deletions(-) delete mode 100644 assets/css/tagcolors.css diff --git a/.gitignore b/.gitignore index 2fc5d5d..e8830c1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.bundle.js.map assets/render/* assets/global/* +assets/css/tagcolors.css database/* fonts/* media/* diff --git a/app/class/Colors.php b/app/class/Colors.php index bf11229..0ad5cca 100644 --- a/app/class/Colors.php +++ b/app/class/Colors.php @@ -42,7 +42,7 @@ class Colors extends Item 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)); + $tagcolor[$tag] = '#' . dechex(rand(50, 255)) . dechex(rand(50, 255)) . dechex(rand(50, 255)); } } $this->tagcolor = $tagcolor; diff --git a/assets/css/tagcolors.css b/assets/css/tagcolors.css deleted file mode 100644 index 8430eba..0000000 --- a/assets/css/tagcolors.css +++ /dev/null @@ -1,17 +0,0 @@ - -.tag_color { background-color: #ff0000; } -.tag_w { background-color: #50e2f9; } -.tag_sans { background-color: #00ff07; } -.tag_secret { background-color: #10580b; } -.tag_fiit { background-color: #ba7db4; } -.tag_salle { background-color: #d2946d; } -.tag_ab { background-color: #fbd4fd; } -.tag_template { background-color: #f4cbfe; } -.tag_tttaaaaggggeee { background-color: #75d26b; } -.tag_salle01 { background-color: #64d377; } -.tag_event { background-color: #9daa97; } -.tag_delire { background-color: #c794c0; } -.tag_phasme { background-color: #bcf2c9; } -.tag_animal { background-color: #c6f9a4; } -.tag_blague { background-color: #6a859f; } -.tag_festival { background-color: #ed65b9; } \ No newline at end of file -- cgit v1.2.3