]> git.wh0rd.org - tt-rss.git/blame - plugins/share/init.php
plugin base class: init pdo object
[tt-rss.git] / plugins / share / init.php
CommitLineData
1baac280 1<?php
5a0e0392 2class Share extends Plugin {
19c73507
AD
3 private $host;
4
d2a421e3 5 function about() {
7a866114
AD
6 return array(1.0,
7 "Share article by unique URL",
8 "fox");
9 }
10
b6f3562d 11 /* @var PluginHost $host */
d2a421e3 12 function init($host) {
19c73507
AD
13 $this->host = $host;
14
15 $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
41a7a066 16 $host->add_hook($host::HOOK_PREFS_TAB_SECTION, $this);
19c73507
AD
17 }
18
19 function get_js() {
20 return file_get_contents(dirname(__FILE__) . "/share.js");
21 }
22
41a7a066
AD
23 function get_prefs_js() {
24 return file_get_contents(dirname(__FILE__) . "/share_prefs.js");
25 }
26
27
98d01eb1 28 function unshare() {
b6f3562d 29 $id = $_REQUEST['id'];
98d01eb1 30
b6f3562d
AD
31 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET uuid = '' WHERE int_id = ?
32 AND owner_uid = ?");
33 $sth->execute([$id, $_SESSION['uid']]);
98d01eb1
AD
34
35 print "OK";
36 }
37
41a7a066
AD
38 function hook_prefs_tab_section($id) {
39 if ($id == "prefFeedsPublishedGenerated") {
40
73dfda1d 41 print "<p>" . __("You can disable all articles shared by unique URLs here.") . "</p>";
41a7a066 42
73dfda1d 43 print "<button class=\"danger\" dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
41a7a066
AD
44 __('Unshare all articles')."</button> ";
45
46 print "</p>";
47
48 }
49 }
50
51 // Silent
52 function clearArticleKeys() {
b6f3562d
AD
53 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET uuid = '' WHERE
54 owner_uid = ?");
55 $sth->execute([$_SESSION['uid']]);
41a7a066
AD
56
57 return;
58 }
59
60
98d01eb1 61 function newkey() {
b6f3562d
AD
62 $id = $_REQUEST['id'];
63 $uuid = uniqid_short();
98d01eb1 64
b6f3562d
AD
65 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET uuid = ? WHERE int_id = ?
66 AND owner_uid = ?");
67 $sth->execute([$uuid, $id, $_SESSION['uid']]);
98d01eb1
AD
68
69 print json_encode(array("link" => $uuid));
70 }
71
19c73507 72 function hook_article_button($line) {
abb04b76
AD
73 $img = $line['uuid'] ? "share.png" : "notshared.png";
74
75 return "<img id='SHARE-IMG-".$line['int_id']."' src=\"plugins/share/$img\"
1baac280
AD
76 class='tagsPic' style=\"cursor : pointer\"
77 onclick=\"shareArticle(".$line['int_id'].")\"
78 title='".__('Share by URL')."'>";
79 }
80
81 function shareArticle() {
b6f3562d 82 $param = $_REQUEST['param'];
1baac280 83
b6f3562d
AD
84 $sth = $this->pdo->prepare("SELECT uuid FROM ttrss_user_entries WHERE int_id = ?
85 AND owner_uid = ?");
86 $sth->execute([$param, $_SESSION['uid']]);
1baac280 87
b6f3562d 88 if ($row = $sth->fetch()) {
1baac280 89
b6f3562d 90 $uuid = $row['uuid'];
1baac280
AD
91
92 if (!$uuid) {
b6f3562d
AD
93 $uuid = uniqid_short();
94
95 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET uuid = ? WHERE int_id = ?
96 AND owner_uid = ?");
97 $sth->execute([$uuid, $param, $_SESSION['uid']]);
1baac280
AD
98 }
99
73dfda1d 100 print __("You can share this article by the following unique URL:") . "<br/>";
1baac280
AD
101
102 $url_path = get_self_url_prefix();
103 $url_path .= "/public.php?op=share&key=$uuid";
104
105 print "<div class=\"tagCloudContainer\">";
ba2853ca 106 print "<a id='gen_article_url' href='$url_path' target='_blank' rel='noopener noreferrer'>$url_path</a>";
1baac280
AD
107 print "</div>";
108
a42c55f0
AD
109 /* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
110 label_create(__('Shared'), $_SESSION["uid"]);
1baac280 111
a42c55f0 112 label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */
b6f3562d
AD
113
114
115 } else {
116 print "Article not found.";
1baac280
AD
117 }
118
119 print "<div align='center'>";
120
98d01eb1
AD
121 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').unshare()\">".
122 __('Unshare article')."</button>";
123
124 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').newurl()\">".
125 __('Generate new URL')."</button>";
126
1baac280
AD
127 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
128 __('Close this window')."</button>";
129
130 print "</div>";
131 }
132
106a3de9
AD
133 function api_version() {
134 return 2;
135 }
1baac280 136
21ce7d9e 137}