From e802d5204b96d645ec3d40b81b4a8bdc6e0ee675 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Mon, 4 Nov 2019 23:31:31 +0100 Subject: refactor: switch to psr-4 autoloading --- app/class/Quickcss.php | 293 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 app/class/Quickcss.php (limited to 'app/class/Quickcss.php') diff --git a/app/class/Quickcss.php b/app/class/Quickcss.php new file mode 100644 index 0000000..0173763 --- /dev/null +++ b/app/class/Quickcss.php @@ -0,0 +1,293 @@ + ['left', 'right', 'center', 'justify'], + 'border-style' => ['solid', 'double', 'outset', 'ridge'], + 'font-family' => ['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy'], + 'text-decoration-line' => ['none', 'underline', 'overline', 'line-through', 'underline overline'], + 'display' => ['none', ] + ]; + + + private static function getselect() + { + return array_keys(self::OPTIONS); + } + + private static function getparams() + { + $params = array_merge(self::COLOR, self::SIZE, self::getselect(), self::UNIQUE); + sort($params, SORT_STRING ); + return $params; + } + + public function __construct($data) + { + $this->hydrate($data); } + + public function hydrate($data) + { + foreach ($data as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function calc() + { + $quickcss = $this->intersect($this->values,$this->active); + $quickcss = $this->merge($quickcss, $this->new); + $quickcss = $this->addunits($quickcss, $this->units); + $quickcss = $this->merge($this->jsoncss, $quickcss); + + $this->quickcss = $quickcss; + } + + + + // _________________________________________ P O S T __________________________________________________ + + public function setvalues($data) + { + if(is_array($data)) { + $this->values = $data; + } + } + + public function setunits($data) + { + if(is_array($data)) { + $this->units = $data; + } + } + + public function setactive($data) + { + if(is_array($data)) { + $this->active = $data; + } + } + + public function setnew($data) + { + if (!empty($data['element']) && !empty($data['param']) && in_array($data['param'], self::getparams())) { + $new = array($data['element'] => array($data['param'] => '')); + $this->new = $new; + } + } + + + public function setjson($jsoncss) + { + if(!empty($jsoncss) && is_string($jsoncss)) { + $jsoncss = json_decode($jsoncss); + if(is_array($jsoncss)) { + $this->jsoncss = $jsoncss; + } else { + $this->jsoncss = []; + } + } + } + + + // _______________________________________ C A L C ___________________________________________________ + + public function intersect($values, $active) + { + $intersect = array_intersect_key($values, $active); + + foreach ($intersect as $element => $css) { + $intersect[$element] = array_intersect_key($values[$element], $active[$element]); + } + return $intersect; + } + + public function merge($quickcss, $new) + { + $quickcss = array_merge_recursive($quickcss, $new); + return $quickcss; + } + + public function addunits($quickcss, $units) + { + foreach ($units as $element => $css) { + foreach ($css as $param => $unit) { + if (array_key_exists($element, $quickcss) && array_key_exists($param, $quickcss[$element])) { + $quickcss[$element][$param] = $quickcss[$element][$param] . $unit; + } + } + } + return $quickcss; + } + + + + // __________________________________________ C O M _________________________________________ + + public function tocss() + { + $string = ''; + foreach ($this->quickcss as $element => $css) { + $string .= PHP_EOL . $element . ' {'; + foreach ($css as $param => $value) { + $string .= PHP_EOL . ' ' . $param . ': ' . $value . ';'; + } + $string .= PHP_EOL . '}' . PHP_EOL; + } + return $string; + } + + public function tojson() + { + return json_encode($this->quickcss); + } + + + + + // _____________________________________________ F O R M ____________________________________________ + + public function form($action) + { + echo '
'; + echo '
'; + $this->inputs($this->quickcss); + echo '
'; + echo '
'; + + } + + public function inputs($quickcss) + { + echo '

Add element

'; + + echo ''; + echo ''; + foreach (array_keys($quickcss) as $element) { + echo ''; + + echo ''; + + foreach ($quickcss as $element => $css) { + echo '

' . $element . '

'; + foreach ($css as $param => $value) { + + echo '
'; + echo ''; + echo ''; + echo '
'; + + echo '
'; + + if (in_array($param, self::COLOR)) { + echo ''; + } + + if (in_array($param, self::SIZE)) { + $this->sizeinput($element, $param, $value); + } + + if (in_array($param, self::getselect())) { + $this->selectinput($element, $param, $value); + } + + if (in_array($param, self::UNIQUE)) { + $method = str_replace('-', '', $param) . 'input'; + if (method_exists($this, $method)) { + $this->$method($element, $param, $value); + } + } + + echo '
'; + } + } + + + } + + + + + + + // ____________________________________ I N P U T __________________________________ + + public function sizeinput($element, $param, $value) + { + echo ''; + + $unit = preg_replace('/\d/', '', $value); + ?> + + '; + + $unit = preg_replace('/\d/', '', $value); + ?> + + '; + } + + public function selectinput($element, $param, $value) + { + echo ''; + } + + +} + + + +?> \ No newline at end of file -- cgit v1.2.3