ILIAS  release_8 Revision v8.24
AbstractMediaWithPath.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28{
29 public function getContent(): string
30 {
32
33 // the version string is only appended if the content string is not
34 // a data uri, otherwise the data uri will behave incorrectly.
35 if (!$this->isContentDataUri($content)) {
36 if ($this->hasContentParameters($content)) {
37 return rtrim($content, "&") . "&version=" . $this->version;
38 } else {
39 return rtrim($content, "?") . "?version=" . $this->version;
40 }
41 }
42
43 return $content;
44 }
45
46 protected function isContentDataUri(string $content): bool
47 {
48 // regex pattern matches if a string follows the data uri syntax.
49 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs#syntax
50
51 return (bool) preg_match('/^(data:)([a-z\/]*)((;base64)?)(,?)([A-z0-9=\/\+]*)$/', $content);
52 }
53
54 protected function hasContentParameters(string $content): bool
55 {
56 return (strpos($content, "?") !== false);
57 }
58}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...