]> git.wh0rd.org - tt-rss.git/blob - modules/pref-instances.php
implement fetching and exporting of shared feeds
[tt-rss.git] / modules / pref-instances.php
1 <?php
2 function module_pref_instances($link) {
3
4 $subop = $_REQUEST['subop'];
5
6 if ($subop == "remove") {
7 $ids = db_escape_string($_REQUEST['ids']);
8
9 db_query($link, "DELETE FROM ttrss_linked_instances WHERE
10 id IN ($ids)");
11
12 return;
13 }
14
15 if ($subop == "add") {
16 $id = db_escape_string($_REQUEST["id"]);
17 $access_url = db_escape_string($_REQUEST["access_url"]);
18 $access_key = db_escape_string($_REQUEST["access_key"]);
19
20 db_query($link, "BEGIN");
21
22 $result = db_query($link, "SELECT id FROM ttrss_linked_instances
23 WHERE access_url = '$access_url'");
24
25 if (db_num_rows($result) == 0) {
26 db_query($link, "INSERT INTO ttrss_linked_instances
27 (access_url, access_key, last_connected, last_status_in, last_status_out)
28 VALUES
29 ('$access_url', '$access_key', '1970-01-01', -1, -1)");
30
31 }
32
33 db_query($link, "COMMIT");
34
35 return;
36 }
37
38 if ($subop == "edit") {
39
40 $id = db_escape_string($_REQUEST["id"]);
41
42 $result = db_query($link, "SELECT * FROM ttrss_linked_instances WHERE
43 id = '$id'");
44
45 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$id\">";
46 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-instances\">";
47 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"editSave\">";
48
49 print "<div class=\"dlgSec\">".__("Instance")."</div>";
50
51 print "<div class=\"dlgSecCont\">";
52
53 /* URL */
54
55 $access_url = htmlspecialchars(db_fetch_result($result, 0, "access_url"));
56
57 print __("URL:") . " ";
58
59 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
60 placeHolder=\"".__("Instance URL")."\"
61 regExp='^(http|https)://.*'
62 style=\"font-size : 16px; width: 20em\" name=\"access_url\"
63 value=\"$access_url\">";
64
65 print "<hr/>";
66
67 $access_key = htmlspecialchars(db_fetch_result($result, 0, "access_key"));
68
69 /* Access key */
70
71 print __("Access key:") . " ";
72
73 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
74 placeHolder=\"".__("Access key")."\" regExp='\w{40}'
75 style=\"width: 20em\" name=\"access_key\" id=\"instance_edit_key\"
76 value=\"$access_key\">";
77
78 print "<p class='insensitive'>" . __("Use one access key for both linked instances.");
79
80 print "</div>";
81
82 print "<div class=\"dlgButtons\">
83 <div style='float : left'>
84 <button dojoType=\"dijit.form.Button\"
85 onclick=\"return dijit.byId('instanceEditDlg').regenKey()\">".
86 __('Generate new key')."</button>
87 </div>
88 <button dojoType=\"dijit.form.Button\"
89 onclick=\"return dijit.byId('instanceEditDlg').execute()\">".
90 __('Save')."</button>
91 <button dojoType=\"dijit.form.Button\"
92 onclick=\"return dijit.byId('instanceEditDlg').hide()\"\">".
93 __('Cancel')."</button></div>";
94
95 return;
96 }
97
98 if ($subop == "editSave") {
99 $id = db_escape_string($_REQUEST["id"]);
100 $access_url = db_escape_string($_REQUEST["access_url"]);
101 $access_key = db_escape_string($_REQUEST["access_key"]);
102
103 db_query($link, "UPDATE ttrss_linked_instances SET
104 access_key = '$access_key', access_url = '$access_url',
105 last_connected = '1970-01-01'
106 WHERE id = '$id'");
107
108 return;
109 }
110
111 print "<div id=\"pref-instance-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
112 print "<div id=\"pref-instance-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
113
114 print "<div id=\"pref-instance-toolbar\" dojoType=\"dijit.Toolbar\">";
115
116 $sort = db_escape_string($_REQUEST["sort"]);
117
118 if (!$sort || $sort == "undefined") {
119 $sort = "access_url";
120 }
121
122 print "<div dojoType=\"dijit.form.DropDownButton\">".
123 "<span>" . __('Select')."</span>";
124 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
125 print "<div onclick=\"selectTableRows('prefInstanceList', 'all')\"
126 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
127 print "<div onclick=\"selectTableRows('prefInstanceList', 'none')\"
128 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
129 print "</div></div>";
130
131 print "<button dojoType=\"dijit.form.Button\" onclick=\"addInstance()\">".__('Link instance')."</button>";
132 print "<button dojoType=\"dijit.form.Button\" onclick=\"editSelectedInstance()\">".__('Edit')."</button>";
133 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedInstances()\">".__('Remove')."</button>";
134
135 print "</div>"; #toolbar
136
137 $result = db_query($link, "SELECT *,
138 (SELECT COUNT(*) FROM ttrss_linked_feeds
139 WHERE instance_id = ttrss_linked_instances.id) AS num_feeds
140 FROM ttrss_linked_instances
141 ORDER BY $sort");
142
143 print "<p class=\"insensitive\" style='margin-left : 1em;'>" . __("You can connect other instances of Tiny Tiny RSS to this one to share Popular feeds. Link to this instance of Tiny Tiny RSS by using this URL:");
144
145 print " <a href=\"#\" onclick=\"alert('".htmlspecialchars(get_self_url_prefix())."')\">(display url)</a>";
146
147 print "<p><table width='100%' id='prefInstanceList' class='prefInstanceList' cellspacing='0'>";
148
149 print "<tr class=\"title\">
150 <td align='center' width=\"5%\">&nbsp;</td>
151 <td width=''><a href=\"#\" onclick=\"updateInstanceList('access_url')\">".__('Instance URL')."</a></td>
152 <td width='20%'><a href=\"#\" onclick=\"updateInstanceList('access_key')\">".__('Access key')."</a></td>
153 <td width='10%'><a href=\"#\" onclick=\"updateUsersList('last_connected')\">".__('Last connected')."</a></td>
154 <td width='10%'><a href=\"#\" onclick=\"updateUsersList('num_feeds')\">".__('Stored feeds')."</a></td>
155 </tr>";
156
157 $lnum = 0;
158
159 while ($line = db_fetch_assoc($result)) {
160 $class = ($lnum % 2) ? "even" : "odd";
161
162 $id = $line['id'];
163 $this_row_id = "id=\"LIRR-$id\"";
164
165 $line["last_connected"] = make_local_datetime($link, $line["last_connected"], false);
166
167 print "<tr class=\"$class\" $this_row_id>";
168
169 print "<td align='center'><input onclick='toggleSelectRow(this);'
170 type=\"checkbox\" id=\"LICHK-$id\"></td>";
171
172 $onclick = "onclick='editInstance($id, event)' title='".__('Click to edit')."'";
173
174 $access_key = mb_substr($line['access_key'], 0, 4) . '...' .
175 mb_substr($line['access_key'], -4);
176
177 print "<td $onclick>" . htmlspecialchars($line['access_url']) . "</td>";
178 print "<td $onclick>" . htmlspecialchars($access_key) . "</td>";
179 print "<td $onclick>" . htmlspecialchars($line['last_connected']) . "</td>";
180 print "<td $onclick>" . htmlspecialchars($line['num_feeds']) . "</td>";
181
182 print "</tr>";
183
184 ++$lnum;
185 }
186
187 print "</table>";
188
189 print "</div>"; #pane
190 print "</div>"; #container
191
192 }
193 ?>