Browse Source

Evolution #52: Embeds: En ajouter

bastien 13 years ago
parent
commit
1b2e4bd1ba

+ 14 - 7
src/Muzich/CoreBundle/ElementFactory/ElementManager.php View File

@@ -102,16 +102,23 @@ class ElementManager
102 102
    */
103 103
   protected function determineType()
104 104
   {
105
-    preg_match("/^(http:\/\/)?([^\/]+)/i", $this->element->getUrl(), $chaines);
106
-    $host = $chaines[2];
107
-    // Repérer les derniers segments
108
-    preg_match("/[^\.\/]+\.[^\.\/]+$/",$host,$chaines);
105
+    // On ne prend pas de risque avec le www, on l'enlève
106
+    $url = str_replace('www.', '', $this->element->getUrl());
109 107
     
110
-    $type = null;
108
+    preg_match("/^(http:\/\/)?([^\/]+)/i", $url, $chaines);
111 109
     
112
-    if (in_array($chaines[0], $this->types))
110
+    if (array_key_exists(2, $chaines))
113 111
     {
114
-      $type = $this->em->getRepository('MuzichCoreBundle:ElementType')->find($chaines[0]);
112
+      $host = $chaines[2];
113
+      // Repérer les derniers segments
114
+      preg_match("/[^\.\/]+\.[^\.\/]+$/",$host,$chaines);
115
+
116
+      $type = null;
117
+
118
+      if (in_array($chaines[0], $this->types))
119
+      {
120
+        $type = $this->em->getRepository('MuzichCoreBundle:ElementType')->find($chaines[0]);
121
+      }
115 122
     }
116 123
     
117 124
     $this->element->setType($type);

+ 28 - 1
src/Muzich/CoreBundle/ElementFactory/Site/SoundCloudFactory.php View File

@@ -3,6 +3,8 @@
3 3
 namespace Muzich\CoreBundle\ElementFactory\Site;
4 4
 
5 5
 use Muzich\CoreBundle\ElementFactory\Site\base\BaseFactory;
6
+use Muzich\CoreBundle\Entity\Element;
7
+use Symfony\Component\DependencyInjection\Container;
6 8
 
7 9
 /**
8 10
  * 
@@ -11,7 +13,32 @@ use Muzich\CoreBundle\ElementFactory\Site\base\BaseFactory;
11 13
  */
12 14
 class SoundCloudFactory extends BaseFactory
13 15
 {
14
-  
16
+  public function getEmbedCode()
17
+  {
18
+    $url = str_replace('www.', '', $this->element->getUrl());
19
+    $data = str_replace('http://soundcloud.com', '', $url);
20
+    
21
+    // http://soundcloud.com/matas/sets/library-project
22
+    if (preg_match("#^\/[a-zA-Z0-9_-]+\/sets\/[a-zA-Z0-9_-]+#", $data)
23
+    // http://soundcloud.com/matas/anadrakonic-waltz
24
+         || preg_match("#^\/[a-zA-Z0-9_]+\/[a-zA-Z0-9_]+#", $data))
25
+    {
26
+      // l'url est valide pour l'api javascript que l'on utilise
27
+      
28
+      $height = $this->container->getParameter('soundcloud_player_height');
29
+      $embed = 
30
+        '<object height="'.$height.'" width="100%" id="embed_'.$this->element->getId().'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
31
+          <param name="movie" value="http://player.soundcloud.com/player.swf?url='.$url.'&amp;enable_api=true&amp;object_id=embed_'.$this->element->getId().'"></param>
32
+          <param name="allowscriptaccess" value="always"></param>
33
+          <embed allowscriptaccess="always" height="'.$height.'" src="http://player.soundcloud.com/player.swf?url='.$url.'&amp;enable_api=true&amp;object_id=embed_'.$this->element->getId().'" type="application/x-shockwave-flash" width="100%" name="embed_'.$this->element->getId().'"></embed>
34
+        </object>
35
+        ';
36
+      
37
+      return $embed;
38
+    }
39
+    
40
+    return null;
41
+  }
15 42
 }
16 43
 
17 44
 ?>

+ 8 - 1
src/Muzich/CoreBundle/ElementFactory/Site/base/BaseFactory.php View File

@@ -14,10 +14,17 @@ class BaseFactory implements FactoryInterface
14 14
 {
15 15
   
16 16
   protected $element;
17
+  protected $container;
17 18
   
19
+  /**
20
+   *
21
+   * @param Element $element
22
+   * @param Container $container 
23
+   */
18 24
   public function __construct(Element $element, Container $container)
19 25
   {
20
-    $this->element = $element;
26
+    $this->element   = $element;
27
+    $this->container = $container;
21 28
   }
22 29
   
23 30
   public function getEmbedCode()

+ 17 - 1
web/bundles/muzichcore/js/muzich.js View File

@@ -54,6 +54,22 @@ if(typeof(String.prototype.trim) === "undefined")
54 54
     };
55 55
 }
56 56
 
57
+$(document).ready(function(){
58
+  
59
+ // Affichage un/des embed
60
+ $('a.element_embed_open_link').click(function(){
61
+   $(this).parent('li.element').find('a.element_embed_open_link').hide();
62
+   $(this).parent('li.element').find('a.element_embed_close_link').show();
63
+   $(this).parent('li.element').find('div.element_embed').show();
64
+   return false;
65
+ });
57 66
 
58
-// Tags
67
+ // Fermeture du embed si demandé
68
+ $('a.element_embed_close_link').click(function(){
69
+   $(this).parent('li.element').find('a.element_embed_open_link').show();
70
+   $(this).parent('li.element').find('a.element_embed_close_link').hide();
71
+   $(this).parent('li.element').find('div.element_embed').hide();
72
+   return false;
73
+ });
59 74
 
75
+ });

+ 0 - 26
web/bundles/muzichhome/js/home.js View File

@@ -14,30 +14,4 @@ $(document).ready(function(){
14 14
      return false;
15 15
    }); 
16 16
    
17
-//   // Affichage du/des embed si existant
18
-//   $('li.element').hover(function(){     
19
-//     $(this).find('div.element_embed').each(function(i){ 
20
-//       if ($(this).css('display') == 'none')
21
-//       {
22
-//         $(this).show();        
23
-//       }
24
-//     });
25
-//   }, function(){});
26
-
27
-   // Affichage du/des embed
28
-   $('a.element_embed_open_link').click(function(){
29
-     $('a.element_embed_open_link').hide();
30
-     $('a.element_embed_close_link').show();
31
-     $(this).parent('li.element').find('div.element_embed').show();
32
-     return false;
33
-   });
34
-   
35
-   // Fermeture du embed si demandé
36
-   $('a.element_embed_close_link').click(function(){
37
-     $('a.element_embed_open_link').show();
38
-     $('a.element_embed_close_link').hide();
39
-     $(this).parent('li.element').find('div.element_embed').hide();
40
-     return false;
41
-   });
42
-   
43 17
  });