ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilWACPath.php
Go to the documentation of this file.
1<?php
25{
26 const DIR_DATA = "data";
27 const DIR_SEC = "sec";
31 const REGEX = "(?<prefix>.*?)(?<path>(?<path_without_query>(?<secure_path_id>(?<module_path>\/data\/(?<client>[\w\-\.]*)\/(?<sec>sec\/|)(?<module_type>.*?)\/(?<module_identifier>.*\/|)))(?<appendix>[^\?\n]*)).*)";
35 protected static $image_suffixes = array(
36 'png',
37 'jpg',
38 'jpeg',
39 'gif',
40 'svg',
41 );
45 protected static $video_suffixes = array(
46 'mp4',
47 'm4v',
48 'mov',
49 'wmv',
50 'webm',
51 );
55 protected static $audio_suffixes = array(
56 'mp3',
57 'aiff',
58 'aif',
59 'm4a',
60 'wav',
61 );
65 protected $client = '';
69 protected $parameters = array();
73 protected $in_sec_folder = false;
77 protected $token = '';
81 protected $timestamp = 0;
85 protected $ttl = 0;
89 protected $secure_path = '';
93 protected $secure_path_id = '';
97 protected $original_request = '';
101 protected $file_name = '';
105 protected $query = '';
109 protected $suffix = '';
113 protected $prefix = '';
117 protected $appendix = '';
121 protected $module_path = '';
125 protected $path = '';
129 protected $module_type = '';
133 protected $module_identifier = '';
137 protected $path_without_query = '';
138
139
145 public function __construct($path)
146 {
147 assert(is_string($path));
149 $re = '/' . self::REGEX . '/';
150 preg_match($re, $path, $result);
151
152 $url_parts = parse_url($path);
153 $result['path_without_query'] = $url_parts['path'];
154
155 foreach ($result as $k => $v) {
156 if (is_numeric($k)) {
157 unset($result[$k]);
158 }
159 }
160
161 $moduleId = strstr(is_null($result['module_identifier']) ? '' : $result['module_identifier'], "/", true);
162 $moduleId = $moduleId === false ? '' : $moduleId;
163
164 $this->setPrefix(is_null($result['prefix']) ? '' : $result['prefix']);
165 $this->setClient(is_null($result['client']) ? '' : $result['client']);
166 $this->setAppendix(is_null($result['appendix']) ? '' : $result['appendix']);
167 $this->setModuleIdentifier($moduleId);
168 $this->setModuleType(is_null($result['module_type']) ? '' : $result['module_type']);
169
170 $modulePath = null;
171
172 if ($this->getModuleIdentifier()) {
173 $modulePath = strstr(is_null($result['module_path']) ? '' : $result['module_path'], $this->getModuleIdentifier(), true);
174 $modulePath = '.' . ($modulePath === false ? '' : $modulePath);
175 } else {
176 $modulePath = ('.' . (is_null($result['module_path']) ? '' : $result['module_path']));
177 }
178
179 $this->setModulePath("$modulePath");
180 $this->setInSecFolder($result['sec'] === 'sec/');
181 $this->setPathWithoutQuery('.'
182 . (is_null($result['path_without_query']) ? '' : $result['path_without_query']));
183 $this->setPath('.' . (is_null($result['path']) ? '' : $result['path']));
184 $this->setSecurePath('.'
185 . (is_null($result['secure_path_id']) ? '' : $result['secure_path_id']));
186 $this->setSecurePathId(is_null($result['module_type']) ? '' : $result['module_type']);
187 // Pathinfo
188 $parts = parse_url($path);
189 $this->setFileName(basename($parts['path']));
190 if (isset($parts['query'])) {
191 $parts_query = $parts['query'];
192 $this->setQuery($parts_query);
193 parse_str($parts_query, $query);
194 $this->setParameters($query);
195 }
196 $this->setSuffix(pathinfo($parts['path'], PATHINFO_EXTENSION));
197 $this->handleParameters();
198 }
199
200
201 protected function handleParameters()
202 {
203 $param = $this->getParameters();
205 $this->setToken($param[ilWACSignedPath::WAC_TOKEN_ID]);
206 }
209 }
212 }
213 }
214
215
219 public function getParameters()
220 {
221 return (array) $this->parameters;
222 }
223
224
228 public function setParameters(array $parameters)
229 {
230 $this->parameters = $parameters;
231 }
232
233
237 public static function getAudioSuffixes()
238 {
239 return (array) self::$audio_suffixes;
240 }
241
242
246 public static function setAudioSuffixes(array $audio_suffixes)
247 {
248 self::$audio_suffixes = $audio_suffixes;
249 }
250
251
255 public static function getImageSuffixes()
256 {
257 return (array) self::$image_suffixes;
258 }
259
260
264 public static function setImageSuffixes(array $image_suffixes)
265 {
266 self::$image_suffixes = $image_suffixes;
267 }
268
269
273 public static function getVideoSuffixes()
274 {
275 return (array) self::$video_suffixes;
276 }
277
278
282 public static function setVideoSuffixes(array $video_suffixes)
283 {
284 self::$video_suffixes = $video_suffixes;
285 }
286
287
291 public function getPrefix()
292 {
293 return (string) $this->prefix;
294 }
295
296
300 public function setPrefix($prefix)
301 {
302 assert(is_string($prefix));
303 $this->prefix = $prefix;
304 }
305
306
310 public function getAppendix()
311 {
312 return (string) $this->appendix;
313 }
314
315
319 public function setAppendix($appendix)
320 {
321 assert(is_string($appendix));
322 $this->appendix = $appendix;
323 }
324
325
329 public function getModulePath()
330 {
331 return (string) $this->module_path;
332 }
333
334
339 {
340 assert(is_string($module_path));
341 $this->module_path = $module_path;
342 }
343
344
348 public function getDirName()
349 {
350 return (string) dirname($this->getPathWithoutQuery());
351 }
352
353
357 public function getPathWithoutQuery()
358 {
359 return (string) $this->path_without_query;
360 }
361
362
367 {
368 assert(is_string($path_without_query));
369 $this->path_without_query = $path_without_query;
370 }
371
372
376 public function isImage()
377 {
378 return (bool) in_array(strtolower($this->getSuffix()), self::$image_suffixes);
379 }
380
381
385 public function getSuffix()
386 {
387 return (string) $this->suffix;
388 }
389
390
394 public function setSuffix($suffix)
395 {
396 assert(is_string($suffix));
397 $this->suffix = $suffix;
398 }
399
400
404 public function isStreamable()
405 {
406 return (bool) ($this->isAudio() || $this->isVideo());
407 }
408
409
413 public function isAudio()
414 {
415 return (bool) in_array(strtolower($this->getSuffix()), self::$audio_suffixes);
416 }
417
418
422 public function isVideo()
423 {
424 return (bool) in_array(strtolower($this->getSuffix()), self::$video_suffixes);
425 }
426
427
431 public function fileExists()
432 {
433 return (bool) is_file($this->getPathWithoutQuery());
434 }
435
436
440 public function hasToken()
441 {
442 return (bool) ($this->token !== '');
443 }
444
445
449 public function hasTimestamp()
450 {
451 return (bool) ($this->timestamp !== 0);
452 }
453
454
458 public function hasTTL()
459 {
460 return (bool) ($this->ttl !== 0);
461 }
462
463
467 public function getToken()
468 {
469 return (string) $this->token;
470 }
471
472
476 public function setToken($token)
477 {
478 assert(is_string($token));
479 $this->parameters[ilWACSignedPath::WAC_TOKEN_ID] = $token;
480 $this->token = $token;
481 }
482
483
487 public function getTimestamp()
488 {
489 return (int) $this->timestamp;
490 }
491
492
496 public function setTimestamp($timestamp)
497 {
498 assert(is_int($timestamp));
500 $this->timestamp = $timestamp;
501 }
502
503
507 public function getTTL()
508 {
509 return (int) $this->ttl;
510 }
511
512
516 public function setTTL($ttl)
517 {
518 $this->parameters[ilWACSignedPath::WAC_TTL_ID] = $ttl;
519 $this->ttl = $ttl;
520 }
521
522
526 public function getClient()
527 {
528 return (string) $this->client;
529 }
530
531
535 public function setClient($client)
536 {
537 assert(is_string($client));
538 $this->client = $client;
539 }
540
541
545 public function getSecurePathId()
546 {
547 return (string) $this->secure_path_id;
548 }
549
550
555 {
556 assert(is_string($secure_path_id));
557 $this->secure_path_id = $secure_path_id;
558 }
559
560
564 public function getPath()
565 {
566 return (string) $this->path;
567 }
568
569
575 public function getCleanURLdecodedPath()
576 {
577 $path_to_file = rawurldecode($this->getPathWithoutQuery());
578
579 return $path_to_file;
580 }
581
582
586 public function setPath($path)
587 {
588 assert(is_string($path));
589 $this->path = $path;
590 }
591
592
596 public function getQuery()
597 {
598 return (string) $this->query;
599 }
600
601
605 public function setQuery($query)
606 {
607 assert(is_string($query));
608 $this->query = $query;
609 }
610
611
615 public function getFileName()
616 {
617 return (string) $this->file_name;
618 }
619
620
624 public function setFileName($file_name)
625 {
626 assert(is_string($file_name));
627 $this->file_name = $file_name;
628 }
629
630
634 public function getOriginalRequest()
635 {
636 return (string) $this->original_request;
637 }
638
639
644 {
645 assert(is_string($original_request));
646 $this->original_request = $original_request;
647 }
648
649
653 public function getSecurePath()
654 {
655 return (string) $this->secure_path;
656 }
657
658
663 {
664 assert(is_string($secure_path));
665 $this->secure_path = $secure_path;
666 }
667
668
672 public function isInSecFolder()
673 {
674 return (bool) $this->in_sec_folder;
675 }
676
677
682 {
683 assert(is_bool($in_sec_folder));
684 $this->in_sec_folder = $in_sec_folder;
685 }
686
687
691 public function getModuleType()
692 {
693 return (string) $this->module_type;
694 }
695
696
701 {
702 assert(is_string($module_type));
703 $this->module_type = $module_type;
704 }
705
706
710 public function getModuleIdentifier()
711 {
712 return (string) $this->module_identifier;
713 }
714
715
720 {
721 assert(is_string($module_identifier));
722 $this->module_identifier = $module_identifier;
723 }
724}
$result
An exception for terminatinating execution or to throw for unit testing.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setAppendix($appendix)
setOriginalRequest($original_request)
setSecurePathId($secure_path_id)
static getAudioSuffixes()
setClient($client)
static $video_suffixes
static getImageSuffixes()
setQuery($query)
setToken($token)
static setAudioSuffixes(array $audio_suffixes)
getCleanURLdecodedPath()
Returns a clean (everything behind ? is removed and rawurldecoded path.
setModuleIdentifier($module_identifier)
setModulePath($module_path)
static setVideoSuffixes(array $video_suffixes)
const REGEX
Copy this without to regex101.com and test with some URL of files.
setModuleType($module_type)
__construct($path)
ilWACPath constructor.
setInSecFolder($in_sec_folder)
setSuffix($suffix)
setTimestamp($timestamp)
static $image_suffixes
setSecurePath($secure_path)
setParameters(array $parameters)
static setImageSuffixes(array $image_suffixes)
setFileName($file_name)
setPrefix($prefix)
static $audio_suffixes
setPathWithoutQuery($path_without_query)
static getVideoSuffixes()
$param
Definition: xapitoken.php:31