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