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