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