]>
git.wh0rd.org - tt-rss.git/blob - mobile/functions.php
a9a4887d41f5523e168540f14dac9c9296bb1a01
2 define('MOBILE_FEEDLIST_ENABLE_ICONS', false);
3 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
5 define ('TW_PATH', '../tw/');
7 function render_feeds_list($link) {
11 print "<div id=\"heading\">";
14 print "Tags <span id=\"headingAddon\">
15 (<a href=\"tt-rss.php\">View feeds</a>, ";
17 print "Feeds <span id=\"headingAddon\">
18 (<a href=\"tt-rss.php?tags=1\">View tags</a>, ";
21 print "<a href=\"tt-rss.php?go=sform\">Search</a>, ";
23 print "<a href=\"logout.php\">Logout</a>)</span>";
26 print "<ul class=\"feedList\">";
28 $owner_uid = $_SESSION["uid"];
34 if (get_pref($link, 'ENABLE_FEED_CATS')) {
35 print "<li class=\"feedCat\">Special</li>";
36 print "<li class=\"feedCatHolder\"><ul class=\"feedCatList\">";
39 $num_starred = getFeedUnread($link, -1);
43 if ($num_starred > 0) $class .= "Unread";
45 printMobileFeedEntry(-1, $class, "Starred articles", $num_starred,
46 "../images/mark_set.png", $link);
48 if (get_pref($link, 'ENABLE_FEED_CATS')) {
52 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
54 $result = db_query($link, "SELECT id,description FROM
55 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
57 if (db_num_rows($result) > 0) {
58 if (get_pref($link, 'ENABLE_FEED_CATS')) {
59 print "<li class=\"feedCat\">Labels</li>";
60 print "<li class=\"feedCatHolder\"><ul class=\"feedCatList\">";
62 // print "<li><hr></li>";
66 while ($line = db_fetch_assoc($result)) {
70 $count = getFeedUnread($link, -$line["id"]-11);
78 error_reporting (DEFAULT_ERROR_LEVEL
);
80 printMobileFeedEntry(-$line["id"]-11,
81 $class, $line["description"], $count, "../images/label.png", $link);
85 if (db_num_rows($result) > 0) {
86 if (get_pref($link, 'ENABLE_FEED_CATS')) {
93 if (get_pref($link, 'ENABLE_FEED_CATS')) {
94 $order_by_qpart = "category,title";
96 $order_by_qpart = "title";
99 $result = db_query($link, "SELECT ttrss_feeds.*,
100 SUBSTRING(last_updated,1,19) AS last_updated_noms,
101 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
102 WHERE feed_id = ttrss_feeds.id AND
103 ttrss_user_entries.ref_id = ttrss_entries.id AND
104 owner_uid = '$owner_uid') AS total,
105 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
106 WHERE feed_id = ttrss_feeds.id AND unread = true
107 AND ttrss_user_entries.ref_id = ttrss_entries.id
108 AND owner_uid = '$owner_uid') as unread,
110 ttrss_feed_categories.title AS category,
111 ttrss_feed_categories.collapsed
112 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
113 ON (ttrss_feed_categories.id = cat_id)
115 ttrss_feeds.hidden = false AND
116 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
117 ORDER BY $order_by_qpart");
119 $actid = $_GET["actid"];
127 while ($line = db_fetch_assoc($result)) {
129 $feed = db_unescape_string($line["title"]);
130 $feed_id = $line["id"];
132 $subop = $_GET["subop"];
134 $total = $line["total"];
135 $unread = $line["unread"];
137 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
140 $rtl_tag = "dir=\"RTL\"";
145 $tmp_result = db_query($link,
146 "SELECT id,COUNT(unread) AS unread
147 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
148 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
149 WHERE parent_feed = '$feed_id' AND unread = true
150 GROUP BY ttrss_feeds.id");
152 if (db_num_rows($tmp_result) > 0) {
153 while ($l = db_fetch_assoc($tmp_result)) {
154 $unread +
= $l["unread"];
158 $cat_id = $line["cat_id"];
160 $tmp_category = $line["category"];
162 if (!$tmp_category) {
163 $tmp_category = "Uncategorized";
166 // $class = ($lnum % 2) ? "even" : "odd";
168 if ($line["last_error"]) {
174 if ($unread > 0) $class .= "Unread";
176 if ($actid == $feed_id) {
177 $class .= "Selected";
180 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
186 $category = $tmp_category;
188 $collapsed = $line["collapsed"];
190 // workaround for NULL category
191 if ($category == "Uncategorized") {
192 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
197 if ($collapsed == "t" ||
$collapsed == "1") {
198 $holder_class = "invisible";
201 $holder_class = "feedCatHolder";
206 $cat_id_qpart = "cat_id = '$cat_id'";
208 $cat_id_qpart = "cat_id IS NULL";
211 $cat_id = sprintf("%d", $cat_id);
212 $cat_unread = getCategoryUnread($link, $cat_id);
214 print "<li class=\"feedCat\">
215 <a href=\"?subop=tc&id=$cat_id\">$tmp_category</a>
216 <a href=\"?go=vf&id=$cat_id&cat=true\">
217 <span class=\"$catctr_class\">($cat_unread
218 unread)$ellipsis</span></a></li>";
220 print "<li id=\"feedCatHolder\" class=\"$holder_class\">
221 <ul class=\"feedCatList\">";
224 printMobileFeedEntry($feed_id, $class, $feed, $unread,
225 "../icons/$feed_id.ico", $link, $rtl_content);
233 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
234 FROM ttrss_user_entries WHERE int_id = post_int_id
235 AND unread = true)) AS count FROM ttrss_tags
236 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
240 while ($line = db_fetch_assoc($result)) {
241 $tags[$line["tag_name"]] +
= $line["count"];
244 foreach (array_keys($tags) as $tag) {
246 $unread = $tags[$tag];
254 printMobileFeedEntry($tag, $class, $tag, $unread,
255 "../images/tag.png", $link);
263 function printMobileFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
264 $rtl_content = false) {
266 if (file_exists($icon_file) && filesize($icon_file) > 0) {
267 $feed_icon = "<img src=\"$icon_file\">";
269 $feed_icon = "<img src=\"../images/blank_icon.gif\">";
273 $rtl_tag = "dir=\"rtl\"";
275 $rtl_tag = "dir=\"ltr\"";
278 $feed = "<a href=\"?go=vf&id=$feed_id\">$feed_title</a>";
280 print "<li class=\"$class\">";
281 # if (get_pref($link, 'ENABLE_FEED_ICONS')) {
282 # print "$feed_icon";
285 print "<span $rtl_tag>$feed</span> ";
288 print "<span $rtl_tag>($unread)</span>";
295 function render_headlines($link) {
297 $feed = db_escape_string($_GET["id"]);
298 $limit = db_escape_string($_GET["limit"]);
299 $view_mode = db_escape_string($_GET["viewmode"]);
300 $cat_view = db_escape_string($_GET["cat"]);
301 $subop = $_GET["subop"];
303 if (!$view_mode) $view_mode = "Adaptive";
304 if (!$limit) $limit = 30;
305 if (!$feed) $feed = 0;
307 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
309 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
310 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
312 if (db_num_rows($result) == 1) {
313 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
315 $rtl_content = false;
319 $rtl_tag = "dir=\"RTL\"";
324 $rtl_content = false;
328 print "<div id=\"headlines\" $rtl_tag>";
330 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
331 update_generic_feed($link, $feed, $cat_view);
334 if ($subop == "MarkAllRead") {
335 catchup_feed($link, $feed, $cat_view);
338 if ($subop == "MarkPageRead") {
339 $ids_to_mark = $_SESSION["last_page_ids.$feed"];
343 foreach ($ids_to_mark as $id) {
344 db_query($link, "UPDATE ttrss_user_entries SET
345 unread = false,last_read = NOW()
346 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
352 /// START /////////////////////////////////////////////////////////////////////////////////
354 $search = db_escape_string($_GET["query"]);
355 $search_mode = db_escape_string($_GET["search_mode"]);
356 $match_on = db_escape_string($_GET["match_on"]);
362 $real_offset = $offset * $limit;
364 if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
366 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
367 $search, $search_mode, $match_on, false, $real_offset);
369 if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
371 $result = $qfh_ret[0];
372 $feed_title = $qfh_ret[1];
373 $feed_site_url = $qfh_ret[2];
374 $last_error = $qfh_ret[3];
376 /// STOP //////////////////////////////////////////////////////////////////////////////////
379 print "<div align='center'>
380 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
384 print "<div id=\"heading\">";
385 # if (!$cat_view && file_exists("../icons/$feed.ico") && filesize("../icons/$feed.ico") > 0) {
386 # print "<img class=\"feedIcon\" src=\"../icons/$feed.ico\">";
389 print "$feed_title <span id=\"headingAddon\">(";
390 print "<a href=\"tt-rss.php\">Back</a>, ";
391 print "<a href=\"tt-rss.php?go=sform&aid=$feed&ic=$cat_view\">Search</a>, ";
392 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=ForceUpdate\">Update</a>";
393 # print "Mark as read: ";
394 # print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAsRead\">Page</a>, ";
395 # print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAllRead\">Feed</a>";
401 if (db_num_rows($result) > 0) {
403 print "<ul class=\"headlines\">";
405 $page_art_ids = array();
409 error_reporting (DEFAULT_ERROR_LEVEL
);
413 while ($line = db_fetch_assoc($result)) {
415 $class = ($lnum %
2) ?
"even" : "odd";
418 $feed_id = $line["feed_id"];
420 array_push($page_art_ids, $id);
422 if ($line["last_read"] == "" &&
423 ($line["unread"] != "t" && $line["unread"] != "1")) {
425 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
428 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
432 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
440 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
441 $marked_pic = "<img class='marked' src=\"../images/mark_set.png\">";
443 $marked_pic = "<img class='marked' src=\"../images/mark_unset.png\">";
446 $content_link = "<a href=\"?go=view&id=$id&ret_feed=$feed&feed=$feed_id\">" .
447 $line["title"] . "</a>";
449 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
450 $updated_fmt = smart_date_time(strtotime($line["updated"]));
452 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
453 $updated_fmt = date($short_date, strtotime($line["updated"]));
456 print "<li class='$class'>";
458 print "<a href=\"?go=vf&id=$feed&ts=$id\">$marked_pic</a>";
462 if ($line["feed_title"]) {
463 print " (<a href='?go=vf&id=$feed_id'>".
464 $line["feed_title"]."</a>)";
467 print "<span class='hlUpdated'> ($updated_fmt)</span>";
477 print "<div class='footerAddon'>Mark as read: ";
479 $_SESSION["last_page_ids.$feed"] = $page_art_ids;
481 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkPageRead\">Page</a>, ";
482 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAllRead\">Feed</a></div>";
485 print "<div align='center'>No articles found.</div>";
490 function render_article($link) {
492 $id = db_escape_string($_GET["id"]);
493 $feed_id = db_escape_string($_GET["feed"]);
494 $ret_feed_id = db_escape_string($_GET["ret_feed"]);
496 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
497 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
499 if (db_num_rows($result) == 1) {
500 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
502 $rtl_content = false;
506 $rtl_tag = "dir=\"RTL\"";
513 $result = db_query($link, "UPDATE ttrss_user_entries
514 SET unread = false,last_read = NOW()
515 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
517 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
518 SUBSTRING(updated,1,16) as updated,
519 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
522 FROM ttrss_entries,ttrss_user_entries
523 WHERE id = '$id' AND ref_id = id");
527 $line = db_fetch_assoc($result);
529 $num_comments = $line["num_comments"];
530 $entry_comments = "";
532 if ($num_comments > 0) {
533 if ($line["comments"]) {
534 $comments_url = $line["comments"];
536 $comments_url = $line["link"];
538 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
540 if ($line["comments"] && $line["link"] != $line["comments"]) {
541 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
545 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
546 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
554 while ($tmp_line = db_fetch_assoc($tmp_result)) {
556 $tag = $tmp_line["tag_name"];
557 $tag_str = "<a href=\"?go=vf&id=$tag\">$tag</a>, ";
558 $tags_str .= $tag_str;
561 $tags_str = preg_replace("/, $/", "", $tags_str);
563 $parsed_updated = date(get_pref($link, 'SHORT_DATE_FORMAT'),
564 strtotime($line["updated"]));
566 print "<div id=\"heading\">";
568 # if (file_exists("../icons/$feed_id.ico") && filesize("../icons/$feed_id.ico") > 0) {
569 # print "<img class=\"feedIcon\" src=\"../icons/$feed_id.ico\">";
572 $feed_link = "<a href=\"tt-rss.php?go=vf&id=$ret_feed_id\">Feed</a>";
574 print "<a href=\"" . $line["link"] . "\">" .
575 truncate_string($line["title"], 30) . "</a>";
576 print " <span id=\"headingAddon\">$parsed_updated ($feed_link)</span>";
580 print "<div class=\"postTags\">Tags: $tags_str</div>";
583 print sanitize_rss($link, $line["content"], true);;
587 print "</body></html>";
590 function render_search_form($link, $active_feed_id = false, $is_cat = false) {
592 print "<div id=\"heading\">";
594 print "Search <span id=\"headingAddon\">
595 (<a href=\"tt-rss.php\">Go back</a>)</span></div>";
597 print "<form method=\"GET\" action=\"tt-rss.php\" class=\"searchForm\">";
599 print "<input type=\"hidden\" name=\"go\" value=\"vf\">";
600 print "<input type=\"hidden\" name=\"id\" value=\"$active_feed_id\">";
601 print "<input type=\"hidden\" name=\"cat\" value=\"$is_cat\">";
603 print "<table><tr><td>".__('Search:')."</td><td>";
604 print "<input name=\"query\"></td></tr>";
606 print "<tr><td>".__('Where:')."</td><td>";
608 print "<select name=\"search_mode\">
609 <option value=\"all_feeds\">".__('All feeds')."</option>";
611 $feed_title = getFeedTitle($link, $active_feed_id);
614 $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
616 $feed_cat_title = getCategoryTitle($link, $active_feed_id);
619 if ($active_feed_id && !$is_cat) {
620 print "<option selected value=\"this_feed\">$feed_title</option>";
622 print "<option disabled>".__('This feed')."</option>";
626 $cat_preselected = "selected";
629 if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 ||
$is_cat)) {
630 print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>";
632 //print "<option disabled>".__('This category')."</option>";
635 print "</select></td></tr>";
637 print "<tr><td>".__('Match on:')."</td><td>";
639 $search_fields = array(
640 "title" => __("Title"),
641 "content" => __("Content"),
642 "both" => __("Title or content"));
644 print_select_hash("match_on", 3, $search_fields);
646 print "</td></tr></table>";
648 print "<input type=\"submit\" value=\"".__('Search')."\">";