]> git.wh0rd.org - tt-rss.git/blame - mobile/functions.php
implement per-user timezone support; store dates in UTC internally (closes #254)
[tt-rss.git] / mobile / functions.php
CommitLineData
e9e95dae 1<?php
3dd46f19 2 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
0d3adafe 3
f0a0c1ff
AD
4 /* TODO replace with interface to db-prefs */
5
6 function mobile_pref_toggled($link, $id) {
e9105eb5
AD
7 if (get_pref($link, "_MOBILE_$id"))
8 return "true";
9 else
10 return "";
f0a0c1ff
AD
11 }
12
13 function mobile_get_pref($link, $id) {
e9105eb5
AD
14 //return $_SESSION["mobile-prefs"][$id];
15 return get_pref($link, "_MOBILE_$id");
f0a0c1ff
AD
16 }
17
18 function mobile_set_pref($link, $id, $value) {
e9105eb5
AD
19 //$_SESSION["mobile-prefs"][$id] = $value;
20 return set_pref($link, "_MOBILE_$id", $value);
f0a0c1ff
AD
21 }
22
3518718b
AD
23 function mobile_feed_has_icon($id) {
24 $filename = "../".ICONS_DIR."/$id.ico";
42096f52 25
3518718b
AD
26 return file_exists($filename) && filesize($filename) > 0;
27 }
42096f52 28
95004daf 29 function render_flat_feed_list($link, $offset) {
b1bd222c 30 $owner_uid = $_SESSION["uid"];
af88c48a 31 $limit = 0;
95004daf
AD
32
33 if (!$offset) $offset = 0;
b1bd222c 34
f0a0c1ff
AD
35 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
36 $order_by = "unread DESC, title";
37 } else {
38 $order_by = "title";
39 }
40
af88c48a
AD
41 if ($limit > 0) {
42 $limit_qpart = "LIMIT $limit OFFSET $offset";
43 } else {
44 $limit_qpart = "";
45 }
46
b1bd222c
AD
47 $result = db_query($link, "SELECT id,
48 title,
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
af88c48a 52 AND owner_uid = '$owner_uid') AS unread
b1bd222c
AD
53 FROM ttrss_feeds
54 WHERE
b1bd222c
AD
55 ttrss_feeds.owner_uid = '$owner_uid' AND
56 parent_feed IS NULL
af88c48a 57 ORDER BY $order_by $limit_qpart");
b1bd222c 58
95004daf 59 if (!$offset) print '<ul id="home" title="'.__('Home').'" selected="true"
9ab798a5 60 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
b1bd222c 61
af88c48a 62
b1bd222c 63 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
95004daf
AD
64
65 $num_feeds = 0;
66
b1bd222c
AD
67 while ($line = db_fetch_assoc($result)) {
68 $id = $line["id"];
69 $unread = $line["unread"];
70
71 // $unread = rand(0, 100);
72
73 if ($unread > 0) {
74 $line["title"] = $line["title"] . " ($unread)";
75 $class = '';
76 } else {
77 $class = 'oldItem';
78 }
79
80 if (mobile_feed_has_icon($id)) {
81 $icon_url = "../".ICONS_URL."/$id.ico";
82 } else {
83 $icon_url = "../images/blank_icon.gif";
84 }
f0a0c1ff
AD
85
86 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
87 print "<li class='$class'><a href='feed.php?id=$id'>" .
88 "<img class='tinyIcon' src='$icon_url'/>".
89 $line["title"] . "</a></li>";
90 }
af88c48a
AD
91
92 ++$num_feeds;
b1bd222c 93 }
b1bd222c 94
af88c48a 95/* $next_offset = $offset + $num_feeds;
95004daf
AD
96
97 print "<li><a href=\"home.php?skip=$next_offset\"
af88c48a 98 target=\"_replace\">Show more feeds...</a></li>"; */
b1bd222c 99
95004daf 100 if (!$offset) print "</ul>";
b1bd222c
AD
101
102 }
103
3518718b
AD
104 function render_category($link, $cat_id) {
105 $owner_uid = $_SESSION["uid"];
42096f52 106
e2b7a855 107 if ($cat_id >= 0) {
85233b8e 108
e2b7a855
AD
109 if ($cat_id != 0) {
110 $cat_query = "cat_id = '$cat_id'";
3518718b 111 } else {
e2b7a855 112 $cat_query = "cat_id IS NULL";
0d3adafe 113 }
f0a0c1ff
AD
114
115 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
116 $order_by = "unread DESC, title";
117 } else {
118 $order_by = "title";
119 }
120
e2b7a855
AD
121 $result = db_query($link, "SELECT id,
122 title,
123 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
124 WHERE feed_id = ttrss_feeds.id AND unread = true
125 AND ttrss_user_entries.ref_id = ttrss_entries.id
126 AND owner_uid = '$owner_uid') as unread
127 FROM ttrss_feeds
128 WHERE
e2b7a855
AD
129 ttrss_feeds.owner_uid = '$owner_uid' AND
130 parent_feed IS NULL AND
131 $cat_query
f0a0c1ff 132 ORDER BY $order_by");
e2b7a855
AD
133
134 $title = getCategoryTitle($link, $cat_id);
135
9ab798a5 136 print "<ul id='cat-$cat_id' title='$title' myBackLabel='".__("Home")."'
bf974b02 137 myBackHref='home.php'>";
e2b7a855
AD
138
139 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
140
141 while ($line = db_fetch_assoc($result)) {
142 $id = $line["id"];
143 $unread = $line["unread"];
3e94601e 144
e2b7a855
AD
145 // $unread = rand(0, 100);
146
147 if ($unread > 0) {
148 $line["title"] = $line["title"] . " ($unread)";
149 $class = '';
150 } else {
151 $class = 'oldItem';
152 }
153
154 if (mobile_feed_has_icon($id)) {
155 $icon_url = "../".ICONS_URL."/$id.ico";
156 } else {
157 $icon_url = "../images/blank_icon.gif";
158 }
f0a0c1ff
AD
159
160 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
161 print "<li class='$class'><a href='feed.php?id=$id&cat=$cat_id'>" .
162 "<img class='tinyIcon' src='$icon_url'/>".
163 $line["title"] . "</a></li>";
164 }
0d3adafe 165 }
e2b7a855
AD
166
167 print "</ul>";
168 } else if ($cat_id == -1) {
169
17fd15be
AD
170 $title = __('Special');
171
9ab798a5
AD
172 print "<ul id='cat--1' title='$title' myBackLabel='".__("Home")."'
173 myBackHref='home.php'>";
e2b7a855 174
87e3d2dd 175 foreach (array(-4, -3, -1, -2, 0) as $id) {
e2b7a855
AD
176 $title = getFeedTitle($link, $id);
177 $unread = getFeedUnread($link, $id, false);
af88c48a 178 $icon = getFeedIcon($id);
e2b7a855
AD
179
180 if ($unread > 0) {
181 $title = $title . " ($unread)";
182 $class = '';
183 } else {
184 $class = 'oldItem';
eead4d26 185 }
8e3f7217 186
f0a0c1ff
AD
187 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
188 print "<li class='$class'>
af88c48a
AD
189 <a href='feed.php?id=$id&cat=-1'>
190 <img class='tinyIcon' src='../$icon'/>$title</a></li>";
f0a0c1ff 191 }
e2b7a855 192 }
8e3f7217 193
17fd15be
AD
194 print "</ul>";
195 } else if ($cat_id == -2) {
196
197 $title = __('Labels');
198
9ab798a5
AD
199 print "<ul id='cat--2' title='$title' myBackLabel='".__("Home")."'
200 myBackHref='home.php'>";
17fd15be
AD
201
202 $result = db_query($link, "SELECT id, caption FROM ttrss_labels2
203 WHERE owner_uid = '$owner_uid'");
204
205 $label_data = array();
206
207 while ($line = db_fetch_assoc($result)) {
208
209 $id = -$line["id"] - 11;
210
211 $unread = getFeedUnread($link, $id);
212 $title = $line["caption"];
213
214 if ($unread > 0) {
215 $title = $title . " ($unread)";
216 $class = '';
217 } else {
218 $class = 'oldItem';
219 }
220
f0a0c1ff
AD
221 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
222 print "<li class='$class'>
223 <a href='feed.php?id=$id&cat=-2'>$title</a></li>";
224 }
17fd15be 225 }
e2b7a855
AD
226 print "</ul>";
227 }
0d3adafe
AD
228 }
229
3518718b
AD
230 function render_categories_list($link) {
231 $owner_uid = $_SESSION["uid"];
3585a3c5 232
9ab798a5
AD
233 print '<ul id="home" title="'.__('Home').'" selected="true"
234 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
eead4d26 235
3585a3c5
AD
236
237// print "<li><a href='#searchForm'>Search...</a></li>";
238
3518718b
AD
239 foreach (array(-1, -2) as $id) {
240 $title = getCategoryTitle($link, $id);
241 $unread = getFeedUnread($link, $id, true);
242 if ($unread > 0) {
243 $title = $title . " ($unread)";
244 $class = '';
eead4d26 245 } else {
3518718b 246 $class = 'oldItem';
c878bc01 247 }
2f468537 248
3518718b 249 print "<li class='$class'><a href='cat.php?id=$id'>$title</a></li>";
2f468537
AD
250 }
251
3518718b
AD
252 $result = db_query($link, "SELECT
253 ttrss_feed_categories.id,
254 ttrss_feed_categories.title,
255 COUNT(ttrss_feeds.id) AS num_feeds
256 FROM ttrss_feed_categories, ttrss_feeds
257 WHERE ttrss_feed_categories.owner_uid = $owner_uid
258 AND ttrss_feed_categories.id = cat_id
3518718b
AD
259 GROUP BY ttrss_feed_categories.id,
260 ttrss_feed_categories.title
261 ORDER BY ttrss_feed_categories.title");
2f468537 262
3518718b 263 while ($line = db_fetch_assoc($result)) {
fc46ab83 264
3518718b 265 if ($line["num_feeds"] > 0) {
2f468537 266
3518718b 267 $unread = getFeedUnread($link, $line["id"], true);
2f468537 268 $id = $line["id"];
510ac75f 269
3518718b
AD
270 if ($unread > 0) {
271 $line["title"] = $line["title"] . " ($unread)";
272 $class = '';
510ac75f 273 } else {
3518718b 274 $class = 'oldItem';
510ac75f 275 }
2f468537 276
f0a0c1ff
AD
277 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
278 print "<li class='$class'><a href='cat.php?id=$id'>" .
279 $line["title"] . "</a></li>";
280 }
2f468537 281 }
2f468537
AD
282 }
283
2f468537 284
3518718b
AD
285 $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE
286 cat_id IS NULL and owner_uid = '$owner_uid'");
42096f52 287
3518718b 288 $num_feeds = db_fetch_result($result, 0, "nf");
42096f52 289
3518718b
AD
290 if ($num_feeds > 0) {
291 $unread = getFeedUnread($link, 0, true);
292 $title = "Uncategorized";
42096f52 293
3518718b
AD
294 if ($unread > 0) {
295 $title = "$title ($unread)";
296 $class = '';
42096f52 297 } else {
3518718b 298 $class = 'oldItem';
42096f52
AD
299 }
300
f0a0c1ff
AD
301 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
302 print "<li class='$class'><a href='cat.php?id=0'>$title</a></li>";
303 }
3518718b 304 }
42096f52 305
3518718b
AD
306 print "</ul>";
307 }
24ac6776 308
3585a3c5 309 function render_headlines_list($link, $feed_id, $cat_id, $offset, $search) {
24ac6776 310
3518718b 311 $feed_id = $feed_id;
78d7a965 312 $limit = 15;
3518718b 313 $filter = '';
3e092346 314 $is_cat = false;
3518718b 315 $view_mode = 'adaptive';
d9aad400 316
3585a3c5
AD
317 if ($search) {
318 $search_mode = 'this_feed';
319 $match_on = 'both';
320 } else {
321 $search_mode = '';
322 $match_on = '';
323 }
78d7a965 324
3518718b 325 $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
78d7a965 326 $view_mode, $is_cat, $search, $search_mode, $match_on, false, $offset);
541890fb 327
3518718b
AD
328 $result = $qfh_ret[0];
329 $feed_title = $qfh_ret[1];
42096f52 330
78d7a965 331 if (!$offset) {
3585a3c5 332
cb216e9d 333 print "<form id=\"searchForm-$feed_id-$cat_id\" class=\"dialog\" method=\"POST\"
3585a3c5
AD
334 action=\"feed.php\">
335
336 <input type=\"hidden\" name=\"id\" value=\"$feed_id\">
337 <input type=\"hidden\" name=\"cat\" value=\"$cat_id\">
338
339 <fieldset>
cb216e9d 340 <h1>Search</h1>
3585a3c5
AD
341 <a class=\"button leftButton\" type=\"cancel\">Cancel</a>
342 <a class=\"button blueButton\" type=\"submit\">Search</a>
343
344 <label>Search:</label>
345 <input id=\"search\" type=\"text\" name=\"search\"/>
346 </fieldset>
347 </form>";
348
78d7a965
AD
349 if ($cat_id) {
350 $cat_title = getCategoryTitle($link, $cat_id);
3e092346 351
78d7a965
AD
352 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
353 myBackLabel='$cat_title' myBackHref='cat.php?id=$cat_id'>";
354 } else {
355 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
356 myBackLabel='".__("Home")."' myBackHref='home.php'>";
357 }
3585a3c5 358
cb216e9d 359 print "<li><a href='#searchForm-$feed_id-$cat_id'>Search...</a></li>";
b1bd222c 360 }
24ac6776 361
78d7a965
AD
362 $num_headlines = 0;
363
3518718b
AD
364 while ($line = db_fetch_assoc($result)) {
365 $id = $line["id"];
3e94601e 366 $real_feed_id = $line["feed_id"];
f70f7e28 367
3518718b
AD
368 if (sql_bool_to_bool($line["unread"])) {
369 $class = '';
f70f7e28 370 } else {
3518718b 371 $class = 'oldItem';
f70f7e28
AD
372 }
373
3e94601e
AD
374 if (mobile_feed_has_icon($real_feed_id)) {
375 $icon_url = "../".ICONS_URL."/$real_feed_id.ico";
376 } else {
377 $icon_url = "../images/blank_icon.gif";
378 }
379
380 print "<li class='$class'><a href='article.php?id=$id&feed=$feed_id&cat=$cat_id'>
381 <img class='tinyIcon' src='$icon_url'>";
3518718b
AD
382 print $line["title"];
383 print "</a></li>";
4a596be6 384
78d7a965
AD
385 ++$num_headlines;
386
42096f52
AD
387 }
388
3585a3c5
AD
389 if ($num_headlines == 0 && $search) {
390 $articles_url = "feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset";
391
392 print "<li><a href=\"$articles_url\">" . __("Nothing found (click to reload feed).") . "</a></li>";
393
394 }
395
78d7a965
AD
396// print "<a target='_replace' href='feed.php?id=$feed_id&cat=$cat_id&skip=0'>Next $limit articles...</a>";
397
398 $next_offset = $offset + $num_headlines;
399 $num_unread = getFeedUnread($link, $feed_id, $is_cat);
400
401 /* FIXME needs normal implementation */
402
3585a3c5
AD
403 if ($num_headlines > 0 && ($num_unread == 0 || $num_unread > $next_offset)) {
404
405 $articles_url = "feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset".
406 "&search=$search";
407
408 print "<li><a href=\"$articles_url\"
78d7a965
AD
409 target=\"_replace\">Get more articles...</a></li>";
410 }
411
412 if (!$offset) print "</ul>";
3518718b 413
42096f52
AD
414 }
415
3e092346 416 function render_article($link, $id, $feed_id, $cat_id) {
0809065e 417
3518718b
AD
418 $query = "SELECT title,link,content,feed_id,comments,int_id,
419 marked,unread,published,
420 ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
421 author
422 FROM ttrss_entries,ttrss_user_entries
423 WHERE id = '$id' AND ref_id = id AND owner_uid = " .
424 $_SESSION["uid"] ;
0809065e 425
3518718b 426 $result = db_query($link, $query);
0809065e 427
3e092346 428 if (db_num_rows($result) != 0) {
0809065e 429
3e092346 430 $line = db_fetch_assoc($result);
0809065e 431
3e092346
AD
432 $tmp_result = db_query($link, "UPDATE ttrss_user_entries
433 SET unread = false,last_read = NOW()
434 WHERE ref_id = '$id'
435 AND owner_uid = " . $_SESSION["uid"]);
0809065e 436
324944f3
AD
437 $updated_fmt = make_local_datetime($link, $line['updated'], false);
438
3e092346
AD
439 $title = $line["title"];
440 $article_link = $line["link"];
441
442 $feed_title = getFeedTitle($link, $feed_id, false);
443
444 print "<div class=\"panel\" id=\"article-$id\" title=\"$title\"
445 selected=\"true\"
446 myBackLabel='$feed_title' myBackHref='feed.php?id=$feed_id&cat=$cat_id'>";
447
17cd1097 448 print "<h2><a target='_blank' href='$article_link'>$title</a></h2>";
3e092346
AD
449
450 print "<fieldset>";
451
bf974b02 452/* print "<div class=\"row\">";
3e092346 453 print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>";
bf974b02 454 print "</div>"; */
3e092346
AD
455
456 $is_starred = (sql_bool_to_bool($line["marked"])) ? "true" : "false";
457 $is_published = (sql_bool_to_bool($line["published"])) ? "true" : "false";
458
3e092346
AD
459 print "<div class=\"row\">";
460 print "<label id='updated'>Updated:</label>";
461 print "<input enabled='false' name='updated' disabled value='$updated_fmt'/>";
462 print "</div>";
463
464 print "</fieldset>";
3bac78a0
AD
465
466 $content = sanitize_rss($link, $line["content"]);
467 $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content);
468
f0a0c1ff
AD
469 if (!mobile_get_pref($link, "SHOW_IMAGES")) {
470 $content = preg_replace('/<img[^>]+>/is', '', $content);
471 }
472
706fe949 473 print "<p>$content</p>";
6101b0e1 474
a6d56d81
AD
475 print "<div class='nav'>
476 <label>Navigation</label>
477 <div class='button left' onclick='goPrev($id, $feed_id, this)'>Prev</div>
478 <div class='button right' onclick='goNext($id, $feed_id, this)'>Next</div>
479 </div>";
480
6101b0e1
AD
481 print "<fieldset>";
482
483 print "<div class=\"row\">
484 <label>Starred</label>
485 <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>
486 </div>";
3e092346 487
6101b0e1
AD
488 print "<div class=\"row\">
489 <label>Published</label>
490 <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>
491 </div>";
492
493 print "</fieldset>";
494
3e092346 495 print "</div>";
f70f7e28 496
3e092346 497 }
4a596be6 498 }
0d3adafe 499?>