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