]>
git.wh0rd.org - tt-rss.git/blob - mobile/functions.php
3 function render_feeds_list($link) {
7 print "<div id=\"heading\">";
10 print "Tags <span id=\"headingAddon\">
11 (<a href=\"tt-rss.php\">View feeds</a>, ";
13 print "Feeds <span id=\"headingAddon\">
14 (<a href=\"tt-rss.php?tags=1\">View tags</a>, ";
17 print "<a href=\"logout.php\">Logout</a>)</span>";
20 print "<ul class=\"feedList\">";
22 $owner_uid = $_SESSION["uid"];
28 if (get_pref($link, 'ENABLE_FEED_CATS')) {
29 print "<li class=\"feedCat\">Special</li>";
30 print "<li class=\"feedCatHolder\"><ul class=\"feedCatList\">";
33 $result = db_query($link, "SELECT count(id) as num_starred
34 FROM ttrss_entries,ttrss_user_entries
35 WHERE marked = true AND
36 ttrss_user_entries.ref_id = ttrss_entries.id AND
37 unread = true AND owner_uid = '$owner_uid'");
38 $num_starred = db_fetch_result($result, 0, "num_starred");
42 if ($num_starred > 0) $class .= "Unread";
44 printMobileFeedEntry(-1, $class, "Starred articles", $num_starred,
45 "../images/mark_set.png", $link);
47 if (get_pref($link, 'ENABLE_FEED_CATS')) {
51 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
53 $result = db_query($link, "SELECT id,sql_exp,description FROM
54 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
56 if (db_num_rows($result) > 0) {
57 if (get_pref($link, 'ENABLE_FEED_CATS')) {
58 print "<li class=\"feedCat\">Labels</li>";
59 print "<li class=\"feedCatHolder\"><ul class=\"feedCatList\">";
61 // print "<li><hr></li>";
65 while ($line = db_fetch_assoc($result)) {
69 $tmp_result = db_query($link, "SELECT count(id) as count
70 FROM ttrss_entries,ttrss_user_entries
71 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
72 ttrss_user_entries.ref_id = ttrss_entries.id
73 AND owner_uid = '$owner_uid'");
75 $count = db_fetch_result($tmp_result, 0, "count");
83 error_reporting (DEFAULT_ERROR_LEVEL
);
85 printMobileFeedEntry(-$line["id"]-11,
86 $class, $line["description"], $count, "../images/label.png", $link);
90 if (db_num_rows($result) > 0) {
91 if (get_pref($link, 'ENABLE_FEED_CATS')) {
98 if (get_pref($link, 'ENABLE_FEED_CATS')) {
99 $order_by_qpart = "category,title";
101 $order_by_qpart = "title";
104 $result = db_query($link, "SELECT ttrss_feeds.*,
105 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
106 WHERE feed_id = ttrss_feeds.id AND
107 ttrss_user_entries.ref_id = ttrss_entries.id AND
108 owner_uid = '$owner_uid') AS total,
109 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
110 WHERE feed_id = ttrss_feeds.id AND unread = true
111 AND ttrss_user_entries.ref_id = ttrss_entries.id
112 AND owner_uid = '$owner_uid') as unread,
114 ttrss_feed_categories.title AS category,
115 ttrss_feed_categories.collapsed
116 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
117 ON (ttrss_feed_categories.id = cat_id)
119 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
120 ORDER BY $order_by_qpart");
122 $actid = $_GET["actid"];
130 while ($line = db_fetch_assoc($result)) {
132 $feed = db_unescape_string($line["title"]);
133 $feed_id = $line["id"];
135 $subop = $_GET["subop"];
137 $total = $line["total"];
138 $unread = $line["unread"];
140 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
143 $rtl_tag = "dir=\"RTL\"";
148 $tmp_result = db_query($link,
149 "SELECT id,COUNT(unread) AS unread
150 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
151 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
152 WHERE parent_feed = '$feed_id' AND unread = true
153 GROUP BY ttrss_feeds.id");
155 if (db_num_rows($tmp_result) > 0) {
156 while ($l = db_fetch_assoc($tmp_result)) {
157 $unread +
= $l["unread"];
161 $cat_id = $line["cat_id"];
163 $tmp_category = $line["category"];
165 if (!$tmp_category) {
166 $tmp_category = "Uncategorized";
169 // $class = ($lnum % 2) ? "even" : "odd";
171 if ($line["last_error"]) {
177 if ($unread > 0) $class .= "Unread";
179 if ($actid == $feed_id) {
180 $class .= "Selected";
183 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
189 $category = $tmp_category;
191 $collapsed = $line["collapsed"];
193 // workaround for NULL category
194 if ($category == "Uncategorized") {
195 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
200 if ($collapsed == "t" ||
$collapsed == "1") {
201 $holder_class = "invisible";
204 $holder_class = "feedCatHolder";
209 $cat_id_qpart = "cat_id = '$cat_id'";
211 $cat_id_qpart = "cat_id IS NULL";
214 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
215 FROM ttrss_user_entries,ttrss_feeds WHERE
217 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
218 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
220 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
222 $cat_id = sprintf("%d", $cat_id);
224 print "<li class=\"feedCat\">
225 <a href=\"?subop=tc&id=$cat_id\">$tmp_category</a>
226 <a href=\"?go=vf&id=$cat_id&cat=true\">
227 <span class=\"$catctr_class\">($cat_unread
228 unread)$ellipsis</span></a></li>";
230 print "<li id=\"feedCatHolder\" class=\"$holder_class\">
231 <ul class=\"feedCatList\">";
234 printMobileFeedEntry($feed_id, $class, $feed, $unread,
235 "../icons/$feed_id.ico", $link, $rtl_content);
243 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
244 FROM ttrss_user_entries WHERE int_id = post_int_id
245 AND unread = true)) AS count FROM ttrss_tags
246 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
250 while ($line = db_fetch_assoc($result)) {
251 $tags[$line["tag_name"]] +
= $line["count"];
254 foreach (array_keys($tags) as $tag) {
256 $unread = $tags[$tag];
264 printMobileFeedEntry($tag, $class, $tag, $unread,
265 "../images/tag.png", $link);
273 function printMobileFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
274 $rtl_content = false) {
276 if (file_exists($icon_file) && filesize($icon_file) > 0) {
277 $feed_icon = "<img src=\"$icon_file\">";
279 $feed_icon = "<img src=\"../images/blank_icon.gif\">";
283 $rtl_tag = "dir=\"rtl\"";
285 $rtl_tag = "dir=\"ltr\"";
288 $feed = "<a href=\"?go=vf&id=$feed_id\">$feed_title</a>";
290 print "<li class=\"$class\">";
291 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
295 print "<span $rtl_tag>$feed</span> ";
298 print "<span $rtl_tag>($unread)</span>";
305 function render_headlines($link) {
307 $feed = db_escape_string($_GET["id"]);
308 $limit = db_escape_string($_GET["limit"]);
309 $view_mode = db_escape_string($_GET["viewmode"]);
310 $cat_view = db_escape_string($_GET["cat"]);
312 if (!$view_mode) $view_mode = "Adaptive";
313 if (!$limit) $limit = 30;
315 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
317 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
318 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
320 if (db_num_rows($result) == 1) {
321 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
323 $rtl_content = false;
327 $rtl_tag = "dir=\"RTL\"";
332 $rtl_content = false;
336 print "<div id=\"headlines\" $rtl_tag>";
338 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
339 update_generic_feed($link, $feed, $cat_view);
342 if ($subop == "MarkAllRead") {
343 catchup_feed($link, $feed, $cat_view);
346 $search = db_escape_string($_GET["search"]);
347 $search_mode = db_escape_string($_GET["smode"]);
350 $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%')
351 OR ttrss_entries.content LIKE '%$search%') AND";
353 $search_query_part = "";
356 $view_query_part = "";
358 if ($view_mode == "Adaptive") {
360 $view_query_part = " ";
361 } else if ($feed != -1) {
362 $unread = getFeedUnread($link, $feed);
364 $view_query_part = " unread = true AND ";
369 if ($view_mode == "Starred") {
370 $view_query_part = " marked = true AND ";
373 if ($view_mode == "Unread") {
374 $view_query_part = " unread = true AND ";
377 if ($limit && $limit != "All") {
378 $limit_query_part = "LIMIT " . $limit;
381 $vfeed_query_part = "";
383 // override query strategy and enable feed display when searching globally
384 if ($search && $search_mode == "All feeds") {
385 $query_strategy_part = "ttrss_entries.id > 0";
386 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
387 } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
388 $query_strategy_part = "ttrss_entries.id > 0";
389 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
390 id = feed_id) as feed_title,";
391 } else if ($feed >= 0 && $search && $search_mode == "This category") {
393 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
395 $tmp_result = db_query($link, "SELECT id
396 FROM ttrss_feeds WHERE cat_id =
397 (SELECT cat_id FROM ttrss_feeds WHERE id = '$feed') AND id != '$feed'");
399 $cat_siblings = array();
401 if (db_num_rows($tmp_result) > 0) {
402 while ($p = db_fetch_assoc($tmp_result)) {
403 array_push($cat_siblings, "feed_id = " . $p["id"]);
406 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
407 $feed, implode(" OR ", $cat_siblings));
410 $query_strategy_part = "ttrss_entries.id > 0";
413 } else if ($feed >= 0) {
418 $query_strategy_part = "cat_id = '$feed'";
420 $query_strategy_part = "cat_id IS NULL";
423 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
426 $tmp_result = db_query($link, "SELECT id
427 FROM ttrss_feeds WHERE parent_feed = '$feed'
428 ORDER BY cat_id,title");
430 $parent_ids = array();
432 if (db_num_rows($tmp_result) > 0) {
433 while ($p = db_fetch_assoc($tmp_result)) {
434 array_push($parent_ids, "feed_id = " . $p["id"]);
437 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
438 $feed, implode(" OR ", $parent_ids));
440 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
442 $query_strategy_part = "feed_id = '$feed'";
445 } else if ($feed == -1) { // starred virtual feed
446 $query_strategy_part = "marked = true";
447 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
448 } else if ($feed <= -10) { // labels
449 $label_id = -$feed - 11;
451 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
452 WHERE id = '$label_id'");
454 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
456 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
458 $query_strategy_part = "id > 0"; // dumb
461 $order_by = "updated DESC";
463 // if ($feed < -10) {
464 // $order_by = "feed_id,updated DESC";
469 if ($search && $search_mode == "All feeds") {
470 $feed_title = "Global search results ($search)";
471 } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
472 $feed_title = "Feed search results ($search, $feed)";
473 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
475 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
480 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
481 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
482 $feed_title = db_fetch_result($result, 0, "title");
484 $feed_title = "Uncategorized";
488 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
489 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
491 $feed_title = db_fetch_result($result, 0, "title");
492 $feed_site_url = db_fetch_result($result, 0, "site_url");
493 $last_error = db_fetch_result($result, 0, "last_error");
497 } else if ($feed == -1) {
498 $feed_title = "Starred articles";
499 } else if ($feed < -10) {
500 $label_id = -$feed - 11;
501 $result = db_query($link, "SELECT description FROM ttrss_labels
502 WHERE id = '$label_id'");
503 $feed_title = db_fetch_result($result, 0, "description");
508 if ($feed < -10) error_reporting (0);
510 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
513 $feed_kind = "Feeds";
515 $feed_kind = "Labels";
519 ttrss_entries.id,ttrss_entries.title,
520 SUBSTRING(updated,1,16) as updated,
521 unread,feed_id,marked,link,last_read,
522 SUBSTRING(last_read,1,19) as last_read_noms,
524 SUBSTRING(updated,1,19) as updated_noms
526 ttrss_entries,ttrss_user_entries,ttrss_feeds
528 ttrss_user_entries.feed_id = ttrss_feeds.id AND
529 ttrss_user_entries.ref_id = ttrss_entries.id AND
530 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
533 $query_strategy_part ORDER BY $order_by
536 $result = db_query($link, $query);
538 if ($_GET["debug"]) print $query;
545 $result = db_query($link, "SELECT
546 ttrss_entries.id as id,title,
547 SUBSTRING(updated,1,16) as updated,
549 marked,link,last_read,
550 SUBSTRING(last_read,1,19) as last_read_noms,
553 SUBSTRING(updated,1,19) as updated_noms
555 ttrss_entries,ttrss_user_entries,ttrss_tags
557 ref_id = ttrss_entries.id AND
558 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
559 post_int_id = int_id AND tag_name = '$feed' AND
562 $query_strategy_part ORDER BY $order_by
567 print "<div align='center'>
568 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
572 print "<div id=\"heading\">";
573 if (!$cat_view && file_exists("../icons/$feed.ico") && filesize("../icons/$feed.ico") > 0) {
574 print "<img class=\"tinyFeedIcon\" src=\"../icons/$feed.ico\">";
578 // print " (» <a href=\"tt-rss.php\">My feeds</a>)";
582 if (db_num_rows($result) > 0) {
584 // print "<table class=\"headlines\" cellspacing=\"0\" width=\"100%\">";
586 print "<ul class=\"headlines\">";
590 error_reporting (DEFAULT_ERROR_LEVEL
);
594 while ($line = db_fetch_assoc($result)) {
596 $class = ($lnum %
2) ?
"even" : "odd";
599 $feed_id = $line["feed_id"];
601 if ($line["last_read"] == "" &&
602 ($line["unread"] != "t" && $line["unread"] != "1")) {
604 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
607 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
611 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
619 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
620 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"../images/mark_set.png\">";
622 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"../images/mark_unset.png\">";
625 $content_link = "<a href=\"?go=view&id=$id&feed=$feed_id\">" .
626 $line["title"] . "</a>";
628 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
629 $updated_fmt = smart_date_time(strtotime($line["updated"]));
631 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
632 $updated_fmt = date($short_date, strtotime($line["updated"]));
635 print "<li class='$class'>";
639 if ($line["feed_title"]) {
640 print " (<a href='?go=vf&id=$feed_id'>".
641 $line["feed_title"]."</a>)";
644 print "<span class='hlUpdated'> — $updated_fmt</span>";
655 print "<div align='center'>No articles found.</div>";
660 function render_article($link) {
662 $id = db_escape_string($_GET["id"]);
663 $feed_id = db_escape_string($_GET["feed"]);
665 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
666 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
668 if (db_num_rows($result) == 1) {
669 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
671 $rtl_content = false;
675 $rtl_tag = "dir=\"RTL\"";
682 $result = db_query($link, "UPDATE ttrss_user_entries
683 SET unread = false,last_read = NOW()
684 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
686 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
687 SUBSTRING(updated,1,16) as updated,
688 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
691 FROM ttrss_entries,ttrss_user_entries
692 WHERE id = '$id' AND ref_id = id");
696 $line = db_fetch_assoc($result);
698 $num_comments = $line["num_comments"];
699 $entry_comments = "";
701 if ($num_comments > 0) {
702 if ($line["comments"]) {
703 $comments_url = $line["comments"];
705 $comments_url = $line["link"];
707 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
709 if ($line["comments"] && $line["link"] != $line["comments"]) {
710 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
714 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
715 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
723 while ($tmp_line = db_fetch_assoc($tmp_result)) {
725 $tag = $tmp_line["tag_name"];
726 $tag_str = "<a href=\"?go=vf&id=$tag\">$tag</a>, ";
727 $tags_str .= $tag_str;
730 $tags_str = preg_replace("/, $/", "", $tags_str);
732 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
733 strtotime($line["updated"]));
735 print "<div id=\"heading\">";
736 print $line["title"] . " <span id=\"headingAddon\">($parsed_updated)</span>";
740 print "<div class=\"postTags\">Tags: $tags_str</div>";
743 print $line["content"];
747 print "</body></html>";