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