]> git.wh0rd.org - tt-rss.git/blame - plugins/share/init.php
Merge branch 'domdocument_content_savehtml' of wn/tt-rss into master
[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
73dfda1d 39 print "<p>" . __("You can disable all articles shared by unique URLs here.") . "</p>";
41a7a066 40
73dfda1d 41 print "<button class=\"danger\" dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
41a7a066
AD
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
98d01eb1
AD
58 function newkey() {
59 $id = db_escape_string($_REQUEST['id']);
60
3ceb893f 61 $uuid = db_escape_string(uniqid_short());
98d01eb1
AD
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
19c73507 69 function hook_article_button($line) {
abb04b76
AD
70 $img = $line['uuid'] ? "share.png" : "notshared.png";
71
72 return "<img id='SHARE-IMG-".$line['int_id']."' src=\"plugins/share/$img\"
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
21ce7d9e 81 $result = db_query("SELECT uuid 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");
1baac280
AD
89
90 if (!$uuid) {
3ceb893f 91 $uuid = db_escape_string(uniqid_short());
a42c55f0 92 db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param'
1baac280
AD
93 AND owner_uid = " . $_SESSION['uid']);
94 }
95
73dfda1d 96 print __("You can share this article by the following unique URL:") . "<br/>";
1baac280
AD
97
98 $url_path = get_self_url_prefix();
99 $url_path .= "/public.php?op=share&key=$uuid";
100
101 print "<div class=\"tagCloudContainer\">";
ba2853ca 102 print "<a id='gen_article_url' href='$url_path' target='_blank' rel='noopener noreferrer'>$url_path</a>";
1baac280
AD
103 print "</div>";
104
a42c55f0
AD
105 /* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
106 label_create(__('Shared'), $_SESSION["uid"]);
1baac280 107
a42c55f0 108 label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */
1baac280
AD
109 }
110
111 print "<div align='center'>";
112
98d01eb1
AD
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
1baac280
AD
119 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
120 __('Close this window')."</button>";
121
122 print "</div>";
123 }
124
106a3de9
AD
125 function api_version() {
126 return 2;
127 }
1baac280 128
21ce7d9e 129}