Browse Source

Evolution #617: Prise en charge sites externes: Gestion (pas autoplay) de vimeo

Sevajol Bastien 11 years ago
parent
commit
d7943c0853

+ 17 - 1
src/Muzich/CoreBundle/Factory/ElementFactory.php View File

@@ -63,7 +63,23 @@ abstract class ElementFactory
63 63
   
64 64
   public function proceedThumbnailUrl()
65 65
   {
66
-    $this->element->setThumbnailUrl(null);
66
+    if (($thumb_url = $this->element->getData(Element::DATA_THUMB_URL)))
67
+    {
68
+      $this->element->setThumbnailUrl($thumb_url);
69
+    }
70
+  }
71
+  
72
+  protected function getJsonDataFromApiWithUrl($url)
73
+  {
74
+    $api_url = curl_init($url);
75
+    
76
+    $options = array(
77
+      CURLOPT_RETURNTRANSFER => true,
78
+      CURLOPT_HTTPHEADER => array('Content-type: application/json')
79
+    );
80
+      
81
+    curl_setopt_array($api_url, $options);
82
+    return json_decode(curl_exec($api_url), true);
67 83
   }
68 84
   
69 85
 }

+ 64 - 0
src/Muzich/CoreBundle/Factory/Elements/Vimeocom.php View File

@@ -0,0 +1,64 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Factory\Elements;
4
+
5
+use Muzich\CoreBundle\Factory\ElementFactory;
6
+use Muzich\CoreBundle\Entity\Element;
7
+
8
+/**
9
+ * 
10
+ *
11
+ * @author bux
12
+ */
13
+class Vimeocom extends ElementFactory
14
+{
15
+  
16
+  public function retrieveDatas()
17
+  {
18
+    $url_clean = $this->getCleanedUrl();
19
+    $ref_id = null;
20
+    
21
+    // http://vimeo.com/43258820
22
+    if (preg_match("#\/([0-9]+)#", $url_clean, $chaines))
23
+    {
24
+      $ref_id = $chaines[1];
25
+    }
26
+    
27
+    if ($ref_id)
28
+    {
29
+      $this->element->setData(Element::DATA_REF_ID, $ref_id);
30
+      $this->getDataFromApi($ref_id);
31
+    }
32
+  }
33
+  
34
+  protected function getDataFromApi($ref_id)
35
+  {
36
+    $data = $this->getJsonDataFromApiWithUrl('http://vimeo.com/api/v2/video/'.$ref_id.'.json');
37
+    
38
+    if (count($data))
39
+    {
40
+      if (array_key_exists('title', $data[0]))
41
+      {
42
+        $this->element->setData(Element::DATA_TITLE, $data[0]['title']);
43
+      }
44
+      if (array_key_exists('thumbnail_medium', $data[0]))
45
+      {
46
+        $this->element->setData(Element::DATA_THUMB_URL, $data[0]['thumbnail_medium']);
47
+      }
48
+    }
49
+  }
50
+  
51
+  public function proceedEmbedCode()
52
+  {
53
+    if (($ref_id = $this->element->getData(Element::DATA_REF_ID)))
54
+    {
55
+      $width = $this->container->getParameter('vimeo_player_width');
56
+      $height = $this->container->getParameter('vimeo_player_height');
57
+      $this->element->setEmbed(
58
+        '<iframe src="http://player.vimeo.com/video/'.$ref_id.'&autoplay=1&api=1" '
59
+        .'width="'.$width.'" height="'.$height.'" frameborder="0" '
60
+        .'webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'
61
+      );
62
+    }
63
+  }
64
+}

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

@@ -13,6 +13,7 @@ use Muzich\CoreBundle\Factory\Elements\Dailymotioncom;
13 13
 use Muzich\CoreBundle\Factory\Elements\Jamendocom;
14 14
 use Muzich\CoreBundle\Factory\Elements\Soundcloudcom;
15 15
 use Muzich\CoreBundle\Factory\Elements\Deezercom;
16
+use Muzich\CoreBundle\Factory\Elements\Vimeocom;
16 17
 
17 18
 /**
18 19
  * 
@@ -167,6 +168,9 @@ class ElementManager
167 168
       case 'deezer.com':
168 169
         return new Deezercom($this->element, $this->container);
169 170
       break;
171
+      case 'vimeo.com':
172
+        return new Vimeocom($this->element, $this->container);
173
+      break;
170 174
       default:
171 175
         throw new \Exception("La Factory n'est pas prise en charge pour ce type.");
172 176
       break;

+ 8 - 2
src/Muzich/CoreBundle/Resources/public/css/main.css View File

@@ -1981,11 +1981,17 @@ a.tags_prompt_helpbox
1981 1981
 {
1982 1982
   float: left;
1983 1983
   margin-bottom: 0;
1984
-  margin-left: -6px;
1985
-  margin-top: -11px;
1984
+  margin-left: 0px;
1985
+  margin-top: 5px;
1986 1986
 }
1987 1987
 
1988 1988
 form#address_update input.intext
1989 1989
 {
1990 1990
   width: 90px;
1991
+}
1992
+
1993
+div#form_add_thumb img
1994
+{
1995
+  width: 100px;
1996
+  height: 100px;
1991 1997
 }

+ 14 - 0
src/Muzich/CoreBundle/Tests/ElementFactory/ElementFactoryTest.php View File

@@ -521,6 +521,20 @@ class ElementFactoryTest extends UnitTest
521 521
       'http://www.deezer.com/fr/music/playlist/18701350'
522 522
     ));
523 523
     
524
+    /*
525
+     * Vimeo
526
+     *
527
+     */
528
+    
529
+    $this->assertEquals(array(
530
+      'data_ref_id' => '43258820',
531
+      'data_title'  => 'Punish Yourself',
532
+      'data_thumb_url' => 'http://b.vimeocdn.com/ts/301/282/301282081_200.jpg'
533
+    ),$this->proceed_element_datas_api(
534
+      $bux, 
535
+      'http://vimeo.com/43258820'
536
+    ));
537
+    
524 538
   }
525 539
   
526 540
 }