]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
support If-Modified-Since
[tt-rss.git] / include / functions.php
index 36d349b54342b0261f1c1a4993d0b745118815f3..307f662009b14dc83c304a86477f4a5e57c96508 100644 (file)
@@ -6,6 +6,7 @@
        define('PLUGIN_FEED_BASE_INDEX', -128);
 
        $fetch_last_error = false;
+       $fetch_last_error_code = false;
        $pluginhost = false;
 
        function __autoload($class) {
                }
        }
 
-       function fetch_file_contents($url, $type = false, $login = false, $pass = false, $post_query = false, $timeout = false) {
+       function fetch_file_contents($url, $type = false, $login = false, $pass = false, $post_query = false, $timeout = false, $timestamp = 0) {
 
                global $fetch_last_error;
+               global $fetch_last_error_code;
 
                if (function_exists('curl_init') && !ini_get("open_basedir")) {
 
                                $ch = curl_init($url);
                        }
 
+                       if ($timestamp) {
+                               curl_setopt($ch, CURLOPT_HTTPHEADER,
+                                       array("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T', $timestamp)));
+                       }
+
                        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : 15);
                        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : 45);
                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("safe_mode"));
                        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                        $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
 
+                       $fetch_last_error_code = $http_code;
+
                        if ($http_code != 200 || $type && strpos($content_type, "$type") === false) {
                                if (curl_errno($ch) != 0) {
                                        $fetch_last_error = curl_errno($ch) . " " . curl_error($ch);