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