]> git.wh0rd.org - tt-rss.git/blob - classes/feeds.php
split several functions to related classes
[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 if (DIGEST_ENABLE) {
719 $reply['content'] .= "<img src=\"".theme_image($this->link, 'images/art-email.png')."\"
720 style=\"cursor : pointer\"
721 onclick=\"emailArticle($id)\"
722 alt='Zoom' title='".__('Forward by email')."'>";
723 }
724
725 if (ENABLE_TWEET_BUTTON) {
726 $reply['content'] .= "<img src=\"".theme_image($this->link, 'images/art-tweet.png')."\"
727 class='tagsPic' style=\"cursor : pointer\"
728 onclick=\"tweetArticle($id)\"
729 alt='Zoom' title='".__('Share on Twitter')."'>";
730 }
731
732 $reply['content'] .= "<img src=\"".theme_image($this->link, 'images/art-share.png')."\"
733 class='tagsPic' style=\"cursor : pointer\"
734 onclick=\"shareArticle(".$line['int_id'].")\"
735 alt='Zoom' title='".__('Share by URL')."'>";
736
737 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
738 style=\"cursor : pointer\" style=\"cursor : pointer\"
739 onclick=\"dismissArticle($id)\"
740 alt='Dismiss' title='".__('Dismiss article')."'>";
741
742 $reply['content'] .= "</div>";
743 $reply['content'] .= "</div>";
744
745 $reply['content'] .= "</div>";
746
747 $reply['content'] .= "</div>";
748
749 }
750
751 ++$lnum;
752 }
753
754 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
755
756 } else {
757 $message = "";
758
759 switch ($view_mode) {
760 case "unread":
761 $message = __("No unread articles found to display.");
762 break;
763 case "updated":
764 $message = __("No updated articles found to display.");
765 break;
766 case "marked":
767 $message = __("No starred articles found to display.");
768 break;
769 default:
770 if ($feed < -10) {
771 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
772 } else {
773 $message = __("No articles found to display.");
774 }
775 }
776
777 if (!$offset && $message) {
778 $reply['content'] .= "<div class='whiteBox'>$message";
779
780 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
781
782 $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
783 WHERE owner_uid = " . $_SESSION['uid']);
784
785 $last_updated = db_fetch_result($result, 0, "last_updated");
786 $last_updated = make_local_datetime($this->link, $last_updated, false);
787
788 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
789
790 $result = db_query($this->link, "SELECT COUNT(id) AS num_errors
791 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
792
793 $num_errors = db_fetch_result($result, 0, "num_errors");
794
795 if ($num_errors > 0) {
796 $reply['content'] .= "<br/>";
797 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
798 __('Some feeds have update errors (click for details)')."</a>";
799 }
800 $reply['content'] .= "</span></p></div>";
801 }
802 }
803
804 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
805
806 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
807 $vgroup_last_feed, $reply);
808 }
809
810 private function outputFeedList($special = true) {
811
812 $feedlist = array();
813
814 $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
815
816 $feedlist['identifier'] = 'id';
817 $feedlist['label'] = 'name';
818 $feedlist['items'] = array();
819
820 $owner_uid = $_SESSION["uid"];
821
822 /* virtual feeds */
823
824 if ($special) {
825
826 if ($enable_cats) {
827 $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
828 $cat = $this->feedlist_init_cat(-1, $cat_hidden);
829 } else {
830 $cat['items'] = array();
831 }
832
833 foreach (array(-4, -3, -1, -2, 0) as $i) {
834 array_push($cat['items'], $this->feedlist_init_feed($i));
835 }
836
837 if ($enable_cats) {
838 array_push($feedlist['items'], $cat);
839 } else {
840 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
841 }
842
843 $result = db_query($this->link, "SELECT * FROM
844 ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
845
846 if (db_num_rows($result) > 0) {
847
848 if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
849 $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");
850 $cat = $this->feedlist_init_cat(-2, $cat_hidden);
851 } else {
852 $cat['items'] = array();
853 }
854
855 while ($line = db_fetch_assoc($result)) {
856
857 $label_id = -$line['id'] - 11;
858 $count = getFeedUnread($this->link, $label_id);
859
860 $feed = $this->feedlist_init_feed($label_id, false, $count);
861
862 $feed['fg_color'] = $line['fg_color'];
863 $feed['bg_color'] = $line['bg_color'];
864
865 array_push($cat['items'], $feed);
866 }
867
868 if ($enable_cats) {
869 array_push($feedlist['items'], $cat);
870 } else {
871 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
872 }
873 }
874 }
875
876 /* if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
877 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
878 $order_by_qpart = "order_id,category,unread DESC,title";
879 } else {
880 $order_by_qpart = "order_id,category,title";
881 }
882 } else {
883 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
884 $order_by_qpart = "unread DESC,title";
885 } else {
886 $order_by_qpart = "title";
887 }
888 } */
889
890 /* real feeds */
891
892 if ($enable_cats)
893 $order_by_qpart = "ttrss_feed_categories.order_id,category,
894 ttrss_feeds.order_id,title";
895 else
896 $order_by_qpart = "title";
897
898 $age_qpart = getMaxAgeSubquery();
899
900 $query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
901 ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
902 cat_id,last_error,
903 ttrss_feed_categories.title AS category,
904 ttrss_feed_categories.collapsed,
905 value AS unread
906 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
907 ON (ttrss_feed_categories.id = cat_id)
908 LEFT JOIN ttrss_counters_cache
909 ON
910 (ttrss_feeds.id = feed_id)
911 WHERE
912 ttrss_feeds.owner_uid = '$owner_uid'
913 ORDER BY $order_by_qpart";
914
915 $result = db_query($this->link, $query);
916
917 $actid = $_REQUEST["actid"];
918
919 if (db_num_rows($result) > 0) {
920
921 $category = "";
922
923 if (!$enable_cats)
924 $cat['items'] = array();
925 else
926 $cat = false;
927
928 while ($line = db_fetch_assoc($result)) {
929
930 $feed = htmlspecialchars(trim($line["title"]));
931
932 if (!$feed) $feed = "[Untitled]";
933
934 $feed_id = $line["id"];
935 $unread = $line["unread"];
936
937 $cat_id = $line["cat_id"];
938 $tmp_category = $line["category"];
939 if (!$tmp_category) $tmp_category = __("Uncategorized");
940
941 if ($category != $tmp_category && $enable_cats) {
942
943 $category = $tmp_category;
944
945 $collapsed = sql_bool_to_bool($line["collapsed"]);
946
947 // workaround for NULL category
948 if ($category == __("Uncategorized")) {
949 $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT");
950 }
951
952 if ($cat) array_push($feedlist['items'], $cat);
953
954 $cat = $this->feedlist_init_cat($cat_id, $collapsed);
955 }
956
957 $updated = make_local_datetime($this->link, $line["updated_noms"], false);
958
959 array_push($cat['items'], $this->feedlist_init_feed($feed_id,
960 $feed, $unread, $line['last_error'], $updated));
961 }
962
963 if ($enable_cats) {
964 array_push($feedlist['items'], $cat);
965 } else {
966 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
967 }
968
969 }
970
971 return $feedlist;
972 }
973
974
975 function catchupAll() {
976 db_query($this->link, "UPDATE ttrss_user_entries SET
977 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
978 ccache_zero_all($this->link, $_SESSION["uid"]);
979 }
980
981 function collapse() {
982 $cat_id = db_escape_string($_REQUEST["cid"]);
983 $mode = (int) db_escape_string($_REQUEST['mode']);
984 toggle_collapse_cat($this->link, $cat_id, $mode);
985 }
986
987 function index() {
988 $root = (bool)$_REQUEST["root"];
989
990 if (!$root) {
991 print json_encode($this->outputFeedList($this->link));
992 } else {
993
994 $feeds = $this->outputFeedList($this->link, false);
995
996 $root = array();
997 $root['id'] = 'root';
998 $root['name'] = __('Feeds');
999 $root['items'] = $feeds['items'];
1000
1001 $fl = array();
1002 $fl['identifier'] = 'id';
1003 $fl['label'] = 'name';
1004 $fl['items'] = array($root);
1005
1006 print json_encode($fl);
1007 }
1008 }
1009
1010 function view() {
1011 $timing_info = getmicrotime();
1012
1013 $reply = array();
1014
1015 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
1016
1017 $omode = db_escape_string($_REQUEST["omode"]);
1018
1019 $feed = db_escape_string($_REQUEST["feed"]);
1020 $method = db_escape_string($_REQUEST["m"]);
1021 $view_mode = db_escape_string($_REQUEST["view_mode"]);
1022 $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");
1023 @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";
1024 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
1025 @$offset = db_escape_string($_REQUEST["skip"]);
1026 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
1027 $order_by = db_escape_string($_REQUEST["order_by"]);
1028
1029 if (is_numeric($feed)) $feed = (int) $feed;
1030
1031 /* Feed -5 is a special case: it is used to display auxiliary information
1032 * when there's nothing to load - e.g. no stuff in fresh feed */
1033
1034 if ($feed == -5) {
1035 print json_encode(generate_dashboard_feed($this->link));
1036 return;
1037 }
1038
1039 $result = false;
1040
1041 if ($feed < -10) {
1042 $label_feed = -11-$feed;
1043 $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE
1044 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
1045 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
1046 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
1047 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1048 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
1049 $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE
1050 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1051 }
1052
1053 if ($result && db_num_rows($result) == 0) {
1054 print json_encode(generate_error_feed($this->link, __("Feed not found.")));
1055 return;
1056 }
1057
1058 /* Updating a label ccache means recalculating all of the caches
1059 * so for performance reasons we don't do that here */
1060
1061 if ($feed >= 0) {
1062 ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);
1063 }
1064
1065 set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);
1066 set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);
1067 set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
1068
1069 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
1070 db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()
1071 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
1072 }
1073
1074 $reply['headlines'] = array();
1075
1076 if (!$next_unread_feed)
1077 $reply['headlines']['id'] = $feed;
1078 else
1079 $reply['headlines']['id'] = $next_unread_feed;
1080
1081 $reply['headlines']['is_cat'] = (bool) $cat_view;
1082
1083 $override_order = false;
1084
1085 if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
1086 $date_sort_field = "updated";
1087 } else {
1088 $date_sort_field = "date_entered";
1089 }
1090
1091 switch ($order_by) {
1092 case "date":
1093 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
1094 $override_order = "$date_sort_field";
1095 } else {
1096 $override_order = "$date_sort_field DESC";
1097 }
1098 break;
1099
1100 case "title":
1101 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
1102 $override_order = "title DESC, $date_sort_field";
1103 } else {
1104 $override_order = "title, $date_sort_field DESC";
1105 }
1106 break;
1107
1108 case "score":
1109 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
1110 $override_order = "score, $date_sort_field";
1111 } else {
1112 $override_order = "score DESC, $date_sort_field DESC";
1113 }
1114 break;
1115 }
1116
1117 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
1118
1119 $ret = $this->format_headlines_list($feed, $method,
1120 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
1121 $vgroup_last_feed, $override_order);
1122
1123 $topmost_article_ids = $ret[0];
1124 $headlines_count = $ret[1];
1125 $returned_feed = $ret[2];
1126 $disable_cache = $ret[3];
1127 $vgroup_last_feed = $ret[4];
1128
1129 $reply['headlines']['content'] =& $ret[5]['content'];
1130 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
1131
1132 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
1133
1134 $reply['headlines-info'] = array("count" => (int) $headlines_count,
1135 "vgroup_last_feed" => $vgroup_last_feed,
1136 "disable_cache" => (bool) $disable_cache);
1137
1138 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
1139
1140 if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
1141 $articles = array();
1142
1143 foreach ($topmost_article_ids as $id) {
1144 array_push($articles, format_article($this->link, $id, false));
1145 }
1146
1147 $reply['articles'] = $articles;
1148 }
1149
1150 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
1151
1152 $reply['runtime-info'] = make_runtime_info($this->link);
1153
1154 print json_encode($reply);
1155
1156 }
1157 }
1158 ?>