aboutsummaryrefslogtreecommitdiff
path: root/app/class/element.php
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2019-11-04 23:31:31 +0100
committern-peugnet <n.peugnet@free.fr>2019-11-05 19:06:40 +0100
commite802d5204b96d645ec3d40b81b4a8bdc6e0ee675 (patch)
tree8e6db5e36ad8f247b442583e1e9e5da2934f4b52 /app/class/element.php
parentf1f63f556c41c99d45cd610186b0982383eff375 (diff)
downloadwcms-e802d5204b96d645ec3d40b81b4a8bdc6e0ee675.tar.gz
wcms-e802d5204b96d645ec3d40b81b4a8bdc6e0ee675.zip
refactor: switch to psr-4 autoloading
Diffstat (limited to 'app/class/element.php')
-rw-r--r--app/class/element.php202
1 files changed, 0 insertions, 202 deletions
diff --git a/app/class/element.php b/app/class/element.php
deleted file mode 100644
index 113daad..0000000
--- a/app/class/element.php
+++ /dev/null
@@ -1,202 +0,0 @@
-<?php
-
-class Element
-{
- protected $fullmatch;
- protected $type;
- protected $options;
- protected $sources = [];
- protected $params = [];
- protected $autolink = 0;
- protected $markdown = 1;
- protected $content = '';
-
- const OPTIONS = ['autolink', 'markdown'];
-
-
-
- // __________________________________________________ F U N ____________________________________________________________
-
-
-
- public function __construct($datas = [], $pageid)
- {
- $this->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 = '<h2>Rendering error :</h2><p>Paramaters must have a value like : <strong><code>/' . $key . '=__value__</code></strong> for parameter : <strong><code>' . $key . '</code></strong></p>';
- //throw new Exception($read);
- }
- $method = 'set' . $key;
- if (in_array($key, self::OPTIONS)) {
- if (!$this->$method($value)) {
- $read = '<h2>Rendering error :</h2><p>Invalid value input : <strong><code>' . $value . '</code></strong> for parameter : <strong><code>' . $key . '</code></strong></p>';
- //throw new Exception($read);
-
- }
- } else {
- $read = '<h2>Rendering error :</h2><p>Parameter name : <strong><code>' . $optionmatch[1] . '</code></strong> does not exist<p>';
- //throw new Exception($read);
- }
- }
- }
- }
-
- public function addtags()
- {
- $this->content = PHP_EOL . '<' . $this->type() . '>' . PHP_EOL . $this->content() . PHP_EOL . '</' . $this->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