]> git.wh0rd.org - tt-rss.git/blob - classes/feeds.php
simplify default global config, expand sanity_check messages
[tt-rss.git] / classes / feeds.php
1 <?php
2 class Feeds extends Protected_Handler {
3
4 private function feedlist_init_cat($cat_id, $hidden = false) {
5 $obj = array();
6 $cat_id = (int) $cat_id;
7
8 if ($cat_id > 0) {
9 $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true);
10 } else if ($cat_id == 0 || $cat_id == -2) {
11 $cat_unread = getCategoryUnread($this->link, $cat_id);
12 }
13
14 $obj['id'] = 'CAT:' . $cat_id;
15 $obj['items'] = array();
16 $obj['name'] = getCategoryTitle($this->link, $cat_id);
17 $obj['type'] = 'feed';
18 $obj['unread'] = (int) $cat_unread;
19 $obj['hidden'] = $hidden;
20 $obj['bare_id'] = $cat_id;
21
22 return $obj;
23 }
24
25 private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
26 $obj = array();
27 $feed_id = (int) $feed_id;
28
29 if (!$title)
30 $title = getFeedTitle($this->link, $feed_id, false);
31
32 if ($unread === false)
33 $unread = getFeedUnread($this->link, $feed_id, false);
34
35 $obj['id'] = 'FEED:' . $feed_id;
36 $obj['name'] = $title;
37 $obj['unread'] = (int) $unread;
38 $obj['type'] = 'feed';
39 $obj['error'] = $error;
40 $obj['updated'] = $updated;
41 $obj['icon'] = getFeedIcon($feed_id);
42 $obj['bare_id'] = $feed_id;
43
44 return $obj;
45 }
46
47 private function format_headline_subtoolbar($feed_site_url, $feed_title,
48 $feed_id, $is_cat, $search, $match_on,
49 $search_mode, $view_mode, $error) {
50
51 $page_prev_link = "viewFeedGoPage(-1)";
52 $page_next_link = "viewFeedGoPage(1)";
53 $page_first_link = "viewFeedGoPage(0)";
54
55 $catchup_page_link = "catchupPage()";
56 $catchup_feed_link = "catchupCurrentFeed()";
57 $catchup_sel_link = "catchupSelection()";
58
59 $archive_sel_link = "archiveSelection()";
60 $delete_sel_link = "deleteSelection()";
61
62 $sel_all_link = "selectArticles('all')";
63 $sel_unread_link = "selectArticles('unread')";
64 $sel_none_link = "selectArticles('none')";
65 $sel_inv_link = "selectArticles('invert')";
66
67 $tog_unread_link = "selectionToggleUnread()";
68 $tog_marked_link = "selectionToggleMarked()";
69 $tog_published_link = "selectionTogglePublished()";
70
71 $reply = "<div id=\"subtoolbar_main\">";
72
73 $reply .= __('Select:')."
74 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
75 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
76 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
77 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
78
79 $reply .= " ";
80
81 $reply .= "<select dojoType=\"dijit.form.Select\"
82 onchange=\"headlineActionsChange(this)\">";
83 $reply .= "<option value=\"false\">".__('Actions...')."</option>";
84
85 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
86
87 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
88 <option value=\"$tog_marked_link\">".__('Starred')."</option>
89 <option value=\"$tog_published_link\">".__('Published')."</option>";
90
91 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
92
93 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
94
95 if ($feed_id != "0") {
96 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
97 } else {
98 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
99 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
100
101 }
102
103 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
104 "</option>";
105
106 if ($is_cat) $cat_q = "&is_cat=$is_cat";
107
108 if ($search) {
109 $search_q = "&q=$search&m=$match_on&smode=$search_mode";
110 } else {
111 $search_q = "";
112 }
113
114 $rss_link = htmlspecialchars(get_self_url_prefix() .
115 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
116
117 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
118
119 $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
120
121 $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
122
123 $reply .= "</select>";
124
125 $reply .= "</div>";
126
127 $reply .= "<div id=\"subtoolbar_ftitle\">";
128
129 if ($feed_site_url) {
130 $target = "target=\"_blank\"";
131 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
132 truncate_string($feed_title,30)."</a>";
133
134 if ($error) {
135 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
136 }
137
138 } else {
139 if ($feed_id < -10) {
140 $label_id = -11-$feed_id;
141
142 $result = db_query($this->link, "SELECT fg_color, bg_color
143 FROM ttrss_labels2 WHERE id = '$label_id' AND owner_uid = " .
144 $_SESSION["uid"]);
145
146 if (db_num_rows($result) != 0) {
147 $fg_color = db_fetch_result($result, 0, "fg_color");
148 $bg_color = db_fetch_result($result, 0, "bg_color");
149
150 $reply .= "<span style=\"background : $bg_color; color : $fg_color\" >";
151 $reply .= $feed_title;
152 $reply .= "</span>";
153 } else {
154 $reply .= $feed_title;
155 }
156
157 } else {
158 $reply .= $feed_title;
159 }
160 }
161
162 $reply .= "
163 <a href=\"#\"
164 title=\"".__("View as RSS feed")."\"
165 onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
166 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";
167
168 $reply .= "</div>";
169
170 return $reply;
171 }
172
173 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
174 $next_unread_feed, $offset, $vgr_last_feed = false,
175 $override_order = false) {
176
177 $disable_cache = false;
178
179 $reply = array();
180
181 $timing_info = getmicrotime();
182
183 $topmost_article_ids = array();
184
185 if (!$offset) $offset = 0;
186 if ($method == "undefined") $method = "";
187
188 $method_split = explode(":", $method);
189
190 /* if ($method == "CatchupSelected") {
191 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
192 $cmode = sprintf("%d", $_REQUEST["cmode"]);
193
194 catchupArticlesById($this->link, $ids, $cmode);
195 } */
196
197 //if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
198 // update_rss_feed($this->link, $feed, true);
199 //}
200
201 if ($method == "MarkAllRead") {
202 catchup_feed($this->link, $feed, $cat_view);
203
204 if (get_pref($this->link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
205 if ($next_unread_feed) {
206 $feed = $next_unread_feed;
207 }
208 }
209 }
210
211 if ($method_split[0] == "MarkAllReadGR") {
212 catchup_feed($this->link, $method_split[1], false);
213 }
214
215 // FIXME: might break tag display?
216
217 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
218 $result = db_query($this->link,
219 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
220
221 if (db_num_rows($result) == 0) {
222 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
223 }
224 }
225
226 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
227
228 $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds
229 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
230
231 if (db_num_rows($result) == 1) {
232 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
233 } else {
234 $rtl_content = false;
235 }
236
237 if ($rtl_content) {
238 $rtl_tag = "dir=\"RTL\"";
239 } else {
240 $rtl_tag = "";
241 }
242 } else {
243 $rtl_tag = "";
244 $rtl_content = false;
245 }
246
247 @$search = db_escape_string($_REQUEST["query"]);
248
249 if ($search) {
250 $disable_cache = true;
251 }
252
253 @$search_mode = db_escape_string($_REQUEST["search_mode"]);
254 @$match_on = db_escape_string($_REQUEST["match_on"]);
255
256 if (!$match_on) {
257 $match_on = "both";
258 }
259
260 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
261
262 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
263 if( $search_mode == '' && $method != '' ){
264 $search_mode = $method;
265 }
266 // error_log("search_mode: " . $search_mode);
267 $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,
268 $search, $search_mode, $match_on, $override_order, $offset);
269
270 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
271
272 $result = $qfh_ret[0];
273 $feed_title = $qfh_ret[1];
274 $feed_site_url = $qfh_ret[2];
275 $last_error = $qfh_ret[3];
276
277 $vgroup_last_feed = $vgr_last_feed;
278
279 // if (!$offset) {
280
281 if (db_num_rows($result) > 0) {
282 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
283 $feed_title,
284 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,
285 $last_error);
286 }
287 // }
288
289 $headlines_count = db_num_rows($result);
290
291 if (db_num_rows($result) > 0) {
292
293 $lnum = $offset;
294
295 $num_unread = 0;
296 $cur_feed_title = '';
297
298 $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
299
300 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
301
302 while ($line = db_fetch_assoc($result)) {
303
304 $class = ($lnum % 2) ? "even" : "odd";
305
306 $id = $line["id"];
307 $feed_id = $line["feed_id"];
308 $label_cache = $line["label_cache"];
309 $labels = false;
310
311 if ($label_cache) {
312 $label_cache = json_decode($label_cache, true);
313
314 if ($label_cache) {
315 if ($label_cache["no-labels"] == 1)
316 $labels = array();
317 else
318 $labels = $label_cache;
319 }
320 }
321
322 if (!is_array($labels)) $labels = get_article_labels($this->link, $id);
323
324 $labels_str = "<span id=\"HLLCTR-$id\">";
325 $labels_str .= format_article_labels($labels, $id);
326 $labels_str .= "</span>";
327
328 if (count($topmost_article_ids) < 3) {
329 array_push($topmost_article_ids, $id);
330 }
331
332 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
333
334 $update_pic = "<img id='FUPDPIC-$id' src=\"".
335 theme_image($this->link, 'images/updated.png')."\"
336 alt=\"Updated\">";
337 } else {
338 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
339 alt=\"Updated\">";
340 }
341
342 if (sql_bool_to_bool($line["unread"]) &&
343 time() - strtotime($line["updated_noms"]) < $fresh_intl) {
344
345 $update_pic = "<img id='FUPDPIC-$id' src=\"".
346 theme_image($this->link, 'images/fresh_sign.png')."\" alt=\"Fresh\">";
347 }
348
349 if ($line["unread"] == "t" || $line["unread"] == "1") {
350 $class .= " Unread";
351 ++$num_unread;
352 $is_unread = true;
353 } else {
354 $is_unread = false;
355 }
356
357 if ($line["marked"] == "t" || $line["marked"] == "1") {
358 $marked_pic = "<img id=\"FMPIC-$id\"
359 src=\"".theme_image($this->link, 'images/mark_set.png')."\"
360 class=\"markedPic\" alt=\"Unstar article\"
361 onclick='javascript:toggleMark($id)'>";
362 } else {
363 $marked_pic = "<img id=\"FMPIC-$id\"
364 src=\"".theme_image($this->link, 'images/mark_unset.png')."\"
365 class=\"markedPic\" alt=\"Star article\"
366 onclick='javascript:toggleMark($id)'>";
367 }
368
369 if ($line["published"] == "t" || $line["published"] == "1") {
370 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,
371 'images/pub_set.png')."\"
372 class=\"markedPic\"
373 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
374 } else {
375 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,
376 'images/pub_unset.png')."\"
377 class=\"markedPic\"
378 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
379 }
380
381 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
382 # $line["title"] . "</a>";
383
384 # $content_link = "<a
385 # href=\"" . htmlspecialchars($line["link"]) . "\"
386 # onclick=\"view($id,$feed_id);\">" .
387 # $line["title"] . "</a>";
388
389 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
390 # $line["title"] . "</a>";
391
392 $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false);
393
394 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
395 $content_preview = truncate_string(strip_tags($line["content_preview"]),
396 100);
397 }
398
399 $score = $line["score"];
400
401 $score_pic = theme_image($this->link,
402 "images/" . get_score_pic($score));
403
404 /* $score_title = __("(Click to change)");
405 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
406 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
407
408 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"
409 title=\"$score\">";
410
411 if ($score > 500) {
412 $hlc_suffix = "H";
413 } else if ($score < -100) {
414 $hlc_suffix = "L";
415 } else {
416 $hlc_suffix = "";
417 }
418
419 $entry_author = $line["author"];
420
421 if ($entry_author) {
422 $entry_author = " - $entry_author";
423 }
424
425 $has_feed_icon = feed_has_icon($feed_id);
426
427 if ($has_feed_icon) {
428 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
429 } else {
430 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
431 }
432
433 if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
434
435 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
436 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
437
438 $cur_feed_title = $line["feed_title"];
439 $vgroup_last_feed = $feed_id;
440
441 $cur_feed_title = htmlspecialchars($cur_feed_title);
442
443 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
444
445 $reply['content'] .= "<div class='cdmFeedTitle'>".
446 "<div style=\"float : right\">$feed_icon_img</div>".
447 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
448 $line["feed_title"]."</a> $vf_catchup_link</div>";
449
450 }
451 }
452
453 $mouseover_attrs = "onmouseover='postMouseIn($id)'
454 onmouseout='postMouseOut($id)'";
455
456 $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";
457
458 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
459
460 $reply['content'] .= "<div class='hlLeft'>";
461
462 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
463 id=\"RCHK-$id\">";
464
465 $reply['content'] .= "$marked_pic";
466 $reply['content'] .= "$published_pic";
467
468 $reply['content'] .= "</div>";
469
470 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
471 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
472 $reply['content'] .= "<a id=\"RTITLE-$id\"
473 href=\"" . htmlspecialchars($line["link"]) . "\"
474 onclick=\"\">" .
475 truncate_string($line["title"], 200);
476
477 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
478 if ($content_preview) {
479 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
480 }
481 }
482
483 $reply['content'] .= "</a></span>";
484
485 $reply['content'] .= $labels_str;
486
487 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&
488 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
489 if (@$line["feed_title"]) {
490 $reply['content'] .= "<span class=\"hlFeed\">
491 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
492 $line["feed_title"]."</a>)
493 </span>";
494 }
495 }
496
497 $reply['content'] .= "</div>";
498
499 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
500 $reply['content'] .= "<div class=\"hlRight\">";
501
502 $reply['content'] .= $score_pic;
503
504 if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
505
506 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
507 style=\"cursor : pointer\"
508 title=\"".htmlspecialchars($line['feed_title'])."\">
509 $feed_icon_img<span>";
510 }
511
512 $reply['content'] .= "</div>";
513 $reply['content'] .= "</div>";
514
515 } else {
516
517 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
518 if ($feed_id != $vgroup_last_feed) {
519
520 $cur_feed_title = $line["feed_title"];
521 $vgroup_last_feed = $feed_id;
522
523 $cur_feed_title = htmlspecialchars($cur_feed_title);
524
525 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
526
527 $has_feed_icon = feed_has_icon($feed_id);
528
529 if ($has_feed_icon) {
530 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
531 } else {
532 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
533 }
534
535 $reply['content'] .= "<div class='cdmFeedTitle'>".
536 "<div style=\"float : right\">$feed_icon_img</div>".
537 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
538 $line["feed_title"]."</a> $vf_catchup_link</div>";
539 }
540 }
541
542 $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');
543
544 $mouseover_attrs = "onmouseover='postMouseIn($id)'
545 onmouseout='postMouseOut($id)'";
546
547 $reply['content'] .= "<div class=\"$class\"
548 id=\"RROW-$id\" $mouseover_attrs'>";
549
550 $reply['content'] .= "<div class=\"cdmHeader\">";
551
552 $reply['content'] .= "<div>";
553
554 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
555 'RROW-$id')\" id=\"RCHK-$id\"/>";
556
557 $reply['content'] .= "$marked_pic";
558 $reply['content'] .= "$published_pic";
559
560 $reply['content'] .= "</div>";
561
562 $reply['content'] .= "<span id=\"RTITLE-$id\"
563 onclick=\"return cdmClicked(event, $id);\"
564 class=\"titleWrap$hlc_suffix\">
565 <a class=\"title\"
566 title=\"".htmlspecialchars($line['title'])."\"
567 target=\"_blank\" href=\"".
568 htmlspecialchars($line["link"])."\">".
569 truncate_string($line["title"], 100) .
570 " $entry_author</a>";
571
572 $reply['content'] .= $labels_str;
573
574 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&
575 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
576 if (@$line["feed_title"]) {
577 $reply['content'] .= "<span class=\"hlFeed\">
578 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
579 $line["feed_title"]."</a>)
580 </span>";
581 }
582 }
583
584 if (!$expand_cdm)
585 $content_hidden = "style=\"display : none\"";
586 else
587 $excerpt_hidden = "style=\"display : none\"";
588
589 $reply['content'] .= "<span $excerpt_hidden
590 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
591
592 $reply['content'] .= "</span>";
593
594 $reply['content'] .= "<div>";
595 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
596 $reply['content'] .= "$score_pic";
597
598 if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
599 $reply['content'] .= "<span style=\"cursor : pointer\"
600 title=\"".htmlspecialchars($line["feed_title"])."\"
601 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
602 }
603 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
604 $reply['content'] .= "</div>";
605
606 $reply['content'] .= "</div>";
607
608 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
609 onclick=\"return cdmClicked(event, $id);\"
610 id=\"CICD-$id\">";
611
612 $reply['content'] .= "<div class=\"cdmContentInner\">";
613
614 if ($line["orig_feed_id"]) {
615
616 $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds
617 WHERE id = ".$line["orig_feed_id"]);
618
619 if (db_num_rows($tmp_result) != 0) {
620
621 $reply['content'] .= "<div clear='both'>";
622 $reply['content'] .= __("Originally from:");
623
624 $reply['content'] .= "&nbsp;";
625
626 $tmp_line = db_fetch_assoc($tmp_result);
627
628 $reply['content'] .= "<a target='_blank'
629 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
630 $tmp_line['title'] . "</a>";
631
632 $reply['content'] .= "&nbsp;";
633
634 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
635 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.gif'></a>";
636
637 $reply['content'] .= "</div>";
638 }
639 }
640
641 $feed_site_url = $line["site_url"];
642
643 $article_content = sanitize($this->link, $line["content_preview"],
644 false, false, $feed_site_url);
645
646 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
647 if ($line['note']) {
648 $reply['content'] .= format_article_note($id, $line['note']);
649 }
650 $reply['content'] .= "</div>";
651
652 $reply['content'] .= "<span id=\"CWRAP-$id\">";
653 $reply['content'] .= $expand_cdm ? $article_content : '';
654 $reply['content'] .= "</span>";
655
656 /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
657 ttrss_feeds WHERE id = ".
658 (($line['feed_id'] == null) ? $line['orig_feed_id'] :
659 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
660
661 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
662 0, "always_display_enclosures")); */
663
664 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
665
666 $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures,
667 $article_content);
668
669 $reply['content'] .= "</div>";
670
671 $reply['content'] .= "<div class=\"cdmFooter\">";
672
673 $tag_cache = $line["tag_cache"];
674
675 $tags_str = format_tags_string(
676 get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache),
677 $id);
678
679 $reply['content'] .= "<img src='".theme_image($this->link,
680 'images/tag.png')."' alt='Tags' title='Tags'>
681 <span id=\"ATSTR-$id\">$tags_str</span>
682 <a title=\"".__('Edit tags for this article')."\"
683 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
684
685 $num_comments = $line["num_comments"];
686 $entry_comments = "";
687
688 if ($num_comments > 0) {
689 if ($line["comments"]) {
690 $comments_url = $line["comments"];
691 } else {
692 $comments_url = $line["link"];
693 }
694 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
695 } else {
696 if ($line["comments"] && $line["link"] != $line["comments"]) {
697 $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";
698 }
699 }
700
701 if ($entry_comments) $reply['content'] .= "&nbsp;($entry_comments)";
702
703 $reply['content'] .= "<div style=\"float : right\">";
704
705 $reply['content'] .= "<img src=\"images/art-zoom.png\"
706 onclick=\"zoomToArticle(event, $id)\"
707 style=\"cursor : pointer\"
708 alt='Zoom'
709 title='".__('Open article in new tab')."'>";
710
711 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
712
713 $reply['content'] .= "<img src=\"images/art-pub-note.png\"
714 style=\"cursor : pointer\" style=\"cursor : pointer\"
715 onclick=\"editArticleNote($id)\"
716 alt='PubNote' title='".__('Edit article note')."'>";
717
718 $reply['content'] .= "<img src=\"".theme_image($this->link, 'images/art-email.png')."\"
719 style=\"cursor : pointer\"
720 onclick=\"emailArticle($id)\"
721 alt='Zoom' title='".__('Forward by email')."'>";
722
723 if (ENABLE_TWEET_BUTTON) {
724 $reply['content'] .= "<img src=\"".theme_image($this->link, 'images/art-tweet.png')."\"
725 class='tagsPic' style=\"cursor : pointer\"
726 onclick=\"tweetArticle($id)\"
727 alt='Zoom' title='".__('Share on Twitter')."'>";
728 }
729
730 $reply['content'] .= "<img src=\"".theme_image($this->link, 'images/art-share.png')."\"
731 class='tagsPic' style=\"cursor : pointer\"
732 onclick=\"shareArticle(".$line['int_id'].")\"
733 alt='Zoom' title='".__('Share by URL')."'>";
734
735 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
736 style=\"cursor : pointer\" style=\"cursor : pointer\"
737 onclick=\"dismissArticle($id)\"
738 alt='Dismiss' title='".__('Dismiss article')."'>";
739
740 $reply['content'] .= "</div>";
741 $reply['content'] .= "</div>";
742
743 $reply['content'] .= "</div>";
744
745 $reply['content'] .= "</div>";
746
747 }
748
749 ++$lnum;
750 }
751
752 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
753
754 } else {
755 $message = "";
756
757 switch ($view_mode) {
758 case "unread":
759 $message = __("No unread articles found to display.");
760 break;
761 case "updated":
762 $message = __("No updated articles found to display.");
763 break;
764 case "marked":
765 $message = __("No starred articles found to display.");
766 break;
767 default:
768 if ($feed < -10) {
769 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
770 } else {
771 $message = __("No articles found to display.");
772 }
773 }
774
775 if (!$offset && $message) {
776 $reply['content'] .= "<div class='whiteBox'>$message";
777
778 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
779
780 $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
781 WHERE owner_uid = " . $_SESSION['uid']);
782
783 $last_updated = db_fetch_result($result, 0, "last_updated");
784 $last_updated = make_local_datetime($this->link, $last_updated, false);
785
786 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
787
788 $result = db_query($this->link, "SELECT COUNT(id) AS num_errors
789 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
790
791 $num_errors = db_fetch_result($result, 0, "num_errors");
792
793 if ($num_errors > 0) {
794 $reply['content'] .= "<br/>";
795 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
796 __('Some feeds have update errors (click for details)')."</a>";
797 }
798 $reply['content'] .= "</span></p></div>";
799 }
800 }
801
802 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
803
804 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
805 $vgroup_last_feed, $reply);
806 }
807
808 private function outputFeedList($special = true) {
809
810 $feedlist = array();
811
812 $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
813
814 $feedlist['identifier'] = 'id';
815 $feedlist['label'] = 'name';
816 $feedlist['items'] = array();
817
818 $owner_uid = $_SESSION["uid"];
819
820 /* virtual feeds */
821
822 if ($special) {
823
824 if ($enable_cats) {
825 $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
826 $cat = $this->feedlist_init_cat(-1, $cat_hidden);
827 } else {
828 $cat['items'] = array();
829 }
830
831 foreach (array(-4, -3, -1, -2, 0) as $i) {
832 array_push($cat['items'], $this->feedlist_init_feed($i));
833 }
834
835 if ($enable_cats) {
836 array_push($feedlist['items'], $cat);
837 } else {
838 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
839 }
840
841 $result = db_query($this->link, "SELECT * FROM
842 ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
843
844 if (db_num_rows($result) > 0) {
845
846 if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
847 $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");
848 $cat = $this->feedlist_init_cat(-2, $cat_hidden);
849 } else {
850 $cat['items'] = array();
851 }
852
853 while ($line = db_fetch_assoc($result)) {
854
855 $label_id = -$line['id'] - 11;
856 $count = getFeedUnread($this->link, $label_id);
857
858 $feed = $this->feedlist_init_feed($label_id, false, $count);
859
860 $feed['fg_color'] = $line['fg_color'];
861 $feed['bg_color'] = $line['bg_color'];
862
863 array_push($cat['items'], $feed);
864 }
865
866 if ($enable_cats) {
867 array_push($feedlist['items'], $cat);
868 } else {
869 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
870 }
871 }
872 }
873
874 /* if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
875 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
876 $order_by_qpart = "order_id,category,unread DESC,title";
877 } else {
878 $order_by_qpart = "order_id,category,title";
879 }
880 } else {
881 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
882 $order_by_qpart = "unread DESC,title";
883 } else {
884 $order_by_qpart = "title";
885 }
886 } */
887
888 /* real feeds */
889
890 if ($enable_cats)
891 $order_by_qpart = "ttrss_feed_categories.order_id,category,
892 ttrss_feeds.order_id,title";
893 else
894 $order_by_qpart = "title";
895
896 $age_qpart = getMaxAgeSubquery();
897
898 $query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
899 ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
900 cat_id,last_error,
901 ttrss_feed_categories.title AS category,
902 ttrss_feed_categories.collapsed,
903 value AS unread
904 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
905 ON (ttrss_feed_categories.id = cat_id)
906 LEFT JOIN ttrss_counters_cache
907 ON
908 (ttrss_feeds.id = feed_id)
909 WHERE
910 ttrss_feeds.owner_uid = '$owner_uid'
911 ORDER BY $order_by_qpart";
912
913 $result = db_query($this->link, $query);
914
915 $actid = $_REQUEST["actid"];
916
917 if (db_num_rows($result) > 0) {
918
919 $category = "";
920
921 if (!$enable_cats)
922 $cat['items'] = array();
923 else
924 $cat = false;
925
926 while ($line = db_fetch_assoc($result)) {
927
928 $feed = htmlspecialchars(trim($line["title"]));
929
930 if (!$feed) $feed = "[Untitled]";
931
932 $feed_id = $line["id"];
933 $unread = $line["unread"];
934
935 $cat_id = $line["cat_id"];
936 $tmp_category = $line["category"];
937 if (!$tmp_category) $tmp_category = __("Uncategorized");
938
939 if ($category != $tmp_category && $enable_cats) {
940
941 $category = $tmp_category;
942
943 $collapsed = sql_bool_to_bool($line["collapsed"]);
944
945 // workaround for NULL category
946 if ($category == __("Uncategorized")) {
947 $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT");
948 }
949
950 if ($cat) array_push($feedlist['items'], $cat);
951
952 $cat = $this->feedlist_init_cat($cat_id, $collapsed);
953 }
954
955 $updated = make_local_datetime($this->link, $line["updated_noms"], false);
956
957 array_push($cat['items'], $this->feedlist_init_feed($feed_id,
958 $feed, $unread, $line['last_error'], $updated));
959 }
960
961 if ($enable_cats) {
962 array_push($feedlist['items'], $cat);
963 } else {
964 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
965 }
966
967 }
968
969 return $feedlist;
970 }
971
972
973 function catchupAll() {
974 db_query($this->link, "UPDATE ttrss_user_entries SET
975 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
976 ccache_zero_all($this->link, $_SESSION["uid"]);
977 }
978
979 function collapse() {
980 $cat_id = db_escape_string($_REQUEST["cid"]);
981 $mode = (int) db_escape_string($_REQUEST['mode']);
982 toggle_collapse_cat($this->link, $cat_id, $mode);
983 }
984
985 function index() {
986 $root = (bool)$_REQUEST["root"];
987
988 if (!$root) {
989 print json_encode($this->outputFeedList($this->link));
990 } else {
991
992 $feeds = $this->outputFeedList($this->link, false);
993
994 $root = array();
995 $root['id'] = 'root';
996 $root['name'] = __('Feeds');
997 $root['items'] = $feeds['items'];
998
999 $fl = array();
1000 $fl['identifier'] = 'id';
1001 $fl['label'] = 'name';
1002 $fl['items'] = array($root);
1003
1004 print json_encode($fl);
1005 }
1006 }
1007
1008 function view() {
1009 $timing_info = getmicrotime();
1010
1011 $reply = array();
1012
1013 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
1014
1015 $omode = db_escape_string($_REQUEST["omode"]);
1016
1017 $feed = db_escape_string($_REQUEST["feed"]);
1018 $method = db_escape_string($_REQUEST["m"]);
1019 $view_mode = db_escape_string($_REQUEST["view_mode"]);
1020 $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");
1021 @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";
1022 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
1023 @$offset = db_escape_string($_REQUEST["skip"]);
1024 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
1025 $order_by = db_escape_string($_REQUEST["order_by"]);
1026
1027 if (is_numeric($feed)) $feed = (int) $feed;
1028
1029 /* Feed -5 is a special case: it is used to display auxiliary information
1030 * when there's nothing to load - e.g. no stuff in fresh feed */
1031
1032 if ($feed == -5) {
1033 print json_encode(generate_dashboard_feed($this->link));
1034 return;
1035 }
1036
1037 $result = false;
1038
1039 if ($feed < -10) {
1040 $label_feed = -11-$feed;
1041 $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE
1042 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
1043 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
1044 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
1045 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1046 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
1047 $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE
1048 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1049 }
1050
1051 if ($result && db_num_rows($result) == 0) {
1052 print json_encode(generate_error_feed($this->link, __("Feed not found.")));
1053 return;
1054 }
1055
1056 /* Updating a label ccache means recalculating all of the caches
1057 * so for performance reasons we don't do that here */
1058
1059 if ($feed >= 0) {
1060 ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);
1061 }
1062
1063 set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);
1064 set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);
1065 set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
1066
1067 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
1068 db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()
1069 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
1070 }
1071
1072 $reply['headlines'] = array();
1073
1074 if (!$next_unread_feed)
1075 $reply['headlines']['id'] = $feed;
1076 else
1077 $reply['headlines']['id'] = $next_unread_feed;
1078
1079 $reply['headlines']['is_cat'] = (bool) $cat_view;
1080
1081 $override_order = false;
1082
1083 if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
1084 $date_sort_field = "updated";
1085 } else {
1086 $date_sort_field = "date_entered";
1087 }
1088
1089 switch ($order_by) {
1090 case "date":
1091 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
1092 $override_order = "$date_sort_field";
1093 } else {
1094 $override_order = "$date_sort_field DESC";
1095 }
1096 break;
1097
1098 case "title":
1099 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
1100 $override_order = "title DESC, $date_sort_field";
1101 } else {
1102 $override_order = "title, $date_sort_field DESC";
1103 }
1104 break;
1105
1106 case "score":
1107 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
1108 $override_order = "score, $date_sort_field";
1109 } else {
1110 $override_order = "score DESC, $date_sort_field DESC";
1111 }
1112 break;
1113 }
1114
1115 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
1116
1117 $ret = $this->format_headlines_list($feed, $method,
1118 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
1119 $vgroup_last_feed, $override_order);
1120
1121 $topmost_article_ids = $ret[0];
1122 $headlines_count = $ret[1];
1123 $returned_feed = $ret[2];
1124 $disable_cache = $ret[3];
1125 $vgroup_last_feed = $ret[4];
1126
1127 $reply['headlines']['content'] =& $ret[5]['content'];
1128 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
1129
1130 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
1131
1132 $reply['headlines-info'] = array("count" => (int) $headlines_count,
1133 "vgroup_last_feed" => $vgroup_last_feed,
1134 "disable_cache" => (bool) $disable_cache);
1135
1136 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
1137
1138 if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
1139 $articles = array();
1140
1141 foreach ($topmost_article_ids as $id) {
1142 array_push($articles, format_article($this->link, $id, false));
1143 }
1144
1145 $reply['articles'] = $articles;
1146 }
1147
1148 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
1149
1150 $reply['runtime-info'] = make_runtime_info($this->link);
1151
1152 print json_encode($reply);
1153
1154 }
1155 }
1156 ?>