summaryrefslogtreecommitdiff
path: root/include/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/functions.php')
-rw-r--r--include/functions.php148
1 files changed, 115 insertions, 33 deletions
diff --git a/include/functions.php b/include/functions.php
index c01e41004..9125247b1 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,6 +1,8 @@
<?php
define('EXPECTED_CONFIG_VERSION', 26);
- define('SCHEMA_VERSION', 106);
+ define('SCHEMA_VERSION', 109);
+
+ define('LABEL_BASE_INDEX', -1024);
$fetch_last_error = false;
$pluginhost = false;
@@ -285,8 +287,6 @@
}
function fetch_file_contents($url, $type = false, $login = false, $pass = false, $post_query = false, $timeout = false) {
- $login = urlencode($login);
- $pass = urlencode($pass);
global $fetch_last_error;
@@ -348,11 +348,13 @@
return $contents;
} else {
- if ($login && $pass ){
+ if ($login && $pass){
$url_parts = array();
preg_match("/(^[^:]*):\/\/(.*)/", $url, $url_parts);
+ $pass = urlencode($pass);
+
if ($url_parts[1] && $url_parts[2]) {
$url = $url_parts[1] . "://$login:$pass@" . $url_parts[2];
}
@@ -1034,7 +1036,7 @@
AND $ref_check_qpart 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
@@ -1085,9 +1087,9 @@
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()
@@ -1334,9 +1336,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);
@@ -1446,7 +1448,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"];
@@ -1535,7 +1537,7 @@
* 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;
@@ -1753,7 +1755,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 +1793,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 +1818,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 +1856,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"]);
@@ -2039,6 +2042,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")) {
@@ -2235,14 +2239,15 @@
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 ";
+
}
}
@@ -2254,7 +2259,7 @@
$view_query_part = " published = true AND ";
}
- if ($view_mode == "unread") {
+ if ($view_mode == "unread" && $feed != -6) {
$view_query_part = " unread = true AND ";
}
@@ -2334,7 +2339,13 @@
$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) {
+ if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
+ $override_order = "date_entered";
+ } else {
+ $override_order = "last_marked DESC, date_entered DESC";
+ }
+ }
} else if ($feed == -2) { // published virtual feed OR labels category
@@ -2343,7 +2354,14 @@
$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) {
+ if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
+ $override_order = "date_entered";
+ } else {
+ $override_order = "last_published DESC, date_entered DESC";
+ }
+ }
+
} else {
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
@@ -2374,8 +2392,8 @@
} 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
@@ -2405,6 +2423,10 @@
$order_by = "score DESC, $order_by";
}
+ if ($view_mode == "unread_first") {
+ $order_by = "unread DESC, $order_by";
+ }
+
if ($override_order) {
$order_by = $override_order;
}
@@ -2666,7 +2688,7 @@
$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',
@@ -2685,16 +2707,22 @@
}
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);
+ }
}
}
@@ -3002,7 +3030,7 @@
<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\">";
@@ -3115,7 +3143,7 @@
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>";
@@ -3192,7 +3220,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 +3237,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 +3261,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;
@@ -3853,7 +3883,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 +3911,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 +3939,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 +4120,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);
+ }
+
?>