]> git.wh0rd.org - tt-rss.git/blob - plugins/share/init.php
increase randomness of shared url keys a bit
[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_warning(__("You can disable all articles shared by unique URLs here."));
40
41 print "<p>";
42
43 print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
44 __('Unshare all articles')."</button> ";
45
46 print "</p>";
47
48 }
49 }
50
51 // Silent
52 function clearArticleKeys() {
53 db_query("UPDATE ttrss_user_entries SET uuid = '' WHERE
54 owner_uid = " . $_SESSION["uid"]);
55
56 return;
57 }
58
59
60 function newkey() {
61 $id = db_escape_string($_REQUEST['id']);
62
63 $uuid = db_escape_string(uniqid(base_convert(rand(), 10, 36)));
64
65 db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$id'
66 AND owner_uid = " . $_SESSION['uid']);
67
68 print json_encode(array("link" => $uuid));
69 }
70
71 function hook_article_button($line) {
72 $img = $line['uuid'] ? "share.png" : "notshared.png";
73
74 return "<img id='SHARE-IMG-".$line['int_id']."' src=\"plugins/share/$img\"
75 class='tagsPic' style=\"cursor : pointer\"
76 onclick=\"shareArticle(".$line['int_id'].")\"
77 title='".__('Share by URL')."'>";
78 }
79
80 function shareArticle() {
81 $param = db_escape_string($_REQUEST['param']);
82
83 $result = db_query("SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '$param'
84 AND owner_uid = " . $_SESSION['uid']);
85
86 if (db_num_rows($result) == 0) {
87 print "Article not found.";
88 } else {
89
90 $uuid = db_fetch_result($result, 0, "uuid");
91 $ref_id = db_fetch_result($result, 0, "ref_id");
92
93 if (!$uuid) {
94 $uuid = db_escape_string(uniqid(base_convert(rand(), 10, 36)));
95 db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param'
96 AND owner_uid = " . $_SESSION['uid']);
97 }
98
99 print "<h2>". __("You can share this article by the following unique URL:") . "</h2>";
100
101 $url_path = get_self_url_prefix();
102 $url_path .= "/public.php?op=share&key=$uuid";
103
104 print "<div class=\"tagCloudContainer\">";
105 print "<a id='gen_article_url' href='$url_path' target='_blank'>$url_path</a>";
106 print "</div>";
107
108 /* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
109 label_create(__('Shared'), $_SESSION["uid"]);
110
111 label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */
112 }
113
114 print "<div align='center'>";
115
116 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').unshare()\">".
117 __('Unshare article')."</button>";
118
119 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').newurl()\">".
120 __('Generate new URL')."</button>";
121
122 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
123 __('Close this window')."</button>";
124
125 print "</div>";
126 }
127
128 function api_version() {
129 return 2;
130 }
131
132 }
133 ?>