X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=include%2Ffunctions.php;h=307f662009b14dc83c304a86477f4a5e57c96508;hb=583dbc56953afbad6ccae5e3add15160e23b68e4;hp=2ae0dc3b92b2a8823926db1d94c2fdfcd7cc541e;hpb=efc6553da498bd16776cf7e88358877b1c088c7f;p=tt-rss.git diff --git a/include/functions.php b/include/functions.php index 2ae0dc3b..307f6620 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,8 +1,12 @@ "; + $line["def_value"] = db_escape_string($link, $line["def_value"]); + $line["pref_name"] = db_escape_string($link, $line["pref_name"]); + if (get_schema_version($link) < 63) { db_query($link, "INSERT INTO ttrss_user_prefs (owner_uid,pref_name,value) VALUES @@ -576,7 +591,6 @@ function authenticate_user($link, $login, $password, $check_only = false) { if (!SINGLE_USER_MODE) { - $user_id = false; global $pluginhost; @@ -591,6 +605,8 @@ } if ($user_id && !$check_only) { + @session_start(); + $_SESSION["uid"] = $user_id; $result = db_query($link, "SELECT login,access_level,pwd_hash FROM ttrss_users @@ -751,6 +767,7 @@ $_SESSION["prefs_cache"] = false; if (SINGLE_USER_MODE) { + @session_start(); authenticate_user($link, "admin", null); cache_prefs($link); load_user_plugins($link, $_SESSION["uid"]); @@ -992,9 +1009,6 @@ //if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { - $ref_check_qpart = ($max_id && - !get_pref($link, 'REVERSE_HEADLINES')) ? "ref_id <= '$max_id'" : "true"; - if (is_numeric($feed)) { if ($cat_view) { @@ -1014,7 +1028,7 @@ db_query($link, "UPDATE ttrss_user_entries SET unread = false,last_read = NOW() WHERE feed_id IN (SELECT id FROM ttrss_feeds WHERE $cat_qpart) - AND $ref_check_qpart AND unread = true + AND unread = true AND owner_uid = $owner_uid"); } else if ($feed == -2) { @@ -1022,7 +1036,6 @@ db_query($link, "UPDATE ttrss_user_entries SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*) FROM ttrss_user_labels2 WHERE article_id = ref_id) > 0 - AND $ref_check_qpart AND unread = true AND owner_uid = $owner_uid"); } @@ -1031,16 +1044,16 @@ db_query($link, "UPDATE ttrss_user_entries SET unread = false,last_read = NOW() WHERE feed_id = '$feed' - AND $ref_check_qpart AND unread = true + AND unread = true AND owner_uid = $owner_uid"); - } else if ($feed < 0 && $feed > -10) { // special, like starred + } else if ($feed < 0 && $feed > LABEL_BASE_INDEX) { // special, like starred if ($feed == -1) { db_query($link, "UPDATE ttrss_user_entries SET unread = false,last_read = NOW() WHERE marked = true - AND $ref_check_qpart AND unread = true + AND unread = true AND owner_uid = $owner_uid"); } @@ -1048,7 +1061,7 @@ db_query($link, "UPDATE ttrss_user_entries SET unread = false,last_read = NOW() WHERE published = true - AND $ref_check_qpart AND unread = true + AND unread = true AND owner_uid = $owner_uid"); } @@ -1081,18 +1094,17 @@ if ($feed == -4) { db_query($link, "UPDATE ttrss_user_entries SET unread = false,last_read = NOW() - WHERE $ref_check_qpart AND unread = true AND + WHERE unread = true AND owner_uid = $owner_uid"); } - } else if ($feed < -10) { // label + } else if ($feed < LABEL_BASE_INDEX) { // label - $label_id = -$feed - 11; + $label_id = feed_to_label_id($feed); db_query($link, "UPDATE ttrss_user_entries, ttrss_user_labels2 SET unread = false, last_read = NOW() WHERE label_id = '$label_id' AND unread = true - AND $ref_check_qpart AND owner_uid = '$owner_uid' AND ref_id = article_id"); } @@ -1110,7 +1122,7 @@ while ($line = db_fetch_assoc($result)) { db_query($link, "UPDATE ttrss_user_entries SET unread = false, last_read = NOW() - WHERE $ref_check_qpart AND unread = true + WHERE unread = true AND int_id = " . $line["post_int_id"]); } db_query($link, "COMMIT"); @@ -1334,9 +1346,9 @@ $match_part = "feed_id IS NULL"; } - } else if ($feed < -10) { + } else if ($feed < LABEL_BASE_INDEX) { - $label_id = -$feed - 11; + $label_id = feed_to_label_id($feed); return getLabelUnread($link, $label_id, $owner_uid); @@ -1428,6 +1440,21 @@ array_push($ret_arr, $cv); } + global $pluginhost; + + if ($pluginhost) { + $feeds = $pluginhost->get_feeds(-1); + + if (is_array($feeds)) { + foreach ($feeds as $feed) { + $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']), + "counter" => $feed['sender']->get_unread($feed['id'])); + + array_push($ret_arr, $cv); + } + } + } + return $ret_arr; } @@ -1446,7 +1473,7 @@ while ($line = db_fetch_assoc($result)) { - $id = -$line["id"] - 11; + $id = label_to_feed_id($line["id"]); $label_name = $line["caption"]; $count = $line["unread"]; @@ -1753,7 +1780,7 @@ function getFeedCatTitle($link, $id) { if ($id == -1) { return __("Special"); - } else if ($id < -10) { + } else if ($id < LABEL_BASE_INDEX) { return __("Labels"); } else if ($id > 0) { $result = db_query($link, "SELECT ttrss_feed_categories.title @@ -1791,7 +1818,7 @@ return "images/recently_read.png"; break; default: - if ($id < -10) { + if ($id < LABEL_BASE_INDEX) { return "images/label.png"; } else { if (file_exists(ICONS_DIR . "/$id.ico")) @@ -1816,8 +1843,8 @@ return __("Archived articles"); } else if ($id == -6) { return __("Recently read"); - } else if ($id < -10) { - $label_id = -$id - 11; + } else if ($id < LABEL_BASE_INDEX) { + $label_id = feed_to_label_id($id); $result = db_query($link, "SELECT caption FROM ttrss_labels2 WHERE id = '$label_id'"); if (db_num_rows($result) == 1) { return db_fetch_result($result, 0, "caption"); @@ -1854,6 +1881,7 @@ $params["default_view_limit"] = (int) get_pref($link, "_DEFAULT_VIEW_LIMIT"); $params["default_view_order_by"] = get_pref($link, "_DEFAULT_VIEW_ORDER_BY"); $params["bw_limit"] = (int) $_SESSION["bw_limit"]; + $params["label_base_index"] = (int) LABEL_BASE_INDEX; $result = db_query($link, "SELECT MAX(id) AS mid, COUNT(*) AS nf FROM ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); @@ -1919,7 +1947,8 @@ "feed_debug_update" => __("Debug feed update"), "catchup_all" => __("Mark all feeds as read"), "cat_toggle_collapse" => __("Un/collapse current category"), - "toggle_combined_mode" => __("Toggle combined mode")), + "toggle_combined_mode" => __("Toggle combined mode"), + "toggle_cdm_expanded" => __("Toggle auto expand in combined mode")), __("Go to") => array( "goto_all" => __("All articles"), "goto_fresh" => __("Fresh"), @@ -1983,6 +2012,7 @@ "f x" => "feed_reverse", "f *d" => "feed_debug_update", "f *c" => "toggle_combined_mode", + "f c" => "toggle_cdm_expanded", "*q" => "catchup_all", "x" => "cat_toggle_collapse", // "goto" => array( @@ -2039,6 +2069,7 @@ $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")) { @@ -2231,18 +2262,19 @@ $view_query_part = ""; - if ($view_mode == "adaptive" || $view_query_part == "noscores") { + if ($view_mode == "adaptive") { if ($search) { $view_query_part = " "; } else if ($feed != -1) { + $unread = getFeedUnread($link, $feed, $cat_view); if ($cat_view && $feed > 0 && $include_children) $unread += getCategoryChildrenUnread($link, $feed); - if ($unread > 0) { - $view_query_part = " unread = true AND "; - } + if ($unread > 0) + $view_query_part = " unread = true AND "; + } } @@ -2250,18 +2282,18 @@ $view_query_part = " marked = true AND "; } + if ($view_mode == "has_note") { + $view_query_part = " (note IS NOT NULL AND note != '') AND "; + } + if ($view_mode == "published") { $view_query_part = " published = true AND "; } - if ($view_mode == "unread") { + if ($view_mode == "unread" && $feed != -6) { $view_query_part = " unread = true AND "; } - if ($view_mode == "updated") { - $view_query_part = " (last_read is null and unread = false) AND "; - } - if ($limit > 0) { $limit_query_part = "LIMIT " . $limit; } @@ -2334,7 +2366,9 @@ $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; $allow_archived = true; - if (!$override_order) $override_order = "last_marked DESC, updated DESC"; + if (!$override_order) { + $override_order = "last_marked DESC, date_entered DESC, updated DESC"; + } } else if ($feed == -2) { // published virtual feed OR labels category @@ -2343,7 +2377,10 @@ $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; $allow_archived = true; - if (!$override_order) $override_order = "last_published DESC, updated DESC"; + if (!$override_order) { + $override_order = "last_published DESC, date_entered DESC, updated DESC"; + } + } else { $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; @@ -2365,17 +2402,17 @@ $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE", $owner_uid); if (DB_TYPE == "pgsql") { - $query_strategy_part .= " AND updated > NOW() - INTERVAL '$intl hour' "; + $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; } else { - $query_strategy_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; + $query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; } $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; } else if ($feed == -4) { // all articles virtual feed $query_strategy_part = "true"; $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; - } else if ($feed <= -10) { // labels - $label_id = -$feed - 11; + } else if ($feed <= LABEL_BASE_INDEX) { // labels + $label_id = feed_to_label_id($feed); $query_strategy_part = "label_id = '$label_id' AND ttrss_labels2.id = ttrss_user_labels2.label_id AND @@ -2395,14 +2432,10 @@ $date_sort_field = "date_entered"; } - if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { - $order_by = "$date_sort_field"; - } else { - $order_by = "$date_sort_field DESC"; - } + $order_by = "$date_sort_field DESC, updated DESC"; - if ($view_mode != "noscores") { - $order_by = "score DESC, $order_by"; + if ($view_mode == "unread_first") { + $order_by = "unread DESC, $order_by"; } if ($override_order) { @@ -2478,10 +2511,8 @@ hide_images, unread,feed_id,marked,published,link,last_read,orig_feed_id, last_marked, last_published, - ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms, $vfeed_query_part $content_query_part - ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms, author,score FROM $from_qpart @@ -2522,11 +2553,9 @@ "last_read," . "(SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images," . "last_marked, last_published, " . - SUBSTRING_FOR_DATE . "(last_read,1,19) as last_read_noms," . $since_id_part . $vfeed_query_part . $content_query_part . - SUBSTRING_FOR_DATE . "(updated,1,19) as updated_noms," . "score "; $feed_kind = "Tags"; @@ -2620,7 +2649,7 @@ if ($entry->nodeName == 'img') { if (($owner && get_pref($link, "STRIP_IMAGES", $owner)) || - $force_remove_images) { + $force_remove_images || $_SESSION["bw_limit"]) { $p = $doc->createElement('p'); @@ -2648,53 +2677,66 @@ } + $allowed_elements = array('a', 'address', 'audio', 'article', + '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', + 'li', 'nav', 'noscript', 'ol', 'p', 'pre', 'q', 's','small', + 'source', 'span', 'strike', 'strong', 'sub', 'summary', + 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', + 'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video' ); + + if ($_SESSION['hasSandbox']) $allowed_elements[] = 'iframe'; + + $disallowed_attributes = array('id', 'style', 'class'); + global $pluginhost; if (isset($pluginhost)) { foreach ($pluginhost->get_hooks($pluginhost::HOOK_SANITIZE) as $plugin) { - $doc = $plugin->hook_sanitize($doc, $site_url); + $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes); + if (is_array($retval)) { + $doc = $retval[0]; + $allowed_elements = $retval[1]; + $disallowed_attributes = $retval[2]; + } else { + $doc = $retval; + } } } $doc->removeChild($doc->firstChild); //remove doctype - $doc = strip_harmful_tags($doc); + $doc = strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes); $res = $doc->saveHTML(); return $res; } - function strip_harmful_tags($doc) { + function strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes) { $entries = $doc->getElementsByTagName("*"); - $allowed_elements = array('a', 'address', 'audio', 'article', - 'b', 'big', 'blockquote', 'body', 'br', 'cite', - 'code', 'dd', 'del', 'details', 'div', 'dl', 'font', - 'dt', 'em', 'footer', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', - 'header', 'html', 'i', 'img', 'ins', 'kbd', - 'li', 'nav', 'ol', 'p', 'pre', 'q', 's','small', - 'source', 'span', 'strike', 'strong', 'sub', 'summary', - 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', - 'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video' ); - - if ($_SESSION['hasSandbox']) array_push($allowed_elements, 'iframe'); - - $disallowed_attributes = array('id', 'style', 'class'); - foreach ($entries as $entry) { if (!in_array($entry->nodeName, $allowed_elements)) { $entry->parentNode->removeChild($entry); } 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); + } } } @@ -2842,19 +2884,19 @@ function format_warning($msg, $id = "") { global $link; return "
- $msg
"; +
$msg
"; } function format_notice($msg, $id = "") { global $link; return "
- $msg
"; +
$msg
"; } function format_error($msg, $id = "") { global $link; return "
- $msg
"; +
$msg
"; } function print_notice($msg) { @@ -3002,7 +3044,7 @@ Tiny Tiny RSS - ".$line["title"]." - "; + "; } $rv['content'] .= "
"; @@ -3115,7 +3157,7 @@ if ($zoom_mode) { $rv['content'] .= " -
+ "; $rv['content'] .= ""; @@ -3192,7 +3234,7 @@ $filter_id = $line["id"]; $result2 = db_query($link, "SELECT - r.reg_exp, r.feed_id, r.cat_id, r.cat_filter, t.name AS type_name + r.reg_exp, r.inverse, r.feed_id, r.cat_id, r.cat_filter, t.name AS type_name FROM ttrss_filters2_rules AS r, ttrss_filter_types AS t WHERE @@ -3209,6 +3251,7 @@ $rule = array(); $rule["reg_exp"] = $rule_line["reg_exp"]; $rule["type"] = $rule_line["type_name"]; + $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]); array_push($rules, $rule); } @@ -3232,6 +3275,7 @@ $filter = array(); $filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]); + $filter["inverse"] = sql_bool_to_bool($line["inverse"]); $filter["rules"] = $rules; $filter["actions"] = $actions; @@ -3609,7 +3653,7 @@ array_push($entries, $entry); } - if ($_SESSION['uid'] && !get_pref($link, "STRIP_IMAGES")) { + if ($_SESSION['uid'] && !get_pref($link, "STRIP_IMAGES") && !$_SESSION["bw_limit"]) { if ($always_display_enclosures || !preg_match("/". - "" . __('Attachments').""; - $rv .= "
"; + $rv .= ""; } return $rv; @@ -3764,7 +3810,6 @@ if (count($ids) > 0) { $ids = join(",", $ids); - print "."; $tmp_result = db_query($link, "DELETE FROM ttrss_tags WHERE id IN ($ids)"); $tags_deleted += db_affected_rows($link, $tmp_result); @@ -3775,8 +3820,6 @@ $limit -= $limit_part; } - print "\n"; - return $tags_deleted; } @@ -3853,7 +3896,7 @@ $rule['reg_exp'] = db_escape_string($link, $rule['reg_exp']); - switch ($rule["type"]) { + switch ($rule["type"]) { case "title": $qpart = "LOWER(ttrss_entries.title) $reg_qpart LOWER('". $rule['reg_exp'] . "')"; @@ -3881,6 +3924,8 @@ break; } + if (isset($rule['inverse'])) $qpart = "NOT ($qpart)"; + if (isset($rule["feed_id"]) && $rule["feed_id"] > 0) { $qpart .= " AND feed_id = " . db_escape_string($link, $rule["feed_id"]); } @@ -3907,10 +3952,14 @@ } if (count($query) > 0) { - return "(" . join($filter["match_any_rule"] ? "OR" : "AND", $query) . ")"; + $fullquery = "(" . join($filter["match_any_rule"] ? "OR" : "AND", $query) . ")"; } else { - return "(false)"; + $fullquery = "(false)"; } + + if ($filter['inverse']) $fullquery = "(NOT $fullquery)"; + + return $fullquery; } if (!function_exists('gzdecode')) { @@ -4084,4 +4133,50 @@ return $max_ts; } + 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); + } + } + + function label_to_feed_id($label) { + return LABEL_BASE_INDEX - 1 - abs($label); + } + + function feed_to_label_id($feed) { + return LABEL_BASE_INDEX - 1 + abs($feed); + } + ?>