]> git.wh0rd.org - tt-rss.git/commitdiff
allow unsharing specific articles / creating new share key
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 11 Jul 2013 10:03:40 +0000 (14:03 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 11 Jul 2013 10:03:40 +0000 (14:03 +0400)
plugins/share/init.php
plugins/share/share.js

index 72a4d4bf980dac7d22c0365cc70e41332dd02ca7..a1b0146a1d2599fa133838466d53fb33c5810dac 100644 (file)
@@ -18,6 +18,26 @@ class Share extends Plugin {
                return file_get_contents(dirname(__FILE__) . "/share.js");
        }
 
+       function unshare() {
+               $id = db_escape_string($_REQUEST['id']);
+
+               db_query("UPDATE ttrss_user_entries SET uuid = '' WHERE int_id = '$id'
+                       AND owner_uid = " . $_SESSION['uid']);
+
+               print "OK";
+       }
+
+       function newkey() {
+               $id = db_escape_string($_REQUEST['id']);
+
+               $uuid = db_escape_string(sha1(uniqid(rand(), true)));
+
+               db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$id'
+                       AND owner_uid = " . $_SESSION['uid']);
+
+               print json_encode(array("link" => $uuid));
+       }
+
        function hook_article_button($line) {
                return "<img src=\"plugins/share/share.png\"
                        class='tagsPic' style=\"cursor : pointer\"
@@ -50,7 +70,7 @@ class Share extends Plugin {
                        $url_path .= "/public.php?op=share&key=$uuid";
 
                        print "<div class=\"tagCloudContainer\">";
-                       print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>";
+                       print "<a id='gen_article_url' href='$url_path' target='_blank'>$url_path</a>";
                        print "</div>";
 
                        /* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
@@ -61,6 +81,12 @@ class Share extends Plugin {
 
                print "<div align='center'>";
 
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').unshare()\">".
+                       __('Unshare article')."</button>";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').newurl()\">".
+                       __('Generate new URL')."</button>";
+
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
                        __('Close this window')."</button>";
 
index 6752189eabdccf049a940bbfa7276258bf77396f..bbfb553d5c3cccea18cc46b11ed8e20d51123059 100644 (file)
@@ -9,12 +9,69 @@ function shareArticle(id) {
                        id: "shareArticleDlg",
                        title: __("Share article by URL"),
                        style: "width: 600px",
+                       newurl: function() {
+
+                               var ok = confirm(__("Generate new share URL for this article?"));
+
+                               if (ok) {
+
+                                       notify_progress("Trying to change URL...", true);
+
+                                       var query = "op=pluginhandler&plugin=share&method=newkey&id=" + param_escape(id);
+
+                                       new Ajax.Request("backend.php", {
+                                               parameters: query,
+                                               onComplete: function(transport) {
+                                                               var reply = JSON.parse(transport.responseText);
+                                                               var new_link = reply.link;
+
+                                                               var e = $('gen_article_url');
+
+                                                               if (new_link) {
+
+                                                                       e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
+                                                                               "&amp;key=" + new_link);
+
+                                                                       e.href = e.href.replace(/\&key=.*$/,
+                                                                               "&key=" + new_link);
+
+                                                                       new Effect.Highlight(e);
+
+                                                                       notify('');
+
+                                                               } else {
+                                                                       notify_error("Could not change URL.");
+                                                               }
+                                               } });
+
+                               }
+
+                       },
+                       unshare: function() {
+
+                               var ok = confirm(__("Remove sharing for this article?"));
+
+                               if (ok) {
+
+                                       notify_progress("Trying to unshare...", true);
+
+                                       var query = "op=pluginhandler&plugin=share&method=unshare&id=" + param_escape(id);
+
+                                       new Ajax.Request("backend.php", {
+                                               parameters: query,
+                                               onComplete: function(transport) {
+                                                       notify("Article unshared.");
+                                                       dialog.hide();
+                                               } });
+                               }
+
+                       },
                        href: query});
 
                dialog.show();
 
        } catch (e) {
-               exception_error("emailArticle", e);
+               exception_error("shareArticle", e);
        }
 }