TYPO3 CMS  TYPO3_6-2
MediaWizardProvider.php
Go to the documentation of this file.
1 <?php
3 
25 
29  protected $providers = array(
30  'youtube',
31  'youtu',
32  'dailymotion',
33  'sevenload',
34  'vimeo',
35  'clipfish',
36  'google',
37  'metacafe',
38  'myvideo',
39  'liveleak',
40  'veoh'
41  );
42 
52  protected function getMethod($url) {
53  $urlInfo = @parse_url($url);
54  if ($urlInfo === FALSE) {
55  return NULL;
56  }
57  // The URL passed might not contain http:// prefix
58  if (!isset($urlInfo['host'])) {
59  $urlInfo = @parse_url('http://' . $url);
60  }
61  if (empty($urlInfo['host'])) {
62  return NULL;
63  }
64  $hostName = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('.', $urlInfo['host'], TRUE);
65  foreach ($this->providers as $provider) {
66  $functionName = 'process_' . $provider;
67  if (in_array($provider, $hostName) && is_callable(array($this, $functionName))) {
68  return $functionName;
69  }
70  }
71  return NULL;
72  }
73 
74  /***********************************************
75  *
76  * Implementation of MediaWizardProviderInterface
77  *
78  ***********************************************/
84  public function canHandle($url) {
85  return $this->getMethod($url) !== NULL;
86  }
87 
93  public function rewriteUrl($url) {
94  $method = $this->getMethod($url);
95  return $this->{$method}($url);
96  }
97 
98  /***********************************************
99  *
100  * Providers URL rewriting:
101  *
102  ***********************************************/
109  protected function process_youtube($url) {
110  $videoId = '';
111 
112  $pattern = '%
113  ^(?:https?://)? # Optional URL scheme Either http or https
114  (?:www\.)? # Optional www subdomain
115  (?: # Group host alternatives:
116  youtu\.be/ # Either youtu.be/,
117  |youtube(?: # or youtube.com/
118  -nocookie # optional nocookie domain
119  )?\.com/(?:
120  [^/]+/.+/ # Either /something/other_params/ for channels,
121  |(?:v|e(?: # or v/ or e/,
122  mbed # optional mbed for embed/
123  )?)/
124  |.*[?&]v= # or ?v= or ?other_param&v=
125  )
126  ) # End host alternatives.
127  ([^"&?/ ]{11}) # 11 characters (Length of Youtube video ids).
128  (?:.+)?$ # Optional other ending URL parameters.
129  %xs';
130  if (preg_match($pattern, $url, $matches)) {
131  $videoId = $matches[1];
132  }
133 
134  if ($videoId) {
135  $url = $this->getUrlSchema() . 'www.youtube.com/v/' . $videoId . '?fs=1';
136  }
137  return $url;
138  }
139 
146  protected function process_youtu($url) {
147  return $this->process_youtube($url);
148  }
149 
156  protected function process_dailymotion($url) {
157  $parts = explode('video/', $url);
158  $videoId = $parts[1];
159  if (strpos($videoId, '/') !== FALSE) {
160  $videoId = substr($videoId, 0, strpos($videoId, '/'));
161  }
162  return $this->getUrlSchema() . 'www.dailymotion.com/swf/' . $videoId;
163  }
164 
171  protected function process_sevenload($url) {
172  $parts = explode('/', $url);
173  $videoId = $parts[count($parts) - 1];
174  if (strpos($videoId, '-') !== FALSE) {
175  $videoId = substr($videoId, 0, strpos($videoId, '-'));
176  }
177  return 'http://de.sevenload.com/pl/' . $videoId . '/400x500/swf';
178  }
179 
191  protected function process_vimeo($url) {
192  if (preg_match('/[\\/#](\\d+)$/', $url, $matches)) {
193  $videoId = $matches[1];
194  $url = $this->getUrlSchema() . 'vimeo.com/moogaloop.swf?clip_id=' . $videoId . '&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&fullscreen=1';
195  }
196  return $url;
197  }
198 
205  protected function process_clipfish($url) {
206  if (preg_match('/video([^(\\&|$)]*)/', $url, $matches)) {
207  $parts = explode('/', $matches[1]);
208  $videoId = $parts[1];
209  $url = 'http://www.clipfish.de/cfng/flash/clipfish_player_3.swf?as=0&r=1&noad=1&fs=1&vid=' . $videoId;
210  }
211  return $url;
212  }
213 
220  protected function process_google($url) {
221  if (preg_match('/docid=([^(\\&|$)]*)/', $url, $matches)) {
222  $videoId = $matches[1];
223  $url = $this->getUrlSchema() . 'video.google.com/googleplayer.swf?docid=' . $videoId;
224  }
225  return $url;
226  }
227 
234  protected function process_metacafe($url) {
235  if (preg_match('/watch([^(\\&|$)]*)/', $url, $matches)) {
236  $parts = explode('/', $matches[1]);
237  $videoId = $parts[1];
238  $url = 'http://www.metacafe.com/fplayer/' . $videoId . '/.swf';
239  }
240  return $url;
241  }
242 
249  protected function process_myvideo($url) {
250  preg_match('/watch([^(\\&|$)]*)/', $url, $matches);
251  $parts = explode('/', $matches[1]);
252  $videoId = $parts[1];
253  return $this->getUrlSchema() . 'www.myvideo.de/movie/' . $videoId . '/';
254  }
255 
262  protected function process_liveleak($url) {
263  preg_match('/i=([^(\\&|$)]*)/', $url, $matches);
264  $videoId = $matches[1];
265  return 'http://www.liveleak.com/e/' . $videoId;
266  }
267 
274  protected function process_veoh($url) {
275  preg_match('/watch\\/([^(\\&|$)]*)/', $url, $matches);
276  $videoId = $matches[1];
277  return 'http://www.veoh.com/static/swf/webplayer/WebPlayer.swf?version=AFrontend.5.5.2.1001&permalinkId=' . $videoId;
278  }
279 
285  protected function getUrlSchema() {
286  return \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://';
287  }
288 
289 }
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)