From: Andrew Dolgov Date: Thu, 9 Aug 2007 12:45:30 +0000 (+0100) Subject: published feeds work X-Git-Tag: 1.2.14~117 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=e4f4b46f9d5d42dc53c4e2c5489da31a8ce10c26;p=tt-rss.git published feeds work --- diff --git a/backend.php b/backend.php index 1bf37f66..d5272dda 100644 --- a/backend.php +++ b/backend.php @@ -124,7 +124,6 @@ require_once "modules/pref-users.php"; require_once "modules/pref-feed-browser.php"; - if (!sanity_check($link)) { return; } if ($op == "rpc") { @@ -269,6 +268,11 @@ module_popup_dialog($link); } + if ($op == "pref-pub-items") { + module_pref_pub_items($link); + } + + // update feeds of all users, may be used anonymously if ($op == "globalUpdateFeeds") { diff --git a/functions.php b/functions.php index 6a55bdc8..a77d2f85 100644 --- a/functions.php +++ b/functions.php @@ -1607,7 +1607,13 @@ SET unread = false,last_read = NOW() WHERE marked = true AND owner_uid = ".$_SESSION["uid"]); } - + + if ($feed == -2) { + db_query($link, "UPDATE ttrss_user_entries + SET unread = false,last_read = NOW() + WHERE published = true AND owner_uid = ".$_SESSION["uid"]); + } + } else if ($feed < -10) { // label // TODO make this more efficient @@ -1773,6 +1779,8 @@ return getCategoryUnread($link, $n_feed); } else if ($n_feed == -1) { $match_part = "marked = true"; + } else if ($n_feed == -2) { + $match_part = "published = true"; } else if ($n_feed > 0) { $result = db_query($link, "SELECT id FROM ttrss_feeds @@ -1942,7 +1950,7 @@ $result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_entries,ttrss_user_entries,ttrss_feeds WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.feed_id = ttrss_feeds.id AND - unread = true AND ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); + hidden = false AND unread = true AND ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); $count = db_fetch_result($result, 0, "count"); @@ -1953,6 +1961,21 @@ $ret_arr["-1"]["description"] = "Starred"; } + $result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_entries,ttrss_user_entries,ttrss_feeds + WHERE published = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND + ttrss_user_entries.feed_id = ttrss_feeds.id AND + hidden = false AND unread = true AND ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); + + $count = db_fetch_result($result, 0, "count"); + + if (!$ret_mode) { + print ""; + } else { + $ret_arr["-2"]["counter"] = $count; + $ret_arr["-2"]["description"] = "Published"; + } + + $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description"); @@ -2518,6 +2541,9 @@ } 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 <= -10) { // labels $label_id = -$feed - 11; @@ -2585,6 +2611,8 @@ } else if ($feed == -1) { $feed_title = __("Starred articles"); + } else if ($feed == -2) { + $feed_title = __("Published articles"); } else if ($feed < -10) { $label_id = -$feed - 11; $result = db_query($link, "SELECT description FROM ttrss_labels @@ -2618,7 +2646,7 @@ guid, ttrss_entries.id,ttrss_entries.title, updated, - unread,feed_id,marked,link,last_read, + unread,feed_id,marked,published,link,last_read, SUBSTRING(last_read,1,19) as last_read_noms, $vfeed_query_part $content_query_part @@ -2936,6 +2964,31 @@ } } + function publishArticlesById($link, $ids, $cmode) { + + $tmp_ids = array(); + + foreach ($ids as $id) { + array_push($tmp_ids, "ref_id = '$id'"); + } + + $ids_qpart = join(" OR ", $tmp_ids); + + if ($cmode == 0) { + db_query($link, "UPDATE ttrss_user_entries SET + published = false,last_read = NOW() + WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); + } else if ($cmode == 1) { + db_query($link, "UPDATE ttrss_user_entries SET + published = true + WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); + } else { + db_query($link, "UPDATE ttrss_user_entries SET + published = NOT published,last_read = NOW() + WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); + } + } + function catchupArticlesById($link, $ids, $cmode) { $tmp_ids = array(); @@ -3022,6 +3075,7 @@ $tog_unread_link = "javascript:selectionToggleUnread()"; $tog_marked_link = "javascript:selectionToggleMarked()"; + $tog_published_link = "javascript:selectionTogglePublished()"; } else { @@ -3031,6 +3085,7 @@ $tog_unread_link = "javascript:selectionToggleUnread(true)"; $tog_marked_link = "javascript:selectionToggleMarked(true)"; + $tog_published_link = "javascript:selectionTogglePublished(true)"; } @@ -3046,7 +3101,9 @@
  •  
  • Toggle
    • ".__('Unread')."
    • -
    • ".__('Starred')."
  • +
  • ".__('Starred')."
  • +
  • ".__('Published')."
  • +
  •  
  • ".__('Mark as read')."
    • ".__('This page')."
    • @@ -3157,6 +3214,7 @@ } $num_starred = getFeedUnread($link, -1); + $num_published = getFeedUnread($link, -2); $class = "virt"; @@ -3165,6 +3223,13 @@ printFeedEntry(-1, $class, __("Starred articles"), $num_starred, "images/mark_set.png", $link); + $class = "virt"; + + if ($num_published > 0) $class .= "Unread"; + + printFeedEntry(-2, $class, __("Published articles"), $num_published, + "images/pub_set.png", $link); + if (get_pref($link, 'ENABLE_FEED_CATS')) { print "
    "; } @@ -3848,6 +3913,16 @@ alt=\"Set mark\" onclick='javascript:tMark($id)'>"; } + if ($line["published"] == "t" || $line["published"] == "1") { + $published_pic = "\"Unpublish\""; + } else { + $published_pic = "\"Publish\""; + } + # $content_link = "" . # $line["title"] . ""; @@ -3887,6 +3962,7 @@ "; print "$marked_pic"; + print "$published_pic"; if ($line["feed_title"]) { print "$content_link"; @@ -3952,6 +4028,7 @@ 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">"; print "$marked_pic "; + print "$published_pic "; $tags = get_article_tags($link, $id); @@ -4094,4 +4171,9 @@ return $tag; } + + function generate_publish_key() { + return sha1(uniqid(rand(), true)); + } + ?> diff --git a/images/feed-icon-12x12.png b/images/feed-icon-12x12.png index 291000ea..10faf254 100644 Binary files a/images/feed-icon-12x12.png and b/images/feed-icon-12x12.png differ diff --git a/images/pub_set.png b/images/pub_set.png new file mode 100644 index 00000000..fa0f5863 Binary files /dev/null and b/images/pub_set.png differ diff --git a/images/pub_unset.png b/images/pub_unset.png new file mode 100644 index 00000000..d6db9c48 Binary files /dev/null and b/images/pub_unset.png differ diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 3ca47137..1e757ca7 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -69,6 +69,22 @@ WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); } + if ($subop == "publ") { + $pub = $_GET["pub"]; + $id = db_escape_string($_GET["id"]); + + if ($pub == "1") { + $mark = "true"; + } else { + $pub = "false"; + } + + // FIXME this needs collision testing + + $result = db_query($link, "UPDATE ttrss_user_entries SET published = $pub + WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); + } + if ($subop == "updateFeed") { $feed_id = db_escape_string($_GET["feed"]); @@ -179,6 +195,21 @@ print ""; } + if ($subop == "publishSelected") { + + $ids = split(",", db_escape_string($_GET["ids"])); + $cmode = sprintf("%d", $_GET["cmode"]); + + publishArticlesById($link, $ids, $cmode); + + print ""; + print ""; + getAllCounters($link); + print ""; + print_runtime_info($link); + print ""; + } + if ($subop == "sanityCheck") { print ""; if (sanity_check($link)) { diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index 9ef88e8f..b5070c7e 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -1043,5 +1043,24 @@ class=\"button\" onclick=\"gotoExportOpml()\" value=\"".__('Export OPML')."\">"; + + print "

    Published articles

    "; + + if (!get_pref($link, "_PREFS_PUBLISH_KEY")) { + set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key()); + } + + print "

    ".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the address specified below.')."

    "; + + $url_path = 'http://' . $_SERVER["HTTP_HOST"] . \ + parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); + + $url_path .= "?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY"); + + print "

    $url_path

    "; + + print "

    "; + } ?> diff --git a/prefs.js b/prefs.js index e9f52476..a662aeef 100644 --- a/prefs.js +++ b/prefs.js @@ -16,32 +16,33 @@ var caller_subop = false; var sanity_check_done = false; -function expand_feed_callback() { +/* +function replace_pubkey_callback() { if (xmlhttp.readyState == 4) { try { - var container = document.getElementById("BRDET-" + feed_to_expand); - container.innerHTML=xmlhttp.responseText; - container.style.display = "block"; -// p_notify(""); + var link = document.getElementById("pubGenAddress"); + + if (xmlhttp.responseXML) { + + + } else { + notify_error("Error while changing adress"); + } } catch (e) { - exception_error("expand_feed_callback", e); + exception_error("replace_pubkey_callback", e); } } -} +} */ -function pubitems_callback() { +function expand_feed_callback() { if (xmlhttp.readyState == 4) { try { - var container = document.getElementById('prefContent'); + var container = document.getElementById("BRDET-" + feed_to_expand); container.innerHTML=xmlhttp.responseText; - selectTab("pubItems", true); - - if (typeof correctPNG != 'undefined') { - correctPNG(); - } - notify(""); + container.style.display = "block"; +// p_notify(""); } catch (e) { - exception_error("feedlist_callback", e); + exception_error("expand_feed_callback", e); } } } @@ -1285,8 +1286,6 @@ function selectTab(id, noupdate, subop) { updateUsersList(); } else if (id == "feedBrowser") { updateBigFeedBrowser(); - } else if (id == "pubItems") { - updatePublishedItems(); } } @@ -1749,14 +1748,24 @@ function feedlistToggleSLAT() { updateFeedList() } -function updatePublishedItems() { +/* +function pubRegenKey() { + if (!xmlhttp_ready(xmlhttp)) { printLockingError(); - return + return false; } - xmlhttp.open("GET", "backend.php?op=pref-pubitems"); - xmlhttp.onreadystatechange=pubitems_callback; - xmlhttp.send(null); + var ok = confirm("Replace current publishing address with a new one?"); -} + if (ok) { + + notify_progress("Trying to change address..."); + + xmlhttp.open("GET", "backend.php?op=backend-rpc&subop=regen-pub-key"); + xmlhttp.onreadystatechange=replace_pubkey_callback; + xmlhttp.send(null); + } + + return false; +} */ diff --git a/prefs.php b/prefs.php index 8efe8288..8bf283f1 100644 --- a/prefs.php +++ b/prefs.php @@ -108,8 +108,8 @@ window.onload = init;
    -
    +
    diff --git a/viewfeed.js b/viewfeed.js index 72562974..74dad5ed 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -334,6 +334,11 @@ function tMark(id) { return toggleMark(id); } +function tPub(id) { + return togglePub(id); +} + + function toggleMark(id) { if (!xmlhttp_ready(xmlhttp_rpc)) { @@ -388,6 +393,60 @@ function toggleMark(id) { } +function togglePub(id) { + + if (!xmlhttp_ready(xmlhttp_rpc)) { + printLockingError(); + return; + } + + var query = "backend.php?op=rpc&id=" + id + "&subop=publ"; + + var mark_img = document.getElementById("FPPIC-" + id); + var vfeedu = document.getElementById("FEEDU--2"); + var crow = document.getElementById("RROW-" + id); + + if (mark_img.alt != "Unpublish") { + mark_img.src = "images/pub_set.png"; + mark_img.alt = "Unpublish"; + query = query + "&pub=1"; + + if (vfeedu && crow.className.match("Unread")) { + vfeedu.innerHTML = (+vfeedu.innerHTML) + 1; + } + + } else { + mark_img.src = "images/pub_unset.png"; + mark_img.alt = "Publish"; + query = query + "&pub=0"; + + if (vfeedu && crow.className.match("Unread")) { + vfeedu.innerHTML = (+vfeedu.innerHTML) - 1; + } + + } + + var vfeedctr = document.getElementById("FEEDCTR--2"); + var vfeedr = document.getElementById("FEEDR--2"); + + if (vfeedu && vfeedctr) { + if ((+vfeedu.innerHTML) > 0) { + if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) { + vfeedr.className = vfeedr.className + "Unread"; + vfeedctr.className = "odd"; + } + } else { + vfeedctr.className = "invisible"; + vfeedr.className = vfeedr.className.replace("Unread", ""); + } + } + + debug("toggle published for aid " + id); + + new Ajax.Request(query); + +} + function correctHeadlinesOffset(id) { try { @@ -587,7 +646,7 @@ function selectionToggleMarked(cdm_mode) { for (i = 0; i < rows.length; i++) { var row = document.getElementById("RROW-" + rows[i]); - var mark_img = document.getElementById("FMARKPIC-" + rows[i]); + var mark_img = document.getElementById("FMPIC-" + rows[i]); if (row && mark_img) { @@ -622,6 +681,63 @@ function selectionToggleMarked(cdm_mode) { } } +function selectionTogglePublished(cdm_mode) { + try { + if (!xmlhttp_ready(xmlhttp_rpc)) { + printLockingError(); + return; + } + + var rows; + + if (cdm_mode) { + rows = cdmGetSelectedArticles(); + } else { + rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); + } + + if (rows.length == 0) { + alert(__("No articles are selected.")); + return; + } + + for (i = 0; i < rows.length; i++) { + var row = document.getElementById("RROW-" + rows[i]); + var mark_img = document.getElementById("FPPIC-" + rows[i]); + + if (row && mark_img) { + + if (mark_img.alt == "Publish") { + mark_img.src = "images/pub_set.png"; + mark_img.alt = "Unpublish"; + mark_img.setAttribute('onclick', + 'javascript:togglePub('+rows[i]+', false)'); + + } else { + mark_img.src = "images/pub_unset.png"; + mark_img.alt = "Publish"; + mark_img.setAttribute('onclick', + 'javascript:togglePub('+rows[i]+', true)'); + } + } + } + + if (rows.length > 0) { + + var query = "backend.php?op=rpc&subop=publishSelected&ids=" + + param_escape(rows.toString()) + "&cmode=2"; + + xmlhttp_rpc.open("GET", query, true); + xmlhttp_rpc.onreadystatechange=all_counters_callback; + xmlhttp_rpc.send(null); + + } + + } catch (e) { + exception_error("selectionToggleMarked", e); + } +} + function cdmGetSelectedArticles() { var sel_articles = new Array(); var container = document.getElementById("headlinesInnerContainer");