ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExternalMediaAnalyzer.php
Go to the documentation of this file.
1<?php
2
26{
30 public static function isYouTube(
31 string $a_location
32 ): bool {
33 if (strpos($a_location, "youtube.com") > 0 ||
34 strpos($a_location, "youtu.be") > 0) {
35 return true;
36 }
37 return false;
38 }
39
44 public static function extractYouTubeParameters(
45 string $a_location
46 ): array {
47 $par = array();
48 $pos1 = strpos($a_location, "v=");
49 $pos2 = strpos($a_location, "&", $pos1);
50 if ($pos1 > 0) {
51 $len = ($pos2 > 0)
52 ? $pos2
53 : strlen($a_location);
54 $par["v"] = substr($a_location, $pos1 + 2, $len - ($pos1 + 2));
55 } elseif (strpos($a_location, "youtu.be") > 0) {
56 $par["v"] = substr($a_location, strrpos($a_location, "/") + 1);
57 }
58 $qpos = strpos($par["v"] ?? "", "?");
59 if (is_int($qpos)) {
60 $par["v"] = substr($par["v"], 0, $qpos);
61 }
62 return $par;
63 }
64
68 public static function isFlickr(
69 string $a_location
70 ): bool {
71 if (strpos($a_location, "flickr.com") > 0) {
72 return true;
73 }
74 return false;
75 }
76
81 public static function extractFlickrParameters(
82 string $a_location
83 ): array {
84 $par = array();
85 $pos1 = strpos($a_location, "flickr.com/photos/");
86 $pos2 = strpos($a_location, "/", $pos1 + 18);
87 if ($pos1 > 0) {
88 $len = ($pos2 > 0)
89 ? $pos2
90 : $a_location;
91 $par["user_id"] = substr($a_location, $pos1 + 18, $len - ($pos1 + 18));
92 }
93
94 // tags
95 $pos1 = strpos($a_location, "/tags/");
96 $pos2 = strpos($a_location, "/", $pos1 + 6);
97 if ($pos1 > 0) {
98 $len = ($pos2 > 0)
99 ? $pos2
100 : strlen($a_location);
101 $par["tags"] = substr($a_location, $pos1 + 6, $len - ($pos1 + 6));
102 }
103
104 // sets
105 $pos1 = strpos($a_location, "/sets/");
106 $pos2 = strpos($a_location, "/", $pos1 + 6);
107 if ($pos1 > 0) {
108 $len = ($pos2 > 0)
109 ? $pos2
110 : $a_location;
111 $par["sets"] = substr($a_location, $pos1 + 6, $len - ($pos1 + 6));
112 }
113
114 return $par;
115 }
116
120 public static function isGoogleVideo(
121 string $a_location
122 ): bool {
123 if (strpos($a_location, "video.google") > 0) {
124 return true;
125 }
126 return false;
127 }
128
133 public static function extractGoogleVideoParameters(
134 string $a_location
135 ): array {
136 $par = array();
137 $pos1 = strpos($a_location, "docid=");
138 $pos2 = strpos($a_location, "&", $pos1 + 6);
139 if ($pos1 > 0) {
140 $len = ($pos2 > 0)
141 ? $pos2
142 : strlen($a_location);
143 $par["docid"] = substr($a_location, $pos1 + 6, $len - ($pos1 + 6));
144 }
145
146 return $par;
147 }
148
152 public static function isVimeo(
153 string $a_location
154 ): bool {
155 if (strpos($a_location, "vimeo.com") > 0) {
156 return true;
157 }
158 return false;
159 }
160
165 public static function extractVimeoParameters(
166 string $a_location
167 ): array {
168 $par = array();
169 $pos1 = strpos($a_location, "vimeo.com/");
170 $pos2 = strpos($a_location, "&", $pos1 + 10);
171 if ($pos1 > 0) {
172 $len = ($pos2 > 0)
173 ? $pos2
174 : strlen($a_location);
175 $par["id"] = substr($a_location, $pos1 + 10, $len - ($pos1 + 10));
176 }
177
178 return $par;
179 }
180
181 public static function getVimeoMetadata(string $vid): array
182 {
183 $json_url = 'https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/' . $vid;
184
185 $curl = curl_init($json_url);
186 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
187 curl_setopt($curl, CURLOPT_TIMEOUT, 10);
188 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
189 curl_setopt($curl, CURLOPT_REFERER, ILIAS_HTTP_PATH);
190
191 $return = curl_exec($curl);
192 curl_close($curl);
193
194 $r = json_decode($return, true);
195
196 if ($return === false || is_null($r)) {
197 throw new ilExternalMediaApiException("Could not connect to vimeo API at $json_url.");
198 }
199 return $r;
200 }
201
202 public static function getYoutubeMetadata(string $vid): array
203 {
204 $json_url = 'https://www.youtube.com/oembed?url=http%3A//youtube.com/watch%3Fv%3D' . $vid . '&format=json';
205 $curl = curl_init($json_url);
206 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
207 curl_setopt($curl, CURLOPT_TIMEOUT, 10);
208 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
209 curl_setopt($curl, CURLOPT_REFERER, ILIAS_HTTP_PATH);
210
211 $return = curl_exec($curl);
212 curl_close($curl);
213
214 $r = json_decode($return, true);
215
216 if ($return === false || is_null($r)) {
217 throw new ilExternalMediaApiException("Could not connect to youtube API at $json_url.");
218 }
219 return $r;
220 }
221
225 public static function isGoogleDocument(
226 string $a_location
227 ): bool {
228 if (strpos($a_location, "docs.google") > 0) {
229 return true;
230 }
231 return false;
232 }
233
238 public static function extractGoogleDocumentParameters(
239 string $a_location
240 ): array {
241 $par = array();
242 $pos1 = strpos($a_location, "id=");
243 $pos2 = strpos($a_location, "&", $pos1 + 3);
244 if ($pos1 > 0) {
245 $len = ($pos2 > 0)
246 ? $pos2
247 : strlen($a_location);
248 $par["docid"] = substr($a_location, $pos1 + 3, $len - ($pos1 + 3));
249 }
250 $pos1 = strpos($a_location, "docID=");
251 $pos2 = strpos($a_location, "&", $pos1 + 6);
252 if ($pos1 > 0) {
253 $len = ($pos2 > 0)
254 ? $pos2
255 : strlen($a_location);
256 $par["docid"] = substr($a_location, $pos1 + 6, $len - ($pos1 + 6));
257 }
258 if (strpos($a_location, "Presentation?") > 0) {
259 $par["type"] = "Presentation";
260 }
261 if (strpos($a_location, "View?") > 0) {
262 $par["type"] = "Document";
263 }
264
265 return $par;
266 }
267
272 public static function extractUrlParameters(
273 string $a_location,
274 array $a_parameter
275 ): array {
276 $ext_par = array();
277
278 // YouTube
279 if (ilExternalMediaAnalyzer::isYouTube($a_location)) {
281 $a_parameter = array();
282 }
283
284 // Flickr
285 if (ilExternalMediaAnalyzer::isFlickr($a_location)) {
287 $a_parameter = array();
288 }
289
290 // GoogleVideo
293 $a_parameter = array();
294 }
295
296 // GoogleDocs
299 $a_parameter = array();
300 }
301
302 foreach ($ext_par as $name => $value) {
303 $a_parameter[$name] = $value;
304 }
305
306 return $a_parameter;
307 }
308}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static extractYouTubeParameters(string $a_location)
Extract YouTube Parameter.
static isGoogleDocument(string $a_location)
Identify Google Document links.
static extractGoogleVideoParameters(string $a_location)
Extract GoogleVideo Parameter.
static isVimeo(string $a_location)
Identify Vimeo links.
static isYouTube(string $a_location)
Identify YouTube links.
static extractFlickrParameters(string $a_location)
Extract Flickr Parameter.
static extractGoogleDocumentParameters(string $a_location)
Extract GoogleDocument Parameter.
static isGoogleVideo(string $a_location)
Identify GoogleVideo links.
static isFlickr(string $a_location)
Identify Flickr links.
static extractVimeoParameters(string $a_location)
Extract Vimeo Parameter.
static extractUrlParameters(string $a_location, array $a_parameter)
Extract URL information to parameter array.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))