blob: da5ba4f5f05339549404296a27c3005d1007732d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
<?php
namespace Wcms;
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 int */
protected $order = 1;
/** @var int display media contents*/
protected $display = 1;
/** @var int display download links*/
protected $links = 0;
/** @var string ouput html code generated*/
protected $content = '';
const SORT_BY_OPTIONS = ['id', 'size', 'type'];
// __________________________________________________ F U N ____________________________________________________________
public function __construct(array $datas = [])
{
$this->hydrate($datas);
$this->readoptions();
$this->generatecontent();
}
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);
}
public function generatecontent()
{
$mediamanager = new Modelmedia();
$medialist = $mediamanager->getlistermedia(Model::MEDIA_DIR . $this->path . '/');
if (!$medialist) {
$this->content = '<strong>RENDERING ERROR :</strong> path : <code>' . Model::MEDIA_DIR . $this->path . '/</code> does not exist';
return false;
} else {
$mediamanager->medialistsort($medialist, $this->sortby, $this->order);
$dirid = str_replace('/', '-', $this->path);
$div = '<div class="medialist" id="' . $dirid . '">' . PHP_EOL;
foreach ($medialist as $media) {
$div .= '<div class="content ' . $media->type() . '">';
if ($media->type() == 'image') {
$div .= '<img alt="' . $media->id() . '" id="' . $media->id() . '" src="' . $media->getincludepath() . '" >';
} elseif ($media->type() == 'sound') {
$div .= '<audio id="' . $media->id() . '" controls src="' . $media->getincludepath() . '" </audio>';
} elseif ($media->type() == 'video') {
$div .= '<video controls><source src="' . $media->getincludepath() . '" type="video/' . $media->extension() . '"></video>';
} elseif ($media->type() == 'other') {
$div .= '<a href="' . $media->getincludepath() . '" target="_blank" class="media" >' . $media->id() . '.' . $media->extension() . '</a>';
}
$div .= '</div>' . PHP_EOL;
}
$div .= '</div>' . PHP_EOL;
$this->content = $div;
return true;
}
}
// __________________________________________________ G E T ____________________________________________________________
public function fullmatch()
{
return $this->fullmatch;
}
public function options()
{
return $this->options;
}
public function content()
{
return $this->content;
}
// __________________________________________________ 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;
}
}
}
|