]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
more work on singleton-based DB
[tt-rss.git] / include / functions.php
index 4ac4e09686e7ba65a7cd1184cddc13b4e5dfb503..f0d5e85faf8325250ae1dc24d16b21f2ebfeabe3 100644 (file)
@@ -1,6 +1,6 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 26);
-       define('SCHEMA_VERSION', 116);
+       define('SCHEMA_VERSION', 118);
 
        define('LABEL_BASE_INDEX', -1024);
        define('PLUGIN_FEED_BASE_INDEX', -128);
        $fetch_last_content_type = false;
        $pluginhost = false;
 
-       function __autoload($class) {
-               $class_file = str_replace("_", "/", strtolower(basename($class)));
-
-               $file = dirname(__FILE__)."/../classes/$class_file.php";
-
-               if (file_exists($file)) {
-                       require $file;
-               }
-
-       }
-
        mb_internal_encoding("UTF-8");
        date_default_timezone_set('UTC');
        if (defined('E_DEPRECATED')) {
 
                if (!defined('NO_CURL') && function_exists('curl_init') && !ini_get("open_basedir")) {
 
-                       if (ini_get("safe_mode")) {
+                       if (ini_get("safe_mode") || ini_get("open_basedir")) {
                                $ch = curl_init(geturl($url));
                        } else {
                                $ch = curl_init($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("safe_mode"));
+                       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("safe_mode") && !ini_get("open_basedir"));
                        curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
                        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                        }
                                }
                        }
+            return $icon_file;
                }
        }
 
                        "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 = db_escape_string($link, $auth_pass);
+
                if (db_num_rows($result) == 0) {
                        $result = db_query($link,
                                "INSERT INTO ttrss_feeds
-                                       (owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method)
+                                       (owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method,auth_pass_encrypted)
                                VALUES ('".$_SESSION["uid"]."', '$url',
-                               '[Unknown]', $cat_qpart, '$auth_login', '$auth_pass', 0)");
+                               '[Unknown]', $cat_qpart, '$auth_login', '$auth_pass', 0, $auth_pass_encrypted)");
 
                        $result = db_query($link,
                                "SELECT id FROM ttrss_feeds WHERE feed_url = '$url'
                        }
                        break;
                }
+
+               return false;
        }
 
        function getFeedTitle($link, $id, $cat = false) {
                                                LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)";
                                }
 
+                               if ($vfeed_query_part)
+                                       $vfeed_query_part .= "favicon_avg_color,";
+
                                $query = "SELECT DISTINCT
                                                date_entered,
                                                guid,
        }
 
        function render_login_form($link) {
+               header('Cache-Control: public');
+
                require_once "login_form.php";
                exit;
        }
 
-       // from http://developer.apple.com/internet/safari/faq.html
-       function no_cache_incantation() {
-               header("Expires: Mon, 22 Dec 1980 00:00:00 GMT"); // Happy birthday to me :)
-               header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
-               header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1
-               header("Cache-Control: post-check=0, pre-check=0", false);
-               header("Pragma: no-cache"); // HTTP/1.0
-       }
-
        function format_warning($msg, $id = "") {
                global $link;
                return "<div class=\"warning\" id=\"$id\">
                if (strpos($ctype, "audio/") === 0) {
 
                        if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false ||
-                               strpos($_SERVER['HTTP_USER_AGENT'], "Chrome") !== false ||
-                               strpos($_SERVER['HTTP_USER_AGENT'], "Safari") !== false )) {
-
-                               $id = 'AUDIO-' . uniqid();
+                               $_SESSION["hasMp3"])) {
 
-                               $entry .= "<audio id=\"$id\"\" controls style='display : none'>
+                               $entry .= "<audio controls>
                                        <source type=\"$ctype\" src=\"$url\"></source>
                                        </audio>";
 
-                               $entry .= "<span onclick=\"player(this)\"
-                                       title=\"".__("Click to play")."\" status=\"0\"
-                                       class=\"player\" audio-id=\"$id\">".__("Play")."</span>";
-
                        } else {
 
                                $entry .= "<object type=\"application/x-shockwave-flash\"
                return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
        }
 
-       function init_connection($link) {
-               if ($link) {
-
-                       if (DB_TYPE == "pgsql") {
-                               pg_query($link, "set client_encoding = 'UTF-8'");
-                               pg_set_client_encoding("UNICODE");
-                               pg_query($link, "set datestyle = 'ISO, european'");
-                               pg_query($link, "set TIME ZONE 0");
-                       } else {
-                               db_query($link, "SET time_zone = '+0:0'");
-
-                               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-                               }
-                       }
-
-                       global $pluginhost;
+       function init_plugins($link) {
+               global $pluginhost;
 
-                       $pluginhost = new PluginHost($link);
-                       $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
+               $pluginhost = new PluginHost($link);
+               $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
 
-                       return true;
-               } else {
-                       print "Unable to connect to database:" . db_last_error();
-                       return false;
-               }
+               return true;
        }
 
        function format_tags_string($tags, $id) {
 
        function format_article_labels($labels, $id) {
 
+               if (is_array($labels)) return '';
+
                $labels_str = "";
 
                foreach ($labels as $l) {
 
                $sphinxClient = new SphinxClient();
 
-               $sphinxClient->SetServer('localhost', 9312);
+               $sphinxpair = explode(":", SPHINX_SERVER, 2);
+
+               $sphinxClient->SetServer($sphinxpair[0], $sphinxpair[1]);
                $sphinxClient->SetConnectTimeout(1);
 
                $sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30,