]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
Merge branch 'master' of git.fakecake.org:tt-rss
[tt-rss.git] / include / functions.php
index d54dacdc60e56c0c636824f3aa52d9a29e6a33cb..b6e49716cd88ee710ede90a9fb835fb996f35761 100755 (executable)
                $useragent = isset($options["useragent"]) ? $options["useragent"] : false;
                $followlocation = isset($options["followlocation"]) ? $options["followlocation"] : true;
                $max_size = isset($options["max_size"]) ? $options["max_size"] : MAX_DOWNLOAD_FILE_SIZE; // in bytes
+               $http_accept = isset($options["http_accept"]) ? $options["http_accept"] : false;
 
                $url = ltrim($url, ' ');
                $url = str_replace(' ', '%20', $url);
 
                        $ch = curl_init($url);
 
-                       if ($last_modified && !$post_query) {
-                               curl_setopt($ch, CURLOPT_HTTPHEADER,
-                                       array("If-Modified-Since: $last_modified"));
-                       }
+                       $curl_http_headers = [];
+
+                       if ($last_modified && !$post_query)
+                               array_push($curl_http_headers, "If-Modified-Since: $last_modified");
+
+                       if ($http_accept)
+                               array_push($curl_http_headers, "Accept: " . $http_accept);
+
+                       if (count($curl_http_headers) > 0)
+                               curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers);
 
                        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT);
                        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : FILE_FETCH_TIMEOUT);
 
                        if ($max_size) {
                                curl_setopt($ch, CURLOPT_NOPROGRESS, false);
-                               curl_setopt($ch, CURLOPT_BUFFERSIZE, 256); // needed to get 5 arguments in progress function?
+                               curl_setopt($ch, CURLOPT_BUFFERSIZE, 16384); // needed to get 5 arguments in progress function?
 
                                // holy shit closures in php
                                // download & upload are *expected* sizes respectively, could be zero
                                                'protocol_version'=> 1.1)
                                  );
 
-                       if (!$post_query && $last_modified) {
+                       if (!$post_query && $last_modified)
                                array_push($context_options['http']['header'], "If-Modified-Since: $last_modified");
-                       }
+
+                       if ($http_accept)
+                               array_push($context_options['http']['header'], "Accept: $http_accept");
 
                        if (defined('_HTTP_PROXY')) {
                                $context_options['http']['request_fulluri'] = true;
                $profile = $profile ? $profile : null;
 
                $u_sth = $pdo->prepare("SELECT pref_name
-                       FROM ttrss_user_prefs WHERE owner_uid = :uid AND 
+                       FROM ttrss_user_prefs WHERE owner_uid = :uid AND
                                (profile = :profile OR (:profile IS NULL AND profile IS NULL))");
                $u_sth->execute([':uid' => $uid, ':profile' => $profile]);
 
 
                                /* cleanup ccache */
 
-                               $sth = $pdo->prepare("DELETE FROM ttrss_counters_cache WHERE owner_uid = ? 
+                               $sth = $pdo->prepare("DELETE FROM ttrss_counters_cache WHERE owner_uid = ?
                                        AND
                                                (SELECT COUNT(id) FROM ttrss_feeds WHERE
                                                        ttrss_feeds.id = feed_id) = 0");
 
                                $sth->execute([$_SESSION['uid']]);
 
-                               $sth = $pdo->prepare("DELETE FROM ttrss_cat_counters_cache WHERE owner_uid = ? 
+                               $sth = $pdo->prepare("DELETE FROM ttrss_cat_counters_cache WHERE owner_uid = ?
                                        AND
                                                (SELECT COUNT(id) FROM ttrss_feed_categories WHERE
                                                        ttrss_feed_categories.id = feed_id) = 0");
                $search_query_leftover = array();
 
                $pdo = Db::pdo();
-               
+
                if ($search_language)
                        $search_language = $pdo->quote(mb_strtolower($search_language));
                else
                }
 
                $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories
-                               WHERE (parent_cat = :parent OR (:parent IS NULL AND parent_cat IS NULL)) 
+                               WHERE (parent_cat = :parent OR (:parent IS NULL AND parent_cat IS NULL))
                                AND title = :title AND owner_uid = :uid");
                $sth->execute([':parent' => $parent_cat_id, ':title' => $feed_cat, ':uid' => $_SESSION['uid']]);
 
        }
 
        function get_minified_js($files) {
-               require_once 'lib/jshrink/Minifier.php';
 
                $rv = '';
 
                        }
 
                        $mimetype = mime_content_type($filename);
+
+                       // this is hardly ideal but 1) only media is cached in images/ and 2) seemingly only mp4
+                       // video files are detected as octet-stream by mime_content_type()
+
+                       if ($mimetype == "application/octet-stream")
+                               $mimetype = "video/mp4";
+
                        header("Content-type: $mimetype");
 
                        $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)) . " GMT";