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