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