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/Element.php | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 app/class/Element.php (limited to 'app/class/Element.php') diff --git a/app/class/Element.php b/app/class/Element.php new file mode 100644 index 0000000..09f4e35 --- /dev/null +++ b/app/class/Element.php @@ -0,0 +1,204 @@ +hydrate($datas); + $this->analyse($pageid); + } + + public function hydrate($datas) + { + foreach ($datas as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + private function analyse(string $pageid) + { + if(!empty($this->options)) { + + // Replace "!" by the real page name + $this->options = str_replace('!', $pageid, $this->options); + + preg_match('~(:([a-z0-9-_+!]+))?(\/([a-z0-9-,_+=]+))?~', $this->options, $matches); + if(isset($matches[2]) && !empty($matches[2])) { + $this->sources = explode('+', $matches[2]); + } else { + $this->sources[] = $pageid; + } + if(isset($matches[4])) { + $this->params = explode(',', $matches[4]); + } + + $this->readoptions(); + + } else { + $this->sources[] = $pageid; + } + } + + private function readoptions() + { + if(!empty($this->params)) { + foreach ($this->params as $param ) { + preg_match('~([a-z0-9-_]+)(=(-?[0-9]+))?~', $param, $optionmatch); + if(isset($optionmatch[1])) { + $key = $optionmatch[1]; + } + if(isset($optionmatch[3])) { + $value = $optionmatch[3]; + } else { + $read = '

Rendering error :

Paramaters must have a value like : /' . $key . '=__value__ for parameter : ' . $key . '

'; + //throw new Exception($read); + } + $method = 'set' . $key; + if (in_array($key, self::OPTIONS)) { + if (!$this->$method($value)) { + $read = '

Rendering error :

Invalid value input : ' . $value . ' for parameter : ' . $key . '

'; + //throw new Exception($read); + + } + } else { + $read = '

Rendering error :

Parameter name : ' . $optionmatch[1] . ' does not exist

'; + //throw new Exception($read); + } + } + } + } + + public function addtags() + { + $this->content = PHP_EOL . '<' . $this->type() . '>' . PHP_EOL . $this->content() . PHP_EOL . 'type() . '>' . PHP_EOL; + } + + + + + + // __________________________________________________ G E T ____________________________________________________________ + + + public function fullmatch() + { + return $this->fullmatch; + } + + public function type() + { + return $this->type; + } + + public function options() + { + return $this->options; + } + + public function params() + { + return $this->params; + } + + public function sources() + { + return $this->sources; + } + + public function autolink() + { + return $this->autolink; + } + + public function markdown() + { + return $this->markdown; + } + + public function content() + { + return $this->content; + } + + + + + + + // __________________________________________________ S E T ____________________________________________________________ + + + public function setfullmatch(string $fullmatch) + { + $this->fullmatch = $fullmatch; + } + + public function settype(string $type) + { + $type = strtolower($type); + if(in_array($type, Model::TEXT_ELEMENTS)) { + $this->type = $type; + } + } + + public function setoptions(string $options) + { + if(!empty($options)) { + $this->options = $options; + } + } + + public function setautolink(int $level) + { + if($level >= 0 && $level <= 16) { + $this->autolink = $level; + return true; + } else { + return false; + } + } + + public function setmarkdown(int $level) + { + if($level >= 0 && $level <= 1) { + $this->markdown = $level; + return true; + } else { + return false; + } + } + + public function setcontent(string $content) + { + $this->content = $content; + } + +} + + + + +?> \ No newline at end of file -- cgit v1.2.3 From c77fe80b05829fbfd5b94f43a7b709e3f3ec6c0d Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Wed, 6 Nov 2019 01:00:10 +0100 Subject: fix: some missed use statements --- app/class/Controllermedia.php | 2 ++ app/class/Controllerpage.php | 1 + app/class/Element.php | 2 ++ app/class/Modeldb.php | 4 ++-- app/class/Modelpage.php | 1 + app/class/Modelrender.php | 8 +++++--- 6 files changed, 13 insertions(+), 5 deletions(-) (limited to 'app/class/Element.php') diff --git a/app/class/Controllermedia.php b/app/class/Controllermedia.php index f596550..5958289 100644 --- a/app/class/Controllermedia.php +++ b/app/class/Controllermedia.php @@ -2,6 +2,8 @@ namespace Wcms; +use Exception; + class Controllermedia extends Controller { /** diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index 5ab2928..2a67106 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -4,6 +4,7 @@ namespace Wcms; use DateTimeImmutable; use DateTimeZone; +use Exception; class Controllerpage extends Controller { diff --git a/app/class/Element.php b/app/class/Element.php index 09f4e35..72eba8f 100644 --- a/app/class/Element.php +++ b/app/class/Element.php @@ -2,6 +2,8 @@ namespace Wcms; +use Exception; + class Element { protected $fullmatch; diff --git a/app/class/Modeldb.php b/app/class/Modeldb.php index 756fd81..32e12cb 100644 --- a/app/class/Modeldb.php +++ b/app/class/Modeldb.php @@ -2,7 +2,7 @@ namespace Wcms; -use JamesMoss\Flywheel\Config; +use JamesMoss\Flywheel; use Wcms\Flywheel\Formatter\JSON; use Wcms\Flywheel\Query; use Wcms\Flywheel\Repository; @@ -22,7 +22,7 @@ class Modeldb extends Model public function dbinit() { - $this->database = new Config(Model::DATABASE_DIR, [ + $this->database = new Flywheel\Config(Model::DATABASE_DIR, [ 'query_class' => Query::class, 'formatter' => new JSON, ]); diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 58bd5d3..9438c96 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -2,6 +2,7 @@ namespace Wcms; +use Exception; use JamesMoss\Flywheel\Document; class Modelpage extends Modeldb diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php index 9f668d4..778b327 100644 --- a/app/class/Modelrender.php +++ b/app/class/Modelrender.php @@ -2,6 +2,9 @@ namespace Wcms; +use Exception; +use Michelf\MarkdownExtra; + class Modelrender extends Modelpage { protected $router; @@ -398,9 +401,8 @@ class Modelrender extends Modelpage } public function markdown($text) - { - //use Michelf\MarkdownExtra; - $fortin = new Michelf\MarkdownExtra; + { + $fortin = new MarkdownExtra; // id in headers // $fortin->header_id_func = function ($header) { // return preg_replace('/[^\w]/', '', strtolower($header)); -- cgit v1.2.3