diff options
Diffstat (limited to 'plugins/share')
-rw-r--r-- | plugins/share/init.php | 64 | ||||
-rw-r--r-- | plugins/share/notshared.png | bin | 0 -> 657 bytes | |||
-rw-r--r-- | plugins/share/share.js | 69 | ||||
-rw-r--r-- | plugins/share/share.png | bin | 3639 -> 343 bytes | |||
-rw-r--r-- | plugins/share/share_prefs.js | 21 |
5 files changed, 150 insertions, 4 deletions
diff --git a/plugins/share/init.php b/plugins/share/init.php index 72a4d4bf9..899677c32 100644 --- a/plugins/share/init.php +++ b/plugins/share/init.php @@ -12,14 +12,66 @@ class Share extends Plugin { $this->host = $host; $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); + $host->add_hook($host::HOOK_PREFS_TAB_SECTION, $this); } function get_js() { return file_get_contents(dirname(__FILE__) . "/share.js"); } + function get_prefs_js() { + return file_get_contents(dirname(__FILE__) . "/share_prefs.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 hook_prefs_tab_section($id) { + if ($id == "prefFeedsPublishedGenerated") { + + print_warning(__("You can disable all articles shared by unique URLs here.")); + + print "<p>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">". + __('Unshare all articles')."</button> "; + + print "</p>"; + + } + } + + // Silent + function clearArticleKeys() { + db_query("UPDATE ttrss_user_entries SET uuid = '' WHERE + owner_uid = " . $_SESSION["uid"]); + + return; + } + + + function newkey() { + $id = db_escape_string($_REQUEST['id']); + + $uuid = db_escape_string(uniqid(base_convert(rand(), 10, 36))); + + 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\" + $img = $line['uuid'] ? "share.png" : "notshared.png"; + + return "<img id='SHARE-IMG-".$line['int_id']."' src=\"plugins/share/$img\" class='tagsPic' style=\"cursor : pointer\" onclick=\"shareArticle(".$line['int_id'].")\" title='".__('Share by URL')."'>"; @@ -39,7 +91,7 @@ class Share extends Plugin { $ref_id = db_fetch_result($result, 0, "ref_id"); if (!$uuid) { - $uuid = db_escape_string(sha1(uniqid(rand(), true))); + $uuid = db_escape_string(uniqid(base_convert(rand(), 10, 36))); db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param' AND owner_uid = " . $_SESSION['uid']); } @@ -50,7 +102,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 +113,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>"; diff --git a/plugins/share/notshared.png b/plugins/share/notshared.png Binary files differnew file mode 100644 index 000000000..523575306 --- /dev/null +++ b/plugins/share/notshared.png diff --git a/plugins/share/share.js b/plugins/share/share.js index 6752189ea..09c973ed8 100644 --- a/plugins/share/share.js +++ b/plugins/share/share.js @@ -9,12 +9,79 @@ 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(/\&key=.*$/, + "&key=" + new_link); + + e.href = e.href.replace(/\&key=.*$/, + "&key=" + new_link); + + new Effect.Highlight(e); + + var img = $("SHARE-IMG-" + id); + if (img) img.src = img.src.replace("notshared.png", "share.png"); + + 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."); + + var img = $("SHARE-IMG-" + id); + if (img) img.src = img.src.replace("share.png", "notshared.png"); + + dialog.hide(); + } }); + } + + }, href: query}); dialog.show(); + var img = $("SHARE-IMG-" + id); + if (img) img.src = img.src.replace("notshared.png", "share.png"); + } catch (e) { - exception_error("emailArticle", e); + exception_error("shareArticle", e); } } diff --git a/plugins/share/share.png b/plugins/share/share.png Binary files differindex 3b6398f4a..25eacb7c2 100644 --- a/plugins/share/share.png +++ b/plugins/share/share.png diff --git a/plugins/share/share_prefs.js b/plugins/share/share_prefs.js new file mode 100644 index 000000000..9efe291f9 --- /dev/null +++ b/plugins/share/share_prefs.js @@ -0,0 +1,21 @@ +function clearArticleAccessKeys() { + + var ok = confirm(__("This will invalidate all previously shared article URLs. Continue?")); + + if (ok) { + notify_progress("Clearing URLs..."); + + var query = "?op=pluginhandler&plugin=share&method=clearArticleKeys"; + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + notify_info("Shared URLs cleared."); + } }); + } + + return false; +} + + + |