]> git.wh0rd.org - tt-rss.git/blame - plugins/share/init.php
share: move unsharing all articles into the plugin
[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
d2a421e3 11 function init($host) {
19c73507
AD
12 $this->host = $host;
13
14 $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
41a7a066 15 $host->add_hook($host::HOOK_PREFS_TAB_SECTION, $this);
19c73507
AD
16 }
17
18 function get_js() {
19 return file_get_contents(dirname(__FILE__) . "/share.js");
20 }
21
41a7a066
AD
22 function get_prefs_js() {
23 return file_get_contents(dirname(__FILE__) . "/share_prefs.js");
24 }
25
26
98d01eb1
AD
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
41a7a066
AD
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
98d01eb1
AD
60 function newkey() {
61 $id = db_escape_string($_REQUEST['id']);
62
63 $uuid = db_escape_string(sha1(uniqid(rand(), true)));
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
19c73507 71 function hook_article_button($line) {
2a3b6de0 72 return "<img src=\"plugins/share/share.png\"
1baac280
AD
73 class='tagsPic' style=\"cursor : pointer\"
74 onclick=\"shareArticle(".$line['int_id'].")\"
75 title='".__('Share by URL')."'>";
76 }
77
78 function shareArticle() {
a42c55f0 79 $param = db_escape_string($_REQUEST['param']);
1baac280 80
a42c55f0 81 $result = db_query("SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '$param'
1baac280
AD
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 $ref_id = db_fetch_result($result, 0, "ref_id");
90
91 if (!$uuid) {
a42c55f0
AD
92 $uuid = db_escape_string(sha1(uniqid(rand(), true)));
93 db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param'
1baac280
AD
94 AND owner_uid = " . $_SESSION['uid']);
95 }
96
fcef9eea 97 print "<h2>". __("You can share this article by the following unique URL:") . "</h2>";
1baac280
AD
98
99 $url_path = get_self_url_prefix();
100 $url_path .= "/public.php?op=share&key=$uuid";
101
102 print "<div class=\"tagCloudContainer\">";
98d01eb1 103 print "<a id='gen_article_url' href='$url_path' target='_blank'>$url_path</a>";
1baac280
AD
104 print "</div>";
105
a42c55f0
AD
106 /* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
107 label_create(__('Shared'), $_SESSION["uid"]);
1baac280 108
a42c55f0 109 label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */
1baac280
AD
110 }
111
112 print "<div align='center'>";
113
98d01eb1
AD
114 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').unshare()\">".
115 __('Unshare article')."</button>";
116
117 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').newurl()\">".
118 __('Generate new URL')."</button>";
119
1baac280
AD
120 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
121 __('Close this window')."</button>";
122
123 print "</div>";
124 }
125
106a3de9
AD
126 function api_version() {
127 return 2;
128 }
1baac280
AD
129
130}
131?>