"en_US" => "English",
"fr_FR" => "Français",
"hu_HU" => "Magyar (Hungarian)",
+ "it_IT" => "Italiano",
+ "ja_JP" => "日本語 (Japanese)",
"nb_NO" => "Norwegian bokmål",
"ru_RU" => "Русский",
"pt_BR" => "Portuguese/Brazil",
$lang = $_COOKIE["ttrss_lang"];
}
+ /* In login action of mobile version */
+ if ($_POST["language"] && defined('MOBILE_VERSION')) {
+ $lang = $_POST["language"];
+ $_COOKIE["ttrss_lang"] = $lang;
+ }
+
if ($lang) {
if (defined('LC_MESSAGES')) {
_setlocale(LC_MESSAGES, $lang);
} else {
die("can't setlocale(): please set ENABLE_TRANSLATIONS to false in config.php");
}
- _bindtextdomain("messages", "locale");
+
+ if (defined('MOBILE_VERSION')) {
+ _bindtextdomain("messages", "../locale");
+ } else {
+ _bindtextdomain("messages", "locale");
+ }
+
_textdomain("messages");
_bind_textdomain_codeset("messages", "UTF-8");
}
define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')');
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
+ define('MAGPIE_CACHE_AGE', 60*15); // 15 minutes
require_once "simplepie/simplepie.inc";
require_once "magpierss/rss_fetch.inc";
if (!$owner_uid) return;
- $purge_unread = get_pref($link, "PURGE_UNREAD_ARTICLES",
- $owner_uid, false);
+ if (FORCE_ARTICLE_PURGE == 0) {
+ $purge_unread = get_pref($link, "PURGE_UNREAD_ARTICLES",
+ $owner_uid, false);
+ } else {
+ $purge_unread = true;
+ $purge_interval = FORCE_ARTICLE_PURGE;
+ }
if (!$purge_unread) $query_limit = " unread = false AND ";
}
+ ccache_update($link, $feed_id, $owner_uid);
+
if ($debug) {
_debug("Purged feed $feed_id ($purge_interval): deleted $rows articles");
}
// print "Feed $feed_id: purge interval = $purge_interval\n";
}
- if ($purge_interval > 0) {
+ if ($purge_interval > 0 || FORCE_ARTICLE_PURGE) {
purge_feed($link, $feed_id, $purge_interval, $do_output);
}
}
} else {
$result = db_query($link, "SELECT id,update_interval,auth_login,
- auth_pass,cache_images,update_method
+ auth_pass,cache_images,update_method,hidden
FROM ttrss_feeds WHERE id = '$feed'");
}
return false;
}
+ $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
$update_method = db_fetch_result($result, 0, "update_method");
db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW()
if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date);
}
- if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
- _debug("update_rss_feed: date $entry_timestamp");
- }
-
if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) {
$entry_timestamp = time();
$no_orig_date = 'true';
$entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
+ if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
+ _debug("update_rss_feed: date $entry_timestamp [$entry_timestamp_fmt]");
+ }
+
if ($use_simplepie) {
$entry_title = $item->get_title();
} else {
}
// <media:content>
- // can there be many of those? -fox
+ // can there be many of those? yes -fox
$m_ctr = $item['media']['content#'];
$item['media']['content@length']);
array_push($enclosures, $e_item);
- }
- // FIXME: parse more of those, if needed.
+ for ($i = 0; $i <= $m_ctr; $i++ ) {
+
+ if ($item["media"]["content#$i@url"]) {
+ $e_item = array($item["media"]["content#$i@url"],
+ $item["media"]["content#$i@medium"],
+ $item["media"]["content#$i@length"]);
+ array_push($enclosures, $e_item);
+ }
+ }
+
+ }
}
# sanitize content
// error_reporting(0);
$article_filters = get_article_filters($filters, $entry_title,
- $entry_content, $entry_link);
+ $entry_content, $entry_link, $entry_timestamp);
if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: article filters: ");
db_query($link, "COMMIT");
+ if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
+ _debug("update_rss_feed: assigning labels...");
+ }
+
+ assign_article_to_labels($link, $entry_ref_id, $article_filters,
+ $owner_uid);
+
if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: looking for enclosures...");
}
}
}
+ if (!$hidden) {
+ if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
+ _debug("update_rss_feed: updating counters cache...");
+ }
+
+ // disabled, purge_feed() does that...
+ //ccache_update($link, $feed, $owner_uid);
+ }
+
+ purge_feed($link, $feed, 0, true);
+
db_query($link, "UPDATE ttrss_feeds
SET last_updated = NOW(), last_error = '' WHERE id = '$feed'");
print "<select name=\"$id\" id='$id' $attributes>";
foreach (array_keys($values) as $v) {
if ($v == $default)
- $sel = "selected";
+ $sel = 'selected="selected"';
else
$sel = "";
print "</select>";
}
- function get_article_filters($filters, $title, $content, $link) {
+ function get_article_filters($filters, $title, $content, $link, $timestamp) {
$matches = array();
if ($filters["title"]) {
}
}
+ if ($filters["date"]) {
+ $reg_exp = $filter["reg_exp"];
+ foreach ($filters["date"] as $filter) {
+ $date_modifier = $filter["filter_param"];
+ $inverse = $filter["inverse"];
+ $check_timestamp = strtotime($filter["reg_exp"]);
+
+ # no-op when timestamp doesn't parse to prevent misfires
+
+ if ($check_timestamp) {
+ $match_ok = false;
+
+ if ($date_modifier == "before" && $timestamp < $check_timestamp ||
+ $date_modifier == "after" && $timestamp > $check_timestamp) {
+ $match_ok = true;
+ }
+
+ if ($inverse) $match_ok = !$match_ok;
+
+ if ($match_ok) {
+ array_push($matches, array($filter["action"], $filter["action_param"]));
+ }
+ }
+ }
+ }
+
return $matches;
}
return $score;
}
+ function assign_article_to_labels($link, $id, $filters, $owner_uid) {
+ foreach ($filters as $f) {
+ if ($f[0] == "label") {
+ label_add_article($link, $id, $f[1], $owner_uid);
+ };
+ }
+ }
function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
$rtl_content = false, $last_updated = false, $last_error = false) {
function initialize_user($link, $uid) {
- db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
- values ('$uid','unread = true', 'Unread articles')");
+/* db_query($link, "INSERT INTO ttrss_labels2 (owner_uid, caption)
+ VALUES ('$uid', 'All Articles')");
- db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
- values ('$uid','last_read is null and unread = false', 'Updated articles')");
+ db_query($link, "INSERT INTO ttrss_filters
+ (owner_uid, feed_id, filter_type, reg_exp, enabled,
+ action_id, action_param, filter_param)
+ VALUES ('$uid', NULL, 1, '.', true, 7, 'All Articles', 'before')"); */
db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url)
values ('$uid', 'Tiny Tiny RSS: New Releases',
- 'http://tt-rss.spb.ru/releases.rss')");
+ 'http://tt-rss.org/releases.rss')");
db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url)
values ('$uid', 'Tiny Tiny RSS: Forum',
- 'http://tt-rss.spb.ru/forum/rss.php')");
+ 'http://tt-rss.org/forum/rss.php')");
}
function logout_user() {
}
}
-// print session_id();
-// print_r($_SESSION);
-
if (!$_SESSION["uid"] || !validate_session($link)) {
render_login_form($link, $mobile);
exit;
setcookie("ttrss_lang", $_SESSION["language"],
time() + SESSION_COOKIE_LIFETIME);
}
+
+ /* bump counters stamp since we're getting reloaded anyway */
+
+ $_SESSION["get_all_counters_stamp"] = time();
}
} else {
}
}
+ if (db_escape_string("testTEST") != "testTEST") {
+ $error_code = 12;
+ }
+
error_reporting (DEFAULT_ERROR_LEVEL);
if ($error_code != 0) {
catchupArticlesById($link, $affected_ids, 0);
}
- } else if ($feed < -10) { // label
+ if ($feed == -4) {
+ db_query($link, "UPDATE ttrss_user_entries
+ SET unread = false,last_read = NOW()
+ WHERE owner_uid = ".$_SESSION["uid"]);
+ }
- // TODO make this more efficient
+ } else if ($feed < -10) { // label
$label_id = -$feed - 11;
- $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
- WHERE id = '$label_id'");
-
- if ($tmp_result) {
- $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
-
- db_query($link, "BEGIN");
-
- $tmp2_result = db_query($link,
- "SELECT
- int_id
- FROM
- ttrss_user_entries,ttrss_entries,ttrss_feeds
- WHERE
- ref_id = ttrss_entries.id AND
- ttrss_user_entries.feed_id = ttrss_feeds.id AND
- $sql_exp AND
- ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
-
- while ($tmp_line = db_fetch_assoc($tmp2_result)) {
- db_query($link, "UPDATE
- ttrss_user_entries
- SET
- unread = false, last_read = NOW()
- WHERE
- int_id = " . $tmp_line["int_id"]);
- }
-
- db_query($link, "COMMIT");
+ db_query($link, "UPDATE ttrss_user_entries, ttrss_user_labels2
+ SET unread = false WHERE label_id = '$label_id' AND unread = true
+ AND owner_uid = '".$_SESSION["uid"]."' AND ref_id = article_id");
-/* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
- SET unread = false,last_read = NOW()
- WHERE $sql_exp
- AND ref_id = id
- AND owner_uid = ".$_SESSION["uid"]); */
- }
}
+
+ ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
+
} else { // tag
db_query($link, "BEGIN");
function getAllCounters($link, $omode = "flc", $active_feed = false) {
- /* getting all counters is a resource intensive operation, so we
- * rate limit it a little bit */
-
-
-
- if (get_pref($link, "SYNC_COUNTERS") ||
- time() - $_SESSION["get_all_counters_stamp"] > 5) {
-
- if (!$omode) $omode = "flc";
+ if (!$omode) $omode = "flc";
- getGlobalCounters($link);
+ getGlobalCounters($link);
- if (strchr($omode, "l")) getLabelCounters($link);
- if (strchr($omode, "f")) getFeedCounters($link, SMART_RPC_COUNTERS, $active_feed);
- if (strchr($omode, "t")) getTagCounters($link);
- if (strchr($omode, "c")) {
- if (get_pref($link, 'ENABLE_FEED_CATS')) {
- getCategoryCounters($link);
- }
+ if (strchr($omode, "l")) getLabelCounters($link);
+ if (strchr($omode, "f")) getFeedCounters($link, SMART_RPC_COUNTERS, $active_feed);
+ if (strchr($omode, "t")) getTagCounters($link);
+ if (strchr($omode, "c")) {
+ if (get_pref($link, 'ENABLE_FEED_CATS')) {
+ getCategoryCounters($link);
}
-
- $_SESSION["get_all_counters_stamp"] = time();
}
-
}
function getCategoryCounters($link) {
# two special categories are -1 and -2 (all virtuals; all labels)
- $ctr = getCategoryUnread($link, -1);
+/* $ctr = getCategoryUnread($link, -1);
- print "<counter type=\"category\" id=\"-1\" counter=\"$ctr\"/>";
+ print "<counter type=\"category\" id=\"-1\" counter=\"$ctr\"/>"; */
- $ctr = getCategoryUnread($link, -2);
+ $ctr = getCategoryUnread($link, -2);
print "<counter type=\"category\" id=\"-2\" counter=\"$ctr\"/>";
$age_qpart = getMaxAgeSubquery();
- $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id)
- FROM ttrss_user_entries, ttrss_entries WHERE feed_id = ttrss_feeds.id
- AND id = ref_id AND $age_qpart
- AND unread = true)) AS unread FROM ttrss_feeds
- WHERE
- hidden = false AND owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
+ $result = db_query($link, "SELECT id AS cat_id, value AS unread
+ FROM ttrss_feed_categories, ttrss_cat_counters_cache
+ WHERE ttrss_cat_counters_cache.feed_id = id AND
+ ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]);
while ($line = db_fetch_assoc($result)) {
$line["cat_id"] = sprintf("%d", $line["cat_id"]);
+
print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"".
$line["unread"]."\"/>";
}
+
+ /* Special case: NULL category doesn't actually exist in the DB */
+
+ print "<counter type=\"category\" id=\"0\" counter=\"".
+ ccache_find($link, 0, $_SESSION["uid"], true)."\"/>";
+
}
- function getCategoryUnread($link, $cat) {
+ function getCategoryUnread($link, $cat, $owner_uid = false) {
+
+ if (!$owner_uid) $owner_uid = $_SESSION["uid"];
if ($cat >= 0) {
$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query
AND hidden = false
- AND owner_uid = " . $_SESSION["uid"]);
+ AND owner_uid = " . $owner_uid);
$cat_feeds = array();
while ($line = db_fetch_assoc($result)) {
$result = db_query($link, "SELECT COUNT(int_id) AS unread
FROM ttrss_user_entries,ttrss_entries
WHERE unread = true AND ($match_part) AND id = ref_id
- AND $age_qpart AND owner_uid = " . $_SESSION["uid"]);
+ AND $age_qpart AND owner_uid = " . $owner_uid);
$unread = 0;
return getFeedUnread($link, -1) + getFeedUnread($link, -2) + getFeedUnread($link, -3);
} else if ($cat == -2) {
- $rv = getLabelCounters($link, false, true);
- $ctr = 0;
+ $result = db_query($link, "
+ SELECT COUNT(unread) AS unread FROM
+ ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds
+ WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND
+ ttrss_labels2.owner_uid = '$owner_uid'
+ AND unread = true AND hidden = false AND feed_id = ttrss_feeds.id
+ AND ttrss_user_entries.owner_uid = '$owner_uid'");
- foreach (array_keys($rv) as $k) {
- if ($k < -10) {
- $ctr += $rv[$k]["counter"];
- }
- }
+ $unread = db_fetch_result($result, 0, "unread");
- return $ctr;
- }
+ return $unread;
+
+ }
}
function getMaxAgeSubquery($days = COUNTERS_MAX_AGE) {
}
function getFeedUnread($link, $feed, $is_cat = false) {
- return getFeedArticles($link, $feed, $is_cat, true);
+ return getFeedArticles($link, $feed, $is_cat, true, $_SESSION["uid"]);
+ }
+
+ function getLabelUnread($link, $label_id, $owner_uid = false) {
+ if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+ $result = db_query($link, "
+ SELECT COUNT(unread) AS unread FROM
+ ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds
+ WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND
+ ttrss_labels2.owner_uid = '$owner_uid' AND ttrss_labels2.id = '$label_id'
+ AND unread = true AND hidden = false AND feed_id = ttrss_feeds.id
+ AND ttrss_user_entries.owner_uid = '$owner_uid'");
+
+ if (db_num_rows($result) != 0) {
+ return db_fetch_result($result, 0, "unread");
+ } else {
+ return 0;
+ }
}
- function getFeedArticles($link, $feed, $is_cat = false, $unread_only = false) {
+ function getFeedArticles($link, $feed, $is_cat = false, $unread_only = false,
+ $owner_uid = false) {
+
$n_feed = sprintf("%d", $feed);
+ if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
if ($unread_only) {
$unread_qpart = "unread = true";
} else {
$age_qpart = getMaxAgeSubquery();
if ($is_cat) {
- return getCategoryUnread($link, $n_feed);
+ return getCategoryUnread($link, $n_feed, $owner_uid);
} else if ($n_feed == -1) {
$match_part = "marked = true";
} else if ($n_feed == -2) {
} else if ($n_feed == -3) {
$match_part = "unread = true";
- $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE");
+ $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE", $owner_uid);
if (DB_TYPE == "pgsql") {
$match_part .= " AND updated > NOW() - INTERVAL '$intl hour' ";
} else {
$match_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
}
-
+ } else if ($n_feed == -4) {
+ $match_part = "true";
} else if ($n_feed > 0) {
$result = db_query($link, "SELECT id FROM ttrss_feeds
WHERE parent_feed = '$n_feed'
AND hidden = false
- AND owner_uid = " . $_SESSION["uid"]);
+ AND owner_uid = " . $owner_uid);
if (db_num_rows($result) > 0) {
ttrss_user_entries.ref_id = ttrss_entries.id AND
$age_qpart AND
($match_part) AND
- owner_uid = " . $_SESSION["uid"]);
+ owner_uid = " . $owner_uid);
$unread = 0;
$label_id = -$feed - 11;
- $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE
- id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
+ return getLabelUnread($link, $label_id, $owner_uid);
- $match_part = db_fetch_result($result, 0, "sql_exp");
}
if ($match_part) {
ttrss_user_entries.ref_id = ttrss_entries.id AND
ttrss_feeds.hidden = false AND
$age_qpart AND
- $unread_qpart AND ($match_part) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
+ $unread_qpart AND ($match_part) AND ttrss_user_entries.owner_uid = " . $owner_uid);
} else {
FROM ttrss_tags,ttrss_user_entries,ttrss_entries
WHERE tag_name = '$feed' AND post_int_id = int_id AND ref_id = ttrss_entries.id
AND $unread_qpart AND $age_qpart AND
- ttrss_tags.owner_uid = " . $_SESSION["uid"]);
+ ttrss_tags.owner_uid = " . $owner_uid);
}
$unread = db_fetch_result($result, 0, "unread");
return $unread;
}
- /* FIXME this needs reworking */
-
function getGlobalUnread($link, $user_id = false) {
if (!$user_id) {
$user_id = $_SESSION["uid"];
}
- $age_qpart = getMaxAgeSubquery();
+ $result = db_query($link, "SELECT SUM(value) AS c_id FROM ttrss_counters_cache
+ WHERE owner_uid = '$user_id' AND feed_id > 0");
+
+ $c_id = db_fetch_result($result, 0, "c_id");
- $result = db_query($link, "SELECT count(ttrss_entries.id) as c_id FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
- WHERE unread = true AND
- ttrss_user_entries.feed_id = ttrss_feeds.id AND
- ttrss_user_entries.ref_id = ttrss_entries.id AND
- hidden = false AND
- $age_qpart AND
- ttrss_user_entries.owner_uid = '$user_id'");
- $c_id = db_fetch_result($result, 0, "c_id");
return $c_id;
}
$tctrs_modified = false;
-/* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
- FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
- ttrss_user_entries.ref_id = ttrss_entries.id AND
- ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
- post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
- UNION
- select tag_name,0 as count FROM ttrss_tags
- WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
-
$age_qpart = getMaxAgeSubquery();
$result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
}
$ret_arr = array();
-
- $old_counters = $_SESSION["lctr_last_value"];
- $lctrs_modified = false;
-
- $count = getFeedUnread($link, -1);
-
- if (!$ret_mode) {
- if (get_pref($link, 'EXTENDED_FEEDLIST')) {
- $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\"";
- } else {
- $xmsg_part = "";
- }
-
- print "<counter type=\"label\" id=\"-1\" counter=\"$count\" $xmsg_part/>";
- } else {
- $ret_arr["-1"]["counter"] = $count;
- $ret_arr["-1"]["description"] = __("Starred articles");
- }
-
- $count = getFeedUnread($link, -2);
+ for ($i = -1; $i >= -4; $i--) {
- if (!$ret_mode) {
+ $count = getFeedUnread($link, $i);
+
+ if (!$ret_mode) {
+
+ if (get_pref($link, 'EXTENDED_FEEDLIST')) {
+ $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $i) . " total)\"";
+ } else {
+ $xmsg_part = "";
+ }
- if (get_pref($link, 'EXTENDED_FEEDLIST')) {
- $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\"";
+ print "<counter type=\"label\" id=\"$i\" counter=\"$count\" $xmsg_part/>";
} else {
- $xmsg_part = "";
+ $ret_arr[$i]["counter"] = $count;
+ $ret_arr[$i]["description"] = getFeedTitle($link, $i);
}
-
- print "<counter type=\"label\" id=\"-2\" counter=\"$count\" $xmsg_part/>";
- } else {
- $ret_arr["-2"]["counter"] = $count;
- $ret_arr["-2"]["description"] = __("Published articles");
+
}
- $count = getFeedUnread($link, -3);
-
- if (!$ret_mode) {
-
- if (get_pref($link, 'EXTENDED_FEEDLIST')) {
- $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\"";
- } else {
- $xmsg_part = "";
- }
+ $old_counters = $_SESSION["lctr_last_value"];
+ $lctrs_modified = false;
- print "<counter type=\"label\" id=\"-3\" counter=\"$count\" $xmsg_part/>";
- } else {
- $ret_arr["-3"]["counter"] = $count;
- $ret_arr["-3"]["description"] = __("Fresh articles");
- }
+ $owner_uid = $_SESSION["uid"];
- $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
- ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
+ $result = db_query($link,
+ "SELECT ttrss_labels2.id, caption, COUNT(unread) AS unread FROM ttrss_labels2
+ LEFT JOIN ttrss_user_labels2 ON (label_id = ttrss_labels2.id)
+ LEFT JOIN ttrss_user_entries ON (ref_id = article_id AND
+ unread = true AND
+ ttrss_user_entries.owner_uid = '$owner_uid')
+ LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id AND hidden = false)
+ WHERE ttrss_labels2.owner_uid = '$owner_uid'
+ GROUP BY ttrss_labels2.id, caption");
+
+ while ($line = db_fetch_assoc($result)) {
- while ($line = db_fetch_assoc($result)) {
-
- $id = -$line["id"] - 11;
-
- $label_name = $line["description"];
-
- error_reporting (0);
-
- $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_user_entries,ttrss_entries,ttrss_feeds
- WHERE (" . $line["sql_exp"] . ") AND unread = true AND
- ttrss_feeds.hidden = false AND
- $age_qpart AND
- ttrss_user_entries.feed_id = ttrss_feeds.id AND
- ttrss_user_entries.ref_id = ttrss_entries.id AND
- ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
-
- $count = db_fetch_result($tmp_result, 0, "count");
-
- if (!$smart_mode || $old_counters[$id] != $count) {
- $old_counters[$id] = $count;
- $lctrs_modified = true;
- if (!$ret_mode) {
-
- if (get_pref($link, 'EXTENDED_FEEDLIST')) {
- $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\"";
+ $id = -$line["id"] - 11;
+
+ $label_name = $line["caption"];
+ $count = $line["unread"];
+
+ if (!$smart_mode || $old_counters[$id] != $count) {
+ $old_counters[$id] = $count;
+ $lctrs_modified = true;
+ if (!$ret_mode) {
+
+ if (get_pref($link, 'EXTENDED_FEEDLIST')) {
+ $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\"";
+ } else {
+ $xmsg_part = "";
+ }
+
+ print "<counter type=\"label\" id=\"$id\" counter=\"$count\" $xmsg_part/>";
} else {
- $xmsg_part = "";
+ $ret_arr[$id]["counter"] = $count;
+ $ret_arr[$id]["description"] = $label_name;
}
-
- print "<counter type=\"label\" id=\"$id\" counter=\"$count\" $xmsg_part/>";
- } else {
- $ret_arr[$id]["counter"] = $count;
- $ret_arr[$id]["description"] = $label_name;
}
+
+ error_reporting (DEFAULT_ERROR_LEVEL);
}
- error_reporting (DEFAULT_ERROR_LEVEL);
- }
-
if ($smart_mode && $lctrs_modified) {
$_SESSION["lctr_last_value"] = $old_counters;
}
return $ret_arr;
}
-/* function getFeedCounter($link, $id) {
-
- $result = db_query($link, "SELECT
- count(id) as count,last_error
- FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
- WHERE feed_id = '$id' AND unread = true
- AND ttrss_user_entries.feed_id = ttrss_feeds.id
- AND ttrss_user_entries.ref_id = ttrss_entries.id");
-
- $count = db_fetch_result($result, 0, "count");
- $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error"));
-
- print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>";
- } */
-
function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS, $active_feed = false) {
$age_qpart = getMaxAgeSubquery();
$old_counters = $_SESSION["fctr_last_value"];
-/* $result = db_query($link, "SELECT id,last_error,parent_feed,
- ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated,
- (SELECT count(id)
- FROM ttrss_entries,ttrss_user_entries
- WHERE feed_id = ttrss_feeds.id AND
- ttrss_user_entries.ref_id = ttrss_entries.id
- AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
- FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . "
- AND parent_feed IS NULL"); */
-
$query = "SELECT ttrss_feeds.id,
ttrss_feeds.title,
".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated,
- last_error,
- COUNT(ttrss_entries.id) AS count
- FROM ttrss_feeds
- LEFT JOIN ttrss_user_entries ON (ttrss_user_entries.feed_id = ttrss_feeds.id
- AND ttrss_user_entries.owner_uid = ttrss_feeds.owner_uid
- AND ttrss_user_entries.unread = true)
- LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id AND
- $age_qpart)
+ last_error, value AS count
+ FROM ttrss_feeds, ttrss_counters_cache
WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]."
AND parent_feed IS NULL
- GROUP BY ttrss_feeds.id, ttrss_feeds.title, ttrss_feeds.last_updated, last_error";
+ AND ttrss_counters_cache.feed_id = id";
$result = db_query($link, $query);
$fctrs_modified = false;
$last_updated = htmlspecialchars($last_updated);
- $has_img = is_file(ICONS_DIR . "/$id.ico");
+ $has_img = feed_has_icon($id);
$tmp_result = db_query($link,
- "SELECT ttrss_feeds.id,COUNT(unread) AS unread
- FROM ttrss_feeds LEFT JOIN ttrss_user_entries
- ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
- LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id)
- WHERE parent_feed = '$id' AND $age_qpart AND unread = true GROUP BY ttrss_feeds.id");
-
- if (db_num_rows($tmp_result) > 0) {
- while ($l = db_fetch_assoc($tmp_result)) {
- $count += $l["unread"];
- }
- }
+ "SELECT SUM(value) AS unread FROM ttrss_feeds, ttrss_counters_cache
+ WHERE parent_feed = '$id' AND feed_id = id");
+
+ $count += db_fetch_result($tmp_result, 0, "unread");
if (!$smart_mode || $old_counters[$id] != $count) {
$old_counters[$id] = $count;
return __("Published articles");
} else if ($id == -3) {
return __("Fresh articles");
+ } else if ($id == -4) {
+ return __("All articles");
} else if ($id < -10) {
$label_id = -$id - 11;
- $result = db_query($link, "SELECT description FROM ttrss_labels WHERE id = '$label_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, "description");
+ return db_fetch_result($result, 0, "caption");
} else {
return "Unknown label ($label_id)";
}
print "<param key=\"default_view_limit\" value=\"" .
(int) get_pref($link, "_DEFAULT_VIEW_LIMIT") . "\"/>";
+ print "<param key=\"default_view_order_by\" value=\"" .
+ get_pref($link, "_DEFAULT_VIEW_ORDER_BY") . "\"/>";
+
print "<param key=\"prefs_active_tab\" value=\"" .
get_pref($link, "_PREFS_ACTIVE_TAB") . "\"/>";
print "<param key=\"bw_limit\" value=\"".
(int) $_SESSION["bw_limit"]."\"/>";
- print "<param key=\"sync_counters\" value=\"" .
- (int) get_pref($link, "SYNC_COUNTERS") . "\"/>";
+// print "<param key=\"sync_counters\" value=\"" .
+// (int) get_pref($link, "SYNC_COUNTERS") . "\"/>";
+
+ print "<param key=\"sync_counters\" value=\"1\"/>";
print "</init-params>";
}
if (CHECK_FOR_NEW_VERSION && $_SESSION["access_level"] >= 10) {
- if ($_SESSION["last_version_check"] + 7200 < time()) {
+ if ($_SESSION["last_version_check"] + 86400 < time()) {
$new_version_details = check_for_update($link);
print "<param key=\"new_version_available\" value=\"".
$view_query_part = "";
- if ($view_mode == "adaptive") {
+ if ($view_mode == "adaptive" || $view_query_part == "noscores") {
if ($search) {
$view_query_part = " ";
} else if ($feed != -1) {
if ($view_mode == "unread") {
$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;
}
} else if ($feed == -1) { // starred virtual feed
$query_strategy_part = "marked = true";
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
- } else if ($feed == -2) { // published virtual feed
- $query_strategy_part = "published = true";
- $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
+ } else if ($feed == -2) { // published virtual feed OR labels category
+
+ if (!$cat_view) {
+ $query_strategy_part = "published = true";
+ $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
+ } else {
+ $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
+
+ $ext_tables_part = ",ttrss_labels2,ttrss_user_labels2";
+
+ $query_strategy_part = "ttrss_labels2.id = ttrss_user_labels2.label_id AND
+ ttrss_user_labels2.article_id = ref_id";
+
+ }
+
} else if ($feed == -3) { // fresh virtual feed
$query_strategy_part = "unread = true";
$query_strategy_part .= " AND updated > 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;
-
- $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
- WHERE id = '$label_id'");
-
- $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
- if (!$query_strategy_part) {
- return false;
- }
+ $query_strategy_part = "label_id = '$label_id' AND
+ ttrss_labels2.id = ttrss_user_labels2.label_id AND
+ ttrss_user_labels2.article_id = ref_id";
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
+ $ext_tables_part = ",ttrss_labels2,ttrss_user_labels2";
+
} else {
$query_strategy_part = "id > 0"; // dumb
}
$order_by = "updated DESC";
}
- $order_by = "score DESC, $order_by";
+ if ($view_mode != "noscores") {
+ $order_by = "score DESC, $order_by";
+ }
if ($override_order) {
$order_by = $override_order;
$feed_title = __("Starred articles");
if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; }
} else if ($feed == -2) {
- $feed_title = __("Published articles");
- if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; }
+ if (!$cat_view) {
+ $feed_title = __("Published articles");
+ if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; }
+ } else {
+ $feed_title = __("Labels");
+ }
} else if ($feed == -3) {
$feed_title = __("Fresh articles");
if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; }
+ } else if ($feed == -4) {
+ $feed_title = __("All articles");
+ if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; }
} else if ($feed < -10) {
$label_id = -$feed - 11;
- $result = db_query($link, "SELECT description FROM ttrss_labels
+ $result = db_query($link, "SELECT caption FROM ttrss_labels2
WHERE id = '$label_id'");
- $feed_title = db_fetch_result($result, 0, "description");
+ $feed_title = db_fetch_result($result, 0, "caption");
if ($search) {
$feed_title = __("Searched for") . " $search ($feed_title)";
} */
}
- $query = "SELECT
+ $query = "SELECT DISTINCT
guid,
ttrss_entries.id,ttrss_entries.title,
updated,
".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms,
author,score
FROM
- ttrss_entries,ttrss_user_entries,ttrss_feeds
+ ttrss_entries,ttrss_user_entries,ttrss_feeds$ext_tables_part
WHERE
$group_limit_part
ttrss_feeds.hidden = false AND
$view_query_part
$query_strategy_part ORDER BY $order_by
$limit_query_part $offset_query_part";
-
- $result = db_query($link, $query);
-
+
if ($_GET["debug"]) print $query;
+
+ $result = db_query($link, $query);
} else {
// browsing by tag
}
function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat,
- $search, $search_mode, $match_on) {
+ $limit, $search, $search_mode, $match_on) {
+
+ if (!$limit) $limit = 30;
$qfh_ret = queryFeedHeadlines($link, $feed,
- 30, false, $is_cat, $search, $search_mode, $match_on, "updated DESC", 0,
+ $limit, false, $is_cat, $search, $search_mode, $match_on, "updated DESC", 0,
$owner_uid);
$result = $qfh_ret[0];
if (get_pref($link, "STRIP_UNSAFE_TAGS") || $force_strip_tags) {
$res = strip_tags_long($res,
- "<p><a><i><em><b><strong><blockquote><br><img><ul><ol><li>");
+ "<p><a><i><em><b><strong><code><pre><blockquote><br><img><ul><ol><li>");
// $res = preg_replace("/\r\n|\n|\r/", "", $res);
// $res = strip_tags_long($res, "<p><a><i><em><b><strong><blockquote><br><img><div><span>");
if (DIGEST_SMTP_HOST) {
$mail->Host = DIGEST_SMTP_HOST;
$mail->Mailer = "smtp";
+ $mail->SMTPAuth = DIGEST_SMTP_LOGIN != '';
$mail->Username = DIGEST_SMTP_LOGIN;
$mail->Password = DIGEST_SMTP_PASSWORD;
}
}
function check_for_update($link, $brief_fmt = true) {
- $releases_feed = "http://tt-rss.spb.ru/releases.rss";
+ $releases_feed = "http://tt-rss.org/releases.rss";
if (!CHECK_FOR_NEW_VERSION || $_SESSION["access_level"] < 10) {
return;
} else {
return "New version of Tiny-Tiny RSS ($latest_version) is available:
<div class='milestoneDetails'>$content</div>
- Visit <a target=\"_blank\" href=\"http://tt-rss.spb.ru/\">official site</a> for
+ Visit <a target=\"_blank\" href=\"http://tt-rss.org/\">official site</a> for
download and update information.";
}
unread = NOT unread,last_read = NOW()
WHERE ($ids_qpart) AND owner_uid = $owner_uid");
}
+
+ /* update ccache */
+
+ $result = db_query($link, "SELECT DISTINCT feed_id FROM ttrss_user_entries
+ WHERE ($ids_qpart) AND owner_uid = $owner_uid");
+
+ while ($line = db_fetch_assoc($result)) {
+ ccache_update($link, $line["feed_id"], $owner_uid);
+ }
}
function catchupArticleById($link, $id, $cmode) {
$tid = "headlineActionsBottom";
}
- print "<table class=\"$class\" id=\"$tid\"
+ print "<nobr><table class=\"$class\" id=\"$tid\"
width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
if ($rtl_content) {
$sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)";
$sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)";
$sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)";
+ $sel_inv_link = "javascript:invertHeadlineSelection()";
$tog_unread_link = "javascript:selectionToggleUnread()";
$tog_marked_link = "javascript:selectionToggleMarked()";
$sel_unread_link = "javascript:cdmSelectArticles('unread')";
$sel_none_link = "javascript:cdmSelectArticles('none')";
+ $sel_inv_link = "javascript:invertHeadlineSelection()";
+
$tog_unread_link = "javascript:selectionToggleUnread(true)";
$tog_marked_link = "javascript:selectionToggleMarked(true)";
$tog_published_link = "javascript:selectionTogglePublished(true)";
}
- if (!$dashboard_menu) {
-
if (strpos($_SESSION["client.userAgent"], "MSIE") === false) {
print "<td class=\"headlineActions$rtl_cpart\">
".__('Select:')."
<a href=\"$sel_all_link\">".__('All')."</a>,
<a href=\"$sel_unread_link\">".__('Unread')."</a>,
+ <a href=\"$sel_inv_link\">".__('Invert')."</a>,
<a href=\"$sel_none_link\">".__('None')."</a></li>
<li class=\"vsep\"> </li>
<li class=\"top\">".__('Actions...')."<ul>
<li onclick=\"$tog_unread_link\"> ".__('Unread')."</li>
<li onclick=\"$tog_marked_link\"> ".__('Starred')."</li>
<li onclick=\"$tog_published_link\"> ".__('Published')."</li>
- <li><span class=\"insensitive\">--------</span></li>
+ <!-- <li><span class=\"insensitive\">--------</span></li> -->
<li><span class=\"insensitive\">".__('Mark as read:')."</span></li>
<li onclick=\"$catchup_sel_link\"> ".__('Selection')."</li>";
print "<li onclick=\"$catchup_feed_link\"> ".__('Entire feed')."</li>";
- print "<li><span class=\"insensitive\">--------</span></li>";
- print "<li><span class=\"insensitive\">".__('Other actions:')."</span></li>";
-
+ //print "<li><span class=\"insensitive\">--------</span></li>";
+ print "<li><span class=\"insensitive\">".__('Assign label:')."</span></li>";
- if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
- print "
- <li onclick=\"javascript:labelFromSearch('$search', '$search_mode',
- '$match_on', '$feed_id', '$is_cat');\">
- ".__('Search to label')."</li>";
- } else {
- print "<li><span class=\"insensitive\"> ".__('Search to label')."</li>";
+ $result = db_query($link, "SELECT id, caption FROM ttrss_labels2 WHERE
+ owner_uid = '".$_SESSION["uid"]."' ORDER BY caption");
+
+ while ($line = db_fetch_assoc($result)) {
+
+ $label_id = $line["id"];
+ $label_caption = $line["caption"];
+
+ if ($feed_id < -10 && $feed_id == -11-$label_id) {
+ print "<li onclick=\"javascript:selectionRemoveLabel($label_id)\">
+ $label_caption ".__('(remove)')."</li>";
+ } else {
+ print "<li onclick=\"javascript:selectionAssignLabel($label_id)\">
+ $label_caption</li>";
+ }
+ }
- }
-
print "</ul></li></ul>";
print "</td>";
__('Mark as read:')."
<a href=\"#\" onclick=\"$catchup_page_link\">".__('Page')."</a>,
<a href=\"#\" onclick=\"$catchup_feed_link\">".__('Feed')."</a>";
-
- if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
-
- print "
- <a href=\"javascript:labelFromSearch('$search', '$search_mode',
- '$match_on', '$feed_id', '$is_cat');\">
- ".__('Convert to label')."</a>";
- }
-
+
print "</td>";
}
- } else { // dashboard menu actions
-
- // not implemented
- print "</td>";
- }
print "<td class=\"headlineTitle$rtl_cpart\">";
print "</span>";
print "</td>";
- print "</tr></table>";
+ print "</tr></table></nobr>";
}
function printCategoryHeader($link, $cat_id, $hidden = false, $can_browse = true) {
$tmp_category = getCategoryTitle($link, $cat_id);
- $cat_unread = getCategoryUnread($link, $cat_id);
+
+ if ($cat_id > 0) {
+ $cat_unread = ccache_find($link, $cat_id, $_SESSION["uid"], true);
+ } else if ($cat_id == 0 || $cat_id == -2) {
+ $cat_unread = getCategoryUnread($link, $cat_id);
+ }
if ($hidden) {
$holder_style = "display:none;";
$catctr_class = ($cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread";
- print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
- <a id=\"FCATN-$cat_id\" href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>";
-
if ($can_browse) {
- print "<a href=\"#\" onclick=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">";
+ $browse_cat_link = "onclick=\"javascript:viewCategory($cat_id)\"";
+ $inner_title_class = "catTitle";
} else {
- print "<span id=\"FCAP-$cat_id\">";
+ $browse_cat_link = "";
+ $inner_title_class = "catTitleNL";
}
+ $cat_class = "feedCat";
+
+ print "<li class=\"$cat_class\" id=\"FCAT-$cat_id\">
+ <img onclick=\"toggleCollapseCat($cat_id)\" class=\"catCollapse\"
+ title=\"".__('Click to collapse category')."\"
+ src=\"images/cat-collapse.png\"><span class=\"$inner_title_class\"
+ id=\"FCATN-$cat_id\" $browse_cat_link
+ \">$tmp_category</span>";
+
+ print "<span id=\"FCAP-$cat_id\">";
+
print " <span id=\"FCATCTR-$cat_id\"
class=\"$catctr_class\">($cat_unread)</span> $ellipsis";
- if ($can_browse) {
- print "</a>";
- } else {
- print "</span>";
- }
+ print "</span>";
- print "</li>";
+ //print "</li>";
print "<ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\" style='$holder_style'>";
printCategoryHeader($link, -1, $cat_hidden, false);
}
- if (defined('_ENABLE_DASHBOARD')) {
- printFeedEntry(-4, "virt", __("Dashboard"), 0,
- "images/tag.png", $link);
- }
-
$num_starred = getFeedUnread($link, -1);
$num_published = getFeedUnread($link, -2);
$num_fresh = getFeedUnread($link, -3);
+ $num_total = getFeedUnread($link, -4);
+
+ $class = "virt";
+
+ if ($num_total > 0) $class .= "Unread";
+
+ printFeedEntry(-4, $class, __("All articles"), $num_total,
+ "images/tag.png", $link);
$class = "virt";
"images/pub_set.gif", $link);
if (get_pref($link, 'ENABLE_FEED_CATS')) {
- print "</ul>";
+ print "</ul></li>";
}
if (!$tags) {
- if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
-
- $result = db_query($link, "SELECT id,sql_exp,description FROM
- ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
+
+ $result = db_query($link, "SELECT id,caption FROM
+ ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
if (db_num_rows($result) > 0) {
if (get_pref($link, 'ENABLE_FEED_CATS')) {
$cat_hidden = false;
}
- printCategoryHeader($link, -2, $cat_hidden, false);
+ printCategoryHeader($link, -2, $cat_hidden, true);
} else {
print "<li><hr></li>";
while ($line = db_fetch_assoc($result)) {
- error_reporting (0);
-
$label_id = -$line['id'] - 11;
$count = getFeedUnread($link, $label_id);
if ($count > 0) {
$class .= "Unread";
}
-
- error_reporting (DEFAULT_ERROR_LEVEL);
printFeedEntry($label_id,
- $class, $line["description"],
+ $class, $line["caption"],
$count, "images/label.png", $link);
}
if (get_pref($link, 'ENABLE_FEED_CATS')) {
print "</ul>";
}
- }
+ }
- }
if (!get_pref($link, 'ENABLE_FEED_CATS')) {
print "<li><hr></li>";
if (get_pref($link, 'ENABLE_FEED_CATS')) {
if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
- $order_by_qpart = "category,unread DESC,title";
+ $order_by_qpart = "order_id,category,unread DESC,title";
} else {
- $order_by_qpart = "category,title";
+ $order_by_qpart = "order_id,category,title";
}
} else {
if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
$query = "SELECT ttrss_feeds.*,
".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
- (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
- WHERE feed_id = ttrss_feeds.id AND unread = true
- AND $age_qpart
- AND ttrss_user_entries.ref_id = ttrss_entries.id
- AND owner_uid = '$owner_uid') as unread,
cat_id,last_error,
ttrss_feed_categories.title AS category,
- ttrss_feed_categories.collapsed
- FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
- ON (ttrss_feed_categories.id = cat_id)
+ ttrss_feed_categories.collapsed,
+ value AS unread
+ FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
+ ON (ttrss_feed_categories.id = cat_id)
+ LEFT JOIN ttrss_counters_cache
+ ON
+ (ttrss_feeds.id = feed_id)
WHERE
ttrss_feeds.hidden = false AND
ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
if (!$feed) $feed = "[Untitled]";
$feed_id = $line["id"];
+ $unread = $line["unread"];
$subop = $_GET["subop"];
-
- $unread = $line["unread"];
if (get_pref($link, 'HEADLINES_SMART_DATE')) {
$last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
}
$tmp_result = db_query($link,
- "SELECT id,COUNT(unread) AS unread
- FROM ttrss_feeds LEFT JOIN ttrss_user_entries
- ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
- WHERE parent_feed = '$feed_id' AND unread = true
- GROUP BY ttrss_feeds.id");
-
- if (db_num_rows($tmp_result) > 0) {
- while ($l = db_fetch_assoc($tmp_result)) {
- $unread += $l["unread"];
- }
- }
+ "SELECT SUM(value) AS unread FROM ttrss_feeds, ttrss_counters_cache
+ WHERE parent_feed = '$feed_id' AND feed_id = id");
+ $unread += db_fetch_result($tmp_result, 0, "unread");
+
$cat_id = $line["cat_id"];
$tmp_category = $line["category"];
if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
if ($category) {
- print "</ul>";
+ print "</ul></li>";
}
$category = $tmp_category;
if ($tag == '') return false;
if (preg_match("/^[0-9]*$/", $tag)) return false;
- $tag = iconv("utf-8", "utf-8", $tag);
+ if (function_exists('iconv')) {
+ $tag = iconv("utf-8", "utf-8", $tag);
+ }
+
if (!$tag) return false;
return true;
return vsprintf(__(array_shift($args)), $args);
}
- function outputArticleXML($link, $id, $feed_id, $mark_as_read = true) {
+ function outputArticleXML($link, $id, $feed_id, $mark_as_read = true,
+ $zoom_mode = false) {
/* we can figure out feed_id from article id anyway, why do we
* pass feed_id here? */
$feed_id = db_fetch_result($result, 0, "feed_id");
- print "<article id='$id'><![CDATA[";
+ if (!$zoom_mode) { print "<article id='$id'><![CDATA["; };
$result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
$result = db_query($link, "UPDATE ttrss_user_entries
SET unread = false,last_read = NOW()
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
+
+ ccache_update($link, $feed_id, $_SESSION["uid"]);
}
$result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
$feed_icon = " ";
}
-/* if ($line["comments"] && $line["link"] != $line["comments"]) {
- $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
- } else {
- $entry_comments = "";
- } */
-
$num_comments = $line["num_comments"];
$entry_comments = "";
}
}
+ if ($zoom_mode) {
+ header("Content-Type: text/html");
+ print "<html><head>
+ <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>";
+ }
+
+
print "<div class=\"postReply\">";
print "<div class=\"postHeader\" onmouseover=\"enable_resize(true)\"
print "<div clear='both'>" . $line["title"] . "$entry_author</div>";
}
-/* $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
- ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
- ORDER BY tag_name"); */
-
$tags = get_article_tags($link, $id);
$tags_str = "";
+ $tags_nolinks_str = "";
$f_tags_str = "";
$num_tags = 0;
if ($num_tags == $tag_limit) {
$tags_str .= "…";
+ $tags_nolinks_str .= "…";
} else if ($num_tags < $tag_limit) {
$tags_str .= $tag_str;
+ $tags_nolinks_str .= "$tag, ";
}
$f_tags_str .= $tag_str;
}
$tags_str = preg_replace("/, $/", "", $tags_str);
+ $tags_nolinks_str = preg_replace("/, $/", "", $tags_nolinks_str);
$f_tags_str = preg_replace("/, $/", "", $f_tags_str);
$all_tags_div = "<span class='cdmAllTagsCtr'>…<div class='cdmAllTags'>All Tags: $f_tags_str</div></span>";
if (!$entry_comments) $entry_comments = " "; # placeholder
if (!$tags_str) $tags_str = '<span class="tagList">'.__('no tags').'</span>';
+ if (!$tags_nolinks_str) $tags_nolinks_str = '<span class="tagList">'.__('no tags').'</span>';
print "<div style='float : right'>
- <img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'>
- $tags_str
- <a title=\"Edit tags for this article\"
- href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a></div>
- <div clear='both'>$entry_comments</div>";
+ <img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'>";
+
+ if (!$zoom_mode) {
+ print "$tags_str
+ <a title=\"".__('Edit tags for this article')."\"
+ href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a>";
+
+ if (defined('_ENABLE_INLINE_VIEW')) {
+
+ print "<img src=\"images/art-inline.png\" class='tagsPic'
+ style=\"cursor : pointer\" style=\"cursor : pointer\"
+ onclick=\"showOriginalArticleInline($id)\"
+ alt='Inline' title='".__('Display original article content')."'>";
+
+ }
+
+ print "<img src=\"images/art-zoom.png\" class='tagsPic'
+ style=\"cursor : pointer\" style=\"cursor : pointer\"
+ onclick=\"zoomToArticle($id)\"
+ alt='Zoom' title='".__('Show article summary in new window')."'>";
+ } else {
+ print "$tags_nolinks_str";
+ }
+ print "</div>";
+ print "<div clear='both'>$entry_comments</div>";
print "</div>";
print "<div class=\"postIcon\">" . $feed_icon . "</div>";
+
print "<div class=\"postContent\">";
-
+
#print "<div id=\"allEntryTags\">".__('Tags:')." $f_tags_str</div>";
- $line["content"] = sanitize_rss($link, $line["content"]);
+ $article_content = sanitize_rss($link, $line["content"]);
if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
- $line["content"] = preg_replace("/href=/i", "target=\"_blank\" href=", $line["content"]);
+ $article_content = preg_replace("/href=/i", "target=\"_blank\" href=",
+ $article_content);
}
- print $line["content"];
+ print $article_content;
$result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE
post_id = '$id' AND content_url != ''");
if (db_num_rows($result) > 0) {
- print "<div class=\"postEnclosures\">";
-
- if (db_num_rows($result) == 1) {
- print __("Attachment:") . " ";
- } else {
- print __("Attachments:") . " ";
- }
+ $entries_html = array();
$entries = array();
while ($line = db_fetch_assoc($result)) {
$entry .= "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
$filename . " (" . $ctype . ")" . "</a>";
+ array_push($entries_html, $entry);
+
+ $entry = array();
+
+ $entry["type"] = $ctype;
+ $entry["filename"] = $filename;
+ $entry["url"] = $url;
+
array_push($entries, $entry);
}
- print join(", ", $entries);
+ print "<div class=\"postEnclosures\">";
+
+ if (!preg_match("/img/i", $article_content)) {
+ foreach ($entries as $entry) {
+ if (preg_match("/image/", $entry["type"])) {
+ print "<p><img
+ alt=\"".htmlspecialchars($entry["filename"])."\"
+ src=\"" .htmlspecialchars($entry["url"]) . "\"></p>";
+ }
+ }
+ }
+
+ print "<div class=\"postEnclosures\">";
+
+ if (db_num_rows($result) == 1) {
+ print __("Attachment:") . " ";
+ } else {
+ print __("Attachments:") . " ";
+ }
+
+ print join(", ", $entries_html);
print "</div>";
}
}
- print "]]></article>";
+ if (!$zoom_mode) {
+ print "]]></article>";
+ } else {
+ print "
+ <div style=\"text-align : center\">
+ <input type=\"submit\" onclick=\"return window.close()\"
+ value=\"".__("Close this window")."\"></div>";
+ print "</body></html>";
+
+ }
}
function outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view,
- $next_unread_feed, $offset, $vgr_last_feed = false) {
+ $next_unread_feed, $offset, $vgr_last_feed = false,
+ $override_order = false) {
$disable_cache = false;
if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
$qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
- $search, $search_mode, $match_on, false, $real_offset);
+ $search, $search_mode, $match_on, $override_order, $real_offset);
if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
$id = $line["id"];
$feed_id = $line["feed_id"];
+ $labels = get_article_labels($link, $id);
+ $labels_str = "<span id=\"HLLCTR-$id\">";
+
+ foreach ($labels as $l) {
+ $labels_str .= "<span
+ class='hlLabelRef'>".
+ $l[1]."</span>";
+ }
+
+ $labels_str .= "</span>";
+
if (count($topmost_article_ids) < 5) {
array_push($topmost_article_ids, $id);
}
$score_pic = get_score_pic($score);
- $score_title = __("(Click to change)");
+/* $score_title = __("(Click to change)");
+ $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
+ onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
$score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
- onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">";
+ title=\"$score\">";
if ($score > 500) {
$hlc_suffix = "H";
$entry_author = " - $entry_author";
}
- $has_feed_icon = is_file(ICONS_DIR . "/$feed_id.ico");
+ $has_feed_icon = feed_has_icon($feed_id);
if ($has_feed_icon) {
$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
} else {
//$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
+ $feed_icon_img = "";
}
if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
print "</a>";
+ print $labels_str;
+
# <a href=\"javascript:viewfeed($feed_id, '', false)\">".
# $line["feed_title"]."</a>
$vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>mark as read</a>)";
- $has_feed_icon = is_file(ICONS_DIR . "/$feed_id.ico");
+ $has_feed_icon = feed_has_icon($feed_id);
if ($has_feed_icon) {
$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
(".__('Show article').")</a>";
} */
+ print $labels_str;
if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) {
if ($line["feed_title"]) {
// print "<div class=\"cdmInnerContent\" id=\"CICD-$id\" $cdm_cstyle>";
print sanitize_rss($link, $line["content_preview"]);
+ $article_content = $line["content_preview"];
$e_result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE
post_id = '$id' AND content_url != ''");
if (db_num_rows($e_result) > 0) {
- print "<div class=\"cdmEnclosures\">";
-
- if (db_num_rows($e_result) == 1) {
- print __("Attachment:") . " ";
- } else {
- print __("Attachments:") . " ";
- }
+ $entries_html = array();
$entries = array();
while ($e_line = db_fetch_assoc($e_result)) {
$entry .= "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
$filename . " (" . $ctype . ")" . "</a>";
+ array_push($entries_html, $entry);
+
+ $entry = array();
+
+ $entry["type"] = $ctype;
+ $entry["filename"] = $filename;
+ $entry["url"] = $url;
+
array_push($entries, $entry);
}
- print join(", ", $entries);
+ if (!preg_match("/img/i", $article_content)) {
+ foreach ($entries as $entry) {
+ if (preg_match("/image/", $entry["type"])) {
+ print "<p><img
+ alt=\"".htmlspecialchars($entry["filename"])."\"
+ src=\"" .htmlspecialchars($entry["url"]) . "\"></p>";
+ }
+ }
+ }
+
+ print "<div class=\"cdmEnclosures\">";
+
+ if (db_num_rows($e_result) == 1) {
+ print __("Attachment:") . " ";
+ } else {
+ print __("Attachments:") . " ";
+ }
+
+ print join(", ", $entries_html);
print "</div>";
}
+
print "<br clear='both'>";
// print "</div>";
print "</span><span class='s1'>$marked_pic</span> ";
print "<span class='s1'>$published_pic</span> ";
+ print "<span class='s1'><img src=\"images/art-zoom.png\" class='tagsPic'
+ onclick=\"zoomToArticle($id)\"
+ style=\"cursor : pointer\"
+ alt='Zoom'
+ title='".__('Show article summary in new window')."'></span>";
$tags = get_article_tags($link, $id);
print "</table>";
}
-// print_headline_subtoolbar($link,
-// "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
-
-
} else {
$message = "";
case "unread":
$message = __("No unread articles found to display.");
break;
+ case "updated":
+ $message = __("No updated articles found to display.");
+ break;
case "marked":
$message = __("No starred articles found to display.");
break;
default:
- $message = __("No articles found to display.");
+ if ($feed < -10) {
+ $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
+ } else {
+ $message = __("No articles found to display.");
+ }
}
if (!$offset) print "<div class='whiteBox'>$message</div>";
function printTagCloud($link) {
- /* get first ref_id to count from */
-
- /*
-
- $query = "";
-
- if (DB_TYPE == "pgsql") {
- $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries
- WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]."
- AND date_entered > NOW() - INTERVAL '30 days'";
- } else {
- $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries
- WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]."
- AND date_entered > DATE_SUB(NOW(), INTERVAL 30 DAY)";
- }
-
- $result = db_query($link, $query);
- $first_id = db_fetch_result($result, 0, "id"); */
-
- //AND post_int_id >= '$first_id'
$query = "SELECT tag_name, COUNT(post_int_id) AS count
FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]."
GROUP BY tag_name ORDER BY count DESC LIMIT 50";
$result = db_query($link, "DELETE FROM ttrss_entries WHERE
(SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
+
+ ccache_update($link, $id, $_SESSION['uid']);
} // function clear_feed_articles
/**
} // function update_daemon_common
- function generate_dashboard_feed($link) {
-
- print "<div id=\"headlinesContainer\">";
-
- print_headline_subtoolbar($link, "", "Dashboard",
- false, false, -4, false, false, false,
- false, 0, 0, true, true, "tag.png");
-
- print "<div id=\"headlinesInnerContainer\" class=\"dashboard\">";
- print "<div>There is <b>666</b> unread articles in <b>666</b> feeds.</div>";
- print "</div>";
-
- print "</div>";
-
- print "]]></headlines>";
- print "<headlines-count value=\"0\"/>";
- print "<headlines-unread value=\"0\"/>";
- print "<disable-cache value=\"1\"/>";
-
- print "<articles>";
- print "</articles>";
- }
-
function sanitize_article_content($text) {
# we don't support CDATA sections in articles, they break our own escaping
$text = preg_replace("/\[\[CDATA/", "", $text);
ttrss_filter_types.name AS name,
ttrss_filter_actions.name AS action,
inverse,
- action_param
+ action_param,
+ filter_param
FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE
enabled = true AND
$ftype_query_part
$filter["reg_exp"] = $line["reg_exp"];
$filter["action"] = $line["action"];
$filter["action_param"] = $line["action_param"];
+ $filter["filter_param"] = $line["filter_param"];
$filter["inverse"] = sql_bool_to_bool($line["inverse"]);
array_push($filters[$line["name"]], $filter);
function rounded_table_start($classname, $header = " ") {
print "<table width='100%' class='$classname' cellspacing='0' cellpadding='0'>";
- print "<tr><td class='c1'> </td><td class='top'>$header</td><td class='c2'> </tr>";
+ print "<tr><td class='c1'> </td><td class='top'>$header</td><td class='c2'> </td></tr>";
print "<tr><td class='left'> </td><td class='content'>";
}
function rounded_table_end($footer = " ") {
print "</td><td class='right'> </td></tr>";
- print "<tr><td class='c4'> </td><td class='bottom'>$footer</td><td class='c3'> </tr>";
+ print "<tr><td class='c4'> </td><td class='bottom'>$footer</td><td class='c3'> </td></tr>";
print "</table>";
}
- function print_label_dlg_common_examples() {
+ function feed_has_icon($id) {
+ return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
+ }
- print __("Match ") . " ";
+ function init_connection($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'");
+ } else {
+ if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
+ db_query($link, "SET NAMES " . MYSQL_CHARSET);
+ // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
+ }
+ }
+ }
-/* print "<select name=\"label_andor\">";
- print "<option value=\"and\">AND</option>";
- print "<option value=\"or\">OR</option>";
- print "</select>"; */
+ function update_feedbrowser_cache($link) {
- print "<select name=\"label_fields\" onchange=\"labelFieldsCheck(this)\">";
- print "<option value=\"unread\">".__("Unread articles")."</option>";
- print "<option value=\"updated\">".__("Updated articles")."</option>";
- print "<option value=\"kw_title\">".__("Title contains")."</option>";
- print "<option value=\"kw_content\">".__("Content contains")."</option>";
- print "<option value=\"scoreE\">".__("Score equals")."</option>";
- print "<option value=\"scoreG\">".__("Score is greater than")."</option>";
- print "<option value=\"scoreL\">".__("Score is less than")."</option>";
- print "<option value=\"newerH\">".__("Articles newer than X hours")."</option>";
- print "<option value=\"newerD\">".__("Articles newer than X days")."</option>";
+ $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
+ FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
+ WHERE tf.feed_url = ttrss_feeds.feed_url
+ AND (private IS true OR feed_url LIKE '%:%@%/%'))
+ GROUP BY feed_url ORDER BY subscribers DESC LIMIT 200");
+
+ db_query($link, "BEGIN");
+
+ db_query($link, "DELETE FROM ttrss_feedbrowser_cache");
+
+ $count = 0;
+
+ while ($line = db_fetch_assoc($result)) {
+ $subscribers = db_escape_string($line["subscribers"]);
+ $feed_url = db_escape_string($line["feed_url"]);
+
+ db_query($link, "INSERT INTO ttrss_feedbrowser_cache
+ (feed_url, subscribers) VALUES ('$feed_url', '$subscribers')");
+
+ ++$count;
+ }
+
+ db_query($link, "COMMIT");
- print "</select>";
+ return $count;
+
+ }
+
+ function ccache_zero($link, $feed_id, $owner_uid) {
+ db_query($link, "UPDATE ttrss_counters_cache SET
+ value = 0, updated = NOW() WHERE
+ feed_id = '$feed_id' AND owner_uid = '$owner_uid'");
+ }
- print "<input style=\"display : none\" name=\"label_fields_param\"
- size=\"10\">";
+ function ccache_zero_all($link, $owner_uid) {
+ db_query($link, "UPDATE ttrss_counters_cache SET
+ value = 0 WHERE owner_uid = '$owner_uid'");
- print " <input type=\"submit\"
- onclick=\"return addLabelExample()\"
- value=\"".__("Add")."\">";
+ db_query($link, "UPDATE ttrss_cat_counters_cache SET
+ value = 0 WHERE owner_uid = '$owner_uid'");
+ }
+
+ function ccache_update_all($link, $owner_uid) {
+
+ if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid)) {
+
+ $result = db_query($link, "SELECT feed_id FROM ttrss_cat_counters_cache
+ WHERE feed_id > 0 AND owner_uid = '$owner_uid'");
+
+ while ($line = db_fetch_assoc($result)) {
+ ccache_update($link, $line["feed_id"], $owner_uid, true);
+ }
+
+ /* We have to manually include category 0 */
+
+ ccache_update($link, 0, $owner_uid, true);
+
+ } else {
+ $result = db_query($link, "SELECT feed_id FROM ttrss_counters_cache
+ WHERE feed_id > 0 AND owner_uid = '$owner_uid'");
+
+ while ($line = db_fetch_assoc($result)) {
+ print ccache_update($link, $line["feed_id"], $owner_uid);
+
+ }
+
+ }
+ }
+
+ function ccache_find($link, $feed_id, $owner_uid, $is_cat = false,
+ $no_update = false) {
+
+ if (!$is_cat) {
+ $table = "ttrss_counters_cache";
+ } else {
+ $table = "ttrss_cat_counters_cache";
+ }
+
+ if (DB_TYPE == "pgsql") {
+ $date_qpart = "updated > NOW() - INTERVAL '15 minutes'";
+ } else if (DB_TYPE == "mysql") {
+ $date_qpart = "updated > DATE_SUB(NOW(), INTERVAL 15 MINUTE)";
+ }
+
+ $result = db_query($link, "SELECT value FROM $table
+ WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id'
+ LIMIT 1");
+
+ if (db_num_rows($result) == 1) {
+ return db_fetch_result($result, 0, "value");
+ } else {
+ if ($no_update) {
+ return -1;
+ } else {
+ return ccache_update($link, $feed_id, $owner_uid, $is_cat);
+ }
+ }
+
+ }
+
+ function ccache_update($link, $feed_id, $owner_uid, $is_cat = false,
+ $update_pcat = true) {
+
+ $prev_unread = ccache_find($link, $feed_id, $owner_uid, $is_cat, true);
+
+ /* When updating a label, all we need to do is recalculate feed counters
+ * because labels are not cached */
+
+ if ($feed_id < 0) {
+ ccache_update_all($link, $owner_uid);
+ return;
+ }
+
+ if (!$is_cat) {
+ $table = "ttrss_counters_cache";
+ } else {
+ $table = "ttrss_cat_counters_cache";
+ }
+
+ if ($is_cat && $feed_id >= 0) {
+ if ($feed_id != 0) {
+ $cat_qpart = "cat_id = '$feed_id'";
+ } else {
+ $cat_qpart = "cat_id IS NULL";
+ }
+
+ /* Recalculate counters for child feeds */
+
+ $result = db_query($link, "SELECT id FROM ttrss_feeds
+ WHERE owner_uid = '$owner_uid' AND $cat_qpart");
+
+ while ($line = db_fetch_assoc($result)) {
+ ccache_update($link, $line["id"], $owner_uid, false, false);
+ }
+
+ $result = db_query($link, "SELECT SUM(value) AS sv
+ FROM ttrss_counters_cache, ttrss_feeds
+ WHERE id = feed_id AND $cat_qpart AND
+ ttrss_feeds.owner_uid = '$owner_uid'");
+
+ $unread = (int) db_fetch_result($result, 0, "sv");
+
+ } else {
+ $unread = (int) getFeedArticles($link, $feed_id, $is_cat, true, $owner_uid);
+ }
+
+ $result = db_query($link, "SELECT feed_id FROM $table
+ WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id' LIMIT 1");
+
+ if (db_num_rows($result) == 1) {
+ db_query($link, "UPDATE $table SET
+ value = '$unread', updated = NOW() WHERE
+ feed_id = '$feed_id' AND owner_uid = '$owner_uid'");
+
+ } else {
+ db_query($link, "INSERT INTO $table
+ (feed_id, value, owner_uid, updated)
+ VALUES
+ ($feed_id, $unread, $owner_uid, NOW())");
+ }
+
+ if ($feed_id > 0 && $prev_unread != $unread) {
+
+ if (!$is_cat) {
+
+ /* Update parent category */
+
+ if ($update_pcat) {
+
+ $result = db_query($link, "SELECT cat_id FROM ttrss_feeds
+ WHERE owner_uid = '$owner_uid' AND id = '$feed_id'");
+
+ $cat_id = (int) db_fetch_result($result, 0, "cat_id");
+
+ ccache_update($link, $cat_id, $owner_uid, true);
+
+ }
+ }
+ } else if ($feed_id < 0) {
+ ccache_update_all($link, $owner_uid);
+ }
+
+ return $unread;
+ }
+
+ function label_find_id($link, $label, $owner_uid) {
+ $result = db_query($link,
+ "SELECT id FROM ttrss_labels2 WHERE caption = '$label'
+ AND owner_uid = '$owner_uid' LIMIT 1");
+
+ if (db_num_rows($result) == 1) {
+ return db_fetch_result($result, 0, "id");
+ } else {
+ return 0;
+ }
+ }
+
+ function get_article_labels($link, $id) {
+ $result = db_query($link,
+ "SELECT DISTINCT label_id,caption
+ FROM ttrss_labels2, ttrss_user_labels2
+ WHERE id = label_id
+ AND article_id = '$id'
+ AND owner_uid = ".$_SESSION["uid"] . "
+ ORDER BY caption");
+
+ $rv = array();
+
+ while ($line = db_fetch_assoc($result)) {
+ $rk = array($line["label_id"], $line["caption"]);
+ array_push($rv, $rk);
+ }
+
+ return $rv;
+ }
+
+
+ function label_find_caption($link, $label, $owner_uid) {
+ $result = db_query($link,
+ "SELECT caption FROM ttrss_labels2 WHERE id = '$label'
+ AND owner_uid = '$owner_uid' LIMIT 1");
+
+ if (db_num_rows($result) == 1) {
+ return db_fetch_result($result, 0, "caption");
+ } else {
+ return "";
+ }
+ }
+
+ function label_remove_article($link, $id, $label, $owner_uid) {
+
+ $label_id = label_find_id($link, $label, $owner_uid);
+
+ if (!$label_id) return;
+
+ $result = db_query($link,
+ "DELETE FROM ttrss_user_labels2
+ WHERE
+ label_id = '$label_id' AND
+ article_id = '$id'");
+ }
+
+ function label_add_article($link, $id, $label, $owner_uid) {
+
+ $label_id = label_find_id($link, $label, $owner_uid);
+
+ if (!$label_id) return;
+
+ $result = db_query($link,
+ "SELECT
+ article_id FROM ttrss_labels2, ttrss_user_labels2
+ WHERE
+ label_id = id AND
+ label_id = '$label_id' AND
+ article_id = '$id' AND owner_uid = '$owner_uid'
+ LIMIT 1");
+
+ if (db_num_rows($result) == 0) {
+ db_query($link, "INSERT INTO ttrss_user_labels2
+ (label_id, article_id) VALUES ('$label_id', '$id')");
+ }
+ }
+
+ function label_remove($link, $id, $owner_uid) {
+
+ db_query($link, "BEGIN");
+
+ $result = db_query($link, "SELECT caption FROM ttrss_labels2
+ WHERE id = '$id'");
+
+ $caption = db_fetch_result($result, 0, "caption");
+
+ $result = db_query($link, "DELETE FROM ttrss_labels2 WHERE id = '$id'
+ AND owner_uid = " . $_SESSION["uid"]);
+
+ if (db_affected_rows($link, $result) != 0 && $caption) {
+
+ /* Disable filters that reference label being removed */
+
+ db_query($link, "UPDATE ttrss_filters SET
+ enabled = false WHERE action_param = '$caption'
+ AND action_id = 7
+ AND owner_uid = " . $_SESSION["uid"]);
+ }
+
+ db_query($link, "COMMIT");
}
?>