]>
git.wh0rd.org - tt-rss.git/blob - mobile/functions.php
2 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
4 /* TODO replace with interface to db-prefs */
6 function mobile_pref_toggled($link, $id) {
7 if (get_pref($link, "_MOBILE_$id"))
13 function mobile_get_pref($link, $id) {
14 //return $_SESSION["mobile-prefs"][$id];
15 return get_pref($link, "_MOBILE_$id");
18 function mobile_set_pref($link, $id, $value) {
19 //$_SESSION["mobile-prefs"][$id] = $value;
20 return set_pref($link, "_MOBILE_$id", $value);
23 function mobile_feed_has_icon($id) {
24 $filename = "../".ICONS_DIR
."/$id.ico";
26 return file_exists($filename) && filesize($filename) > 0;
29 function render_flat_feed_list($link, $offset) {
30 $owner_uid = $_SESSION["uid"];
33 if (!$offset) $offset = 0;
35 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
36 $order_by = "unread DESC, title";
42 $limit_qpart = "LIMIT $limit OFFSET $offset";
47 $result = db_query($link, "SELECT id,
49 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
50 WHERE feed_id = ttrss_feeds.id AND unread = true
51 AND ttrss_user_entries.ref_id = ttrss_entries.id
52 AND owner_uid = '$owner_uid') AS unread
55 ttrss_feeds.owner_uid = '$owner_uid'
56 ORDER BY $order_by $limit_qpart");
58 if (!$offset) print '<ul id="home" title="'.__('Home').'" selected="true"
59 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
62 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
66 while ($line = db_fetch_assoc($result)) {
68 $unread = $line["unread"];
70 // $unread = rand(0, 100);
73 $line["title"] = $line["title"] . " ($unread)";
79 if (mobile_feed_has_icon($id)) {
80 $icon_url = "../".ICONS_URL
."/$id.ico";
82 $icon_url = "../images/blank_icon.gif";
85 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
86 print "<li class='$class'><a href='feed.php?id=$id'>" .
87 "<img class='tinyIcon' src='$icon_url'/>".
88 $line["title"] . "</a></li>";
94 /* $next_offset = $offset + $num_feeds;
96 print "<li><a href=\"home.php?skip=$next_offset\"
97 target=\"_replace\">Show more feeds...</a></li>"; */
99 if (!$offset) print "</ul>";
103 function render_category($link, $cat_id, $offset) {
104 $owner_uid = $_SESSION["uid"];
109 $cat_query = "cat_id = '$cat_id'";
111 $cat_query = "cat_id IS NULL";
114 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
115 $order_by = "unread DESC, title";
120 $result = db_query($link, "SELECT id,
122 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
123 WHERE feed_id = ttrss_feeds.id AND unread = true
124 AND ttrss_user_entries.ref_id = ttrss_entries.id
125 AND owner_uid = '$owner_uid') as unread
128 ttrss_feeds.owner_uid = '$owner_uid' AND
130 ORDER BY $order_by");
132 $title = getCategoryTitle($link, $cat_id);
134 print "<ul id='cat-$cat_id' title='$title' myBackLabel='".__("Home")."'
135 myBackHref='home.php'>";
137 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
139 while ($line = db_fetch_assoc($result)) {
141 $unread = $line["unread"];
143 // $unread = rand(0, 100);
146 $line["title"] = $line["title"] . " ($unread)";
152 if (mobile_feed_has_icon($id)) {
153 $icon_url = "../".ICONS_URL
."/$id.ico";
155 $icon_url = "../images/blank_icon.gif";
158 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
159 print "<li class='$class'><a href='feed.php?id=$id&cat=$cat_id'>" .
160 "<img class='tinyIcon' src='$icon_url'/>".
161 $line["title"] . "</a></li>";
166 } else if ($cat_id == -1) {
168 $title = __('Special');
170 print "<ul id='cat--1' title='$title' myBackLabel='".__("Home")."'
171 myBackHref='home.php'>";
173 foreach (array(-4, -3, -1, -2, 0) as $id) {
174 $title = getFeedTitle($link, $id);
175 $unread = getFeedUnread($link, $id, false);
176 $icon = getFeedIcon($id);
179 $title = $title . " ($unread)";
185 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
186 print "<li class='$class'>
187 <a href='feed.php?id=$id&cat=-1'>
188 <img class='tinyIcon' src='../$icon'/>$title</a></li>";
193 } else if ($cat_id == -2) {
195 $title = __('Labels');
197 print "<ul id='cat--2' title='$title' myBackLabel='".__("Home")."'
198 myBackHref='home.php'>";
200 $result = db_query($link, "SELECT id, caption FROM ttrss_labels2
201 WHERE owner_uid = '$owner_uid'");
203 $label_data = array();
205 while ($line = db_fetch_assoc($result)) {
207 $id = -$line["id"] - 11;
209 $unread = getFeedUnread($link, $id);
210 $title = $line["caption"];
213 $title = $title . " ($unread)";
219 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
220 print "<li class='$class'>
221 <a href='feed.php?id=$id&cat=-2'>$title</a></li>";
228 function render_categories_list($link) {
229 $owner_uid = $_SESSION["uid"];
231 $cat_browse = mobile_get_pref($link, "BROWSE_CATS");
233 print '<ul id="home" title="'.__('Home').'" selected="true"
234 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
236 // print "<li><a href='#searchForm'>Search...</a></li>";
238 foreach (array(-1, -2) as $id) {
239 $title = getCategoryTitle($link, $id);
240 $unread = getFeedUnread($link, $id, true);
242 $title = $title . " ($unread)";
249 print "<li class='$class'><a href='cat.php?id=$id'>$title</a></li>";
251 print "<li class='$class'><a href='feed.php?id=$id&is_cat=true'>$title</a></li>";
254 $result = db_query($link, "SELECT
255 ttrss_feed_categories.id,
256 ttrss_feed_categories.title,
257 COUNT(ttrss_feeds.id) AS num_feeds
258 FROM ttrss_feed_categories, ttrss_feeds
259 WHERE ttrss_feed_categories.owner_uid = $owner_uid
260 AND ttrss_feed_categories.id = cat_id
261 GROUP BY ttrss_feed_categories.id,
262 ttrss_feed_categories.title
263 ORDER BY ttrss_feed_categories.title");
265 while ($line = db_fetch_assoc($result)) {
267 if ($line["num_feeds"] > 0) {
269 $unread = getFeedUnread($link, $line["id"], true);
273 $line["title"] = $line["title"] . " ($unread)";
279 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
282 print "<li class='$class'><a href='cat.php?id=$id'>" .
283 $line["title"] . "</a></li>";
285 print "<li class='$class'><a href='feed.php?id=$id&is_cat=true'>".
286 $line["title"] . "</a></li>";
292 $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE
293 cat_id IS NULL and owner_uid = '$owner_uid'");
295 $num_feeds = db_fetch_result($result, 0, "nf");
297 if ($num_feeds > 0) {
298 $unread = getFeedUnread($link, 0, true);
299 $title = "Uncategorized";
302 $title = "$title ($unread)";
308 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
310 print "<li class='$class'><a href='cat.php?id=0'>$title</a></li>";
312 print "<li class='$class'><a href='feed.php?id=0&is_cat=true'>$title</a></li>";
320 function render_headlines_list($link, $feed_id, $cat_id, $offset, $search,
326 $view_mode = 'adaptive';
329 $search_mode = 'this_feed';
336 $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
337 $view_mode, $is_cat, $search, $search_mode, $match_on, false, $offset);
339 $result = $qfh_ret[0];
340 $feed_title = $qfh_ret[1];
344 print "<form id=\"searchForm-$feed_id-$cat_id\" class=\"dialog\" method=\"POST\"
347 <input type=\"hidden\" name=\"id\" value=\"$feed_id\">
348 <input type=\"hidden\" name=\"cat\" value=\"$cat_id\">
352 <a class=\"button leftButton\" type=\"cancel\">Cancel</a>
353 <a class=\"button blueButton\" type=\"submit\">Search</a>
355 <label>Search:</label>
356 <input id=\"search\" type=\"text\" name=\"search\"/>
361 $cat_title = getCategoryTitle($link, $cat_id);
363 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
364 myBackLabel='$cat_title' myBackHref='cat.php?id=$cat_id'>";
366 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
367 myBackLabel='".__("Home")."' myBackHref='home.php'>";
370 print "<li><a href='#searchForm-$feed_id-$cat_id'>Search...</a></li>";
375 while ($line = db_fetch_assoc($result)) {
377 $real_feed_id = $line["feed_id"];
379 if (sql_bool_to_bool($line["unread"])) {
385 if (mobile_feed_has_icon($real_feed_id)) {
386 $icon_url = "../".ICONS_URL
."/$real_feed_id.ico";
388 $icon_url = "../images/blank_icon.gif";
391 print "<li class='$class'><a href='article.php?id=$id&feed=$feed_id&cat=$cat_id'>
392 <img class='tinyIcon' src='$icon_url'>";
393 print $line["title"];
400 if ($num_headlines == 0 && $search) {
401 $articles_url = "feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset";
403 print "<li><a href=\"$articles_url\">" . __("Nothing found (click to reload feed).") . "</a></li>";
407 // print "<a target='_replace' href='feed.php?id=$feed_id&cat=$cat_id&skip=0'>Next $limit articles...</a>";
409 $next_offset = $offset +
$num_headlines;
410 $num_unread = getFeedUnread($link, $feed_id, $is_cat);
412 /* FIXME needs normal implementation */
414 if ($num_headlines > 0 && ($num_unread == 0 ||
$num_unread > $next_offset)) {
416 $articles_url = "feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset".
419 print "<li><a href=\"$articles_url\"
420 target=\"_replace\">Get more articles...</a></li>";
423 if (!$offset) print "</ul>";
427 function render_article($link, $id, $feed_id, $cat_id) {
429 $query = "SELECT title,link,content,feed_id,comments,int_id,
430 marked,unread,published,
431 ".SUBSTRING_FOR_DATE
."(updated,1,16) as updated,
433 FROM ttrss_entries,ttrss_user_entries
434 WHERE id = '$id' AND ref_id = id AND owner_uid = " .
437 $result = db_query($link, $query);
439 if (db_num_rows($result) != 0) {
441 $line = db_fetch_assoc($result);
443 $tmp_result = db_query($link, "UPDATE ttrss_user_entries
444 SET unread = false,last_read = NOW()
446 AND owner_uid = " . $_SESSION["uid"]);
448 $updated_fmt = make_local_datetime($link, $line['updated'], false);
450 $title = $line["title"];
451 $article_link = $line["link"];
453 $feed_title = getFeedTitle($link, $feed_id, false);
455 print "<div class=\"panel\" id=\"article-$id\" title=\"$title\"
457 myBackLabel='$feed_title' myBackHref='feed.php?id=$feed_id&cat=$cat_id'>";
459 print "<h2><a target='_blank' href='$article_link'>$title</a></h2>";
463 /* print "<div class=\"row\">";
464 print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>";
467 $is_starred = (sql_bool_to_bool($line["marked"])) ?
"true" : "false";
468 $is_published = (sql_bool_to_bool($line["published"])) ?
"true" : "false";
470 print "<div class=\"row\">";
471 print "<label id='updated'>Updated:</label>";
472 print "<input enabled='false' name='updated' disabled value='$updated_fmt'/>";
477 $content = sanitize_rss($link, $line["content"]);
478 $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content);
480 if (!mobile_get_pref($link, "SHOW_IMAGES")) {
481 $content = preg_replace('/<img[^>]+>/is', '', $content);
484 print "<p>$content</p>";
486 print "<div class='nav'>
487 <label>Navigation</label>
488 <div class='button left' onclick='goPrev($id, $feed_id, this)'>Prev</div>
489 <div class='button right' onclick='goNext($id, $feed_id, this)'>Next</div>
494 print "<div class=\"row\">
495 <label>Starred</label>
496 <div class=\"toggle\" onclick=\"toggleMarked($id, this)\" toggled=\"$is_starred\"><span class=\"thumb\"></span><span class=\"toggleOn\">ON</span><span class=\"toggleOff\">OFF</span></div>
499 print "<div class=\"row\">
500 <label>Published</label>
501 <div class=\"toggle\" onclick=\"togglePublished($id, this)\" toggled=\"$is_published\"><span class=\"thumb\"></span><span class=\"toggleOn\">ON</span><span class=\"toggleOff\">OFF</span></div>