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 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 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; + } + } } -- 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 --- app/class/Colors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/class/Colors.php') 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; -- cgit v1.2.3