]> git.wh0rd.org Git - tt-rss.git/blob - modules/pref-feeds.php
pref-feeds: fix type of Uncategorized category
[tt-rss.git] / modules / pref-feeds.php
1 <?php
2
3         function batch_edit_cbox($elem, $label = false) {
4                 print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\"
5                         onchange=\"batchFeedsToggleField(this, '$elem', '$label')\">";
6         }
7
8         function module_pref_feeds($link) {
9
10                 global $update_intervals;
11                 global $purge_intervals;
12                 global $update_methods;
13
14                 $subop = $_REQUEST["subop"];
15                 $quiet = $_REQUEST["quiet"];
16                 $mode = $_REQUEST["mode"];
17
18                 if ($subop == "renamecat") {
19                         $title = db_escape_string($_REQUEST['title']);
20                         $id = db_escape_string($_REQUEST['id']);
21
22                         if ($title) {
23                                 db_query($link, "UPDATE ttrss_feed_categories SET
24                                         title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
25                         }
26                         return;
27                 }
28
29                 if ($subop == "getfeedtree") {
30
31                         $root = array();
32                         $root['id'] = 'root';
33                         $root['name'] = __('Feeds');
34                         $root['items'] = array();
35                         $root['type'] = 'category';
36
37                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
38
39                                 $result = db_query($link, "SELECT id, title FROM ttrss_feed_categories
40                                         WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY order_id, title");
41         
42                                 while ($line = db_fetch_assoc($result)) {
43                                         $cat = array();
44                                         $cat['id'] = 'CAT:' . $line['id'];
45                                         $cat['bare_id'] = $feed_id;
46                                         $cat['name'] = $line['title'];
47                                         $cat['items'] = array();
48                                         $cat['type'] = 'category';
49         
50                                         $feed_result = db_query($link, "SELECT id, title, last_error 
51                                                 FROM ttrss_feeds
52                                                 WHERE cat_id = '".$line['id']."' AND owner_uid = ".$_SESSION["uid"].
53                                                 " ORDER BY order_id, title");
54         
55                                         while ($feed_line = db_fetch_assoc($feed_result)) {
56                                                 $feed = array();
57                                                 $feed['id'] = 'FEED:' . $feed_line['id'];
58                                                 $feed['bare_id'] = $feed_line['id'];
59                                                 $feed['name'] = $feed_line['title'];
60                                                 $feed['checkbox'] = false;
61                                                 $feed['error'] = $feed_line['last_error'];
62                                                 $feed['icon'] = getFeedIcon($feed_line['id']);
63
64                                                 array_push($cat['items'], $feed);
65                                         }
66         
67                                         array_push($root['items'], $cat);
68                                 }
69         
70                                 /* Uncategorized is a special case */
71         
72                                 $cat = array();
73                                 $cat['id'] = 'CAT:0';
74                                 $cat['bare_id'] = 0;
75                                 $cat['name'] = __("Uncategorized");
76                                 $cat['items'] = array();
77                                 $cat['type'] = 'category';
78
79                                 $feed_result = db_query($link, "SELECT id, title,last_error 
80                                         FROM ttrss_feeds
81                                         WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"].
82                                         " ORDER BY order_id, title");
83         
84                                 while ($feed_line = db_fetch_assoc($feed_result)) {
85                                         $feed = array();
86                                         $feed['id'] = 'FEED:' . $feed_line['id'];
87                                         $feed['bare_id'] = $feed_line['id'];
88                                         $feed['name'] = $feed_line['title'];
89                                         $feed['checkbox'] = false;
90                                         $feed['error'] = $feed_line['last_error'];
91                                         $feed['icon'] = getFeedIcon($feed_line['id']);
92
93                                         array_push($cat['items'], $feed);
94                                 }
95         
96                                 array_push($root['items'], $cat);
97                         } else {
98                                 $feed_result = db_query($link, "SELECT id, title, last_error 
99                                         FROM ttrss_feeds
100                                         WHERE owner_uid = ".$_SESSION["uid"].
101                                         " ORDER BY order_id, title");
102         
103                                 while ($feed_line = db_fetch_assoc($feed_result)) {
104                                         $feed = array();
105                                         $feed['id'] = 'FEED:' . $feed_line['id'];
106                                         $feed['bare_id'] = $feed_line['id'];
107                                         $feed['name'] = $feed_line['title'];
108                                         $feed['checkbox'] = false;
109                                         $feed['error'] = $feed_line['last_error'];
110                                         $feed['icon'] = getFeedIcon($feed_line['id']);
111
112                                         array_push($root['items'], $feed);
113                                 }
114                         }
115
116                         $fl = array();
117                         $fl['identifier'] = 'id';
118                         $fl['label'] = 'name';
119                         $fl['items'] = array($root);
120
121                         print json_encode($fl);
122                         return;
123                 }
124
125                 if ($subop == "catsortreset") {
126                         db_query($link, "UPDATE ttrss_feed_categories 
127                                         SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
128                         return;
129                 }       
130
131                 if ($subop == "feedsortreset") {
132                         db_query($link, "UPDATE ttrss_feeds 
133                                         SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
134                         return;
135                 }       
136
137                 if ($subop == "savefeedorder") {
138 #                       if ($_POST['payload']) {
139 #                               file_put_contents("/tmp/blahblah.txt", $_POST['payload']);
140 #                               $data = json_decode($_POST['payload'], true);   
141 #                       } else {
142 #                               $data = json_decode(file_get_contents("/tmp/blahblah.txt"), true);
143 #                       }
144
145                         $data = json_decode($_POST['payload'], true);
146
147                         if (is_array($data) && is_array($data['items'])) {
148                                 $cat_order_id = 0;
149
150                                 $data_map = array();
151
152                                 foreach ($data['items'] as $item) {
153
154                                         if ($item['id'] != 'root') {
155                                                 if (is_array($item['items'])) {
156                                                         if (isset($item['items']['_reference'])) {
157                                                                 $data_map[$item['id']] = array($item['items']);
158                                                         } else {
159                                                                 $data_map[$item['id']] =& $item['items'];
160                                                         }
161                                                 }
162                                         }
163                                 }
164
165                                 foreach ($data['items'][0]['items'] as $item) {
166                                         $id = $item['_reference'];
167                                         $bare_id = substr($id, strpos($id, ':')+1);
168
169                                         ++$cat_order_id;
170
171                                         if ($bare_id > 0) {
172                                                 db_query($link, "UPDATE ttrss_feed_categories 
173                                                         SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND
174                                                         owner_uid = " . $_SESSION["uid"]);
175                                         }
176
177                                         $feed_order_id = 0;
178
179                                         if (is_array($data_map[$id])) {
180                                                 foreach ($data_map[$id] as $feed) {
181                                                         $id = $feed['_reference'];
182                                                         $feed_id = substr($id, strpos($id, ':')+1);
183
184                                                         if ($bare_id != 0) 
185                                                                 $cat_query = "cat_id = '$bare_id'";
186                                                         else
187                                                                 $cat_query = "cat_id = NULL";
188
189                                                         db_query($link, "UPDATE ttrss_feeds
190                                                                 SET order_id = '$feed_order_id',
191                                                                 $cat_query
192                                                                 WHERE id = '$feed_id' AND
193                                                                         owner_uid = " . $_SESSION["uid"]);
194         
195                                                         ++$feed_order_id;
196                                                 } 
197                                         }
198                                 }
199                         }
200
201                         return;
202                 }
203
204                 if ($subop == "removeicon") {                   
205                         $feed_id = db_escape_string($_REQUEST["feed_id"]);
206
207                         $result = db_query($link, "SELECT id FROM ttrss_feeds
208                                 WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
209
210                         if (db_num_rows($result) != 0) {
211                                 unlink(ICONS_DIR . "/$feed_id.ico");
212                         }
213
214                         return;
215                 }
216
217                 if ($subop == "uploadicon") {
218                         $icon_file = $_FILES['icon_file']['tmp_name'];
219                         $feed_id = db_escape_string($_REQUEST["feed_id"]);
220
221                         if (is_file($icon_file) && $feed_id) {
222                                 if (filesize($icon_file) < 20000) {
223                                         
224                                         $result = db_query($link, "SELECT id FROM ttrss_feeds
225                                                 WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
226
227                                         if (db_num_rows($result) != 0) {
228                                                 unlink(ICONS_DIR . "/$feed_id.ico");
229                                                 move_uploaded_file($icon_file, ICONS_DIR . "/$feed_id.ico");
230                                                 $rc = 0;
231                                         } else {
232                                                 $rc = 2;
233                                         }
234                                 } else {
235                                         $rc = 1;
236                                 }
237                         } else {
238                                 $rc = 2;
239                         }
240
241                         print "<script type=\"text/javascript\">";
242                         print "parent.uploadIconHandler($rc);";
243                         print "</script>";
244                         return;
245                 }
246
247                 if ($subop == "editfeed") {
248                         header("Content-Type: text/xml");
249
250                         print "<dlg id=\"$subop\">";
251                         print "<title>".__('Feed Editor')."</title>";
252                         print "<content><![CDATA[";
253
254                         $feed_id = db_escape_string($_REQUEST["id"]);
255
256                         $result = db_query($link, 
257                                 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
258                                         owner_uid = " . $_SESSION["uid"]);
259
260                         $title = htmlspecialchars(db_fetch_result($result,
261                                 0, "title"));
262
263                         $icon_file = ICONS_DIR . "/$feed_id.ico";
264         
265                         if (file_exists($icon_file) && filesize($icon_file) > 0) {
266                                         $feed_icon = "<img width=\"16\" height=\"16\"
267                                                 src=\"" . ICONS_URL . "/$feed_id.ico\">";
268                         } else {
269                                 $feed_icon = "";
270                         }
271
272                         print "<form id=\"edit_feed_form\" onsubmit=\"return false\">"; 
273
274                         print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
275                         print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
276                         print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
277
278                         print "<div class=\"dlgSec\">".__("Feed")."</div>";
279                         print "<div class=\"dlgSecCont\">";
280
281                         /* Title */
282
283                         print "<input style=\"font-size : 16px\" size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
284                                             name=\"title\" value=\"$title\">";
285
286                         /* Feed URL */
287
288                         $feed_url = db_fetch_result($result, 0, "feed_url");
289                         $feed_url = htmlspecialchars(db_fetch_result($result,
290                                 0, "feed_url"));
291
292                         print "<br/>";
293
294                         print __('URL:') . " ";
295                         print "<input size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
296                                 name=\"feed_url\" value=\"$feed_url\">";
297
298                         /* Category */
299
300                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
301
302                                 $cat_id = db_fetch_result($result, 0, "cat_id");
303
304                                 print "<br/>";
305
306                                 print __('Place in category:') . " ";
307
308                                 print_feed_cat_select($link, "cat_id", $cat_id, $disabled);
309                         }
310
311                         print "</div>";
312
313                         print "<div class=\"dlgSec\">".__("Update")."</div>";
314                         print "<div class=\"dlgSecCont\">";
315
316                         /* Update Interval */
317
318                         $update_interval = db_fetch_result($result, 0, "update_interval");
319
320                         print_select_hash("update_interval", $update_interval, $update_intervals);
321
322                         /* Update method */
323
324                         $update_method = db_fetch_result($result, 0, "update_method");
325
326                         print " " . __('using') . " ";
327                         print_select_hash("update_method", $update_method, $update_methods);                    
328
329                         $purge_interval = db_fetch_result($result, 0, "purge_interval");
330
331                         if (FORCE_ARTICLE_PURGE == 0) {
332
333                                 /* Purge intl */
334
335                                 print "<br/>";
336
337                                 print __('Article purging:') . " ";
338
339                                 print_select_hash("purge_interval", $purge_interval, $purge_intervals);
340
341                         } else {
342                                 print "<input type='hidden' name='purge_interval' value='$purge_interval'>";
343
344                         }
345
346                         print "</div>";
347                         print "<div class=\"dlgSec\">".__("Authentication")."</div>";
348                         print "<div class=\"dlgSecCont\">";
349
350                         $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
351
352                         print "<table>";
353
354                         print "<tr><td>" . __('Login:') . "</td><td>";
355
356                         print "<input size=\"20\" onkeypress=\"return filterCR(event, feedEditSave)\"
357                                 name=\"auth_login\" value=\"$auth_login\">";
358
359                         print "</tr><tr><td>" . __("Password:") . "</td><td>";
360
361                         $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
362
363                         print "<input size=\"20\" type=\"password\" name=\"auth_pass\" 
364                                 onkeypress=\"return filterCR(event, feedEditSave)\"
365                                 value=\"$auth_pass\">";
366
367                         print "</td></tr></table>";
368
369                         print "</div>";
370                         print "<div class=\"dlgSec\">".__("Options")."</div>";
371                         print "<div class=\"dlgSecCont\">";
372
373                         print "<div style=\"line-height : 100%\">";
374
375                         $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
376
377                         if ($private) {
378                                 $checked = "checked";
379                         } else {
380                                 $checked = "";
381                         }
382
383                         print "<input type=\"checkbox\" name=\"private\" id=\"private\" 
384                                 $checked>&nbsp;<label for=\"private\">".__('Hide from Popular feeds')."</label>";
385
386                         $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
387
388                         if ($rtl_content) {
389                                 $checked = "checked";
390                         } else {
391                                 $checked = "";
392                         }
393
394                         print "<br/><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
395                                 $checked>&nbsp;<label for=\"rtl_content\">".__('Right-to-left content')."</label>";
396
397                         $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
398
399                         if ($include_in_digest) {
400                                 $checked = "checked";
401                         } else {
402                                 $checked = "";
403                         }
404
405                         print "<br/><input type=\"checkbox\" id=\"include_in_digest\" 
406                                 name=\"include_in_digest\"
407                                 $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
408
409
410                         $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
411
412                         if ($always_display_enclosures) {
413                                 $checked = "checked";
414                         } else {
415                                 $checked = "";
416                         }
417
418                         print "<br/><input type=\"checkbox\" id=\"always_display_enclosures\" 
419                                 name=\"always_display_enclosures\"
420                                 $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
421
422
423                         $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
424
425                         if ($cache_images) {
426                                 $checked = "checked";
427                         } else {
428                                 $checked = "";
429                         }
430
431                         if (SIMPLEPIE_CACHE_IMAGES) {
432                                 $disabled = "";
433                                 $label_class = "";
434                         } else {
435                                 $disabled = "disabled";
436                                 $label_class = "class='insensitive'";
437                         }
438
439                         print "<br/><input type=\"checkbox\" id=\"cache_images\" 
440                                 name=\"cache_images\" $disabled
441                                 $checked>&nbsp;<label $label_class for=\"cache_images\">".
442                                 __('Cache images locally')."</label>";
443
444
445                         print "</div>";
446                         print "</div>";
447
448                         print "</form>";
449
450                         /* Icon */
451
452                         print "<br/>";
453
454                         print "<div class=\"dlgSec\">".__("Icon")."</div>";
455                         print "<div class=\"dlgSecCont\">";
456
457                         print "<iframe name=\"icon_upload_iframe\"
458                                 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
459
460                         print "<form style='display : block' target=\"icon_upload_iframe\"
461                                 enctype=\"multipart/form-data\" method=\"POST\" 
462                                 action=\"backend.php\">
463                                 <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">
464                                 <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
465                                 <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
466                                 <input type=\"hidden\" name=\"subop\" value=\"uploadicon\">
467                                 <button onclick=\"return uploadFeedIcon();\"
468                                         type=\"submit\">".__('Replace')."</button>
469                                 <button onclick=\"return removeFeedIcon($feed_id);\"
470                                         type=\"submit\">".__('Remove')."</button>
471                                 </form>";
472
473                         print "</div>";
474
475                         $title = htmlspecialchars($title, ENT_QUOTES);
476
477                         print "<div class='dlgButtons'>
478                                 <div style=\"float : left\">
479                                 <button onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
480                                         __('Unsubscribe')."</button>
481                                 </div>
482                                 <button onclick=\"return feedEditSave()\">".__('Save')."</button>
483                                 <button onclick=\"return feedEditCancel()\">".__('Cancel')."</button>
484                                 </div>";
485
486                         print "]]></content></dlg>";
487
488                         return;
489                 }
490
491                 if ($subop == "editfeeds") {
492
493                         $feed_ids = db_escape_string($_REQUEST["ids"]);
494                         
495                         header("Content-Type: text/xml");
496                         print "<dlg id=\"$subop\">";
497                         print "<title>".__('Multiple Feed Editor')."</title>";
498                         print "<content><![CDATA[";
499
500                         print "<form id=\"batch_edit_feed_form\" onsubmit=\"return false\">";   
501
502                         print "<input type=\"hidden\" name=\"ids\" value=\"$feed_ids\">";
503                         print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
504                         print "<input type=\"hidden\" name=\"subop\" value=\"batchEditSave\">";
505
506                         print "<div class=\"dlgSec\">".__("Feed")."</div>";
507                         print "<div class=\"dlgSecCont\">";
508
509                         /* Title */
510
511                         print "<input disabled style=\"font-size : 16px\" size=\"35\" onkeypress=\"return filterCR(event, feedEditSave)\"
512                                             name=\"title\" value=\"$title\">";
513
514                         batch_edit_cbox("title");
515
516                         /* Feed URL */
517
518                         print "<br/>";
519
520                         print __('URL:') . " ";
521                         print "<input disabled size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
522                                 name=\"feed_url\" value=\"$feed_url\">";
523
524                         batch_edit_cbox("feed_url");
525
526                         /* Category */
527
528                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
529
530                                 print "<br/>";
531
532                                 print __('Place in category:') . " ";
533
534                                 print_feed_cat_select($link, "cat_id", $cat_id, "disabled");
535
536                                 batch_edit_cbox("cat_id");
537
538                         }
539
540                         print "</div>";
541
542                         print "<div class=\"dlgSec\">".__("Update")."</div>";
543                         print "<div class=\"dlgSecCont\">";
544
545                         /* Update Interval */
546
547                         print_select_hash("update_interval", $update_interval, $update_intervals, 
548                                 "disabled");
549
550                         batch_edit_cbox("update_interval");
551
552                         /* Update method */
553
554                         print " " . __('using') . " ";
555                         print_select_hash("update_method", $update_method, $update_methods, 
556                                 "disabled");                    
557                         batch_edit_cbox("update_method");
558
559                         /* Purge intl */
560
561                         if (FORCE_ARTICLE_PURGE != 0) {
562
563                                 print "<br/>";
564
565                                 print __('Article purging:') . " ";
566
567                                 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
568                                         "disabled");
569
570                                 batch_edit_cbox("purge_interval");
571                         }
572
573                         print "</div>";
574                         print "<div class=\"dlgSec\">".__("Authentication")."</div>";
575                         print "<div class=\"dlgSecCont\">";
576
577                         print __('Login:') . " ";
578                         print "<input disabled size=\"15\" onkeypress=\"return filterCR(event, feedEditSave)\"
579                                 name=\"auth_login\" value=\"$auth_login\">";
580
581                         batch_edit_cbox("auth_login");
582
583                         print " " . __("Password:") . " ";
584
585                         print "<input disabled size=\"15\" type=\"password\" name=\"auth_pass\" 
586                                 onkeypress=\"return filterCR(event, feedEditSave)\"
587                                 value=\"$auth_pass\">";
588
589                         batch_edit_cbox("auth_pass");
590
591                         print "</div>";
592                         print "<div class=\"dlgSec\">".__("Options")."</div>";
593                         print "<div class=\"dlgSecCont\">";
594
595                         print "<div style=\"line-height : 100%\">";
596
597                         print "<input disabled type=\"checkbox\" name=\"private\" id=\"private\" 
598                                 $checked>&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
599
600                         print "&nbsp;"; batch_edit_cbox("private", "private_l");
601
602                         print "<br/><input disabled type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
603                                 $checked>&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
604
605                         print "&nbsp;"; batch_edit_cbox("rtl_content", "rtl_content_l");
606
607                         print "<br/><input disabled type=\"checkbox\" id=\"include_in_digest\" 
608                                 name=\"include_in_digest\" 
609                                 $checked>&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
610
611                         print "&nbsp;"; batch_edit_cbox("include_in_digest", "include_in_digest_l");
612
613                         print "<br/><input disabled type=\"checkbox\" id=\"always_display_enclosures\" 
614                                 name=\"always_display_enclosures\" 
615                                 $checked>&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
616
617                         print "&nbsp;"; batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
618
619                         print "<br/><input disabled type=\"checkbox\" id=\"cache_images\" 
620                                 name=\"cache_images\" 
621                                 $checked>&nbsp;<label class='insensitive' id=\"cache_images_l\" 
622                                         for=\"cache_images\">".
623                                 __('Cache images locally')."</label>";
624
625
626                         if (SIMPLEPIE_CACHE_IMAGES) {
627                                 print "&nbsp;"; batch_edit_cbox("cache_images", "cache_images_l");
628                         }
629
630                         print "</div>";
631                         print "</div>";
632
633                         print "</form>";
634
635                         print "<div class='dlgButtons'>
636                                 <input type=\"submit\" class=\"button\" 
637                                 onclick=\"return feedsEditSave()\" value=\"".__('Save')."\">
638                                 <input type='submit' class='button'                     
639                                 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\">
640                                 </div>";
641
642                         print "]]></content></dlg>";
643
644                         return;
645                 }
646
647                 if ($subop == "editSave" || $subop == "batchEditSave") {
648
649                         $feed_title = db_escape_string(trim($_POST["title"]));
650                         $feed_link = db_escape_string(trim($_POST["feed_url"]));
651                         $upd_intl = db_escape_string($_POST["update_interval"]);
652                         $purge_intl = db_escape_string($_POST["purge_interval"]);
653                         $feed_id = db_escape_string($_POST["id"]); /* editSave */
654                         $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */
655                         $cat_id = db_escape_string($_POST["cat_id"]);
656                         $auth_login = db_escape_string(trim($_POST["auth_login"]));
657                         $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
658                         $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
659                         $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
660                         $include_in_digest = checkbox_to_sql_bool(
661                                 db_escape_string($_POST["include_in_digest"]));
662                         $cache_images = checkbox_to_sql_bool(
663                                 db_escape_string($_POST["cache_images"]));
664                         $update_method = (int) db_escape_string($_POST["update_method"]);
665
666                         $always_display_enclosures = checkbox_to_sql_bool(
667                                 db_escape_string($_POST["always_display_enclosures"]));
668
669                         if (get_pref($link, 'ENABLE_FEED_CATS')) {                      
670                                 if ($cat_id && $cat_id != 0) {
671                                         $category_qpart = "cat_id = '$cat_id',";
672                                         $category_qpart_nocomma = "cat_id = '$cat_id'";
673                                 } else {
674                                         $category_qpart = 'cat_id = NULL,';
675                                         $category_qpart_nocomma = 'cat_id = NULL';
676                                 }
677                         } else {
678                                 $category_qpart = "";
679                                 $category_qpart_nocomma = "";
680                         }
681
682                         if (SIMPLEPIE_CACHE_IMAGES) {
683                                 $cache_images_qpart = "cache_images = $cache_images,";
684                         } else {
685                                 $cache_images_qpart = "";
686                         }
687
688                         if ($subop == "editSave") {
689
690                                 $result = db_query($link, "UPDATE ttrss_feeds SET 
691                                         $category_qpart
692                                         title = '$feed_title', feed_url = '$feed_link',
693                                         update_interval = '$upd_intl',
694                                         purge_interval = '$purge_intl',
695                                         auth_login = '$auth_login',
696                                         auth_pass = '$auth_pass',
697                                         private = $private,
698                                         rtl_content = $rtl_content,
699                                         $cache_images_qpart
700                                         include_in_digest = $include_in_digest,
701                                         always_display_enclosures = $always_display_enclosures,
702                                         update_method = '$update_method'
703                                         WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
704
705                         } else if ($subop == "batchEditSave") {
706                                 $feed_data = array();
707
708                                 foreach (array_keys($_POST) as $k) {
709                                         if ($k != "op" && $k != "subop" && $k != "ids") {
710                                                 $feed_data[$k] = $_POST[$k];
711                                         }
712                                 }
713
714                                 db_query($link, "BEGIN");
715
716                                 foreach (array_keys($feed_data) as $k) {
717
718                                         $qpart = "";
719
720                                         switch ($k) {
721                                                 case "title":                                                   
722                                                         $qpart = "title = '$feed_title'";
723                                                         break;
724
725                                                 case "feed_url":
726                                                         $qpart = "feed_url = '$feed_link'";
727                                                         break;
728
729                                                 case "update_interval":
730                                                         $qpart = "update_interval = '$upd_intl'";
731                                                         break;
732
733                                                 case "purge_interval":
734                                                         $qpart = "purge_interval = '$purge_intl'";
735                                                         break;
736
737                                                 case "auth_login":
738                                                         $qpart = "auth_login = '$auth_login'";
739                                                         break;
740
741                                                 case "auth_pass":
742                                                         $qpart = "auth_pass = '$auth_pass'";
743                                                         break;
744
745                                                 case "private":
746                                                         $qpart = "private = '$private'";
747                                                         break;
748
749                                                 case "include_in_digest":
750                                                         $qpart = "include_in_digest = '$include_in_digest'";
751                                                         break;
752
753                                                 case "always_display_enclosures":
754                                                         $qpart = "always_display_enclosures = '$always_display_enclosures'";
755                                                         break;
756
757                                                 case "cache_images":
758                                                         $qpart = "cache_images = '$cache_images'";
759                                                         break;
760
761                                                 case "rtl_content":
762                                                         $qpart = "rtl_content = '$rtl_content'";
763                                                         break;
764
765                                                 case "update_method":
766                                                         $qpart = "update_method = '$update_method'";
767                                                         break;
768
769                                                 case "cat_id":
770                                                         $qpart = $category_qpart_nocomma;
771                                                         break;
772
773                                         }
774
775                                         if ($qpart) {
776                                                 db_query($link,
777                                                         "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
778                                                         AND owner_uid = " . $_SESSION["uid"]);
779                                                 print "<br/>";
780                                         }
781                                 }
782
783                                 db_query($link, "COMMIT");
784                         }
785
786                 }
787
788                 if ($subop == "remove") {
789
790                         $ids = split(",", db_escape_string($_REQUEST["ids"]));
791
792                         foreach ($ids as $id) {
793                                 remove_feed($link, $id, $_SESSION["uid"]);
794                         }
795
796                         return;
797                 }
798
799                 if ($subop == "clear") {
800                         $id = db_escape_string($_REQUEST["id"]);
801                         clear_feed_articles($link, $id);
802                 }
803
804                 if ($subop == "rescore") {
805                         $ids = split(",", db_escape_string($_REQUEST["ids"]));
806
807                         foreach ($ids as $id) {
808
809                                 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
810
811                                 $result = db_query($link, "SELECT 
812                                         title, content, link, ref_id, author,".
813                                         SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
814                                         FROM
815                                                 ttrss_user_entries, ttrss_entries 
816                                                 WHERE ref_id = id AND feed_id = '$id' AND 
817                                                         owner_uid = " .$_SESSION['uid']."
818                                                 ");
819
820                                 $scores = array();
821
822                                 while ($line = db_fetch_assoc($result)) {
823
824                                         $tags = get_article_tags($link, $line["ref_id"]);
825
826                                         $article_filters = get_article_filters($filters, $line['title'], 
827                                                 $line['content'], $line['link'], strtotime($line['updated']), 
828                                                 $line['author'], $tags);
829                                         
830                                         $new_score = calculate_article_score($article_filters);
831
832                                         if (!$scores[$new_score]) $scores[$new_score] = array();
833
834                                         array_push($scores[$new_score], $line['ref_id']);
835                                 }
836
837                                 foreach (array_keys($scores) as $s) {
838                                         if ($s > 1000) {
839                                                 db_query($link, "UPDATE ttrss_user_entries SET score = '$s', 
840                                                         marked = true WHERE
841                                                         ref_id IN (" . join(',', $scores[$s]) . ")");
842                                         } else if ($s < -500) {
843                                                 db_query($link, "UPDATE ttrss_user_entries SET score = '$s', 
844                                                         unread = false WHERE
845                                                         ref_id IN (" . join(',', $scores[$s]) . ")");
846                                         } else {
847                                                 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
848                                                         ref_id IN (" . join(',', $scores[$s]) . ")");
849                                         }
850                                 }
851                         }
852
853                         print __("All done.");
854
855                 }
856
857                 if ($subop == "rescoreAll") {
858
859                         $result = db_query($link, 
860                                 "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
861
862                         while ($feed_line = db_fetch_assoc($result)) {
863
864                                 $id = $feed_line["id"];
865
866                                 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
867
868                                 $tmp_result = db_query($link, "SELECT 
869                                         title, content, link, ref_id, author,".
870                                                 SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
871                                                 FROM
872                                                 ttrss_user_entries, ttrss_entries 
873                                                 WHERE ref_id = id AND feed_id = '$id' AND 
874                                                         owner_uid = " .$_SESSION['uid']."
875                                                 ");
876
877                                 $scores = array();
878
879                                 while ($line = db_fetch_assoc($tmp_result)) {
880
881                                         $tags = get_article_tags($link, $line["ref_id"]);
882
883                                         $article_filters = get_article_filters($filters, $line['title'], 
884                                                 $line['content'], $line['link'], strtotime($line['updated']), 
885                                                 $line['author'], $tags);
886
887                                         $new_score = calculate_article_score($article_filters);
888
889                                         if (!$scores[$new_score]) $scores[$new_score] = array();
890
891                                         array_push($scores[$new_score], $line['ref_id']);
892                                 }
893
894                                 foreach (array_keys($scores) as $s) {
895                                         if ($s > 1000) {
896                                                 db_query($link, "UPDATE ttrss_user_entries SET score = '$s', 
897                                                         marked = true WHERE
898                                                         ref_id IN (" . join(',', $scores[$s]) . ")");
899                                         } else {
900                                                 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
901                                                         ref_id IN (" . join(',', $scores[$s]) . ")");
902                                         }
903                                 }
904                         }
905
906                         print __("All done.");
907
908                 }
909
910                 if ($subop == "add") {
911
912                         $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
913                         $cat_id = db_escape_string($_REQUEST["cat_id"]);
914                         $p_from = db_escape_string($_REQUEST["from"]);
915
916                         /* only read authentication information from POST */
917
918                         $auth_login = db_escape_string(trim($_POST["auth_login"]));
919                         $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
920
921                         if ($p_from != 'tt-rss') {
922                                 print "<html>
923                                         <head>
924                                                 <title>Tiny Tiny RSS</title>
925                                                 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
926                                         </head>
927                                         <body>
928                                         <img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
929                                                 alt=\"Tiny Tiny RSS\"/> 
930                                         <h1>Subscribe to feed...</h1>";
931                         }
932
933                         $rc = subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass);
934
935                         switch ($rc) {
936                         case 1: 
937                                 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
938                                 break;
939                         case 2:
940                                 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
941                                 break;
942                         case 0:
943                                 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
944                                 break;
945                         }
946
947                         if ($p_from != 'tt-rss') {
948                                 $tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
949
950
951                                 $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
952
953                                 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
954                                         feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
955
956                                 $feed_id = db_fetch_result($result, 0, "id");
957
958                                 print "<p>";
959
960                                 if ($feed_id) {
961                                         print "<form method=\"GET\" style='display: inline' 
962                                                 action=\"$tp_uri\">
963                                                 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
964                                                 <input type=\"hidden\" name=\"subop\" value=\"editFeed\">
965                                                 <input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
966                                                 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
967                                                 </form>";
968                                 }
969
970                                 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
971                                         <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
972                                         </form></p>";
973
974                                 print "</body></html>";
975                                 return;
976                         }
977                 }
978
979                 if ($subop == "categorize") {
980
981
982                         $ids = split(",", db_escape_string($_REQUEST["ids"]));
983
984                         $cat_id = db_escape_string($_REQUEST["cat_id"]);
985
986                         if ($cat_id == 0) {
987                                 $cat_id_qpart = 'NULL';
988                         } else {
989                                 $cat_id_qpart = "'$cat_id'";
990                         }
991
992                         db_query($link, "BEGIN");
993
994                         foreach ($ids as $id) {
995                         
996                                 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
997                                         WHERE id = '$id'
998                                         AND owner_uid = " . $_SESSION["uid"]);
999
1000                         }
1001
1002                         db_query($link, "COMMIT");
1003
1004                 }
1005
1006                 if ($subop == "editCats") {
1007
1008                         $action = $_REQUEST["action"];
1009
1010                         if ($action == "save") {
1011
1012                                 $cat_title = db_escape_string(trim($_REQUEST["value"]));
1013                                 $cat_id = db_escape_string($_REQUEST["cid"]);
1014
1015                                 db_query($link, "BEGIN");
1016
1017                                 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
1018                                         WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1019
1020                                 if (db_num_rows($result) == 1) {
1021
1022                                         $old_title = db_fetch_result($result, 0, "title");
1023                                         
1024                                         if ($cat_title != "") {
1025                                                 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1026                                                         title = '$cat_title' WHERE id = '$cat_id' AND 
1027                                                         owner_uid = ".$_SESSION["uid"]);
1028
1029                                                 print $cat_title;
1030                                         } else {
1031                                                 print $old_title;
1032                                         }
1033                                 } else {
1034                                         print $_REQUEST["value"];
1035                                 }
1036
1037                                 db_query($link, "COMMIT");
1038
1039                                 return;
1040
1041                         }
1042
1043                         header("Content-Type: text/xml");
1044                         print "<dlg id=\"$subop\">";
1045                         print "<title>".__('Category editor')."</title>";
1046                         print "<content><![CDATA[";
1047
1048                         if ($action == "add") {
1049
1050                                 $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
1051
1052                                 if (!add_feed_category($link, $feed_cat))
1053                                         print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.", $feed_cat));
1054
1055                         }
1056
1057                         if ($action == "remove") {
1058         
1059                                 $ids = split(",", db_escape_string($_REQUEST["ids"]));
1060         
1061                                 foreach ($ids as $id) {
1062                                         remove_feed_category($link, $id, $_SESSION["uid"]);
1063                                 }
1064                         }
1065
1066                         print "<div dojoType=\"dijit.Toolbar\">
1067                                 <input id=\"fadd_cat\" 
1068                                         onkeypress=\"return filterCR(event, addFeedCat)\"
1069                                         size=\"40\">
1070                                         <button onclick=\"addFeedCat()\">".
1071                                         __('Create category')."</button></div>";
1072         
1073                         $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1074                                 WHERE owner_uid = ".$_SESSION["uid"]."
1075                                 ORDER BY title");
1076
1077 #                       print "<p>";
1078
1079                         if (db_num_rows($result) != 0) {
1080
1081 #                               print   __('Select:')." 
1082 #                                       <a href=\"#\" onclick=\"selectTableRows('prefFeedCatList', 'all')\">".__('All')."</a>,
1083 #                                       <a href=\"#\" onclick=\"selectTableRows('prefFeedCatList', 'none')\">".__('None')."</a>";
1084 #
1085                                 print "<div class=\"prefFeedCatHolder\">";
1086
1087                                 print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
1088
1089                                 print "<table width=\"100%\" class=\"prefFeedCatList\" 
1090                                         cellspacing=\"0\" id=\"prefFeedCatList\">";
1091                                                 
1092                                 $lnum = 0;
1093                                 
1094                                 while ($line = db_fetch_assoc($result)) {
1095                 
1096                                         $class = ($lnum % 2) ? "even" : "odd";
1097                 
1098                                         $cat_id = $line["id"];
1099                                         $this_row_id = "id=\"FCATR-$cat_id\"";
1100                 
1101                                         print "<tr class=\"\" $this_row_id>";
1102                 
1103                                         $edit_title = htmlspecialchars($line["title"]);
1104                 
1105                                         print "<td width='5%' align='center'><input 
1106                                                 onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" 
1107                                                 type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
1108         
1109                                         print "<td>";
1110                                         
1111 #                                       print "<span id=\"FCATT-$cat_id\">" . 
1112 #                                               $edit_title . "</span>";                
1113
1114                                         print "<span dojoType=\"dijit.InlineEditBox\" 
1115                                                 width=\"300px\" autoSave=\"false\"
1116                                                 cat-id=\"$cat_id\">" . $edit_title . 
1117                                                 "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
1118                                                         var elem = this;
1119                                                         dojo.xhrPost({
1120                                                                 url: 'backend.php',
1121                                                                 content: {op: 'pref-feeds', subop: 'editCats',
1122                                                                         action: 'save',
1123                                                                         value: this.value,
1124                                                                         cid: this.srcNodeRef.getAttribute('cat-id')},
1125                                                                         load: function(response) {
1126                                                                                 elem.attr('value', response);
1127                                                                 }
1128                                                         });     
1129                                                 </script>
1130                                         </span>";
1131
1132                                         print "</td></tr>";
1133                 
1134                                         ++$lnum;
1135                                 }
1136         
1137                                 print "</table>";
1138
1139                                 print "</form>";
1140
1141                                 print "</div>";
1142
1143                         } else {
1144                                 print "<p>".__('No feed categories defined.')."</p>";
1145                         }
1146
1147                         print "<div class='dlgButtons'>
1148                                 <div style='float : left'>
1149                                 <button onclick=\"return removeSelectedFeedCats()\">".
1150                                 __('Remove')."</button>
1151                                 </div>";
1152
1153                         print "<button onclick=\"selectTab('feedConfig')\">".
1154                                 __('Close this window')."</button></div>";
1155
1156                         print "]]></content></dlg>";
1157
1158                         return;
1159
1160                 }
1161
1162                 if ($quiet) return;
1163
1164                 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
1165                 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">";
1166
1167                 set_pref($link, "_PREFS_ACTIVE_TAB", "feedConfig");
1168
1169                 $result = db_query($link, "SELECT COUNT(id) AS num_errors
1170                         FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1171
1172                 $num_errors = db_fetch_result($result, 0, "num_errors");
1173
1174                 if ($num_errors > 0) {
1175
1176                         $error_button = "<button dojoType=\"dijit.form.Button\"
1177                                         onclick=\"showFeedsWithErrors\" id=\"errorButton\">" .
1178                                 __("Feeds with errors") . "</button>";
1179
1180 //                      print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
1181 //                              __('Some feeds have update errors (click for details)')."</a>");
1182                 }
1183
1184                 $feed_search = db_escape_string($_REQUEST["search"]);
1185
1186                 if (array_key_exists("search", $_REQUEST)) {
1187                         $_SESSION["prefs_feed_search"] = $feed_search;
1188                 } else {
1189                         $feed_search = $_SESSION["prefs_feed_search"];
1190                 }
1191
1192                 print "<div dojoType=\"dijit.Toolbar\">";
1193
1194                 /* 
1195                 print "<div style='float : right'> 
1196                         <input id=\"feed_search\" size=\"20\" type=\"search\"
1197                                 onfocus=\"disableHotkeys();\" 
1198                                 onblur=\"enableHotkeys();\"
1199                                 onchange=\"updateFeedList()\" value=\"$feed_search\">
1200                         <button onclick=\"updateFeedList()\">".
1201                                 __('Search')."</button>
1202                                 </div>"; */
1203
1204                 print "<div dojoType=\"dijit.form.DropDownButton\">".
1205                                 "<span>" . __('Select')."</span>";
1206                 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1207                 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\" 
1208                         dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1209                 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\" 
1210                         dojoType=\"dijit.MenuItem\">".__('None')."</div>";
1211                 print "</div></div>";
1212
1213                 print "<div dojoType=\"dijit.form.DropDownButton\">".
1214                                 "<span>" . __('Feeds')."</span>";
1215                 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1216                 print "<div onclick=\"quickAddFeed()\" 
1217                         dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>";
1218                 print "<div onclick=\"editSelectedFeed()\" 
1219                         dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
1220                 print "<div onclick=\"resetFeedOrder()\" 
1221                         dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
1222                 print "</div></div>";
1223
1224                 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1225                         print "<div dojoType=\"dijit.form.DropDownButton\">".
1226                                         "<span>" . __('Categories')."</span>";
1227                         print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1228                         print "<div onclick=\"editFeedCats()\" 
1229                                 dojoType=\"dijit.MenuItem\">".__('Edit categories')."</div>";
1230                         print "<div onclick=\"resetCatOrder()\" 
1231                                 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
1232                         print "</div></div>";
1233
1234                 }
1235
1236                 print $error_button;
1237
1238                 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedFeeds()\">"
1239                         .__('Unsubscribe')."</button dojoType=\"dijit.form.Button\"> ";
1240
1241                 if (defined('_ENABLE_FEED_DEBUGGING')) {
1242
1243                         print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1244                                 <option value=\"facDefault\" selected>".__('More actions...')."</option>";
1245         
1246                         if (FORCE_ARTICLE_PURGE == 0) {
1247                                 print 
1248                                         "<option value=\"facPurge\">".__('Manual purge')."</option>";
1249                         }
1250         
1251                         print "
1252                                 <option value=\"facClear\">".__('Clear feed data')."</option>
1253                                 <option value=\"facRescore\">".__('Rescore articles')."</option>";
1254         
1255                         print "</select>";
1256
1257                 }
1258
1259                 print "</div>"; # toolbar
1260
1261                 print "<div id=\"feedlistLoading\">
1262                 <img src='images/indicator_tiny.gif'>".
1263                  __("Loading, please wait...")."</div>";
1264
1265                 print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\" 
1266                         url=\"backend.php?op=pref-feeds&subop=getfeedtree\">
1267                 </div>
1268                 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\"
1269                 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
1270                         childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
1271                 </div>
1272                 <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\" 
1273                         dndController=\"dijit.tree.dndSource\" 
1274                         betweenThreshold=\"5\"
1275                         model=\"feedModel\" openOnClick=\"false\">
1276                 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
1277                         var id = String(item.id);
1278                         var bare_id = id.substr(id.indexOf(':')+1);
1279
1280                         if (id.match('FEED:')) {
1281                                 editFeed(bare_id, event);
1282                         } else if (id.match('CAT:')) {
1283                                 editCat(bare_id, item, event);
1284                         }                       
1285                 </script>
1286                 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
1287                         Element.hide(\"feedlistLoading\");
1288                 </script>
1289                 </div>";
1290
1291                 print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
1292                         <b>Hint:</b> you can drag feeds and categories around.
1293                         </div>";
1294
1295                 print "</div>"; # feeds pane
1296
1297                 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
1298
1299                 print "<p>" . __("Using OPML you can export and import your feeds and Tiny Tiny RSS settings.");
1300
1301                 print "<div class=\"insensitive\">" . __("Note: Only main settings profile can be migrated using OPML.") . "</div>";
1302
1303                 print "</p>";
1304
1305                 print "<iframe name=\"upload_iframe\"
1306                         style=\"width: 400px; height: 100px; display: none;\"></iframe>";
1307
1308                 print "<div style='float : left'>";
1309                 print "<form style='display : block' target=\"upload_iframe\"
1310                         enctype=\"multipart/form-data\" method=\"POST\" 
1311                                 action=\"backend.php\">
1312                         <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1313                         <input type=\"hidden\" name=\"op\" value=\"dlg\">
1314                         <input type=\"hidden\" name=\"id\" value=\"importOpml\">
1315                         <button onclick=\"return opmlImport();\"
1316                                 type=\"submit\">".__('Import')."</button>
1317                         </form>";
1318                 print "</div>&nbsp;";
1319
1320                 print "<button onclick=\"gotoExportOpml()\">".__('Export OPML')."</button>";
1321
1322                 print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.');
1323
1324                 print "<div class=\"insensitive\">" . __("Note: Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") .                  "</div>" . "</p>";
1325
1326                 print "<button onclick=\"return displayDlg('pubOPMLUrl')\">".
1327                         __('Display URL')."</button> ";
1328
1329
1330                 print "</div>"; # pane
1331
1332                 if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
1333
1334                         print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
1335                 
1336                         print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
1337
1338                         print "<p>";
1339
1340                         print "<button onclick='window.navigator.registerContentHandler(" .
1341                       "\"application/vnd.mozilla.maybe.feed\", " .
1342                       "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
1343                                                          __('Click here to register this site as a feed reader.') . 
1344                                 "</button>";
1345
1346                         print "</p>";
1347
1348                         print "</div>"; # pane
1349                 }
1350
1351                 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Subscribing using bookmarklet')."\">";
1352                 
1353                 print "<p>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</p>";
1354
1355                 $bm_subscribe_url = str_replace('%s', '', add_feed_url());
1356
1357                 $confirm_str = __('Subscribe to %s in Tiny Tiny RSS?');
1358
1359                 $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}");
1360
1361                 print "<a href=\"$bm_url\" class='visibleLink'>" . __('Subscribe in Tiny Tiny RSS'). "</a>";
1362
1363                 print "</div>"; #pane
1364
1365                 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published articles and generated feeds')."\">";
1366
1367                 print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
1368
1369                 $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . 
1370                                 "/backend.php?op=rss&id=-2&view-mode=all_articles");;
1371
1372                 print "<button onclick=\"return displayDlg('generatedFeed', '$rss_url')\">".
1373                         __('Display URL')."</button> ";
1374                
1375                 print "<button onclick=\"return clearFeedAccessKeys()\">".
1376                         __('Clear all generated URLs')."</button> ";
1377
1378                 print "</div>"; #pane
1379                 print "</div>"; #container
1380
1381         }
1382
1383         function print_feed_browser($link, $search, $limit, $mode = 1) {
1384
1385                         $owner_uid = $_SESSION["uid"];
1386
1387                         if ($search) {
1388                                 $search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR 
1389                                         UPPER(title) LIKE UPPER('%$search%'))";
1390                         } else {
1391                                 $search_qpart = "";
1392                         }
1393
1394                         if ($mode == 1) {
1395                                 $result = db_query($link, "SELECT feed_url, subscribers FROM
1396                                         ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1397                                         WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
1398                                         AND owner_uid = '$owner_uid') $search_qpart 
1399                                         ORDER BY subscribers DESC LIMIT $limit");
1400                         } else if ($mode == 2) {
1401                                 $result = db_query($link, "SELECT *,
1402                                         (SELECT COUNT(*) FROM ttrss_user_entries WHERE
1403                                                 orig_feed_id = ttrss_archived_feeds.id) AS articles_archived
1404                                         FROM
1405                                                 ttrss_archived_feeds
1406                                         WHERE 
1407                                         (SELECT COUNT(*) FROM ttrss_feeds 
1408                                                 WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND
1409                                                         owner_uid = '$owner_uid') = 0   AND                                     
1410                                         owner_uid = '$owner_uid' $search_qpart 
1411                                         ORDER BY id DESC LIMIT $limit");
1412                         }
1413
1414                         $feedctr = 0;
1415                         
1416                         while ($line = db_fetch_assoc($result)) {
1417
1418                                 if ($mode == 1) {
1419
1420                                         $feed_url = $line["feed_url"];
1421                                         $subscribers = $line["subscribers"];
1422
1423                                         $det_result = db_query($link, "SELECT site_url,title,id 
1424                                                 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1425         
1426                                         $details = db_fetch_assoc($det_result);
1427                                 
1428                                         $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1429         
1430                                         if (file_exists($icon_file) && filesize($icon_file) > 0) {
1431                                                         $feed_icon = "<img style=\"vertical-align : middle\" class=\"tinyFeedIcon\"     src=\"" . ICONS_URL . 
1432                                                                 "/".$details["id"].".ico\">";
1433                                         } else {
1434                                                 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1435                                         }
1436         
1437                                         $check_box = "<input onclick='toggleSelectListRow2(this)' 
1438                                                 dojoType=\"dijit.form.CheckBox\"
1439                                                 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1440         
1441                                         $class = ($feedctr % 2) ? "even" : "odd";
1442         
1443                                         $feed_url = htmlspecialchars($line["feed_url"]);
1444
1445                                         if ($details["site_url"]) {
1446                                                 $site_url = "<a target=\"_blank\" href=\"".
1447                                                         htmlspecialchars($details["site_url"])."\">
1448                                                         <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1449                                         } else {
1450                                                 $site_url = "";
1451                                         }
1452
1453                                         $feed_url = "<a target=\"_blank\" href=\"$feed_url\"><img 
1454                                                 style='border-width : 0px; vertical-align : middle' 
1455                                                 src='images/feed-icon-12x12.png'></a>";
1456
1457                                         print "<li title=\"".htmlspecialchars($details["site_url"])."\" 
1458                                                 id=\"FBROW-".$details["id"]."\">$check_box".
1459                                                 "$feed_icon $feed_url " . htmlspecialchars($details["title"]) . 
1460                                                 "&nbsp;<span class='subscribers'>($subscribers)</span>
1461                                                 $site_url</li>";
1462         
1463                                 } else if ($mode == 2) {
1464                                         $feed_url = htmlspecialchars($line["feed_url"]);
1465                                         $site_url = htmlspecialchars($line["site_url"]); 
1466                                         $title = htmlspecialchars($line["title"]);
1467
1468                                         $icon_file = ICONS_DIR . "/" . $line["id"] . ".ico";
1469         
1470                                         if (file_exists($icon_file) && filesize($icon_file) > 0) {
1471                                                         $feed_icon = "<img class=\"tinyFeedIcon\"       src=\"" . ICONS_URL . 
1472                                                                 "/".$line["id"].".ico\">";
1473                                         } else {
1474                                                 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1475                                         }
1476
1477                                         $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' 
1478                                                 type=\"checkbox\" id=\"FBCHK-" . $line["id"] . "\">";
1479         
1480                                         $class = ($feedctr % 2) ? "even" : "odd";
1481
1482                                         if ($line['articles_archived'] > 0) {
1483                                                 $archived = sprintf(__("%d archived articles"), $line['articles_archived']);
1484                                                 $archived = "&nbsp;<span class='subscribers'>($archived)</span>";
1485                                         } else {
1486                                                 $archived = '';
1487                                         }
1488
1489                                         if ($line["site_url"]) {
1490                                                 $site_url = "<a target=\"_blank\" href=\"$site_url\">
1491                                                         <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1492                                         } else {
1493                                                 $site_url = "";
1494                                         }
1495
1496                                         $feed_url = "<a target=\"_blank\" href=\"$feed_url\"><img 
1497                                                 style='border-width : 0px; vertical-align : middle' 
1498                                                 src='images/feed-icon-12x12.png'></a>";
1499
1500                                         print "<li title='".$line['site_url']."' class='$class' 
1501                                                 id=\"FBROW-".$line["id"]."\">".
1502                                                 $check_box . "$feed_icon $feed_url " . $title . 
1503                                                 $archived . $site_url . "</li>";
1504
1505
1506                                 }
1507
1508                                 ++$feedctr;
1509                         }
1510
1511                         if ($feedctr == 0) {
1512                                 print "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";
1513                         }
1514
1515                 return $feedctr;
1516
1517         }
1518
1519 ?>