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