ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilExternalMediaAnalyzer.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
34{
38 public static function isYouTube($a_location)
39 {
40 if (strpos($a_location, "youtube.com") > 0 ||
41 strpos($a_location, "youtu.be") > 0) {
42 return true;
43 }
44 return false;
45 }
46
50 public static function extractYouTubeParameters($a_location)
51 {
52 $par = array();
53 $pos1 = strpos($a_location, "v=");
54 $pos2 = strpos($a_location, "&", $pos1);
55 if ($pos1 > 0) {
56 $len = ($pos2 > 0)
57 ? $pos2
58 : strlen($a_location);
59 $par["v"] = substr($a_location, $pos1 + 2, $len - ($pos1 + 2));
60 } elseif (strpos($a_location, "youtu.be") > 0) {
61 $par["v"] = substr($a_location, strrpos($a_location, "/") + 1);
62 }
63
64 return $par;
65 }
66
70 public static function isFlickr($a_location)
71 {
72 if (strpos($a_location, "flickr.com") > 0) {
73 return true;
74 }
75 return false;
76 }
77
81 public static function extractFlickrParameters($a_location)
82 {
83 $par = array();
84 $pos1 = strpos($a_location, "flickr.com/photos/");
85 $pos2 = strpos($a_location, "/", $pos1 + 18);
86 if ($pos1 > 0) {
87 $len = ($pos2 > 0)
88 ? $pos2
89 : $a_location;
90 $par["user_id"] = substr($a_location, $pos1 + 18, $len - ($pos1 + 18));
91 }
92
93 // tags
94 $pos1 = strpos($a_location, "/tags/");
95 $pos2 = strpos($a_location, "/", $pos1 + 6);
96 if ($pos1 > 0) {
97 $len = ($pos2 > 0)
98 ? $pos2
99 : strlen($a_location);
100 $par["tags"] = substr($a_location, $pos1 + 6, $len - ($pos1 + 6));
101 }
102
103 // sets
104 $pos1 = strpos($a_location, "/sets/");
105 $pos2 = strpos($a_location, "/", $pos1 + 6);
106 if ($pos1 > 0) {
107 $len = ($pos2 > 0)
108 ? $pos2
109 : $a_location;
110 $par["sets"] = substr($a_location, $pos1 + 6, $len - ($pos1 + 6));
111 }
112
113 return $par;
114 }
115
119 public static function isGoogleVideo($a_location)
120 {
121 if (strpos($a_location, "video.google") > 0) {
122 return true;
123 }
124 return false;
125 }
126
130 public static function extractGoogleVideoParameters($a_location)
131 {
132 $par = array();
133 $pos1 = strpos($a_location, "docid=");
134 $pos2 = strpos($a_location, "&", $pos1 + 6);
135 if ($pos1 > 0) {
136 $len = ($pos2 > 0)
137 ? $pos2
138 : strlen($a_location);
139 $par["docid"] = substr($a_location, $pos1 + 6, $len - ($pos1 + 6));
140 }
141
142 return $par;
143 }
144
148 public static function isVimeo($a_location)
149 {
150 if (strpos($a_location, "vimeo.com") > 0) {
151 return true;
152 }
153 return false;
154 }
155
159 public static function extractVimeoParameters($a_location)
160 {
161 $par = array();
162 $pos1 = strpos($a_location, "vimeo.com/");
163 $pos2 = strpos($a_location, "&", $pos1 + 10);
164 if ($pos1 > 0) {
165 $len = ($pos2 > 0)
166 ? $pos2
167 : strlen($a_location);
168 $par["id"] = substr($a_location, $pos1 + 10, $len - ($pos1 + 10));
169 }
170
171 return $par;
172 }
173
177 public static function isGoogleDocument($a_location)
178 {
179 if (strpos($a_location, "docs.google") > 0) {
180 return true;
181 }
182 return false;
183 }
184
188 public static function extractGoogleDocumentParameters($a_location)
189 {
190 $par = array();
191 $pos1 = strpos($a_location, "id=");
192 $pos2 = strpos($a_location, "&", $pos1 + 3);
193 if ($pos1 > 0) {
194 $len = ($pos2 > 0)
195 ? $pos2
196 : strlen($a_location);
197 $par["docid"] = substr($a_location, $pos1 + 3, $len - ($pos1 + 3));
198 }
199 $pos1 = strpos($a_location, "docID=");
200 $pos2 = strpos($a_location, "&", $pos1 + 6);
201 if ($pos1 > 0) {
202 $len = ($pos2 > 0)
203 ? $pos2
204 : strlen($a_location);
205 $par["docid"] = substr($a_location, $pos1 + 6, $len - ($pos1 + 6));
206 }
207 if (strpos($a_location, "Presentation?") > 0) {
208 $par["type"] = "Presentation";
209 }
210 if (strpos($a_location, "View?") > 0) {
211 $par["type"] = "Document";
212 }
213
214 return $par;
215 }
216
220 public static function extractUrlParameters($a_location, $a_parameter)
221 {
222 if (!is_array($a_parameter)) {
223 $a_parameter = array();
224 }
225
226 $ext_par = array();
227
228 // YouTube
229 if (ilExternalMediaAnalyzer::isYouTube($a_location)) {
231 $a_parameter = array();
232 }
233
234 // Flickr
235 if (ilExternalMediaAnalyzer::isFlickr($a_location)) {
237 $a_parameter = array();
238 }
239
240 // GoogleVideo
243 $a_parameter = array();
244 }
245
246 // GoogleDocs
249 $a_parameter = array();
250 }
251
252 foreach ($ext_par as $name => $value) {
253 $a_parameter[$name] = $value;
254 }
255
256 return $a_parameter;
257 }
258}
An exception for terminatinating execution or to throw for unit testing.
Analyzes external media locations and extracts important information into parameter field.
static extractUrlParameters($a_location, $a_parameter)
Extract URL information to parameter array.
static extractYouTubeParameters($a_location)
Extract YouTube Parameter.
static extractFlickrParameters($a_location)
Extract Flickr Parameter.
static isVimeo($a_location)
Identify Vimeo links.
static isGoogleDocument($a_location)
Identify Google Document links.
static extractGoogleVideoParameters($a_location)
Extract GoogleVideo Parameter.
static extractVimeoParameters($a_location)
Extract Vimeo Parameter.
static isGoogleVideo($a_location)
Identify GoogleVideo links.
static isFlickr($a_location)
Identify Flickr links.
static extractGoogleDocumentParameters($a_location)
Extract GoogleDocument Parameter.
static isYouTube($a_location)
Identify YouTube links.
if($format !==null) $name
Definition: metadata.php:230