Procházet zdrojové kódy

Réécriture code factory Elements

Sevajol Bastien před 11 roky
rodič
revize
0ddc4ee7f9

+ 0 - 69
src/Muzich/CoreBundle/ElementFactory/Site/DailymotioncomFactory.php Zobrazit soubor

@@ -1,69 +0,0 @@
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 DailymotioncomFactory extends BaseFactory
13
-{
14
-  public function getEmbedCode()
15
-  {
16
-    $url = $this->getCleanedUrl();
17
-    $embed_url = null;
18
-    
19
-    // /video/xnqcwx_le-nazisme-dans-le-couple_fun#hp-v-v2
20
-    if (preg_match("#(video\/)([a-zA-Z0-9]+)([a-zA-Z0-9_-]*)#", $url, $chaines))
21
-    {
22
-      $embed_url = 'http://www.dailymotion.com/embed/video/'.$chaines[2];
23
-    }
24
-    
25
-    if ($embed_url)
26
-    {
27
-      $width = $this->container->getParameter('dailymotion_player_width');
28
-      $height = $this->container->getParameter('dailymotion_player_height');
29
-      return '<iframe frameborder="0" width="'.$width.'" height="'.$height.'" '
30
-        .'src="'.$embed_url.'"></iframe>';
31
-    }
32
-    
33
-    return null;
34
-  }
35
-  
36
-  /*
37
-   * http://www.dailymotion.com/doc/api/obj-video.html
38
-   */
39
-  public function getThumbnailUrl()
40
-  {
41
-    // https://api.dailymotion.com/video/xmi3i1&fields=thumbnail_medium_url
42
-    $url_object = $this->getCleanedUrl();
43
-    $url = null;
44
-    
45
-    if (preg_match("#(video\/)([a-zA-Z0-9]+)([a-zA-Z0-9_-]*)#", $url_object, $chaines))
46
-    {
47
-      $ch = curl_init('https://api.dailymotion.com/video/'.$chaines[2].'&fields=thumbnail_medium_url');
48
-      
49
-      $options = array(
50
-        CURLOPT_RETURNTRANSFER => true,
51
-        CURLOPT_HTTPHEADER => array('Content-type: application/json')
52
-      );
53
-      
54
-      curl_setopt_array( $ch, $options );
55
-      $result = json_decode(curl_exec($ch));
56
-      
57
-      if (isset($result->thumbnail_medium_url))
58
-      {
59
-        $url = $result->thumbnail_medium_url;
60
-      }
61
-      
62
-    }
63
-    
64
-    return $url;
65
-  }
66
-  
67
-}
68
-
69
-?>

+ 0 - 87
src/Muzich/CoreBundle/ElementFactory/Site/DeezercomFactory.php Zobrazit soubor

@@ -1,87 +0,0 @@
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 DeezercomFactory extends BaseFactory
13
-{
14
-  
15
-  protected function getCleanedUrl($decode = false)
16
-  {
17
-    $data = parent::getCleanedUrl(true);
18
-    $data = str_replace(' ', '-', $data);
19
-    $data = strtolower($data);
20
-    
21
-    return $data;
22
-  }
23
-  
24
-  public function getEmbedCode()
25
-  {
26
-    $data = $this->getCleanedUrl(true);
27
-    
28
-    $embed = null;
29
-    $element_id = null;
30
-    $type = null;
31
-    // album
32
-    // http://www.deezer.com/fr/music/pantera/far-beyond-driven-80398
33
-    if (preg_match("#^\/[a-zA-Z_-]+\/music\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+-([0-9]+)#", $data, $chaines))
34
-    {
35
-      $element_id = $chaines[1];
36
-      $type = 'album';
37
-    }
38
-    // playlist
39
-    // http://www.deezer.com/fr/music/playlist/18701350
40
-    else if (preg_match("#^\/[a-zA-Z_-]+\/music\/playlist\/([0-9]+)#", $data, $chaines))
41
-    {
42
-      $element_id = $chaines[1];
43
-      $type = 'playlist';
44
-    }
45
-    
46
-    if ($element_id)
47
-    {
48
-      $width = $this->container->getParameter('deezer_player_width');
49
-      $heigth = $this->container->getParameter('deezer_player_height');
50
-      $embed = '<iframe scrolling="no" frameborder="0" allowTransparency="true" '
51
-        .'src="http://www.deezer.com/fr/plugins/player?autoplay=false&playlist=true'
52
-        .'&width='.$width.'&height='.$heigth.'&cover=true&btn_popup=true&type='.$type.'&id='.$element_id.'&title=" '
53
-        .'width="'.$width.'" height="'.$heigth.'"></iframe>'
54
-      ;
55
-    }
56
-    
57
-    return $embed;
58
-  }
59
-  
60
-  public function getThumbnailUrl()
61
-  {
62
-    $url_object = $this->getCleanedUrl();
63
-    $url = null;
64
-    
65
-    // album
66
-    // http://www.deezer.com/fr/music/pantera/far-beyond-driven-80398
67
-    if (preg_match("#^\/[a-zA-Z_-]+\/music\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+-([0-9]+)#", $url_object, $chaines))
68
-    {
69
-      $id = $chaines[1];
70
-      $ch = curl_init('http://api.deezer.com/2.0/album/'.$id);
71
-      $options = array(
72
-        CURLOPT_RETURNTRANSFER => true,
73
-        CURLOPT_HTTPHEADER => array('Content-type: application/json')
74
-      );
75
-      curl_setopt_array( $ch, $options );
76
-      $result = json_decode(curl_exec($ch));
77
-      
78
-      if (isset($result->cover))
79
-      {
80
-        $url = $result->cover;
81
-      }
82
-    }
83
-    
84
-    return $url;
85
-  }
86
-  
87
-}

+ 0 - 123
src/Muzich/CoreBundle/ElementFactory/Site/JamendocomFactory.php Zobrazit soubor

@@ -1,123 +0,0 @@
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 JamendocomFactory extends BaseFactory
13
-{
14
-  public function getEmbedCode()
15
-  {
16
-    $data = $this->getCleanedUrl();
17
-    
18
-    $embed_url = null;
19
-    // http://www.jamendo.com/fr/album/30661
20
-    if (preg_match("#^\/[a-zA-Z0-9_-]+\/album\/([0-9]+)#", $data, $chaines))
21
-    {
22
-      $id_album = $chaines[1];
23
-      $embed_url = "http://widgets.jamendo.com/fr/album/?album_id=$id_album&playertype=2008";
24
-    }
25
-    // http://www.jamendo.com/fr/track/207079
26
-    else if (preg_match("#^\/[a-zA-Z0-9_-]+\/track\/([0-9]+)#", $data, $chaines))
27
-    {
28
-      $id_track = $chaines[1];
29
-      $embed_url = "http://widgets.jamendo.com/fr/track/?playertype=2008&track_id=$id_track";
30
-    }
31
-    
32
-    if ($embed_url)
33
-    {
34
-      $height = $this->container->getParameter('jamendo_player_height');
35
-      $width = $this->container->getParameter('jamendo_player_width');
36
-      return  '
37
-          <object width="'.$width.'" height="'.$height.'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" align="middle">
38
-            <param name="allowScriptAccess" value="always" />
39
-            <param name="wmode" value="transparent" />
40
-            <param name="movie" value="'.$embed_url.'" />
41
-            <param name="quality" value="high" />
42
-            <param name="bgcolor" value="#FFFFFF" />
43
-            <embed src="'.$embed_url.'" quality="high" wmode="transparent" bgcolor="#FFFFFF" width="'.$width.'" height="'.$height.'" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
44
-              &nbsp;
45
-            </embed>
46
-            &nbsp;
47
-          </object>
48
-          <a href="http://pro.jamendo.com/" style="display:block;font-size:8px !important;">Catalogue professionnel de musique libre</a>
49
-        ';
50
-    }
51
-    
52
-    return null;
53
-  }
54
-  
55
-  public function getThumbnailUrl()
56
-  {
57
-    $url_object = $this->getCleanedUrl();
58
-    $get_url = null;
59
-    $url = null;
60
-    
61
-    // http://www.jamendo.com/fr/album/30661
62
-    if (preg_match("#^\/[a-zA-Z0-9_-]+\/album\/([0-9]+)#", $url_object, $chaines))
63
-    {
64
-      $id_album = $chaines[1];
65
-      $get_url = "http://api.jamendo.com/get2/image/album/json/?id=".$id_album;
66
-    }
67
-    // http://www.jamendo.com/fr/track/207079
68
-    else if (preg_match("#^\/[a-zA-Z0-9_-]+\/track\/([0-9]+)#", $url_object, $chaines))
69
-    {
70
-      /*
71
-      * Pour une track c'est un peu différent
72
-      */
73
-      $id_track = $chaines[1];
74
-      $get_album_url = "http://www.jamendo.com/get/album/id/track/page/json/".$id_track.'/';
75
-      
76
-      $ch = curl_init($get_album_url);
77
-      curl_setopt_array($ch, array(
78
-        CURLOPT_RETURNTRANSFER => true,
79
-        CURLOPT_HTTPHEADER => array('Content-type: application/json')
80
-      ));
81
-      $result = json_decode(curl_exec($ch));
82
-      if (count($result))
83
-      {
84
-        $album_url = str_replace('http://www.jamendo.com', '', $result[0]);
85
-        
86
-        $expl_alb = null;
87
-        if (preg_match("#^\/album\/([0-9]+)#", $album_url, $expl_alb))
88
-        {
89
-          $id_album = $expl_alb[1];
90
-          $get_url = "http://api.jamendo.com/get2/image/album/json/?id=".$id_album;
91
-        }
92
-      }
93
-    }
94
-    
95
-    if ($get_url)
96
-    {
97
-      $ch = curl_init($get_url);
98
-      $options = array(
99
-        CURLOPT_RETURNTRANSFER => true,
100
-        CURLOPT_HTTPHEADER => array('Content-type: text/plain')
101
-      );
102
-      curl_setopt_array( $ch, $options );
103
-      $result = json_decode(curl_exec($ch));
104
-      
105
-      if (count($result))
106
-      {
107
-        $url = $result[0];
108
-      }
109
-    }
110
-    
111
-      
112
-    /**
113
-     * www.jamendo.com/get/album/id/track/page/plain/2000/
114
-     * api.jamendo.com/get2/image/track/json/?id=
115
-     * 
116
-     * api.jamendo.com/get2/album/id/track/json/?id=
117
-     * 
118
-     */
119
-     
120
-    return $url;
121
-  }
122
-  
123
-}

+ 0 - 94
src/Muzich/CoreBundle/ElementFactory/Site/SoundcloudcomFactory.php Zobrazit soubor

@@ -1,94 +0,0 @@
1
-<?php
2
-
3
-namespace Muzich\CoreBundle\ElementFactory\Site;
4
-
5
-use Muzich\CoreBundle\ElementFactory\Site\base\BaseFactory;
6
-use Muzich\CoreBundle\Entity\Element;
7
-use Symfony\Component\DependencyInjection\Container;
8
-
9
-/**
10
- * 
11
- *
12
- * @author bux
13
- */
14
-class SoundcloudcomFactory extends BaseFactory
15
-{
16
-  public function getEmbedCode()
17
-  {
18
-    $url = str_replace('www.', '', $this->element->getUrl());
19
-    $data = $this->getCleanedUrl();
20
-    $embed_url = null;
21
-    
22
-    // http://soundcloud.com/matas/sets/library-project
23
-    if (preg_match("#^\/[a-zA-Z0-9_-]+\/sets\/[a-zA-Z0-9_-]+#", $data, $chaines))
24
-    {
25
-      $embed_url = $url;
26
-    }
27
-    // http://soundcloud.com/matas/anadrakonic-waltz
28
-    else if (preg_match("#^\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+#", $data, $chaines))
29
-    {
30
-      $embed_url = $url;
31
-    }
32
-        
33
-    // Si c'est une recherche, on gère pas !
34
-    // /search?q[fulltext]=tatou
35
-    // /tracks/search?q%5Bfulltext%5D=EEK+A+MOUSSE&q%5Btype%5D=&q%5Bduration%5D=
36
-    if (preg_match("#\/search\?q#", $data, $chaines))
37
-    {
38
-      $embed_url = null;
39
-    }
40
-    
41
-    if ($embed_url)
42
-    {
43
-      // l'url est valide pour l'api javascript que l'on utilise
44
-      
45
-      $id = md5($url);
46
-      $height = $this->container->getParameter('soundcloud_player_height');
47
-      $embed = 
48
-        '<object height="'.$height.'" width="100%" id="embed_'.$id.'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
49
-          <param name="movie" value="http://player.soundcloud.com/player.swf?url='.$embed_url.'&amp;enable_api=true&amp;object_id=embed_'.$id.'"></param>
50
-          <param name="allowscriptaccess" value="always"></param>
51
-          <embed allowscriptaccess="always" height="'.$height.'" src="http://player.soundcloud.com/player.swf?url='.$embed_url.'&amp;enable_api=true&amp;object_id=embed_'.$id.'" type="application/x-shockwave-flash" width="100%" name="embed_'.$id.'"></embed>
52
-        </object>
53
-        ';
54
-      
55
-      return $embed;
56
-    }
57
-    
58
-    return null;
59
-  }
60
-  
61
-  public function getThumbnailUrl()
62
-  {
63
-    
64
-    
65
-    $url_object = $this->element->getUrl();
66
-    $url = null;
67
-    
68
-    $ch = curl_init('http://api.soundcloud.com/resolve.json?url='.$url_object.'&client_id=39946ea18e3d78d64c0ac95a025794e1');
69
-      
70
-    $options = array(
71
-      CURLOPT_RETURNTRANSFER => true,
72
-      CURLOPT_HTTPHEADER => array('Content-type: application/json')
73
-    );
74
-
75
-    curl_setopt_array( $ch, $options );
76
-    $result = json_decode(curl_exec($ch));
77
-    
78
-    if (isset($result->errors))
79
-    {
80
-      if (count($result->errors))
81
-      {
82
-        return null;
83
-      }
84
-    }
85
-    
86
-    $getjsonurl = $result->location;
87
-    $ch = curl_init($getjsonurl);
88
-    curl_setopt_array($ch, $options);
89
-    $result = json_decode(curl_exec($ch));
90
-    
91
-    $url = $result->artwork_url;
92
-    return $url;
93
-  }
94
-}

+ 0 - 49
src/Muzich/CoreBundle/ElementFactory/Site/YoutubeFactory.php Zobrazit soubor

@@ -1,49 +0,0 @@
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
-    $embed_url = null;
18
-    
19
-    // http://youtu.be/9hQVA2sloGc
20
-    if (preg_match("#\/([a-zA-Z0-9]+)#", $url, $chaines))
21
-    {
22
-      $embed_url = 'http://www.youtube.com/embed/'.$chaines[1];
23
-    }
24
-        
25
-    if ($embed_url)
26
-    {
27
-      $width = $this->container->getParameter('youtube_player_width');
28
-      $height = $this->container->getParameter('youtube_player_height');
29
-      return '<iframe width="'.$width.'" height="'.$height.'" src="'.$embed_url.'" '
30
-        .'frameborder="0" allowfullscreen></iframe>';
31
-    }
32
-    
33
-    return null;
34
-  }
35
-  
36
-  public function getThumbnailUrl()
37
-  {
38
-    $url_object = $this->getCleanedUrl();
39
-    $url = null;
40
-    
41
-    // http://youtu.be/9hQVA2sloGc
42
-    if (preg_match("#\/([a-zA-Z0-9]+)#", $url_object, $chaines))
43
-    {
44
-      $url = 'http://img.youtube.com/vi/'.$chaines[1].'/default.jpg';
45
-    }
46
-    
47
-    return $url;
48
-  }
49
-}

+ 0 - 57
src/Muzich/CoreBundle/ElementFactory/Site/YoutubecomFactory.php Zobrazit soubor

@@ -1,57 +0,0 @@
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 YoutubecomFactory extends BaseFactory
13
-{
14
-  public function getEmbedCode()
15
-  {
16
-    $url = $this->getCleanedUrl();
17
-    $embed_url = null;
18
-    
19
-    // '/watch?v=kOLQIV22JAs&feature=feedrec_grec_index'
20
-    if (preg_match("#(v\/|watch\?v=)([\w\-]+)#", $url, $chaines))
21
-    {
22
-      $embed_url = 'http://www.youtube.com/embed/'.$chaines[2];
23
-    }
24
-    else if (preg_match("#(v=|watch\?v=)([\w\-]+)#", $url, $chaines))
25
-    {
26
-      $embed_url = 'http://www.youtube.com/embed/'.$chaines[2];
27
-    }
28
-    
29
-    if ($embed_url)
30
-    {
31
-      $width = $this->container->getParameter('youtube_player_width');
32
-      $height = $this->container->getParameter('youtube_player_height');
33
-      return '<iframe width="'.$width.'" height="'.$height.'" src="'.$embed_url.'" '
34
-        .'frameborder="0" allowfullscreen></iframe>';
35
-    }
36
-    
37
-    return null;
38
-  }
39
-  
40
-  public function getThumbnailUrl()
41
-  {
42
-    $url_object = $this->getCleanedUrl();
43
-    $url = null;
44
-    
45
-    // '/watch?v=kOLQIV22JAs&feature=feedrec_grec_index'
46
-    if (preg_match("#(v\/|watch\?v=)([\w\-]+)#", $url_object, $chaines))
47
-    {
48
-      $url = 'http://img.youtube.com/vi/'.$chaines[2].'/default.jpg';
49
-    }
50
-    else if (preg_match("#(v=|watch\?v=)([\w\-]+)#", $url_object, $chaines))
51
-    {
52
-      $url = 'http://img.youtube.com/vi/'.$chaines[2].'/default.jpg';
53
-    }
54
-    
55
-    return $url;
56
-  }
57
-}

+ 0 - 17
src/Muzich/CoreBundle/ElementFactory/Site/base/FactoryInterface.php Zobrazit soubor

@@ -1,17 +0,0 @@
1
-<?php
2
-
3
-namespace Muzich\CoreBundle\ElementFactory\Site\base;
4
-
5
-use Muzich\CoreBundle\Entity\Element;
6
-use Symfony\Component\DependencyInjection\Container;
7
-
8
-interface FactoryInterface
9
-{
10
-  
11
-  public function __construct(Element $element, Container $container);
12
-  
13
-  public function getEmbedCode();
14
-  
15
-}
16
-
17
-?>

+ 61 - 0
src/Muzich/CoreBundle/Entity/Element.php Zobrazit soubor

@@ -206,6 +206,14 @@ class Element
206 206
   protected $count_comment_report = false;
207 207
 
208 208
   /**
209
+   * Données de l'objet chez le service externe
210
+   * 
211
+   * @ORM\Column(type="text", nullable=true)
212
+   * @var type string
213
+   */
214
+  protected $datas;
215
+  
216
+  /**
209 217
    * Get id
210 218
    *
211 219
    * @return integer 
@@ -503,6 +511,59 @@ class Element
503 511
     $this->comments = json_encode($comments);
504 512
   }
505 513
   
514
+  
515
+  
516
+  /**
517
+   *
518
+   * @return type array
519
+   */
520
+  public function getDatas()
521
+  {
522
+    if ($this->datas === null)
523
+    {
524
+      return array();
525
+    }
526
+    return json_decode($this->datas, true);
527
+  }
528
+  
529
+  /**
530
+   *
531
+   * @param string $data_id
532
+   * @return all 
533
+   */
534
+  public function getData($data_id)
535
+  {
536
+    $datas = $this->getDatas();
537
+    if (array_key_exists($data_id, $datas))
538
+    {
539
+      return $datas[$data_id];
540
+    }
541
+    
542
+    return null;
543
+  }
544
+  
545
+  
546
+  /**
547
+   *
548
+   * @param array $datas 
549
+   */
550
+  public function setDatas($datas)
551
+  {
552
+    $this->datas = json_encode($datas);
553
+  }
554
+  
555
+  /**
556
+   *
557
+   * @param string $data_id
558
+   * @param all $data_value 
559
+   */
560
+  public function setData($data_id, $data_value)
561
+  {
562
+    $datas = $this->getDatas();
563
+    $datas[$data_id] = $data_value;
564
+    $this->setDatas($datas);
565
+  }
566
+  
506 567
   public function setHasTagProposition($has_prop)
507 568
   {
508 569
     $this->has_tags_proposition = $has_prop;

src/Muzich/CoreBundle/ElementFactory/Site/base/BaseFactory.php → src/Muzich/CoreBundle/Factory/ElementFactory.php Zobrazit soubor

@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 
3
-namespace Muzich\CoreBundle\ElementFactory\Site\base;
3
+namespace Muzich\CoreBundle\Factory;
4 4
 
5 5
 use Muzich\CoreBundle\Entity\Element;
6 6
 use Symfony\Component\DependencyInjection\Container;
@@ -10,9 +10,13 @@ use \Exception;
10 10
  *
11 11
  * @author bux
12 12
  */
13
-class BaseFactory implements FactoryInterface
13
+abstract class ElementFactory
14 14
 {
15 15
   
16
+  /**
17
+   *
18
+   * @var Element 
19
+   */
16 20
   protected $element;
17 21
   protected $container;
18 22
   
@@ -27,11 +31,6 @@ class BaseFactory implements FactoryInterface
27 31
     $this->container = $container;
28 32
   }
29 33
   
30
-  public function getEmbedCode()
31
-  {
32
-    return null;
33
-  }
34
-  
35 34
   /**
36 35
    * Retourne l'url relative dans le site
37 36
    * 
@@ -52,9 +51,19 @@ class BaseFactory implements FactoryInterface
52 51
     return $url;
53 52
   }
54 53
   
55
-  public function getThumbnailUrl()
54
+  public function retrieveDatas()
55
+  {
56
+    $this->element->setDatas(array());
57
+  }
58
+  
59
+  public function proceedEmbedCode()
60
+  {
61
+    $this->element->setEmbed(null);
62
+  }
63
+  
64
+  public function proceedThumbnailUrl()
56 65
   {
57
-    return null;
66
+    $this->element->setThumbnailUrl(null);
58 67
   }
59 68
   
60 69
 }

+ 74 - 0
src/Muzich/CoreBundle/Factory/Elements/Dailymotioncom.php Zobrazit soubor

@@ -0,0 +1,74 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Factory\Elements;
4
+
5
+use Muzich\CoreBundle\Factory\ElementFactory;
6
+
7
+/**
8
+ * 
9
+ *
10
+ * @author bux
11
+ */
12
+class Dailymotioncom extends ElementFactory
13
+{
14
+  
15
+  /**
16
+   * URL_API: http://www.dailymotion.com/doc/api/obj-video.html
17
+   * URL_TYPE: /video/xnqcwx_le-nazisme-dans-le-couple_fun#hp-v-v2 (c'est quoi cette url ^^ ?) 
18
+   */
19
+  public function retrieveDatas()
20
+  {
21
+    $url_clean = $this->getCleanedUrl();
22
+    $ref_id = null;
23
+    
24
+    // Récupération de l'id
25
+    if (preg_match("#(video\/)([a-zA-Z0-9]+)([a-zA-Z0-9_-]*)#", $url_clean, $preg_result))
26
+    {
27
+      $ref_id = $preg_result[2];
28
+      $this->element->setData('ref_id', $ref_id);
29
+    }
30
+    
31
+    // Récupération de données auprés de l'API
32
+    if ($ref_id)
33
+    {
34
+      $api_url = curl_init('https://api.dailymotion.com/video/'.$chaines[2]
35
+        .'&fields=thumbnail_medium_url');
36
+      
37
+      $options = array(
38
+        CURLOPT_RETURNTRANSFER => true,
39
+        CURLOPT_HTTPHEADER => array('Content-type: application/json')
40
+      );
41
+      
42
+      curl_setopt_array($api_url, $options);
43
+      $api_result = json_decode(curl_exec($api_url));
44
+      
45
+      // On récupère l'url du thumbnail
46
+      if (isset($api_result->thumbnail_medium_url))
47
+      {
48
+        $this->element->setData('thumb_medium_url', $api_result->thumbnail_medium_url);
49
+      }
50
+    }
51
+  }
52
+  
53
+  public function proceedEmbedCode()
54
+  {
55
+    if (($ref_id = $this->element->getData('ref_id')))
56
+    {
57
+      $width = $this->container->getParameter('dailymotion_player_width');
58
+      $height = $this->container->getParameter('dailymotion_player_height');
59
+      $this->element->setEmbed(
60
+        '<iframe frameborder="0" width="'.$width.'" height="'.$height.'" '
61
+        .'src="http://www.dailymotion.com/embed/video/'.$ref_id.'"></iframe>'
62
+      );
63
+    }
64
+  }
65
+  
66
+  public function proceedThumbnailUrl()
67
+  {
68
+    if (($thumb = $this->element->getData('thumb_medium_url')))
69
+    {
70
+      $this->element->setThumbnailUrl($thumb);
71
+    }
72
+  }
73
+  
74
+}

+ 91 - 0
src/Muzich/CoreBundle/Factory/Elements/Deezercom.php Zobrazit soubor

@@ -0,0 +1,91 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Factory\Elements;
4
+
5
+use Muzich\CoreBundle\Factory\ElementFactory;
6
+
7
+/**
8
+ * 
9
+ *
10
+ * @author bux
11
+ */
12
+class Deezercom extends ElementFactory
13
+{
14
+  
15
+  protected function getCleanedUrl($decode = false)
16
+  {
17
+    $data = parent::getCleanedUrl($decode);
18
+    $data = str_replace(' ', '-', $data);
19
+    $data = strtolower($data);
20
+    
21
+    return $data;
22
+  }
23
+  
24
+  /**
25
+   *  URL_PLAYLIST: http://www.deezer.com/fr/music/playlist/18701350
26
+   *  URL_ALBUM:    http://www.deezer.com/fr/music/pantera/far-beyond-driven-80398
27
+   */
28
+  public function retrieveDatas()
29
+  {
30
+    $url_clean = $this->getCleanedUrl(true);
31
+    
32
+    // album
33
+    $type   = null;
34
+    $ref_id = null;
35
+    if (preg_match("#^\/[a-zA-Z_-]+\/music\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+-([0-9]+)#", $url_clean, $chaines))
36
+    {
37
+      $type   = 'album';
38
+      $ref_id = $chaines[1];
39
+    }
40
+    // playlist
41
+    else if (preg_match("#^\/[a-zA-Z_-]+\/music\/playlist\/([0-9]+)#", $url_clean, $chaines))
42
+    {
43
+      $type = 'playlist';
44
+      $ref_id = $chaines[1];
45
+    }
46
+    
47
+    $this->element->setData('type'  , $type);
48
+    $this->element->setData('ref_id', $ref_id);
49
+    
50
+    if ($type && $ref_id)
51
+    {
52
+      // Récupération d'infos auprès de l'API
53
+      $ch = curl_init('http://api.deezer.com/2.0/'.$type.'/'.$ref_id);
54
+      $options = array(
55
+        CURLOPT_RETURNTRANSFER => true,
56
+        CURLOPT_HTTPHEADER => array('Content-type: application/json')
57
+      );
58
+      curl_setopt_array( $ch, $options );
59
+      $result = json_decode(curl_exec($ch));
60
+
61
+      if (isset($result->cover))
62
+      {
63
+        $this->element->setData('cover_url', $result->cover);
64
+      }
65
+    }
66
+  }
67
+  
68
+  public function proceedEmbedCode()
69
+  {
70
+    if (($ref_id = $this->element->getData('ref_id')) && ($type = $this->element->getData('type')))
71
+    {
72
+      $width = $this->container->getParameter('deezer_player_width');
73
+      $heigth = $this->container->getParameter('deezer_player_height');
74
+      $this->element->setEmbed(
75
+        '<iframe scrolling="no" frameborder="0" allowTransparency="true" '
76
+        .'src="http://www.deezer.com/fr/plugins/player?autoplay=false&playlist=true'
77
+        .'&width='.$width.'&height='.$heigth.'&cover=true&btn_popup=true&type='.$type.'&id='.$ref_id.'&title=" '
78
+        .'width="'.$width.'" height="'.$heigth.'"></iframe>'
79
+      );
80
+    }
81
+  }
82
+  
83
+  public function proceedThumbnailUrl()
84
+  {
85
+    if (($thumb = $this->element->getData('cover_url')))
86
+    {
87
+      $this->element->setThumbnailUrl($thumb);
88
+    }
89
+  }
90
+  
91
+}

+ 127 - 0
src/Muzich/CoreBundle/Factory/Elements/Jamendocom.php Zobrazit soubor

@@ -0,0 +1,127 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Factory\Elements;
4
+
5
+use Muzich\CoreBundle\Factory\ElementFactory;
6
+
7
+/**
8
+ * 
9
+ *
10
+ * @author bux
11
+ */
12
+class Jamendocom extends ElementFactory
13
+{
14
+  
15
+  /**
16
+   *  ALBUM = http://www.jamendo.com/fr/album/30661
17
+   *  TRACK = http://www.jamendo.com/fr/track/207079
18
+   */
19
+  public function retrieveDatas()
20
+  {
21
+    $url_clean = $this->getCleanedUrl();
22
+    
23
+    // album
24
+    $type   = null;
25
+    $ref_id = null;
26
+    if (preg_match("#^\/[a-zA-Z0-9_-]+\/album\/([0-9]+)#", $url_clean, $chaines))
27
+    {
28
+      $type   = 'album';
29
+      $ref_id = $chaines[1];
30
+    }
31
+    // track
32
+    else if (preg_match("#^\/[a-zA-Z0-9_-]+\/track\/([0-9]+)#", $url_clean, $chaines))
33
+    {
34
+      $type = 'track';
35
+      $ref_id = $chaines[1];
36
+    }
37
+    
38
+    $this->element->setData('type'  , $type);
39
+    $this->element->setData('ref_id', $ref_id);
40
+    
41
+    // Récupération de données avec l'API
42
+    $api_url = null;
43
+    switch ($type)
44
+    {
45
+      case 'album':
46
+        $api_url = "http://api.jamendo.com/get2/image/album/json/?id=".$ref_id;
47
+      break;
48
+    
49
+      /**
50
+       * Lorsque l'on a une track, il faut récupérer les infos sur l'album dans laquelle
51
+       * est la track
52
+       */
53
+      case 'track':
54
+        $get_album_url = "http://www.jamendo.com/get/album/id/track/page/json/".$ref_id.'/';
55
+
56
+        $ch = curl_init($get_album_url);
57
+        curl_setopt_array($ch, array(
58
+          CURLOPT_RETURNTRANSFER => true,
59
+          CURLOPT_HTTPHEADER => array('Content-type: application/json')
60
+        ));
61
+        $result = json_decode(curl_exec($ch));
62
+        if (count($result))
63
+        {
64
+          $album_url = str_replace('http://www.jamendo.com', '', $result[0]);
65
+
66
+          $expl_alb = null;
67
+          if (preg_match("#^\/album\/([0-9]+)#", $album_url, $expl_alb))
68
+          {
69
+            $id_album = $expl_alb[1];
70
+            $api_url = "http://api.jamendo.com/get2/image/album/json/?id=".$id_album;
71
+          }
72
+        }
73
+      break;
74
+    }
75
+    
76
+    if ($api_url)
77
+    {
78
+      $ch = curl_init($api_url);
79
+      $options = array(
80
+        CURLOPT_RETURNTRANSFER => true,
81
+        CURLOPT_HTTPHEADER => array('Content-type: text/plain')
82
+      );
83
+      curl_setopt_array( $ch, $options );
84
+      $result = json_decode(curl_exec($ch));
85
+      
86
+      if (count($result))
87
+      {
88
+        $this->element->setData('thumb_url', $result[0]);
89
+      }
90
+    }
91
+  }
92
+  
93
+  public function proceedEmbedCode()
94
+  {
95
+    if (($ref_id = $this->element->getData('ref_id')) && ($type = $this->element->getData('type')))
96
+    {
97
+      $height = $this->container->getParameter('jamendo_player_height');
98
+      $width = $this->container->getParameter('jamendo_player_width');
99
+      $embed_url = "http://widgets.jamendo.com/fr/$type/?album_id=$ref_id&playertype=2008";
100
+      $this->element->setEmbed(
101
+        '<object width="'.$width.'" height="'.$height.'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'
102
+            .' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" align="middle">
103
+            <param name="allowScriptAccess" value="always" />
104
+            <param name="wmode" value="transparent" />
105
+            <param name="movie" value="'.$embed_url.'" />
106
+            <param name="quality" value="high" />
107
+            <param name="bgcolor" value="#FFFFFF" />
108
+            <embed src="'.$embed_url.'" quality="high" wmode="transparent" bgcolor="#FFFFFF"'
109
+            .' width="'.$width.'" height="'.$height.'" align="middle" allowScriptAccess="always"'
110
+            .' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
111
+              &nbsp;
112
+            </embed>
113
+            &nbsp;
114
+          </object>'  
115
+      );
116
+    }
117
+  }
118
+  
119
+  public function proceedThumbnailUrl()
120
+  {
121
+    if (($thumb = $this->element->getData('thumb_url')))
122
+    {
123
+      $this->element->setThumbnailUrl($thumb);
124
+    }
125
+  }
126
+  
127
+}

+ 105 - 0
src/Muzich/CoreBundle/Factory/Elements/Soundcloudcom.php Zobrazit soubor

@@ -0,0 +1,105 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Factory\Elements;
4
+
5
+use Muzich\CoreBundle\Factory\ElementFactory;
6
+
7
+/**
8
+ * 
9
+ *
10
+ * @author bux
11
+ */
12
+class SoundcloudcomFactory extends ElementFactory
13
+{
14
+  
15
+  /**
16
+   * ??SET = http://soundcloud.com/matas/sets/library-project
17
+   * ??    = http://soundcloud.com/matas/anadrakonic-waltz
18
+   */
19
+  public function retrieveDatas()
20
+  {
21
+    $url_clean = $this->getCleanedUrl();
22
+    
23
+    $ref_id = null;
24
+    // ??SET
25
+    if (preg_match("#^\/[a-zA-Z0-9_-]+\/sets\/[a-zA-Z0-9_-]+#", $url_clean, $chaines))
26
+    {
27
+      $ref_id = $url;
28
+    }
29
+    // ???
30
+    else if (preg_match("#^\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+#", $url_clean, $chaines))
31
+    {
32
+      $ref_id = $url;
33
+    }
34
+    
35
+    // On en gère pas encore les recherches
36
+    if (preg_match("#\/search\?q#", $url_clean, $chaines))
37
+    {
38
+      $ref_id = null;
39
+    }
40
+    
41
+    $this->element->setData('ref_id', $ref_id);
42
+    
43
+    // récupération de données avec l'API
44
+    if ($ref_id)
45
+    {
46
+      $ch = curl_init('http://api.soundcloud.com/resolve.json?url='.$url_object.'&client_id=39946ea18e3d78d64c0ac95a025794e1');
47
+
48
+      $options = array(
49
+        CURLOPT_RETURNTRANSFER => true,
50
+        CURLOPT_HTTPHEADER => array('Content-type: application/json')
51
+      );
52
+
53
+      curl_setopt_array( $ch, $options );
54
+      $result = json_decode(curl_exec($ch));
55
+
56
+      if (isset($result->errors))
57
+      {
58
+        if (count($result->errors))
59
+        {
60
+          return null;
61
+        }
62
+      }
63
+
64
+      $getjsonurl = $result->location;
65
+      $ch = curl_init($getjsonurl);
66
+      curl_setopt_array($ch, $options);
67
+      $result = json_decode(curl_exec($ch));
68
+
69
+      if (isset($result->artwork_url))
70
+      {
71
+        $this->element->setData('artwork_url', $result->artwork_url);
72
+      }
73
+    }
74
+  }
75
+  
76
+  public function proceedEmbedCode()
77
+  {
78
+    if (($ref_id = $this->element->getData('ref_id')))
79
+    {
80
+      $embed_id = md5($ref_id);
81
+      $height = $this->container->getParameter('soundcloud_player_height');
82
+      $this->element->setEmbed(
83
+        '<object height="'.$height.'" width="100%" id="embed_'.$embed_id.'" '
84
+          .'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
85
+          <param name="movie" value="http://player.soundcloud.com/player.swf?url='.$ref_id.'&amp;'
86
+          .'enable_api=true&amp;object_id=embed_'.$embed_id.'"></param>
87
+          <param name="allowscriptaccess" value="always"></param>
88
+          <embed allowscriptaccess="always" height="'.$height.'" '
89
+          .'src="http://player.soundcloud.com/player.swf?url='.$ref_id.'&amp;enable_api=true'
90
+          .'&amp;object_id=embed_'.$embed_id.'" type="application/x-shockwave-flash" '
91
+          .'width="100%" name="embed_'.$embed_id.'"></embed>
92
+        </object>'
93
+      );
94
+    }
95
+  }
96
+  
97
+  public function proceedThumbnailUrl()
98
+  {
99
+    if (($thumb = $this->element->getData('artwork_url')))
100
+    {
101
+      $this->element->setThumbnailUrl($thumb);
102
+    }
103
+  }
104
+  
105
+}

+ 34 - 0
src/Muzich/CoreBundle/Factory/Elements/Youtube.php Zobrazit soubor

@@ -0,0 +1,34 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Factory\Elements;
4
+
5
+use Muzich\CoreBundle\Factory\Elements\Youtubecom;
6
+
7
+/**
8
+ * 
9
+ *
10
+ * @author bux
11
+ */
12
+class Youtube extends Youtubecom
13
+{
14
+  
15
+  public function retrieveDatas()
16
+  {
17
+    $url_clean = $this->getCleanedUrl();
18
+    $ref_id = null;
19
+    
20
+    if (preg_match("#\/([a-zA-Z0-9]+)#", $url_clean, $chaines))
21
+    {
22
+      $ref_id = $chaines[2];
23
+    }
24
+    
25
+    $this->element->setData('ref_id', $ref_id);
26
+    
27
+    // Données API
28
+    if ($ref_id)
29
+    {
30
+      
31
+    }
32
+  }
33
+  
34
+}

+ 61 - 0
src/Muzich/CoreBundle/Factory/Elements/Youtubecom.php Zobrazit soubor

@@ -0,0 +1,61 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Factory\Elements;
4
+
5
+use Muzich\CoreBundle\Factory\ElementFactory;
6
+
7
+/**
8
+ * 
9
+ *
10
+ * @author bux
11
+ */
12
+class Youtubecom extends ElementFactory
13
+{
14
+  
15
+  public function retrieveDatas()
16
+  {
17
+    $url_clean = $this->getCleanedUrl();
18
+    $ref_id = null;
19
+    
20
+    if (preg_match("#(v\/|watch\?v=)([\w\-]+)#", $url_clean, $chaines))
21
+    {
22
+      $ref_id = $chaines[2];
23
+    }
24
+    else if (preg_match("#(v=|watch\?v=)([\w\-]+)#", $url_clean, $chaines))
25
+    {
26
+      $ref_id = $chaines[2];
27
+    }
28
+    
29
+    $this->element->setData('ref_id', $ref_id);
30
+    
31
+    // Données API TODO: REFACTORISER
32
+    if ($ref_id)
33
+    {
34
+      
35
+    }
36
+  }
37
+  
38
+  public function proceedEmbedCode()
39
+  {
40
+    if (($ref_id = $this->element->getData('ref_id')))
41
+    {
42
+      $width = $this->container->getParameter('youtube_player_width');
43
+      $height = $this->container->getParameter('youtube_player_height');
44
+      $this->element->setEmbed(
45
+        '<iframe width="'.$width.'" height="'.$height.'" '
46
+        .'src="http://www.youtube.com/embed/'.$ref_id.'" '
47
+        .'frameborder="0" allowfullscreen></iframe>'
48
+      );
49
+    }
50
+  }
51
+  
52
+  public function proceedThumbnailUrl()
53
+  {
54
+    if (($ref_id = $this->element->getData('ref_id')))
55
+    {
56
+      $this->element->setThumbnailUrl(
57
+        'http://img.youtube.com/vi/'.$ref_id.'/default.jpg'        
58
+      );
59
+    }
60
+  }
61
+}

src/Muzich/CoreBundle/ElementFactory/ElementManager.php → src/Muzich/CoreBundle/Managers/ElementManager.php Zobrazit soubor

@@ -1,18 +1,18 @@
1 1
 <?php
2 2
 
3
-namespace Muzich\CoreBundle\ElementFactory;
3
+namespace Muzich\CoreBundle\Managers;
4 4
 
5 5
 use Muzich\CoreBundle\Entity\Element;
6 6
 use Muzich\CoreBundle\Entity\User;
7 7
 use Doctrine\ORM\EntityManager;
8 8
 use Symfony\Component\DependencyInjection\Container;
9 9
 
10
-use Muzich\CoreBundle\ElementFactory\Site\YoutubecomFactory;
11
-use Muzich\CoreBundle\ElementFactory\Site\YoutubeFactory;
12
-use Muzich\CoreBundle\ElementFactory\Site\DailymotioncomFactory;
13
-use Muzich\CoreBundle\ElementFactory\Site\JamendocomFactory;
14
-use Muzich\CoreBundle\ElementFactory\Site\SoundcloudcomFactory;
15
-use Muzich\CoreBundle\ElementFactory\Site\DeezercomFactory;
10
+use Muzich\CoreBundle\Factory\Elements\YoutubecomFactory;
11
+use Muzich\CoreBundle\Factory\Elements\YoutubeFactory;
12
+use Muzich\CoreBundle\Factory\Elements\DailymotioncomFactory;
13
+use Muzich\CoreBundle\Factory\Elements\JamendocomFactory;
14
+use Muzich\CoreBundle\Factory\Elements\SoundcloudcomFactory;
15
+use Muzich\CoreBundle\Factory\Elements\DeezercomFactory;
16 16
 
17 17
 /**
18 18
  * 
@@ -130,8 +130,11 @@ class ElementManager
130 130
     if (in_array($this->element->getType(), $this->factories))
131 131
     {
132 132
       $site_factory = $this->getFactory();
133
-      $this->element->setEmbed($site_factory->getEmbedCode());
134
-      $this->element->setThumbnailUrl($site_factory->getThumbnailUrl());
133
+      // On récupères les datas de l'élément
134
+      $site_factory->retrieveDatas();
135
+      // On procède a la construction de nos informations
136
+      $site_factory->proceedEmbedCode();
137
+      $site_factory->proceedThumbnailUrl();
135 138
     }
136 139
     
137 140
   }