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