]> git.wh0rd.org - tt-rss.git/blobdiff - functions.php
new option: USE_CURL_FOR_ICONS (closes #101), add some CRs to error messages
[tt-rss.git] / functions.php
index 99cea3e6fff2336f1f297961affb199b1bbe886c..6ed06898bf8f40f655f796d6b6083e1ccfdc576f 100644 (file)
                $icon_file = ICONS_DIR . "/$feed.ico";
 
                if (!file_exists($icon_file)) {
-                               
-                       error_reporting(0);
-                       $r = fopen($icon_url, "r");
-                       error_reporting (DEFAULT_ERROR_LEVEL);
 
-                       if ($r) {
-                               $tmpfname = tempnam(TMP_DIRECTORY, "ttrssicon");
-                       
-                               $t = fopen($tmpfname, "w");
-                               
-                               while (!feof($r)) {
-                                       $buf = fread($r, 16384);
-                                       fwrite($t, $buf);
-                               }
-                               
-                               fclose($r);
-                               fclose($t);
+                       if (USE_CURL_FOR_ICONS) {
+                               //error_reporting(0);
+                               $ch = curl_init($icon_url);
+                               $fp = fopen($icon_file, "w");
 
-                               error_reporting(0);
-                               if (!rename($tmpfname, $icon_file)) {
-                                       unlink($tmpfname);
+                               if ($fp) {
+                                       curl_setopt($ch, CURLOPT_FILE, $fp);
+                                       curl_setopt($ch, CURLOPT_FILE, $fp);
+
+                                       curl_exec($ch);
+                                       curl_close($ch);
+                                       fclose($fp);                                    
                                }
 
-                               chmod($icon_file, 0644);
-                               
+                               //error_reporting (DEFAULT_ERROR_LEVEL);
+
+                       } else {
+
+                               error_reporting(0);
+                               $r = fopen($icon_url, "r");
                                error_reporting (DEFAULT_ERROR_LEVEL);
+       
+                               if ($r) {
+                                       $tmpfname = tempnam(TMP_DIRECTORY, "ttrssicon");
+                               
+                                       $t = fopen($tmpfname, "w");
+                                       
+                                       while (!feof($r)) {
+                                               $buf = fread($r, 16384);
+                                               fwrite($t, $buf);
+                                       }
+                                       
+                                       fclose($r);
+                                       fclose($t);
+       
+                                       error_reporting(0);
+                                       if (!rename($tmpfname, $icon_file)) {
+                                               unlink($tmpfname);
+                                       }
+       
+                                       chmod($icon_file, 0644);
+                                       
+                                       error_reporting (DEFAULT_ERROR_LEVEL);
+                               }
 
                        }       
                }