]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
add a knob to disable reload on js change
[tt-rss.git] / include / functions.php
index 238ba0121e8d51a6498684851e25c088b22cfa16..9a3ea4315779360bd2404ba6a9e850c5021d7dc6 100644 (file)
@@ -54,6 +54,7 @@
                                        "ja_JP" => "日本語 (Japanese)",
                                        "lv_LV" => "Latviešu",
                                        "nb_NO" => "Norwegian bokmål",
+                                       "nl_NL" => "Dutch",
                                        "pl_PL" => "Polski",
                                        "ru_RU" => "Русский",
                                        "pt_BR" => "Portuguese/Brazil",
 
                        $data = @file_get_contents($url);
 
-                       $gzdecoded = gzdecode($data);
+                       @$gzdecoded = gzdecode($data);
                        if ($gzdecoded) $data = $gzdecoded;
 
                        if (!$data && function_exists('error_get_last')) {
                                /* bump login timestamp */
                                db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
                                        $_SESSION["uid"]);
+                               $_SESSION["last_login_update"] = time();
                        }
 
                        if ($_SESSION["uid"] && $_SESSION["language"] && SESSION_COOKIE_LIFETIME > 0) {
                        if ($_SESSION["uid"]) {
                                cache_prefs($link);
                                load_user_plugins($link, $_SESSION["uid"]);
+
+                               /* cleanup ccache */
+
+                               db_query($link, "DELETE FROM ttrss_counters_cache WHERE owner_uid = ".
+                                       $_SESSION["uid"] . " AND
+                                               (SELECT COUNT(id) FROM ttrss_feeds WHERE
+                                                       ttrss_feeds.id = feed_id) = 0");
+
+                               db_query($link, "DELETE FROM ttrss_cat_counters_cache WHERE owner_uid = ".
+                                       $_SESSION["uid"] . " AND
+                                               (SELECT COUNT(id) FROM ttrss_feed_categories WHERE
+                                                       ttrss_feed_categories.id = feed_id) = 0");
+
                        }
+
                }
        }
 
         *                 5 - Couldn't download the URL content.
         */
        function subscribe_to_feed($link, $url, $cat_id = 0,
-                       $auth_login = '', $auth_pass = '', $need_auth = false) {
+                       $auth_login = '', $auth_pass = '') {
 
                global $fetch_last_error;
 
                $data['cdm_expanded'] = get_pref($link, 'CDM_EXPANDED');
 
                $data['dep_ts'] = calculate_dep_timestamp();
+               $data['reload_on_ts_change'] = !defined('_NO_RELOAD_ON_TS_CHANGE');
 
                if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
 
                $entries = $doc->getElementsByTagName("*");
 
                $allowed_elements = array('a', 'address', 'audio', 'article',
-                       'b', 'big', 'blockquote', 'body', 'br', 'cite',
+                       'b', 'big', 'blockquote', 'body', 'br', 'cite', 'center',
                        'code', 'dd', 'del', 'details', 'div', 'dl', 'font',
                        'dt', 'em', 'footer', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
                        'header', 'html', 'i', 'img', 'ins', 'kbd',
                        }
 
                        if ($entry->hasAttributes()) {
-                               foreach (iterator_to_array($entry->attributes) as $attr) {
+                               $attrs_to_remove = array();
+
+                               foreach ($entry->attributes as $attr) {
 
                                        if (strpos($attr->nodeName, 'on') === 0) {
-                                               $entry->removeAttributeNode($attr);
+                                               array_push($attrs_to_remove, $attr);
                                        }
 
                                        if (in_array($attr->nodeName, $disallowed_attributes)) {
-                                               $entry->removeAttributeNode($attr);
+                                               array_push($attrs_to_remove, $attr);
                                        }
                                }
+
+                               foreach ($attrs_to_remove as $attr) {
+                                       $entry->removeAttributeNode($attr);
+                               }
                        }
                }
 
                                                <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
                                                <title>Tiny Tiny RSS - ".$line["title"]."</title>
                                                <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss.css\">
-                                       </head><body>";
+                                       </head><body id=\"ttrssZoom\">";
                        }
 
                        $rv['content'] .= "<div class=\"postReply\" id=\"POST-$id\">";
                                        title=\"".htmlspecialchars($line['title'])."\"
                                        href=\"" .
                                        htmlspecialchars($line["link"]) . "\">" .
-                                       $line["title"] .
-                                       "<span class='author'>$entry_author</span></a></div>";
+                                       $line["title"] . "</a>" .
+                                       "<span class='author'>$entry_author</span></div>";
                        } else {
                                $rv['content'] .= "<div class='postTitle'>" . $line["title"] . "$entry_author</div>";
                        }
 
                if ($zoom_mode) {
                        $rv['content'] .= "
-                               <div style=\"text-align : center\">
+                               <div class='footer'>
                                <button onclick=\"return window.close()\">".
                                        __("Close this window")."</button></div>";
                        $rv['content'] .= "</body></html>";
                return $max_ts;
        }
 
-    function get_site_title() {
-        if (defined("_SITE_TITLE")) {
-            return _SITE_TITLE;
-        } else {
-               return "Tiny Tiny RSS";
-                 }
-    }
+       function T_js_decl($s1, $s2) {
+               if ($s1 && $s2) {
+                       $s1 = preg_replace("/\n/", "", $s1);
+                       $s2 = preg_replace("/\n/", "", $s2);
+
+                       $s1 = preg_replace("/\"/", "\\\"", $s1);
+                       $s2 = preg_replace("/\"/", "\\\"", $s2);
+
+                       return "T_messages[\"$s1\"] = \"$s2\";\n";
+               }
+       }
+
+       function init_js_translations() {
+
+       print 'var T_messages = new Object();
+
+               function __(msg) {
+                       if (T_messages[msg]) {
+                               return T_messages[msg];
+                       } else {
+                               return msg;
+                       }
+               }
+
+               function ngettext(msg1, msg2, n) {
+                       return (parseInt(n) > 1) ? msg2 : msg1;
+               }';
+
+               $l10n = _get_reader();
+
+               for ($i = 0; $i < $l10n->total; $i++) {
+                       $orig = $l10n->get_original_string($i);
+                       $translation = __($orig);
+
+                       print T_js_decl($orig, $translation);
+               }
+       }
+
 ?>