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