]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
unify houskeeping stuff, increase spawn interval
[tt-rss.git] / include / functions.php
index 88484cadd6a925ff6284934a77fa7993a8d43568..a41d3a950c6ba393fd827b0389ba778e08271169 100644 (file)
                                $ch = curl_init($url);
                        }
 
-                       if ($timestamp) {
+                       if ($timestamp && !$post_query) {
                                curl_setopt($ch, CURLOPT_HTTPHEADER,
                                        array("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T', $timestamp)));
                        }
                                }
                        }
 
-                       $data = @file_get_contents($url);
+                       if (!$post_query && $timestamp) {
+                               $context = stream_context_create(array(
+                                       'http' => array(
+                                               'method' => 'GET',
+                                               'header' => "If-Modified-Since: ".gmdate("D, d M Y H:i:s \\G\\M\\T\r\n", $timestamp)
+                                       )));
+                       } else {
+                               $context = NULL;
+                       }
+
+                       $old_error = error_get_last();
+
+                       $data = @file_get_contents($url, false, $context);
 
                        $fetch_last_content_type = false;  // reset if no type was sent from server
-                       if (is_array($http_response_header)) {
+                       if (isset($http_response_header) && is_array($http_response_header)) {
                                foreach ($http_response_header as $h) {
                                        if (substr(strtolower($h), 0, 13) == 'content-type:') {
                                                $fetch_last_content_type = substr($h, 14);
                                                // don't abort here b/c there might be more than one
                                                // e.g. if we were being redirected -- last one is the right one
                                        }
+
+                                       if (substr(strtolower($h), 0, 7) == 'http/1.') {
+                                               $fetch_last_error_code = (int) substr($h, 9, 3);
+                                       }
                                }
                        }
 
-                       if (!$data && function_exists('error_get_last')) {
+                       if (!$data) {
                                $error = error_get_last();
-                               $fetch_last_error = $error["message"];
+
+                               if ($error['message'] != $old_error['message']) {
+                                       $fetch_last_error = $error["message"];
+                               } else {
+                                       $fetch_last_error = "HTTP Code: $fetch_last_error_code";
+                               }
                        }
                        return $data;
                }
        function get_schema_version($nocache = false) {
                global $schema_version;
 
-               if (!$schema_version) {
+               if (!$schema_version && !$nocache) {
                        $result = db_query("SELECT schema_version FROM ttrss_version");
                        $version = db_fetch_result($result, 0, "schema_version");
                        $schema_version = $version;
                        $url = key($feedUrls);
                }
 
-               libxml_use_internal_errors(true);
+               /* libxml_use_internal_errors(true);
                $doc = new DOMDocument();
-               $doc->loadXML(html_entity_decode($contents));
+               $doc->loadXML($contents);
                $error = libxml_get_last_error();
                libxml_clear_errors();
 
                        $error_message = format_libxml_error($error);
 
                        return array("code" => 6, "message" => $error_message);
-               }
+               } */
 
                if ($cat_id == "0" || !$cat_id) {
                        $cat_qpart = "NULL";