Browse Source

Evolution #78: Remplacer VideoEmbed

bastien 13 years ago
parent
commit
622e7bf385

+ 4 - 0
src/Muzich/CoreBundle/ElementFactory/ElementManager.php View File

@@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManager;
8 8
 use Symfony\Component\DependencyInjection\Container;
9 9
 
10 10
 use Muzich\CoreBundle\ElementFactory\Site\YoutubecomFactory;
11
+use Muzich\CoreBundle\ElementFactory\Site\YoutubeFactory;
11 12
 use Muzich\CoreBundle\ElementFactory\Site\DailymotioncomFactory;
12 13
 use Muzich\CoreBundle\ElementFactory\Site\JamendocomFactory;
13 14
 use Muzich\CoreBundle\ElementFactory\Site\SoundcloudcomFactory;
@@ -144,6 +145,9 @@ class ElementManager
144 145
       case 'youtube.com':
145 146
         return new YoutubecomFactory($this->element, $this->container);
146 147
       break;
148
+      case 'youtu.be':
149
+        return new YoutubeFactory($this->element, $this->container);
150
+      break;
147 151
       case 'soundcloud.com':
148 152
         return new SoundcloudcomFactory($this->element, $this->container);
149 153
       break;

+ 22 - 3
src/Muzich/CoreBundle/ElementFactory/Site/DailymotioncomFactory.php View File

@@ -2,16 +2,35 @@
2 2
 
3 3
 namespace Muzich\CoreBundle\ElementFactory\Site;
4 4
 
5
-use Muzich\CoreBundle\ElementFactory\Site\base\VideoSiteFactory;
5
+use Muzich\CoreBundle\ElementFactory\Site\base\BaseFactory;
6 6
 
7 7
 /**
8 8
  * 
9 9
  *
10 10
  * @author bux
11 11
  */
12
-class DailymotioncomFactory extends VideoSiteFactory
12
+class DailymotioncomFactory extends BaseFactory
13 13
 {
14
-  
14
+  public function getEmbedCode()
15
+  {
16
+    $url = $this->getCleanedUrl();
17
+    
18
+    // /video/xnqcwx_le-nazisme-dans-le-couple_fun#hp-v-v2
19
+    if (preg_match("#(video\/)([a-zA-Z0-9]+)([a-zA-Z0-9_-]*)#", $url, $chaines))
20
+    {
21
+      $embed_url = 'http://www.dailymotion.com/embed/video/'.$chaines[2];
22
+    }
23
+    
24
+    if ($embed_url)
25
+    {
26
+      $width = $this->container->getParameter('dailymotion_player_width');
27
+      $height = $this->container->getParameter('dailymotion_player_height');
28
+      return '<iframe frameborder="0" width="'.$width.'" height="'.$height.'" '
29
+        .'src="http://www.dailymotion.com/embed/video/xnqcwx"></iframe>';
30
+    }
31
+    
32
+    return null;
33
+  }
15 34
 }
16 35
 
17 36
 ?>

+ 36 - 0
src/Muzich/CoreBundle/ElementFactory/Site/YoutubeFactory.php View File

@@ -0,0 +1,36 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+use Muzich\CoreBundle\ElementFactory\Site\base\BaseFactory;
6
+
7
+/**
8
+ * 
9
+ *
10
+ * @author bux
11
+ */
12
+class YoutubeFactory extends BaseFactory
13
+{
14
+  public function getEmbedCode()
15
+  {
16
+    $url = $this->getCleanedUrl();
17
+    
18
+    // http://youtu.be/9hQVA2sloGc
19
+    if (preg_match("#\/([a-zA-Z0-9]+)#", $url, $chaines))
20
+    {
21
+      $embed_url = 'http://www.youtube.com/embed/'.$chaines[1];
22
+    }
23
+        
24
+    if ($embed_url)
25
+    {
26
+      $width = $this->container->getParameter('youtube_player_width');
27
+      $height = $this->container->getParameter('youtube_player_height');
28
+      return '<iframe width="'.$width.'" height="'.$height.'" src="'.$embed_url.'" '
29
+        .'frameborder="0" allowfullscreen></iframe>';
30
+    }
31
+    
32
+    return null;
33
+  }
34
+}
35
+
36
+?>

+ 26 - 3
src/Muzich/CoreBundle/ElementFactory/Site/YoutubecomFactory.php View File

@@ -2,16 +2,39 @@
2 2
 
3 3
 namespace Muzich\CoreBundle\ElementFactory\Site;
4 4
 
5
-use Muzich\CoreBundle\ElementFactory\Site\base\VideoSiteFactory;
5
+use Muzich\CoreBundle\ElementFactory\Site\base\BaseFactory;
6 6
 
7 7
 /**
8 8
  * 
9 9
  *
10 10
  * @author bux
11 11
  */
12
-class YoutubecomFactory extends VideoSiteFactory
12
+class YoutubecomFactory extends BaseFactory
13 13
 {
14
-  
14
+  public function getEmbedCode()
15
+  {
16
+    $url = $this->getCleanedUrl();
17
+    
18
+    // '/watch?v=kOLQIV22JAs&feature=feedrec_grec_index'
19
+    if (preg_match("#(v\/|watch\?v=)([\w\-]+)#", $url, $chaines))
20
+    {
21
+      $embed_url = 'http://www.youtube.com/embed/'.$chaines[2];
22
+    }
23
+    else if (preg_match("#(v=|watch\?v=)([\w\-]+)#", $url, $chaines))
24
+    {
25
+      $embed_url = 'http://www.youtube.com/embed/'.$chaines[2];
26
+    }
27
+    
28
+    if ($embed_url)
29
+    {
30
+      $width = $this->container->getParameter('youtube_player_width');
31
+      $height = $this->container->getParameter('youtube_player_height');
32
+      return '<iframe width="'.$width.'" height="'.$height.'" src="'.$embed_url.'" '
33
+        .'frameborder="0" allowfullscreen></iframe>';
34
+    }
35
+    
36
+    return null;
37
+  }
15 38
 }
16 39
 
17 40
 ?>

+ 11 - 0
src/Muzich/CoreBundle/ElementFactory/Site/base/BaseFactory.php View File

@@ -32,6 +32,17 @@ class BaseFactory implements FactoryInterface
32 32
     return null;
33 33
   }
34 34
   
35
+  /**
36
+   * Retourne l'url relative dans le site
37
+   * 
38
+   * @return string
39
+   */
40
+  protected function getCleanedUrl()
41
+  {
42
+    $url = str_replace('www.', '', $this->element->getUrl());
43
+    return str_replace('http://'.$this->element->getType(), '', $url);
44
+  }
45
+  
35 46
 }
36 47
 
37 48
 ?>