diff options
-rw-r--r-- | api/index.php | 133 | ||||
-rw-r--r-- | digest.css | 223 | ||||
-rw-r--r-- | digest.js | 433 | ||||
-rw-r--r-- | digest.php | 112 | ||||
-rw-r--r-- | functions.php | 145 | ||||
-rwxr-xr-x | images/digest_checkbox.png | bin | 0 -> 244 bytes | |||
-rw-r--r-- | modules/backend-rpc.php | 51 |
7 files changed, 967 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..b94044f98 --- /dev/null +++ b/digest.css @@ -0,0 +1,223 @@ +body { + background : #f0f0f0; + color : gray; + font-family : sans-serif; + font-size : 12px; +} + +a { + color : #0069D8; + text-decoration : none; +} + +a:hover { + color : gray; +} + +#header a, #footer a { + color : gray; +} + +#header { + font-weight : bold; + font-size : 14px; + font-family : "Lucida Grande", "Segoe UI", Tahoma, Arial, sans-serif; + margin-left : 1em; + margin-right : 1em; +} + +#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; +} + +/*#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 { + color : gray; + float : right; +} + +#feeds ul#feeds-content li { + margin : 0px 0px 2px 0px; + padding : 2px; +} + +#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 ul#headlines-content img.digest-check { + cursor : pointer; +} + +#headlines ul#headlines-content div.digest-check { + float : right; +} + +#headlines ul#headlines-content img.icon { + width : 16px; + height : 16px; + vertical-align : middle; + margin-right : 5px; +} + +#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:hover { + background : #fafafa; +} + +#headlines ul#headlines-content a.title { + font-weight : bold; + font-size : 16px; +} + +#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 { + margin-top : 2px; + font-size : 11px; +} + +#headlines ul#headlines-content div.info a { + color : gray; + font-weight : bold; +} + +#headlines ul#headlines-content div.info a:hover { + color : #659a4c; +} diff --git a/digest.js b/digest.js new file mode 100644 index 000000000..0e567193f --- /dev/null +++ b/digest.js @@ -0,0 +1,433 @@ +var last_feeds = []; + +var _active_feed_id = false; +var _active_feed_offset = false; +var _update_timeout = false; + +function mark_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 = ""; + } + + } catch (e) { + exception_error("mark_selected_feed", e); + } +} + +function zoom(article_id) { + try { + var elem = $('A-' + article_id); + + if (elem) { + var divs = elem.getElementsByTagName('DIV'); + + for (var i = 0; i < divs.length; i++) { + if (divs[i].className == 'excerpt') + Element.hide(divs[i]); + + if (divs[i].className == 'content') + Element.show(divs[i]); + } + } + + var query = "backend.php?op=rpc&subop=digest-mark&article_id=" + article_id; + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + window.clearTimeout(_update_timeout); + _update_timeout = window.setTimeout('update()', 1000); + } }); + + } catch (e) { + exception_error("zoom", e); + } +} + +function load_more() { + try { + var elem = $('MORE-PROMPT'); + + if (elem) { + elem.id = ''; + Element.hide(elem); + } + + viewfeed(_active_feed_id, _active_feed_offset + 10); + } catch (e) { + exception_error("load_more", e); + } +} + +function update() { + try { + viewfeed(_active_feed_id, _active_feed_offset); + } catch (e) { + exception_error("update", e); + } +} + +function view(article_id, dismiss_only) { + try { + var elem = $('A-' + article_id); + + elem.id = ''; + + //new Effect.Fade(elem, {duration : 0.3}); + + Element.hide(elem); + + var query = "backend.php?op=rpc&subop=digest-mark&article_id=" + article_id; + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + window.clearTimeout(_update_timeout); + _update_timeout = window.setTimeout('update()', 1000); + } }); + + return dismiss_only != true; + } catch (e) { + exception_error("view", e); + } +} + +function viewfeed(feed_id, offset) { + try { + + if (!feed_id) feed_id = _active_feed_id; + + if (!offset) + offset = 0; + else + offset = _active_feed_offset + offset; + + var query = "backend.php?op=rpc&subop=digest-update&feed_id=" + feed_id + + "&offset=" + offset; + + console.log(query); + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + digest_update(transport, feed_id); + _active_feed_id = feed_id; + _active_feed_offset = offset; + mark_selected_feed(feed_id); + } }); + + } 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 'icons/' + 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'; + + } 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+"\">" + + icon_part + + "<a href=\"#\" onclick=\"viewfeed("+feed.id+")\">" + feed.title + + "<div class='unread-ctr'>" + feed.unread + "</div>" + + "</li>"; + + $("feeds-content").innerHTML += tmp_html; + + } catch (e) { + exception_error("add_feed_entry", e); + } +} + +function add_latest_entry(article, feed) { + try { + + + //$("latest-content").innerHTML += "bbb"; + + } catch (e) { + exception_error("add_latest_entry", e); + } +} + +function add_headline_entry(article, feed) { + try { + + var icon_part = ""; + + if (article.has_icon) + icon_part = "<img class='icon' src='icons/" + article.feed_id + ".ico'/>"; + + var tmp_html = "<li id=\"A-"+article.id+"\">" + + icon_part + + "<div class='digest-check'>" + + "<img title='Set starred' onclick=\"toggleMark(this, "+article.id+")\" src='images/mark_unset.png'>" + + "<img title='Set published' onclick=\"togglePub(this, "+article.id+")\" src='images/pub_unset.png'>" + + "<img title='Dismiss' onclick=\"view("+article.id+", true)\" class='digest-check' 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("+article.id+")\" class='excerpt'>" + + article.excerpt + "</div>" + + "<div style='display : none' class='content'>" + + article.content + "</div>" + + "<div class='info'><a href=\#\" onclick=\"viewfeed("+feed.id+")\">" + + feed.title + "</a> " + " @ " + + new Date(article.updated * 1000) + "</div>" + + "</div></li>"; + + $("headlines-content").innerHTML += tmp_html; + + } catch (e) { + exception_error("add_headline_entry", e); + } +} + +function digest_update(transport, feed_id) { + try { + var feeds = transport.responseXML.getElementsByTagName('feeds')[0]; + var headlines = transport.responseXML.getElementsByTagName('headlines')[0]; + + if (feeds) { + feeds = eval("(" + feeds.firstChild.nodeValue + ")"); + + last_feeds = feeds; + + $('feeds-content').innerHTML = ""; + + for (var i = 0; i < feeds.length; i++) { + add_feed_entry(feeds[i]); + } + } else { + feeds = last_feeds; + } + + if (headlines) { + headlines = eval("(" + headlines.firstChild.nodeValue + ")"); + + if (_active_feed_id != feed_id) + $('headlines-content').innerHTML = ""; + + //Element.hide('headlines-content'); + + var pr = $('MORE-PROMPT'); + + if (pr) { + pr.id = ''; + Element.hide(pr); + } + + for (var i = 0; i < headlines.length; i++) { + var elem = $('A-' + headlines[i].id); + + if (elem && Element.visible(elem)) { + + + } else { + add_headline_entry(headlines[i], find_feed(feeds, headlines[i].feed_id)); + } + } + + $('headlines-content').innerHTML += "<li id='MORE-PROMPT'>" + + "<div class='body'><a href=\"#\" onclick=\"load_more()\">" + + __("More articles...") + "</a></div></li>"; + + new Effect.Appear('headlines-content'); + + } + + } catch (e) { + exception_error("digest_update", e); + } + } + +function digest_init() { + try { + + new Ajax.Request("backend.php", { + parameters: "backend.php?op=rpc&subop=digest-init", + onComplete: function(transport) { + digest_update(transport, -4); + window.setTimeout('viewfeed(-4)', 100); + } }); + + } catch (e) { + exception_error("digest_init", e); + } +} + +function tMark_afh_off(effect) { + try { + var elem = effect.effects[0].element; + + console.log("tMark_afh_off : " + elem.id); + + if (elem) { + elem.src = elem.src.replace("mark_set", "mark_unset"); + elem.alt = __("Star article"); + Element.show(elem); + } + + } catch (e) { + exception_error("tMark_afh_off", e); + } +} + +function tPub_afh_off(effect) { + try { + var elem = effect.effects[0].element; + + console.log("tPub_afh_off : " + elem.id); + + if (elem) { + elem.src = elem.src.replace("pub_set", "pub_unset"); + elem.alt = __("Publish article"); + Element.show(elem); + } + + } catch (e) { + exception_error("tPub_afh_off", e); + } +} + +function toggleMark(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; + + var vfeedu = $("FEEDU--1"); + var crow = $("RROW-" + id); + + 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) { + // + } }); + + } catch (e) { + exception_error("toggleMark", e); + } +} + +function togglePub(mark_img, id, note) { + + try { + + var query = "?op=rpc&id=" + id + "&subop=publ"; + + query = query + "&afid=" + _active_feed_id; + + if (note != undefined) { + query = query + "¬e=" + param_escape(note); + } else { + query = query + "¬e=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) { + // + } }); + + } catch (e) { + exception_error("togglePub", e); + } +} + diff --git a/digest.php b/digest.php new file mode 100644 index 000000000..7b1bfd23d --- /dev/null +++ b/digest.php @@ -0,0 +1,112 @@ +<?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 Digest</title> + <link rel="stylesheet" type="text/css" href="digest.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() { + digest_init(); + }); + </script> +</head> +<body id="ttrssDigest"> + <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><?php echo __('headlines') ?></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 } ?> + © 2005–<?php echo date('Y') ?> + <a href="http://fakecake.org/">Andrew Dolgov</a></div> + +</body> diff --git a/functions.php b/functions.php index 2f895cd30..735fd2c73 100644 --- a/functions.php +++ b/functions.php @@ -6655,4 +6655,149 @@ 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"]), + "updated" => strtotime($line["updated"]), + "is_updated" => $is_updated, + "title" => $line["title"], + "link" => $line["link"], + "feed_id" => $line["feed_id"], + "has_icon" => feed_has_icon($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); + } + + return $headlines; + } + ?> diff --git a/images/digest_checkbox.png b/images/digest_checkbox.png Binary files differnew file mode 100755 index 000000000..c5e4b98ea --- /dev/null +++ b/images/digest_checkbox.png diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index b21e161e4..70b690111 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -978,6 +978,57 @@ return; } + if ($subop == "digest-update") { + $feed_id = db_escape_string($_REQUEST['feed_id']); + $offset = db_escape_string($_REQUEST['offset']); + + if (!$feed_id) $feed_id = -4; + if (!$offset) $offset = 0; + + + print "<rpc-reply>"; + + $headlines = api_get_headlines($link, $feed_id, 10, $offset, + '', ($feed_id == -4), true, true, "unread", "updated DESC"); + + //function api_get_headlines($link, $feed_id, $limit, $offset, + // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) { + + 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); + } + + function feeds_sort_by_unread_rev($a, $b) { + $a = $a['unread']; + $b = $b['unread']; + + if ($a == $b) { + return 0; + } + return ($a < $b) ? 1 : -1; + } + + //uasort($feeds, 'feeds_sort_by_unread_rev'); + //$feeds = array_slice($feeds, 0, 10); + + print "<feeds><![CDATA[" . json_encode($feeds) . "]]></feeds>"; + + print "</rpc-reply>"; + return; + } + print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>"; } ?> |