From 69211185e5578b72d3a0f9e10b5dd3d0b2f0e2a0 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sun, 9 Dec 2018 18:43:21 +0100 Subject: auto-media-dir-list --- app/class/modelrender.php | 53 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'app/class/modelrender.php') diff --git a/app/class/modelrender.php b/app/class/modelrender.php index c36417d..7ef7e45 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -56,21 +56,24 @@ class Modelrender extends Modelart } else { $templatebody = $templateart->body(); } - $body = $templatebody . PHP_EOL . $this->art->body(); + $body = $templatebody; } else { $body = $this->art->body(); } + $body = $this->article($body); + $body = $this->automedialist($body); + $body = $this->autotaglistupdate($body); return $body; } public function getbody(string $body) { $rend = $this; - $body = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)((\.([a-z0-9-_]+|!))*|!)?\%~', function ($match) use ($rend) { + $body = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)((:[a-z0-9-_]+|!)(\+([a-z0-9-_]+|!))*)?\%~', function ($match) use ($rend) { $element = strtolower($match[1]); $getelement = ''; if (isset($match[2]) && !empty($match[2])) { - $templatelist = str_replace('!', $this->art->id(), explode('.', ltrim($match[2], '.'))); + $templatelist = str_replace('!', $this->art->id(), explode('+', ltrim($match[2], ':'))); foreach ($templatelist as $template) { if ($template === $rend->art->id()) { $templateelement = $rend->art->$element(); @@ -94,6 +97,7 @@ class Modelrender extends Modelart public function elementparser($element) { $element = $this->article($element); + $element = $this->automedialist($element); $element = $this->autotaglistupdate($element); $element = $this->markdown($element); @@ -200,7 +204,7 @@ class Modelrender extends Modelart public function media(string $text): string { $rend = $this; - $text = preg_replace('%(src|target)="((\/?[\w-_]+)+\.[a-z0-9]{1,5})"%', '$1="'.Model::mediapath() . '$2"', $text); + $text = preg_replace('%(src|href)="((\/?[\w-_]+)+\.[a-z0-9]{1,5})"%', '$1="'.Model::mediapath() . '$2" target="_blank" class="media"', $text); return $text; } @@ -299,6 +303,47 @@ class Modelrender extends Modelart return $text; } + public function automedialist(string $text): string + { + $text = preg_replace_callback('~\%MEDIA:(([a-z0-9-_]+(\/([a-z0-9-_])+)*))\%~', + function($matches) { + $dir = trim($matches[1], '/'); + $mediamanager = new Modelmedia(); + + + + if(is_dir(Model::MEDIA_DIR . $dir)) { + $medialist = $mediamanager->getlistermedia(Model::MEDIA_DIR . $dir . '/'); + + $dirid = str_replace('/', '-', $dir); + + $ul = '' . PHP_EOL; + + return $ul; + } else { + return 'directory not founded'; + } + }, $text); + + return $text; + } + function sumparser($text) -- cgit v1.2.3