]>
Commit | Line | Data |
---|---|---|
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) { | |
7 | if ($_SESSION["mobile-prefs"][$id]) return "true"; | |
8 | ||
9 | } | |
10 | ||
11 | function mobile_get_pref($link, $id) { | |
12 | return $_SESSION["mobile-prefs"][$id]; | |
13 | } | |
14 | ||
15 | function mobile_set_pref($link, $id, $value) { | |
16 | $_SESSION["mobile-prefs"][$id] = $value; | |
17 | } | |
18 | ||
3518718b AD |
19 | function mobile_feed_has_icon($id) { |
20 | $filename = "../".ICONS_DIR."/$id.ico"; | |
42096f52 | 21 | |
3518718b AD |
22 | return file_exists($filename) && filesize($filename) > 0; |
23 | } | |
42096f52 | 24 | |
b1bd222c AD |
25 | function render_flat_feed_list($link) { |
26 | $owner_uid = $_SESSION["uid"]; | |
27 | ||
f0a0c1ff AD |
28 | if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) { |
29 | $order_by = "unread DESC, title"; | |
30 | } else { | |
31 | $order_by = "title"; | |
32 | } | |
33 | ||
b1bd222c AD |
34 | $result = db_query($link, "SELECT id, |
35 | title, | |
36 | (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries | |
37 | WHERE feed_id = ttrss_feeds.id AND unread = true | |
38 | AND ttrss_user_entries.ref_id = ttrss_entries.id | |
39 | AND owner_uid = '$owner_uid') as unread | |
40 | FROM ttrss_feeds | |
41 | WHERE | |
42 | ttrss_feeds.hidden = false AND | |
43 | ttrss_feeds.owner_uid = '$owner_uid' AND | |
44 | parent_feed IS NULL | |
f0a0c1ff | 45 | ORDER BY $order_by"); |
b1bd222c | 46 | |
f0a0c1ff AD |
47 | print '<ul id="home" title="Feeds" selected="true" |
48 | myBackLabel="Logout" myBackHref="logout.php" myBackTarget="_self">'; | |
b1bd222c AD |
49 | |
50 | // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>"; | |
51 | ||
52 | while ($line = db_fetch_assoc($result)) { | |
53 | $id = $line["id"]; | |
54 | $unread = $line["unread"]; | |
55 | ||
56 | // $unread = rand(0, 100); | |
57 | ||
58 | if ($unread > 0) { | |
59 | $line["title"] = $line["title"] . " ($unread)"; | |
60 | $class = ''; | |
61 | } else { | |
62 | $class = 'oldItem'; | |
63 | } | |
64 | ||
65 | if (mobile_feed_has_icon($id)) { | |
66 | $icon_url = "../".ICONS_URL."/$id.ico"; | |
67 | } else { | |
68 | $icon_url = "../images/blank_icon.gif"; | |
69 | } | |
f0a0c1ff AD |
70 | |
71 | if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) { | |
72 | print "<li class='$class'><a href='feed.php?id=$id'>" . | |
73 | "<img class='tinyIcon' src='$icon_url'/>". | |
74 | $line["title"] . "</a></li>"; | |
75 | } | |
b1bd222c AD |
76 | } |
77 | ||
78 | print "</ul>"; | |
79 | ||
80 | ||
81 | ||
82 | } | |
83 | ||
3518718b AD |
84 | function render_category($link, $cat_id) { |
85 | $owner_uid = $_SESSION["uid"]; | |
42096f52 | 86 | |
e2b7a855 | 87 | if ($cat_id >= 0) { |
85233b8e | 88 | |
e2b7a855 AD |
89 | if ($cat_id != 0) { |
90 | $cat_query = "cat_id = '$cat_id'"; | |
3518718b | 91 | } else { |
e2b7a855 | 92 | $cat_query = "cat_id IS NULL"; |
0d3adafe | 93 | } |
f0a0c1ff AD |
94 | |
95 | if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) { | |
96 | $order_by = "unread DESC, title"; | |
97 | } else { | |
98 | $order_by = "title"; | |
99 | } | |
100 | ||
e2b7a855 AD |
101 | $result = db_query($link, "SELECT id, |
102 | title, | |
103 | (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries | |
104 | WHERE feed_id = ttrss_feeds.id AND unread = true | |
105 | AND ttrss_user_entries.ref_id = ttrss_entries.id | |
106 | AND owner_uid = '$owner_uid') as unread | |
107 | FROM ttrss_feeds | |
108 | WHERE | |
109 | ttrss_feeds.hidden = false AND | |
110 | ttrss_feeds.owner_uid = '$owner_uid' AND | |
111 | parent_feed IS NULL AND | |
112 | $cat_query | |
f0a0c1ff | 113 | ORDER BY $order_by"); |
e2b7a855 AD |
114 | |
115 | $title = getCategoryTitle($link, $cat_id); | |
116 | ||
117 | print "<ul id='cat-$cat_id' title='$title' myBackLabel='Feeds' | |
bf974b02 | 118 | myBackHref='home.php'>"; |
e2b7a855 AD |
119 | |
120 | // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>"; | |
121 | ||
122 | while ($line = db_fetch_assoc($result)) { | |
123 | $id = $line["id"]; | |
124 | $unread = $line["unread"]; | |
3e94601e | 125 | |
e2b7a855 AD |
126 | // $unread = rand(0, 100); |
127 | ||
128 | if ($unread > 0) { | |
129 | $line["title"] = $line["title"] . " ($unread)"; | |
130 | $class = ''; | |
131 | } else { | |
132 | $class = 'oldItem'; | |
133 | } | |
134 | ||
135 | if (mobile_feed_has_icon($id)) { | |
136 | $icon_url = "../".ICONS_URL."/$id.ico"; | |
137 | } else { | |
138 | $icon_url = "../images/blank_icon.gif"; | |
139 | } | |
f0a0c1ff AD |
140 | |
141 | if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) { | |
142 | print "<li class='$class'><a href='feed.php?id=$id&cat=$cat_id'>" . | |
143 | "<img class='tinyIcon' src='$icon_url'/>". | |
144 | $line["title"] . "</a></li>"; | |
145 | } | |
0d3adafe | 146 | } |
e2b7a855 AD |
147 | |
148 | print "</ul>"; | |
149 | } else if ($cat_id == -1) { | |
150 | ||
17fd15be AD |
151 | $title = __('Special'); |
152 | ||
e2b7a855 AD |
153 | print "<ul id='cat--1' title='$title' myBackLabel='Feeds' |
154 | myBackHref='index.php' myBackTarget='_self'>"; | |
155 | ||
156 | foreach (array(-4, -1,-2,-3) as $id) { | |
157 | $title = getFeedTitle($link, $id); | |
158 | $unread = getFeedUnread($link, $id, false); | |
159 | ||
160 | if ($unread > 0) { | |
161 | $title = $title . " ($unread)"; | |
162 | $class = ''; | |
163 | } else { | |
164 | $class = 'oldItem'; | |
eead4d26 | 165 | } |
8e3f7217 | 166 | |
f0a0c1ff AD |
167 | if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) { |
168 | print "<li class='$class'> | |
169 | <a href='feed.php?id=$id&cat_id=-1'>$title</a></li>"; | |
170 | } | |
e2b7a855 | 171 | } |
8e3f7217 | 172 | |
17fd15be AD |
173 | print "</ul>"; |
174 | } else if ($cat_id == -2) { | |
175 | ||
176 | $title = __('Labels'); | |
177 | ||
178 | print "<ul id='cat--2' title='$title' myBackLabel='Feeds' | |
179 | myBackHref='index.php' myBackTarget='_self'>"; | |
180 | ||
181 | $result = db_query($link, "SELECT id, caption FROM ttrss_labels2 | |
182 | WHERE owner_uid = '$owner_uid'"); | |
183 | ||
184 | $label_data = array(); | |
185 | ||
186 | while ($line = db_fetch_assoc($result)) { | |
187 | ||
188 | $id = -$line["id"] - 11; | |
189 | ||
190 | $unread = getFeedUnread($link, $id); | |
191 | $title = $line["caption"]; | |
192 | ||
193 | if ($unread > 0) { | |
194 | $title = $title . " ($unread)"; | |
195 | $class = ''; | |
196 | } else { | |
197 | $class = 'oldItem'; | |
198 | } | |
199 | ||
f0a0c1ff AD |
200 | if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) { |
201 | print "<li class='$class'> | |
202 | <a href='feed.php?id=$id&cat=-2'>$title</a></li>"; | |
203 | } | |
17fd15be | 204 | } |
e2b7a855 AD |
205 | print "</ul>"; |
206 | } | |
0d3adafe AD |
207 | } |
208 | ||
3518718b AD |
209 | function render_categories_list($link) { |
210 | $owner_uid = $_SESSION["uid"]; | |
2f468537 | 211 | |
2f468537 | 212 | |
f0a0c1ff AD |
213 | print '<ul id="home" title="'.__('Categories').'" selected="true" |
214 | myBackLabel="Logout" myBackHref="logout.php" myBackTarget="_self">'; | |
eead4d26 | 215 | |
3518718b AD |
216 | foreach (array(-1, -2) as $id) { |
217 | $title = getCategoryTitle($link, $id); | |
218 | $unread = getFeedUnread($link, $id, true); | |
219 | if ($unread > 0) { | |
220 | $title = $title . " ($unread)"; | |
221 | $class = ''; | |
eead4d26 | 222 | } else { |
3518718b | 223 | $class = 'oldItem'; |
c878bc01 | 224 | } |
2f468537 | 225 | |
3518718b | 226 | print "<li class='$class'><a href='cat.php?id=$id'>$title</a></li>"; |
2f468537 AD |
227 | } |
228 | ||
3518718b AD |
229 | $result = db_query($link, "SELECT |
230 | ttrss_feed_categories.id, | |
231 | ttrss_feed_categories.title, | |
232 | COUNT(ttrss_feeds.id) AS num_feeds | |
233 | FROM ttrss_feed_categories, ttrss_feeds | |
234 | WHERE ttrss_feed_categories.owner_uid = $owner_uid | |
235 | AND ttrss_feed_categories.id = cat_id | |
236 | AND hidden = false | |
237 | GROUP BY ttrss_feed_categories.id, | |
238 | ttrss_feed_categories.title | |
239 | ORDER BY ttrss_feed_categories.title"); | |
2f468537 | 240 | |
3518718b | 241 | while ($line = db_fetch_assoc($result)) { |
fc46ab83 | 242 | |
3518718b | 243 | if ($line["num_feeds"] > 0) { |
2f468537 | 244 | |
3518718b | 245 | $unread = getFeedUnread($link, $line["id"], true); |
2f468537 | 246 | $id = $line["id"]; |
510ac75f | 247 | |
3518718b AD |
248 | if ($unread > 0) { |
249 | $line["title"] = $line["title"] . " ($unread)"; | |
250 | $class = ''; | |
510ac75f | 251 | } else { |
3518718b | 252 | $class = 'oldItem'; |
510ac75f | 253 | } |
2f468537 | 254 | |
f0a0c1ff AD |
255 | if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) { |
256 | print "<li class='$class'><a href='cat.php?id=$id'>" . | |
257 | $line["title"] . "</a></li>"; | |
258 | } | |
2f468537 | 259 | } |
2f468537 AD |
260 | } |
261 | ||
2f468537 | 262 | |
3518718b AD |
263 | $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE |
264 | cat_id IS NULL and owner_uid = '$owner_uid'"); | |
42096f52 | 265 | |
3518718b | 266 | $num_feeds = db_fetch_result($result, 0, "nf"); |
42096f52 | 267 | |
3518718b AD |
268 | if ($num_feeds > 0) { |
269 | $unread = getFeedUnread($link, 0, true); | |
270 | $title = "Uncategorized"; | |
42096f52 | 271 | |
3518718b AD |
272 | if ($unread > 0) { |
273 | $title = "$title ($unread)"; | |
274 | $class = ''; | |
42096f52 | 275 | } else { |
3518718b | 276 | $class = 'oldItem'; |
42096f52 AD |
277 | } |
278 | ||
f0a0c1ff AD |
279 | if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) { |
280 | print "<li class='$class'><a href='cat.php?id=0'>$title</a></li>"; | |
281 | } | |
3518718b | 282 | } |
42096f52 | 283 | |
3518718b AD |
284 | print "</ul>"; |
285 | } | |
24ac6776 | 286 | |
3e092346 | 287 | function render_headlines_list($link, $feed_id, $cat_id) { |
24ac6776 | 288 | |
3518718b AD |
289 | $feed_id = $feed_id; |
290 | $limit = 30; | |
291 | $filter = ''; | |
3e092346 | 292 | $is_cat = false; |
3518718b | 293 | $view_mode = 'adaptive'; |
d9aad400 | 294 | |
3518718b | 295 | /* do not rely on params below */ |
d9aad400 | 296 | |
3518718b AD |
297 | $search = ''; |
298 | $search_mode = ''; | |
299 | $match_on = ''; | |
300 | ||
301 | $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit, | |
302 | $view_mode, $is_cat, $search, $search_mode, $match_on); | |
541890fb | 303 | |
3518718b AD |
304 | $result = $qfh_ret[0]; |
305 | $feed_title = $qfh_ret[1]; | |
42096f52 | 306 | |
b1bd222c AD |
307 | if ($cat_id) { |
308 | $cat_title = getCategoryTitle($link, $cat_id); | |
3e092346 | 309 | |
b1bd222c AD |
310 | print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\" |
311 | myBackLabel='$cat_title' myBackHref='cat.php?id=$cat_id'>"; | |
312 | } else { | |
313 | print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\" | |
314 | myBackLabel='Feeds' myBackHref='home.php'>"; | |
315 | } | |
24ac6776 | 316 | |
3518718b AD |
317 | while ($line = db_fetch_assoc($result)) { |
318 | $id = $line["id"]; | |
3e94601e | 319 | $real_feed_id = $line["feed_id"]; |
f70f7e28 | 320 | |
3518718b AD |
321 | if (sql_bool_to_bool($line["unread"])) { |
322 | $class = ''; | |
f70f7e28 | 323 | } else { |
3518718b | 324 | $class = 'oldItem'; |
f70f7e28 AD |
325 | } |
326 | ||
3e94601e AD |
327 | if (mobile_feed_has_icon($real_feed_id)) { |
328 | $icon_url = "../".ICONS_URL."/$real_feed_id.ico"; | |
329 | } else { | |
330 | $icon_url = "../images/blank_icon.gif"; | |
331 | } | |
332 | ||
333 | print "<li class='$class'><a href='article.php?id=$id&feed=$feed_id&cat=$cat_id'> | |
334 | <img class='tinyIcon' src='$icon_url'>"; | |
3518718b AD |
335 | print $line["title"]; |
336 | print "</a></li>"; | |
4a596be6 | 337 | |
42096f52 AD |
338 | } |
339 | ||
3518718b AD |
340 | print "</ul>"; |
341 | ||
42096f52 AD |
342 | } |
343 | ||
3e092346 | 344 | function render_article($link, $id, $feed_id, $cat_id) { |
0809065e | 345 | |
3518718b AD |
346 | $query = "SELECT title,link,content,feed_id,comments,int_id, |
347 | marked,unread,published, | |
348 | ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, | |
349 | author | |
350 | FROM ttrss_entries,ttrss_user_entries | |
351 | WHERE id = '$id' AND ref_id = id AND owner_uid = " . | |
352 | $_SESSION["uid"] ; | |
0809065e | 353 | |
3518718b | 354 | $result = db_query($link, $query); |
0809065e | 355 | |
3e092346 | 356 | if (db_num_rows($result) != 0) { |
0809065e | 357 | |
3e092346 | 358 | $line = db_fetch_assoc($result); |
0809065e | 359 | |
3e092346 AD |
360 | $tmp_result = db_query($link, "UPDATE ttrss_user_entries |
361 | SET unread = false,last_read = NOW() | |
362 | WHERE ref_id = '$id' | |
363 | AND owner_uid = " . $_SESSION["uid"]); | |
0809065e | 364 | |
3e092346 AD |
365 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { |
366 | $updated_fmt = smart_date_time(strtotime($line["updated"])); | |
367 | } else { | |
368 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
369 | $updated_fmt = date($short_date, strtotime($line["updated"])); | |
370 | } | |
371 | ||
372 | $title = $line["title"]; | |
373 | $article_link = $line["link"]; | |
374 | ||
375 | $feed_title = getFeedTitle($link, $feed_id, false); | |
376 | ||
377 | print "<div class=\"panel\" id=\"article-$id\" title=\"$title\" | |
378 | selected=\"true\" | |
379 | myBackLabel='$feed_title' myBackHref='feed.php?id=$feed_id&cat=$cat_id'>"; | |
380 | ||
bf974b02 | 381 | print "<h2><a target='_blank' href='$link'>$title</a></h2>"; |
3e092346 AD |
382 | |
383 | print "<fieldset>"; | |
384 | ||
bf974b02 | 385 | /* print "<div class=\"row\">"; |
3e092346 | 386 | print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>"; |
bf974b02 | 387 | print "</div>"; */ |
3e092346 AD |
388 | |
389 | $is_starred = (sql_bool_to_bool($line["marked"])) ? "true" : "false"; | |
390 | $is_published = (sql_bool_to_bool($line["published"])) ? "true" : "false"; | |
391 | ||
3e092346 AD |
392 | print "<div class=\"row\">"; |
393 | print "<label id='updated'>Updated:</label>"; | |
394 | print "<input enabled='false' name='updated' disabled value='$updated_fmt'/>"; | |
395 | print "</div>"; | |
396 | ||
397 | print "</fieldset>"; | |
3bac78a0 AD |
398 | |
399 | $content = sanitize_rss($link, $line["content"]); | |
400 | $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content); | |
401 | ||
f0a0c1ff AD |
402 | if (!mobile_get_pref($link, "SHOW_IMAGES")) { |
403 | $content = preg_replace('/<img[^>]+>/is', '', $content); | |
404 | } | |
405 | ||
706fe949 | 406 | print "<p>$content</p>"; |
6101b0e1 AD |
407 | |
408 | print "<fieldset>"; | |
409 | ||
410 | print "<div class=\"row\"> | |
411 | <label>Starred</label> | |
412 | <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> | |
413 | </div>"; | |
3e092346 | 414 | |
6101b0e1 AD |
415 | print "<div class=\"row\"> |
416 | <label>Published</label> | |
417 | <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> | |
418 | </div>"; | |
419 | ||
420 | print "</fieldset>"; | |
421 | ||
3e092346 | 422 | print "</div>"; |
f70f7e28 | 423 | |
3e092346 | 424 | } |
4a596be6 | 425 | } |
0d3adafe | 426 | ?> |