]>
Commit | Line | Data |
---|---|---|
afcfe6ca | 1 | <?php |
369dbc19 | 2 | class Pref_Feeds extends Handler_Protected { |
8484ce22 AD |
3 | |
4 | function csrf_ignore($method) { | |
f6cd767b | 5 | $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed", |
201bb1ca AD |
6 | "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds", |
7 | "batchsubscribe"); | |
8484ce22 AD |
8 | |
9 | return array_search($method, $csrf_ignored) !== false; | |
10 | } | |
11 | ||
afcfe6ca AD |
12 | function batch_edit_cbox($elem, $label = false) { |
13 | print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\" | |
14 | onchange=\"dijit.byId('feedEditDlg').toggleField(this, '$elem', '$label')\">"; | |
15 | } | |
16 | ||
17 | function renamecat() { | |
d9c85e0f AD |
18 | $title = $this->dbh->escape_string($_REQUEST['title']); |
19 | $id = $this->dbh->escape_string($_REQUEST['id']); | |
afcfe6ca AD |
20 | |
21 | if ($title) { | |
d9c85e0f | 22 | $this->dbh->query("UPDATE ttrss_feed_categories SET |
afcfe6ca AD |
23 | title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
24 | } | |
25 | return; | |
26 | } | |
27 | ||
2a060a94 | 28 | private function get_category_items($cat_id) { |
6e0ee833 AD |
29 | |
30 | if ($_REQUEST['mode'] != 2) | |
31 | $search = $_SESSION["prefs_feed_search"]; | |
32 | else | |
33 | $search = ""; | |
17c755f0 AD |
34 | |
35 | if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')"; | |
36 | ||
66ca7c30 AD |
37 | // first one is set by API |
38 | $show_empty_cats = $_REQUEST['force_show_empty'] || | |
39 | ($_REQUEST['mode'] != 2 && !$search && | |
a42c55f0 | 40 | get_pref('_PREFS_SHOW_EMPTY_CATS')); |
2a060a94 AD |
41 | |
42 | $items = array(); | |
43 | ||
d9c85e0f | 44 | $result = $this->dbh->query("SELECT id, title FROM ttrss_feed_categories |
2a060a94 AD |
45 | WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat = '$cat_id' ORDER BY order_id, title"); |
46 | ||
d9c85e0f | 47 | while ($line = $this->dbh->fetch_assoc($result)) { |
2a060a94 AD |
48 | |
49 | $cat = array(); | |
50 | $cat['id'] = 'CAT:' . $line['id']; | |
2ecd2df5 | 51 | $cat['bare_id'] = (int)$line['id']; |
2a060a94 AD |
52 | $cat['name'] = $line['title']; |
53 | $cat['items'] = array(); | |
54 | $cat['checkbox'] = false; | |
55 | $cat['type'] = 'category'; | |
2ecd2df5 | 56 | $cat['unread'] = 0; |
2c5f231e | 57 | $cat['child_unread'] = 0; |
2a060a94 AD |
58 | |
59 | $cat['items'] = $this->get_category_items($line['id']); | |
60 | ||
1a293f10 | 61 | $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
2a060a94 AD |
62 | |
63 | if (count($cat['items']) > 0 || $show_empty_cats) | |
64 | array_push($items, $cat); | |
65 | ||
66 | } | |
67 | ||
d9c85e0f | 68 | $feed_result = $this->dbh->query("SELECT id, title, last_error, |
2a060a94 AD |
69 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
70 | FROM ttrss_feeds | |
71 | WHERE cat_id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]. | |
72 | "$search_qpart ORDER BY order_id, title"); | |
73 | ||
d9c85e0f | 74 | while ($feed_line = $this->dbh->fetch_assoc($feed_result)) { |
2a060a94 AD |
75 | $feed = array(); |
76 | $feed['id'] = 'FEED:' . $feed_line['id']; | |
2ecd2df5 | 77 | $feed['bare_id'] = (int)$feed_line['id']; |
2a060a94 AD |
78 | $feed['name'] = $feed_line['title']; |
79 | $feed['checkbox'] = false; | |
2ecd2df5 | 80 | $feed['unread'] = 0; |
2a060a94 AD |
81 | $feed['error'] = $feed_line['last_error']; |
82 | $feed['icon'] = getFeedIcon($feed_line['id']); | |
6322ac79 | 83 | $feed['param'] = make_local_datetime( |
2a060a94 AD |
84 | $feed_line['last_updated'], true); |
85 | ||
86 | array_push($items, $feed); | |
87 | } | |
88 | ||
89 | return $items; | |
90 | } | |
91 | ||
afcfe6ca | 92 | function getfeedtree() { |
0bb5833b AD |
93 | print json_encode($this->makefeedtree()); |
94 | } | |
95 | ||
96 | function makefeedtree() { | |
afcfe6ca | 97 | |
6e0ee833 AD |
98 | if ($_REQUEST['mode'] != 2) |
99 | $search = $_SESSION["prefs_feed_search"]; | |
100 | else | |
101 | $search = ""; | |
afcfe6ca AD |
102 | |
103 | if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')"; | |
104 | ||
105 | $root = array(); | |
106 | $root['id'] = 'root'; | |
107 | $root['name'] = __('Feeds'); | |
108 | $root['items'] = array(); | |
109 | $root['type'] = 'category'; | |
110 | ||
a42c55f0 | 111 | $enable_cats = get_pref('ENABLE_FEED_CATS'); |
2ecd2df5 AD |
112 | |
113 | if ($_REQUEST['mode'] == 2) { | |
114 | ||
115 | if ($enable_cats) { | |
88918ca6 | 116 | $cat = $this->feedlist_init_cat(-1); |
2ecd2df5 AD |
117 | } else { |
118 | $cat['items'] = array(); | |
119 | } | |
120 | ||
5417fbd7 | 121 | foreach (array(-4, -3, -1, -2, 0, -6) as $i) { |
2ecd2df5 AD |
122 | array_push($cat['items'], $this->feedlist_init_feed($i)); |
123 | } | |
124 | ||
a413f53e AD |
125 | /* Plugin feeds for -1 */ |
126 | ||
1ffe3391 | 127 | $feeds = PluginHost::getInstance()->get_feeds(-1); |
a413f53e AD |
128 | |
129 | if ($feeds) { | |
130 | foreach ($feeds as $feed) { | |
131 | $feed_id = PluginHost::pfeed_to_feed_id($feed['id']); | |
132 | ||
133 | $item = array(); | |
134 | $item['id'] = 'FEED:' . $feed_id; | |
135 | $item['bare_id'] = (int)$feed_id; | |
136 | $item['name'] = $feed['title']; | |
137 | $item['checkbox'] = false; | |
138 | $item['error'] = ''; | |
139 | $item['icon'] = $feed['icon']; | |
140 | ||
141 | $item['param'] = ''; | |
142 | $item['unread'] = 0; //$feed['sender']->get_unread($feed['id']); | |
143 | $item['type'] = 'feed'; | |
144 | ||
145 | array_push($cat['items'], $item); | |
146 | } | |
147 | } | |
148 | ||
2ecd2df5 AD |
149 | if ($enable_cats) { |
150 | array_push($root['items'], $cat); | |
151 | } else { | |
152 | $root['items'] = array_merge($root['items'], $cat['items']); | |
153 | } | |
afcfe6ca | 154 | |
d9c85e0f | 155 | $result = $this->dbh->query("SELECT * FROM |
2ecd2df5 AD |
156 | ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption"); |
157 | ||
d9c85e0f | 158 | if ($this->dbh->num_rows($result) > 0) { |
2ecd2df5 | 159 | |
a42c55f0 | 160 | if (get_pref('ENABLE_FEED_CATS')) { |
88918ca6 | 161 | $cat = $this->feedlist_init_cat(-2); |
2ecd2df5 AD |
162 | } else { |
163 | $cat['items'] = array(); | |
164 | } | |
165 | ||
d9c85e0f | 166 | while ($line = $this->dbh->fetch_assoc($result)) { |
2ecd2df5 | 167 | |
f822a8e5 | 168 | $label_id = label_to_feed_id($line['id']); |
2ecd2df5 | 169 | |
88918ca6 | 170 | $feed = $this->feedlist_init_feed($label_id, false, 0); |
2ecd2df5 AD |
171 | |
172 | $feed['fg_color'] = $line['fg_color']; | |
173 | $feed['bg_color'] = $line['bg_color']; | |
174 | ||
175 | array_push($cat['items'], $feed); | |
176 | } | |
177 | ||
178 | if ($enable_cats) { | |
179 | array_push($root['items'], $cat); | |
180 | } else { | |
181 | $root['items'] = array_merge($root['items'], $cat['items']); | |
182 | } | |
183 | } | |
184 | } | |
185 | ||
186 | if ($enable_cats) { | |
66ca7c30 AD |
187 | $show_empty_cats = $_REQUEST['force_show_empty'] || |
188 | ($_REQUEST['mode'] != 2 && !$search && | |
a42c55f0 | 189 | get_pref('_PREFS_SHOW_EMPTY_CATS')); |
2ecd2df5 | 190 | |
d9c85e0f | 191 | $result = $this->dbh->query("SELECT id, title FROM ttrss_feed_categories |
2a060a94 | 192 | WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title"); |
afcfe6ca | 193 | |
d9c85e0f | 194 | while ($line = $this->dbh->fetch_assoc($result)) { |
afcfe6ca AD |
195 | $cat = array(); |
196 | $cat['id'] = 'CAT:' . $line['id']; | |
2ecd2df5 | 197 | $cat['bare_id'] = (int)$line['id']; |
afcfe6ca AD |
198 | $cat['name'] = $line['title']; |
199 | $cat['items'] = array(); | |
200 | $cat['checkbox'] = false; | |
201 | $cat['type'] = 'category'; | |
2ecd2df5 | 202 | $cat['unread'] = 0; |
2c5f231e | 203 | $cat['child_unread'] = 0; |
afcfe6ca | 204 | |
2a060a94 | 205 | $cat['items'] = $this->get_category_items($line['id']); |
afcfe6ca | 206 | |
1a293f10 | 207 | $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
afcfe6ca | 208 | |
5b7bd238 | 209 | if (count($cat['items']) > 0 || $show_empty_cats) |
afcfe6ca AD |
210 | array_push($root['items'], $cat); |
211 | ||
212 | $root['param'] += count($cat['items']); | |
213 | } | |
214 | ||
215 | /* Uncategorized is a special case */ | |
216 | ||
217 | $cat = array(); | |
218 | $cat['id'] = 'CAT:0'; | |
219 | $cat['bare_id'] = 0; | |
220 | $cat['name'] = __("Uncategorized"); | |
221 | $cat['items'] = array(); | |
222 | $cat['type'] = 'category'; | |
223 | $cat['checkbox'] = false; | |
2ecd2df5 | 224 | $cat['unread'] = 0; |
2c5f231e | 225 | $cat['child_unread'] = 0; |
afcfe6ca | 226 | |
d9c85e0f | 227 | $feed_result = $this->dbh->query("SELECT id, title,last_error, |
afcfe6ca AD |
228 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
229 | FROM ttrss_feeds | |
230 | WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"]. | |
231 | "$search_qpart ORDER BY order_id, title"); | |
232 | ||
d9c85e0f | 233 | while ($feed_line = $this->dbh->fetch_assoc($feed_result)) { |
afcfe6ca AD |
234 | $feed = array(); |
235 | $feed['id'] = 'FEED:' . $feed_line['id']; | |
2ecd2df5 | 236 | $feed['bare_id'] = (int)$feed_line['id']; |
afcfe6ca AD |
237 | $feed['name'] = $feed_line['title']; |
238 | $feed['checkbox'] = false; | |
239 | $feed['error'] = $feed_line['last_error']; | |
240 | $feed['icon'] = getFeedIcon($feed_line['id']); | |
6322ac79 | 241 | $feed['param'] = make_local_datetime( |
afcfe6ca | 242 | $feed_line['last_updated'], true); |
2ecd2df5 AD |
243 | $feed['unread'] = 0; |
244 | $feed['type'] = 'feed'; | |
afcfe6ca AD |
245 | |
246 | array_push($cat['items'], $feed); | |
247 | } | |
248 | ||
1a293f10 | 249 | $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
afcfe6ca | 250 | |
5b7bd238 | 251 | if (count($cat['items']) > 0 || $show_empty_cats) |
afcfe6ca AD |
252 | array_push($root['items'], $cat); |
253 | ||
254 | $root['param'] += count($cat['items']); | |
1a293f10 | 255 | $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
afcfe6ca AD |
256 | |
257 | } else { | |
d9c85e0f | 258 | $feed_result = $this->dbh->query("SELECT id, title, last_error, |
afcfe6ca AD |
259 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
260 | FROM ttrss_feeds | |
261 | WHERE owner_uid = ".$_SESSION["uid"]. | |
262 | "$search_qpart ORDER BY order_id, title"); | |
263 | ||
d9c85e0f | 264 | while ($feed_line = $this->dbh->fetch_assoc($feed_result)) { |
afcfe6ca AD |
265 | $feed = array(); |
266 | $feed['id'] = 'FEED:' . $feed_line['id']; | |
2ecd2df5 | 267 | $feed['bare_id'] = (int)$feed_line['id']; |
afcfe6ca AD |
268 | $feed['name'] = $feed_line['title']; |
269 | $feed['checkbox'] = false; | |
270 | $feed['error'] = $feed_line['last_error']; | |
271 | $feed['icon'] = getFeedIcon($feed_line['id']); | |
6322ac79 | 272 | $feed['param'] = make_local_datetime( |
afcfe6ca | 273 | $feed_line['last_updated'], true); |
2ecd2df5 AD |
274 | $feed['unread'] = 0; |
275 | $feed['type'] = 'feed'; | |
afcfe6ca AD |
276 | |
277 | array_push($root['items'], $feed); | |
278 | } | |
279 | ||
1a293f10 | 280 | $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
afcfe6ca AD |
281 | } |
282 | ||
283 | $fl = array(); | |
284 | $fl['identifier'] = 'id'; | |
285 | $fl['label'] = 'name'; | |
2ecd2df5 AD |
286 | |
287 | if ($_REQUEST['mode'] != 2) { | |
288 | $fl['items'] = array($root); | |
289 | } else { | |
290 | $fl['items'] =& $root['items']; | |
291 | } | |
afcfe6ca | 292 | |
0bb5833b | 293 | return $fl; |
afcfe6ca AD |
294 | } |
295 | ||
296 | function catsortreset() { | |
d9c85e0f | 297 | $this->dbh->query("UPDATE ttrss_feed_categories |
afcfe6ca AD |
298 | SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); |
299 | return; | |
300 | } | |
301 | ||
302 | function feedsortreset() { | |
d9c85e0f | 303 | $this->dbh->query("UPDATE ttrss_feeds |
afcfe6ca AD |
304 | SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); |
305 | return; | |
306 | } | |
307 | ||
5b7bd238 | 308 | function togglehiddenfeedcats() { |
a42c55f0 AD |
309 | set_pref('_PREFS_SHOW_EMPTY_CATS', |
310 | (get_pref('_PREFS_SHOW_EMPTY_CATS') ? 'false' : 'true')); | |
5b7bd238 AD |
311 | } |
312 | ||
95ee44b3 AD |
313 | private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) { |
314 | $debug = isset($_REQUEST["debug"]); | |
315 | ||
316 | $prefix = ""; | |
317 | for ($i = 0; $i < $nest_level; $i++) | |
318 | $prefix .= " "; | |
319 | ||
320 | if ($debug) _debug("$prefix C: $item_id P: $parent_id"); | |
321 | ||
322 | $bare_item_id = substr($item_id, strpos($item_id, ':')+1); | |
2a060a94 AD |
323 | |
324 | if ($item_id != 'root') { | |
325 | if ($parent_id && $parent_id != 'root') { | |
326 | $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1); | |
d9c85e0f | 327 | $parent_qpart = $this->dbh->escape_string($parent_bare_id); |
2a060a94 AD |
328 | } else { |
329 | $parent_qpart = 'NULL'; | |
330 | } | |
331 | ||
d9c85e0f | 332 | $this->dbh->query("UPDATE ttrss_feed_categories |
95ee44b3 | 333 | SET parent_cat = $parent_qpart WHERE id = '$bare_item_id' AND |
2a060a94 AD |
334 | owner_uid = " . $_SESSION["uid"]); |
335 | } | |
336 | ||
337 | $order_id = 0; | |
338 | ||
339 | $cat = $data_map[$item_id]; | |
340 | ||
341 | if ($cat && is_array($cat)) { | |
342 | foreach ($cat as $item) { | |
343 | $id = $item['_reference']; | |
344 | $bare_id = substr($id, strpos($id, ':')+1); | |
345 | ||
95ee44b3 | 346 | if ($debug) _debug("$prefix [$order_id] $id/$bare_id"); |
2a060a94 AD |
347 | |
348 | if ($item['_reference']) { | |
349 | ||
350 | if (strpos($id, "FEED") === 0) { | |
351 | ||
95ee44b3 | 352 | $cat_id = ($item_id != "root") ? |
d9c85e0f | 353 | $this->dbh->escape_string($bare_item_id) : "NULL"; |
95ee44b3 | 354 | |
49b2401e AD |
355 | $cat_qpart = ($cat_id != 0) ? "cat_id = '$cat_id'" : |
356 | "cat_id = NULL"; | |
357 | ||
d9c85e0f | 358 | $this->dbh->query("UPDATE ttrss_feeds |
49b2401e | 359 | SET order_id = $order_id, $cat_qpart |
95ee44b3 | 360 | WHERE id = '$bare_id' AND |
2a060a94 AD |
361 | owner_uid = " . $_SESSION["uid"]); |
362 | ||
363 | } else if (strpos($id, "CAT:") === 0) { | |
95ee44b3 AD |
364 | $this->process_category_order($data_map, $item['_reference'], $item_id, |
365 | $nest_level+1); | |
2a060a94 AD |
366 | |
367 | if ($item_id != 'root') { | |
d9c85e0f | 368 | $parent_qpart = $this->dbh->escape_string($bare_id); |
2a060a94 AD |
369 | } else { |
370 | $parent_qpart = 'NULL'; | |
371 | } | |
372 | ||
d9c85e0f | 373 | $this->dbh->query("UPDATE ttrss_feed_categories |
2a060a94 AD |
374 | SET order_id = '$order_id' WHERE id = '$bare_id' AND |
375 | owner_uid = " . $_SESSION["uid"]); | |
376 | } | |
377 | } | |
378 | ||
379 | ++$order_id; | |
380 | } | |
381 | } | |
382 | } | |
383 | ||
afcfe6ca AD |
384 | function savefeedorder() { |
385 | $data = json_decode($_POST['payload'], true); | |
386 | ||
2a060a94 AD |
387 | #file_put_contents("/tmp/saveorder.json", $_POST['payload']); |
388 | #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); | |
a26f57e6 | 389 | |
95ee44b3 AD |
390 | if (!is_array($data['items'])) |
391 | $data['items'] = json_decode($data['items'], true); | |
392 | ||
393 | # print_r($data['items']); | |
2a060a94 | 394 | |
afcfe6ca AD |
395 | if (is_array($data) && is_array($data['items'])) { |
396 | $cat_order_id = 0; | |
397 | ||
398 | $data_map = array(); | |
2a060a94 | 399 | $root_item = false; |
afcfe6ca AD |
400 | |
401 | foreach ($data['items'] as $item) { | |
402 | ||
2a060a94 | 403 | # if ($item['id'] != 'root') { |
afcfe6ca AD |
404 | if (is_array($item['items'])) { |
405 | if (isset($item['items']['_reference'])) { | |
406 | $data_map[$item['id']] = array($item['items']); | |
407 | } else { | |
408 | $data_map[$item['id']] =& $item['items']; | |
409 | } | |
410 | } | |
2a060a94 AD |
411 | if ($item['id'] == 'root') { |
412 | $root_item = $item['id']; | |
afcfe6ca AD |
413 | } |
414 | } | |
415 | ||
d04f8c82 | 416 | $this->process_category_order($data_map, $root_item); |
2a060a94 AD |
417 | |
418 | /* foreach ($data['items'][0]['items'] as $item) { | |
afcfe6ca AD |
419 | $id = $item['_reference']; |
420 | $bare_id = substr($id, strpos($id, ':')+1); | |
421 | ||
422 | ++$cat_order_id; | |
423 | ||
424 | if ($bare_id > 0) { | |
d9c85e0f | 425 | $this->dbh->query("UPDATE ttrss_feed_categories |
afcfe6ca AD |
426 | SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND |
427 | owner_uid = " . $_SESSION["uid"]); | |
428 | } | |
429 | ||
430 | $feed_order_id = 0; | |
431 | ||
432 | if (is_array($data_map[$id])) { | |
433 | foreach ($data_map[$id] as $feed) { | |
434 | $id = $feed['_reference']; | |
435 | $feed_id = substr($id, strpos($id, ':')+1); | |
436 | ||
437 | if ($bare_id != 0) | |
438 | $cat_query = "cat_id = '$bare_id'"; | |
439 | else | |
440 | $cat_query = "cat_id = NULL"; | |
441 | ||
d9c85e0f | 442 | $this->dbh->query("UPDATE ttrss_feeds |
afcfe6ca AD |
443 | SET order_id = '$feed_order_id', |
444 | $cat_query | |
445 | WHERE id = '$feed_id' AND | |
446 | owner_uid = " . $_SESSION["uid"]); | |
447 | ||
448 | ++$feed_order_id; | |
449 | } | |
450 | } | |
2a060a94 | 451 | } */ |
afcfe6ca AD |
452 | } |
453 | ||
454 | return; | |
455 | } | |
456 | ||
457 | function removeicon() { | |
d9c85e0f | 458 | $feed_id = $this->dbh->escape_string($_REQUEST["feed_id"]); |
afcfe6ca | 459 | |
d9c85e0f | 460 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds |
afcfe6ca AD |
461 | WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]); |
462 | ||
d9c85e0f | 463 | if ($this->dbh->num_rows($result) != 0) { |
3306daec | 464 | @unlink(ICONS_DIR . "/$feed_id.ico"); |
bc7a144d | 465 | |
d9c85e0f | 466 | $this->dbh->query("UPDATE ttrss_feeds SET favicon_avg_color = NULL |
bc7a144d | 467 | where id = '$feed_id'"); |
afcfe6ca AD |
468 | } |
469 | ||
470 | return; | |
471 | } | |
472 | ||
473 | function uploadicon() { | |
350e3944 AD |
474 | header("Content-type: text/html"); |
475 | ||
3306daec AD |
476 | $tmp_file = false; |
477 | ||
478 | if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) { | |
479 | $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon'); | |
480 | ||
481 | $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], | |
482 | $tmp_file); | |
483 | ||
484 | if (!$result) { | |
485 | return; | |
486 | } | |
487 | } else { | |
488 | return; | |
489 | } | |
490 | ||
491 | $icon_file = $tmp_file; | |
d9c85e0f | 492 | $feed_id = $this->dbh->escape_string($_REQUEST["feed_id"]); |
afcfe6ca AD |
493 | |
494 | if (is_file($icon_file) && $feed_id) { | |
495 | if (filesize($icon_file) < 20000) { | |
496 | ||
d9c85e0f | 497 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds |
afcfe6ca AD |
498 | WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]); |
499 | ||
d9c85e0f | 500 | if ($this->dbh->num_rows($result) != 0) { |
3306daec | 501 | @unlink(ICONS_DIR . "/$feed_id.ico"); |
bc7a144d AD |
502 | if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) { |
503 | ||
504 | require_once "colors.php"; | |
505 | ||
d9c85e0f | 506 | $favicon_color = $this->dbh->escape_string( |
bc7a144d AD |
507 | calculate_avg_color(ICONS_DIR . "/$feed_id.ico")); |
508 | ||
d9c85e0f | 509 | $this->dbh->query("UPDATE ttrss_feeds SET |
bc7a144d AD |
510 | favicon_avg_color = '$favicon_color' |
511 | WHERE id = '$feed_id'"); | |
512 | ||
513 | $rc = 0; | |
514 | } | |
afcfe6ca AD |
515 | } else { |
516 | $rc = 2; | |
517 | } | |
518 | } else { | |
519 | $rc = 1; | |
520 | } | |
521 | } else { | |
522 | $rc = 2; | |
523 | } | |
524 | ||
3306daec AD |
525 | @unlink($icon_file); |
526 | ||
afcfe6ca AD |
527 | print "<script type=\"text/javascript\">"; |
528 | print "parent.uploadIconHandler($rc);"; | |
529 | print "</script>"; | |
530 | return; | |
531 | } | |
532 | ||
533 | function editfeed() { | |
534 | global $purge_intervals; | |
535 | global $update_intervals; | |
afcfe6ca | 536 | |
d9c85e0f | 537 | $feed_id = $this->dbh->escape_string($_REQUEST["id"]); |
afcfe6ca | 538 | |
d9c85e0f | 539 | $result = $this->dbh->query( |
afcfe6ca AD |
540 | "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND |
541 | owner_uid = " . $_SESSION["uid"]); | |
542 | ||
d9c85e0f | 543 | $auth_pass_encrypted = sql_bool_to_bool($this->dbh->fetch_result($result, 0, |
044cff2d AD |
544 | "auth_pass_encrypted")); |
545 | ||
d9c85e0f | 546 | $title = htmlspecialchars($this->dbh->fetch_result($result, |
afcfe6ca AD |
547 | 0, "title")); |
548 | ||
549 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$feed_id\">"; | |
550 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">"; | |
551 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">"; | |
552 | ||
553 | print "<div class=\"dlgSec\">".__("Feed")."</div>"; | |
554 | print "<div class=\"dlgSecCont\">"; | |
555 | ||
556 | /* Title */ | |
557 | ||
558 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" | |
559 | placeHolder=\"".__("Feed Title")."\" | |
560 | style=\"font-size : 16px; width: 20em\" name=\"title\" value=\"$title\">"; | |
561 | ||
562 | /* Feed URL */ | |
563 | ||
d9c85e0f AD |
564 | $feed_url = $this->dbh->fetch_result($result, 0, "feed_url"); |
565 | $feed_url = htmlspecialchars($this->dbh->fetch_result($result, | |
afcfe6ca AD |
566 | 0, "feed_url")); |
567 | ||
568 | print "<hr/>"; | |
569 | ||
570 | print __('URL:') . " "; | |
571 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" | |
572 | placeHolder=\"".__("Feed URL")."\" | |
573 | regExp='^(http|https)://.*' style=\"width : 20em\" | |
574 | name=\"feed_url\" value=\"$feed_url\">"; | |
575 | ||
d9c85e0f | 576 | $last_error = $this->dbh->fetch_result($result, 0, "last_error"); |
afcfe6ca AD |
577 | |
578 | if ($last_error) { | |
579 | print " <span title=\"".htmlspecialchars($last_error)."\" | |
580 | class=\"feed_error\">(error)</span>"; | |
581 | ||
582 | } | |
583 | ||
584 | /* Category */ | |
585 | ||
a42c55f0 | 586 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca | 587 | |
d9c85e0f | 588 | $cat_id = $this->dbh->fetch_result($result, 0, "cat_id"); |
afcfe6ca AD |
589 | |
590 | print "<hr/>"; | |
591 | ||
592 | print __('Place in category:') . " "; | |
593 | ||
a42c55f0 | 594 | print_feed_cat_select("cat_id", $cat_id, |
afcfe6ca AD |
595 | 'dojoType="dijit.form.Select"'); |
596 | } | |
597 | ||
598 | print "</div>"; | |
599 | ||
600 | print "<div class=\"dlgSec\">".__("Update")."</div>"; | |
601 | print "<div class=\"dlgSecCont\">"; | |
602 | ||
603 | /* Update Interval */ | |
604 | ||
d9c85e0f | 605 | $update_interval = $this->dbh->fetch_result($result, 0, "update_interval"); |
afcfe6ca AD |
606 | |
607 | print_select_hash("update_interval", $update_interval, $update_intervals, | |
608 | 'dojoType="dijit.form.Select"'); | |
609 | ||
19b3992b | 610 | /* Purge intl */ |
afcfe6ca | 611 | |
d9c85e0f | 612 | $purge_interval = $this->dbh->fetch_result($result, 0, "purge_interval"); |
afcfe6ca | 613 | |
afcfe6ca AD |
614 | print "<hr/>"; |
615 | print __('Article purging:') . " "; | |
616 | ||
617 | print_select_hash("purge_interval", $purge_interval, $purge_intervals, | |
618 | 'dojoType="dijit.form.Select" ' . | |
619 | ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); | |
620 | ||
621 | print "</div>"; | |
622 | print "<div class=\"dlgSec\">".__("Authentication")."</div>"; | |
623 | print "<div class=\"dlgSecCont\">"; | |
624 | ||
d9c85e0f | 625 | $auth_login = htmlspecialchars($this->dbh->fetch_result($result, 0, "auth_login")); |
afcfe6ca AD |
626 | |
627 | print "<input dojoType=\"dijit.form.TextBox\" id=\"feedEditDlg_login\" | |
628 | placeHolder=\"".__("Login")."\" | |
629 | name=\"auth_login\" value=\"$auth_login\"><hr/>"; | |
630 | ||
d9c85e0f | 631 | $auth_pass = $this->dbh->fetch_result($result, 0, "auth_pass"); |
044cff2d AD |
632 | |
633 | if ($auth_pass_encrypted) { | |
634 | require_once "crypt.php"; | |
635 | $auth_pass = decrypt_string($auth_pass); | |
636 | } | |
637 | ||
638 | $auth_pass = htmlspecialchars($auth_pass); | |
afcfe6ca AD |
639 | |
640 | print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\" | |
641 | placeHolder=\"".__("Password")."\" | |
642 | value=\"$auth_pass\">"; | |
643 | ||
644 | print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedEditDlg_login\" position=\"below\"> | |
645 | ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')." | |
646 | </div>"; | |
647 | ||
648 | print "</div>"; | |
649 | print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
650 | print "<div class=\"dlgSecCont\">"; | |
651 | ||
d9c85e0f | 652 | $private = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "private")); |
afcfe6ca AD |
653 | |
654 | if ($private) { | |
655 | $checked = "checked=\"1\""; | |
656 | } else { | |
657 | $checked = ""; | |
658 | } | |
659 | ||
660 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\" | |
661 | $checked> <label for=\"private\">".__('Hide from Popular feeds')."</label>"; | |
662 | ||
d9c85e0f | 663 | $include_in_digest = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "include_in_digest")); |
afcfe6ca AD |
664 | |
665 | if ($include_in_digest) { | |
666 | $checked = "checked=\"1\""; | |
667 | } else { | |
668 | $checked = ""; | |
669 | } | |
670 | ||
671 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\" | |
672 | name=\"include_in_digest\" | |
673 | $checked> <label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; | |
674 | ||
675 | ||
d9c85e0f | 676 | $always_display_enclosures = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "always_display_enclosures")); |
afcfe6ca AD |
677 | |
678 | if ($always_display_enclosures) { | |
679 | $checked = "checked"; | |
680 | } else { | |
681 | $checked = ""; | |
682 | } | |
683 | ||
684 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\" | |
685 | name=\"always_display_enclosures\" | |
686 | $checked> <label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; | |
687 | ||
d9c85e0f | 688 | $hide_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "hide_images")); |
bfd61d3f AD |
689 | |
690 | if ($hide_images) { | |
691 | $checked = "checked=\"1\""; | |
692 | } else { | |
693 | $checked = ""; | |
694 | } | |
695 | ||
696 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"hide_images\" | |
697 | name=\"hide_images\" | |
698 | $checked> <label for=\"hide_images\">". | |
699 | __('Do not embed images')."</label>"; | |
afcfe6ca | 700 | |
d9c85e0f | 701 | $cache_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "cache_images")); |
afcfe6ca AD |
702 | |
703 | if ($cache_images) { | |
704 | $checked = "checked=\"1\""; | |
705 | } else { | |
706 | $checked = ""; | |
707 | } | |
708 | ||
3c696512 AD |
709 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\" |
710 | name=\"cache_images\" | |
afcfe6ca | 711 | $checked> <label for=\"cache_images\">". |
3c696512 | 712 | __('Cache images locally')."</label>"; |
afcfe6ca | 713 | |
d9c85e0f | 714 | $mark_unread_on_update = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "mark_unread_on_update")); |
afcfe6ca AD |
715 | |
716 | if ($mark_unread_on_update) { | |
717 | $checked = "checked"; | |
718 | } else { | |
719 | $checked = ""; | |
720 | } | |
721 | ||
722 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\" | |
723 | name=\"mark_unread_on_update\" | |
724 | $checked> <label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>"; | |
725 | ||
afcfe6ca AD |
726 | print "</div>"; |
727 | ||
728 | /* Icon */ | |
729 | ||
730 | print "<div class=\"dlgSec\">".__("Icon")."</div>"; | |
731 | print "<div class=\"dlgSecCont\">"; | |
732 | ||
733 | print "<iframe name=\"icon_upload_iframe\" | |
734 | style=\"width: 400px; height: 100px; display: none;\"></iframe>"; | |
735 | ||
736 | print "<form style='display : block' target=\"icon_upload_iframe\" | |
737 | enctype=\"multipart/form-data\" method=\"POST\" | |
738 | action=\"backend.php\"> | |
739 | <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\"> | |
740 | <input type=\"hidden\" name=\"op\" value=\"pref-feeds\"> | |
741 | <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\"> | |
742 | <input type=\"hidden\" name=\"method\" value=\"uploadicon\"> | |
743 | <button dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\" | |
744 | type=\"submit\">".__('Replace')."</button> | |
745 | <button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\" | |
746 | type=\"submit\">".__('Remove')."</button> | |
747 | </form>"; | |
748 | ||
749 | print "</div>"; | |
750 | ||
057177eb AD |
751 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, |
752 | "hook_prefs_edit_feed", $feed_id); | |
753 | ||
afcfe6ca AD |
754 | $title = htmlspecialchars($title, ENT_QUOTES); |
755 | ||
756 | print "<div class='dlgButtons'> | |
757 | <div style=\"float : left\"> | |
758 | <button dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>". | |
759 | __('Unsubscribe')."</button>"; | |
760 | ||
761 | if (PUBSUBHUBBUB_ENABLED) { | |
d9c85e0f | 762 | $pubsub_state = $this->dbh->fetch_result($result, 0, "pubsub_state"); |
afcfe6ca AD |
763 | $pubsub_btn_disabled = ($pubsub_state == 2) ? "" : "disabled=\"1\""; |
764 | ||
765 | print "<button dojoType=\"dijit.form.Button\" id=\"pubsubReset_Btn\" $pubsub_btn_disabled | |
766 | onclick='return resetPubSub($feed_id, \"$title\")'>".__('Resubscribe to push updates'). | |
767 | "</button>"; | |
768 | } | |
769 | ||
770 | print "</div>"; | |
771 | ||
772 | print "<div dojoType=\"dijit.Tooltip\" connectId=\"pubsubReset_Btn\" position=\"below\">". | |
773 | __('Resets PubSubHubbub subscription status for push-enabled feeds.')."</div>"; | |
774 | ||
775 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button> | |
776 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button> | |
777 | </div>"; | |
778 | ||
779 | return; | |
780 | } | |
781 | ||
782 | function editfeeds() { | |
783 | global $purge_intervals; | |
784 | global $update_intervals; | |
46da73c2 | 785 | |
d9c85e0f | 786 | $feed_ids = $this->dbh->escape_string($_REQUEST["ids"]); |
afcfe6ca | 787 | |
fcef9eea AD |
788 | print_notice("Enable the options you wish to apply using checkboxes on the right:"); |
789 | ||
790 | print "<p>"; | |
ca6a0741 | 791 | |
afcfe6ca AD |
792 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"$feed_ids\">"; |
793 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">"; | |
794 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchEditSave\">"; | |
795 | ||
796 | print "<div class=\"dlgSec\">".__("Feed")."</div>"; | |
797 | print "<div class=\"dlgSecCont\">"; | |
798 | ||
799 | /* Title */ | |
800 | ||
801 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
802 | disabled=\"1\" style=\"font-size : 16px; width : 20em;\" required=\"1\" | |
803 | name=\"title\" value=\"$title\">"; | |
804 | ||
805 | $this->batch_edit_cbox("title"); | |
806 | ||
807 | /* Feed URL */ | |
808 | ||
809 | print "<br/>"; | |
810 | ||
811 | print __('URL:') . " "; | |
812 | print "<input dojoType=\"dijit.form.ValidationTextBox\" disabled=\"1\" | |
813 | required=\"1\" regExp='^(http|https)://.*' style=\"width : 20em\" | |
814 | name=\"feed_url\" value=\"$feed_url\">"; | |
815 | ||
816 | $this->batch_edit_cbox("feed_url"); | |
817 | ||
818 | /* Category */ | |
819 | ||
a42c55f0 | 820 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca AD |
821 | |
822 | print "<br/>"; | |
823 | ||
824 | print __('Place in category:') . " "; | |
825 | ||
a42c55f0 | 826 | print_feed_cat_select("cat_id", $cat_id, |
afcfe6ca AD |
827 | 'disabled="1" dojoType="dijit.form.Select"'); |
828 | ||
829 | $this->batch_edit_cbox("cat_id"); | |
830 | ||
831 | } | |
832 | ||
833 | print "</div>"; | |
834 | ||
835 | print "<div class=\"dlgSec\">".__("Update")."</div>"; | |
836 | print "<div class=\"dlgSecCont\">"; | |
837 | ||
838 | /* Update Interval */ | |
839 | ||
840 | print_select_hash("update_interval", $update_interval, $update_intervals, | |
841 | 'disabled="1" dojoType="dijit.form.Select"'); | |
842 | ||
843 | $this->batch_edit_cbox("update_interval"); | |
844 | ||
afcfe6ca AD |
845 | /* Purge intl */ |
846 | ||
847 | if (FORCE_ARTICLE_PURGE == 0) { | |
848 | ||
849 | print "<br/>"; | |
850 | ||
851 | print __('Article purging:') . " "; | |
852 | ||
853 | print_select_hash("purge_interval", $purge_interval, $purge_intervals, | |
854 | 'disabled="1" dojoType="dijit.form.Select"'); | |
855 | ||
856 | $this->batch_edit_cbox("purge_interval"); | |
857 | } | |
858 | ||
859 | print "</div>"; | |
860 | print "<div class=\"dlgSec\">".__("Authentication")."</div>"; | |
861 | print "<div class=\"dlgSecCont\">"; | |
862 | ||
863 | print "<input dojoType=\"dijit.form.TextBox\" | |
864 | placeHolder=\"".__("Login")."\" disabled=\"1\" | |
865 | name=\"auth_login\" value=\"$auth_login\">"; | |
866 | ||
867 | $this->batch_edit_cbox("auth_login"); | |
868 | ||
869 | print "<br/><input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\" | |
870 | placeHolder=\"".__("Password")."\" disabled=\"1\" | |
871 | value=\"$auth_pass\">"; | |
872 | ||
873 | $this->batch_edit_cbox("auth_pass"); | |
874 | ||
875 | print "</div>"; | |
876 | print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
877 | print "<div class=\"dlgSecCont\">"; | |
878 | ||
879 | print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\" | |
880 | dojoType=\"dijit.form.CheckBox\"> <label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>"; | |
881 | ||
882 | print " "; $this->batch_edit_cbox("private", "private_l"); | |
883 | ||
afcfe6ca AD |
884 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\" |
885 | name=\"include_in_digest\" | |
886 | dojoType=\"dijit.form.CheckBox\"> <label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; | |
887 | ||
888 | print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l"); | |
889 | ||
890 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\" | |
891 | name=\"always_display_enclosures\" | |
892 | dojoType=\"dijit.form.CheckBox\"> <label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; | |
893 | ||
894 | print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l"); | |
895 | ||
bfd61d3f AD |
896 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"hide_images\" |
897 | name=\"hide_images\" | |
898 | dojoType=\"dijit.form.CheckBox\"> <label class='insensitive' id=\"hide_images_l\" | |
899 | for=\"hide_images\">". | |
900 | __('Do not embed images')."</label>"; | |
901 | ||
902 | print " "; $this->batch_edit_cbox("hide_images", "hide_images_l"); | |
903 | ||
3c696512 AD |
904 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\" |
905 | name=\"cache_images\" | |
906 | dojoType=\"dijit.form.CheckBox\"> <label class='insensitive' id=\"cache_images_l\" | |
907 | for=\"cache_images\">". | |
908 | __('Cache images locally')."</label>"; | |
afcfe6ca | 909 | |
3c696512 | 910 | print " "; $this->batch_edit_cbox("cache_images", "cache_images_l"); |
afcfe6ca AD |
911 | |
912 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\" | |
913 | name=\"mark_unread_on_update\" | |
914 | dojoType=\"dijit.form.CheckBox\"> <label id=\"mark_unread_on_update_l\" class='insensitive' for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>"; | |
915 | ||
916 | print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l"); | |
917 | ||
afcfe6ca AD |
918 | print "</div>"; |
919 | ||
920 | print "<div class='dlgButtons'> | |
921 | <button dojoType=\"dijit.form.Button\" | |
922 | onclick=\"return dijit.byId('feedEditDlg').execute()\">". | |
923 | __('Save')."</button> | |
924 | <button dojoType=\"dijit.form.Button\" | |
925 | onclick=\"return dijit.byId('feedEditDlg').hide()\">". | |
926 | __('Cancel')."</button> | |
927 | </div>"; | |
928 | ||
929 | return; | |
930 | } | |
931 | ||
932 | function batchEditSave() { | |
3a76e2a2 | 933 | return $this->editsaveops(true); |
afcfe6ca | 934 | } |
46da73c2 | 935 | |
afcfe6ca | 936 | function editSave() { |
3a76e2a2 | 937 | return $this->editsaveops(false); |
afcfe6ca | 938 | } |
46da73c2 AD |
939 | |
940 | function editsaveops($batch) { | |
941 | ||
d9c85e0f AD |
942 | $feed_title = $this->dbh->escape_string(trim($_POST["title"])); |
943 | $feed_link = $this->dbh->escape_string(trim($_POST["feed_url"])); | |
944 | $upd_intl = (int) $this->dbh->escape_string($_POST["update_interval"]); | |
945 | $purge_intl = (int) $this->dbh->escape_string($_POST["purge_interval"]); | |
946 | $feed_id = (int) $this->dbh->escape_string($_POST["id"]); /* editSave */ | |
947 | $feed_ids = $this->dbh->escape_string($_POST["ids"]); /* batchEditSave */ | |
948 | $cat_id = (int) $this->dbh->escape_string($_POST["cat_id"]); | |
949 | $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"])); | |
41694a95 | 950 | $auth_pass = trim($_POST["auth_pass"]); |
d9c85e0f | 951 | $private = checkbox_to_sql_bool($this->dbh->escape_string($_POST["private"])); |
afcfe6ca | 952 | $include_in_digest = checkbox_to_sql_bool( |
d9c85e0f | 953 | $this->dbh->escape_string($_POST["include_in_digest"])); |
afcfe6ca | 954 | $cache_images = checkbox_to_sql_bool( |
d9c85e0f | 955 | $this->dbh->escape_string($_POST["cache_images"])); |
bfd61d3f | 956 | $hide_images = checkbox_to_sql_bool( |
d9c85e0f | 957 | $this->dbh->escape_string($_POST["hide_images"])); |
afcfe6ca | 958 | $always_display_enclosures = checkbox_to_sql_bool( |
d9c85e0f | 959 | $this->dbh->escape_string($_POST["always_display_enclosures"])); |
afcfe6ca AD |
960 | |
961 | $mark_unread_on_update = checkbox_to_sql_bool( | |
d9c85e0f | 962 | $this->dbh->escape_string($_POST["mark_unread_on_update"])); |
afcfe6ca | 963 | |
044cff2d AD |
964 | if (strlen(FEED_CRYPT_KEY) > 0) { |
965 | require_once "crypt.php"; | |
966 | $auth_pass = substr(encrypt_string($auth_pass), 0, 250); | |
967 | $auth_pass_encrypted = 'true'; | |
968 | } else { | |
969 | $auth_pass_encrypted = 'false'; | |
970 | } | |
971 | ||
d9c85e0f | 972 | $auth_pass = $this->dbh->escape_string($auth_pass); |
41694a95 | 973 | |
a42c55f0 | 974 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca AD |
975 | if ($cat_id && $cat_id != 0) { |
976 | $category_qpart = "cat_id = '$cat_id',"; | |
977 | $category_qpart_nocomma = "cat_id = '$cat_id'"; | |
978 | } else { | |
979 | $category_qpart = 'cat_id = NULL,'; | |
980 | $category_qpart_nocomma = 'cat_id = NULL'; | |
981 | } | |
982 | } else { | |
983 | $category_qpart = ""; | |
984 | $category_qpart_nocomma = ""; | |
985 | } | |
986 | ||
3a76e2a2 | 987 | if (!$batch) { |
afcfe6ca | 988 | |
d9c85e0f | 989 | $result = $this->dbh->query("UPDATE ttrss_feeds SET |
afcfe6ca AD |
990 | $category_qpart |
991 | title = '$feed_title', feed_url = '$feed_link', | |
992 | update_interval = '$upd_intl', | |
993 | purge_interval = '$purge_intl', | |
994 | auth_login = '$auth_login', | |
995 | auth_pass = '$auth_pass', | |
044cff2d | 996 | auth_pass_encrypted = $auth_pass_encrypted, |
afcfe6ca | 997 | private = $private, |
87764a50 | 998 | cache_images = $cache_images, |
bfd61d3f | 999 | hide_images = $hide_images, |
afcfe6ca AD |
1000 | include_in_digest = $include_in_digest, |
1001 | always_display_enclosures = $always_display_enclosures, | |
5321e775 | 1002 | mark_unread_on_update = $mark_unread_on_update |
19b3992b | 1003 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); |
afcfe6ca | 1004 | |
8cefe38a AD |
1005 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, |
1006 | "hook_prefs_save_feed", $feed_id); | |
1007 | ||
3a76e2a2 | 1008 | } else { |
afcfe6ca AD |
1009 | $feed_data = array(); |
1010 | ||
1011 | foreach (array_keys($_POST) as $k) { | |
1012 | if ($k != "op" && $k != "method" && $k != "ids") { | |
1013 | $feed_data[$k] = $_POST[$k]; | |
1014 | } | |
1015 | } | |
1016 | ||
d9c85e0f | 1017 | $this->dbh->query("BEGIN"); |
afcfe6ca AD |
1018 | |
1019 | foreach (array_keys($feed_data) as $k) { | |
1020 | ||
1021 | $qpart = ""; | |
1022 | ||
1023 | switch ($k) { | |
1024 | case "title": | |
1025 | $qpart = "title = '$feed_title'"; | |
1026 | break; | |
1027 | ||
1028 | case "feed_url": | |
1029 | $qpart = "feed_url = '$feed_link'"; | |
1030 | break; | |
1031 | ||
1032 | case "update_interval": | |
1033 | $qpart = "update_interval = '$upd_intl'"; | |
1034 | break; | |
1035 | ||
1036 | case "purge_interval": | |
1037 | $qpart = "purge_interval = '$purge_intl'"; | |
1038 | break; | |
1039 | ||
1040 | case "auth_login": | |
1041 | $qpart = "auth_login = '$auth_login'"; | |
1042 | break; | |
1043 | ||
1044 | case "auth_pass": | |
044cff2d AD |
1045 | $qpart = "auth_pass = '$auth_pass' AND |
1046 | auth_pass_encrypted = $auth_pass_encrypted"; | |
afcfe6ca AD |
1047 | break; |
1048 | ||
1049 | case "private": | |
a498d18b | 1050 | $qpart = "private = $private"; |
afcfe6ca AD |
1051 | break; |
1052 | ||
1053 | case "include_in_digest": | |
a498d18b | 1054 | $qpart = "include_in_digest = $include_in_digest"; |
afcfe6ca AD |
1055 | break; |
1056 | ||
1057 | case "always_display_enclosures": | |
a498d18b | 1058 | $qpart = "always_display_enclosures = $always_display_enclosures"; |
afcfe6ca AD |
1059 | break; |
1060 | ||
1061 | case "mark_unread_on_update": | |
a498d18b | 1062 | $qpart = "mark_unread_on_update = $mark_unread_on_update"; |
afcfe6ca AD |
1063 | break; |
1064 | ||
afcfe6ca | 1065 | case "cache_images": |
a498d18b | 1066 | $qpart = "cache_images = $cache_images"; |
afcfe6ca AD |
1067 | break; |
1068 | ||
bfd61d3f AD |
1069 | case "hide_images": |
1070 | $qpart = "hide_images = $hide_images"; | |
1071 | break; | |
1072 | ||
afcfe6ca AD |
1073 | case "cat_id": |
1074 | $qpart = $category_qpart_nocomma; | |
1075 | break; | |
1076 | ||
1077 | } | |
1078 | ||
1079 | if ($qpart) { | |
d9c85e0f | 1080 | $this->dbh->query( |
afcfe6ca AD |
1081 | "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids) |
1082 | AND owner_uid = " . $_SESSION["uid"]); | |
1083 | print "<br/>"; | |
1084 | } | |
1085 | } | |
1086 | ||
d9c85e0f | 1087 | $this->dbh->query("COMMIT"); |
afcfe6ca AD |
1088 | } |
1089 | return; | |
1090 | } | |
1091 | ||
1092 | function resetPubSub() { | |
1093 | ||
d9c85e0f | 1094 | $ids = $this->dbh->escape_string($_REQUEST["ids"]); |
afcfe6ca | 1095 | |
d9c85e0f | 1096 | $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ($ids) |
afcfe6ca AD |
1097 | AND owner_uid = " . $_SESSION["uid"]); |
1098 | ||
1099 | return; | |
1100 | } | |
1101 | ||
1102 | function remove() { | |
1103 | ||
d9c85e0f | 1104 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
afcfe6ca AD |
1105 | |
1106 | foreach ($ids as $id) { | |
a42c55f0 | 1107 | Pref_Feeds::remove_feed($id, $_SESSION["uid"]); |
afcfe6ca AD |
1108 | } |
1109 | ||
1110 | return; | |
1111 | } | |
1112 | ||
1113 | function clear() { | |
d9c85e0f | 1114 | $id = $this->dbh->escape_string($_REQUEST["id"]); |
a42c55f0 | 1115 | $this->clear_feed_articles($id); |
afcfe6ca AD |
1116 | } |
1117 | ||
1118 | function rescore() { | |
92c14e9d AD |
1119 | require_once "rssfuncs.php"; |
1120 | ||
d9c85e0f | 1121 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
afcfe6ca AD |
1122 | |
1123 | foreach ($ids as $id) { | |
1124 | ||
a42c55f0 | 1125 | $filters = load_filters($id, $_SESSION["uid"], 6); |
afcfe6ca | 1126 | |
d9c85e0f | 1127 | $result = $this->dbh->query("SELECT |
afcfe6ca AD |
1128 | title, content, link, ref_id, author,". |
1129 | SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated | |
1130 | FROM | |
1131 | ttrss_user_entries, ttrss_entries | |
1132 | WHERE ref_id = id AND feed_id = '$id' AND | |
1133 | owner_uid = " .$_SESSION['uid']." | |
1134 | "); | |
1135 | ||
1136 | $scores = array(); | |
1137 | ||
d9c85e0f | 1138 | while ($line = $this->dbh->fetch_assoc($result)) { |
afcfe6ca | 1139 | |
a42c55f0 | 1140 | $tags = get_article_tags($line["ref_id"]); |
afcfe6ca AD |
1141 | |
1142 | $article_filters = get_article_filters($filters, $line['title'], | |
1143 | $line['content'], $line['link'], strtotime($line['updated']), | |
1144 | $line['author'], $tags); | |
1145 | ||
1146 | $new_score = calculate_article_score($article_filters); | |
1147 | ||
1148 | if (!$scores[$new_score]) $scores[$new_score] = array(); | |
1149 | ||
1150 | array_push($scores[$new_score], $line['ref_id']); | |
1151 | } | |
1152 | ||
1153 | foreach (array_keys($scores) as $s) { | |
1154 | if ($s > 1000) { | |
d9c85e0f | 1155 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s', |
afcfe6ca AD |
1156 | marked = true WHERE |
1157 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1158 | } else if ($s < -500) { | |
d9c85e0f | 1159 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s', |
afcfe6ca AD |
1160 | unread = false WHERE |
1161 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1162 | } else { | |
d9c85e0f | 1163 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE |
afcfe6ca AD |
1164 | ref_id IN (" . join(',', $scores[$s]) . ")"); |
1165 | } | |
1166 | } | |
1167 | } | |
1168 | ||
1169 | print __("All done."); | |
1170 | ||
1171 | } | |
1172 | ||
1173 | function rescoreAll() { | |
1174 | ||
d9c85e0f | 1175 | $result = $this->dbh->query( |
afcfe6ca AD |
1176 | "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']); |
1177 | ||
d9c85e0f | 1178 | while ($feed_line = $this->dbh->fetch_assoc($result)) { |
afcfe6ca AD |
1179 | |
1180 | $id = $feed_line["id"]; | |
1181 | ||
a42c55f0 | 1182 | $filters = load_filters($id, $_SESSION["uid"], 6); |
afcfe6ca | 1183 | |
d9c85e0f | 1184 | $tmp_result = $this->dbh->query("SELECT |
afcfe6ca AD |
1185 | title, content, link, ref_id, author,". |
1186 | SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated | |
1187 | FROM | |
1188 | ttrss_user_entries, ttrss_entries | |
1189 | WHERE ref_id = id AND feed_id = '$id' AND | |
1190 | owner_uid = " .$_SESSION['uid']." | |
1191 | "); | |
1192 | ||
1193 | $scores = array(); | |
1194 | ||
d9c85e0f | 1195 | while ($line = $this->dbh->fetch_assoc($tmp_result)) { |
afcfe6ca | 1196 | |
a42c55f0 | 1197 | $tags = get_article_tags($line["ref_id"]); |
afcfe6ca AD |
1198 | |
1199 | $article_filters = get_article_filters($filters, $line['title'], | |
1200 | $line['content'], $line['link'], strtotime($line['updated']), | |
1201 | $line['author'], $tags); | |
1202 | ||
1203 | $new_score = calculate_article_score($article_filters); | |
1204 | ||
1205 | if (!$scores[$new_score]) $scores[$new_score] = array(); | |
1206 | ||
1207 | array_push($scores[$new_score], $line['ref_id']); | |
1208 | } | |
1209 | ||
1210 | foreach (array_keys($scores) as $s) { | |
1211 | if ($s > 1000) { | |
d9c85e0f | 1212 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s', |
afcfe6ca AD |
1213 | marked = true WHERE |
1214 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1215 | } else { | |
d9c85e0f | 1216 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE |
afcfe6ca AD |
1217 | ref_id IN (" . join(',', $scores[$s]) . ")"); |
1218 | } | |
1219 | } | |
1220 | } | |
1221 | ||
1222 | print __("All done."); | |
1223 | ||
1224 | } | |
1225 | ||
afcfe6ca | 1226 | function categorize() { |
d9c85e0f | 1227 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
afcfe6ca | 1228 | |
d9c85e0f | 1229 | $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]); |
afcfe6ca AD |
1230 | |
1231 | if ($cat_id == 0) { | |
1232 | $cat_id_qpart = 'NULL'; | |
1233 | } else { | |
1234 | $cat_id_qpart = "'$cat_id'"; | |
1235 | } | |
1236 | ||
d9c85e0f | 1237 | $this->dbh->query("BEGIN"); |
afcfe6ca AD |
1238 | |
1239 | foreach ($ids as $id) { | |
1240 | ||
d9c85e0f | 1241 | $this->dbh->query("UPDATE ttrss_feeds SET cat_id = $cat_id_qpart |
afcfe6ca AD |
1242 | WHERE id = '$id' |
1243 | AND owner_uid = " . $_SESSION["uid"]); | |
1244 | ||
1245 | } | |
1246 | ||
d9c85e0f | 1247 | $this->dbh->query("COMMIT"); |
afcfe6ca AD |
1248 | } |
1249 | ||
28537341 | 1250 | function removeCat() { |
d9c85e0f | 1251 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
28537341 | 1252 | foreach ($ids as $id) { |
a42c55f0 | 1253 | $this->remove_feed_category($id, $_SESSION["uid"]); |
28537341 AD |
1254 | } |
1255 | } | |
1256 | ||
1257 | function addCat() { | |
d9c85e0f | 1258 | $feed_cat = $this->dbh->escape_string(trim($_REQUEST["cat"])); |
28537341 | 1259 | |
a42c55f0 | 1260 | add_feed_category($feed_cat); |
28537341 AD |
1261 | } |
1262 | ||
afcfe6ca AD |
1263 | function index() { |
1264 | ||
1265 | print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">"; | |
1266 | print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">"; | |
1267 | ||
d9c85e0f | 1268 | $result = $this->dbh->query("SELECT COUNT(id) AS num_errors |
afcfe6ca AD |
1269 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); |
1270 | ||
d9c85e0f | 1271 | $num_errors = $this->dbh->fetch_result($result, 0, "num_errors"); |
afcfe6ca AD |
1272 | |
1273 | if ($num_errors > 0) { | |
1274 | ||
1275 | $error_button = "<button dojoType=\"dijit.form.Button\" | |
1276 | onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" . | |
1277 | __("Feeds with errors") . "</button>"; | |
1278 | } | |
1279 | ||
1280 | if (DB_TYPE == "pgsql") { | |
1281 | $interval_qpart = "NOW() - INTERVAL '3 months'"; | |
1282 | } else { | |
1283 | $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; | |
1284 | } | |
1285 | ||
d9c85e0f | 1286 | $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE |
afcfe6ca AD |
1287 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE |
1288 | ttrss_entries.id = ref_id AND | |
1289 | ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND | |
1290 | ttrss_feeds.owner_uid = ".$_SESSION["uid"]); | |
1291 | ||
d9c85e0f | 1292 | $num_inactive = $this->dbh->fetch_result($result, 0, "num_inactive"); |
afcfe6ca AD |
1293 | |
1294 | if ($num_inactive > 0) { | |
1295 | $inactive_button = "<button dojoType=\"dijit.form.Button\" | |
1296 | onclick=\"showInactiveFeeds()\">" . | |
1297 | __("Inactive feeds") . "</button>"; | |
1298 | } | |
1299 | ||
d9c85e0f | 1300 | $feed_search = $this->dbh->escape_string($_REQUEST["search"]); |
afcfe6ca AD |
1301 | |
1302 | if (array_key_exists("search", $_REQUEST)) { | |
1303 | $_SESSION["prefs_feed_search"] = $feed_search; | |
1304 | } else { | |
1305 | $feed_search = $_SESSION["prefs_feed_search"]; | |
1306 | } | |
1307 | ||
1308 | print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; | |
1309 | ||
1310 | print "<div region='top' dojoType=\"dijit.Toolbar\">"; #toolbar | |
1311 | ||
1312 | print "<div style='float : right; padding-right : 4px;'> | |
1313 | <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\" | |
1314 | value=\"$feed_search\"> | |
1315 | <button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">". | |
1316 | __('Search')."</button> | |
1317 | </div>"; | |
1318 | ||
1319 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1320 | "<span>" . __('Select')."</span>"; | |
1321 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1322 | print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\" | |
1323 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1324 | print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\" | |
1325 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1326 | print "</div></div>"; | |
1327 | ||
1328 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1329 | "<span>" . __('Feeds')."</span>"; | |
1330 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1331 | print "<div onclick=\"quickAddFeed()\" | |
1332 | dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>"; | |
1333 | print "<div onclick=\"editSelectedFeed()\" | |
1334 | dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>"; | |
1335 | print "<div onclick=\"resetFeedOrder()\" | |
1336 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; | |
33f0fdd0 AD |
1337 | print "<div onclick=\"batchSubscribe()\" |
1338 | dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>"; | |
0671359f AD |
1339 | print "<div dojoType=\"dijit.MenuItem\" onclick=\"removeSelectedFeeds()\">" |
1340 | .__('Unsubscribe')."</div> "; | |
afcfe6ca AD |
1341 | print "</div></div>"; |
1342 | ||
a42c55f0 | 1343 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca AD |
1344 | print "<div dojoType=\"dijit.form.DropDownButton\">". |
1345 | "<span>" . __('Categories')."</span>"; | |
1346 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
5ef071e0 AD |
1347 | print "<div onclick=\"createCategory()\" |
1348 | dojoType=\"dijit.MenuItem\">".__('Add category')."</div>"; | |
afcfe6ca AD |
1349 | print "<div onclick=\"resetCatOrder()\" |
1350 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; | |
fd26d5bf AD |
1351 | print "<div onclick=\"removeSelectedCategories()\" |
1352 | dojoType=\"dijit.MenuItem\">".__('Remove selected')."</div>"; | |
afcfe6ca AD |
1353 | print "</div></div>"; |
1354 | ||
1355 | } | |
1356 | ||
1357 | print $error_button; | |
1358 | print $inactive_button; | |
1359 | ||
0671359f AD |
1360 | print "<button onclick=\"toggleHiddenFeedCats()\" |
1361 | dojoType=\"dijit.form.Button\">".__('(Un)hide empty categories')."</button>"; | |
afcfe6ca AD |
1362 | |
1363 | if (defined('_ENABLE_FEED_DEBUGGING')) { | |
1364 | ||
1365 | print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\"> | |
1366 | <option value=\"facDefault\" selected>".__('More actions...')."</option>"; | |
1367 | ||
1368 | if (FORCE_ARTICLE_PURGE == 0) { | |
1369 | ||
1370 | "<option value=\"facPurge\">".__('Manual purge')."</option>"; | |
1371 | } | |
1372 | ||
1373 | print " | |
1374 | <option value=\"facClear\">".__('Clear feed data')."</option> | |
1375 | <option value=\"facRescore\">".__('Rescore articles')."</option>"; | |
1376 | ||
1377 | print "</select>"; | |
1378 | ||
1379 | } | |
1380 | ||
1381 | print "</div>"; # toolbar | |
1382 | ||
1383 | //print '</div>'; | |
1384 | print '<div dojoType="dijit.layout.ContentPane" region="center">'; | |
1385 | ||
1386 | print "<div id=\"feedlistLoading\"> | |
1387 | <img src='images/indicator_tiny.gif'>". | |
1388 | __("Loading, please wait...")."</div>"; | |
1389 | ||
1390 | print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\" | |
1391 | url=\"backend.php?op=pref-feeds&method=getfeedtree\"> | |
1392 | </div> | |
1393 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\" | |
1394 | query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\" | |
1395 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
1396 | </div> | |
1397 | <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\" | |
1398 | dndController=\"dijit.tree.dndSource\" | |
1399 | betweenThreshold=\"5\" | |
1400 | model=\"feedModel\" openOnClick=\"false\"> | |
1401 | <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> | |
1402 | var id = String(item.id); | |
1403 | var bare_id = id.substr(id.indexOf(':')+1); | |
1404 | ||
1405 | if (id.match('FEED:')) { | |
1406 | editFeed(bare_id); | |
1407 | } else if (id.match('CAT:')) { | |
1408 | editCat(bare_id, item); | |
1409 | } | |
1410 | </script> | |
1411 | <script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> | |
1412 | Element.hide(\"feedlistLoading\"); | |
1413 | </script> | |
1414 | </div>"; | |
1415 | ||
ba5296a1 AD |
1416 | # print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\"> |
1417 | # ".__('<b>Hint:</b> you can drag feeds and categories around.')." | |
1418 | # </div>"; | |
afcfe6ca AD |
1419 | |
1420 | print '</div>'; | |
1421 | print '</div>'; | |
1422 | ||
1423 | print "</div>"; # feeds pane | |
1424 | ||
6c2637d9 | 1425 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">"; |
afcfe6ca | 1426 | |
566faa14 | 1427 | print "<p>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . " "; |
afcfe6ca | 1428 | |
566faa14 | 1429 | print __("Only main settings profile can be migrated using OPML.") . "</p>"; |
afcfe6ca | 1430 | |
55f34b81 | 1431 | print "<iframe id=\"upload_iframe\" |
afcfe6ca AD |
1432 | name=\"upload_iframe\" onload=\"opmlImportComplete(this)\" |
1433 | style=\"width: 400px; height: 100px; display: none;\"></iframe>"; | |
1434 | ||
1435 | print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\" | |
1436 | enctype=\"multipart/form-data\" method=\"POST\" | |
55f34b81 | 1437 | action=\"backend.php\"> |
afcfe6ca AD |
1438 | <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> |
1439 | <input type=\"hidden\" name=\"op\" value=\"dlg\"> | |
c4c74732 | 1440 | <input type=\"hidden\" name=\"method\" value=\"importOpml\"> |
afcfe6ca | 1441 | <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" . |
a1159c01 | 1442 | __('Import my OPML') . "</button>"; |
afcfe6ca | 1443 | |
a1159c01 | 1444 | print "<hr>"; |
afcfe6ca AD |
1445 | |
1446 | print "<p>" . __('Filename:') . | |
1447 | " <input type=\"text\" id=\"filename\" value=\"TinyTinyRSS.opml\" /> " . | |
a1159c01 | 1448 | __('Include settings') . "<input type=\"checkbox\" id=\"settings\" checked=\"1\"/>"; |
afcfe6ca | 1449 | |
a1159c01 | 1450 | print "</p><button dojoType=\"dijit.form.Button\" |
afcfe6ca | 1451 | onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" . |
a1159c01 | 1452 | __('Export OPML') . "</button></p></form>"; |
afcfe6ca | 1453 | |
a1159c01 | 1454 | print "<hr>"; |
afcfe6ca AD |
1455 | |
1456 | print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . " "; | |
1457 | ||
566faa14 | 1458 | print __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "</p>"; |
afcfe6ca | 1459 | |
fb54e3b1 | 1460 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">". |
a1159c01 | 1461 | __('Display published OPML URL')."</button> "; |
afcfe6ca | 1462 | |
1ffe3391 | 1463 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
1464 | "hook_prefs_tab_section", "prefFeedsOPML"); |
1465 | ||
afcfe6ca AD |
1466 | print "</div>"; # pane |
1467 | ||
1468 | if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) { | |
1469 | ||
1470 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">"; | |
1471 | ||
1472 | print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>"; | |
1473 | ||
1474 | print "<p>"; | |
1475 | ||
1476 | print "<button onclick='window.navigator.registerContentHandler(" . | |
1477 | "\"application/vnd.mozilla.maybe.feed\", " . | |
1478 | "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" . | |
1479 | __('Click here to register this site as a feed reader.') . | |
1480 | "</button>"; | |
1481 | ||
1482 | print "</p>"; | |
1483 | ||
1484 | print "</div>"; # pane | |
1485 | } | |
1486 | ||
e95e7819 | 1487 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">"; |
afcfe6ca AD |
1488 | |
1489 | print "<h3>" . __("Published articles and generated feeds") . "</h3>"; | |
1490 | ||
1491 | print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>"; | |
1492 | ||
1493 | $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . | |
1494 | "/public.php?op=rss&id=-2&view-mode=all_articles");; | |
1495 | ||
fb54e3b1 | 1496 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">". |
afcfe6ca AD |
1497 | __('Display URL')."</button> "; |
1498 | ||
1499 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">". | |
1500 | __('Clear all generated URLs')."</button> "; | |
1501 | ||
1502 | print "<h3>" . __("Articles shared by URL") . "</h3>"; | |
1503 | ||
1504 | print "<p>" . __("You can disable all articles shared by unique URLs here.") . "</p>"; | |
1505 | ||
1506 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">". | |
1507 | __('Unshare all articles')."</button> "; | |
1508 | ||
1ffe3391 | 1509 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
1510 | "hook_prefs_tab_section", "prefFeedsPublishedGenerated"); |
1511 | ||
afcfe6ca AD |
1512 | print "</div>"; #pane |
1513 | ||
1ffe3391 | 1514 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
6065f3ad AD |
1515 | "hook_prefs_tab", "prefFeeds"); |
1516 | ||
afcfe6ca | 1517 | print "</div>"; #container |
afcfe6ca | 1518 | } |
2ecd2df5 | 1519 | |
88918ca6 | 1520 | private function feedlist_init_cat($cat_id) { |
2ecd2df5 AD |
1521 | $obj = array(); |
1522 | $cat_id = (int) $cat_id; | |
1523 | ||
1524 | if ($cat_id > 0) { | |
a42c55f0 | 1525 | $cat_unread = ccache_find($cat_id, $_SESSION["uid"], true); |
2ecd2df5 | 1526 | } else if ($cat_id == 0 || $cat_id == -2) { |
a42c55f0 | 1527 | $cat_unread = getCategoryUnread($cat_id); |
2ecd2df5 AD |
1528 | } |
1529 | ||
1530 | $obj['id'] = 'CAT:' . $cat_id; | |
1531 | $obj['items'] = array(); | |
a42c55f0 | 1532 | $obj['name'] = getCategoryTitle($cat_id); |
2ecd2df5 AD |
1533 | $obj['type'] = 'category'; |
1534 | $obj['unread'] = (int) $cat_unread; | |
2ecd2df5 AD |
1535 | $obj['bare_id'] = $cat_id; |
1536 | ||
1537 | return $obj; | |
1538 | } | |
1539 | ||
1540 | private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { | |
1541 | $obj = array(); | |
1542 | $feed_id = (int) $feed_id; | |
1543 | ||
1544 | if (!$title) | |
a42c55f0 | 1545 | $title = getFeedTitle($feed_id, false); |
2ecd2df5 AD |
1546 | |
1547 | if ($unread === false) | |
a42c55f0 | 1548 | $unread = getFeedUnread($feed_id, false); |
2ecd2df5 AD |
1549 | |
1550 | $obj['id'] = 'FEED:' . $feed_id; | |
1551 | $obj['name'] = $title; | |
1552 | $obj['unread'] = (int) $unread; | |
1553 | $obj['type'] = 'feed'; | |
1554 | $obj['error'] = $error; | |
1555 | $obj['updated'] = $updated; | |
1556 | $obj['icon'] = getFeedIcon($feed_id); | |
1557 | $obj['bare_id'] = $feed_id; | |
1558 | ||
1559 | return $obj; | |
1560 | } | |
1561 | ||
bc6fa236 AD |
1562 | function inactiveFeeds() { |
1563 | ||
1564 | if (DB_TYPE == "pgsql") { | |
1565 | $interval_qpart = "NOW() - INTERVAL '3 months'"; | |
1566 | } else { | |
1567 | $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; | |
1568 | } | |
1569 | ||
d9c85e0f | 1570 | $result = $this->dbh->query("SELECT ttrss_feeds.title, ttrss_feeds.site_url, |
bc6fa236 AD |
1571 | ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article |
1572 | FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE | |
1573 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE | |
1574 | ttrss_entries.id = ref_id AND | |
1575 | ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart | |
1576 | AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." AND | |
1577 | ttrss_user_entries.feed_id = ttrss_feeds.id AND | |
1578 | ttrss_entries.id = ref_id | |
1579 | GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url | |
1580 | ORDER BY last_article"); | |
1581 | ||
fcef9eea | 1582 | print "<h2" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</h2>"; |
bc6fa236 AD |
1583 | |
1584 | print "<div dojoType=\"dijit.Toolbar\">"; | |
1585 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1586 | "<span>" . __('Select')."</span>"; | |
1587 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1588 | print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'all')\" | |
1589 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1590 | print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'none')\" | |
1591 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1592 | print "</div></div>"; | |
1593 | print "</div>"; #toolbar | |
1594 | ||
1595 | print "<div class=\"inactiveFeedHolder\">"; | |
1596 | ||
1597 | print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">"; | |
1598 | ||
1599 | $lnum = 1; | |
1600 | ||
d9c85e0f | 1601 | while ($line = $this->dbh->fetch_assoc($result)) { |
bc6fa236 AD |
1602 | |
1603 | $class = ($lnum % 2) ? "even" : "odd"; | |
1604 | $feed_id = $line["id"]; | |
1605 | $this_row_id = "id=\"FUPDD-$feed_id\""; | |
1606 | ||
1607 | # class needed for selectTableRows() | |
1608 | print "<tr class=\"placeholder\" $this_row_id>"; | |
1609 | ||
1610 | $edit_title = htmlspecialchars($line["title"]); | |
1611 | ||
1612 | # id needed for selectTableRows() | |
1613 | print "<td width='5%' align='center'><input | |
1614 | onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" | |
1615 | type=\"checkbox\" id=\"FUPDC-$feed_id\"></td>"; | |
1616 | print "<td>"; | |
1617 | ||
1618 | print "<a class=\"visibleLink\" href=\"#\" ". | |
1619 | "title=\"".__("Click to edit feed")."\" ". | |
1620 | "onclick=\"editFeed(".$line["id"].")\">". | |
1621 | htmlspecialchars($line["title"])."</a>"; | |
1622 | ||
1623 | print "</td><td class=\"insensitive\" align='right'>"; | |
a42c55f0 | 1624 | print make_local_datetime($line['last_article'], false); |
bc6fa236 AD |
1625 | print "</td>"; |
1626 | print "</tr>"; | |
1627 | ||
1628 | ++$lnum; | |
1629 | } | |
1630 | ||
1631 | print "</table>"; | |
1632 | print "</div>"; | |
1633 | ||
1634 | print "<div class='dlgButtons'>"; | |
1635 | print "<div style='float : left'>"; | |
1636 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">" | |
1637 | .__('Unsubscribe from selected feeds')."</button> "; | |
1638 | print "</div>"; | |
1639 | ||
1640 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">". | |
1641 | __('Close this window')."</button>"; | |
1642 | ||
1643 | print "</div>"; | |
1644 | ||
1645 | } | |
1646 | ||
1647 | function feedsWithErrors() { | |
fcef9eea AD |
1648 | print "<h2>" . __("These feeds have not been updated because of errors:") . |
1649 | "</h2>"; | |
bc6fa236 | 1650 | |
d9c85e0f | 1651 | $result = $this->dbh->query("SELECT id,title,feed_url,last_error,site_url |
bc6fa236 AD |
1652 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); |
1653 | ||
1654 | print "<div dojoType=\"dijit.Toolbar\">"; | |
1655 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1656 | "<span>" . __('Select')."</span>"; | |
1657 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1658 | print "<div onclick=\"selectTableRows('prefErrorFeedList', 'all')\" | |
1659 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1660 | print "<div onclick=\"selectTableRows('prefErrorFeedList', 'none')\" | |
1661 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1662 | print "</div></div>"; | |
1663 | print "</div>"; #toolbar | |
1664 | ||
1665 | print "<div class=\"inactiveFeedHolder\">"; | |
1666 | ||
1667 | print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">"; | |
1668 | ||
1669 | $lnum = 1; | |
1670 | ||
d9c85e0f | 1671 | while ($line = $this->dbh->fetch_assoc($result)) { |
bc6fa236 AD |
1672 | |
1673 | $class = ($lnum % 2) ? "even" : "odd"; | |
1674 | $feed_id = $line["id"]; | |
1675 | $this_row_id = "id=\"FERDD-$feed_id\""; | |
1676 | ||
1677 | # class needed for selectTableRows() | |
1678 | print "<tr class=\"placeholder\" $this_row_id>"; | |
1679 | ||
1680 | $edit_title = htmlspecialchars($line["title"]); | |
1681 | ||
1682 | # id needed for selectTableRows() | |
1683 | print "<td width='5%' align='center'><input | |
1684 | onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" | |
1685 | type=\"checkbox\" id=\"FERDC-$feed_id\"></td>"; | |
1686 | print "<td>"; | |
1687 | ||
1688 | print "<a class=\"visibleLink\" href=\"#\" ". | |
1689 | "title=\"".__("Click to edit feed")."\" ". | |
1690 | "onclick=\"editFeed(".$line["id"].")\">". | |
1691 | htmlspecialchars($line["title"])."</a>: "; | |
1692 | ||
1693 | print "<span class=\"insensitive\">"; | |
1694 | print htmlspecialchars($line["last_error"]); | |
1695 | print "</span>"; | |
1696 | ||
1697 | print "</td>"; | |
1698 | print "</tr>"; | |
1699 | ||
1700 | ++$lnum; | |
1701 | } | |
1702 | ||
1703 | print "</table>"; | |
1704 | print "</div>"; | |
1705 | ||
1706 | print "<div class='dlgButtons'>"; | |
1707 | print "<div style='float : left'>"; | |
1708 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">" | |
1709 | .__('Unsubscribe from selected feeds')."</button> "; | |
1710 | print "</div>"; | |
1711 | ||
1712 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">". | |
1713 | __('Close this window')."</button>"; | |
1714 | ||
1715 | print "</div>"; | |
1716 | } | |
1717 | ||
87d7e850 AD |
1718 | /** |
1719 | * Purge a feed contents, marked articles excepted. | |
1720 | * | |
1721 | * @param mixed $link The database connection. | |
1722 | * @param integer $id The id of the feed to purge. | |
1723 | * @return void | |
1724 | */ | |
6322ac79 | 1725 | private function clear_feed_articles($id) { |
87d7e850 AD |
1726 | |
1727 | if ($id != 0) { | |
d9c85e0f | 1728 | $result = $this->dbh->query("DELETE FROM ttrss_user_entries |
87d7e850 AD |
1729 | WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]); |
1730 | } else { | |
d9c85e0f | 1731 | $result = $this->dbh->query("DELETE FROM ttrss_user_entries |
87d7e850 AD |
1732 | WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]); |
1733 | } | |
1734 | ||
d9c85e0f | 1735 | $result = $this->dbh->query("DELETE FROM ttrss_entries WHERE |
87d7e850 AD |
1736 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); |
1737 | ||
a42c55f0 | 1738 | ccache_update($id, $_SESSION['uid']); |
87d7e850 AD |
1739 | } // function clear_feed_articles |
1740 | ||
a42c55f0 | 1741 | private function remove_feed_category($id, $owner_uid) { |
a6a9b812 | 1742 | |
d9c85e0f | 1743 | $this->dbh->query("DELETE FROM ttrss_feed_categories |
a6a9b812 AD |
1744 | WHERE id = '$id' AND owner_uid = $owner_uid"); |
1745 | ||
a42c55f0 | 1746 | ccache_remove($id, $owner_uid, true); |
a6a9b812 AD |
1747 | } |
1748 | ||
a42c55f0 | 1749 | static function remove_feed($id, $owner_uid) { |
a6a9b812 AD |
1750 | |
1751 | if ($id > 0) { | |
1752 | ||
1753 | /* save starred articles in Archived feed */ | |
1754 | ||
a42c55f0 | 1755 | db_query("BEGIN"); |
a6a9b812 AD |
1756 | |
1757 | /* prepare feed if necessary */ | |
1758 | ||
a42c55f0 | 1759 | $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = $id |
aa5ac2cd AD |
1760 | AND owner_uid = $owner_uid"); |
1761 | ||
a42c55f0 | 1762 | $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); |
aa5ac2cd | 1763 | |
a42c55f0 | 1764 | $result = db_query("SELECT id FROM ttrss_archived_feeds |
aa5ac2cd | 1765 | WHERE feed_url = '$feed_url' AND owner_uid = $owner_uid"); |
a6a9b812 AD |
1766 | |
1767 | if (db_num_rows($result) == 0) { | |
a42c55f0 | 1768 | $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds"); |
b1df14d0 AD |
1769 | $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1; |
1770 | ||
a42c55f0 | 1771 | db_query("INSERT INTO ttrss_archived_feeds |
a6a9b812 | 1772 | (id, owner_uid, title, feed_url, site_url) |
b1df14d0 | 1773 | SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds |
aa5ac2cd AD |
1774 | WHERE id = '$id'"); |
1775 | ||
b1df14d0 | 1776 | $archive_id = $new_feed_id; |
aa5ac2cd AD |
1777 | } else { |
1778 | $archive_id = db_fetch_result($result, 0, "id"); | |
a6a9b812 AD |
1779 | } |
1780 | ||
a42c55f0 | 1781 | db_query("UPDATE ttrss_user_entries SET feed_id = NULL, |
aa5ac2cd | 1782 | orig_feed_id = '$archive_id' WHERE feed_id = '$id' AND |
a6a9b812 AD |
1783 | marked = true AND owner_uid = $owner_uid"); |
1784 | ||
1785 | /* Remove access key for the feed */ | |
1786 | ||
a42c55f0 | 1787 | db_query("DELETE FROM ttrss_access_keys WHERE |
a6a9b812 AD |
1788 | feed_id = '$id' AND owner_uid = $owner_uid"); |
1789 | ||
1790 | /* remove the feed */ | |
1791 | ||
a42c55f0 | 1792 | db_query("DELETE FROM ttrss_feeds |
a6a9b812 AD |
1793 | WHERE id = '$id' AND owner_uid = $owner_uid"); |
1794 | ||
a42c55f0 | 1795 | db_query("COMMIT"); |
a6a9b812 AD |
1796 | |
1797 | if (file_exists(ICONS_DIR . "/$id.ico")) { | |
1798 | unlink(ICONS_DIR . "/$id.ico"); | |
1799 | } | |
1800 | ||
a42c55f0 | 1801 | ccache_remove($id, $owner_uid); |
a6a9b812 AD |
1802 | |
1803 | } else { | |
a42c55f0 AD |
1804 | label_remove(feed_to_label_id($id), $owner_uid); |
1805 | //ccache_remove($id, $owner_uid); don't think labels are cached | |
a6a9b812 AD |
1806 | } |
1807 | } | |
87d7e850 | 1808 | |
201bb1ca | 1809 | function batchSubscribe() { |
96e3ae8c | 1810 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">"; |
201bb1ca AD |
1811 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchaddfeeds\">"; |
1812 | ||
1813 | print "<table width='100%'><tr><td> | |
1814 | ".__("Add one valid RSS feed per line (no feed detection is done)")." | |
1815 | </td><td align='right'>"; | |
a42c55f0 | 1816 | if (get_pref('ENABLE_FEED_CATS')) { |
201bb1ca | 1817 | print __('Place in category:') . " "; |
a42c55f0 | 1818 | print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"'); |
201bb1ca AD |
1819 | } |
1820 | print "</td></tr><tr><td colspan='2'>"; | |
1821 | print "<textarea | |
1822 | style='font-size : 12px; width : 100%; height: 200px;' | |
1823 | placeHolder=\"".__("Feeds to subscribe, One per line")."\" | |
1824 | dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>"; | |
1825 | ||
1826 | print "</td></tr><tr><td colspan='2'>"; | |
1827 | ||
1828 | print "<div id='feedDlg_loginContainer' style='display : none'> | |
1829 | " . | |
1830 | " <input dojoType=\"dijit.form.TextBox\" name='login'\" | |
1831 | placeHolder=\"".__("Login")."\" | |
1832 | style=\"width : 10em;\"> ". | |
1833 | " <input | |
1834 | placeHolder=\"".__("Password")."\" | |
1835 | dojoType=\"dijit.form.TextBox\" type='password' | |
1836 | style=\"width : 10em;\" name='pass'\">". | |
1837 | "</div>"; | |
1838 | ||
1839 | print "</td></tr><tr><td colspan='2'>"; | |
1840 | ||
1841 | print "<div style=\"clear : both\"> | |
1842 | <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\" | |
1843 | onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'> | |
1844 | <label for=\"feedDlg_loginCheck\">". | |
1845 | __('Feeds require authentication.')."</div>"; | |
1846 | ||
1847 | print "</form>"; | |
1848 | ||
1849 | print "</td></tr></table>"; | |
1850 | ||
1851 | print "<div class=\"dlgButtons\"> | |
1852 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">".__('Subscribe')."</button> | |
1853 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button> | |
1854 | </div>"; | |
1855 | } | |
1856 | ||
96e3ae8c | 1857 | function batchAddFeeds() { |
d9c85e0f | 1858 | $cat_id = $this->dbh->escape_string($_REQUEST['cat']); |
2714d5ca | 1859 | $feeds = explode("\n", $_REQUEST['feeds']); |
d9c85e0f | 1860 | $login = $this->dbh->escape_string($_REQUEST['login']); |
41694a95 | 1861 | $pass = trim($_REQUEST['pass']); |
96e3ae8c AD |
1862 | |
1863 | foreach ($feeds as $feed) { | |
d9c85e0f | 1864 | $feed = $this->dbh->escape_string(trim($feed)); |
96e3ae8c AD |
1865 | |
1866 | if (validate_feed_url($feed)) { | |
1867 | ||
d9c85e0f | 1868 | $this->dbh->query("BEGIN"); |
96e3ae8c AD |
1869 | |
1870 | if ($cat_id == "0" || !$cat_id) { | |
1871 | $cat_qpart = "NULL"; | |
1872 | } else { | |
1873 | $cat_qpart = "'$cat_id'"; | |
1874 | } | |
1875 | ||
d9c85e0f | 1876 | $result = $this->dbh->query( |
96e3ae8c AD |
1877 | "SELECT id FROM ttrss_feeds |
1878 | WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]); | |
1879 | ||
044cff2d AD |
1880 | if (strlen(FEED_CRYPT_KEY) > 0) { |
1881 | require_once "crypt.php"; | |
1882 | $pass = substr(encrypt_string($pass), 0, 250); | |
1883 | $auth_pass_encrypted = 'true'; | |
1884 | } else { | |
1885 | $auth_pass_encrypted = 'false'; | |
1886 | } | |
1887 | ||
d9c85e0f | 1888 | $pass = $this->dbh->escape_string($pass); |
41694a95 | 1889 | |
d9c85e0f AD |
1890 | if ($this->dbh->num_rows($result) == 0) { |
1891 | $result = $this->dbh->query( | |
96e3ae8c | 1892 | "INSERT INTO ttrss_feeds |
044cff2d | 1893 | (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted) |
96e3ae8c | 1894 | VALUES ('".$_SESSION["uid"]."', '$feed', |
044cff2d | 1895 | '[Unknown]', $cat_qpart, '$login', '$pass', 0, $auth_pass_encrypted)"); |
96e3ae8c AD |
1896 | } |
1897 | ||
d9c85e0f | 1898 | $this->dbh->query("COMMIT"); |
96e3ae8c AD |
1899 | } |
1900 | } | |
1901 | } | |
201bb1ca | 1902 | |
195187c4 | 1903 | function regenOPMLKey() { |
a42c55f0 | 1904 | $this->update_feed_access_key('OPML:Publish', |
195187c4 AD |
1905 | false, $_SESSION["uid"]); |
1906 | ||
6322ac79 | 1907 | $new_link = Opml::opml_publish_url(); |
195187c4 AD |
1908 | |
1909 | print json_encode(array("link" => $new_link)); | |
1910 | } | |
1911 | ||
1912 | function regenFeedKey() { | |
d9c85e0f AD |
1913 | $feed_id = $this->dbh->escape_string($_REQUEST['id']); |
1914 | $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true"; | |
195187c4 | 1915 | |
a42c55f0 | 1916 | $new_key = $this->update_feed_access_key($feed_id, $is_cat); |
195187c4 AD |
1917 | |
1918 | print json_encode(array("link" => $new_key)); | |
1919 | } | |
1920 | ||
1921 | ||
a42c55f0 | 1922 | private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) { |
195187c4 AD |
1923 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
1924 | ||
1925 | $sql_is_cat = bool_to_sql_bool($is_cat); | |
1926 | ||
d9c85e0f | 1927 | $result = $this->dbh->query("SELECT access_key FROM ttrss_access_keys |
195187c4 AD |
1928 | WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat |
1929 | AND owner_uid = " . $owner_uid); | |
1930 | ||
d9c85e0f AD |
1931 | if ($this->dbh->num_rows($result) == 1) { |
1932 | $key = $this->dbh->escape_string(sha1(uniqid(rand(), true))); | |
195187c4 | 1933 | |
d9c85e0f | 1934 | $this->dbh->query("UPDATE ttrss_access_keys SET access_key = '$key' |
195187c4 AD |
1935 | WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat |
1936 | AND owner_uid = " . $owner_uid); | |
1937 | ||
1938 | return $key; | |
1939 | ||
1940 | } else { | |
a42c55f0 | 1941 | return get_feed_access_key($feed_id, $is_cat, $owner_uid); |
195187c4 AD |
1942 | } |
1943 | } | |
1944 | ||
1945 | // Silent | |
1946 | function clearKeys() { | |
d9c85e0f | 1947 | $this->dbh->query("DELETE FROM ttrss_access_keys WHERE |
195187c4 AD |
1948 | owner_uid = " . $_SESSION["uid"]); |
1949 | } | |
1950 | ||
1951 | ||
afcfe6ca AD |
1952 | } |
1953 | ?> |