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