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