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 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 app/class/Colors.php (limited to 'app/class/Colors.php') 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; + } +} -- 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(-) (limited to 'app/class/Colors.php') 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 = ''; 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 (limited to 'app/class/Colors.php') 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