root/modules/pref-feeds.php

Revision 2684, 40.8 kB (checked in by Andrew Dolgov <fox@madoka.spb.ru>, 4 days ago)

[project @ feed edit dialog: make unsubscribe button work for feeds with quotes in title]

Line 
1 <?php
2
3     function batch_edit_cbox($elem, $label = false) {
4         print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\"
5             onchange=\"batchFeedsToggleField(this, '$elem', '$label')\">";
6     }
7
8     function module_pref_feeds($link) {
9
10         global $update_intervals;
11         global $purge_intervals;
12         global $update_methods;
13
14         $subop = $_REQUEST["subop"];
15         $quiet = $_REQUEST["quiet"];
16
17         if ($subop == "massSubscribe") {
18             $ids = split(",", db_escape_string($_GET["ids"]));
19
20             $subscribed = array();
21
22             foreach ($ids as $id) {
23                 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
24                     WHERE id = '$id'");
25
26                 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
27                 $title = db_escape_string(db_fetch_result($result, 0, "title"));
28
29                 $title_orig = db_fetch_result($result, 0, "title");
30
31                 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
32                     feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
33
34                 if (db_num_rows($result) == 0) {           
35                     $result = db_query($link,
36                         "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
37                         VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
38
39                     array_push($subscribed, $title_orig);
40                 }
41             }
42
43             if (count($subscribed) > 0) {
44                 $msg = "<b>".__('Subscribed to feeds:')."</b>".
45                     "<ul class=\"nomarks\">";
46
47                 foreach ($subscribed as $title) {
48                     $msg .= "<li>$title</li>";
49                 }
50                 $msg .= "</ul>";
51
52                 print format_notice($msg);
53             }
54         }       
55
56         if ($subop == "browse") {
57
58             if (!ENABLE_FEED_BROWSER) {
59                 print __("Feed browser is administratively disabled.");
60                 return;
61             }
62
63             print "<div id=\"infoBoxTitle\">".__('Other feeds: Top 25')."</div>";
64             
65             print "<div class=\"infoBoxContents\">";
66
67             print "<p>".__("Showing top 25 registered feeds, sorted by popularity:")."</p>";
68
69             $owner_uid = $_SESSION["uid"];
70
71             $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
72                   FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
73                     WHERE tf.feed_url = ttrss_feeds.feed_url
74                         AND owner_uid = '$owner_uid') GROUP BY feed_url
75                             ORDER BY subscribers DESC LIMIT 25");
76
77             print "<ul class='browseFeedList' id='browseFeedList'>";
78
79             $feedctr = 0;
80             
81             while ($line = db_fetch_assoc($result)) {
82                 $feed_url = $line["feed_url"];
83                 $subscribers = $line["subscribers"];
84
85                 $det_result = db_query($link, "SELECT site_url,title,id
86                     FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
87
88                 $details = db_fetch_assoc($det_result);
89             
90                 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
91
92                 if (file_exists($icon_file) && filesize($icon_file) > 0) {
93                         $feed_icon = "<img class=\"tinyFeedIcon\"    src=\"" . ICONS_URL .
94                             "/".$details["id"].".ico\">";
95                 } else {
96                     $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
97                 }
98
99                 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
100                     type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
101
102                 $class = ($feedctr % 2) ? "even" : "odd";
103
104                 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
105                     "$feed_icon " . $details["title"] .
106                     "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
107
108                     ++$feedctr;
109             }
110
111             if ($feedctr == 0) {
112                 print "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";
113                 $subscribe_btn_disabled = "disabled";
114             } else {
115                 $subscribe_btn_disabled = "";
116             }
117
118             print "</ul>";
119
120             print "<div align='center'>
121                 <input type=\"submit\" class=\"button\"
122                 $subscribe_btn_disabled
123                 onclick=\"feedBrowserSubscribe()\" value=\"".__('Subscribe')."\">
124                 <input type='submit' class='button'           
125                 onclick=\"closeInfoBox()\" value=\"".__('Cancel')."\"></div>";
126
127             print "</div>";
128             return;
129         }
130
131         if ($subop == "editfeed") {
132             $feed_id = db_escape_string($_REQUEST["id"]);
133
134             $result = db_query($link,
135                 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
136                     owner_uid = " . $_SESSION["uid"]);
137
138             $title = htmlspecialchars(db_fetch_result($result,
139                 0, "title"));
140
141             $icon_file = ICONS_DIR . "/$feed_id.ico";
142     
143             if (file_exists($icon_file) && filesize($icon_file) > 0) {
144                     $feed_icon = "<img width=\"16\" height=\"16\"
145                         src=\"" . ICONS_URL . "/$feed_id.ico\">";
146             } else {
147                 $feed_icon = "";
148             }
149
150             print "<div id=\"infoBoxTitle\">".__('Feed Editor')."</div>";
151
152             print "<div class=\"infoBoxContents\">";
153
154             print "<form id=\"edit_feed_form\" onsubmit=\"return false\">";   
155
156             print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
157             print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
158             print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
159
160             print "<div class=\"dlgSec\">".__("Feed")."</div>";
161             print "<div class=\"dlgSecCont\">";
162
163             /* Title */
164
165             print "<input style=\"font-size : 16px\" size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
166                             name=\"title\" value=\"$title\">";
167
168             /* Feed URL */
169
170             $feed_url = db_fetch_result($result, 0, "feed_url");
171             $feed_url = htmlspecialchars(db_fetch_result($result,
172                 0, "feed_url"));
173
174             print "<br/>";
175
176             print __('URL:') . " ";
177             print "<input size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
178                 name=\"feed_url\" value=\"$feed_url\">";
179
180             /* Category */
181
182             if (get_pref($link, 'ENABLE_FEED_CATS')) {
183
184                 $cat_id = db_fetch_result($result, 0, "cat_id");
185
186                 print "<br/>";
187
188                 print __('Place in category:') . " ";
189
190                 $parent_feed = db_fetch_result($result, 0, "parent_feed");
191
192                 if (sprintf("%d", $parent_feed) > 0) {
193                     $disabled = "disabled";
194                 } else {
195                     $disabled = "";
196                 }
197
198                 print_feed_cat_select($link, "cat_id", $cat_id, $disabled);
199             }
200
201             /* Link to */
202
203             print "<br/>";
204
205             print __('Link to feed:') . " ";
206
207             $tmp_result = db_query($link, "SELECT COUNT(id) AS count
208                 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
209
210             $linked_count = db_fetch_result($tmp_result, 0, "count");
211
212             $parent_feed = db_fetch_result($result, 0, "parent_feed");
213
214             if ($linked_count > 0) {
215                 $disabled = "disabled";
216             } else {
217                 $disabled = "";
218             }
219
220             print "<select $disabled name=\"parent_feed\">";
221             
222             print "<option value=\"0\">".__('Not linked')."</option>";
223
224             if (get_pref($link, 'ENABLE_FEED_CATS')) {
225                 if ($cat_id) {
226                     $cat_qpart = "AND cat_id = '$cat_id'";
227                 } else {
228                     $cat_qpart = "AND cat_id IS NULL";
229                 }
230             }
231
232             $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
233                 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
234                       (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
235                     $cat_qpart ORDER BY title");
236
237                 if (db_num_rows($tmp_result) > 0) {
238                     print "<option disabled>--------</option>";
239                 }
240
241                 while ($tmp_line = db_fetch_assoc($tmp_result)) {
242                     if ($tmp_line["id"] == $parent_feed) {
243                         $is_selected = "selected";
244                     } else {
245                         $is_selected = "";
246                     }
247                     printf("<option $is_selected value='%d'>%s</option>",
248                         $tmp_line["id"], $tmp_line["title"]);
249                 }
250
251             print "</select>";
252
253
254             print "</div>";
255
256             print "<div class=\"dlgSec\">".__("Update")."</div>";
257             print "<div class=\"dlgSecCont\">";
258
259             /* Update Interval */
260
261             $update_interval = db_fetch_result($result, 0, "update_interval");
262
263             print_select_hash("update_interval", $update_interval, $update_intervals);
264
265             /* Update method */
266
267             if (ALLOW_SELECT_UPDATE_METHOD) {
268                 $update_method = db_fetch_result($result, 0, "update_method");
269
270                 print " " . __('using') . " ";
271                 print_select_hash("update_method", $update_method, $update_methods);           
272             }
273
274             /* Purge intl */
275
276             print "<br/>";
277
278             $purge_interval = db_fetch_result($result, 0, "purge_interval");
279
280             print __('Article purging:') . " ";
281
282             print_select_hash("purge_interval", $purge_interval, $purge_intervals);
283
284             print "</div>";
285             print "<div class=\"dlgSec\">".__("Authentication")."</div>";
286             print "<div class=\"dlgSecCont\">";
287
288             $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
289
290             print __('Login:') . " ";
291             print "<input size=\"20\" onkeypress=\"return filterCR(event, feedEditSave)\"
292                 name=\"auth_login\" value=\"$auth_login\">";
293
294             print " " . __("Password:") . " ";
295
296             $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
297
298             print "<input size=\"20\" type=\"password\" name=\"auth_pass\"
299                 onkeypress=\"return filterCR(event, feedEditSave)\"
300                 value=\"$auth_pass\">";
301
302             print "</div>";
303             print "<div class=\"dlgSec\">".__("Options")."</div>";
304             print "<div class=\"dlgSecCont\">";
305
306             print "<div style=\"line-height : 100%\">";
307
308             $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
309
310             if ($private) {
311                 $checked = "checked";
312             } else {
313                 $checked = "";
314             }
315
316             print "<input type=\"checkbox\" name=\"private\" id=\"private\"
317                 $checked>&nbsp;<label for=\"private\">".__('Hide from "Other Feeds"')."</label>";
318
319             $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
320
321             if ($rtl_content) {
322                 $checked = "checked";
323             } else {
324                 $checked = "";
325             }
326
327             print "<br/><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
328                 $checked>&nbsp;<label for=\"rtl_content\">".__('Right-to-left content')."</label>";
329
330             $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
331
332             if ($hidden) {
333                 $checked = "checked";
334             } else {
335                 $checked = "";
336             }
337
338             print "<br/><input type=\"checkbox\" id=\"hidden\" name=\"hidden\"
339                 $checked>&nbsp;<label for=\"hidden\">".__('Hide from my feed list')."</label>";
340
341             $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
342
343             if ($include_in_digest) {
344                 $checked = "checked";
345             } else {
346                 $checked = "";
347             }
348
349             print "<br/><input type=\"checkbox\" id=\"include_in_digest\"
350                 name=\"include_in_digest\"
351                 $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
352
353             $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
354
355             if ($cache_images) {
356                 $checked = "checked";
357             } else {
358                 $checked = "";
359             }
360
361             if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
362                 $disabled = "";
363                 $label_class = "";
364             } else {
365                 $disabled = "disabled";
366                 $label_class = "class='insensitive'";
367             }
368
369             print "<br/><input type=\"checkbox\" id=\"cache_images\"
370                 name=\"cache_images\" $disabled
371                 $checked>&nbsp;<label $label_class for=\"cache_images\">".
372                 __('Cache images locally')."</label>";
373
374
375             print "</div>";
376             print "</div>";
377
378             print "</form>";
379
380             $title = htmlspecialchars($title, ENT_QUOTES);
381
382             print "<div class='dlgButtons'>
383                 <div style=\"float : left\">
384                     <input type='submit' class='button'           
385                     onclick='return unsubscribeFeed($feed_id, \"$title\")' value=\"".__('Unsubscribe')."\">
386                 </div>
387                 <input type=\"submit\" class=\"button\"
388                 onclick=\"return feedEditSave()\" value=\"".__('Save')."\">
389                 <input type='submit' class='button'           
390                 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\">
391                 </div>";
392
393             return;
394         }
395
396         if ($subop == "editfeeds") {
397
398             $feed_ids = db_escape_string($_REQUEST["ids"]);
399
400             print "<div id=\"infoBoxTitle\">".__('Multiple Feed Editor')."</div>";
401
402             print "<div class=\"infoBoxContents\">";
403
404             print "<form id=\"batch_edit_feed_form\" onsubmit=\"return false\">";   
405
406             print "<input type=\"hidden\" name=\"ids\" value=\"$feed_ids\">";
407             print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
408             print "<input type=\"hidden\" name=\"subop\" value=\"batchEditSave\">";
409
410             print "<div class=\"dlgSec\">".__("Feed")."</div>";
411             print "<div class=\"dlgSecCont\">";
412
413             /* Title */
414
415             print "<input disabled style=\"font-size : 16px\" size=\"35\" onkeypress=\"return filterCR(event, feedEditSave)\"
416                             name=\"title\" value=\"$title\">";
417
418             batch_edit_cbox("title");
419
420             /* Feed URL */
421
422             print "<br/>";
423
424             print __('URL:') . " ";
425             print "<input disabled size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
426                 name=\"feed_url\" value=\"$feed_url\">";
427
428             batch_edit_cbox("feed_url");
429
430             /* Category */
431
432             if (get_pref($link, 'ENABLE_FEED_CATS')) {
433
434                 print "<br/>";
435
436                 print __('Place in category:') . " ";
437
438                 print_feed_cat_select($link, "cat_id", $cat_id, "disabled");
439
440                 batch_edit_cbox("cat_id");
441
442             }
443
444             print "</div>";
445
446             print "<div class=\"dlgSec\">".__("Update")."</div>";
447             print "<div class=\"dlgSecCont\">";
448
449             /* Update Interval */
450
451             print_select_hash("update_interval", $update_interval, $update_intervals,
452                 "disabled");
453
454             batch_edit_cbox("update_interval");
455
456             /* Update method */
457
458             if (ALLOW_SELECT_UPDATE_METHOD) {
459                 print " " . __('using') . " ";
460                 print_select_hash("update_method", $update_method, $update_methods,
461                     "disabled");           
462                 batch_edit_cbox("update_method");
463             }
464
465             /* Purge intl */
466
467             print "<br/>";
468
469             print __('Article purging:') . " ";
470
471             print_select_hash("purge_interval", $purge_interval, $purge_intervals,
472                 "disabled");
473
474             batch_edit_cbox("purge_interval");
475
476             print "</div>";
477             print "<div class=\"dlgSec\">".__("Authentication")."</div>";
478             print "<div class=\"dlgSecCont\">";
479
480             print __('Login:') . " ";
481             print "<input disabled size=\"15\" onkeypress=\"return filterCR(event, feedEditSave)\"
482                 name=\"auth_login\" value=\"$auth_login\">";
483
484             batch_edit_cbox("auth_login");
485
486             print " " . __("Password:") . " ";
487
488             print "<input disabled size=\"15\" type=\"password\" name=\"auth_pass\"
489                 onkeypress=\"return filterCR(event, feedEditSave)\"
490                 value=\"$auth_pass\">";
491
492             batch_edit_cbox("auth_pass");
493
494             print "</div>";
495             print "<div class=\"dlgSec\">".__("Options")."</div>";
496             print "<div class=\"dlgSecCont\">";
497
498             print "<div style=\"line-height : 100%\">";
499
500             print "<input disabled type=\"checkbox\" name=\"private\" id=\"private\"
501                 $checked>&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from "Other Feeds"')."</label>";
502
503             print "&nbsp;"; batch_edit_cbox("private", "private_l");
504
505             print "<br/><input disabled type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
506                 $checked>&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
507
508             print "&nbsp;"; batch_edit_cbox("rtl_content", "rtl_content_l");
509
510             print "<br/><input disabled type=\"checkbox\" id=\"hidden\" name=\"hidden\"
511                 $checked>&nbsp;<label class='insensitive' id=\"hidden_l\" for=\"hidden\">".__('Hide from my feed list')."</label>";
512
513             print "&nbsp;"; batch_edit_cbox("hidden", "hidden_l");
514
515             print "<br/><input disabled type=\"checkbox\" id=\"include_in_digest\"
516                 name=\"include_in_digest\"
517                 $checked>&nbsp;<label