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