From b41c254984df3fcb9fc7db4bb5218f2391e62164 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 9 Sep 2010 19:02:12 +0400 Subject: [PATCH] small digest page improvements --- digest.css | 8 ++++ digest.js | 57 +++++++++++++++++++++++--- digest.php | 1 - functions.php | 88 +++++++++++++++++++++-------------------- modules/backend-rpc.php | 14 ++++--- 5 files changed, 115 insertions(+), 53 deletions(-) diff --git a/digest.css b/digest.css index 5139114f0..62852adb0 100644 --- a/digest.css +++ b/digest.css @@ -126,6 +126,14 @@ a:hover { 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; diff --git a/digest.js b/digest.js index 7bfd9df27..3d58ca95f 100644 --- a/digest.js +++ b/digest.js @@ -1,5 +1,19 @@ var last_feeds = []; +function view(feed_id) { + try { + + new Ajax.Request("backend.php", { + parameters: "backend.php?op=rpc&subop=digest-init&feed_id=" + feed_id, + onComplete: function(transport) { + digest_update(transport); + } }); + + } catch (e) { + exception_error("view", e); + } +} + function find_feed(feeds, feed_id) { try { for (var i = 0; i < feeds.length; i++) { @@ -14,16 +28,40 @@ function find_feed(feeds, feed_id) { } } +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 = ""; - if (feed.has_icon) - icon_part = "zz"; + icon_part = ""; var tmp_html = "
  • " + icon_part + - feed.title + + "" + feed.title + "
    " + feed.unread + "
    " + "
  • "; @@ -34,8 +72,11 @@ function add_feed_entry(feed) { } } -function add_latest_entry(article) { +function add_latest_entry(article, feed) { try { + + + //$("latest-content").innerHTML += "bbb"; } catch (e) { exception_error("add_latest_entry", e); @@ -55,7 +96,7 @@ function add_headline_entry(article, feed) { "" + article.title + "" + "
    " + article.excerpt + "
    " + "
    " + feed.title + " " + " @ " + - article.updated + "
    " + + new Date(article.updated * 1000) + "" + ""; $("headlines-content").innerHTML += tmp_html; @@ -75,6 +116,8 @@ function digest_update(transport) { feeds = eval("(" + feeds.firstChild.nodeValue + ")"); + $('feeds-content').innerHTML = ""; + for (var i = 0; i < feeds.length; i++) { add_feed_entry(feeds[i]); } @@ -83,9 +126,13 @@ function digest_update(transport) { if (headlines) { headlines = eval("(" + headlines.firstChild.nodeValue + ")"); + $('headlines-content').innerHTML = ""; + for (var i = 0; i < headlines.length; i++) { add_headline_entry(headlines[i], find_feed(feeds, headlines[i].feed_id)); } + + $('headlines-content').innerHTML += "
  • More articles...
  • "; } } catch (e) { diff --git a/digest.php b/digest.php index cfe16cfe4..94489eb0b 100644 --- a/digest.php +++ b/digest.php @@ -39,7 +39,6 @@ - diff --git a/functions.php b/functions.php index 78e0d4f18..ce1a06a62 100644 --- a/functions.php +++ b/functions.php @@ -6653,51 +6653,9 @@ } function api_get_feeds($link, $cat_id, $unread_only, $limit, $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"]); - - $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); - } - } - /* Labels */ if (!$cat_id || $cat_id == -2) { @@ -6741,6 +6699,52 @@ } } + + /* 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; } diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index f8233a7cd..edf2ae2e4 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -979,13 +979,17 @@ } if ($subop == "digest-init") { + $feed_id = db_escape_string($_REQUEST['feed_id']); + + if (!$feed_id) $feed_id = -4; + print ""; $tmp_feeds = api_get_feeds($link, false, true, false, 0); $feeds = array(); foreach ($tmp_feeds as $f) { - if ($f['id'] > 0) array_push($feeds, $f); + if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f); } function feeds_sort_by_unread_rev($a, $b) { @@ -998,13 +1002,13 @@ return ($a < $b) ? 1 : -1; } -// uasort($feeds, 'feeds_sort_by_unread_rev'); -// $feeds = array_slice($feeds, 0, 10); + //uasort($feeds, 'feeds_sort_by_unread_rev'); + //$feeds = array_slice($feeds, 0, 10); print ""; - $headlines = api_get_headlines($link, -4, 20, 0, - '', true, true, false, "all_articles", "updated DESC"); + $headlines = api_get_headlines($link, $feed_id, 10, 0, + '', ($feed_id == -4), true, false, "all_articles", "updated DESC"); //function api_get_headlines($link, $feed_id, $limit, $offset, // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) {