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