]>
git.wh0rd.org - tt-rss.git/blob - plugins/share/init.php
2 class Share
extends Plugin
{
7 "Share article by unique URL",
11 /* @var PluginHost $host */
12 function init($host) {
15 $host->add_hook($host::HOOK_ARTICLE_BUTTON
, $this);
16 $host->add_hook($host::HOOK_PREFS_TAB_SECTION
, $this);
20 return file_get_contents(dirname(__FILE__
) . "/share.js");
23 function get_prefs_js() {
24 return file_get_contents(dirname(__FILE__
) . "/share_prefs.js");
29 $id = $_REQUEST['id'];
31 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET uuid = '' WHERE int_id = ?
33 $sth->execute([$id, $_SESSION['uid']]);
38 function hook_prefs_tab_section($id) {
39 if ($id == "prefFeedsPublishedGenerated") {
41 print "<p>" . __("You can disable all articles shared by unique URLs here.") . "</p>";
43 print "<button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
44 __('Unshare all articles')."</button> ";
52 function clearArticleKeys() {
53 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET uuid = '' WHERE
55 $sth->execute([$_SESSION['uid']]);
62 $id = $_REQUEST['id'];
63 $uuid = uniqid_short();
65 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET uuid = ? WHERE int_id = ?
67 $sth->execute([$uuid, $id, $_SESSION['uid']]);
69 print json_encode(array("link" => $uuid));
72 function hook_article_button($line) {
73 $img = $line['uuid'] ?
"share.png" : "notshared.png";
75 return "<img id='SHARE-IMG-".$line['int_id']."' src=\"plugins/share/$img\"
76 class='tagsPic' style=\"cursor : pointer\"
77 onclick=\"shareArticle(".$line['int_id'].")\"
78 title='".__('Share by URL')."'>";
81 function shareArticle() {
82 $param = $_REQUEST['param'];
84 $sth = $this->pdo
->prepare("SELECT uuid FROM ttrss_user_entries WHERE int_id = ?
86 $sth->execute([$param, $_SESSION['uid']]);
88 if ($row = $sth->fetch()) {
93 $uuid = uniqid_short();
95 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET uuid = ? WHERE int_id = ?
97 $sth->execute([$uuid, $param, $_SESSION['uid']]);
100 print __("You can share this article by the following unique URL:") . "<br/>";
102 $url_path = get_self_url_prefix();
103 $url_path .= "/public.php?op=share&key=$uuid";
105 print "<div class=\"tagCloudContainer\">";
106 print "<a id='gen_article_url' href='$url_path' target='_blank' rel='noopener noreferrer'>$url_path</a>";
109 /* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
110 label_create(__('Shared'), $_SESSION["uid"]);
112 label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */
116 print "Article not found.";
119 print "<div align='center'>";
121 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').unshare()\">".
122 __('Unshare article')."</button>";
124 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').newurl()\">".
125 __('Generate new URL')."</button>";
127 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
128 __('Close this window')."</button>";
133 function api_version() {