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