]> git.wh0rd.org - tt-rss.git/commitdiff
published feeds work
authorAndrew Dolgov <fox@bah.spb.su>
Thu, 9 Aug 2007 12:45:30 +0000 (13:45 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Thu, 9 Aug 2007 12:45:30 +0000 (13:45 +0100)
backend.php
functions.php
images/feed-icon-12x12.png
images/pub_set.png [new file with mode: 0644]
images/pub_unset.png [new file with mode: 0644]
modules/backend-rpc.php
modules/pref-feeds.php
prefs.js
prefs.php
viewfeed.js

index 1bf37f6658b82bfe300c5ba61d2978878d942021..d5272ddae51736407245be79c3c16b69beaf66c8 100644 (file)
        require_once "modules/pref-users.php";
        require_once "modules/pref-feed-browser.php"; 
 
-
        if (!sanity_check($link)) { return; }
 
        if ($op == "rpc") {
                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") {
 
index 6a55bdc8e8e7e3df06a58428985b843517a00f66..a77d2f85c0cc7ef0c10d8c0c60d2b91e88bf302f 100644 (file)
                                                        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
                        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 
                $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");
 
                        $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 "<counter type=\"label\" id=\"-2\" counter=\"$count\"/>";
+               } 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");
        
                        } 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;
        
        
                        } 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
                                                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
                }
        }
 
+       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();
 
                                $tog_unread_link = "javascript:selectionToggleUnread()";
                                $tog_marked_link = "javascript:selectionToggleMarked()";
+                               $tog_published_link = "javascript:selectionTogglePublished()";
 
                        } else {
 
 
                                $tog_unread_link = "javascript:selectionToggleUnread(true)";
                                $tog_marked_link = "javascript:selectionToggleMarked(true)";
+                               $tog_published_link = "javascript:selectionTogglePublished(true)";
 
                        }
 
                                        <li class=\"vsep\">&nbsp;</li>
                                        <li class=\"top\">Toggle<ul>
                                                <li onclick=\"$tog_unread_link\">".__('Unread')."</li>
-                                               <li onclick=\"$tog_marked_link\">".__('Starred')."</li></ul></li>
+                                               <li onclick=\"$tog_marked_link\">".__('Starred')."</li>
+                                               <li onclick=\"$tog_published_link\">".__('Published')."</li>
+                                               </ul></li>
                                        <li class=\"vsep\">&nbsp;</li>
                                        <li class=\"top\"><a href=\"$catchup_page_link\">".__('Mark as read')."</a><ul>
                                                <li onclick=\"$catchup_page_link\">".__('This page')."</li>
                }
 
                $num_starred = getFeedUnread($link, -1);
+               $num_published = getFeedUnread($link, -2);
 
                $class = "virt";
 
                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 "</ul>";
                }
                                                alt=\"Set mark\" onclick='javascript:tMark($id)'>";
                                }
 
+                               if ($line["published"] == "t" || $line["published"] == "1") {
+                                       $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_set.png\" 
+                                               class=\"markedPic\"
+                                               alt=\"Unpublish\" onclick='javascript:tPub($id)'>";
+                               } else {
+                                       $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_unset.png\" 
+                                               class=\"markedPic\"
+                                               alt=\"Publish\" onclick='javascript:tPub($id)'>";
+                               }
+
 #                              $content_link = "<a target=\"_new\" href=\"".$line["link"]."\">" .
 #                                      $line["title"] . "</a>";
 
                                                </td>";
                
                                        print "<td class='hlMarkedPic'>$marked_pic</td>";
+                                       print "<td class='hlMarkedPic'>$published_pic</td>";
 
                                        if ($line["feed_title"]) {                      
                                                print "<td class='hlContent'>$content_link</td>";
                                                        'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">";
 
                                        print "</span><span class='s1'>$marked_pic</span> ";
+                                       print "<span class='s1'>$published_pic</span> ";
 
                                        $tags = get_article_tags($link, $id);
 
 
                return $tag;
        }
+
+       function generate_publish_key() {
+               return sha1(uniqid(rand(), true));
+       }
+
 ?>
index 291000eab2b97c9a5a6f76e77afd6837ec10ac5f..10faf2548a5336c1f1a1645346e3a4ed0a6194bf 100644 (file)
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 (file)
index 0000000..fa0f586
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 (file)
index 0000000..d6db9c4
Binary files /dev/null and b/images/pub_unset.png differ
index 3ca471377c619ce621f2f67b71cd565f22bf928d..1e757ca72526ad801f81eec335478481cc158bc4 100644 (file)
                                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"]);
 
                        print "</rpc-reply>";
                }
 
+               if ($subop == "publishSelected") {
+
+                       $ids = split(",", db_escape_string($_GET["ids"]));
+                       $cmode = sprintf("%d", $_GET["cmode"]);
+
+                       publishArticlesById($link, $ids, $cmode);
+
+                       print "<rpc-reply>";
+                       print "<counters>";
+                       getAllCounters($link);
+                       print "</counters>";
+                       print_runtime_info($link);
+                       print "</rpc-reply>";
+               }
+
                if ($subop == "sanityCheck") {
                        print "<rpc-reply>";
                        if (sanity_check($link)) {
index 9ef88e8fa5eb1aee9c2df2eb843627b0a32e7cd2..b5070c7e926ad6b1db9295c5b34e2c29dafd43ed 100644 (file)
                        class=\"button\" onclick=\"gotoExportOpml()\" 
                                value=\"".__('Export OPML')."\">";                      
 
+
+               print "<h3>Published articles</h3>";
+
+               if (!get_pref($link, "_PREFS_PUBLISH_KEY")) {
+                       set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
+               }
+               
+               print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the address specified below.')."</p>";
+
+               $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 "<p><a id=\"pubGenAddress\" target=\"_new\" href=\"$url_path\">$url_path</a></p>";
+
+               print "<p><input type=\"submit\" onclick=\"return pubRegenKey()\" 
+                       value=\"".__('Generate another address')."\"></p>";
+
        }
 ?>
index e9f52476f8ee38c14e68de17223bd364e8d25b81..a662aeef7711896c53a366fd8155e9f13f64e845 100644 (file)
--- 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;
+} */
index 8efe82883dd17f7f8c3c792a22829505fdbb8de5..8bf283f1f105bd40c4457e51a4fd1bb361cbd613 100644 (file)
--- a/prefs.php
+++ b/prefs.php
@@ -108,8 +108,8 @@ window.onload = init;
                <div id="feedBrowserTab" class="prefsTab" 
                        onclick="selectTab('feedBrowser')"><?php echo __('Other Feeds') ?></div>
                <?php } ?>
-               <div id="pubItemsTab" class="prefsTab" 
-                       onclick="selectTab('pubItems')"><?php echo __('Published Articles') ?></div>
+               <!-- <div id="pubItemsTab" class="prefsTab" 
+                       onclick="selectTab('pubItems')"><?php echo __('Published Articles') ?></div> -->
                <div id="filterConfigTab" class="prefsTab" 
                        onclick="selectTab('filterConfig')"><?php echo __('Content Filtering') ?></div>
                <?php if (get_pref($link, 'ENABLE_LABELS')) { ?>
index 725629747534dcef735cdb03076dd863906b05b1..74dad5edd77af9e210d73db8b22222ee14a459df 100644 (file)
@@ -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");