[TASK] Remove deprecated cObj HTML
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_mediawizardcoreprovider.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Aishwara M.B. (aishu.moorthy@gmail.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Contains an implementation of the mediaWizardProvider supporting some
29 * well known providers.
30 *
31 * @author Aishwara M.B.<aishu.moorthy@gmail.com>
32 * @author Steffen Kamper <info@sk-typo3.de>
33 * @author Ernesto Baschny <ernst@cron-it.de>
34 */
35
36
37 class tslib_mediaWizardCoreProvider implements tslib_mediaWizardProvider {
38
39 /**
40 * @var array List of providers we can handle in this class
41 */
42 protected $providers = array(
43 'youtube',
44 'youtu',
45 'dailymotion',
46 'sevenload',
47 'vimeo',
48 'clipfish',
49 'google',
50 'metacafe',
51 'myvideo',
52 'liveleak',
53 'veoh'
54 );
55
56 /**
57 * Checks if we have a valid method for processing a given URL.
58 *
59 * This is done by analysing the hostname of the URL and checking if it contains
60 * any of our provider tags defined in $this->providers.
61 *
62 * @param $url
63 * @return string
64 */
65 protected function getMethod($url) {
66 $urlInfo = @parse_url($url);
67 if ($urlInfo === FALSE) {
68 return NULL;
69 }
70 $hostName = t3lib_div::trimExplode('.', $urlInfo['host'], TRUE);
71 foreach ($this->providers as $provider) {
72 $functionName = 'process_' . $provider;
73 if (in_array($provider, $hostName) && is_callable(array($this, $functionName))) {
74 return $functionName;
75 }
76 }
77 return NULL;
78 }
79
80 /***********************************************
81 *
82 * Implementation of tslib_mediaWizardProvider
83 *
84 ***********************************************/
85
86 /**
87 * @param $url
88 * @return bool
89 * @see tslib_mediaWizardProvider::canHandle
90 */
91 public function canHandle($url) {
92 return ($this->getMethod($url) !== NULL);
93 }
94
95 /**
96 * @param $url URL to rewrite
97 * @return string The rewritten URL
98 * @see tslib_mediaWizardProvider::rewriteUrl
99 */
100 public function rewriteUrl($url) {
101 $method = $this->getMethod($url);
102 return $this->$method($url);
103 }
104
105 /***********************************************
106 *
107 * Providers URL rewriting:
108 *
109 ***********************************************/
110
111 /**
112 * Parse youtube url
113 *
114 * @param string $url
115 * @return string processed url
116 */
117 protected function process_youtube($url) {
118 $videoId = '';
119 if (strpos($url, '/user/') !== FALSE) {
120 // it's a channel
121 $parts = explode('/', $url);
122 $videoId = $parts[count($parts) - 1];
123 } elseif (preg_match('/(v=|v\/|.be\/)([^(\&|$)]*)/', $url, $matches)) {
124 $videoId = $matches[2];
125 }
126
127 if ($videoId) {
128 $url = 'http://www.youtube.com/v/' . $videoId . '?fs=1';
129 }
130 return $url;
131 }
132
133 /**
134 * Parse youtube short url
135 *
136 * @param string $url
137 * @return string processed url
138 */
139 protected function process_youtu($url) {
140 return $this->process_youtube($url);
141 }
142
143 /**
144 * Parse dailymotion url
145 *
146 * @param string $url
147 * @return string processed url
148 */
149 protected function process_dailymotion($url) {
150 $parts = explode('video/', $url);
151 $videoId = $parts[1];
152 if (strpos($videoId, '/') !== FALSE) {
153 $videoId = substr($videoId, 0, strpos($videoId, '/'));
154 }
155 return 'http://www.dailymotion.com/swf/' . $videoId;
156 }
157
158 /**
159 * Parse sevenload url
160 *
161 * @param string $url
162 * @return string processed url and preview image
163 */
164 protected function process_sevenload($url) {
165 $parts = explode('/', $url);
166 $videoId = $parts[count($parts) - 1];
167 if (strpos($videoId, '-') !== FALSE) {
168 $videoId = substr($videoId, 0, strpos($videoId, '-'));
169 }
170 return 'http://de.sevenload.com/pl/' . $videoId . '/400x500/swf';
171 }
172
173 /**
174 * Parse vimeo url
175 *
176 * Supports:
177 * - http://vimeo.com/hd#<id>
178 * - http://vimeo.com/<id>
179 * - http://player.vimeo.com/video/<id>
180 *
181 * @param string $url
182 * @return string processed url
183 */
184 protected function process_vimeo($url) {
185 if (preg_match('/[\/#](\d+)$/', $url, $matches)) {
186 $videoId = $matches[1];
187 $url = 'http://vimeo.com/moogaloop.swf?clip_id=' . $videoId . '&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&fullscreen=1';
188 }
189 return $url;
190 }
191
192 /**
193 * Parse clipfish url
194 *
195 * @param string $url
196 * @return string processed url
197 */
198 protected function process_clipfish($url) {
199 if (preg_match('/video([^(\&|$)]*)/', $url, $matches)) {
200 $parts = explode('/', $matches[1]);
201 $videoId = $parts[1];
202 $url = 'http://www.clipfish.de/cfng/flash/clipfish_player_3.swf?as=0&r=1&noad=1&fs=1&vid=' . $videoId;
203 }
204 return $url;
205 }
206
207
208 /**
209 * Parse google url
210 *
211 * @param string $url
212 * @return string processed url
213 */
214 protected function process_google($url) {
215 if (preg_match('/docid=([^(\&|$)]*)/', $url, $matches)) {
216 $videoId = $matches[1];
217 $url = 'http://video.google.com/googleplayer.swf?docid=' . $videoId;
218 }
219 return $url;
220 }
221
222 /**
223 * Parse metacafe url
224 *
225 * @param string $url
226 * @return string processed url
227 */
228
229 protected function process_metacafe($url) {
230 if (preg_match('/watch([^(\&|$)]*)/', $url, $matches)) {
231 $parts = explode('/', $matches[1]);
232 $videoId = $parts[1];
233 $url = 'http://www.metacafe.com/fplayer/' . $videoId . '/.swf';
234 }
235 return $url;
236 }
237
238 /**
239 * Parse myvideo url
240 *
241 * @param string $url
242 * @return string processed url
243 */
244
245 protected function process_myvideo($url) {
246 preg_match('/watch([^(\&|$)]*)/', $url, $matches);
247 $parts = explode('/', $matches[1]);
248 $videoId = $parts[1];
249
250 return 'http://www.myvideo.de/movie/' . $videoId . '/';
251 }
252
253
254 /**
255 * Parse liveleak url
256 *
257 * @param string $url
258 * @return string processed url
259 */
260 protected function process_liveleak($url) {
261 preg_match('/i=([^(\&|$)]*)/', $url, $matches);
262 $videoId = $matches[1];
263
264 return 'http://www.liveleak.com/e/' . $videoId;
265 }
266
267 /**
268 * Parse veoh url
269 *
270 * @param string $url
271 * @return string processed url
272 */
273 protected function process_veoh($url) {
274 preg_match('/watch\/([^(\&|$)]*)/', $url, $matches);
275 $videoId = $matches[1];
276
277 return 'http://www.veoh.com/static/swf/webplayer/WebPlayer.swf?version=AFrontend.5.5.2.1001&permalinkId=' . $videoId;
278 }
279
280 }
281
282 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_mediawizardcoreprovider.php'])) {
283 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_mediawizardcoreprovider.php']);
284 }
285
286 ?>