]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
move language detection to a plugin, remove config.php constant
[tt-rss.git] / include / functions.php
index deddf358fb608d8d1462fedf88268e4f91097199..5c10ac6ac790198e21ed55bee25407172767b6f3 100644 (file)
@@ -1,6 +1,6 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 26);
-       define('SCHEMA_VERSION', 123);
+       define('SCHEMA_VERSION', 127);
 
        define('LABEL_BASE_INDEX', -1024);
        define('PLUGIN_FEED_BASE_INDEX', -128);
        $fetch_last_error = false;
        $fetch_last_error_code = false;
        $fetch_last_content_type = false;
+       $fetch_last_error_content = false; // curl only for the time being
        $fetch_curl_used = false;
        $suppress_debugging = false;
 
+       libxml_disable_entity_loader(true);
+
        mb_internal_encoding("UTF-8");
        date_default_timezone_set('UTC');
        if (defined('E_DEPRECATED')) {
        function get_translations() {
                $tr = array(
                                        "auto"  => "Detect automatically",
+                                       "ar_SA" => "العربيّة (Arabic)",
+                                       "bg_BG" => "Bulgarian",
+                                       "da_DA" => "Dansk",
                                        "ca_CA" => "Català",
                                        "cs_CZ" => "Česky",
                                        "en_US" => "English",
-                                       "es_ES" => "Español",
+                                       "el_GR" => "Ελληνικά",
+                                       "es_ES" => "Español (España)",
+                                       "es_LA" => "Español",
                                        "de_DE" => "Deutsch",
                                        "fr_FR" => "Français",
                                        "hu_HU" => "Magyar (Hungarian)",
@@ -78,6 +86,7 @@
                                        "pl_PL" => "Polski",
                                        "ru_RU" => "Русский",
                                        "pt_BR" => "Portuguese/Brazil",
+                                       "pt_PT" => "Portuguese/Portugal",
                                        "zh_CN" => "Simplified Chinese",
                                        "zh_TW" => "Traditional Chinese",
                                        "sv_SE" => "Svenska",
@@ -90,8 +99,6 @@
        require_once "lib/accept-to-gettext.php";
        require_once "lib/gettext/gettext.inc";
 
-       require_once "lib/languagedetect/LanguageDetect.php";
-
        function startup_gettext() {
 
                # Get locale from Accept-Language header
 
                global $fetch_last_error;
                global $fetch_last_error_code;
+               global $fetch_last_error_content;
                global $fetch_last_content_type;
                global $fetch_curl_used;
 
+               $url = ltrim($url, ' ');
                $url = str_replace(' ', '%20', $url);
 
+               if (strpos($url, "//") === 0)
+                       $url = 'http:' . $url;
+
                if (!defined('NO_CURL') && function_exists('curl_init')) {
 
                        $fetch_curl_used = true;
 
-                       if (ini_get("safe_mode") || ini_get("open_basedir")) {
+                       if (ini_get("safe_mode") || ini_get("open_basedir") || defined("FORCE_GETURL")) {
                                $new_url = geturl($url);
                                if (!$new_url) {
                                    // geturl has already populated $fetch_last_error
                        curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent :
                                SELF_USER_AGENT);
                        curl_setopt($ch, CURLOPT_ENCODING, "");
-                       curl_setopt($ch, CURLOPT_REFERER, $url);
+                       //curl_setopt($ch, CURLOPT_REFERER, $url);
 
                        if (!ini_get("safe_mode") && !ini_get("open_basedir")) {
                                curl_setopt($ch, CURLOPT_COOKIEJAR, "/dev/null");
                                curl_setopt($ch, CURLOPT_POSTFIELDS, $post_query);
                        }
 
-                       if ((OPENSSL_VERSION_NUMBER >= 0x0090808f) && (OPENSSL_VERSION_NUMBER < 0x10000000)) {
-                               curl_setopt($ch, CURLOPT_SSLVERSION, 3);
-                       }
-
                        if ($login && $pass)
                                curl_setopt($ch, CURLOPT_USERPWD, "$login:$pass");
 
                                } else {
                                        $fetch_last_error = "HTTP Code: $http_code";
                                }
+                               $fetch_last_error_content = $contents;
                                curl_close($ch);
                                return false;
                        }
 
        function initialize_user($uid) {
 
-               db_query("insert into ttrss_feeds (owner_uid,title,feed_url)
-                       values ('$uid', 'Tiny Tiny RSS: New Releases',
-                       'http://tt-rss.org/releases.rss')");
-
                db_query("insert into ttrss_feeds (owner_uid,title,feed_url)
                        values ('$uid', 'Tiny Tiny RSS: Forum',
                                'http://tt-rss.org/forum/rss.php')");
                                                        SET unread = false, last_read = NOW() WHERE ref_id IN
                                                                (SELECT id FROM
                                                                        (SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
-                                                                               AND owner_uid = $owner_uid AND unread = true AND $date_qpart AND $match_part) as tmp)");
+                                                                               AND owner_uid = $owner_uid AND score >= 0 AND unread = true AND $date_qpart AND $match_part) as tmp)");
                                        }
 
                                        if ($feed == -4) {
                        return array("code" => 5, "message" => $fetch_last_error);
                }
 
+               foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SUBSCRIBE_FEED) as $plugin) {
+                       $contents = $plugin->hook_subscribe_feed($contents, $url, $auth_login, $auth_pass);
+               }
+
                if (is_html($contents)) {
                        $feedUrls = get_feeds_from_html($url, $contents);
 
                        $url = key($feedUrls);
                }
 
-               /* libxml_use_internal_errors(true);
-               $doc = new DOMDocument();
-               $doc->loadXML($contents);
-               $error = libxml_get_last_error();
-               libxml_clear_errors();
-
-               if ($error) {
-                       $error_message = format_libxml_error($error);
-
-                       return array("code" => 6, "message" => $error_message);
-               } */
-
                if ($cat_id == "0" || !$cat_id) {
                        $cat_qpart = "NULL";
                } else {
                        $feed_id = db_fetch_result($result, 0, "id");
 
                        if ($feed_id) {
-                               update_rss_feed($feed_id, true);
+                               set_basic_feed_info($feed_id);
                        }
 
                        return array("code" => 1);