[BUGFIX] Fix url for youtube embeds 52/29952/3
authorThomas Löffler <loeffler@spooner-web.de>
Thu, 8 May 2014 19:14:16 +0000 (21:14 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Thu, 22 May 2014 22:06:32 +0000 (00:06 +0200)
Additionally solve the problem when http:// is missing
due to usage of the link wizard.

Change-Id: I676d14b4ddf81d5d3ec0fc0d0ebb32d08910047a
Resolves: #58569
Resolves: #58986
Releases: 6.2
Reviewed-on: https://review.typo3.org/29952
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/frontend/Classes/MediaWizard/MediaWizardProvider.php
typo3/sysext/frontend/Classes/MediaWizard/MediaWizardProviderManager.php
typo3/sysext/frontend/Tests/Unit/MediaWizard/MediaWizardProviderTest.php

index 48a1695..b364171 100644 (file)
@@ -34,7 +34,7 @@ namespace TYPO3\CMS\Frontend\MediaWizard;
  * @author Steffen Kamper <info@sk-typo3.de>
  * @author Ernesto Baschny <ernst@cron-it.de>
  */
-class MediaWizardProvider implements \TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderInterface {
+class MediaWizardProvider implements MediaWizardProviderInterface {
 
        /**
         * @var array List of providers we can handle in this class
@@ -67,6 +67,13 @@ class MediaWizardProvider implements \TYPO3\CMS\Frontend\MediaWizard\MediaWizard
                if ($urlInfo === FALSE) {
                        return NULL;
                }
+               // The URL passed might not contain http:// prefix
+               if (!isset($urlInfo['host'])) {
+                       $urlInfo = @parse_url('http://' . $url);
+               }
+               if (empty($urlInfo['host'])) {
+                       return NULL;
+               }
                $hostName = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('.', $urlInfo['host'], TRUE);
                foreach ($this->providers as $provider) {
                        $functionName = 'process_' . $provider;
@@ -138,7 +145,7 @@ class MediaWizardProvider implements \TYPO3\CMS\Frontend\MediaWizard\MediaWizard
                }
 
                if ($videoId) {
-                       $url = $this->getUrlSchema() . 'www.youtube.com/embed/' . $videoId . '?fs=1';
+                       $url = $this->getUrlSchema() . 'www.youtube.com/v/' . $videoId . '?fs=1';
                }
                return $url;
        }
index 6491653..3bd6a09 100644 (file)
@@ -43,12 +43,13 @@ class MediaWizardProviderManager {
         * Allows extensions to register themselves as media wizard providers
         *
         * @param string $className A class implementing MediaWizardProviderInterface
+        * @throws \UnexpectedValueException
         * @return void
         */
        static public function registerMediaWizardProvider($className) {
                if (!isset(self::$providers[$className])) {
                        $provider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
-                       if (!$provider instanceof \TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderInterface) {
+                       if (!$provider instanceof MediaWizardProviderInterface) {
                                throw new \UnexpectedValueException($className . ' is registered as a mediaWizardProvider, so it must implement interface TYPO3\\CMS\\Frontend\\MediaWizard\\MediaWizardProviderInterface', 1285022360);
                        }
                        self::$providers[$className] = $provider;
@@ -57,13 +58,13 @@ class MediaWizardProviderManager {
 
        /**
         * @param string $url
-        * @return A valid mediaWizardProvider that can handle this URL
+        * @return MediaWizardProviderInterface|NULL A valid mediaWizardProvider that can handle this URL
         */
        static public function getValidMediaWizardProvider($url) {
                // Go through registered providers in reverse order (last one registered wins)
                $providers = array_reverse(self::$providers, TRUE);
                foreach ($providers as $provider) {
-                       /** @var $provider \TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderInterface */
+                       /** @var $provider MediaWizardProviderInterface */
                        if ($provider->canHandle($url)) {
                                return $provider;
                        }
index 9848fda..5cde60f 100644 (file)
@@ -49,35 +49,35 @@ class MediaWizardProviderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                return array(
                        'http://youtu.be/2PMeCSQ--08' => array(
                                'http://youtu.be/2PMeCSQ--08',
-                               'http://www.youtube.com/embed/2PMeCSQ--08?fs=1'
+                               'http://www.youtube.com/v/2PMeCSQ--08?fs=1'
                        ),
                        'http://www.youtube.com/embed/2PMeCSQ--08' => array(
                                'http://www.youtube.com/embed/2PMeCSQ--08',
-                               'http://www.youtube.com/embed/2PMeCSQ--08?fs=1'
+                               'http://www.youtube.com/v/2PMeCSQ--08?fs=1'
                        ),
                        'http://www.youtube.com/watch?v=2PMeCSQ--08' => array(
                                'http://www.youtube.com/watch?v=2PMeCSQ--08',
-                               'http://www.youtube.com/embed/2PMeCSQ--08?fs=1'
+                               'http://www.youtube.com/v/2PMeCSQ--08?fs=1'
                        ),
                        'http://www.youtube.com/?v=2PMeCSQ--08' => array(
                                'http://www.youtube.com/?v=2PMeCSQ--08',
-                               'http://www.youtube.com/embed/2PMeCSQ--08?fs=1'
+                               'http://www.youtube.com/v/2PMeCSQ--08?fs=1'
                        ),
                        'http://www.youtube.com/v/2PMeCSQ--08' => array(
                                'http://www.youtube.com/v/2PMeCSQ--08',
-                               'http://www.youtube.com/embed/2PMeCSQ--08?fs=1'
+                               'http://www.youtube.com/v/2PMeCSQ--08?fs=1'
                        ),
                        'http://www.youtube.com/e/2PMeCSQ--08' => array(
                                'http://www.youtube.com/e/2PMeCSQ--08',
-                               'http://www.youtube.com/embed/2PMeCSQ--08?fs=1'
+                               'http://www.youtube.com/v/2PMeCSQ--08?fs=1'
                        ),
                        'http://www.youtube.com/watch?feature=player_embedded&v=2PMeCSQ--08' => array(
                                'http://www.youtube.com/watch?feature=player_embedded&v=2PMeCSQ--08',
-                               'http://www.youtube.com/embed/2PMeCSQ--08?fs=1'
+                               'http://www.youtube.com/v/2PMeCSQ--08?fs=1'
                        ),
                        'http://www.youtube.com/watch?v=2PMeCSQ--08&list=PLGWGc5dfbzn_pvtJg7XskLva9XZpNTI88' => array(
                                'http://www.youtube.com/watch?v=2PMeCSQ--08&list=PLGWGc5dfbzn_pvtJg7XskLva9XZpNTI88',
-                               'http://www.youtube.com/embed/2PMeCSQ--08?fs=1'
+                               'http://www.youtube.com/v/2PMeCSQ--08?fs=1'
                        ),
                );
        }