aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
Diffstat (limited to 'app/class')
-rw-r--r--app/class/media.php14
-rw-r--r--app/class/medialist.php102
-rw-r--r--app/class/modelrender.php53
3 files changed, 152 insertions, 17 deletions
diff --git a/app/class/media.php b/app/class/media.php
index cd6c6f0..4b947fc 100644
--- a/app/class/media.php
+++ b/app/class/media.php
@@ -13,7 +13,7 @@ class Media
const IMAGE = array('jpg', 'jpeg', 'gif', 'png');
const SOUND = array('mp3', 'flac');
- const VIDEO = array('mp4', 'mov', 'avi');
+ const VIDEO = array('mp4', 'mov', 'avi', 'mkv');
@@ -98,9 +98,13 @@ class Media
return $this->type;
}
- public function size()
+ public function size($display = 'binary')
{
- return $this->size;
+ if($display == 'hr') {
+ return readablesize($this->size);
+ } else {
+ return $this->size;
+ }
}
public function width()
@@ -122,8 +126,8 @@ class Media
public function setid($id)
{
- if (strlen($id) < 40 and is_string($id)) {
- $this->id = strip_tags(strtolower($id));
+ if (is_string($id)) {
+ $this->id = $id;
}
}
diff --git a/app/class/medialist.php b/app/class/medialist.php
new file mode 100644
index 0000000..f3bdac5
--- /dev/null
+++ b/app/class/medialist.php
@@ -0,0 +1,102 @@
+<?php
+
+class Medialist
+{
+ /** @var string full regex match */
+ protected $fullmatch;
+ /** @var string options */
+ protected $options = '';
+ /** @var string directory of media */
+ protected $path = '';
+ /** @var string */
+ protected $sortby = 'id';
+ /** @var string */
+ protected $order = 1;
+ /** @var string */
+ protected $recursive = 'id';
+
+ const SORT_BY_OPTIONS = ['id', 'size'];
+
+
+
+ // __________________________________________________ F U N ____________________________________________________________
+
+
+
+ public function __construct(array $datas = [])
+ {
+ $this->hydrate($datas);
+ $this->readoptions();
+
+ }
+
+ public function hydrate($datas)
+ {
+ foreach ($datas as $key => $value) {
+ $method = 'set' . $key;
+
+ if (method_exists($this, $method)) {
+ $this->$method($value);
+ }
+ }
+ }
+
+ public function readoptions()
+ {
+ parse_str($this->options, $datas);
+ $this->hydrate($datas);
+ }
+
+
+ // __________________________________________________ G E T ____________________________________________________________
+
+
+ public function fullmatch()
+ {
+ return $this->fullmatch;
+ }
+
+ public function options()
+ {
+ return $this->options;
+ }
+
+
+
+ // __________________________________________________ S E T ____________________________________________________________
+
+
+ public function setfullmatch(string $fullmatch)
+ {
+ $this->fullmatch = $fullmatch;
+ }
+
+
+ public function setoptions(string $options)
+ {
+ if(!empty($options)) {
+ $this->options = $options;
+ }
+ }
+
+ public function setpath(string $path)
+ {
+ $this->path = $path;
+ }
+
+ public function setsortby(string $sortby)
+ {
+ if(in_array($sortby, self::SORT_BY_OPTIONS)) {
+ $this->sortby = $sortby;
+ }
+ }
+
+ public function setorder(int $order)
+ {
+ if($order === -1 || $order === 1) {
+ $this->order = $order;
+ }
+ }
+
+
+} \ No newline at end of file
diff --git a/app/class/modelrender.php b/app/class/modelrender.php
index 553442d..b5c8552 100644
--- a/app/class/modelrender.php
+++ b/app/class/modelrender.php
@@ -94,14 +94,17 @@ class Modelrender extends Modelart
$matches[$key] = ['fullmatch' => $match, 'type' => $out[1][$key], 'options' => $out[2][$key]];
}
- // First, analyse the synthax and call the corresponding methods
- foreach ($matches as $key => $match) {
- $element = new Element($match, $this->art->id());
- $element->setcontent($this->getelementcontent($element));
- $element->setcontent($this->elementparser($element));
- $element->addtags();
- $body = str_replace($element->fullmatch(), $element->content(), $body);
+ // First, analyse the synthax and call the corresponding methods
+ if(isset($matches)) {
+ foreach ($matches as $key => $match) {
+ $element = new Element($match, $this->art->id());
+ $element->setcontent($this->getelementcontent($element));
+ $element->setcontent($this->elementparser($element));
+ $element->addtags();
+ $body = str_replace($element->fullmatch(), $element->content(), $body);
+
+ }
}
@@ -394,8 +397,34 @@ class Modelrender extends Modelart
return $text;
}
- public function automedialist(string $text) : string
+ /**
+ * Check for media list call in the text and insert media list
+ * @param string $text Text to scan and replace
+ *
+ * @return string Output text
+ */
+ public function automedialist(string $text)
+ {
+ preg_match_all('~\%MEDIA\?([a-zA-Z0-9\&=\-\/\%]*)\%~', $text, $out);
+
+ foreach ($out[0] as $key => $match) {
+ $matches[$key] = ['fullmatch' => $match, 'options' => $out[1][$key]];
+ }
+
+ if(isset($matches)) {
+ foreach ($matches as $match) {
+ $medialist = new Medialist($match);
+ }
+ }
+
+ return $text;
+ }
+
+ public function aautomedialist(string $text) : string
{
+
+
+
$text = preg_replace_callback(
'~\%MEDIA:(([a-z0-9-_]+(\/([a-z0-9-_])+)*))\%~',
function ($matches) {
@@ -409,10 +438,10 @@ class Modelrender extends Modelart
$dirid = str_replace('/', '-', $dir);
- $ul = '<ul class="medialist" id="' . $dirid . '">' . PHP_EOL;
+ $ul = '<div class="medialist" id="' . $dirid . '">' . PHP_EOL;
foreach ($medialist as $media) {
- $ul .= '<li>';
+ $ul .= '<div class="content ' . $media->type() . '">';
if ($media->type() == 'image') {
$ul .= '<img alt="' . $media->id() . '" id="' . $media->id() . '" src="' . $media->getincludepath() . '" >';
} elseif ($media->type() == 'sound') {
@@ -422,10 +451,10 @@ class Modelrender extends Modelart
} elseif ($media->type() == 'other') {
$ul .= '<a href="' . $media->getincludepath() . '" target="_blank" class="media" >' . $media->id() . '.' . $media->extension() . '</a>';
}
- $ul .= '</li>' . PHP_EOL;
+ $ul .= '</div>' . PHP_EOL;
}
- $ul .= '</ul>' . PHP_EOL;
+ $ul .= '</div>' . PHP_EOL;
return $ul;
} else {