]> git.wh0rd.org - tt-rss.git/blob - mobile/functions.php
daemon2: properly abort stuck children
[tt-rss.git] / mobile / functions.php
1 <?php
2 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
3
4 /* TODO replace with interface to db-prefs */
5
6 function mobile_pref_toggled($link, $id) {
7 if (get_pref($link, "_MOBILE_$id"))
8 return "true";
9 else
10 return "";
11 }
12
13 function mobile_get_pref($link, $id) {
14 //return $_SESSION["mobile-prefs"][$id];
15 return get_pref($link, "_MOBILE_$id");
16 }
17
18 function mobile_set_pref($link, $id, $value) {
19 //$_SESSION["mobile-prefs"][$id] = $value;
20 return set_pref($link, "_MOBILE_$id", $value);
21 }
22
23 function mobile_feed_has_icon($id) {
24 $filename = "../".ICONS_DIR."/$id.ico";
25
26 return file_exists($filename) && filesize($filename) > 0;
27 }
28
29 function render_flat_feed_list($link, $offset) {
30 $owner_uid = $_SESSION["uid"];
31 $limit = 0;
32
33 if (!$offset) $offset = 0;
34
35 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
36 $order_by = "unread DESC, title";
37 } else {
38 $order_by = "title";
39 }
40
41 if ($limit > 0) {
42 $limit_qpart = "LIMIT $limit OFFSET $offset";
43 } else {
44 $limit_qpart = "";
45 }
46
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
52 AND owner_uid = '$owner_uid') AS unread
53 FROM ttrss_feeds
54 WHERE
55 ttrss_feeds.owner_uid = '$owner_uid' AND
56 parent_feed IS NULL
57 ORDER BY $order_by $limit_qpart");
58
59 if (!$offset) print '<ul id="home" title="'.__('Home').'" selected="true"
60 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
61
62
63 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
64
65 $num_feeds = 0;
66
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 }
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 }
91
92 ++$num_feeds;
93 }
94
95 /* $next_offset = $offset + $num_feeds;
96
97 print "<li><a href=\"home.php?skip=$next_offset\"
98 target=\"_replace\">Show more feeds...</a></li>"; */
99
100 if (!$offset) print "</ul>";
101
102 }
103
104 function render_category($link, $cat_id) {
105 $owner_uid = $_SESSION["uid"];
106
107 if ($cat_id >= 0) {
108
109 if ($cat_id != 0) {
110 $cat_query = "cat_id = '$cat_id'";
111 } else {
112 $cat_query = "cat_id IS NULL";
113 }
114
115 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
116 $order_by = "unread DESC, title";
117 } else {
118 $order_by = "title";
119 }
120
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
129 ttrss_feeds.owner_uid = '$owner_uid' AND
130 parent_feed IS NULL AND
131 $cat_query
132 ORDER BY $order_by");
133
134 $title = getCategoryTitle($link, $cat_id);
135
136 print "<ul id='cat-$cat_id' title='$title' myBackLabel='".__("Home")."'
137 myBackHref='home.php'>";
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"];
144
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 }
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 }
165 }
166
167 print "</ul>";
168 } else if ($cat_id == -1) {
169
170 $title = __('Special');
171
172 print "<ul id='cat--1' title='$title' myBackLabel='".__("Home")."'
173 myBackHref='home.php'>";
174
175 foreach (array(-4, -3, -1, -2, 0) as $id) {
176 $title = getFeedTitle($link, $id);
177 $unread = getFeedUnread($link, $id, false);
178 $icon = getFeedIcon($id);
179
180 if ($unread > 0) {
181 $title = $title . " ($unread)";
182 $class = '';
183 } else {
184 $class = 'oldItem';
185 }
186
187 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
188 print "<li class='$class'>
189 <a href='feed.php?id=$id&cat=-1'>
190 <img class='tinyIcon' src='../$icon'/>$title</a></li>";
191 }
192 }
193
194 print "</ul>";
195 } else if ($cat_id == -2) {
196
197 $title = __('Labels');
198
199 print "<ul id='cat--2' title='$title' myBackLabel='".__("Home")."'
200 myBackHref='home.php'>";
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
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 }
225 }
226 print "</ul>";
227 }
228 }
229
230 function render_categories_list($link) {
231 $owner_uid = $_SESSION["uid"];
232
233 print '<ul id="home" title="'.__('Home').'" selected="true"
234 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
235
236
237 // print "<li><a href='#searchForm'>Search...</a></li>";
238
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 = '';
245 } else {
246 $class = 'oldItem';
247 }
248
249 print "<li class='$class'><a href='cat.php?id=$id'>$title</a></li>";
250 }
251
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
259 GROUP BY ttrss_feed_categories.id,
260 ttrss_feed_categories.title
261 ORDER BY ttrss_feed_categories.title");
262
263 while ($line = db_fetch_assoc($result)) {
264
265 if ($line["num_feeds"] > 0) {
266
267 $unread = getFeedUnread($link, $line["id"], true);
268 $id = $line["id"];
269
270 if ($unread > 0) {
271 $line["title"] = $line["title"] . " ($unread)";
272 $class = '';
273 } else {
274 $class = 'oldItem';
275 }
276
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 }
281 }
282 }
283
284
285 $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE
286 cat_id IS NULL and owner_uid = '$owner_uid'");
287
288 $num_feeds = db_fetch_result($result, 0, "nf");
289
290 if ($num_feeds > 0) {
291 $unread = getFeedUnread($link, 0, true);
292 $title = "Uncategorized";
293
294 if ($unread > 0) {
295 $title = "$title ($unread)";
296 $class = '';
297 } else {
298 $class = 'oldItem';
299 }
300
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 }
304 }
305
306 print "</ul>";
307 }
308
309 function render_headlines_list($link, $feed_id, $cat_id, $offset, $search) {
310
311 $feed_id = $feed_id;
312 $limit = 15;
313 $filter = '';
314 $is_cat = false;
315 $view_mode = 'adaptive';
316
317 if ($search) {
318 $search_mode = 'this_feed';
319 $match_on = 'both';
320 } else {
321 $search_mode = '';
322 $match_on = '';
323 }
324
325 $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
326 $view_mode, $is_cat, $search, $search_mode, $match_on, false, $offset);
327
328 $result = $qfh_ret[0];
329 $feed_title = $qfh_ret[1];
330
331 if (!$offset) {
332
333 print "<form id=\"searchForm-$feed_id-$cat_id\" class=\"dialog\" method=\"POST\"
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>
340 <h1>Search</h1>
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
349 if ($cat_id) {
350 $cat_title = getCategoryTitle($link, $cat_id);
351
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 }
358
359 print "<li><a href='#searchForm-$feed_id-$cat_id'>Search...</a></li>";
360 }
361
362 $num_headlines = 0;
363
364 while ($line = db_fetch_assoc($result)) {
365 $id = $line["id"];
366 $real_feed_id = $line["feed_id"];
367
368 if (sql_bool_to_bool($line["unread"])) {
369 $class = '';
370 } else {
371 $class = 'oldItem';
372 }
373
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'>";
382 print $line["title"];
383 print "</a></li>";
384
385 ++$num_headlines;
386
387 }
388
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
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
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\"
409 target=\"_replace\">Get more articles...</a></li>";
410 }
411
412 if (!$offset) print "</ul>";
413
414 }
415
416 function render_article($link, $id, $feed_id, $cat_id) {
417
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"] ;
425
426 $result = db_query($link, $query);
427
428 if (db_num_rows($result) != 0) {
429
430 $line = db_fetch_assoc($result);
431
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"]);
436
437 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
438 $updated_fmt = smart_date_time(strtotime($line["updated"]));
439 } else {
440 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
441 $updated_fmt = date($short_date, strtotime($line["updated"]));
442 }
443
444 $title = $line["title"];
445 $article_link = $line["link"];
446
447 $feed_title = getFeedTitle($link, $feed_id, false);
448
449 print "<div class=\"panel\" id=\"article-$id\" title=\"$title\"
450 selected=\"true\"
451 myBackLabel='$feed_title' myBackHref='feed.php?id=$feed_id&cat=$cat_id'>";
452
453 print "<h2><a target='_blank' href='$article_link'>$title</a></h2>";
454
455 print "<fieldset>";
456
457 /* print "<div class=\"row\">";
458 print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>";
459 print "</div>"; */
460
461 $is_starred = (sql_bool_to_bool($line["marked"])) ? "true" : "false";
462 $is_published = (sql_bool_to_bool($line["published"])) ? "true" : "false";
463
464 print "<div class=\"row\">";
465 print "<label id='updated'>Updated:</label>";
466 print "<input enabled='false' name='updated' disabled value='$updated_fmt'/>";
467 print "</div>";
468
469 print "</fieldset>";
470
471 $content = sanitize_rss($link, $line["content"]);
472 $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content);
473
474 if (!mobile_get_pref($link, "SHOW_IMAGES")) {
475 $content = preg_replace('/<img[^>]+>/is', '', $content);
476 }
477
478 print "<p>$content</p>";
479
480 print "<div class='nav'>
481 <label>Navigation</label>
482 <div class='button left' onclick='goPrev($id, $feed_id, this)'>Prev</div>
483 <div class='button right' onclick='goNext($id, $feed_id, this)'>Next</div>
484 </div>";
485
486 print "<fieldset>";
487
488 print "<div class=\"row\">
489 <label>Starred</label>
490 <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>
491 </div>";
492
493 print "<div class=\"row\">
494 <label>Published</label>
495 <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>
496 </div>";
497
498 print "</fieldset>";
499
500 print "</div>";
501
502 }
503 }
504 ?>