ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilWACPath.php
Go to the documentation of this file.
1<?php
2
9class ilWACPath {
10
11 const DIR_DATA = "data";
12 const DIR_SEC = "sec";
16 const REGEX = "(?<prefix>.*?)(?<path>(?<path_without_query>(?<secure_path_id>(?<module_path>\/data\/(?<client>[\w-\.]*)\/(?<sec>sec\/|)(?<module_type>.*?)\/(?<module_identifier>.*\/|)))(?<appendix>[^\?\n]*)).*)";
20 protected static $image_suffixes = array(
21 'png',
22 'jpg',
23 'jpeg',
24 'gif',
25 'svg',
26 );
30 protected static $video_suffixes = array(
31 'mp4',
32 'm4v',
33 'mov',
34 'wmv',
35 'webm',
36 );
40 protected static $audio_suffixes = array(
41 'mp3',
42 'aiff',
43 'aif',
44 'm4a',
45 'wav',
46 );
50 protected $client = '';
54 protected $parameters = array();
58 protected $in_sec_folder = false;
62 protected $token = '';
66 protected $timestamp = 0;
70 protected $ttl = 0;
74 protected $secure_path = '';
78 protected $secure_path_id = '';
82 protected $original_request = '';
86 protected $file_name = '';
90 protected $query = '';
94 protected $suffix = '';
98 protected $prefix = '';
102 protected $appendix = '';
106 protected $module_path = '';
110 protected $path = '';
114 protected $module_type = '';
118 protected $module_identifier = '';
122 protected $path_without_query = '';
123
124
130 public function __construct($path) {
132 $re = '/' . self::REGEX . '/';
133 preg_match($re, $path, $result);
134
135 foreach ($result as $k => $v) {
136 if (is_numeric($k)) {
137 unset($result[$k]);
138 }
139 }
140
141 $this->setPrefix($result['prefix']);
142 $this->setClient($result['client']);
143 $this->setAppendix($result['appendix']);
144 $this->setModuleIdentifier(strstr($result['module_identifier'], "/", true));
145 $this->setModuleType($result['module_type']);
146 if ($this->getModuleIdentifier()) {
147 $this->setModulePath('.' . strstr($result['module_path'], $this->getModuleIdentifier(), true));
148 }else {
149 $this->setModulePath('.' . $result['module_path']);
150 }
151 $this->setInSecFolder($result['sec'] == 'sec/');
152 $this->setPathWithoutQuery('.' . $result['path_without_query']);
153 $this->setPath('.' . $result['path']);
154 $this->setSecurePath('.' . $result['secure_path_id']);
155 $this->setSecurePathId($result['module_type']);
156 // Pathinfo
157 $parts = parse_url($path);
158 $this->setFileName(basename($parts['path']));
159 if (isset($parts['query'])) {
160 $parts_query = $parts['query'];
161 $this->setQuery($parts_query);
162 parse_str($parts_query, $query);
163 $this->setParameters($query);
164 }
165 $this->setSuffix(pathinfo($parts['path'], PATHINFO_EXTENSION));
166 $this->handleParameters();
167 }
168
169
170 protected function handleParameters() {
171 $param = $this->getParameters();
172 if (isset($param[ilWACSignedPath::WAC_TOKEN_ID])) {
174 }
175 if (isset($param[ilWACSignedPath::WAC_TIMESTAMP_ID])) {
177 }
178 if (isset($param[ilWACSignedPath::WAC_TTL_ID])) {
179 $this->setTTL($param[ilWACSignedPath::WAC_TTL_ID]);
180 }
181 }
182
183
187 public function getParameters() {
188 return $this->parameters;
189 }
190
191
195 public function setParameters($parameters) {
196 $this->parameters = $parameters;
197 }
198
199
203 public static function getAudioSuffixes() {
205 }
206
207
211 public static function setAudioSuffixes($audio_suffixes) {
212 self::$audio_suffixes = $audio_suffixes;
213 }
214
215
219 public static function getImageSuffixes() {
221 }
222
223
227 public static function setImageSuffixes($image_suffixes) {
228 self::$image_suffixes = $image_suffixes;
229 }
230
231
235 public static function getVideoSuffixes() {
237 }
238
239
243 public static function setVideoSuffixes($video_suffixes) {
244 self::$video_suffixes = $video_suffixes;
245 }
246
247
251 public function getPrefix() {
252 return $this->prefix;
253 }
254
255
259 public function setPrefix($prefix) {
260 $this->prefix = $prefix;
261 }
262
263
267 public function getAppendix() {
268 return $this->appendix;
269 }
270
271
275 public function setAppendix($appendix) {
276 $this->appendix = $appendix;
277 }
278
279
283 public function getModulePath() {
284 return $this->module_path;
285 }
286
287
291 public function setModulePath($module_path) {
292 $this->module_path = $module_path;
293 }
294
295
299 public function getDirName() {
300 return dirname($this->getPathWithoutQuery());
301 }
302
303
307 public function getPathWithoutQuery() {
309 }
310
311
316 $this->path_without_query = $path_without_query;
317 }
318
319
323 public function isImage() {
324 return in_array(strtolower($this->getSuffix()), self::$image_suffixes);
325 }
326
327
331 public function getSuffix() {
332 return $this->suffix;
333 }
334
335
339 public function setSuffix($suffix) {
340 $this->suffix = $suffix;
341 }
342
343
347 public function isStreamable() {
348 return ($this->isAudio() || $this->isVideo());
349 }
350
351
355 public function isAudio() {
356 return in_array(strtolower($this->getSuffix()), self::$audio_suffixes);
357 }
358
359
363 public function isVideo() {
364 return in_array(strtolower($this->getSuffix()), self::$video_suffixes);
365 }
366
367
371 public function fileExists() {
372 return is_file($this->getPathWithoutQuery());
373 }
374
375
379 public function hasToken() {
380 return ($this->token != '');
381 }
382
383
387 public function hasTimestamp() {
388 return ($this->timestamp != 0);
389 }
390
391
395 public function hasTTL() {
396 return ($this->ttl != 0);
397 }
398
399
403 public function getToken() {
404 return $this->token;
405 }
406
407
411 public function setToken($token) {
412 $this->parameters[ilWACSignedPath::WAC_TOKEN_ID] = $token;
413 $this->token = $token;
414 }
415
416
420 public function getTimestamp() {
421 return $this->timestamp;
422 }
423
424
428 public function setTimestamp($timestamp) {
430 $this->timestamp = $timestamp;
431 }
432
433
437 public function getTTL() {
438 return $this->ttl;
439 }
440
441
445 public function setTTL($ttl) {
446 $this->parameters[ilWACSignedPath::WAC_TTL_ID] = $ttl;
447 $this->ttl = $ttl;
448 }
449
450
454 public function getClient() {
455 return $this->client;
456 }
457
458
462 public function setClient($client) {
463 $this->client = $client;
464 }
465
466
470 public function getSecurePathId() {
472 }
473
474
479 $this->secure_path_id = $secure_path_id;
480 }
481
482
486 public function getPath() {
487 return $this->path;
488 }
489
490
494 public function setPath($path) {
495 $this->path = $path;
496 }
497
498
502 public function getQuery() {
503 return $this->query;
504 }
505
506
510 public function setQuery($query) {
511 $this->query = $query;
512 }
513
514
518 public function getFileName() {
519 return $this->file_name;
520 }
521
522
526 public function setFileName($file_name) {
527 $this->file_name = $file_name;
528 }
529
530
534 public function getOriginalRequest() {
536 }
537
538
543 $this->original_request = $original_request;
544 }
545
546
550 public function getSecurePath() {
551 return $this->secure_path;
552 }
553
554
558 public function setSecurePath($secure_path) {
559 $this->secure_path = $secure_path;
560 }
561
562
566 public function isInSecFolder() {
568 }
569
570
575 $this->in_sec_folder = $in_sec_folder;
576 }
577
578
582 public function getModuleType() {
583 return $this->module_type;
584 }
585
586
590 public function setModuleType($module_type) {
591 $this->module_type = $module_type;
592 }
593
594
598 public function getModuleIdentifier() {
600 }
601
602
607 $this->module_identifier = $module_identifier;
608 }
609}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilWACPath.
setAppendix($appendix)
setOriginalRequest($original_request)
setSecurePathId($secure_path_id)
setParameters($parameters)
static getAudioSuffixes()
static setAudioSuffixes($audio_suffixes)
setClient($client)
static $video_suffixes
static getImageSuffixes()
setQuery($query)
setToken($token)
setModuleIdentifier($module_identifier)
static setImageSuffixes($image_suffixes)
setModulePath($module_path)
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)
static setVideoSuffixes($video_suffixes)
setSuffix($suffix)
setTimestamp($timestamp)
static $image_suffixes
setSecurePath($secure_path)
setFileName($file_name)
setPrefix($prefix)
static $audio_suffixes
setPathWithoutQuery($path_without_query)
static getVideoSuffixes()