]> git.wh0rd.org Git - tt-rss.git/blob - plugins/share/init.php
a1b0146a1d2599fa133838466d53fb33c5810dac
[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         }
16
17         function get_js() {
18                 return file_get_contents(dirname(__FILE__) . "/share.js");
19         }
20
21         function unshare() {
22                 $id = db_escape_string($_REQUEST['id']);
23
24                 db_query("UPDATE ttrss_user_entries SET uuid = '' WHERE int_id = '$id'
25                         AND owner_uid = " . $_SESSION['uid']);
26
27                 print "OK";
28         }
29
30         function newkey() {
31                 $id = db_escape_string($_REQUEST['id']);
32
33                 $uuid = db_escape_string(sha1(uniqid(rand(), true)));
34
35                 db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$id'
36                         AND owner_uid = " . $_SESSION['uid']);
37
38                 print json_encode(array("link" => $uuid));
39         }
40
41         function hook_article_button($line) {
42                 return "<img src=\"plugins/share/share.png\"
43                         class='tagsPic' style=\"cursor : pointer\"
44                         onclick=\"shareArticle(".$line['int_id'].")\"
45                         title='".__('Share by URL')."'>";
46         }
47
48         function shareArticle() {
49                 $param = db_escape_string($_REQUEST['param']);
50
51                 $result = db_query("SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '$param'
52                         AND owner_uid = " . $_SESSION['uid']);
53
54                 if (db_num_rows($result) == 0) {
55                         print "Article not found.";
56                 } else {
57
58                         $uuid = db_fetch_result($result, 0, "uuid");
59                         $ref_id = db_fetch_result($result, 0, "ref_id");
60
61                         if (!$uuid) {
62                                 $uuid = db_escape_string(sha1(uniqid(rand(), true)));
63                                 db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param'
64                                         AND owner_uid = " . $_SESSION['uid']);
65                         }
66
67                         print "<h2>". __("You can share this article by the following unique URL:") . "</h2>";
68
69                         $url_path = get_self_url_prefix();
70                         $url_path .= "/public.php?op=share&key=$uuid";
71
72                         print "<div class=\"tagCloudContainer\">";
73                         print "<a id='gen_article_url' href='$url_path' target='_blank'>$url_path</a>";
74                         print "</div>";
75
76                         /* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
77                                 label_create(__('Shared'), $_SESSION["uid"]);
78
79                         label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */
80                 }
81
82                 print "<div align='center'>";
83
84                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').unshare()\">".
85                         __('Unshare article')."</button>";
86
87                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').newurl()\">".
88                         __('Generate new URL')."</button>";
89
90                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
91                         __('Close this window')."</button>";
92
93                 print "</div>";
94         }
95
96         function api_version() {
97                 return 2;
98         }
99
100 }
101 ?>