aboutsummaryrefslogtreecommitdiff
path: root/app/class/modelrender.php
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2018-12-09 18:43:21 +0100
committervincent-peugnet <v.peugnet@free.fr>2018-12-09 18:43:21 +0100
commit69211185e5578b72d3a0f9e10b5dd3d0b2f0e2a0 (patch)
tree74d94124d83a9b0a48a58bb96f5d2111994d01e9 /app/class/modelrender.php
parentae0693d074a63412e7ab9587520096cb60a48e64 (diff)
downloadwcms-69211185e5578b72d3a0f9e10b5dd3d0b2f0e2a0.tar.gz
wcms-69211185e5578b72d3a0f9e10b5dd3d0b2f0e2a0.zip
auto-media-dir-list
Diffstat (limited to 'app/class/modelrender.php')
-rw-r--r--app/class/modelrender.php53
1 files changed, 49 insertions, 4 deletions
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 = '<ul class="medialist" id="'.$dirid.'">' . PHP_EOL;
+
+ foreach ($medialist as $media) {
+ $ul .= '<li>';
+ if($media->type() == 'image') {
+ $ul .= '<img alt="'.$media->id().'" id="'.$media->id().'" src="'.$media->getfullpath().'" >';
+ } elseif ($media->type() == 'sound') {
+ $ul .= '<audio id="'.$media->id().'" controls src="'.$media->getfullpath().'" </audio>';
+ } elseif ($media->type() == 'video') {
+ $ul .= '<video controls><source src="'.$media->getfullpath().'" type="video/'.$media->extension().'"></video>';
+ } elseif ($media->type() == 'other') {
+ $ul .= '<a href="'.$media->getfullpath().'" target="_blank" class="media" >'.$media->id().'.'.$media->extension().'</a>';
+ }
+ $ul .= '</li>' . PHP_EOL;
+ }
+
+ $ul .= '</ul>' . PHP_EOL;
+
+ return $ul;
+ } else {
+ return 'directory not founded';
+ }
+ }, $text);
+
+ return $text;
+ }
+
function sumparser($text)