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