ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilWACPath.php
Go to the documentation of this file.
1 <?php
2 
9 class ilWACPath {
10 
11  const DIR_DATA = "data";
12  const DIR_SEC = "sec";
16  protected $client = '';
20  protected $secure_path_id = '';
24  protected $secure_path = '';
28  protected $path = '';
32  protected $suffix = '';
36  protected $query = '';
40  protected $parameters = array();
44  protected $file_name = '';
48  protected $original_request = '';
52  protected $path_without_query = '';
56  protected $in_sec_folder = false;
60  protected $token = '';
64  protected $timestamp = 0;
68  protected $ttl = 0;
72  protected static $image_suffixes = array(
73  'png',
74  'jpg',
75  'jpeg',
76  'gif',
77  'svg',
78  );
82  protected static $video_suffixes = array(
83  'mp4',
84  'm4v',
85  'mov',
86  'wmv',
87  'webm',
88  );
92  protected static $audio_suffixes = array(
93  'mp3',
94  'aiff',
95  'aif',
96  'wav',
97  );
98 
99 
105  public function __construct($path) {
106  $this->setOriginalRequest($path);
107 
108  $regex_client = "[\\w-\\.]*";
109 
110  preg_match("/\\/" . self::DIR_DATA . "\\/({$regex_client})\\/(" . self::DIR_SEC . "\\/|)([\\w]*)\\/(.*)/ui", $path, $results);
111  preg_match("/(\\/" . self::DIR_DATA . "\\/{$regex_client}\\/[\\w]*\\/.*)\\?/ui", $path, $results2);
112  $this->setPathWithoutQuery(isset($results2[1]) ? '.' . $results2[1] : '.' . $results[0]);
113  $this->setPath('.' . $results[0]);
114  $this->setClient($results[1]);
115  $this->setInSecFolder($results[2] == 'sec/');
116  $this->setSecurePathId($results[3]);
117  $parts = parse_url($path);
118  $this->setFileName(basename($parts['path']));
119  if (isset($parts['query'])) {
120  $parts_query = $parts['query'];
121  $this->setQuery($parts_query);
122  parse_str($parts_query, $query);
123  $this->setParameters($query);
124  }
125  $this->setSuffix(pathinfo($parts['path'], PATHINFO_EXTENSION));
126  preg_match("/\\/" . self::DIR_DATA . "\\/({$regex_client})\\/(" . self::DIR_SEC
127  . "\\/[\\w]*\\/[\\d]*\\/|[\\w]*\\/)([\\w]*)\\//ui", $path, $results3);
128  $this->setSecurePath(isset($results3[0]) ? '.' . $results3[0] : null);
129  $this->handleParameters();
130  }
131 
132 
133  protected function handleParameters() {
134  $param = $this->getParameters();
135  if (isset($param[ilWACSignedPath::WAC_TOKEN_ID])) {
136  $this->setToken($param[ilWACSignedPath::WAC_TOKEN_ID]);
137  }
138  if (isset($param[ilWACSignedPath::WAC_TIMESTAMP_ID])) {
139  $this->setTimestamp($param[ilWACSignedPath::WAC_TIMESTAMP_ID]);
140  }
141  if (isset($param[ilWACSignedPath::WAC_TTL_ID])) {
142  $this->setTTL($param[ilWACSignedPath::WAC_TTL_ID]);
143  }
144  }
145 
146 
150  public function getDirName() {
151  return dirname($this->getPathWithoutQuery());
152  }
153 
154 
158  public function isImage() {
159  return in_array(strtolower($this->getSuffix()), self::$image_suffixes);
160  }
161 
162 
166  public function isVideo() {
167  return in_array(strtolower($this->getSuffix()), self::$video_suffixes);
168  }
169 
170 
174  public function isAudio() {
175  return in_array(strtolower($this->getSuffix()), self::$audio_suffixes);
176  }
177 
178 
182  public function isStreamable() {
183  return ($this->isAudio() || $this->isVideo());
184  }
185 
186 
190  public function fileExists() {
191  return is_file($this->getPathWithoutQuery());
192  }
193 
194 
198  public function hasToken() {
199  return ($this->token != '');
200  }
201 
202 
206  public function hasTimestamp() {
207  return ($this->timestamp != 0);
208  }
209 
210 
214  public function hasTTL() {
215  return ($this->ttl != 0);
216  }
217 
218 
222  public function getToken() {
223  return $this->token;
224  }
225 
226 
230  public function setToken($token) {
231  $this->parameters[ilWACSignedPath::WAC_TOKEN_ID] = $token;
232  $this->token = $token;
233  }
234 
235 
239  public function getTimestamp() {
240  return $this->timestamp;
241  }
242 
243 
247  public function setTimestamp($timestamp) {
248  $this->parameters[ilWACSignedPath::WAC_TIMESTAMP_ID] = $timestamp;
249  $this->timestamp = $timestamp;
250  }
251 
252 
256  public function getTTL() {
257  return $this->ttl;
258  }
259 
260 
264  public function setTTL($ttl) {
265  $this->parameters[ilWACSignedPath::WAC_TTL_ID] = $ttl;
266  $this->ttl = $ttl;
267  }
268 
269 
273  public function getClient() {
274  return $this->client;
275  }
276 
277 
281  public function setClient($client) {
282  $this->client = $client;
283  }
284 
285 
289  public function getSecurePathId() {
290  return $this->secure_path_id;
291  }
292 
293 
297  public function setSecurePathId($secure_path_id) {
298  $this->secure_path_id = $secure_path_id;
299  }
300 
301 
305  public function getPath() {
306  return $this->path;
307  }
308 
309 
313  public function setPath($path) {
314  $this->path = $path;
315  }
316 
317 
321  public function getSuffix() {
322  return $this->suffix;
323  }
324 
325 
329  public function setSuffix($suffix) {
330  $this->suffix = $suffix;
331  }
332 
333 
337  public function getQuery() {
338  return $this->query;
339  }
340 
341 
345  public function setQuery($query) {
346  $this->query = $query;
347  }
348 
349 
353  public function getParameters() {
354  return $this->parameters;
355  }
356 
357 
361  public function setParameters($parameters) {
362  $this->parameters = $parameters;
363  }
364 
365 
369  public function getFileName() {
370  return $this->file_name;
371  }
372 
373 
377  public function setFileName($file_name) {
378  $this->file_name = $file_name;
379  }
380 
381 
385  public function getOriginalRequest() {
387  }
388 
389 
394  $this->original_request = $original_request;
395  }
396 
397 
401  public static function getImageSuffixes() {
402  return self::$image_suffixes;
403  }
404 
405 
409  public static function setImageSuffixes($image_suffixes) {
410  self::$image_suffixes = $image_suffixes;
411  }
412 
413 
417  public static function getVideoSuffixes() {
418  return self::$video_suffixes;
419  }
420 
421 
425  public static function setVideoSuffixes($video_suffixes) {
426  self::$video_suffixes = $video_suffixes;
427  }
428 
429 
433  public function getPathWithoutQuery() {
435  }
436 
437 
442  $this->path_without_query = $path_without_query;
443  }
444 
445 
449  public function getSecurePath() {
450  return $this->secure_path;
451  }
452 
453 
457  public function setSecurePath($secure_path) {
458  $this->secure_path = $secure_path;
459  }
460 
461 
465  public function isInSecFolder() {
466  return $this->in_sec_folder;
467  }
468 
469 
473  public function setInSecFolder($in_sec_folder) {
474  $this->in_sec_folder = $in_sec_folder;
475  }
476 }
setPathWithoutQuery($path_without_query)
static $image_suffixes
setQuery($query)
setClient($client)
static $audio_suffixes
static $video_suffixes
Class ilWACPath.
setSuffix($suffix)
setSecurePath($secure_path)
setToken($token)
static getVideoSuffixes()
$results
setTimestamp($timestamp)
static getImageSuffixes()
static setImageSuffixes($image_suffixes)
__construct($path)
ilWACPath constructor.
static setVideoSuffixes($video_suffixes)
setParameters($parameters)
setSecurePathId($secure_path_id)
setFileName($file_name)
setOriginalRequest($original_request)
setInSecFolder($in_sec_folder)