]> git.wh0rd.org - tt-rss.git/blob - mobile/functions.php
mobile: fix page to page navigation
[tt-rss.git] / mobile / functions.php
1 <?php
2 define('MOBILE_FEEDLIST_ENABLE_ICONS', false);
3 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
4
5 function mobile_feed_has_icon($id) {
6 $filename = "../".ICONS_DIR."/$id.ico";
7
8 return file_exists($filename) && filesize($filename) > 0;
9 }
10
11 function render_category($link, $cat_id) {
12 $owner_uid = $_SESSION["uid"];
13
14 if ($cat_id != 0) {
15 $cat_query = "cat_id = '$cat_id'";
16 } else {
17 $cat_query = "cat_id IS NULL";
18 }
19
20 $result = db_query($link, "SELECT id,
21 title,
22 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
23 WHERE feed_id = ttrss_feeds.id AND unread = true
24 AND ttrss_user_entries.ref_id = ttrss_entries.id
25 AND owner_uid = '$owner_uid') as unread
26 FROM ttrss_feeds
27 WHERE
28 ttrss_feeds.hidden = false AND
29 ttrss_feeds.owner_uid = '$owner_uid' AND
30 parent_feed IS NULL AND
31 $cat_query
32 ORDER BY unread DESC,title");
33
34 $title = getCategoryTitle($link, $cat_id);
35
36 print "<ul id='cat-$cat_id' title='$title' myBackLabel='Feeds'
37 myBackHref='index.php' myBackTarget='_self'>";
38
39 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
40
41 while ($line = db_fetch_assoc($result)) {
42 $id = $line["id"];
43 $unread = $line["unread"];
44
45 // $unread = rand(0, 100);
46
47 if ($unread > 0) {
48 $line["title"] = $line["title"] . " ($unread)";
49 $class = '';
50 } else {
51 $class = 'oldItem';
52 }
53
54 if (mobile_feed_has_icon($id)) {
55 $icon_url = "../".ICONS_URL."/$id.ico";
56 } else {
57 $icon_url = "../images/blank_icon.gif";
58 }
59
60 print "<li class='$class'><a href='feed.php?id=$id&cat=$cat_id'>" .
61 "<img class='tinyIcon' src='$icon_url'/>".
62 $line["title"] . "</a></li>";
63 }
64
65 print "</ul>";
66
67 /* print "<ul id='cat--1' title='$title'>";
68
69 foreach (array(-4, -1,-2,-3) as $id) {
70 $title = getFeedTitle($link, $id);
71 $unread = getFeedUnread($link, $id, false);
72
73 if ($unread > 0) {
74 $title = $title . " ($unread)";
75 $class = '';
76 } else {
77 $class = 'oldItem';
78 }
79
80 print "<li class='$class'><a href='feed.php?id=$id'>$title</a></li>";
81 }
82
83 print "</ul>"; */
84
85 }
86
87 function render_categories_list($link) {
88 $owner_uid = $_SESSION["uid"];
89
90
91 print '<ul id="home" title="Feeds" selected="true">';
92
93 foreach (array(-1, -2) as $id) {
94 $title = getCategoryTitle($link, $id);
95 $unread = getFeedUnread($link, $id, true);
96 if ($unread > 0) {
97 $title = $title . " ($unread)";
98 $class = '';
99 } else {
100 $class = 'oldItem';
101 }
102
103 print "<li class='$class'><a href='cat.php?id=$id'>$title</a></li>";
104 }
105
106 $result = db_query($link, "SELECT
107 ttrss_feed_categories.id,
108 ttrss_feed_categories.title,
109 COUNT(ttrss_feeds.id) AS num_feeds
110 FROM ttrss_feed_categories, ttrss_feeds
111 WHERE ttrss_feed_categories.owner_uid = $owner_uid
112 AND ttrss_feed_categories.id = cat_id
113 AND hidden = false
114 GROUP BY ttrss_feed_categories.id,
115 ttrss_feed_categories.title
116 ORDER BY ttrss_feed_categories.title");
117
118 $cat_ids = array();
119
120 while ($line = db_fetch_assoc($result)) {
121
122 if ($line["num_feeds"] > 0) {
123
124 $unread = getFeedUnread($link, $line["id"], true);
125 $id = $line["id"];
126
127 if ($unread > 0) {
128 $line["title"] = $line["title"] . " ($unread)";
129 $class = '';
130 } else {
131 $class = 'oldItem';
132 }
133
134
135 print "<li class='$class'><a href='cat.php?id=$id'>" .
136 $line["title"] . "</a></li>";
137
138 array_push($cat_ids, $id);
139
140 }
141 }
142
143
144 $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE
145 cat_id IS NULL and owner_uid = '$owner_uid'");
146
147 $num_feeds = db_fetch_result($result, 0, "nf");
148
149 if ($num_feeds > 0) {
150 $unread = getFeedUnread($link, 0, true);
151 $title = "Uncategorized";
152
153 if ($unread > 0) {
154 $title = "$title ($unread)";
155 $class = '';
156 } else {
157 $class = 'oldItem';
158 }
159
160 array_push($cat_ids, 0);
161
162 print "<li class='$class'><a href='cat.php?id=0'>$title</a></li>";
163 }
164
165 print "</ul>";
166 }
167
168 function render_headlines_list($link, $feed_id, $cat_id) {
169
170 $feed_id = $feed_id;
171 $limit = 30;
172 $filter = '';
173 $is_cat = false;
174 $view_mode = 'adaptive';
175
176 /* do not rely on params below */
177
178 $search = '';
179 $search_mode = '';
180 $match_on = '';
181
182 $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
183 $view_mode, $is_cat, $search, $search_mode, $match_on);
184
185 $result = $qfh_ret[0];
186 $feed_title = $qfh_ret[1];
187
188 $cat_title = getCategoryTitle($link, $cat_id);
189
190 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
191 myBackLabel='$cat_title' myBackHref='cat.php?id=$cat_id'>";
192
193 while ($line = db_fetch_assoc($result)) {
194 $id = $line["id"];
195
196 if (sql_bool_to_bool($line["unread"])) {
197 $class = '';
198 } else {
199 $class = 'oldItem';
200 }
201
202 print "<li class='$class'>
203 <a href='article.php?id=$id&feed=$feed_id&cat=$cat_id'>";
204 print $line["title"];
205 print "</a></li>";
206
207 }
208
209 print "</ul>";
210
211 }
212
213 function render_article($link, $id, $feed_id, $cat_id) {
214
215 $query = "SELECT title,link,content,feed_id,comments,int_id,
216 marked,unread,published,
217 ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
218 author
219 FROM ttrss_entries,ttrss_user_entries
220 WHERE id = '$id' AND ref_id = id AND owner_uid = " .
221 $_SESSION["uid"] ;
222
223 $result = db_query($link, $query);
224
225 if (db_num_rows($result) != 0) {
226
227 $line = db_fetch_assoc($result);
228
229 $tmp_result = db_query($link, "UPDATE ttrss_user_entries
230 SET unread = false,last_read = NOW()
231 WHERE ref_id = '$id'
232 AND owner_uid = " . $_SESSION["uid"]);
233
234 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
235 $updated_fmt = smart_date_time(strtotime($line["updated"]));
236 } else {
237 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
238 $updated_fmt = date($short_date, strtotime($line["updated"]));
239 }
240
241 $title = $line["title"];
242 $article_link = $line["link"];
243
244 $feed_title = getFeedTitle($link, $feed_id, false);
245
246 print "<div class=\"panel\" id=\"article-$id\" title=\"$title\"
247 selected=\"true\"
248 myBackLabel='$feed_title' myBackHref='feed.php?id=$feed_id&cat=$cat_id'>";
249
250 // print "<h2><a target='_blank' href='$link'>$title</a></h2>";
251
252 print "<fieldset>";
253
254 print "<div class=\"row\">";
255 print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>";
256 print "</div>";
257
258 $is_starred = (sql_bool_to_bool($line["marked"])) ? "true" : "false";
259 $is_published = (sql_bool_to_bool($line["published"])) ? "true" : "false";
260
261 print "<div class=\"row\">
262 <label>Starred</label>
263 <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>
264 </div>";
265
266 print "<div class=\"row\">
267 <label>Published</label>
268 <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>
269 </div>";
270
271
272 print "<div class=\"row\">";
273 print "<label id='updated'>Updated:</label>";
274 print "<input enabled='false' name='updated' disabled value='$updated_fmt'/>";
275 print "</div>";
276
277 print "</fieldset>";
278
279 print "<p>";
280 print $line["content"];
281 print "</p>";
282
283 print "</div>";
284
285 }
286
287 }
288 ?>