From: Andrew Dolgov Date: Fri, 10 Sep 2010 13:47:45 +0000 (+0400) Subject: Merge branch 'master' into digest-experimental X-Git-Tag: 1.4.3~3 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=9de31493ddf1b9d01d203376eedd52733325be9f;hp=eef20159e430dfe5984f1e70f3c320c53de741a4;p=tt-rss.git Merge branch 'master' into digest-experimental --- diff --git a/api/index.php b/api/index.php index 8d69e1a7..ae4f1eb5 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 00000000..b0d17b4f --- /dev/null +++ b/digest.css @@ -0,0 +1,206 @@ +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; +} + +#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 { + 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.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 00000000..2a886a89 --- /dev/null +++ b/digest.js @@ -0,0 +1,416 @@ +var last_feeds = []; + +var _active_feed_id = false; +var _active_feed_offset = false; +var _update_timeout = false; + +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; + } }); + + } 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 = ""; + + var tmp_html = "
  • " + + icon_part + + "" + feed.title + + "
    " + feed.unread + "
    " + + "
  • "; + + $("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 = ""; + + var tmp_html = "
  • " + + icon_part + + "
    " + + "" + + "" + + "" + + "
    " + + "
    " + + article.title + "" + + "
    " + + "
    " + + article.excerpt + "
    " + + "" + + "
    " + + feed.title + " " + " @ " + + new Date(article.updated * 1000) + "
    " + + "
  • "; + + $("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 += "
  • " + + "
  • "; + + 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 00000000..7b1bfd23 --- /dev/null +++ b/digest.php @@ -0,0 +1,112 @@ + + + + + + Tiny Tiny Digest + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    +

    + +
    +
    + +
    +

    + +
    +
    + +
    + +
    + + + + diff --git a/functions.php b/functions.php index 2f895cd3..735fd2c7 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 new file mode 100755 index 00000000..c5e4b98e Binary files /dev/null and b/images/digest_checkbox.png differ diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index b21e161e..70b69011 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 ""; + + $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 ""; + + print ""; + return; + } + + if ($subop == "digest-init") { + print ""; + + $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 ""; + + print ""; + return; + } + print "Unknown method: $subop"; } ?>