summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/index.php133
-rw-r--r--digest.css300
-rw-r--r--digest.js809
-rw-r--r--digest.php146
-rw-r--r--functions.php149
-rwxr-xr-ximages/digest_checkbox.pngbin0 -> 244 bytes
-rw-r--r--modules/backend-rpc.php78
7 files changed, 1485 insertions, 130 deletions
diff --git a/api/index.php b/api/index.php
index 8d69e1a73..ae4f1eb5d 100644
--- a/api/index.php
+++ b/api/index.php
@@ -100,95 +100,7 @@
$limit = (int) db_escape_string($_REQUEST["limit"]);
$offset = (int) db_escape_string($_REQUEST["offset"]);
- if ($limit) {
- $limit_qpart = "LIMIT $limit OFFSET $offset";
- } else {
- $limit_qpart = "";
- }
-
- if (!$cat_id) {
- $result = db_query($link, "SELECT
- id, feed_url, cat_id, title, ".
- SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
- FROM ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"] .
- " ORDER BY cat_id, title " . $limit_qpart);
- } else {
- $result = db_query($link, "SELECT
- id, feed_url, cat_id, title, ".
- SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
- FROM ttrss_feeds WHERE
- cat_id = '$cat_id' AND owner_uid = " . $_SESSION["uid"] .
- " ORDER BY cat_id, title " . $limit_qpart);
- }
-
- $feeds = array();
-
- while ($line = db_fetch_assoc($result)) {
-
- $unread = getFeedUnread($link, $line["id"]);
-
- $icon_path = "../" . ICONS_DIR . "/" . $line["id"] . ".ico";
- $has_icon = file_exists($icon_path) && filesize($icon_path) > 0;
-
- if ($unread || !$unread_only) {
-
- $row = array(
- "feed_url" => $line["feed_url"],
- "title" => $line["title"],
- "id" => (int)$line["id"],
- "unread" => (int)$unread,
- "has_icon" => $has_icon,
- "cat_id" => (int)$line["cat_id"],
- "last_updated" => strtotime($line["last_updated"])
- );
-
- array_push($feeds, $row);
- }
- }
-
- /* Labels */
-
- if (!$cat_id || $cat_id == -2) {
- $counters = getLabelCounters($link, true);
-
- foreach (array_keys($counters) as $id) {
-
- $unread = $counters[$id]["counter"];
-
- if ($unread || !$unread_only) {
-
- $row = array(
- "id" => $id,
- "title" => $counters[$id]["description"],
- "unread" => $counters[$id]["counter"],
- "cat_id" => -2,
- );
-
- array_push($feeds, $row);
- }
- }
- }
-
- /* Virtual feeds */
-
- if (!$cat_id || $cat_id == -1) {
- foreach (array(-1, -2, -3, -4, 0) as $i) {
- $unread = getFeedUnread($link, $i);
-
- if ($unread || !$unread_only) {
- $title = getFeedTitle($link, $i);
-
- $row = array(
- "id" => $i,
- "title" => $title,
- "unread" => $unread,
- "cat_id" => -1,
- );
- array_push($feeds, $row);
- }
-
- }
- }
+ $feeds = api_get_feeds($link, $cat_id, $unread_only, $limit, $offset);
print json_encode($feeds);
@@ -226,47 +138,8 @@
/* all_articles, unread, adaptive, marked, updated */
$view_mode = db_escape_string($_REQUEST["view_mode"]);
- /* do not rely on params below */
-
- $search = db_escape_string($_REQUEST["search"]);
- $search_mode = db_escape_string($_REQUEST["search_mode"]);
- $match_on = db_escape_string($_REQUEST["match_on"]);
-
- $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
- $view_mode, $is_cat, $search, $search_mode, $match_on,
- false, $offset);
-
- $result = $qfh_ret[0];
- $feed_title = $qfh_ret[1];
-
- $headlines = array();
-
- while ($line = db_fetch_assoc($result)) {
- $is_updated = ($line["last_read"] == "" &&
- ($line["unread"] != "t" && $line["unread"] != "1"));
-
- $headline_row = array(
- "id" => (int)$line["id"],
- "unread" => sql_bool_to_bool($line["unread"]),
- "marked" => sql_bool_to_bool($line["marked"]),
- "updated" => strtotime($line["updated"]),
- "is_updated" => $is_updated,
- "title" => $line["title"],
- "link" => $line["link"],
- "feed_id" => $line["feed_id"],
- );
-
- if ($show_excerpt) {
- $excerpt = truncate_string(strip_tags($line["content_preview"]), 100);
- $headline_row["excerpt"] = $excerpt;
- }
-
- if ($show_content) {
- $headline_row["content"] = $line["content_preview"];
- }
-
- array_push($headlines, $headline_row);
- }
+ $headlines = api_get_headlines($link, $feed_id, $limit, $offset,
+ $filter, $is_cat, $show_excerpt, $show_content, $view_mode, false);
print json_encode($headlines);
diff --git a/digest.css b/digest.css
new file mode 100644
index 000000000..2ed6aae93
--- /dev/null
+++ b/digest.css
@@ -0,0 +1,300 @@
+body {
+ background : #f0f0f0;
+ color : black;
+ font-family : sans-serif;
+ font-size : 12px;
+}
+
+a {
+ color : #0069D8;
+ text-decoration : none;
+}
+
+a:hover {
+ color : gray;
+}
+
+#header a, #footer a {
+ color : gray;
+}
+
+#header a:hover, #footer a:hover {
+ color : #0069D8;
+}
+
+#header {
+ font-weight : bold;
+ font-size : 14px;
+ font-family : "Lucida Grande", "Segoe UI", Tahoma, Arial, sans-serif;
+ margin-left : 1em;
+ margin-right : 1em;
+ color : gray;
+}
+
+#header div.links {
+ float : right;
+}
+
+#search {
+ float : right;
+ clear : left;
+
+}
+
+#content {
+ border : 1px solid #e0e0e0;
+ background : white;
+ padding : 0.8em;
+ margin : 0.5em;
+}
+
+#footer {
+ font-size : 12px;
+ text-align : center;
+ color : gray;
+}
+
+/*#content h1 {
+ font-weight : bold;
+ font-size : 25px;
+ font-family : "Lucida Grande", "Segoe UI", Tahoma, Arial, sans-serif;
+ letter-spacing : -2;
+ margin : 0px 0px 0.5em 0px;
+ color : black;
+}
+
+#content h2 {
+ font-weight : bold;
+ font-size : 20px;
+ font-family : "Lucida Grande", "Segoe UI", Tahoma, Arial, sans-serif;
+ letter-spacing : 2;
+ margin : 0px 0px 0.5em 0px;
+ color : #684C99;
+}
+
+#content h3 {
+ font-weight : bold;
+ font-size : 16px;
+ font-family : "Lucida Grande", "Segoe UI", Tahoma, Arial, sans-serif;
+ letter-spacing : 2;
+ margin : 0px 0px 0.5em 0px;
+ color : #659a4c;
+} */
+
+#content h1 {
+ margin : 0px 0px 20px 0px;
+ font-family : "Lucida Grande", "Segoe UI", Tahoma, Arial, sans-serif;
+ font-size : 18px;
+ letter-spacing : 1px;
+ color : #684C99;
+}
+
+#title {
+}
+
+#latest {
+ padding : 5px;
+}
+
+#feeds {
+ float : right;
+ width : 30%;
+ min-width : 300px;
+ padding : 5px;
+ font-size : 14px;
+}
+
+#feeds h1 {
+ text-align : right;
+}
+
+#feeds ul#feeds-content img {
+ width : 16px;
+ height : 16px;
+ vertical-align : middle;
+ margin-right : 5px;
+}
+
+#feeds ul#feeds-content div.unread-ctr img.dismiss {
+ margin-right : 0px;
+ cursor : pointer;
+}
+
+#feeds ul#feeds-content div.unread-ctr {
+ color : gray;
+ float : right;
+}
+
+#feeds ul#feeds-content li {
+ margin : 0px 0px 2px 0px;
+ padding : 2px;
+ clear : both;
+}
+
+#feeds ul#feeds-content li.selected {
+ background : #f0f0f0;
+}
+
+#feeds ul#feeds-content li.selected a {
+ color : #404040;
+}
+
+#feeds ul#feeds-content li.selected a:hover {
+ color : #659a4c;
+}
+
+#feeds ul#feeds-content {
+ list-style-type : none;
+ font-weight : bold;
+ color : #659a4c;
+ margin : 0px;
+ padding : 0px;
+}
+
+#feeds ul#feeds-content li a {
+ color : #659a4c;
+}
+
+#feeds ul#feeds-content li a:hover {
+ color : gray;
+}
+
+#headlines {
+ padding : 5px;
+ font-size : 14px;
+ max-width : 65%;
+}
+
+#headlines h1 a {
+ color : #684C99;
+}
+
+#headlines h1 a:hover {
+ color : gray;
+}
+
+#headlines h1 #headlines-title {
+ color : gray;
+}
+
+#headlines ul#headlines-content div.digest-check {
+ float : right;
+}
+
+#headlines ul#headlines-content div.digest-check img {
+ cursor : pointer;
+ margin-right : 0px;
+ margin-left : 3px;
+}
+
+
+#headlines ul#headlines-content img.icon {
+ width : 16px;
+ height : 16px;
+ vertical-align : middle;
+ margin-right : 5px;
+ float : left;
+}
+
+#headlines ul#headlines-content {
+ list-style-type : none;
+ color : gray;
+ margin : 0px;
+ padding : 0px;
+}
+
+#headlines ul#headlines-content li {
+ margin : 0px 0px 10px 0px;
+ color : #909090;
+ clear : left;
+}
+
+#headlines ul#headlines-content li.fresh a.title {
+ font-weight : bold;
+ font-size : 16px;
+ display : block;
+ padding-left : 21px;
+ color : #007FFF;
+}
+
+#headlines ul#headlines-content li.unread a.title {
+ font-weight : bold;
+ font-size : 16px;
+ display : block;
+ padding-left : 21px;
+}
+
+#headlines ul#headlines-content li.read a.title {
+ font-size : 16px;
+ font-weight : bold;
+ display : block;
+ padding-left : 21px;
+ color : #8DB1D6;
+}
+
+#headlines ul#headlines-content li.read a.title:hover {
+ color : gray;
+}
+
+#headlines ul#headlines-content img#H-LOADING-IMG {
+ margin-left : 5px;
+}
+
+#headlines ul#headlines-content div.excerpt {
+ color : #404040;
+ cursor : pointer;
+}
+
+#headlines ul#headlines-content div.content {
+ color : #404040;
+}
+
+#headlines ul#headlines-content div.content img {
+ max-width : 75%;
+}
+
+#headlines ul#headlines-content div.body {
+ margin-left : 21px;
+ /*margin-left : 42px;*/
+}
+
+#headlines ul#headlines-content div.info {
+ font-size : 11px;
+}
+
+#headlines ul#headlines-content div.info a {
+ color : gray;
+}
+
+#headlines ul#headlines-content span.tags {
+ font-size : 11px;
+ margin-bottom : 2px;
+}
+
+#headlines ul#headlines-content span.tags a {
+ color : #684C99;
+}
+
+#headlines ul#headlines-content div.info a:hover,
+#headlines ul#headlines-content span.tags a:hover {
+ color : #659a4c;
+}
+
+#overlay {
+ background : white;
+ left : 0;
+ top : 0;
+ height : 100%;
+ width : 100%;
+ z-index : 100;
+ position : absolute;
+ text-align : center;
+}
+
+#overlay_inner {
+ margin : 1em;
+}
+
+#overlay img {
+ vertical-align : middle;
+}
diff --git a/digest.js b/digest.js
new file mode 100644
index 000000000..98ae14d8c
--- /dev/null
+++ b/digest.js
@@ -0,0 +1,809 @@
+var last_feeds = [];
+var init_params = {};
+
+var db = false;
+var store = false;
+
+var _active_feed_id = false;
+var _active_feed_offset = false;
+var _update_timeout = false;
+var _view_update_timeout = false;
+var _feedlist_expanded = false;
+var _update_seq = 1;
+
+function article_appear(article_id) {
+ try {
+ new Effect.Appear('A-' + article_id);
+ } catch (e) {
+ exception_error("article_appear", e);
+ }
+}
+
+function catchup_feed(feed_id, callback) {
+ try {
+
+ var fn = find_feed(last_feeds, feed_id).title;
+
+ if (confirm(__("Mark all articles in %s as read?").replace("%s", fn))) {
+
+ var is_cat = "";
+
+ if (feed_id < 0) is_cat = "true"; // KLUDGE
+
+ var query = "?op=rpc&subop=catchupFeed&feed_id=" +
+ feed_id + "&is_cat=" + is_cat;
+
+ new Ajax.Request("backend.php", {
+ parameters: query,
+ onComplete: function(transport) {
+ if (callback) callback(transport);
+
+ update();
+ } });
+ }
+
+ } catch (e) {
+ exception_error("catchup_article", e);
+ }
+}
+
+function get_visible_article_ids() {
+ try {
+ var elems = $("headlines-content").getElementsByTagName("LI");
+ var ids = [];
+
+ for (var i = 0; i < elems.length; i++) {
+ if (elems[i].id && elems[i].id.match("A-")) {
+ ids.push(elems[i].id.replace("A-", ""));
+ }
+ }
+
+ return ids;
+
+ } catch (e) {
+ exception_error("get_visible_article_ids", e);
+ }
+}
+
+function catchup_visible_articles(callback) {
+ try {
+
+ var ids = get_visible_article_ids();
+
+ if (confirm(__("Mark %d displayed articles as read?").replace("%d", ids.length))) {
+
+ var query = "?op=rpc&subop=catchupSelected" +
+ "&cmode=0&ids=" + param_escape(ids);
+
+ new Ajax.Request("backend.php", {
+ parameters: query,
+ onComplete: function(transport) {
+ if (callback) callback(transport);
+
+ viewfeed(_active_feed_id, 0);
+ } });
+
+ }
+
+ } catch (e) {
+ exception_error("catchup_visible_articles", e);
+ }
+}
+
+function catchup_article(article_id, callback) {
+ try {
+ var query = "?op=rpc&subop=catchupSelected" +
+ "&cmode=0&ids=" + article_id;
+
+ new Ajax.Request("backend.php", {
+ parameters: query,
+ onComplete: function(transport) {
+ if (callback) callback(transport);
+ } });
+
+ } catch (e) {
+ exception_error("catchup_article", e);
+ }
+}
+
+function set_selected_feed(feed_id) {
+ try {
+ var feeds = $("feeds-content").getElementsByTagName("LI");
+
+ for (var i = 0; i < feeds.length; i++) {
+ if (feeds[i].id == "F-" + feed_id)
+ feeds[i].className = "selected";
+ else
+ feeds[i].className = "";
+ }
+
+ _active_feed_id = feed_id;
+
+ } catch (e) {
+ exception_error("mark_selected_feed", e);
+ }
+}
+
+function zoom(elem, article_id) {
+ try {
+ //alert(elem + "/" + article_id);
+
+ elem.innerHTML = "<img src='images/indicator_tiny.gif'> " +
+ __("Loading, please wait...");
+
+ new Ajax.Request("backend.php", {
+ parameters: "?op=rpc&subop=digest-get-contents&article_id=" +
+ article_id,
+ onComplete: function(transport) {
+ fatal_error_check(transport);
+
+ if (transport.responseXML) {
+ var article = transport.responseXML.getElementsByTagName('article')[0];
+ elem.innerHTML = article.firstChild.nodeValue;
+
+ new Effect.BlindDown(elem, {duration : 0.5});
+
+ elem.onclick = false;
+ elem.style.cursor = "auto";
+
+ catchup_article(article_id,
+ function() {
+ window.clearTimeout(_view_update_timeout);
+ _view_update_timeout = window.setTimeout("view_update()", 500);
+ $("A-" + article_id).className = "read";
+ });
+
+
+ } else {
+ elem.innerHTML = __("Error: unable to load article.");
+ }
+
+ } });
+
+
+ } catch (e) {
+ exception_error("zoom", e);
+ }
+}
+
+function load_more() {
+ try {
+ var pr = $("H-LOADING-IMG");
+
+ if (pr) Element.show(pr);
+
+ viewfeed(_active_feed_id, _active_feed_offset + 10, false, false, true,
+ function() {
+ var pr = $("H-LOADING-IMG");
+
+ if (pr) Element.hide(pr);
+ });
+ } catch (e) {
+ exception_error("load_more", e);
+ }
+}
+
+function update(callback) {
+ try {
+ console.log('updating feeds...');
+
+ window.clearTimeout(_update_timeout);
+
+ new Ajax.Request("backend.php", {
+ parameters: "?op=rpc&subop=digest-init",
+ onComplete: function(transport) {
+ fatal_error_check(transport);
+ parse_feeds(transport);
+ set_selected_feed(_active_feed_id);
+
+ if (callback) callback(transport);
+ } });
+
+ _update_timeout = window.setTimeout('update()', 5*1000);
+ } catch (e) {
+ exception_error("update", e);
+ }
+}
+
+function remove_headline_entry(article_id) {
+ try {
+ var elem = $('A-' + article_id);
+
+ if (elem) {
+ elem.parentNode.removeChild(elem);
+ }
+
+ } catch (e) {
+ exception_error("remove_headline_entry", e);
+ }
+}
+
+function view_update() {
+ try {
+ viewfeed(_active_feed_id, _active_feed_offset, false, true, true);
+ update();
+ } catch (e) {
+ exception_error("view_update", e);
+ }
+}
+
+function view(article_id, dismiss_only) {
+ try {
+ remove_headline_entry(article_id);
+
+ catchup_article(article_id,
+ function() {
+ window.clearTimeout(_view_update_timeout);
+ _view_update_timeout = window.setTimeout("view_update()", 500);
+ });
+
+ return dismiss_only != true;
+ } catch (e) {
+ exception_error("view", e);
+ }
+}
+
+function viewfeed(feed_id, offset, replace, no_effects, no_indicator, callback) {
+ try {
+
+ if (!feed_id) feed_id = _active_feed_id;
+
+ if (!offset) {
+ offset = 0;
+ } else {
+ offset = _active_feed_offset + offset;
+ }
+
+ if (replace == undefined) replace = (offset == 0);
+
+ _update_seq = _update_seq + 1;
+
+ var query = "backend.php?op=rpc&subop=digest-update&feed_id=" +
+ param_escape(feed_id) + "&offset=" + offset +
+ "&seq=" + _update_seq;
+
+ console.log(query);
+
+ if ($("F-" + feed_id)) {
+ var img = $("F-" + feed_id).getElementsByTagName("IMG")[0];
+
+ if (img && !no_indicator) {
+ img.setAttribute("orig_src", img.src);
+ img.src = 'images/indicator_tiny.gif';
+ }
+ }
+
+ new Ajax.Request("backend.php", {
+ parameters: query,
+ onComplete: function(transport) {
+ Element.hide("overlay");
+
+ fatal_error_check(transport);
+ parse_headlines(transport, replace, no_effects);
+ set_selected_feed(feed_id);
+ _active_feed_offset = offset;
+
+ if (img && !no_indicator)
+ img.src = img.getAttribute("orig_src");
+
+ if (callback) callback(transport);
+
+ } });
+
+ } catch (e) {
+ exception_error("view", e);
+ }
+}
+
+function find_article(articles, article_id) {
+ try {
+ for (var i = 0; i < articles.length; i++) {
+ if (articles[i].id == article_id)
+ return articles[i];
+ }
+
+ return false;
+
+ } catch (e) {
+ exception_error("find_article", e);
+ }
+}
+
+function find_feed(feeds, feed_id) {
+ try {
+ for (var i = 0; i < feeds.length; i++) {
+ if (feeds[i].id == feed_id)
+ return feeds[i];
+ }
+
+ return false;
+
+ } catch (e) {
+ exception_error("find_feed", e);
+ }
+}
+
+function get_feed_icon(feed) {
+ try {
+ if (feed.has_icon)
+ return getInitParam('icons_location') + "/" + feed.id + '.ico';
+
+ if (feed.id == -1)
+ return 'images/mark_set.png';
+
+ if (feed.id == -2)
+ return 'images/pub_set.png';
+
+ if (feed.id == -3)
+ return 'images/fresh.png';
+
+ if (feed.id == -4)
+ return 'images/tag.png';
+
+ if (feed.id < -10)
+ return 'images/label.png';
+
+ return 'images/blank_icon.gif';
+
+ } catch (e) {
+ exception_error("get_feed_icon", e);
+ }
+}
+
+function add_feed_entry(feed) {
+ try {
+ var icon_part = "";
+
+ icon_part = "<img src='" + get_feed_icon(feed) + "'/>";
+
+ var tmp_html = "<li id=\"F-"+feed.id+"\" " +
+ "onmouseover=\"feed_mi(this)\" onmouseout=\"feed_mo(this)\">" +
+ icon_part +
+ "<a href=\"#\" onclick=\"viewfeed("+feed.id+")\">" + feed.title + "</a>" +
+ "<div class='unread-ctr'>" +
+ "<img onclick=\"catchup_feed("+feed.id+")\" title=\"" +
+ __("Mark as read") +
+ "\" class=\"dismiss\" style='display : none' src=\"images/digest_checkbox.png\">" +
+ "<span class=\"unread\">" + feed.unread + "</span>" +
+ "</div>" +
+ "</li>";
+
+ $("feeds-content").innerHTML += tmp_html;
+
+ } catch (e) {
+ exception_error("add_feed_entry", e);
+ }
+}
+
+function add_headline_entry(article, feed, no_effects) {
+ try {
+
+ var icon_part = "";
+
+ icon_part = "<img class='icon' src='" + get_feed_icon(feed) + "'/>";
+
+ var mark_part = "";
+ var publ_part = "";
+
+ var tags_part = "";
+
+ if (article.tags.length > 0) {
+
+ tags_part = " " + __("in") + " ";
+
+ for (var i = 0; i < Math.min(5, article.tags.length); i++) {
+ tags_part += "<a href=\"#\" onclick=\"viewfeed('" +
+ article.tags[i] + "')\">" +
+ article.tags[i] + "</a>, ";
+ }
+
+ tags_part = tags_part.replace(/, $/, "");
+ tags_part = "<span class=\"tags\">" + tags_part + "</span>";
+ }
+
+ if (article.marked)
+ mark_part = "<img title='"+ __("Unstar article")+"' onclick=\"toggle_mark(this, "+article.id+")\" src='images/mark_set.png'>";
+ else
+ mark_part = "<img title='"+__("Star article")+"' onclick=\"toggle_mark(this, "+article.id+")\" src='images/mark_unset.png'>";
+
+ if (article.published)
+ publ_part = "<img title='"+__("Unpublish article")+"' onclick=\"toggle_pub(this, "+article.id+")\" src='images/pub_set.png'>";
+ else
+ publ_part = "<img title='"+__("Publish article")+"' onclick=\"toggle_pub(this, "+article.id+")\" src='images/pub_unset.png'>";
+
+ var style = "";
+
+ if (!no_effects) style = "style=\"display : none\"";
+
+ if (article.excerpt.trim() == "")
+ article.excerpt = __("Click to expand article.");
+
+ var li_class = "unread";
+
+ var fresh_max = getInitParam("fresh_article_max_age") * 60 * 60;
+ var d = new Date();
+
+ if (d.getTime() / 1000 - article.updated < fresh_max)
+ li_class = "fresh";
+
+ var tmp_html = "<li id=\"A-"+article.id+"\" "+style+" class=\""+li_class+"\">" +
+ icon_part +
+
+ "<div class='digest-check'>" +
+ mark_part +
+ publ_part +
+ "<img title='" + __("Mark as read") + "' onclick=\"view("+article.id+", true)\" src='images/digest_checkbox.png'>" +
+ "</div>" +
+ "<a target=\"_blank\" href=\""+article.link+"\""+
+ "onclick=\"return view("+article.id+")\" class='title'>" +
+ article.title + "</a>" +
+ "<div class='body'>" +
+ "<div title=\""+__("Click to expand article")+"\" onclick=\"zoom(this, "+article.id+")\" class='excerpt'>" +
+ article.excerpt + "</div>" +
+ "<div class='info'><a href=\#\" onclick=\"viewfeed("+feed.id+")\">" +
+ feed.title + "</a> " + tags_part + " @ " +
+ new Date(article.updated * 1000) + "</div>" +
+ "</div></li>";
+
+ $("headlines-content").innerHTML += tmp_html;
+
+ if (!no_effects)
+ window.setTimeout('article_appear(' + article.id + ')', 100);
+
+ } catch (e) {
+ exception_error("add_headline_entry", e);
+ }
+}
+
+function expand_feeds() {
+ try {
+ _feedlist_expanded = true;
+
+ redraw_feedlist(last_feeds);
+
+ } catch (e) {
+ exception_error("expand_feeds", e);
+ }
+}
+
+function redraw_feedlist(feeds) {
+ try {
+
+ $('feeds-content').innerHTML = "";
+
+ var limit = 10;
+
+ if (_feedlist_expanded) limit = feeds.length;
+
+ for (var i = 0; i < Math.min(limit, feeds.length); i++) {
+ add_feed_entry(feeds[i]);
+ }
+
+ if (feeds.length > limit) {
+ $('feeds-content').innerHTML += "<li id='F-MORE-PROMPT'>" +
+ "<img src='images/blank_icon.gif'>" +
+ "<a href=\"#\" onclick=\"expand_feeds()\">" +
+ __("%d more...").replace("%d", feeds.length-10) +
+ "</a>" + "</li>";
+ }
+
+ } catch (e) {
+ exception_error("redraw_feedlist", e);
+ }
+}
+
+function parse_feeds(transport) {
+ try {
+
+ if (!transport.responseXML) return;
+
+ var feeds = transport.responseXML.getElementsByTagName('feeds')[0];
+
+ if (feeds) {
+ feeds = eval("(" + feeds.firstChild.nodeValue + ")");
+
+ feeds.sort( function (a,b)
+ {
+ if (b.unread != a.unread)
+ return (b.unread - a.unread)
+ else
+ if (a.title > b.title)
+ return 1;
+ else if (a.title < b.title)
+ return -1;
+ else
+ return 0;
+ });
+
+ var all_articles = find_feed(feeds, -4);
+
+ update_title(all_articles.unread);
+
+ last_feeds = feeds;
+
+ redraw_feedlist(feeds);
+ }
+
+ } catch (e) {
+ exception_error("parse_feeds", e);
+ }
+}
+
+function parse_headlines(transport, replace, no_effects) {
+ try {
+ if (!transport.responseXML) return;
+
+ var seq = transport.responseXML.getElementsByTagName('seq')[0];
+
+ if (seq) {
+ seq = seq.firstChild.nodeValue;
+ if (seq != _update_seq) {
+ console.log("parse_headlines: wrong sequence received.");
+ return;
+ }
+ } else {
+ return;
+ }
+
+ var headlines = transport.responseXML.getElementsByTagName('headlines')[0];
+ var headlines_title = transport.responseXML.getElementsByTagName('headlines-title')[0];
+
+ if (headlines && headlines_title) {
+ headlines = eval("(" + headlines.firstChild.nodeValue + ")");
+
+ var title = headlines_title.firstChild.nodeValue;
+
+ $("headlines-title").innerHTML = title;
+
+ if (replace) {
+ $('headlines-content').innerHTML = '';
+ Element.hide('headlines-content');
+ }
+
+ var pr = $('H-MORE-PROMPT');
+
+ if (pr) pr.parentNode.removeChild(pr);
+
+ var inserted = false;
+
+ for (var i = 0; i < headlines.length; i++) {
+
+ if (!$('A-' + headlines[i].id)) {
+ add_headline_entry(headlines[i],
+ find_feed(last_feeds, headlines[i].feed_id), !no_effects);
+
+ inserted = $("A-" + headlines[i].id);
+ }
+ }
+
+ var ids = get_visible_article_ids();
+
+ if (ids.length > 0) {
+ if (pr) {
+ $('headlines-content').appendChild(pr);
+ if (!no_effects) new Effect.ScrollTo(inserted);
+ } else {
+ $('headlines-content').innerHTML += "<li id='H-MORE-PROMPT'>" +
+ "<div class='body'>" +
+ "<a href=\"javascript:catchup_visible_articles()\">" +
+ __("Mark as read") + "</a> | " +
+ "<a href=\"javascript:load_more()\">" +
+ __("Load more...") + "</a>" +
+ "<img style=\"display : none\" "+
+ "id=\"H-LOADING-IMG\" src='images/indicator_tiny.gif'>" +
+ "</div></li>";
+ }
+ } else {
+ // FIXME : display some kind of "nothing to see here" prompt here
+ }
+
+ if (replace && !no_effects)
+ new Effect.Appear('headlines-content', {duration : 0.3});
+
+ //new Effect.Appear('headlines-content');
+ }
+
+ } catch (e) {
+ exception_error("parse_headlines", e);
+ }
+}
+
+function init_second_stage() {
+ try {
+ new Ajax.Request("backend.php", {
+ parameters: "backend.php?op=rpc&subop=digest-init",
+ onComplete: function(transport) {
+ parse_feeds(transport);
+ window.setTimeout('viewfeed(-4)', 100);
+ _update_timeout = window.setTimeout('update()', 5*1000);
+ } });
+
+ } catch (e) {
+ exception_error("init_second_stage", e);
+ }
+}
+
+function init() {
+ try {
+
+ new Ajax.Request("backend.php", {
+ parameters: "?op=rpc&subop=sanityCheck",
+ onComplete: function(transport) {
+ backend_sanity_check_callback(transport);
+ } });
+
+ } catch (e) {
+ exception_error("digest_init", e);
+ }
+}
+
+function toggle_mark(mark_img, id) {
+
+ try {
+
+ var query = "?op=rpc&id=" + id + "&subop=mark";
+
+ query = query + "&afid=" + _active_feed_id;
+ query = query + "&omode=c";
+
+ if (!mark_img) return;
+
+ if (mark_img.src.match("mark_unset")) {
+ mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
+ mark_img.alt = __("Unstar article");
+ query = query + "&mark=1";
+ } else {
+ mark_img.alt = __("Please wait...");
+ query = query + "&mark=0";
+
+ mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
+ mark_img.alt = __("Star article");
+ }
+
+ new Ajax.Request("backend.php", {
+ parameters: query,
+ onComplete: function(transport) {
+ update();
+ } });
+
+ } catch (e) {
+ exception_error("toggle_mark", e);
+ }
+}
+
+function toggle_pub(mark_img, id, note) {
+
+ try {
+
+ var query = "?op=rpc&id=" + id + "&subop=publ";
+
+ query = query + "&afid=" + _active_feed_id;
+
+ if (note != undefined) {
+ query = query + "&note=" + param_escape(note);
+ } else {
+ query = query + "&note=undefined";
+ }
+
+ query = query + "&omode=c";
+
+ if (!mark_img) return;
+
+ if (mark_img.src.match("pub_unset") || note != undefined) {
+ mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
+ mark_img.alt = __("Unpublish article");
+ query = query + "&pub=1";
+
+ } else {
+ mark_img.alt = __("Please wait...");
+ query = query + "&pub=0";
+
+ mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
+ mark_img.alt = __("Publish article");
+ }
+
+ new Ajax.Request("backend.php", {
+ parameters: query,
+ onComplete: function(transport) {
+ update();
+ } });
+
+ } catch (e) {
+ exception_error("toggle_pub", e);
+ }
+}
+
+function fatal_error(code, msg) {
+ try {
+
+ if (code == 6) {
+ window.location.href = "digest.php";
+ } else if (code == 5) {
+ window.location.href = "update.php";
+ } else {
+
+ if (msg == "") msg = "Unknown error";
+
+ console.error("Fatal error: " + code + "\n" +
+ msg);
+
+ }
+
+ } catch (e) {
+ exception_error("fatalError", e);
+ }
+}
+
+function fatal_error_check(transport) {
+ try {
+ if (transport.responseXML) {
+ var error = transport.responseXML.getElementsByTagName("error")[0];
+
+ if (error) {
+ var code = error.getAttribute("error-code");
+ var msg = error.getAttribute("error-msg");
+ if (code != 0) {
+ fatal_error(code, msg);
+ return false;
+ }
+ }
+ }
+ } catch (e) {
+ exception_error("fatal_error_check", e);
+ }
+ return true;
+}
+
+function feed_mi(elem) {
+ try {
+ var imgs = elem.getElementsByTagName('IMG');
+ var spans = elem.getElementsByTagName('SPAN');
+
+ for (var i = 0; i < imgs.length; i++) {
+ if (imgs[i].className == "dismiss")
+ Element.show(imgs[i]);
+ }
+
+ for (var i = 0; i < spans.length; i++) {
+ if (spans[i].className == "unread")
+ Element.hide(spans[i]);
+ }
+
+
+ } catch (e) {
+ exception_error("feed_mi", e);
+ }
+}
+
+function feed_mo(elem) {
+ try {
+ var imgs = elem.getElementsByTagName('IMG');
+ var spans = elem.getElementsByTagName('SPAN');
+
+ for (var i = 0; i < imgs.length; i++) {
+ if (imgs[i].className == "dismiss")
+ Element.hide(imgs[i]);
+ }
+
+ for (var i = 0; i < spans.length; i++) {
+ if (spans[i].className == "unread")
+ Element.show(spans[i]);
+ }
+
+ } catch (e) {
+ exception_error("feed_mo", e);
+ }
+}
+
+function update_title(unread) {
+ try {
+ document.title = "Tiny Tiny RSS";
+
+ if (unread > 0)
+ document.title += " (" + unread + ")";
+
+ } catch (e) {
+ exception_error("update_title", e);
+ }
+}
+
diff --git a/digest.php b/digest.php
new file mode 100644
index 000000000..c2ff2a330
--- /dev/null
+++ b/digest.php
@@ -0,0 +1,146 @@
+<?php
+ error_reporting(E_ERROR | E_WARNING | E_PARSE);
+
+ require_once "functions.php";
+ require_once "sessions.php";
+ require_once "sanity_check.php";
+ require_once "version.php";
+ require_once "config.php";
+ require_once "db-prefs.php";
+
+ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+
+ login_sequence($link);
+
+ $dt_add = get_script_dt_add();
+
+ no_cache_incantation();
+
+ header('Content-Type: text/html; charset=utf-8');
+
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+ <title>Tiny Tiny RSS</title>
+ <link rel="stylesheet" type="text/css" href="digest.css?<?php echo $dt_add ?>"/>
+ <link rel="stylesheet" type="text/css" href="infobox.css?<?php echo $dt_add ?>"/>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+ <?php $user_css_url = get_pref($link, 'USER_STYLESHEET_URL'); ?>
+ <?php if ($user_css_url) { ?>
+ <link rel="stylesheet" type="text/css" href="<?php echo $user_css_url ?>"/>
+ <?php } ?>
+
+ <link rel="shortcut icon" type="image/png" href="images/favicon.png"/>
+
+ <script type="text/javascript" src="lib/prototype.js"></script>
+ <script type="text/javascript" src="lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls"></script>
+ <script type="text/javascript" charset="utf-8" src="localized_js.php?<?php echo $dt_add ?>"></script>
+ <script type="text/javascript" charset="utf-8" src="functions.js?<?php echo $dt_add ?>"></script>
+
+ <script type="text/javascript" src="digest.js"></script>
+
+ <script type="text/javascript">
+ Event.observe(window, 'load', function() {
+ init();
+ });
+ </script>
+</head>
+<body id="ttrssDigest">
+ <div id="overlay" style="display : block">
+ <div id="overlay_inner">
+ <noscript>
+ <p>
+ <?php print_error(__("Your browser doesn't support Javascript, which is required
+ for this application to function properly. Please check your
+ browser settings.")) ?></p>
+ </noscript>
+
+ <img src="images/indicator_white.gif"/>
+ <?php echo __("Loading, please wait...") ?>
+ </div>
+ </div>
+
+ <div id="dialog_overlay" style="display : none"> </div>
+
+ <div id="errorBoxShadow" style="display : none">
+ <div id="errorBox">
+ <div id="xebTitle"><?php echo __('Fatal Exception') ?></div><div id="xebContent">&nbsp;</div>
+ <div id="xebBtn" align='center'>
+ <button onclick="closeErrorBox()"><?php echo __('Close this window') ?></button>
+ </div>
+ </div>
+ </div>
+
+ <div id="header">
+
+ <div class="links">
+
+ <?php if (!SINGLE_USER_MODE) { ?>
+ <?php echo __('Hello,') ?> <b><?php echo $_SESSION["name"] ?></b> |
+ <?php } ?>
+
+ <?php if (!SINGLE_USER_MODE) { ?>
+ <a href="logout.php"><?php echo __('Logout') ?></a>
+ <?php } ?>
+
+ </div>
+
+ <?php echo __('Tiny Tiny RSS') ?>
+
+ </div>
+ <div id="content">
+ <!-- <div id="title">
+ <div id="search">
+ <input name="search" type="search"></input>
+ <button>Search</button>
+ </div>
+
+ </div>
+
+ <div id="latest">
+ <h1>latest articles</h1>
+
+ <em>TODO</em>
+
+ <div id="latest-content"> </div>
+ </div> -->
+
+ <div id="feeds">
+ <h1><?php echo __('feeds') ?></h1>
+
+ <ul id="feeds-content"> </ul>
+ </div>
+
+ <div id="headlines">
+ <h1><a href="#" onclick="viewfeed(-4)"><?php echo __('headlines') ?></a>:
+ <span id="headlines-title"></span></h1>
+
+ <ul id="headlines-content"> </ul>
+ </div>
+
+ <br clear="both">
+
+ </div>
+
+ <div id="footer">
+
+ <a href="http://tt-rss.org/">Tiny Tiny RSS</a>
+ <?php if (!defined('HIDE_VERSION')) { ?>
+ v<?php echo VERSION ?>
+ <?php } ?>
+ &copy; 2005&ndash;<?php echo date('Y') ?>
+ <a href="http://fakecake.org/">Andrew Dolgov</a>
+
+ <br/>
+
+ <a href="tt-rss.php">
+ <?php echo __("You are viewing the digest page. Click to open full version.") ?></a>
+
+</div>
+
+</body>
diff --git a/functions.php b/functions.php
index 527e78f85..d628ec743 100644
--- a/functions.php
+++ b/functions.php
@@ -3175,6 +3175,9 @@
print "<param key=\"cdm_auto_catchup\" value=\"" .
(int) get_pref($link, "CDM_AUTO_CATCHUP") . "\"/>";
+ print "<param key=\"fresh_article_max_age\" value=\"" .
+ (int) get_pref($link, "FRESH_ARTICLE_MAX_AGE") . "\"/>";
+
print "<param key=\"icons_url\" value=\"" . ICONS_URL . "\"/>";
print "<param key=\"cookie_lifetime\" value=\"" . SESSION_COOKIE_LIFETIME . "\"/>";
@@ -6658,4 +6661,150 @@
return $rv;
}
+ function api_get_feeds($link, $cat_id, $unread_only, $limit, $offset) {
+
+ $feeds = array();
+
+ /* Labels */
+
+ if (!$cat_id || $cat_id == -2) {
+ $counters = getLabelCounters($link, true);
+
+ foreach (array_keys($counters) as $id) {
+
+ $unread = $counters[$id]["counter"];
+
+ if ($unread || !$unread_only) {
+
+ $row = array(
+ "id" => $id,
+ "title" => $counters[$id]["description"],
+ "unread" => $counters[$id]["counter"],
+ "cat_id" => -2,
+ );
+
+ array_push($feeds, $row);
+ }
+ }
+ }
+
+ /* Virtual feeds */
+
+ if (!$cat_id || $cat_id == -1) {
+ foreach (array(-1, -2, -3, -4, 0) as $i) {
+ $unread = getFeedUnread($link, $i);
+
+ if ($unread || !$unread_only) {
+ $title = getFeedTitle($link, $i);
+
+ $row = array(
+ "id" => $i,
+ "title" => $title,
+ "unread" => $unread,
+ "cat_id" => -1,
+ );
+ array_push($feeds, $row);
+ }
+
+ }
+ }
+
+ /* Real feeds */
+
+ if ($limit) {
+ $limit_qpart = "LIMIT $limit OFFSET $offset";
+ } else {
+ $limit_qpart = "";
+ }
+
+ if (!$cat_id) {
+ $result = db_query($link, "SELECT
+ id, feed_url, cat_id, title, ".
+ SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
+ FROM ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"] .
+ " ORDER BY cat_id, title " . $limit_qpart);
+ } else {
+ $result = db_query($link, "SELECT
+ id, feed_url, cat_id, title, ".
+ SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
+ FROM ttrss_feeds WHERE
+ cat_id = '$cat_id' AND owner_uid = " . $_SESSION["uid"] .
+ " ORDER BY cat_id, title " . $limit_qpart);
+ }
+
+ while ($line = db_fetch_assoc($result)) {
+
+ $unread = getFeedUnread($link, $line["id"]);
+
+ $has_icon = feed_has_icon($line['id']);
+
+ if ($unread || !$unread_only) {
+
+ $row = array(
+ "feed_url" => $line["feed_url"],
+ "title" => $line["title"],
+ "id" => (int)$line["id"],
+ "unread" => (int)$unread,
+ "has_icon" => $has_icon,
+ "cat_id" => (int)$line["cat_id"],
+ "last_updated" => strtotime($line["last_updated"])
+ );
+
+ array_push($feeds, $row);
+ }
+ }
+
+ return $feeds;
+ }
+
+ function api_get_headlines($link, $feed_id, $limit, $offset,
+ $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order) {
+
+ /* do not rely on params below */
+
+ $search = db_escape_string($_REQUEST["search"]);
+ $search_mode = db_escape_string($_REQUEST["search_mode"]);
+ $match_on = db_escape_string($_REQUEST["match_on"]);
+
+ $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
+ $view_mode, $is_cat, $search, $search_mode, $match_on,
+ $order, $offset);
+
+ $result = $qfh_ret[0];
+ $feed_title = $qfh_ret[1];
+
+ $headlines = array();
+
+ while ($line = db_fetch_assoc($result)) {
+ $is_updated = ($line["last_read"] == "" &&
+ ($line["unread"] != "t" && $line["unread"] != "1"));
+
+ $headline_row = array(
+ "id" => (int)$line["id"],
+ "unread" => sql_bool_to_bool($line["unread"]),
+ "marked" => sql_bool_to_bool($line["marked"]),
+ "published" => sql_bool_to_bool($line["published"]),
+ "updated" => strtotime($line["updated"]),
+ "is_updated" => $is_updated,
+ "title" => $line["title"],
+ "link" => $line["link"],
+ "feed_id" => $line["feed_id"],
+ "tags" => get_article_tags($link, $line["id"]),
+ );
+
+ if ($show_excerpt) {
+ $excerpt = truncate_string(strip_tags($line["content_preview"]), 100);
+ $headline_row["excerpt"] = $excerpt;
+ }
+
+ if ($show_content) {
+ $headline_row["content"] = $line["content_preview"];
+ }
+
+ array_push($headlines, $headline_row);
+ }
+
+ return $headlines;
+ }
+
?>
diff --git a/images/digest_checkbox.png b/images/digest_checkbox.png
new file mode 100755
index 000000000..c5e4b98ea
--- /dev/null
+++ b/images/digest_checkbox.png
Binary files differ
diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php
index b21e161e4..aa05e8e8e 100644
--- a/modules/backend-rpc.php
+++ b/modules/backend-rpc.php
@@ -978,6 +978,84 @@
return;
}
+ if ($subop == "digest-get-contents") {
+ $article_id = db_escape_string($_REQUEST['article_id']);
+
+ $result = db_query($link, "SELECT content
+ FROM ttrss_entries, ttrss_user_entries
+ WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']);
+
+ print "<rpc-reply>";
+
+ print "<article id=\"$article_id\"><![CDATA[";
+
+ $content = sanitize_rss($link, db_fetch_result($result, 0, "content"));
+
+ print $content;
+
+ print "]]></article>";
+
+ print "</rpc-reply>";
+
+ return;
+ }
+
+ if ($subop == "digest-update") {
+ $feed_id = db_escape_string($_REQUEST['feed_id']);
+ $offset = db_escape_string($_REQUEST['offset']);
+ $seq = db_escape_string($_REQUEST['seq']);
+
+ if (!$feed_id) $feed_id = -4;
+ if (!$offset) $offset = 0;
+ print "<rpc-reply>";
+
+ print "<seq>$seq</seq>";
+
+ $headlines = api_get_headlines($link, $feed_id, 10, $offset,
+ '', ($feed_id == -4), true, false, "unread", "updated DESC");
+
+ //function api_get_headlines($link, $feed_id, $limit, $offset,
+ // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) {
+
+ print "<headlines-title><![CDATA[" . getFeedTitle($link, $feed_id) .
+ "]]></headlines-title>";
+
+ print "<headlines><![CDATA[" . json_encode($headlines) . "]]></headlines>";
+
+ print "</rpc-reply>";
+ return;
+ }
+
+ if ($subop == "digest-init") {
+ print "<rpc-reply>";
+
+ $tmp_feeds = api_get_feeds($link, false, true, false, 0);
+ $feeds = array();
+
+ foreach ($tmp_feeds as $f) {
+ if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f);
+ }
+
+ print "<feeds><![CDATA[" . json_encode($feeds) . "]]></feeds>";
+
+ print "</rpc-reply>";
+ return;
+ }
+
+ if ($subop == "catchupFeed") {
+
+ $feed_id = db_escape_string($_REQUEST['feed_id']);
+ $is_cat = db_escape_string($_REQUEST['is_cat']);
+
+ print "<rpc-reply>";
+
+ catchup_feed($link, $feed_id, $is_cat);
+
+ print "</rpc-reply>";
+
+ return;
+ }
+
print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";
}
?>