]>
git.wh0rd.org - tt-rss.git/blob - mobile/functions.php
07a7544de8e29fe2c609bc0f1deeceada457f418
2 define('MOBILE_FEEDLIST_ENABLE_ICONS', false);
3 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
5 function render_feeds_list($link) {
9 print "<div id=\"heading\">";
12 print "Tags <span id=\"headingAddon\">
13 (<a href=\"tt-rss.php\">View feeds</a>, ";
15 print "Feeds <span id=\"headingAddon\">
16 (<a href=\"tt-rss.php?tags=1\">View tags</a>, ";
19 print "<a href=\"tt-rss.php?go=sform\">Search</a>, ";
21 print "<a href=\"logout.php\">Logout</a>)</span>";
24 print "<ul class=\"feedList\">";
26 $owner_uid = $_SESSION["uid"];
32 if (get_pref($link, 'ENABLE_FEED_CATS')) {
33 print "<li class=\"feedCat\">Special</li>";
34 print "<li class=\"feedCatHolder\"><ul class=\"feedCatList\">";
37 $num_fresh = getFeedUnread($link, -3);
41 if ($num_fresh > 0) $class .= "Unread";
43 printMobileFeedEntry(-3, $class, "Fresh articles", $num_fresh,
44 "../images/fresh.png", $link);
46 $num_starred = getFeedUnread($link, -1);
50 if ($num_starred > 0) $class .= "Unread";
52 printMobileFeedEntry(-1, $class, "Starred articles", $num_starred,
53 "../images/mark_set.png", $link);
55 if (get_pref($link, 'ENABLE_FEED_CATS')) {
59 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
61 $result = db_query($link, "SELECT id,description FROM
62 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
64 if (db_num_rows($result) > 0) {
65 if (get_pref($link, 'ENABLE_FEED_CATS')) {
66 print "<li class=\"feedCat\">Labels</li>";
67 print "<li class=\"feedCatHolder\"><ul class=\"feedCatList\">";
69 // print "<li><hr></li>";
73 while ($line = db_fetch_assoc($result)) {
77 $count = getFeedUnread($link, -$line["id"]-11);
85 error_reporting (DEFAULT_ERROR_LEVEL
);
87 printMobileFeedEntry(-$line["id"]-11,
88 $class, $line["description"], $count, "../images/label.png", $link);
92 if (db_num_rows($result) > 0) {
93 if (get_pref($link, 'ENABLE_FEED_CATS')) {
100 if (get_pref($link, 'ENABLE_FEED_CATS')) {
101 $order_by_qpart = "category,title";
103 $order_by_qpart = "title";
106 $result = db_query($link, "SELECT ttrss_feeds.*,
107 SUBSTRING(last_updated,1,19) AS last_updated_noms,
108 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
109 WHERE feed_id = ttrss_feeds.id AND
110 ttrss_user_entries.ref_id = ttrss_entries.id AND
111 owner_uid = '$owner_uid') AS total,
112 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
113 WHERE feed_id = ttrss_feeds.id AND unread = true
114 AND ttrss_user_entries.ref_id = ttrss_entries.id
115 AND owner_uid = '$owner_uid') as unread,
117 ttrss_feed_categories.title AS category,
118 ttrss_feed_categories.collapsed
119 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
120 ON (ttrss_feed_categories.id = cat_id)
122 ttrss_feeds.hidden = false AND
123 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
124 ORDER BY $order_by_qpart");
126 $actid = $_GET["actid"];
134 while ($line = db_fetch_assoc($result)) {
136 $feed = db_unescape_string($line["title"]);
137 $feed_id = $line["id"];
139 $subop = $_GET["subop"];
141 $total = $line["total"];
142 $unread = $line["unread"];
144 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
147 $rtl_tag = "dir=\"RTL\"";
152 $tmp_result = db_query($link,
153 "SELECT id,COUNT(unread) AS unread
154 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
155 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
156 WHERE parent_feed = '$feed_id' AND unread = true
157 GROUP BY ttrss_feeds.id");
159 if (db_num_rows($tmp_result) > 0) {
160 while ($l = db_fetch_assoc($tmp_result)) {
161 $unread +
= $l["unread"];
165 $cat_id = $line["cat_id"];
167 $tmp_category = $line["category"];
169 if (!$tmp_category) {
170 $tmp_category = "Uncategorized";
173 // $class = ($lnum % 2) ? "even" : "odd";
175 if ($line["last_error"]) {
181 if ($unread > 0) $class .= "Unread";
183 if ($actid == $feed_id) {
184 $class .= "Selected";
187 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
193 $category = $tmp_category;
195 $collapsed = $line["collapsed"];
197 // workaround for NULL category
198 if ($category == "Uncategorized") {
199 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
204 if ($collapsed == "t" ||
$collapsed == "1") {
205 $holder_class = "invisible";
208 $holder_class = "feedCatHolder";
213 $cat_id_qpart = "cat_id = '$cat_id'";
215 $cat_id_qpart = "cat_id IS NULL";
218 $cat_id = sprintf("%d", $cat_id);
219 $cat_unread = getCategoryUnread($link, $cat_id);
221 print "<li class=\"feedCat\">
222 <a href=\"?subop=tc&id=$cat_id\">$tmp_category</a>
223 <a href=\"?go=vf&id=$cat_id&cat=true\">
224 <span class=\"$catctr_class\">($cat_unread
225 unread)$ellipsis</span></a></li>";
227 print "<li id=\"feedCatHolder\" class=\"$holder_class\">
228 <ul class=\"feedCatList\">";
231 printMobileFeedEntry($feed_id, $class, $feed, $unread,
232 "../icons/$feed_id.ico", $link, $rtl_content);
240 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
241 FROM ttrss_user_entries WHERE int_id = post_int_id
242 AND unread = true)) AS count FROM ttrss_tags
243 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
247 while ($line = db_fetch_assoc($result)) {
248 $tags[$line["tag_name"]] +
= $line["count"];
251 foreach (array_keys($tags) as $tag) {
253 $unread = $tags[$tag];
261 printMobileFeedEntry($tag, $class, $tag, $unread,
262 "../images/tag.png", $link);
270 function printMobileFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
271 $rtl_content = false) {
273 if (file_exists($icon_file) && filesize($icon_file) > 0) {
274 $feed_icon = "<img src=\"$icon_file\">";
276 $feed_icon = "<img src=\"../images/blank_icon.gif\">";
280 $rtl_tag = "dir=\"rtl\"";
282 $rtl_tag = "dir=\"ltr\"";
285 $feed = "<a href=\"?go=vf&id=$feed_id\">$feed_title</a>";
287 print "<li class=\"$class\">";
288 # if (get_pref($link, 'ENABLE_FEED_ICONS')) {
289 # print "$feed_icon";
292 print "<span $rtl_tag>$feed</span> ";
295 print "<span $rtl_tag>($unread)</span>";
302 function render_headlines($link) {
304 $feed = db_escape_string($_GET["id"]);
305 $limit = db_escape_string($_GET["limit"]);
306 $view_mode = db_escape_string($_GET["viewmode"]);
307 $cat_view = db_escape_string($_GET["cat"]);
308 $subop = $_GET["subop"];
310 if (!$view_mode) $view_mode = "Adaptive";
311 if (!$limit) $limit = 30;
312 if (!$feed) $feed = 0;
314 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
316 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
317 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
319 if (db_num_rows($result) == 1) {
320 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
322 $rtl_content = false;
326 $rtl_tag = "dir=\"RTL\"";
331 $rtl_content = false;
335 print "<div id=\"headlines\" $rtl_tag>";
337 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
338 update_generic_feed($link, $feed, $cat_view, true);
341 if ($subop == "MarkAllRead") {
342 catchup_feed($link, $feed, $cat_view);
345 if ($subop == "MarkPageRead") {
346 $ids_to_mark = $_SESSION["last_page_ids.$feed"];
350 foreach ($ids_to_mark as $id) {
351 db_query($link, "UPDATE ttrss_user_entries SET
352 unread = false,last_read = NOW()
353 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
359 /// START /////////////////////////////////////////////////////////////////////////////////
361 $search = db_escape_string($_GET["query"]);
362 $search_mode = db_escape_string($_GET["search_mode"]);
363 $match_on = db_escape_string($_GET["match_on"]);
369 $real_offset = $offset * $limit;
371 if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
373 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
374 $search, $search_mode, $match_on, false, $real_offset);
376 if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
378 $result = $qfh_ret[0];
379 $feed_title = $qfh_ret[1];
380 $feed_site_url = $qfh_ret[2];
381 $last_error = $qfh_ret[3];
383 /// STOP //////////////////////////////////////////////////////////////////////////////////
386 print "<div align='center'>
387 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
391 print "<div id=\"heading\">";
392 # if (!$cat_view && file_exists("../icons/$feed.ico") && filesize("../icons/$feed.ico") > 0) {
393 # print "<img class=\"feedIcon\" src=\"../icons/$feed.ico\">";
396 print "$feed_title <span id=\"headingAddon\">(";
397 print "<a href=\"tt-rss.php\">Back</a>, ";
398 print "<a href=\"tt-rss.php?go=sform&aid=$feed&ic=$cat_view\">Search</a>, ";
399 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=ForceUpdate\">Update</a>";
400 # print "Mark as read: ";
401 # print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAsRead\">Page</a>, ";
402 # print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAllRead\">Feed</a>";
408 if (db_num_rows($result) > 0) {
410 print "<ul class=\"headlines\">";
412 $page_art_ids = array();
416 error_reporting (DEFAULT_ERROR_LEVEL
);
420 while ($line = db_fetch_assoc($result)) {
422 $class = ($lnum %
2) ?
"even" : "odd";
425 $feed_id = $line["feed_id"];
427 array_push($page_art_ids, $id);
429 if ($line["last_read"] == "" &&
430 ($line["unread"] != "t" && $line["unread"] != "1")) {
432 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
435 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
439 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
447 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
448 $marked_pic = "<img class='marked' src=\"../images/mark_set.png\">";
450 $marked_pic = "<img class='marked' src=\"../images/mark_unset.png\">";
453 $content_link = "<a href=\"?go=view&id=$id&ret_feed=$feed&feed=$feed_id\">" .
454 $line["title"] . "</a>";
456 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
457 $updated_fmt = smart_date_time(strtotime($line["updated"]));
459 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
460 $updated_fmt = date($short_date, strtotime($line["updated"]));
463 print "<li class='$class'>";
465 print "<a href=\"?go=vf&id=$feed&ts=$id\">$marked_pic</a>";
469 if ($line["feed_title"]) {
470 print " (<a href='?go=vf&id=$feed_id'>".
471 $line["feed_title"]."</a>)";
474 print "<span class='hlUpdated'> ($updated_fmt)</span>";
484 print "<div class='footerAddon'>Mark as read: ";
486 $_SESSION["last_page_ids.$feed"] = $page_art_ids;
488 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkPageRead\">Page</a>, ";
489 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAllRead\">Feed</a></div>";
492 print "<div align='center'>No articles found.</div>";
497 function render_article($link) {
499 $id = db_escape_string($_GET["id"]);
500 $feed_id = db_escape_string($_GET["feed"]);
501 $ret_feed_id = db_escape_string($_GET["ret_feed"]);
503 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
504 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
506 if (db_num_rows($result) == 1) {
507 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
509 $rtl_content = false;
513 $rtl_tag = "dir=\"RTL\"";
520 $result = db_query($link, "UPDATE ttrss_user_entries
521 SET unread = false,last_read = NOW()
522 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
524 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
525 SUBSTRING(updated,1,16) as updated,
526 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
529 FROM ttrss_entries,ttrss_user_entries
530 WHERE id = '$id' AND ref_id = id");
534 $line = db_fetch_assoc($result);
536 $num_comments = $line["num_comments"];
537 $entry_comments = "";
539 if ($num_comments > 0) {
540 if ($line["comments"]) {
541 $comments_url = $line["comments"];
543 $comments_url = $line["link"];
545 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
547 if ($line["comments"] && $line["link"] != $line["comments"]) {
548 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
552 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
553 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
561 while ($tmp_line = db_fetch_assoc($tmp_result)) {
563 $tag = $tmp_line["tag_name"];
564 $tag_str = "<a href=\"?go=vf&id=$tag\">$tag</a>, ";
565 $tags_str .= $tag_str;
568 $tags_str = preg_replace("/, $/", "", $tags_str);
570 $parsed_updated = date(get_pref($link, 'SHORT_DATE_FORMAT'),
571 strtotime($line["updated"]));
573 print "<div id=\"heading\">";
575 # if (file_exists("../icons/$feed_id.ico") && filesize("../icons/$feed_id.ico") > 0) {
576 # print "<img class=\"feedIcon\" src=\"../icons/$feed_id.ico\">";
579 $feed_link = "<a href=\"tt-rss.php?go=vf&id=$ret_feed_id\">Feed</a>";
581 print "<a href=\"" . $line["link"] . "\">" .
582 truncate_string($line["title"], 30) . "</a>";
583 print " <span id=\"headingAddon\">$parsed_updated ($feed_link)</span>";
587 print "<div class=\"postTags\">Tags: $tags_str</div>";
590 print sanitize_rss($link, $line["content"], true);;
594 print "</body></html>";
597 function render_search_form($link, $active_feed_id = false, $is_cat = false) {
599 print "<div id=\"heading\">";
601 print "Search <span id=\"headingAddon\">
602 (<a href=\"tt-rss.php\">Go back</a>)</span></div>";
604 print "<form method=\"GET\" action=\"tt-rss.php\" class=\"searchForm\">";
606 print "<input type=\"hidden\" name=\"go\" value=\"vf\">";
607 print "<input type=\"hidden\" name=\"id\" value=\"$active_feed_id\">";
608 print "<input type=\"hidden\" name=\"cat\" value=\"$is_cat\">";
610 print "<table><tr><td>".__('Search:')."</td><td>";
611 print "<input name=\"query\"></td></tr>";
613 print "<tr><td>".__('Where:')."</td><td>";
615 print "<select name=\"search_mode\">
616 <option value=\"all_feeds\">".__('All feeds')."</option>";
618 $feed_title = getFeedTitle($link, $active_feed_id);
621 $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
623 $feed_cat_title = getCategoryTitle($link, $active_feed_id);
626 if ($active_feed_id && !$is_cat) {
627 print "<option selected value=\"this_feed\">$feed_title</option>";
629 print "<option disabled>".__('This feed')."</option>";
633 $cat_preselected = "selected";
636 if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 ||
$is_cat)) {
637 print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>";
639 //print "<option disabled>".__('This category')."</option>";
642 print "</select></td></tr>";
644 print "<tr><td>".__('Match on:')."</td><td>";
646 $search_fields = array(
647 "title" => __("Title"),
648 "content" => __("Content"),
649 "both" => __("Title or content"));
651 print_select_hash("match_on", 3, $search_fields);
653 print "</td></tr></table>";
655 print "<input type=\"submit\" value=\"".__('Search')."\">";