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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
<?php
class Media
{
private $id;
private $path;
private $extension;
private $type;
private $size;
private $width;
private $height;
private $length;
const IMAGE = array('jpg', 'jpeg', 'gif', 'png');
const SOUND = array('mp3', 'flac');
const VIDEO = array('mp4', 'mov', 'avi');
// _____________________________________________________ F U N ____________________________________________________
public function __construct(array $donnees)
{
$this->hydrate($donnees);
}
public function hydrate(array $donnees)
{
foreach ($donnees as $key => $value) {
$method = 'set' . $key;
if (method_exists($this, $method)) {
$this->$method($value);
}
}
}
public function analyse()
{
$this->settype();
$filepath = $this->path . $this->id . '.' . $this->extension;
$this->size = filesize($filepath);
if ($this->type == 'image') {
list($width, $height, $type, $attr) = getimagesize($filepath);
$this->width = $width;
$this->height = $height;
}
}
public function getfullpath()
{
if(!empty(Config::basepath())) {
$base = '/' . Config::basepath();
} else {
$base = '';
}
$fullpath = $base . '/'. $this->path() . $this->id() . '.' . $this->extension();
$fullpath = str_replace('\\', '/', $fullpath);
return $fullpath;
}
public function getincludepath()
{
$includepath = $this->path() . $this->id() . '.' . $this->extension();
$includepath = str_replace('\\', '/', $includepath);
$includepath = substr($includepath, 6);
return $includepath;
}
// _________________________________________________ G E T ____________________________________________________
public function id()
{
return $this->id;
}
public function path()
{
return $this->path;
}
public function extension()
{
return $this->extension;
}
public function type()
{
return $this->type;
}
public function size()
{
return $this->size;
}
public function width()
{
return $this->width;
}
public function height()
{
return $this->height;
}
public function length()
{
return $this->length;
}
// ___________________________________________________ S E T __________________________________________________
public function setid($id)
{
if (strlen($id) < 40 and is_string($id)) {
$this->id = strip_tags(strtolower($id));
}
}
public function setpath($path)
{
if (strlen($path) < 40 and is_string($path)) {
$this->path = strip_tags(strtolower($path));
}
}
public function setextension($extension)
{
if (strlen($extension) < 7 and is_string($extension)) {
$this->extension = strip_tags(strtolower($extension));
}
}
public function settype()
{
if (isset($this->extension)) {
if (in_array($this->extension, $this::IMAGE)) {
$this->type = "image";
} elseif (in_array($this->extension, $this::SOUND)) {
$this->type = "sound";
} elseif (in_array($this->extension, $this::VIDEO)) {
$this->type = "video";
} else {
$this->type = "other";
}
}
}
public function setsize($size)
{
if (40 and is_int($size)) {
$this->size = strip_tags(strtolower($size));
}
}
public function setwidth($width)
{
if (is_int($width)) {
$this->width = strip_tags(strtolower($width));
}
}
public function setheight($height)
{
if (is_int($height)) {
$this->height = strip_tags(strtolower($height));
}
}
public function setlength($length)
{
if ($this->type == 'sound') {
$this->length = $length;
}
}
}
?>
|