浏览代码

Evolution #383: Gestion des api indisponibles

Sevajol Bastien 12 年前
父节点
当前提交
32c97f0edc

+ 2 - 2
src/Muzich/CoreBundle/Factory/Elements/Dailymotioncom.php 查看文件

23
     $ref_id = null;
23
     $ref_id = null;
24
     
24
     
25
     // Récupération de l'id
25
     // Récupération de l'id
26
-    if (preg_match("#(video\/)([a-zA-Z0-9]+)([a-zA-Z0-9_-]*)#", $url_clean, $preg_result))
26
+    if (preg_match("#\/(video\/)([a-zA-Z0-9]+)([a-zA-Z0-9_-]*)#", $url_clean, $preg_result))
27
     {
27
     {
28
       $ref_id = $preg_result[2];
28
       $ref_id = $preg_result[2];
29
       $this->element->setData(Element::DATA_REF_ID, $ref_id);
29
       $this->element->setData(Element::DATA_REF_ID, $ref_id);
42
       
42
       
43
       curl_setopt_array($api_url, $options);
43
       curl_setopt_array($api_url, $options);
44
       $api_result = json_decode(curl_exec($api_url));
44
       $api_result = json_decode(curl_exec($api_url));
45
-      
45
+            
46
       // On récupère l'url du thumbnail
46
       // On récupère l'url du thumbnail
47
       if (isset($api_result->thumbnail_medium_url))
47
       if (isset($api_result->thumbnail_medium_url))
48
       {
48
       {

+ 18 - 6
src/Muzich/CoreBundle/Factory/Elements/Soundcloudcom.php 查看文件

57
       curl_setopt_array( $ch, $options );
57
       curl_setopt_array( $ch, $options );
58
       $result = json_decode(curl_exec($ch));
58
       $result = json_decode(curl_exec($ch));
59
 
59
 
60
-      if (isset($result->errors))
60
+      if (!isset($result->errors))
61
       {
61
       {
62
-        if (count($result->errors))
63
-        {
64
-          return null;
65
-        }
62
+        return;
66
       }
63
       }
67
-
64
+      
65
+      if (count($result->errors))
66
+      {
67
+        return;  
68
+      }
69
+      
70
+      if (!isset($result->location))
71
+      {
72
+        return null;
73
+      }
74
+      
75
+      if (!$result->location)
76
+      {
77
+        return null;
78
+      }
79
+      
68
       $getjsonurl = $result->location;
80
       $getjsonurl = $result->location;
69
       // On a maintenant la bonne url pour demander les infos
81
       // On a maintenant la bonne url pour demander les infos
70
       $ch = curl_init($getjsonurl);
82
       $ch = curl_init($getjsonurl);

+ 16 - 4
src/Muzich/CoreBundle/Factory/Elements/Youtubecom.php 查看文件

16
   protected function proceedAPIDatas($ref_id)
16
   protected function proceedAPIDatas($ref_id)
17
   {
17
   {
18
     $video_data_dom = new \DOMDocument;
18
     $video_data_dom = new \DOMDocument;
19
-    $video_data_dom->load("http://gdata.youtube.com/feeds/api/videos/". $ref_id);
20
-    
21
-    if (($title = $video_data_dom->getElementsByTagName("title")->item(0)->nodeValue))
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)
22
     {
34
     {
23
-      $this->element->setData(Element::DATA_TITLE, $title);
35
+      // Api injoignable
24
     }
36
     }
25
   }
37
   }
26
   
38