| 
				
			 | 
			
			
				@@ -4,61 +4,82 @@ namespace Muzich\CoreBundle\Factory\Elements; 
			 | 
		
	
		
			
			| 
				4
			 | 
			
				4
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				5
			 | 
			
				5
			 | 
			
			
				 use Muzich\CoreBundle\Factory\ElementFactory; 
			 | 
		
	
		
			
			| 
				6
			 | 
			
				6
			 | 
			
			
				 use Muzich\CoreBundle\Entity\Element; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				7
			 | 
			
			
				+use Muzich\CoreBundle\Factory\UrlMatchs; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				8
			 | 
			
			
				+use Symfony\Component\DependencyInjection\Container; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				9
			 | 
			
			
				+use Doctrine\ORM\EntityManager; 
			 | 
		
	
		
			
			| 
				7
			 | 
			
				10
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				8
			 | 
			
				
			 | 
			
			
				-/** 
			 | 
		
	
		
			
			| 
				9
			 | 
			
				
			 | 
			
			
				- *  
			 | 
		
	
		
			
			| 
				10
			 | 
			
				
			 | 
			
			
				- * 
			 | 
		
	
		
			
			| 
				11
			 | 
			
				
			 | 
			
			
				- * @author bux 
			 | 
		
	
		
			
			| 
				12
			 | 
			
				
			 | 
			
			
				- */ 
			 | 
		
	
		
			
			| 
				13
			 | 
			
				11
			 | 
			
			
				 class Youtubecom extends ElementFactory 
			 | 
		
	
		
			
			| 
				14
			 | 
			
				12
			 | 
			
			
				 { 
			 | 
		
	
		
			
			| 
				15
			 | 
			
				13
			 | 
			
			
				    
			 | 
		
	
		
			
			| 
				16
			 | 
			
				
			 | 
			
			
				-  protected function proceedAPIDatas($ref_id) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+  public function __construct(Element $element, Container $container, EntityManager $entity_manager) 
			 | 
		
	
		
			
			| 
				17
			 | 
			
				15
			 | 
			
			
				   { 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				
			 | 
			
			
				-    $video_data_dom = new \DOMDocument; 
			 | 
		
	
		
			
			| 
				19
			 | 
			
				
			 | 
			
			
				-    try { 
			 | 
		
	
		
			
			| 
				20
			 | 
			
				
			 | 
			
			
				-      $video_data_dom->load("http://gdata.youtube.com/feeds/api/videos/". $ref_id); 
			 | 
		
	
		
			
			| 
				21
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				22
			 | 
			
				
			 | 
			
			
				-      if ($video_data_dom->getElementsByTagName("title")) 
			 | 
		
	
		
			
			| 
				23
			 | 
			
				
			 | 
			
			
				-      { 
			 | 
		
	
		
			
			| 
				24
			 | 
			
				
			 | 
			
			
				-        if ($video_data_dom->getElementsByTagName("title")->item(0)) 
			 | 
		
	
		
			
			| 
				25
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				26
			 | 
			
				
			 | 
			
			
				-          if (($title = $video_data_dom->getElementsByTagName("title")->item(0)->nodeValue)) 
			 | 
		
	
		
			
			| 
				27
			 | 
			
				
			 | 
			
			
				-          { 
			 | 
		
	
		
			
			| 
				28
			 | 
			
				
			 | 
			
			
				-            $this->element->setData(Element::DATA_TITLE, $title); 
			 | 
		
	
		
			
			| 
				29
			 | 
			
				
			 | 
			
			
				-          } 
			 | 
		
	
		
			
			| 
				30
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				31
			 | 
			
				
			 | 
			
			
				-      } 
			 | 
		
	
		
			
			| 
				32
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				33
			 | 
			
				
			 | 
			
			
				-    catch (\ErrorException $e) 
			 | 
		
	
		
			
			| 
				34
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				35
			 | 
			
				
			 | 
			
			
				-      // Api injoignable 
			 | 
		
	
		
			
			| 
				36
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				+    $this->url_matchs = UrlMatchs::$youtube; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				17
			 | 
			
			
				+    parent::__construct($element, $container, $entity_manager); 
			 | 
		
	
		
			
			| 
				37
			 | 
			
				18
			 | 
			
			
				   } 
			 | 
		
	
		
			
			| 
				38
			 | 
			
				19
			 | 
			
			
				    
			 | 
		
	
		
			
			| 
				39
			 | 
			
				
			 | 
			
			
				-  public function retrieveDatas() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				+  public function proceedDatas() 
			 | 
		
	
		
			
			| 
				40
			 | 
			
				21
			 | 
			
			
				   { 
			 | 
		
	
		
			
			| 
				41
			 | 
			
				
			 | 
			
			
				-    $url_clean = $this->getCleanedUrl(); 
			 | 
		
	
		
			
			| 
				42
			 | 
			
				
			 | 
			
			
				-    $ref_id = null; 
			 | 
		
	
		
			
			| 
				43
			 | 
			
				
			 | 
			
			
				-     
			 | 
		
	
		
			
			| 
				44
			 | 
			
				
			 | 
			
			
				-    if (preg_match("#(v\/|watch\?v=)([\w\-]+)#", $url_clean, $chaines)) 
			 | 
		
	
		
			
			| 
				45
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				46
			 | 
			
				
			 | 
			
			
				-      $ref_id = $chaines[2]; 
			 | 
		
	
		
			
			| 
				47
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				48
			 | 
			
				
			 | 
			
			
				-    else if (preg_match("#(v=|watch\?v=)([\w\-]+)#", $url_clean, $chaines)) 
			 | 
		
	
		
			
			| 
				49
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				50
			 | 
			
				
			 | 
			
			
				-      $ref_id = $chaines[2]; 
			 | 
		
	
		
			
			| 
				51
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				52
			 | 
			
				
			 | 
			
			
				-     
			 | 
		
	
		
			
			| 
				53
			 | 
			
				
			 | 
			
			
				-    $this->element->setData(Element::DATA_REF_ID, $ref_id); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				22
			 | 
			
			
				+    $this->setElementDatasWithApi(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				23
			 | 
			
			
				+    $this->proceedEmbedCode(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				+    $this->proceedThumbnailUrl(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				+  } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				+   
			 | 
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				+  protected function setElementDatasWithApi() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				28
			 | 
			
			
				+  { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				+    $response = $this->getApiConnector()->getResponseForUrl('https://www.googleapis.com/youtube/v3/videos?id=' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				+      .$this->url_analyzer->getRefId().'&key=AIzaSyC1DjeoUerFTUDdf2Rw8L8znEWbueGeykg&part=snippet,contentDetails,statistics,status'); 
			 | 
		
	
		
			
			| 
				54
			 | 
			
				31
			 | 
			
			
				      
			 | 
		
	
		
			
			| 
				55
			 | 
			
				
			 | 
			
			
				-    // Données API TODO: REFACTORISER 
			 | 
		
	
		
			
			| 
				56
			 | 
			
				
			 | 
			
			
				-    if ($ref_id) 
			 | 
		
	
		
			
			| 
				57
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				58
			 | 
			
				
			 | 
			
			
				-      $this->proceedAPIDatas($ref_id); 
			 | 
		
	
		
			
			| 
				59
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+    $this->getApiConnector()->setElementDatasWithResponse($response, array( 
			 | 
		
	
		
			
			| 
				
			 | 
			
				33
			 | 
			
			
				+      Element::DATA_THUMB_URL  => array('items' => array(0 => array('thumbnails' => 'medium'))), 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+      Element::DATA_TITLE      => array('items' => array(0 => array('snippet' => 'title'))), 
			 | 
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				+    )); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				+    // 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+    //die(var_dump($response->getContent())); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+    // 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+    //$video_data_dom = new \DOMDocument; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+    //try { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+    //  $video_data_dom->load("http://gdata.youtube.com/feeds/api/videos/". $ref_id); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+    // 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+    //  if ($video_data_dom->getElementsByTagName("title")) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+    //  { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+    //    if ($video_data_dom->getElementsByTagName("title")->item(0)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+    //    { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+    //      if (($title = $video_data_dom->getElementsByTagName("title")->item(0)->nodeValue)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+    //      { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+    //        $this->element->setData(Element::DATA_TITLE, $title); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+    //      } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+    //    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+    //  } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+    //} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+    //catch (\ErrorException $e) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+    //{ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+    //  // Api injoignable 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+    //} 
			 | 
		
	
		
			
			| 
				60
			 | 
			
				58
			 | 
			
			
				   } 
			 | 
		
	
		
			
			| 
				61
			 | 
			
				59
			 | 
			
			
				    
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+  //public function retrieveDatas() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				+  //{ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+  //  $url_clean = $this->getCleanedUrl(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				+  //  $ref_id = null; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				+  //   
			 | 
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				+  //  if (preg_match("#(v\/|watch\?v=)([\w\-]+)#", $url_clean, $chaines)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				+  //  { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				+  //    $ref_id = $chaines[2]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				+  //  } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				+  //  else if (preg_match("#(v=|watch\?v=)([\w\-]+)#", $url_clean, $chaines)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				+  //  { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				71
			 | 
			
			
				+  //    $ref_id = $chaines[2]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				72
			 | 
			
			
				+  //  } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				73
			 | 
			
			
				+  //   
			 | 
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				+  //  $this->element->setData(Element::DATA_REF_ID, $ref_id); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				+  //   
			 | 
		
	
		
			
			| 
				
			 | 
			
				76
			 | 
			
			
				+  //  // Données API TODO: REFACTORISER 
			 | 
		
	
		
			
			| 
				
			 | 
			
				77
			 | 
			
			
				+  //  if ($ref_id) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				+  //  { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				+  //    $this->proceedAPIDatas($ref_id); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				80
			 | 
			
			
				+  //  } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				+  //} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+   
			 | 
		
	
		
			
			| 
				62
			 | 
			
				83
			 | 
			
			
				   public function proceedEmbedCode() 
			 | 
		
	
		
			
			| 
				63
			 | 
			
				84
			 | 
			
			
				   { 
			 | 
		
	
		
			
			| 
				64
			 | 
			
				85
			 | 
			
			
				     if (($ref_id = $this->element->getData(Element::DATA_REF_ID))) 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -78,7 +99,7 @@ class Youtubecom extends ElementFactory 
			 | 
		
	
		
			
			| 
				78
			 | 
			
				99
			 | 
			
			
				     if (($ref_id = $this->element->getData(Element::DATA_REF_ID))) 
			 | 
		
	
		
			
			| 
				79
			 | 
			
				100
			 | 
			
			
				     { 
			 | 
		
	
		
			
			| 
				80
			 | 
			
				101
			 | 
			
			
				       $this->element->setThumbnailUrl( 
			 | 
		
	
		
			
			| 
				81
			 | 
			
				
			 | 
			
			
				-        'http://img.youtube.com/vi/'.$ref_id.'/default.jpg'         
			 | 
		
	
		
			
			| 
				
			 | 
			
				102
			 | 
			
			
				+        'http://img.youtube.com/vi/'.$ref_id.'/default.jpg' 
			 | 
		
	
		
			
			| 
				82
			 | 
			
				103
			 | 
			
			
				       ); 
			 | 
		
	
		
			
			| 
				83
			 | 
			
				104
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				84
			 | 
			
				105
			 | 
			
			
				   } 
			 |