]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
Add proper support for proxies
[tt-rss.git] / include / functions.php
index 02d0416f8e863fe462cf76f42854eec11aa785cc..f58a2fc6865c8b4d0cf24c9cafda539f80b09eb8 100644 (file)
                                curl_setopt($ch, CURLOPT_COOKIEJAR, "/dev/null");
                        }
 
-                       if (defined('_CURL_HTTP_PROXY')) {
-                               curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);
+                       if (defined('PROXY')) {
+                               curl_setopt($ch, CURLOPT_PROXY, PROXY);
                        }
 
                        if ($post_query) {
 
                        // TODO: should this support POST requests or not? idk
 
+                        $context_options = array(
+                                 'http' => array(
+                                               'method' => 'GET',
+                                           'ignore_errors' => true,
+                                           'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
+                                               'protocol_version'=> 1.1)
+                                 );
+
                        if (!$post_query && $last_modified) {
-                                $context = stream_context_create(array(
-                                         'http' => array(
-                                                       'method' => 'GET',
-                                                   'ignore_errors' => true,
-                                                   'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
-                                                       'protocol_version'=> 1.1,
-                                                       'header' => "If-Modified-Since: $last_modified\r\n")
-                                         ));
-                       } else {
-                                $context = stream_context_create(array(
-                                         'http' => array(
-                                                       'method' => 'GET',
-                                                   'ignore_errors' => true,
-                                                   'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
-                                                       'protocol_version'=> 1.1
-                                         )));
+                $context_options['http']['header'] = "If-Modified-Since: $last_modified\r\n";
                        }
 
+                       if (defined('PROXY')) {
+                               $context_options['http']['proxy'] = PROXY;
+                       }
+
+            $context = stream_context_create($context_options);
+
                        $old_error = error_get_last();
 
                        $data = @file_get_contents($url, false, $context);
        // this is used for user http parameters unless HTML code is actually needed
        function clean($param) {
                if (is_array($param)) {
-                       return array_map(strip_tags, $param);
+                       return array_map("strip_tags", $param);
                } else if (is_string($param)) {
                        return strip_tags($param);
                } else {
        }
 
        function bool_to_sql_bool($s) {
-               return (bool)$s; //no-op for PDO
+               return $s ? 1 : 0;
        }
 
        // Session caching removed due to causing wrong redirects to upgrade
                if ($search_language)
                        $search_language = $pdo->quote(mb_strtolower($search_language));
                else
-                       $search_language = "english";
+                       $search_language = $pdo->quote("english");
 
                foreach ($keywords as $k) {
                        if (strpos($k, "-") === 0) {
                        }
 
                        if ($entry->nodeName == 'img') {
+                               $entry->setAttribute('referrerpolicy', 'no-referrer');
 
                                if ($entry->hasAttribute('src')) {
                                        $is_https_url = parse_url($entry->getAttribute('src'), PHP_URL_SCHEME) === 'https';
                                        if ($rule["cat_id"] > 0) {
                                                $children = Feeds::getChildCategories($rule["cat_id"], $owner_uid);
                                                array_push($children, $rule["cat_id"]);
+                                               $children = array_map("intval", $children);
 
                                                $children = join(",", $children);