]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
Added support to fetch_file_contents() to explicitly set CURLOPT_FOLLOWLOCATION.
[tt-rss.git] / include / functions.php
old mode 100755 (executable)
new mode 100644 (file)
index 0a74db8..17bd9f3
@@ -16,7 +16,9 @@
 
        libxml_disable_entity_loader(true);
 
-       mb_internal_encoding("UTF-8");
+       // separate test because this is included before sanity checks
+       if (function_exists("mb_internal_encoding")) mb_internal_encoding("UTF-8");
+
        date_default_timezone_set('UTC');
        if (defined('E_DEPRECATED')) {
                error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
        define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . VERSION . ' (http://tt-rss.org/)');
        ini_set('user_agent', SELF_USER_AGENT);
 
-       require_once 'lib/pubsubhubbub/publisher.php';
+       require_once 'lib/pubsubhubbub/Publisher.php';
 
        $schema_version = false;
 
                global $fetch_last_content_type;
                global $fetch_curl_used;
 
-               if (!is_array($options) && func_num_args() > 1) {
+               if (!is_array($options)) {
 
                        // falling back on compatibility shim
                        $options = array(
                $timeout = isset($options["timeout"]) ? $options["timeout"] : false;
                $timestamp = isset($options["timestamp"]) ? $options["timestamp"] : 0;
                $useragent = isset($options["useragent"]) ? $options["useragent"] : false;
+               $followlocation = isset($options["followlocation"]) ? $options["followlocation"] : true;
 
                $url = ltrim($url, ' ');
                $url = str_replace(' ', '%20', $url);
 
                        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT);
                        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : FILE_FETCH_TIMEOUT);
-                       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir"));
+                       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir") && $followlocation);
                        curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
                        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                }
                        }
 
+                       // TODO: should this support POST requests or not? idk
+
                        if (!$post_query && $timestamp) {
                                 $context = stream_context_create(array(
                                          'http' => array(
                                                        'method' => 'GET',
+                                                   'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
                                                        'protocol_version'=> 1.1,
                                                        'header' => "If-Modified-Since: ".gmdate("D, d M Y H:i:s \\G\\M\\T\r\n", $timestamp)
                                          )));
                                 $context = stream_context_create(array(
                                          'http' => array(
                                                        'method' => 'GET',
+                                                   'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
                                                        'protocol_version'=> 1.1
                                          )));
                        }
                return $csrf_token == $_SESSION['csrf_token'];
        }
 
-       function load_user_plugins($owner_uid) {
+       function load_user_plugins($owner_uid, $pluginhost = false) {
+
+               if (!$pluginhost) $pluginhost = PluginHost::getInstance();
+
                if ($owner_uid && SCHEMA_VERSION >= 100) {
                        $plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
 
-                       PluginHost::getInstance()->load($plugins, PluginHost::KIND_USER, $owner_uid);
+                       $pluginhost->load($plugins, PluginHost::KIND_USER, $owner_uid);
 
                        if (get_schema_version() > 100) {
-                               PluginHost::getInstance()->load_data();
+                               $pluginhost->load_data();
                        }
                }
        }
                        "SELECT id FROM ttrss_feeds
                        WHERE feed_url = '$url' AND owner_uid = ".$_SESSION["uid"]);
 
-               if (strlen(FEED_CRYPT_KEY) > 0) {
-                       require_once "crypt.php";
-                       $auth_pass = substr(encrypt_string($auth_pass), 0, 250);
-                       $auth_pass_encrypted = 'true';
-               } else {
-                       $auth_pass_encrypted = 'false';
-               }
-
+               $auth_pass_encrypted = 'false';
                $auth_pass = db_escape_string($auth_pass);
 
                if (db_num_rows($result) == 0) {
                                set_basic_feed_info($feed_id);
                        }
 
-                       return array("code" => 1);
+                       return array("code" => 1, "feed_id" => (int) $feed_id);
                } else {
-                       return array("code" => 0);
+                       return array("code" => 0, "feed_id" => (int) db_fetch_result($result, 0, "id"));
                }
        }