Fixed bug #15580: Add calls to logDeprecatedFunction() for more deprecated functions...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_mediawizardcoreprovider.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 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 * $Id: $
32
33 * @author Aishwara M.B.<aishu.moorthy@gmail.com>
34 * @author Steffen Kamper <info@sk-typo3.de>
35 * @author Ernesto Baschny <ernst@cron-it.de>
36 */
37
38
39 class tslib_mediaWizardCoreProvider implements tslib_mediaWizardProvider {
40
41 /**
42 * @var array List of providers we can handle in this class
43 */
44 protected $providers = array(
45 'youtube',
46 'dailymotion',
47 'sevenload',
48 'vimeo',
49 'clipfish',
50 'google',
51 'metacafe',
52 'myvideo',
53 'liveleak',
54 'veoh'
55 );
56
57 /**
58 * Checks if we have a valid method for processing a given URL.
59 *
60 * This is done by analysing the hostname of the URL and checking if it contains
61 * any of our provider tags defined in $this->providers.
62 *
63 * @param $url
64 * @return string
65 */
66 protected function getMethod($url) {
67 $urlInfo = @parse_url($url);
68 if ($urlInfo === FALSE) {
69 return NULL;
70 }
71 $hostName = t3lib_div::trimExplode('.', $urlInfo['host'], TRUE);
72 foreach ($this->providers as $provider) {
73 $functionName = 'process_' . $provider;
74 if (in_array($provider, $hostName) && is_callable(array($this, $functionName))) {
75 return $functionName;
76 }
77 }
78 return NULL;
79 }
80
81 /***********************************************
82 *
83 * Implementation of tslib_mediaWizardProvider
84 *
85 ***********************************************/
86
87 /**
88 * @param $url
89 * @return bool
90 * @see tslib_mediaWizardProvider::canHandle
91 */
92 public function canHandle($url) {
93 return ($this->getMethod($url) !== NULL);
94 }
95
96 /**
97 * @param $url URL to rewrite
98 * @return string The rewritten URL
99 * @see tslib_mediaWizardProvider::rewriteUrl
100 */
101 public function rewriteUrl($url) {
102 $method = $this->getMethod($url);
103 return $this->$method($url);
104 }
105
106 /***********************************************
107 *
108 * Providers URL rewriting:
109 *
110 ***********************************************/
111
112 /**
113 * Parse youtube url
114 *
115 * @param string $url
116 * @return string processed url
117 */
118 protected function process_youtube($url) {
119 $videoId = '';
120 if (strpos($url, '/user/') !== FALSE) {
121 // it's a channel
122 $parts = explode('/', $url);
123 $videoId = $parts[count($parts) - 1];
124 } else if (preg_match('/v=([^(\&|$)]*)/', $url, $matches)) {
125 $videoId = $matches[1];
126 }
127
128 if ($videoId) {
129 $url = 'http://www.youtube.com/v/' . $videoId . '?fs=1';
130 }
131 return $url;
132 }
133
134 /**
135 * Parse dailymotion url
136 *
137 * @param string $url
138 * @return string processed url
139 */
140 protected function process_dailymotion($url) {
141 $parts = explode('video/', $url);
142 $videoId = $parts[1];
143 if (strpos($videoId, '/') !== FALSE) {
144 $videoId = substr($videoId, 0, strpos($videoId, '/'));
145 }
146 return 'http://www.dailymotion.com/swf/' . $videoId;
147 }
148
149 /**
150 * Parse sevenload url
151 *
152 * @param string $url
153 * @return string processed url and preview image
154 */
155 protected function process_sevenload($url) {
156 $parts = explode('/', $url);
157 $videoId = $parts[count($parts) - 1];
158 if (strpos($videoId, '-') !== FALSE) {
159 $videoId = substr($videoId, 0, strpos($videoId, '-'));
160 }
161 return 'http://de.sevenload.com/pl/' . $videoId . '/400x500/swf';
162 }
163
164 /**
165 * Parse vimeo url
166 *
167 * Supports:
168 * - http://vimeo.com/hd#<id>
169 * - http://vimeo.com/<id>
170 * - http://player.vimeo.com/video/<id>
171 *
172 * @param string $url
173 * @return string processed url
174 */
175 protected function process_vimeo($url) {
176 if (preg_match('/[\/#](\d+)$/', $url, $matches)) {
177 $videoId = $matches[1];
178 $url = 'http://vimeo.com/moogaloop.swf?&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&fullscreen=1&clip_id=' .
179 $videoId;
180 }
181 return $url;
182 }
183
184 /**
185 * Parse clipfish url
186 *
187 * @param string $url
188 * @return string processed url
189 */
190 protected function process_clipfish($url) {
191 if (preg_match('/video([^(\&|$)]*)/', $url, $matches)) {
192 $parts = explode('/', $matches[1]);
193 $videoId = $parts[1];
194 $url = 'http://www.clipfish.de/cfng/flash/clipfish_player_3.swf?as=0&r=1&noad=1&fs=1&vid=' . $videoId;
195 }
196 return $url;
197 }
198
199
200 /**
201 * Parse google url
202 *
203 * @param string $url
204 * @return string processed url
205 */
206 protected function process_google($url) {
207 if (preg_match('/docid=([^(\&|$)]*)/', $url, $matches)) {
208 $videoId = $matches[1];
209 $url = 'http://video.google.com/googleplayer.swf?docid=' . $videoId;
210 }
211 return $url;
212 }
213
214 /**
215 * Parse metacafe url
216 *
217 * @param string $url
218 * @return string processed url
219 */
220
221 protected function process_metacafe($url) {
222 if (preg_match('/watch([^(\&|$)]*)/', $url, $matches)) {
223 $parts = explode('/', $matches[1]);
224 $videoId = $parts[1];
225 $url = 'http://www.metacafe.com/fplayer/' . $videoId . '/.swf';
226 }
227 return $url;
228 }
229
230 /**
231 * Parse myvideo url
232 *
233 * @param string $url
234 * @return string processed url
235 */
236
237 protected function process_myvideo($url) {
238 preg_match('/watch([^(\&|$)]*)/', $url, $matches);
239 $parts = explode('/', $matches[1]);
240 $videoId = $parts[1];
241
242 return 'http://www.myvideo.de/movie/' . $videoId . '/';
243 }
244
245
246 /**
247 * Parse liveleak url
248 *
249 * @param string $url
250 * @return string processed url
251 */
252 protected function process_liveleak($url) {
253 preg_match('/i=([^(\&|$)]*)/', $url, $matches);
254 $videoId = $matches[1];
255
256 return 'http://www.liveleak.com/e/' . $videoId;
257 }
258
259 /**
260 * Parse veoh url
261 *
262 * @param string $url
263 * @return string processed url
264 */
265 protected function process_veoh($url) {
266 preg_match('/watch\/([^(\&|$)]*)/', $url, $matches);
267 $videoId = $matches[1];
268
269 return 'http://www.veoh.com/static/swf/webplayer/WebPlayer.swf?version=AFrontend.5.5.2.1001&permalinkId=' . $videoId;
270 }
271
272 }
273
274 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_mediawizardcoreprovider.php']) {
275 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_mediawizardcoreprovider.php']);
276 }
277
278 ?>