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