]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
fix ttrss_feeds.last_update defaulting to 0 on mysql, set to null instead
[tt-rss.git] / include / functions.php
index 0d4c8ed09cd6dd4a9e1a06f3eb843c8001a2e86f..92d6e9790b7d8a055d1c721ba2a10faa003c6106 100644 (file)
@@ -1,6 +1,6 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 26);
-       define('SCHEMA_VERSION', 127);
+       define('SCHEMA_VERSION', 130);
 
        define('LABEL_BASE_INDEX', -1024);
        define('PLUGIN_FEED_BASE_INDEX', -128);
@@ -99,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
                if (!$purge_unread) $query_limit = " unread = false AND ";
 
                if (DB_TYPE == "pgsql") {
-                       $pg_version = get_pgsql_version();
-
-                       if (preg_match("/^7\./", $pg_version) || preg_match("/^8\.0/", $pg_version)) {
-
-                               $result = db_query("DELETE FROM ttrss_user_entries WHERE
-                                       ttrss_entries.id = ref_id AND
-                                       marked = false AND
-                                       feed_id = '$feed_id' AND
-                                       $query_limit
-                                       ttrss_entries.date_updated < NOW() - INTERVAL '$purge_interval days'");
-
-                       } else {
-
-                               $result = db_query("DELETE FROM ttrss_user_entries
-                                       USING ttrss_entries
-                                       WHERE ttrss_entries.id = ref_id AND
-                                       marked = false AND
-                                       feed_id = '$feed_id' AND
-                                       $query_limit
-                                       ttrss_entries.date_updated < NOW() - INTERVAL '$purge_interval days'");
-                       }
+                       $result = db_query("DELETE FROM ttrss_user_entries
+                               USING ttrss_entries
+                               WHERE ttrss_entries.id = ref_id AND
+                               marked = false AND
+                               feed_id = '$feed_id' AND
+                               $query_limit
+                               ttrss_entries.date_updated < NOW() - INTERVAL '$purge_interval days'");
 
                } else {
 
 
                // purge orphaned posts in main content table
                $result = db_query("DELETE FROM ttrss_entries WHERE
-                       (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
+                       NOT EXISTS (SELECT ref_id FROM ttrss_user_entries WHERE ref_id = id)");
 
                if ($do_output) {
                        $rows = db_affected_rows($result);
                        curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
                        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-                       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
                        curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent :
                                SELF_USER_AGENT);
                        }
 
                        if (!$post_query && $timestamp) {
-                               $context = stream_context_create(array(
-                                       'http' => array(
-                                               'method' => 'GET',
-                                               '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',
+                                                       'protocol_version'=> 1.1,
+                                                       'header' => "If-Modified-Since: ".gmdate("D, d M Y H:i:s \\G\\M\\T\r\n", $timestamp)
+                                         )));
                        } else {
-                               $context = NULL;
+                                $context = stream_context_create(array(
+                                         'http' => array(
+                                                       'method' => 'GET',
+                                                       'protocol_version'=> 1.1
+                                         )));
                        }
 
                        $old_error = error_get_last();
                }
        }
 
-       function print_select($id, $default, $values, $attributes = "") {
-               print "<select name=\"$id\" id=\"$id\" $attributes>";
+       function print_select($id, $default, $values, $attributes = "", $name = "") {
+               if (!$name) $name = $id;
+
+               print "<select name=\"$name\" id=\"$id\" $attributes>";
                foreach ($values as $v) {
                        if ($v == $default)
                                $sel = "selected=\"1\"";
                print "</select>";
        }
 
-       function print_select_hash($id, $default, $values, $attributes = "") {
-               print "<select name=\"$id\" id='$id' $attributes>";
+       function print_select_hash($id, $default, $values, $attributes = "", $name = "") {
+               if (!$name) $name = $id;
+
+               print "<select name=\"$name\" id='$id' $attributes>";
                foreach (array_keys($values) as $v) {
                        if ($v == $default)
                                $sel = 'selected="selected"';
 
                                $_SESSION["name"] = db_fetch_result($result, 0, "login");
                                $_SESSION["access_level"] = db_fetch_result($result, 0, "access_level");
-                               $_SESSION["csrf_token"] = uniqid(rand(), true);
+                               $_SESSION["csrf_token"] = uniqid_short();
 
                                db_query("UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
                                        $_SESSION["uid"]);
                        $_SESSION["auth_module"] = false;
 
                        if (!$_SESSION["csrf_token"]) {
-                               $_SESSION["csrf_token"] = uniqid(rand(), true);
+                               $_SESSION["csrf_token"] = uniqid_short();
                        }
 
                        $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
        }
 
        function make_local_datetime($timestamp, $long, $owner_uid = false,
-                                       $no_smart_dt = false) {
+                                       $no_smart_dt = false, $eta_min = false) {
 
                if (!$owner_uid) $owner_uid = $_SESSION['uid'];
                if (!$timestamp) $timestamp = '1970-01-01 0:00';
 
                if (!$no_smart_dt) {
                        return smart_date_time($user_timestamp,
-                               $tz_offset, $owner_uid);
+                               $tz_offset, $owner_uid, $eta_min);
                } else {
                        if ($long)
                                $format = get_pref('LONG_DATE_FORMAT', $owner_uid);
                }
        }
 
-       function smart_date_time($timestamp, $tz_offset = 0, $owner_uid = false) {
+       function smart_date_time($timestamp, $tz_offset = 0, $owner_uid = false, $eta_min = false) {
                if (!$owner_uid) $owner_uid = $_SESSION['uid'];
 
-               if (date("Y.m.d", $timestamp) == date("Y.m.d", time() + $tz_offset)) {
+               if ($eta_min && time() + $tz_offset - $timestamp < 3600) {
+                       return T_sprintf("%d min", date("i", time() + $tz_offset - $timestamp));
+               } else if (date("Y.m.d", $timestamp) == date("Y.m.d", time() + $tz_offset)) {
                        return date("G:i", $timestamp);
                } else if (date("Y", $timestamp) == date("Y", time() + $tz_offset)) {
                        $format = get_pref('SHORT_DATE_FORMAT', $owner_uid);
                        FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
                                (ttrss_labels2.id = label_id)
                                LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id
-                               WHERE ttrss_labels2.owner_uid = $owner_uid GROUP BY ttrss_labels2.id,
+                               WHERE ttrss_labels2.owner_uid = $owner_uid AND u1.owner_uid = $owner_uid
+                               GROUP BY ttrss_labels2.id,
                                        ttrss_labels2.caption");
 
                while ($line = db_fetch_assoc($result)) {
                        $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);
                }
        }
 
+       function uniqid_short() {
+               return uniqid(base_convert(rand(), 10, 36));
+       }
+
        // TODO: less dumb splitting
        require_once "functions2.php";