]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
f1a80dae | 2 | |
894ebcf5 | 3 | /* if ($_GET["debug"]) { |
cce28758 AD |
4 | define('DEFAULT_ERROR_LEVEL', E_ALL); |
5 | } else { | |
6 | define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE); | |
894ebcf5 | 7 | } */ |
cce28758 | 8 | |
40d13c28 | 9 | require_once 'config.php'; |
cc17c205 | 10 | |
f8c612d4 | 11 | function get_translations() { |
6a214f92 | 12 | $tr = array( |
019bd5a9 | 13 | "auto" => "Detect automatically", |
6a214f92 AD |
14 | "en_US" => "English", |
15 | "fr_FR" => "Français", | |
16 | "ru_RU" => "Русский", | |
17 | "zh_CN" => "Simplified Chinese"); | |
f8c612d4 AD |
18 | |
19 | return $tr; | |
20 | } | |
21 | ||
8d039718 | 22 | if (ENABLE_TRANSLATIONS == true) { |
865220a4 AD |
23 | require_once "accept-to-gettext.php"; |
24 | require_once "gettext/gettext.inc"; | |
aba609e0 | 25 | |
8d039718 AD |
26 | function startup_gettext() { |
27 | ||
28 | # Get locale from Accept-Language header | |
6a214f92 | 29 | $lang = al2gt(array_keys(get_translations()), "text/html"); |
89cb787e AD |
30 | |
31 | if (defined('_TRANSLATION_OVERRIDE_DEFAULT')) { | |
32 | $lang = _TRANSLATION_OVERRIDE_DEFAULT; | |
33 | } | |
34 | ||
672f3f3c | 35 | if ($_COOKIE["ttrss_lang"] && $_COOKIE["ttrss_lang"] != "auto") { |
68659d98 AD |
36 | $lang = $_COOKIE["ttrss_lang"]; |
37 | } | |
38 | ||
8d039718 AD |
39 | if ($lang) { |
40 | _setlocale(LC_MESSAGES, $lang); | |
41 | _bindtextdomain("messages", "locale"); | |
42 | _textdomain("messages"); | |
43 | _bind_textdomain_codeset("messages", "UTF-8"); | |
44 | } | |
aba609e0 | 45 | } |
aba609e0 | 46 | |
cc17c205 | 47 | startup_gettext(); |
865220a4 AD |
48 | |
49 | } else { | |
50 | function __($msg) { | |
51 | return $msg; | |
52 | } | |
53 | function startup_gettext() { | |
54 | // no-op | |
55 | return true; | |
56 | } | |
cc17c205 AD |
57 | } |
58 | ||
b619ff15 | 59 | require_once 'db-prefs.php'; |
5bc0bd27 | 60 | require_once 'compat.php'; |
af106b0e | 61 | require_once 'errors.php'; |
8911ac8b | 62 | require_once 'version.php'; |
40d13c28 | 63 | |
49f9c923 | 64 | define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')'); |
a3ee2a38 AD |
65 | define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); |
66 | ||
9fdf7824 AD |
67 | if (ENABLE_SIMPLEPIE) { |
68 | require_once "simplepie/simplepie.inc"; | |
69 | } else { | |
70 | require_once "magpierss/rss_fetch.inc"; | |
71 | require_once 'magpierss/rss_utils.inc'; | |
72 | } | |
49f9c923 | 73 | |
f738aef1 AD |
74 | include_once "tw/tw-config.php"; |
75 | include_once "tw/tw.php"; | |
76 | include_once TW_SETUP . "paranoya.php"; | |
77 | ||
78 | $tw_parser = new twParser(); | |
79 | ||
6f9e33e4 AD |
80 | function _debug($msg) { |
81 | $ts = strftime("%H:%M:%S", time()); | |
82 | print "[$ts] $msg\n"; | |
83 | } | |
84 | ||
ad507f85 AD |
85 | function purge_feed($link, $feed_id, $purge_interval, $debug = false) { |
86 | ||
87 | $rows = -1; | |
4c193675 | 88 | |
fefa6ca3 | 89 | if (DB_TYPE == "pgsql") { |
44e241cb | 90 | /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE |
fefa6ca3 | 91 | marked = false AND feed_id = '$feed_id' AND |
35d8cf43 | 92 | (SELECT date_entered FROM ttrss_entries WHERE |
44e241cb AD |
93 | id = ref_id) < NOW() - INTERVAL '$purge_interval days'"); */ |
94 | ||
6e7f8d26 AD |
95 | $pg_version = get_pgsql_version($link); |
96 | ||
97 | if (preg_match("/^7\./", $pg_version) || preg_match("/^8\.0/", $pg_version)) { | |
1e59ae35 AD |
98 | |
99 | $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE | |
100 | ttrss_entries.id = ref_id AND | |
101 | marked = false AND | |
102 | feed_id = '$feed_id' AND | |
103 | ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); | |
104 | ||
105 | } else { | |
106 | ||
107 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
108 | USING ttrss_entries | |
109 | WHERE ttrss_entries.id = ref_id AND | |
110 | marked = false AND | |
111 | feed_id = '$feed_id' AND | |
fc774155 | 112 | ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); |
1e59ae35 | 113 | } |
ad507f85 AD |
114 | |
115 | $rows = pg_affected_rows($result); | |
116 | ||
fefa6ca3 | 117 | } else { |
1e59ae35 | 118 | |
30f1746f | 119 | /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE |
fefa6ca3 | 120 | marked = false AND feed_id = '$feed_id' AND |
35d8cf43 | 121 | (SELECT date_entered FROM ttrss_entries WHERE |
30f1746f AD |
122 | id = ref_id) < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); */ |
123 | ||
124 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
125 | USING ttrss_user_entries, ttrss_entries | |
126 | WHERE ttrss_entries.id = ref_id AND | |
127 | marked = false AND | |
128 | feed_id = '$feed_id' AND | |
129 | ttrss_entries.date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); | |
130 | ||
ad507f85 AD |
131 | $rows = mysql_affected_rows($link); |
132 | ||
133 | } | |
134 | ||
135 | if ($debug) { | |
6f9e33e4 | 136 | _debug("Purged feed $feed_id ($purge_interval): deleted $rows articles"); |
fefa6ca3 AD |
137 | } |
138 | } | |
139 | ||
44e241cb AD |
140 | function global_purge_old_posts($link, $do_output = false, $limit = false) { |
141 | ||
894ebcf5 | 142 | $random_qpart = sql_random_function(); |
fefa6ca3 | 143 | |
44e241cb AD |
144 | if ($limit) { |
145 | $limit_qpart = "LIMIT $limit"; | |
146 | } else { | |
147 | $limit_qpart = ""; | |
148 | } | |
149 | ||
fefa6ca3 | 150 | $result = db_query($link, |
44e241cb AD |
151 | "SELECT id,purge_interval,owner_uid FROM ttrss_feeds |
152 | ORDER BY $random_qpart $limit_qpart"); | |
fefa6ca3 AD |
153 | |
154 | while ($line = db_fetch_assoc($result)) { | |
155 | ||
156 | $feed_id = $line["id"]; | |
157 | $purge_interval = $line["purge_interval"]; | |
158 | $owner_uid = $line["owner_uid"]; | |
159 | ||
160 | if ($purge_interval == 0) { | |
161 | ||
162 | $tmp_result = db_query($link, | |
163 | "SELECT value FROM ttrss_user_prefs WHERE | |
164 | pref_name = 'PURGE_OLD_DAYS' AND owner_uid = '$owner_uid'"); | |
165 | ||
166 | if (db_num_rows($tmp_result) != 0) { | |
167 | $purge_interval = db_fetch_result($tmp_result, 0, "value"); | |
168 | } | |
169 | } | |
170 | ||
171 | if ($do_output) { | |
ad507f85 | 172 | // print "Feed $feed_id: purge interval = $purge_interval\n"; |
fefa6ca3 AD |
173 | } |
174 | ||
175 | if ($purge_interval > 0) { | |
ad507f85 | 176 | purge_feed($link, $feed_id, $purge_interval, $do_output); |
fefa6ca3 AD |
177 | } |
178 | } | |
179 | ||
71604ca4 AD |
180 | // purge orphaned posts in main content table |
181 | db_query($link, "DELETE FROM ttrss_entries WHERE | |
182 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); | |
183 | ||
fefa6ca3 AD |
184 | } |
185 | ||
b6eefba5 | 186 | function purge_old_posts($link) { |
5d73494a | 187 | |
f1a80dae AD |
188 | $user_id = $_SESSION["uid"]; |
189 | ||
190 | $result = db_query($link, "SELECT id,purge_interval FROM ttrss_feeds | |
191 | WHERE owner_uid = '$user_id'"); | |
5d73494a AD |
192 | |
193 | while ($line = db_fetch_assoc($result)) { | |
194 | ||
195 | $feed_id = $line["id"]; | |
196 | $purge_interval = $line["purge_interval"]; | |
197 | ||
b619ff15 | 198 | if ($purge_interval == 0) $purge_interval = get_pref($link, 'PURGE_OLD_DAYS'); |
5d73494a | 199 | |
140aae81 | 200 | if ($purge_interval > 0) { |
fefa6ca3 | 201 | purge_feed($link, $feed_id, $purge_interval); |
5d73494a AD |
202 | } |
203 | } | |
71604ca4 AD |
204 | |
205 | // purge orphaned posts in main content table | |
206 | db_query($link, "DELETE FROM ttrss_entries WHERE | |
207 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); | |
c3a8d71a AD |
208 | } |
209 | ||
1f2b01ed | 210 | function update_all_feeds($link, $fetch, $user_id = false, $force_daemon = false) { |
40d13c28 | 211 | |
4769ddaf | 212 | if (WEB_DEMO_MODE) return; |
b0b4abcf | 213 | |
a2770077 AD |
214 | if (!$user_id) { |
215 | $user_id = $_SESSION["uid"]; | |
216 | purge_old_posts($link); | |
217 | } | |
218 | ||
25af8dad | 219 | // db_query($link, "BEGIN"); |
b82af8c3 | 220 | |
cbd8650d AD |
221 | if (MAX_UPDATE_TIME > 0) { |
222 | if (DB_TYPE == "mysql") { | |
223 | $q_order = "RAND()"; | |
224 | } else { | |
225 | $q_order = "RANDOM()"; | |
226 | } | |
227 | } else { | |
228 | $q_order = "last_updated DESC"; | |
229 | } | |
230 | ||
d148926e | 231 | $result = db_query($link, "SELECT feed_url,id, |
798f722b | 232 | SUBSTRING(last_updated,1,19) AS last_updated, |
5c563acd | 233 | update_interval FROM ttrss_feeds WHERE owner_uid = '$user_id' |
cbd8650d AD |
234 | ORDER BY $q_order"); |
235 | ||
236 | $upd_start = time(); | |
40d13c28 | 237 | |
b6eefba5 | 238 | while ($line = db_fetch_assoc($result)) { |
d148926e AD |
239 | $upd_intl = $line["update_interval"]; |
240 | ||
b619ff15 | 241 | if (!$upd_intl || $upd_intl == 0) { |
e289ca71 | 242 | $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id, false); |
b619ff15 | 243 | } |
d148926e | 244 | |
c1e202b7 AD |
245 | if ($upd_intl < 0) { |
246 | // Updates for this feed are disabled | |
247 | continue; | |
248 | } | |
249 | ||
93d40f50 AD |
250 | if ($fetch || (!$line["last_updated"] || |
251 | time() - strtotime($line["last_updated"]) > ($upd_intl * 60))) { | |
c5142cca | 252 | |
cbd8650d AD |
253 | // print "<!-- feed: ".$line["feed_url"]." -->"; |
254 | ||
1f2b01ed | 255 | update_rss_feed($link, $line["feed_url"], $line["id"], $force_daemon); |
cbd8650d AD |
256 | |
257 | $upd_elapsed = time() - $upd_start; | |
258 | ||
259 | if (MAX_UPDATE_TIME > 0 && $upd_elapsed > MAX_UPDATE_TIME) { | |
260 | return; | |
261 | } | |
d148926e | 262 | } |
40d13c28 AD |
263 | } |
264 | ||
25af8dad | 265 | // db_query($link, "COMMIT"); |
b82af8c3 | 266 | |
40d13c28 AD |
267 | } |
268 | ||
4065b60b AD |
269 | function fetch_file_contents($url) { |
270 | if (USE_CURL_FOR_ICONS) { | |
271 | $tmpfile = tempnam(TMP_DIRECTORY, "ttrss-tmp"); | |
272 | ||
273 | $ch = curl_init($url); | |
274 | $fp = fopen($tmpfile, "w"); | |
275 | ||
276 | if ($fp) { | |
277 | curl_setopt($ch, CURLOPT_FILE, $fp); | |
dd966fed AD |
278 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); |
279 | curl_setopt($ch, CURLOPT_TIMEOUT, 45); | |
4065b60b AD |
280 | curl_exec($ch); |
281 | curl_close($ch); | |
282 | fclose($fp); | |
283 | } | |
284 | ||
285 | $contents = file_get_contents($tmpfile); | |
286 | unlink($tmpfile); | |
287 | ||
288 | return $contents; | |
289 | ||
290 | } else { | |
291 | return file_get_contents($url); | |
292 | } | |
293 | ||
294 | } | |
78800912 | 295 | |
4065b60b AD |
296 | // adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/) |
297 | // http://dev.wp-plugins.org/file/favatars/trunk/favatars.php | |
78800912 | 298 | |
4065b60b | 299 | function get_favicon_url($url) { |
99331724 | 300 | |
4065b60b | 301 | if ($html = @fetch_file_contents($url)) { |
78800912 | 302 | |
4065b60b AD |
303 | if ( preg_match('/<link[^>]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $html, $matches)) { |
304 | // Attempt to grab a favicon link from their webpage url | |
305 | $linkUrl = html_entity_decode($matches[1]); | |
c798704b | 306 | |
4065b60b AD |
307 | if (substr($linkUrl, 0, 1) == '/') { |
308 | $urlParts = parse_url($url); | |
309 | $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].$linkUrl; | |
310 | } else if (substr($linkUrl, 0, 7) == 'http://') { | |
311 | $faviconURL = $linkUrl; | |
312 | } else if (substr($url, -1, 1) == '/') { | |
313 | $faviconURL = $url.$linkUrl; | |
314 | } else { | |
315 | $faviconURL = $url.'/'.$linkUrl; | |
e695fdc8 | 316 | } |
717f5e64 | 317 | |
c798704b | 318 | } else { |
4065b60b AD |
319 | // If unsuccessful, attempt to "guess" the favicon location |
320 | $urlParts = parse_url($url); | |
321 | $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].'/favicon.ico'; | |
322 | } | |
323 | } | |
c798704b | 324 | |
4065b60b AD |
325 | // Run a test to see if what we have attempted to get actually exists. |
326 | if(USE_CURL_FOR_ICONS || url_validate($faviconURL)) { | |
327 | return $faviconURL; | |
328 | } else { | |
329 | return false; | |
330 | } | |
331 | } | |
332 | ||
333 | function url_validate($link) { | |
334 | ||
335 | $url_parts = @parse_url($link); | |
336 | ||
337 | if ( empty( $url_parts["host"] ) ) | |
338 | return false; | |
339 | ||
340 | if ( !empty( $url_parts["path"] ) ) { | |
341 | $documentpath = $url_parts["path"]; | |
342 | } else { | |
343 | $documentpath = "/"; | |
344 | } | |
345 | ||
346 | if ( !empty( $url_parts["query"] ) ) | |
347 | $documentpath .= "?" . $url_parts["query"]; | |
348 | ||
349 | $host = $url_parts["host"]; | |
350 | $port = $url_parts["port"]; | |
351 | ||
352 | if ( empty($port) ) | |
353 | $port = "80"; | |
354 | ||
355 | $socket = @fsockopen( $host, $port, $errno, $errstr, 30 ); | |
356 | ||
357 | if ( !$socket ) | |
358 | return false; | |
c798704b | 359 | |
4065b60b AD |
360 | fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n"); |
361 | ||
362 | $http_response = fgets( $socket, 22 ); | |
363 | ||
364 | $responses = "/(200 OK)|(30[0-9] Moved)/"; | |
365 | if ( preg_match($responses, $http_response) ) { | |
366 | fclose($socket); | |
367 | return true; | |
368 | } else { | |
369 | return false; | |
370 | } | |
371 | ||
372 | } | |
373 | ||
374 | function check_feed_favicon($site_url, $feed, $link) { | |
375 | $favicon_url = get_favicon_url($site_url); | |
376 | ||
377 | # print "FAVICON [$site_url]: $favicon_url\n"; | |
378 | ||
379 | error_reporting(0); | |
380 | ||
381 | $icon_file = ICONS_DIR . "/$feed.ico"; | |
382 | ||
383 | if ($favicon_url && !file_exists($icon_file)) { | |
384 | $contents = fetch_file_contents($favicon_url); | |
385 | ||
386 | $fp = fopen($icon_file, "w"); | |
78800912 | 387 | |
4065b60b AD |
388 | if ($fp) { |
389 | fwrite($fp, $contents); | |
390 | fclose($fp); | |
391 | chmod($icon_file, 0644); | |
392 | } | |
78800912 | 393 | } |
4065b60b AD |
394 | |
395 | error_reporting(DEFAULT_ERROR_LEVEL); | |
396 | ||
78800912 AD |
397 | } |
398 | ||
ddb68b81 | 399 | function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) { |
40d13c28 | 400 | |
ddb68b81 | 401 | if (DAEMON_REFRESH_ONLY && !$_GET["daemon"] && !$ignore_daemon) { |
21cfcdf2 AD |
402 | return; |
403 | } | |
404 | ||
4bc64807 | 405 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb | 406 | _debug("update_rss_feed: start"); |
219bd8fc AD |
407 | } |
408 | ||
47c6c988 | 409 | $result = db_query($link, "SELECT update_interval,auth_login,auth_pass |
a88c1f36 AD |
410 | FROM ttrss_feeds WHERE id = '$feed'"); |
411 | ||
47439031 AD |
412 | $auth_login = db_fetch_result($result, 0, "auth_login"); |
413 | $auth_pass = db_fetch_result($result, 0, "auth_pass"); | |
47c6c988 | 414 | |
a88c1f36 AD |
415 | $update_interval = db_fetch_result($result, 0, "update_interval"); |
416 | ||
417 | if ($update_interval < 0) { return; } | |
418 | ||
ab3d0b99 AD |
419 | $feed = db_escape_string($feed); |
420 | ||
47c6c988 AD |
421 | $fetch_url = $feed_url; |
422 | ||
423 | if ($auth_login && $auth_pass) { | |
424 | $url_parts = array(); | |
425 | preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts); | |
426 | ||
427 | if ($url_parts[1] && $url_parts[2]) { | |
428 | $fetch_url = $url_parts[1] . "://$auth_login:$auth_pass@" . $url_parts[2]; | |
429 | } | |
430 | ||
431 | } | |
ab3d0b99 | 432 | |
4bc64807 | 433 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
ca872b9d | 434 | _debug("update_rss_feed: fetching [$fetch_url]..."); |
219bd8fc AD |
435 | } |
436 | ||
9fdf7824 | 437 | if (!defined('DAEMON_EXTENDED_DEBUG') && !$_GET['xdebug']) { |
219bd8fc AD |
438 | error_reporting(0); |
439 | } | |
440 | ||
9fdf7824 AD |
441 | if (!ENABLE_SIMPLEPIE) { |
442 | $rss = fetch_rss($fetch_url); | |
443 | } else { | |
ca872b9d AD |
444 | $rss = new SimplePie(); |
445 | $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT); | |
03a577bf | 446 | $rss->set_timeout(MAGPIE_FETCH_TIME_OUT); |
ca872b9d AD |
447 | $rss->set_feed_url($fetch_url); |
448 | $rss->set_output_encoding('UTF-8'); | |
9fdf7824 | 449 | $rss->init(); |
9fdf7824 AD |
450 | } |
451 | ||
452 | // print_r($rss); | |
219bd8fc | 453 | |
4bc64807 | 454 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb | 455 | _debug("update_rss_feed: fetch done, parsing..."); |
219bd8fc AD |
456 | } else { |
457 | error_reporting (DEFAULT_ERROR_LEVEL); | |
458 | } | |
459 | ||
b6eefba5 | 460 | $feed = db_escape_string($feed); |
dcee8f61 | 461 | |
ca872b9d AD |
462 | if (ENABLE_SIMPLEPIE) { |
463 | $fetch_ok = !$rss->error(); | |
464 | } else { | |
465 | $fetch_ok = !!$rss; | |
466 | } | |
467 | ||
468 | if ($fetch_ok) { | |
50b62214 | 469 | |
4bc64807 | 470 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
471 | _debug("update_rss_feed: processing feed data..."); |
472 | } | |
473 | ||
44e241cb | 474 | // db_query($link, "BEGIN"); |
dd8c76a9 | 475 | |
a88c1f36 | 476 | $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid |
f324892e | 477 | FROM ttrss_feeds WHERE id = '$feed'"); |
331900c6 | 478 | |
b6eefba5 AD |
479 | $registered_title = db_fetch_result($result, 0, "title"); |
480 | $orig_icon_url = db_fetch_result($result, 0, "icon_url"); | |
f324892e | 481 | $orig_site_url = db_fetch_result($result, 0, "site_url"); |
331900c6 | 482 | |
7fed1940 AD |
483 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); |
484 | ||
9fdf7824 AD |
485 | if (ENABLE_SIMPLEPIE) { |
486 | $site_url = $rss->get_link(); | |
487 | } else { | |
488 | $site_url = $rss->channel["link"]; | |
489 | } | |
490 | ||
8d0ec6fd | 491 | if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid, false)) { |
4bc64807 | 492 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
493 | _debug("update_rss_feed: checking favicon..."); |
494 | } | |
9fdf7824 AD |
495 | |
496 | check_feed_favicon($site_url, $feed, $link); | |
a2770077 AD |
497 | } |
498 | ||
746b249f | 499 | if (!$registered_title || $registered_title == "[Unknown]") { |
4bc64807 | 500 | |
fb486a33 | 501 | if (ENABLE_SIMPLEPIE) { |
c2f8aac4 | 502 | $feed_title = db_escape_string($rss->get_title()); |
fb486a33 AD |
503 | } else { |
504 | $feed_title = db_escape_string($rss->channel["title"]); | |
505 | } | |
4bc64807 AD |
506 | |
507 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
508 | _debug("update_rss_feed: registering title: $feed_title"); | |
509 | } | |
7c5a308d | 510 | |
f324892e AD |
511 | db_query($link, "UPDATE ttrss_feeds SET |
512 | title = '$feed_title' WHERE id = '$feed'"); | |
513 | } | |
514 | ||
49f9c923 | 515 | // weird, weird Magpie |
9fdf7824 AD |
516 | if (!ENABLE_SIMPLEPIE) { |
517 | if (!$site_url) $site_url = db_escape_string($rss->channel["link_"]); | |
518 | } | |
147f7691 AD |
519 | |
520 | if ($site_url && $orig_site_url != db_escape_string($site_url)) { | |
f324892e AD |
521 | db_query($link, "UPDATE ttrss_feeds SET |
522 | site_url = '$site_url' WHERE id = '$feed'"); | |
331900c6 | 523 | } |
40d13c28 | 524 | |
b7f4bda2 AD |
525 | // print "I: " . $rss->channel["image"]["url"]; |
526 | ||
9fdf7824 AD |
527 | if (!ENABLE_SIMPLEPIE) { |
528 | $icon_url = $rss->image["url"]; | |
529 | } else { | |
530 | $icon_url = $rss->get_image_url(); | |
531 | } | |
b7f4bda2 | 532 | |
147f7691 | 533 | if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) { |
b6eefba5 AD |
534 | $icon_url = db_escape_string($icon_url); |
535 | db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'"); | |
b7f4bda2 AD |
536 | } |
537 | ||
51e456d6 | 538 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
539 | _debug("update_rss_feed: loading filters..."); |
540 | } | |
e6155a06 AD |
541 | |
542 | $filters = array(); | |
543 | ||
4b3dff6e | 544 | $result = db_query($link, "SELECT reg_exp, |
db42b934 | 545 | ttrss_filter_types.name AS name, |
073ca0e6 | 546 | ttrss_filter_actions.name AS action, |
c2d9322b | 547 | inverse, |
073ca0e6 | 548 | action_param |
db42b934 | 549 | FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE |
e8b79d16 | 550 | enabled = true AND |
db42b934 AD |
551 | owner_uid = $owner_uid AND |
552 | ttrss_filter_types.id = filter_type AND | |
553 | ttrss_filter_actions.id = action_id AND | |
f8382011 | 554 | (feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp"); |
e6155a06 | 555 | |
b6eefba5 | 556 | while ($line = db_fetch_assoc($result)) { |
e6155a06 | 557 | if (!$filters[$line["name"]]) $filters[$line["name"]] = array(); |
19c9cb11 AD |
558 | |
559 | $filter["reg_exp"] = $line["reg_exp"]; | |
560 | $filter["action"] = $line["action"]; | |
073ca0e6 | 561 | $filter["action_param"] = $line["action_param"]; |
c2d9322b | 562 | $filter["inverse"] = sql_bool_to_bool($line["inverse"]); |
073ca0e6 | 563 | |
19c9cb11 | 564 | array_push($filters[$line["name"]], $filter); |
e6155a06 AD |
565 | } |
566 | ||
9fdf7824 AD |
567 | if (ENABLE_SIMPLEPIE) { |
568 | $iterator = $rss->get_items(); | |
569 | } else { | |
570 | $iterator = $rss->items; | |
571 | if (!$iterator || !is_array($iterator)) $iterator = $rss->entries; | |
572 | if (!$iterator || !is_array($iterator)) $iterator = $rss; | |
573 | } | |
c22789da AD |
574 | |
575 | if (!is_array($iterator)) { | |
39541e74 | 576 | /* db_query($link, "UPDATE ttrss_feeds |
75bd0669 | 577 | SET last_error = 'Parse error: can\'t find any articles.' |
77f0a2a7 AD |
578 | WHERE id = '$feed'"); */ |
579 | ||
580 | // clear any errors and mark feed as updated if fetched okay | |
581 | // even if it's blank | |
582 | ||
51e456d6 | 583 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
844012bc AD |
584 | _debug("update_rss_feed: entry iterator is not an array, no articles?"); |
585 | } | |
586 | ||
77f0a2a7 AD |
587 | db_query($link, "UPDATE ttrss_feeds |
588 | SET last_updated = NOW(), last_error = '' WHERE id = '$feed'"); | |
589 | ||
590 | return; // no articles | |
c22789da | 591 | } |
ddb68b81 | 592 | |
51e456d6 | 593 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
594 | _debug("update_rss_feed: processing articles..."); |
595 | } | |
596 | ||
ddb68b81 | 597 | foreach ($iterator as $item) { |
7c5a308d | 598 | |
9fdf7824 AD |
599 | if (ENABLE_SIMPLEPIE) { |
600 | $entry_guid = $item->get_id(); | |
601 | if (!$entry_guid) $entry_guid = $item->get_link(); | |
602 | if (!$entry_guid) $entry_guid = make_guid_from_title($item->get_title()); | |
603 | ||
604 | } else { | |
605 | ||
606 | $entry_guid = $item["id"]; | |
34e420fb | 607 | |
9fdf7824 AD |
608 | if (!$entry_guid) $entry_guid = $item["guid"]; |
609 | if (!$entry_guid) $entry_guid = $item["link"]; | |
610 | if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]); | |
611 | } | |
be832a1a | 612 | |
9fdf7824 | 613 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
614 | _debug("update_rss_feed: guid $entry_guid"); |
615 | } | |
616 | ||
be832a1a AD |
617 | if (!$entry_guid) continue; |
618 | ||
619 | $entry_timestamp = ""; | |
620 | ||
9fdf7824 AD |
621 | if (ENABLE_SIMPLEPIE) { |
622 | $entry_timestamp = strtotime($item->get_date()); | |
623 | } else { | |
624 | $rss_2_date = $item['pubdate']; | |
625 | $rss_1_date = $item['dc']['date']; | |
626 | $atom_date = $item['issued']; | |
627 | if (!$atom_date) $atom_date = $item['updated']; | |
be832a1a | 628 | |
9fdf7824 AD |
629 | if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date); |
630 | if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date); | |
631 | if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date); | |
632 | } | |
9bb36aa0 AD |
633 | |
634 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
635 | _debug("update_rss_feed: date $entry_timestamp"); | |
636 | } | |
637 | ||
2e930846 | 638 | if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) { |
be832a1a AD |
639 | $entry_timestamp = time(); |
640 | $no_orig_date = 'true'; | |
641 | } else { | |
642 | $no_orig_date = 'false'; | |
643 | } | |
644 | ||
645 | $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); | |
646 | ||
9fdf7824 AD |
647 | if (ENABLE_SIMPLEPIE) { |
648 | $entry_title = $item->get_title(); | |
649 | } else { | |
650 | $entry_title = trim(strip_tags($item["title"])); | |
651 | } | |
be832a1a | 652 | |
9fdf7824 AD |
653 | if (ENABLE_SIMPLEPIE) { |
654 | $entry_link = $item->get_link(); | |
655 | } else { | |
656 | // strange Magpie workaround | |
657 | $entry_link = $item["link_"]; | |
658 | if (!$entry_link) $entry_link = $item["link"]; | |
659 | } | |
be832a1a | 660 | |
9bb36aa0 AD |
661 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
662 | _debug("update_rss_feed: title $entry_title"); | |
663 | } | |
664 | ||
665 | if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);; | |
7d3ab0dd | 666 | |
be832a1a | 667 | $entry_link = strip_tags($entry_link); |
7d3ab0dd | 668 | |
9fdf7824 AD |
669 | if (ENABLE_SIMPLEPIE) { |
670 | $entry_content = $item->get_description(); | |
671 | } else { | |
672 | $entry_content = $item["content:escaped"]; | |
673 | ||
674 | if (!$entry_content) $entry_content = $item["content:encoded"]; | |
675 | if (!$entry_content) $entry_content = $item["content"]; | |
676 | if (!$entry_content) $entry_content = $item["atom_content"]; | |
677 | if (!$entry_content) $entry_content = $item["summary"]; | |
678 | if (!$entry_content) $entry_content = $item["description"]; | |
679 | ||
680 | // WTF | |
681 | if (is_array($entry_content)) { | |
682 | $entry_content = $entry_content["encoded"]; | |
683 | if (!$entry_content) $entry_content = $entry_content["escaped"]; | |
684 | } | |
be832a1a AD |
685 | } |
686 | ||
687 | // print_r($item); | |
688 | // print_r(htmlspecialchars($entry_content)); | |
689 | // print "<br>"; | |
690 | ||
691 | $entry_content_unescaped = $entry_content; | |
be832a1a | 692 | |
9fdf7824 AD |
693 | if (ENABLE_SIMPLEPIE) { |
694 | $entry_comments = strip_tags($item->data["comments"]); | |
30cf38dd AD |
695 | if ($item->get_author()) { |
696 | $entry_author = $item->get_author()->get_name(); | |
697 | } | |
9fdf7824 AD |
698 | } else { |
699 | $entry_comments = strip_tags($item["comments"]); | |
700 | ||
701 | $entry_author = db_escape_string(strip_tags($item['dc']['creator'])); | |
4d6e9157 | 702 | |
9fdf7824 AD |
703 | if ($item['author']) { |
704 | ||
705 | if (is_array($item['author'])) { | |
706 | ||
707 | if (!$entry_author) { | |
708 | $entry_author = db_escape_string(strip_tags($item['author']['name'])); | |
709 | } | |
710 | ||
711 | if (!$entry_author) { | |
712 | $entry_author = db_escape_string(strip_tags($item['author']['email'])); | |
713 | } | |
4d6e9157 | 714 | } |
9fdf7824 | 715 | |
4d6e9157 | 716 | if (!$entry_author) { |
9fdf7824 | 717 | $entry_author = db_escape_string(strip_tags($item['author'])); |
4d6e9157 | 718 | } |
83f114c8 | 719 | } |
be832a1a AD |
720 | } |
721 | ||
83f114c8 AD |
722 | if (preg_match('/^[\t\n\r ]*$/', $entry_author)) $entry_author = ''; |
723 | ||
be832a1a AD |
724 | $entry_guid = db_escape_string(strip_tags($entry_guid)); |
725 | ||
726 | $result = db_query($link, "SELECT id FROM ttrss_entries | |
727 | WHERE guid = '$entry_guid'"); | |
728 | ||
729 | $entry_content = db_escape_string($entry_content); | |
7e43ad58 AD |
730 | |
731 | $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); | |
732 | ||
be832a1a AD |
733 | $entry_title = db_escape_string($entry_title); |
734 | $entry_link = db_escape_string($entry_link); | |
2544f36b AD |
735 | $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250); |
736 | $entry_author = mb_substr($entry_author, 0, 250); | |
be832a1a | 737 | |
9fdf7824 AD |
738 | if (ENABLE_SIMPLEPIE) { |
739 | $num_comments = 0; #FIXME# | |
740 | } else { | |
741 | $num_comments = db_escape_string($item["slash"]["comments"]); | |
742 | } | |
be832a1a AD |
743 | |
744 | if (!$num_comments) $num_comments = 0; | |
745 | ||
fefef828 | 746 | // parse <category> entries into tags |
be832a1a | 747 | |
9fdf7824 | 748 | if (ENABLE_SIMPLEPIE) { |
be832a1a | 749 | |
fefef828 | 750 | $additional_tags = array(); |
9fdf7824 AD |
751 | $additional_tags_src = $item->get_categories(); |
752 | ||
a702e931 AD |
753 | if (is_array($additional_tags_src)) { |
754 | foreach ($additional_tags_src as $tobj) { | |
755 | array_push($additional_tags, $tobj->get_term()); | |
756 | } | |
fefef828 | 757 | } |
fefef828 | 758 | |
6af621c7 AD |
759 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
760 | _debug("update_rss_feed: category tags:"); | |
761 | print_r($additional_tags); | |
762 | } | |
763 | ||
9fdf7824 | 764 | } else { |
fefef828 | 765 | |
9fdf7824 | 766 | $t_ctr = $item['category#']; |
fefef828 | 767 | |
9fdf7824 AD |
768 | $additional_tags = false; |
769 | ||
770 | if ($t_ctr == 0) { | |
771 | $additional_tags = false; | |
772 | } else if ($t_ctr == 1) { | |
773 | $additional_tags = array($item['category']); | |
774 | } else { | |
775 | $additional_tags = array(); | |
776 | for ($i = 0; $i <= $t_ctr; $i++ ) { | |
777 | if ($item["category#$i"]) { | |
778 | array_push($additional_tags, $item["category#$i"]); | |
779 | } | |
780 | } | |
781 | } | |
782 | ||
783 | // parse <dc:subject> elements | |
784 | ||
785 | $t_ctr = $item['dc']['subject#']; | |
786 | ||
787 | if ($t_ctr == 1) { | |
788 | $additional_tags = array($item['dc']['subject']); | |
789 | } else if ($t_ctr > 1) { | |
790 | $additional_tags = array(); | |
791 | for ($i = 0; $i <= $t_ctr; $i++ ) { | |
792 | if ($item['dc']["subject#$i"]) { | |
793 | array_push($additional_tags, $item['dc']["subject#$i"]); | |
794 | } | |
fefef828 AD |
795 | } |
796 | } | |
797 | } | |
8add756a | 798 | |
d48d160c | 799 | # sanitize content |
183ad07b | 800 | |
007a38d4 | 801 | // $entry_content = sanitize_rss($entry_content); |
d48d160c | 802 | |
9fdf7824 | 803 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
804 | _debug("update_rss_feed: done collecting data [TITLE:$entry_title]"); |
805 | } | |
806 | ||
44e241cb AD |
807 | db_query($link, "BEGIN"); |
808 | ||
4c193675 AD |
809 | if (db_num_rows($result) == 0) { |
810 | ||
9fdf7824 | 811 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
812 | _debug("update_rss_feed: base guid not found"); |
813 | } | |
814 | ||
4c193675 AD |
815 | // base post entry does not exist, create it |
816 | ||
4c193675 AD |
817 | $result = db_query($link, |
818 | "INSERT INTO ttrss_entries | |
819 | (title, | |
820 | guid, | |
821 | link, | |
822 | updated, | |
823 | content, | |
824 | content_hash, | |
825 | no_orig_date, | |
826 | date_entered, | |
11b0dce2 | 827 | comments, |
b6104dee AD |
828 | num_comments, |
829 | author) | |
4c193675 AD |
830 | VALUES |
831 | ('$entry_title', | |
832 | '$entry_guid', | |
833 | '$entry_link', | |
834 | '$entry_timestamp_fmt', | |
835 | '$entry_content', | |
836 | '$content_hash', | |
837 | $no_orig_date, | |
838 | NOW(), | |
11b0dce2 | 839 | '$entry_comments', |
b6104dee AD |
840 | '$num_comments', |
841 | '$entry_author')"); | |
8926aab8 AD |
842 | } else { |
843 | // we keep encountering the entry in feeds, so we need to | |
844 | // update date_entered column so that we don't get horrible | |
845 | // dupes when the entry gets purged and reinserted again e.g. | |
846 | // in the case of SLOW SLOW OMG SLOW updating feeds | |
847 | ||
848 | $base_entry_id = db_fetch_result($result, 0, "id"); | |
849 | ||
850 | db_query($link, "UPDATE ttrss_entries SET date_entered = NOW() | |
851 | WHERE id = '$base_entry_id'"); | |
4c193675 AD |
852 | } |
853 | ||
854 | // now it should exist, if not - bad luck then | |
855 | ||
6385315d AD |
856 | $result = db_query($link, "SELECT |
857 | id,content_hash,no_orig_date,title, | |
8926aab8 | 858 | substring(date_entered,1,19) as date_entered, |
11b0dce2 AD |
859 | substring(updated,1,19) as updated, |
860 | num_comments | |
6385315d AD |
861 | FROM |
862 | ttrss_entries | |
863 | WHERE guid = '$entry_guid'"); | |
4c193675 AD |
864 | |
865 | if (db_num_rows($result) == 1) { | |
866 | ||
9fdf7824 | 867 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
7ca91eb3 | 868 | _debug("update_rss_feed: base guid found, checking for user record"); |
34e420fb AD |
869 | } |
870 | ||
11b0dce2 AD |
871 | // this will be used below in update handler |
872 | $orig_content_hash = db_fetch_result($result, 0, "content_hash"); | |
873 | $orig_title = db_fetch_result($result, 0, "title"); | |
874 | $orig_num_comments = db_fetch_result($result, 0, "num_comments"); | |
8926aab8 AD |
875 | $orig_date_entered = strtotime(db_fetch_result($result, |
876 | 0, "date_entered")); | |
6385315d | 877 | |
11b0dce2 | 878 | $ref_id = db_fetch_result($result, 0, "id"); |
4c193675 | 879 | |
11b0dce2 | 880 | // check for user post link to main table |
4c193675 | 881 | |
11b0dce2 | 882 | // do we allow duplicate posts with same GUID in different feeds? |
8d0ec6fd | 883 | if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) { |
11b0dce2 AD |
884 | $dupcheck_qpart = "AND feed_id = '$feed'"; |
885 | } else { | |
886 | $dupcheck_qpart = ""; | |
887 | } | |
71604ca4 | 888 | |
11b0dce2 | 889 | // error_reporting(0); |
19c9cb11 | 890 | |
f8382011 AD |
891 | $article_filters = get_article_filters($filters, $entry_title, |
892 | $entry_content, $entry_link); | |
19c9cb11 | 893 | |
9fdf7824 | 894 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
7ca91eb3 AD |
895 | _debug("update_rss_feed: article filters: "); |
896 | if (count($article_filters) != 0) { | |
897 | print_r($article_filters); | |
898 | } | |
899 | } | |
900 | ||
f8382011 | 901 | if (find_article_filter($article_filters, "filter")) { |
11b0dce2 AD |
902 | continue; |
903 | } | |
19c9cb11 | 904 | |
11b0dce2 | 905 | // error_reporting (DEFAULT_ERROR_LEVEL); |
3a933f22 | 906 | |
11b0dce2 AD |
907 | $result = db_query($link, |
908 | "SELECT ref_id FROM ttrss_user_entries WHERE | |
909 | ref_id = '$ref_id' AND owner_uid = '$owner_uid' | |
910 | $dupcheck_qpart"); | |
7ca91eb3 | 911 | |
11b0dce2 AD |
912 | // okay it doesn't exist - create user entry |
913 | if (db_num_rows($result) == 0) { | |
914 | ||
9fdf7824 | 915 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
7ca91eb3 AD |
916 | _debug("update_rss_feed: user record not found, creating..."); |
917 | } | |
918 | ||
f8382011 | 919 | if (!find_article_filter($article_filters, 'catchup')) { |
11b0dce2 AD |
920 | $unread = 'true'; |
921 | $last_read_qpart = 'NULL'; | |
922 | } else { | |
923 | $unread = 'false'; | |
924 | $last_read_qpart = 'NOW()'; | |
925 | } | |
dd7d3187 | 926 | |
f8382011 | 927 | if (find_article_filter($article_filters, 'mark')) { |
dd7d3187 AD |
928 | $marked = 'true'; |
929 | } else { | |
930 | $marked = 'false'; | |
931 | } | |
a36c0dfe AD |
932 | |
933 | if (find_article_filter($article_filters, 'publish')) { | |
934 | $published = 'true'; | |
935 | } else { | |
936 | $published = 'false'; | |
937 | } | |
938 | ||
11b0dce2 AD |
939 | $result = db_query($link, |
940 | "INSERT INTO ttrss_user_entries | |
a36c0dfe | 941 | (ref_id, owner_uid, feed_id, unread, last_read, marked, published) |
11b0dce2 | 942 | VALUES ('$ref_id', '$owner_uid', '$feed', $unread, |
a36c0dfe | 943 | $last_read_qpart, $marked, $published)"); |
11b0dce2 AD |
944 | } |
945 | ||
6385315d AD |
946 | $post_needs_update = false; |
947 | ||
8d0ec6fd | 948 | if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid, false) && |
6385315d | 949 | ($content_hash != $orig_content_hash)) { |
7e43ad58 | 950 | // print "<!-- [$entry_title] $content_hash vs $orig_content_hash -->"; |
6385315d AD |
951 | $post_needs_update = true; |
952 | } | |
953 | ||
7e43ad58 | 954 | if (db_escape_string($orig_title) != $entry_title) { |
6385315d AD |
955 | $post_needs_update = true; |
956 | } | |
957 | ||
11b0dce2 AD |
958 | if ($orig_num_comments != $num_comments) { |
959 | $post_needs_update = true; | |
960 | } | |
961 | ||
6385315d AD |
962 | // this doesn't seem to be very reliable |
963 | // | |
964 | // if ($orig_timestamp != $entry_timestamp && !$orig_no_orig_date) { | |
965 | // $post_needs_update = true; | |
966 | // } | |
967 | ||
968 | // if post needs update, update it and mark all user entries | |
1c73bc0c | 969 | // linking to this post as updated |
6385315d AD |
970 | if ($post_needs_update) { |
971 | ||
7ca91eb3 AD |
972 | if (defined('DAEMON_EXTENDED_DEBUG')) { |
973 | _debug("update_rss_feed: post $entry_guid needs update..."); | |
974 | } | |
975 | ||
6385315d AD |
976 | // print "<!-- post $orig_title needs update : $post_needs_update -->"; |
977 | ||
6385315d | 978 | db_query($link, "UPDATE ttrss_entries |
11b0dce2 | 979 | SET title = '$entry_title', content = '$entry_content', |
7e43ad58 | 980 | content_hash = '$content_hash', |
11b0dce2 | 981 | num_comments = '$num_comments' |
6385315d AD |
982 | WHERE id = '$ref_id'"); |
983 | ||
8d0ec6fd | 984 | if (get_pref($link, "MARK_UNREAD_ON_UPDATE", $owner_uid, false)) { |
4919fb42 AD |
985 | db_query($link, "UPDATE ttrss_user_entries |
986 | SET last_read = null, unread = true WHERE ref_id = '$ref_id'"); | |
987 | } else { | |
988 | db_query($link, "UPDATE ttrss_user_entries | |
989 | SET last_read = null WHERE ref_id = '$ref_id' AND unread = false"); | |
990 | } | |
6385315d AD |
991 | |
992 | } | |
4c193675 AD |
993 | } |
994 | ||
44e241cb AD |
995 | db_query($link, "COMMIT"); |
996 | ||
9fdf7824 | 997 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
998 | _debug("update_rss_feed: looking for tags..."); |
999 | } | |
1000 | ||
eb36b4eb | 1001 | /* taaaags */ |
40e1a95b | 1002 | // <a href="..." rel="tag">Xorg</a>, // |
eb36b4eb | 1003 | |
05732aa0 | 1004 | $entry_tags = null; |
eb36b4eb | 1005 | |
40e1a95b | 1006 | preg_match_all("/<a.*?rel=['\"]tag['\"].*?>([^<]+)<\/a>/i", |
ee2c3050 AD |
1007 | $entry_content_unescaped, $entry_tags); |
1008 | ||
fefef828 AD |
1009 | /* print "<p><br/>$entry_title : $entry_content_unescaped<br>"; |
1010 | print_r($entry_tags); | |
1011 | print "<br/></p>"; */ | |
eb36b4eb AD |
1012 | |
1013 | $entry_tags = $entry_tags[1]; | |
1014 | ||
073ca0e6 AD |
1015 | # check for manual tags |
1016 | ||
f8382011 AD |
1017 | $tag_filter = find_article_filter($article_filters, "tag"); |
1018 | ||
1019 | if ($tag_filter) { | |
073ca0e6 | 1020 | |
f8382011 | 1021 | $manual_tags = trim_array(split(",", $tag_filter[1])); |
073ca0e6 | 1022 | |
f8382011 | 1023 | foreach ($manual_tags as $tag) { |
be832a1a AD |
1024 | if (tag_is_valid($tag)) { |
1025 | array_push($entry_tags, $tag); | |
1026 | } | |
1027 | } | |
1028 | } | |
1029 | ||
11c9ea1f AD |
1030 | $boring_tags = trim_array(split(",", mb_strtolower(get_pref($link, |
1031 | 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); | |
8fc70781 | 1032 | |
fefef828 AD |
1033 | if ($additional_tags && is_array($additional_tags)) { |
1034 | foreach ($additional_tags as $tag) { | |
156a785d AD |
1035 | if (tag_is_valid($tag) && |
1036 | array_search($tag, $boring_tags) === FALSE) { | |
073ca0e6 AD |
1037 | array_push($entry_tags, $tag); |
1038 | } | |
1039 | } | |
fefef828 AD |
1040 | } |
1041 | ||
fcc95e24 | 1042 | // print "<p>TAGS: "; print_r($entry_tags); print "</p>"; |
073ca0e6 | 1043 | |
9fdf7824 AD |
1044 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
1045 | print_r($entry_tags); | |
1046 | } | |
1047 | ||
eb36b4eb AD |
1048 | if (count($entry_tags) > 0) { |
1049 | ||
44e241cb AD |
1050 | db_query($link, "BEGIN"); |
1051 | ||
05732aa0 AD |
1052 | $result = db_query($link, "SELECT id,int_id |
1053 | FROM ttrss_entries,ttrss_user_entries | |
25da6909 | 1054 | WHERE guid = '$entry_guid' |
05732aa0 | 1055 | AND feed_id = '$feed' AND ref_id = id |
7fed1940 | 1056 | AND owner_uid = '$owner_uid'"); |
eb36b4eb | 1057 | |
fe99ab12 | 1058 | if (db_num_rows($result) == 1) { |
eb36b4eb | 1059 | |
fe99ab12 AD |
1060 | $entry_id = db_fetch_result($result, 0, "id"); |
1061 | $entry_int_id = db_fetch_result($result, 0, "int_id"); | |
1062 | ||
1063 | foreach ($entry_tags as $tag) { | |
fefef828 | 1064 | |
14b6c54b | 1065 | $tag = sanitize_tag($tag); |
fefef828 | 1066 | $tag = db_escape_string($tag); |
31483fc1 | 1067 | |
ef063748 AD |
1068 | if (!tag_is_valid($tag)) continue; |
1069 | ||
fe99ab12 AD |
1070 | $result = db_query($link, "SELECT id FROM ttrss_tags |
1071 | WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND | |
1072 | owner_uid = '$owner_uid' LIMIT 1"); | |
1073 | ||
1074 | // print db_fetch_result($result, 0, "id"); | |
1075 | ||
1076 | if ($result && db_num_rows($result) == 0) { | |
1077 | ||
fe99ab12 AD |
1078 | db_query($link, "INSERT INTO ttrss_tags |
1079 | (owner_uid,tag_name,post_int_id) | |
1080 | VALUES ('$owner_uid','$tag', '$entry_int_id')"); | |
1081 | } | |
1082 | } | |
eb36b4eb | 1083 | } |
44e241cb | 1084 | db_query($link, "COMMIT"); |
05732aa0 | 1085 | } |
9fdf7824 AD |
1086 | |
1087 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1088 | _debug("update_rss_feed: article processed"); | |
1089 | } | |
4c193675 | 1090 | } |
40d13c28 | 1091 | |
ab3d0b99 AD |
1092 | db_query($link, "UPDATE ttrss_feeds |
1093 | SET last_updated = NOW(), last_error = '' WHERE id = '$feed'"); | |
eb36b4eb | 1094 | |
44e241cb | 1095 | // db_query($link, "COMMIT"); |
dd8c76a9 | 1096 | |
ab3d0b99 | 1097 | } else { |
ca872b9d | 1098 | |
9fdf7824 | 1099 | if (ENABLE_SIMPLEPIE) { |
ca872b9d | 1100 | $error_msg = mb_substr($rss->error(), 0, 250); |
9fdf7824 | 1101 | } else { |
ca872b9d | 1102 | $error_msg = mb_substr(magpie_error(), 0, 250); |
9fdf7824 | 1103 | } |
ca872b9d AD |
1104 | |
1105 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1106 | _debug("update_rss_feed: error fetching feed: $error_msg"); | |
1107 | } | |
1108 | ||
1109 | $error_msg = db_escape_string($error_msg); | |
1110 | ||
ab3d0b99 | 1111 | db_query($link, |
aa5f9f5f AD |
1112 | "UPDATE ttrss_feeds SET last_error = '$error_msg', |
1113 | last_updated = NOW() WHERE id = '$feed'"); | |
40d13c28 AD |
1114 | } |
1115 | ||
9fdf7824 | 1116 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb | 1117 | _debug("update_rss_feed: done"); |
219bd8fc AD |
1118 | } |
1119 | ||
40d13c28 AD |
1120 | } |
1121 | ||
f175937c | 1122 | function print_select($id, $default, $values, $attributes = "") { |
79f3553b | 1123 | print "<select name=\"$id\" id=\"$id\" $attributes>"; |
a0d53889 AD |
1124 | foreach ($values as $v) { |
1125 | if ($v == $default) | |
1126 | $sel = " selected"; | |
1127 | else | |
1128 | $sel = ""; | |
1129 | ||
1130 | print "<option$sel>$v</option>"; | |
1131 | } | |
1132 | print "</select>"; | |
1133 | } | |
40d13c28 | 1134 | |
79f3553b AD |
1135 | function print_select_hash($id, $default, $values, $attributes = "") { |
1136 | print "<select name=\"$id\" id='$id' $attributes>"; | |
673d54ca AD |
1137 | foreach (array_keys($values) as $v) { |
1138 | if ($v == $default) | |
1139 | $sel = "selected"; | |
1140 | else | |
1141 | $sel = ""; | |
1142 | ||
1143 | print "<option $sel value=\"$v\">".$values[$v]."</option>"; | |
1144 | } | |
1145 | ||
1146 | print "</select>"; | |
1147 | } | |
1148 | ||
f8382011 | 1149 | function get_article_filters($filters, $title, $content, $link) { |
240054f1 | 1150 | $matches = array(); |
c2d9322b | 1151 | |
240054f1 AD |
1152 | if ($filters["title"]) { |
1153 | foreach ($filters["title"] as $filter) { | |
c2d9322b AD |
1154 | $reg_exp = $filter["reg_exp"]; |
1155 | $inverse = $filter["inverse"]; | |
1156 | if ((!$inverse && preg_match("/$reg_exp/i", $title)) || | |
1157 | ($inverse && !preg_match("/$reg_exp/i", $title))) { | |
1158 | ||
240054f1 AD |
1159 | array_push($matches, array($filter["action"], $filter["action_param"])); |
1160 | } | |
1161 | } | |
1162 | } | |
1163 | ||
1164 | if ($filters["content"]) { | |
1165 | foreach ($filters["content"] as $filter) { | |
c2d9322b AD |
1166 | $reg_exp = $filter["reg_exp"]; |
1167 | $inverse = $filter["inverse"]; | |
1168 | ||
1169 | if ((!$inverse && preg_match("/$reg_exp/i", $content)) || | |
1170 | ($inverse && !preg_match("/$reg_exp/i", $content))) { | |
1171 | ||
240054f1 AD |
1172 | array_push($matches, array($filter["action"], $filter["action_param"])); |
1173 | } | |
1174 | } | |
1175 | } | |
1176 | ||
1177 | if ($filters["both"]) { | |
1178 | foreach ($filters["both"] as $filter) { | |
1179 | $reg_exp = $filter["reg_exp"]; | |
c2d9322b AD |
1180 | $inverse = $filter["inverse"]; |
1181 | ||
1182 | if ($inverse) { | |
1183 | if (!preg_match("/$reg_exp/i", $title) || !preg_match("/$reg_exp/i", $content)) { | |
1184 | array_push($matches, array($filter["action"], $filter["action_param"])); | |
1185 | } | |
1186 | } else { | |
1187 | if (preg_match("/$reg_exp/i", $title) || preg_match("/$reg_exp/i", $content)) { | |
1188 | array_push($matches, array($filter["action"], $filter["action_param"])); | |
1189 | } | |
240054f1 AD |
1190 | } |
1191 | } | |
1192 | } | |
1193 | ||
1194 | if ($filters["link"]) { | |
1195 | $reg_exp = $filter["reg_exp"]; | |
1196 | foreach ($filters["link"] as $filter) { | |
1197 | $reg_exp = $filter["reg_exp"]; | |
c2d9322b AD |
1198 | $inverse = $filter["inverse"]; |
1199 | ||
1200 | if ((!$inverse && preg_match("/$reg_exp/i", $link)) || | |
1201 | ($inverse && !preg_match("/$reg_exp/i", $link))) { | |
1202 | ||
240054f1 AD |
1203 | array_push($matches, array($filter["action"], $filter["action_param"])); |
1204 | } | |
1205 | } | |
1206 | } | |
1207 | ||
1208 | return $matches; | |
1209 | } | |
1210 | ||
f8382011 AD |
1211 | function find_article_filter($filters, $filter_name) { |
1212 | foreach ($filters as $f) { | |
1213 | if ($f[0] == $filter_name) { | |
1214 | return $f; | |
1215 | }; | |
1216 | } | |
1217 | return false; | |
1218 | } | |
1219 | ||
9323147e | 1220 | function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link, |
fb1fb4ab | 1221 | $rtl_content = false, $last_updated = false, $last_error = false) { |
254e0e4b AD |
1222 | |
1223 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
023fe037 | 1224 | $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"$icon_file\">"; |
254e0e4b | 1225 | } else { |
023fe037 | 1226 | $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"images/blank_icon.gif\">"; |
254e0e4b AD |
1227 | } |
1228 | ||
9323147e AD |
1229 | if ($rtl_content) { |
1230 | $rtl_tag = "dir=\"rtl\""; | |
1231 | } else { | |
1232 | $rtl_tag = "dir=\"ltr\""; | |
1233 | } | |
1234 | ||
78d5212c AD |
1235 | $error_notify_msg = ""; |
1236 | ||
fb1fb4ab AD |
1237 | if ($last_error) { |
1238 | $link_title = "Error: $last_error ($last_updated)"; | |
78d5212c | 1239 | $error_notify_msg = "(Error)"; |
ad780e9c | 1240 | } else if ($last_updated) { |
fb1fb4ab AD |
1241 | $link_title = "Updated: $last_updated"; |
1242 | } | |
1243 | ||
7210613a | 1244 | $feed = "<a title=\"$link_title\" id=\"FEEDL-$feed_id\" |
c50e2b30 | 1245 | href=\"javascript:viewfeed('$feed_id', '', false, '', false, 0);\">$feed_title</a>"; |
254e0e4b AD |
1246 | |
1247 | print "<li id=\"FEEDR-$feed_id\" class=\"$class\">"; | |
b619ff15 | 1248 | if (get_pref($link, 'ENABLE_FEED_ICONS')) { |
254e0e4b AD |
1249 | print "$feed_icon"; |
1250 | } | |
1251 | ||
9323147e | 1252 | print "<span $rtl_tag id=\"FEEDN-$feed_id\">$feed</span>"; |
254e0e4b AD |
1253 | |
1254 | if ($unread != 0) { | |
1255 | $fctr_class = ""; | |
1256 | } else { | |
1257 | $fctr_class = "class=\"invisible\""; | |
1258 | } | |
1259 | ||
9323147e | 1260 | print " <span $rtl_tag $fctr_class id=\"FEEDCTR-$feed_id\"> |
254e0e4b | 1261 | (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>"; |
78d5212c AD |
1262 | |
1263 | if (get_pref($link, "EXTENDED_FEEDLIST")) { | |
1264 | print "<div class=\"feedExtInfo\"> | |
1265 | <span id=\"FLUPD-$feed_id\">$last_updated $error_notify_msg</span></div>"; | |
1266 | } | |
1267 | ||
254e0e4b AD |
1268 | print "</li>"; |
1269 | ||
1270 | } | |
1271 | ||
406d9489 AD |
1272 | function getmicrotime() { |
1273 | list($usec, $sec) = explode(" ",microtime()); | |
1274 | return ((float)$usec + (float)$sec); | |
1275 | } | |
1276 | ||
f541eb78 | 1277 | function print_radio($id, $default, $true_is, $values, $attributes = "") { |
77e96719 AD |
1278 | foreach ($values as $v) { |
1279 | ||
1280 | if ($v == $default) | |
5da169d9 | 1281 | $sel = "checked"; |
77e96719 | 1282 | else |
5da169d9 AD |
1283 | $sel = ""; |
1284 | ||
f541eb78 | 1285 | if ($v == $true_is) { |
5da169d9 AD |
1286 | $sel .= " value=\"1\""; |
1287 | } else { | |
1288 | $sel .= " value=\"0\""; | |
1289 | } | |
77e96719 | 1290 | |
69654950 AD |
1291 | print "<input class=\"noborder\" |
1292 | type=\"radio\" $sel $attributes name=\"$id\"> $v "; | |
77e96719 AD |
1293 | |
1294 | } | |
1295 | } | |
1296 | ||
ff485f1d AD |
1297 | function initialize_user_prefs($link, $uid) { |
1298 | ||
1299 | $uid = db_escape_string($uid); | |
1300 | ||
1301 | db_query($link, "BEGIN"); | |
1302 | ||
1303 | $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs"); | |
1304 | ||
1305 | $u_result = db_query($link, "SELECT pref_name | |
1306 | FROM ttrss_user_prefs WHERE owner_uid = '$uid'"); | |
1307 | ||
1308 | $active_prefs = array(); | |
1309 | ||
1310 | while ($line = db_fetch_assoc($u_result)) { | |
1311 | array_push($active_prefs, $line["pref_name"]); | |
1312 | } | |
1313 | ||
1314 | while ($line = db_fetch_assoc($result)) { | |
1315 | if (array_search($line["pref_name"], $active_prefs) === FALSE) { | |
1316 | // print "adding " . $line["pref_name"] . "<br>"; | |
1317 | ||
1318 | db_query($link, "INSERT INTO ttrss_user_prefs | |
1319 | (owner_uid,pref_name,value) VALUES | |
1320 | ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')"); | |
1321 | ||
1322 | } | |
1323 | } | |
1324 | ||
1325 | db_query($link, "COMMIT"); | |
1326 | ||
1327 | } | |
956c7629 AD |
1328 | |
1329 | function lookup_user_id($link, $user) { | |
1330 | ||
1331 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
1332 | login = '$login'"); | |
1333 | ||
1334 | if (db_num_rows($result) == 1) { | |
1335 | return db_fetch_result($result, 0, "id"); | |
1336 | } else { | |
1337 | return false; | |
1338 | } | |
1339 | } | |
1340 | ||
18664970 AD |
1341 | function http_authenticate_user($link) { |
1342 | ||
4bc64807 AD |
1343 | error_log("http_authenticate_user: ".$_SERVER["PHP_AUTH_USER"]."\n", 3, '/tmp/tt-rss.log'); |
1344 | ||
18664970 AD |
1345 | if (!$_SERVER["PHP_AUTH_USER"]) { |
1346 | ||
1347 | header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"'); | |
1348 | header('HTTP/1.0 401 Unauthorized'); | |
1349 | exit; | |
1350 | ||
1351 | } else { | |
1352 | $auth_result = authenticate_user($link, | |
1353 | $_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]); | |
1354 | ||
1355 | if (!$auth_result) { | |
1356 | header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"'); | |
1357 | header('HTTP/1.0 401 Unauthorized'); | |
1358 | exit; | |
1359 | } | |
1360 | } | |
1361 | ||
1362 | return true; | |
1363 | } | |
1364 | ||
461766f3 | 1365 | function authenticate_user($link, $login, $password, $force_auth = false) { |
c8437f35 | 1366 | |
131b01b3 | 1367 | if (!SINGLE_USER_MODE) { |
c8437f35 | 1368 | |
131b01b3 | 1369 | $pwd_hash = 'SHA1:' . sha1($password); |
461766f3 AD |
1370 | |
1371 | if ($force_auth && defined('_DEBUG_USER_SWITCH')) { | |
1372 | $query = "SELECT id,login,access_level | |
1373 | FROM ttrss_users WHERE | |
1374 | login = '$login'"; | |
1375 | } else { | |
1376 | $query = "SELECT id,login,access_level | |
1377 | FROM ttrss_users WHERE | |
1378 | login = '$login' AND pwd_hash = '$pwd_hash'"; | |
1379 | } | |
1380 | ||
1381 | $result = db_query($link, $query); | |
131b01b3 AD |
1382 | |
1383 | if (db_num_rows($result) == 1) { | |
1384 | $_SESSION["uid"] = db_fetch_result($result, 0, "id"); | |
1385 | $_SESSION["name"] = db_fetch_result($result, 0, "login"); | |
1386 | $_SESSION["access_level"] = db_fetch_result($result, 0, "access_level"); | |
1387 | ||
1388 | db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . | |
1389 | $_SESSION["uid"]); | |
1390 | ||
1391 | $user_theme = get_user_theme_path($link); | |
1392 | ||
1393 | $_SESSION["theme"] = $user_theme; | |
1394 | $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; | |
1395 | ||
1396 | initialize_user_prefs($link, $_SESSION["uid"]); | |
1397 | ||
1398 | return true; | |
1399 | } | |
1400 | ||
1401 | return false; | |
503eb349 | 1402 | |
131b01b3 | 1403 | } else { |
503eb349 | 1404 | |
131b01b3 AD |
1405 | $_SESSION["uid"] = 1; |
1406 | $_SESSION["name"] = "admin"; | |
f557cd78 | 1407 | |
0bbba72d AD |
1408 | $user_theme = get_user_theme_path($link); |
1409 | ||
1410 | $_SESSION["theme"] = $user_theme; | |
1411 | $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; | |
1412 | ||
1413 | initialize_user_prefs($link, $_SESSION["uid"]); | |
1414 | ||
c8437f35 AD |
1415 | return true; |
1416 | } | |
c8437f35 AD |
1417 | } |
1418 | ||
e6cb77a0 AD |
1419 | function make_password($length = 8) { |
1420 | ||
1421 | $password = ""; | |
798f722b AD |
1422 | $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ"; |
1423 | ||
1424 | $i = 0; | |
e6cb77a0 AD |
1425 | |
1426 | while ($i < $length) { | |
1427 | $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); | |
1428 | ||
1429 | if (!strstr($password, $char)) { | |
1430 | $password .= $char; | |
1431 | $i++; | |
1432 | } | |
1433 | } | |
1434 | return $password; | |
1435 | } | |
1436 | ||
1437 | // this is called after user is created to initialize default feeds, labels | |
1438 | // or whatever else | |
1439 | ||
1440 | // user preferences are checked on every login, not here | |
1441 | ||
1442 | function initialize_user($link, $uid) { | |
1443 | ||
1444 | db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description) | |
1445 | values ('$uid','unread = true', 'Unread articles')"); | |
1446 | ||
1447 | db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description) | |
1448 | values ('$uid','last_read is null and unread = false', 'Updated articles')"); | |
1449 | ||
1450 | db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url) | |
74bff337 | 1451 | values ('$uid', 'Tiny Tiny RSS: New Releases', |
628fcd2c | 1452 | 'http://tt-rss.spb.ru/releases.rss')"); |
3b0feb9b | 1453 | |
cd2cd415 AD |
1454 | db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url) |
1455 | values ('$uid', 'Tiny Tiny RSS: Forum', | |
1456 | 'http://tt-rss.spb.ru/forum/rss.php')"); | |
3b0feb9b | 1457 | } |
e6cb77a0 | 1458 | |
b8aa49bc | 1459 | function logout_user() { |
5ccc1cf5 AD |
1460 | session_destroy(); |
1461 | if (isset($_COOKIE[session_name()])) { | |
1462 | setcookie(session_name(), '', time()-42000, '/'); | |
1463 | } | |
b8aa49bc AD |
1464 | } |
1465 | ||
75836f33 | 1466 | function get_script_urlpath() { |
87a79fa4 | 1467 | return preg_replace('/\/[^\/]*$/', "", $_SERVER["REQUEST_URI"]); |
75836f33 AD |
1468 | } |
1469 | ||
916f788a | 1470 | function validate_session($link) { |
a2e9b457 | 1471 | if (SESSION_CHECK_ADDRESS && $_SESSION["uid"]) { |
916f788a AD |
1472 | if ($_SESSION["ip_address"]) { |
1473 | if ($_SESSION["ip_address"] != $_SERVER["REMOTE_ADDR"]) { | |
7f0acba7 | 1474 | $_SESSION["login_error_msg"] = "Session failed to validate (incorrect IP)"; |
916f788a AD |
1475 | return false; |
1476 | } | |
1477 | } | |
1478 | } | |
d620cfe7 | 1479 | |
a885f0ec | 1480 | /* if ($_SESSION["cookie_lifetime"] && $_SESSION["uid"]) { |
d620cfe7 | 1481 | |
8e849206 | 1482 | //print_r($_SESSION); |
d620cfe7 AD |
1483 | |
1484 | if (time() > $_SESSION["cookie_lifetime"]) { | |
1485 | return false; | |
1486 | } | |
a885f0ec AD |
1487 | } */ |
1488 | ||
916f788a AD |
1489 | return true; |
1490 | } | |
1491 | ||
793185a9 | 1492 | function login_sequence($link, $mobile = false) { |
b8aa49bc | 1493 | if (!SINGLE_USER_MODE) { |
75836f33 | 1494 | |
461766f3 AD |
1495 | if (defined('_DEBUG_USER_SWITCH') && $_SESSION["uid"]) { |
1496 | $swu = db_escape_string($_REQUEST["swu"]); | |
1497 | if ($swu) { | |
1498 | $_SESSION["prefs_cache"] = false; | |
1499 | return authenticate_user($link, $swu, null, true); | |
1500 | } | |
1501 | } | |
1502 | ||
7f0acba7 | 1503 | $login_action = $_POST["login_action"]; |
a885f0ec | 1504 | |
01a87dff | 1505 | # try to authenticate user if called from login form |
7f0acba7 | 1506 | if ($login_action == "do_login") { |
01a87dff AD |
1507 | $login = $_POST["login"]; |
1508 | $password = $_POST["password"]; | |
d620cfe7 | 1509 | $remember_me = $_POST["remember_me"]; |
f557cd78 | 1510 | |
01a87dff AD |
1511 | if (authenticate_user($link, $login, $password)) { |
1512 | $_POST["password"] = ""; | |
d620cfe7 | 1513 | |
f8c612d4 AD |
1514 | $_SESSION["language"] = $_POST["language"]; |
1515 | ||
d620cfe7 AD |
1516 | header("Location: " . $_SERVER["REQUEST_URI"]); |
1517 | exit; | |
1518 | ||
01a87dff | 1519 | return; |
7f0acba7 AD |
1520 | } else { |
1521 | $_SESSION["login_error_msg"] = "Incorrect username or password"; | |
01a87dff AD |
1522 | } |
1523 | } | |
1524 | ||
1df0f48b AD |
1525 | // print session_id(); |
1526 | // print_r($_SESSION); | |
7f0acba7 AD |
1527 | |
1528 | if (!$_SESSION["uid"] || !validate_session($link)) { | |
793185a9 | 1529 | render_login_form($link, $mobile); |
01a87dff | 1530 | exit; |
d3687e7a AD |
1531 | } else { |
1532 | /* bump login timestamp */ | |
1533 | db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . | |
1534 | $_SESSION["uid"]); | |
019bd5a9 | 1535 | |
d54780bc | 1536 | if ($_SESSION["language"] && SESSION_COOKIE_LIFETIME > 0) { |
019bd5a9 AD |
1537 | setcookie("ttrss_lang", $_SESSION["language"], |
1538 | time() + SESSION_COOKIE_LIFETIME); | |
1539 | } | |
b8aa49bc | 1540 | } |
d620cfe7 | 1541 | |
b8aa49bc | 1542 | } else { |
0bbba72d | 1543 | return authenticate_user($link, "admin", null); |
b8aa49bc AD |
1544 | } |
1545 | } | |
3547842a AD |
1546 | |
1547 | function truncate_string($str, $max_len) { | |
12db369c AD |
1548 | if (mb_strlen($str, "utf-8") > $max_len - 3) { |
1549 | return mb_substr($str, 0, $max_len, "utf-8") . "..."; | |
3547842a AD |
1550 | } else { |
1551 | return $str; | |
1552 | } | |
1553 | } | |
54a60e1a AD |
1554 | |
1555 | function get_user_theme_path($link) { | |
798f722b AD |
1556 | $result = db_query($link, "SELECT theme_path |
1557 | FROM | |
1558 | ttrss_themes,ttrss_users | |
1559 | WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]); | |
54a60e1a AD |
1560 | if (db_num_rows($result) != 0) { |
1561 | return db_fetch_result($result, 0, "theme_path"); | |
1562 | } else { | |
1563 | return null; | |
1564 | } | |
1565 | } | |
be773442 AD |
1566 | |
1567 | function smart_date_time($timestamp) { | |
1568 | if (date("Y.m.d", $timestamp) == date("Y.m.d")) { | |
1569 | return date("G:i", $timestamp); | |
f26450f1 | 1570 | } else if (date("Y", $timestamp) == date("Y")) { |
be773442 AD |
1571 | return date("M d, G:i", $timestamp); |
1572 | } else { | |
7d7e0509 | 1573 | return date("Y/m/d, G:i", $timestamp); |
be773442 AD |
1574 | } |
1575 | } | |
1576 | ||
1577 | function smart_date($timestamp) { | |
1578 | if (date("Y.m.d", $timestamp) == date("Y.m.d")) { | |
1579 | return "Today"; | |
f26450f1 | 1580 | } else if (date("Y", $timestamp) == date("Y")) { |
be773442 AD |
1581 | return date("D m", $timestamp); |
1582 | } else { | |
b02111c2 | 1583 | return date("Y/m/d", $timestamp); |
be773442 AD |
1584 | } |
1585 | } | |
a654a595 AD |
1586 | |
1587 | function sql_bool_to_string($s) { | |
1588 | if ($s == "t" || $s == "1") { | |
1589 | return "true"; | |
1590 | } else { | |
1591 | return "false"; | |
1592 | } | |
1593 | } | |
e3c99f3b AD |
1594 | |
1595 | function sql_bool_to_bool($s) { | |
1596 | if ($s == "t" || $s == "1") { | |
1597 | return true; | |
1598 | } else { | |
1599 | return false; | |
1600 | } | |
1601 | } | |
0ea4fb50 | 1602 | |
e3c99f3b | 1603 | |
0ea4fb50 AD |
1604 | function toggleEvenOdd($a) { |
1605 | if ($a == "even") | |
1606 | return "odd"; | |
1607 | else | |
1608 | return "even"; | |
1609 | } | |
6043fb7e AD |
1610 | |
1611 | function sanity_check($link) { | |
9cbca41f | 1612 | |
aec3ce39 AD |
1613 | error_reporting(0); |
1614 | ||
6043fb7e AD |
1615 | $error_code = 0; |
1616 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
1617 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
1618 | ||
1619 | if ($schema_version != SCHEMA_VERSION) { | |
1620 | $error_code = 5; | |
1621 | } | |
1622 | ||
aec3ce39 AD |
1623 | if (DB_TYPE == "mysql") { |
1624 | $result = db_query($link, "SELECT true", false); | |
1625 | if (db_num_rows($result) != 1) { | |
1626 | $error_code = 10; | |
1627 | } | |
1628 | } | |
1629 | ||
1630 | error_reporting (DEFAULT_ERROR_LEVEL); | |
1631 | ||
6043fb7e | 1632 | if ($error_code != 0) { |
aec3ce39 | 1633 | print_error_xml($error_code); |
6043fb7e AD |
1634 | return false; |
1635 | } else { | |
1636 | return true; | |
4220d6b0 | 1637 | } |
6043fb7e AD |
1638 | } |
1639 | ||
27981ca3 AD |
1640 | function file_is_locked($filename) { |
1641 | error_reporting(0); | |
1642 | $fp = fopen($filename, "r"); | |
1643 | error_reporting(DEFAULT_ERROR_LEVEL); | |
1644 | if ($fp) { | |
1645 | if (flock($fp, LOCK_EX | LOCK_NB)) { | |
1646 | flock($fp, LOCK_UN); | |
1647 | fclose($fp); | |
1648 | return false; | |
1649 | } | |
1650 | fclose($fp); | |
1651 | return true; | |
1652 | } | |
1653 | return false; | |
1654 | } | |
1655 | ||
fcb4c0c9 AD |
1656 | function make_lockfile($filename) { |
1657 | $fp = fopen($filename, "w"); | |
1658 | ||
1659 | if (flock($fp, LOCK_EX | LOCK_NB)) { | |
1660 | return $fp; | |
1661 | } else { | |
1662 | return false; | |
1663 | } | |
1664 | } | |
1665 | ||
bf7fcde8 AD |
1666 | function make_stampfile($filename) { |
1667 | $fp = fopen($filename, "w"); | |
1668 | ||
8e00ae9b | 1669 | if (flock($fp, LOCK_EX | LOCK_NB)) { |
bf7fcde8 | 1670 | fwrite($fp, time() . "\n"); |
8e00ae9b | 1671 | flock($fp, LOCK_UN); |
bf7fcde8 AD |
1672 | fclose($fp); |
1673 | return true; | |
1674 | } else { | |
1675 | return false; | |
1676 | } | |
1677 | } | |
1678 | ||
8e00ae9b AD |
1679 | function read_stampfile($filename) { |
1680 | ||
1681 | error_reporting(0); | |
1682 | $fp = fopen($filename, "r"); | |
1683 | error_reporting (DEFAULT_ERROR_LEVEL); | |
1684 | ||
1685 | if (flock($fp, LOCK_EX)) { | |
1686 | $stamp = fgets($fp); | |
1687 | flock($fp, LOCK_UN); | |
1688 | fclose($fp); | |
1689 | return $stamp; | |
1690 | } else { | |
1691 | return false; | |
1692 | } | |
1693 | } | |
bf7fcde8 | 1694 | |
894ebcf5 AD |
1695 | function sql_random_function() { |
1696 | if (DB_TYPE == "mysql") { | |
1697 | return "RAND()"; | |
1698 | } else { | |
1699 | return "RANDOM()"; | |
1700 | } | |
1701 | } | |
1702 | ||
23aa0d16 | 1703 | function catchup_feed($link, $feed, $cat_view) { |
88040f57 AD |
1704 | |
1705 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { | |
23aa0d16 AD |
1706 | |
1707 | if ($cat_view) { | |
1708 | ||
1709 | if ($feed > 0) { | |
1710 | $cat_qpart = "cat_id = '$feed'"; | |
1711 | } else { | |
1712 | $cat_qpart = "cat_id IS NULL"; | |
1713 | } | |
1714 | ||
1715 | $tmp_result = db_query($link, "SELECT id | |
1716 | FROM ttrss_feeds WHERE $cat_qpart AND owner_uid = " . | |
1717 | $_SESSION["uid"]); | |
1718 | ||
1719 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1720 | ||
1721 | $tmp_feed = $tmp_line["id"]; | |
1722 | ||
1723 | db_query($link, "UPDATE ttrss_user_entries | |
1724 | SET unread = false,last_read = NOW() | |
1725 | WHERE feed_id = '$tmp_feed' AND owner_uid = " . $_SESSION["uid"]); | |
1726 | } | |
1727 | ||
1728 | } else if ($feed > 0) { | |
1729 | ||
1730 | $tmp_result = db_query($link, "SELECT id | |
1731 | FROM ttrss_feeds WHERE parent_feed = '$feed' | |
1732 | ORDER BY cat_id,title"); | |
1733 | ||
1734 | $parent_ids = array(); | |
1735 | ||
1736 | if (db_num_rows($tmp_result) > 0) { | |
1737 | while ($p = db_fetch_assoc($tmp_result)) { | |
1738 | array_push($parent_ids, "feed_id = " . $p["id"]); | |
1739 | } | |
1740 | ||
1741 | $children_qpart = implode(" OR ", $parent_ids); | |
1742 | ||
1743 | db_query($link, "UPDATE ttrss_user_entries | |
1744 | SET unread = false,last_read = NOW() | |
1745 | WHERE (feed_id = '$feed' OR $children_qpart) | |
1746 | AND owner_uid = " . $_SESSION["uid"]); | |
1747 | ||
1748 | } else { | |
1749 | db_query($link, "UPDATE ttrss_user_entries | |
1750 | SET unread = false,last_read = NOW() | |
1751 | WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
1752 | } | |
1753 | ||
1754 | } else if ($feed < 0 && $feed > -10) { // special, like starred | |
1755 | ||
1756 | if ($feed == -1) { | |
1757 | db_query($link, "UPDATE ttrss_user_entries | |
1758 | SET unread = false,last_read = NOW() | |
1759 | WHERE marked = true AND owner_uid = ".$_SESSION["uid"]); | |
1760 | } | |
e4f4b46f AD |
1761 | |
1762 | if ($feed == -2) { | |
1763 | db_query($link, "UPDATE ttrss_user_entries | |
1764 | SET unread = false,last_read = NOW() | |
1765 | WHERE published = true AND owner_uid = ".$_SESSION["uid"]); | |
1766 | } | |
1767 | ||
2d24f032 AD |
1768 | if ($feed == -3) { |
1769 | ||
c1d7e6c3 AD |
1770 | $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE"); |
1771 | ||
2d24f032 | 1772 | if (DB_TYPE == "pgsql") { |
c1d7e6c3 | 1773 | $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; |
2d24f032 AD |
1774 | } else { |
1775 | $match_part .= " AND date_entered > DATE_SUB(NOW(), | |
c1d7e6c3 | 1776 | INTERVAL $intl HOUR) "; |
2d24f032 AD |
1777 | } |
1778 | ||
1779 | db_query($link, "UPDATE ttrss_user_entries | |
1780 | SET unread = false,last_read = NOW() | |
1781 | WHERE $match_part AND owner_uid = ".$_SESSION["uid"]); | |
1782 | } | |
1783 | ||
23aa0d16 AD |
1784 | } else if ($feed < -10) { // label |
1785 | ||
1786 | // TODO make this more efficient | |
1787 | ||
1788 | $label_id = -$feed - 11; | |
1789 | ||
1790 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
1791 | WHERE id = '$label_id'"); | |
1792 | ||
1793 | if ($tmp_result) { | |
1794 | $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp"); | |
1795 | ||
1796 | db_query($link, "BEGIN"); | |
1797 | ||
1798 | $tmp2_result = db_query($link, | |
1799 | "SELECT | |
1800 | int_id | |
1801 | FROM | |
88040f57 | 1802 | ttrss_user_entries,ttrss_entries,ttrss_feeds |
23aa0d16 | 1803 | WHERE |
88040f57 AD |
1804 | ref_id = ttrss_entries.id AND |
1805 | ttrss_user_entries.feed_id = ttrss_feeds.id AND | |
23aa0d16 | 1806 | $sql_exp AND |
88040f57 | 1807 | ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); |
23aa0d16 AD |
1808 | |
1809 | while ($tmp_line = db_fetch_assoc($tmp2_result)) { | |
1810 | db_query($link, "UPDATE | |
1811 | ttrss_user_entries | |
1812 | SET | |
1813 | unread = false, last_read = NOW() | |
1814 | WHERE | |
1815 | int_id = " . $tmp_line["int_id"]); | |
1816 | } | |
1817 | ||
1818 | db_query($link, "COMMIT"); | |
1819 | ||
1820 | /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries | |
1821 | SET unread = false,last_read = NOW() | |
1822 | WHERE $sql_exp | |
1823 | AND ref_id = id | |
1824 | AND owner_uid = ".$_SESSION["uid"]); */ | |
1825 | } | |
1826 | } | |
1827 | } else { // tag | |
1828 | db_query($link, "BEGIN"); | |
1829 | ||
1830 | $tag_name = db_escape_string($feed); | |
1831 | ||
1832 | $result = db_query($link, "SELECT post_int_id FROM ttrss_tags | |
1833 | WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]); | |
1834 | ||
1835 | while ($line = db_fetch_assoc($result)) { | |
1836 | db_query($link, "UPDATE ttrss_user_entries SET | |
1837 | unread = false, last_read = NOW() | |
1838 | WHERE int_id = " . $line["post_int_id"]); | |
1839 | } | |
1840 | db_query($link, "COMMIT"); | |
1841 | } | |
1842 | } | |
1843 | ||
1844 | function update_generic_feed($link, $feed, $cat_view) { | |
1845 | if ($cat_view) { | |
1846 | ||
1847 | if ($feed > 0) { | |
1848 | $cat_qpart = "cat_id = '$feed'"; | |
1849 | } else { | |
1850 | $cat_qpart = "cat_id IS NULL"; | |
1851 | } | |
1852 | ||
1853 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
1854 | WHERE $cat_qpart AND owner_uid = " . $_SESSION["uid"]); | |
1855 | ||
1856 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1857 | $feed_url = $tmp_line["feed_url"]; | |
1858 | update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON); | |
1859 | } | |
1860 | ||
1861 | } else { | |
1862 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
1863 | WHERE id = '$feed'"); | |
1864 | $feed_url = db_fetch_result($tmp_result, 0, "feed_url"); | |
1865 | update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON); | |
1866 | } | |
1867 | } | |
a9cb1f83 | 1868 | |
2bc2147f | 1869 | function getAllCounters($link, $omode = "flc") { |
cf4d339c | 1870 | /* getLabelCounters($link); |
a9cb1f83 AD |
1871 | getFeedCounters($link); |
1872 | getTagCounters($link); | |
1873 | getGlobalCounters($link); | |
1874 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1875 | getCategoryCounters($link); | |
cf4d339c AD |
1876 | } */ |
1877 | ||
2bc2147f | 1878 | if (!$omode) $omode = "flc"; |
cf4d339c AD |
1879 | |
1880 | getGlobalCounters($link); | |
1881 | ||
1882 | if (strchr($omode, "l")) getLabelCounters($link); | |
1883 | if (strchr($omode, "f")) getFeedCounters($link); | |
1884 | if (strchr($omode, "t")) getTagCounters($link); | |
1885 | if (strchr($omode, "c")) { | |
1886 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1887 | getCategoryCounters($link); | |
1888 | } | |
a9cb1f83 AD |
1889 | } |
1890 | } | |
1891 | ||
1892 | function getCategoryCounters($link) { | |
bba7c4bf AD |
1893 | # two special categories are -1 and -2 (all virtuals; all labels) |
1894 | ||
1895 | $ctr = getCategoryUnread($link, -1); | |
1896 | ||
1897 | print "<counter type=\"category\" id=\"-1\" counter=\"$ctr\"/>"; | |
1898 | ||
1899 | $ctr = getCategoryUnread($link, -2); | |
1900 | ||
1901 | print "<counter type=\"category\" id=\"-2\" counter=\"$ctr\"/>"; | |
1902 | ||
14073c0a AD |
1903 | $age_qpart = getMaxAgeSubquery(); |
1904 | ||
a9cb1f83 | 1905 | $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id) |
14073c0a AD |
1906 | FROM ttrss_user_entries, ttrss_entries WHERE feed_id = ttrss_feeds.id |
1907 | AND id = ref_id AND $age_qpart | |
a9cb1f83 AD |
1908 | AND unread = true)) AS unread FROM ttrss_feeds |
1909 | WHERE | |
cfb02131 | 1910 | hidden = false AND owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id"); |
a9cb1f83 AD |
1911 | |
1912 | while ($line = db_fetch_assoc($result)) { | |
1913 | $line["cat_id"] = sprintf("%d", $line["cat_id"]); | |
1914 | print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"". | |
1915 | $line["unread"]."\"/>"; | |
1916 | } | |
1917 | } | |
1918 | ||
f295c368 AD |
1919 | function getCategoryUnread($link, $cat) { |
1920 | ||
bba7c4bf | 1921 | if ($cat >= 0) { |
18664970 | 1922 | |
bba7c4bf AD |
1923 | if ($cat != 0) { |
1924 | $cat_query = "cat_id = '$cat'"; | |
1925 | } else { | |
1926 | $cat_query = "cat_id IS NULL"; | |
1927 | } | |
14073c0a AD |
1928 | |
1929 | $age_qpart = getMaxAgeSubquery(); | |
1930 | ||
bba7c4bf AD |
1931 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query |
1932 | AND hidden = false | |
1933 | AND owner_uid = " . $_SESSION["uid"]); | |
1934 | ||
1935 | $cat_feeds = array(); | |
1936 | while ($line = db_fetch_assoc($result)) { | |
1937 | array_push($cat_feeds, "feed_id = " . $line["id"]); | |
1938 | } | |
1939 | ||
1940 | if (count($cat_feeds) == 0) return 0; | |
1941 | ||
1942 | $match_part = implode(" OR ", $cat_feeds); | |
1943 | ||
1944 | $result = db_query($link, "SELECT COUNT(int_id) AS unread | |
14073c0a AD |
1945 | FROM ttrss_user_entries,ttrss_entries |
1946 | WHERE unread = true AND ($match_part) AND id = ref_id | |
1947 | AND $age_qpart AND owner_uid = " . $_SESSION["uid"]); | |
bba7c4bf AD |
1948 | |
1949 | $unread = 0; | |
1950 | ||
1951 | # this needs to be rewritten | |
1952 | while ($line = db_fetch_assoc($result)) { | |
1953 | $unread += $line["unread"]; | |
1954 | } | |
1955 | ||
1956 | return $unread; | |
1957 | } else if ($cat == -1) { | |
2d24f032 | 1958 | return getFeedUnread($link, -1) + getFeedUnread($link, -2) + getFeedUnread($link, -3); |
bba7c4bf | 1959 | } else if ($cat == -2) { |
f295c368 | 1960 | |
bba7c4bf AD |
1961 | $rv = getLabelCounters($link, false, true); |
1962 | $ctr = 0; | |
f295c368 | 1963 | |
bba7c4bf AD |
1964 | foreach (array_keys($rv) as $k) { |
1965 | if ($k < -10) { | |
1966 | $ctr += $rv[$k]["counter"]; | |
1967 | } | |
1968 | } | |
f295c368 | 1969 | |
bba7c4bf | 1970 | return $ctr; |
f295c368 | 1971 | } |
f295c368 AD |
1972 | } |
1973 | ||
14073c0a AD |
1974 | function getMaxAgeSubquery($days = COUNTERS_MAX_AGE) { |
1975 | if (DB_TYPE == "pgsql") { | |
1976 | return "ttrss_entries.date_entered > | |
1977 | NOW() - INTERVAL '$days days'"; | |
1978 | } else { | |
1979 | return "ttrss_entries.date_entered > | |
1980 | DATE_SUB(NOW(), INTERVAL $days DAY)"; | |
1981 | } | |
1982 | } | |
1983 | ||
f295c368 | 1984 | function getFeedUnread($link, $feed, $is_cat = false) { |
a9cb1f83 | 1985 | $n_feed = sprintf("%d", $feed); |
f295c368 | 1986 | |
14073c0a AD |
1987 | $age_qpart = getMaxAgeSubquery(); |
1988 | ||
f295c368 | 1989 | if ($is_cat) { |
831ff047 | 1990 | return getCategoryUnread($link, $n_feed); |
f295c368 | 1991 | } else if ($n_feed == -1) { |
a9cb1f83 | 1992 | $match_part = "marked = true"; |
e4f4b46f AD |
1993 | } else if ($n_feed == -2) { |
1994 | $match_part = "published = true"; | |
2d24f032 AD |
1995 | } else if ($n_feed == -3) { |
1996 | $match_part = "unread = true"; | |
1997 | ||
c1d7e6c3 AD |
1998 | $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE"); |
1999 | ||
2d24f032 | 2000 | if (DB_TYPE == "pgsql") { |
c1d7e6c3 | 2001 | $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; |
2d24f032 | 2002 | } else { |
c1d7e6c3 | 2003 | $match_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; |
2d24f032 AD |
2004 | } |
2005 | ||
4919fb42 | 2006 | } else if ($n_feed > 0) { |
831ff047 | 2007 | |
e8b8485f AD |
2008 | $result = db_query($link, "SELECT id FROM ttrss_feeds |
2009 | WHERE parent_feed = '$n_feed' | |
318260cc | 2010 | AND hidden = false |
4919fb42 | 2011 | AND owner_uid = " . $_SESSION["uid"]); |
831ff047 AD |
2012 | |
2013 | if (db_num_rows($result) > 0) { | |
4919fb42 | 2014 | |
831ff047 AD |
2015 | $linked_feeds = array(); |
2016 | while ($line = db_fetch_assoc($result)) { | |
2017 | array_push($linked_feeds, "feed_id = " . $line["id"]); | |
2018 | } | |
e8b8485f AD |
2019 | |
2020 | array_push($linked_feeds, "feed_id = $n_feed"); | |
831ff047 AD |
2021 | |
2022 | $match_part = implode(" OR ", $linked_feeds); | |
2023 | ||
4919fb42 | 2024 | $result = db_query($link, "SELECT COUNT(int_id) AS unread |
14073c0a AD |
2025 | FROM ttrss_user_entries,ttrss_entries |
2026 | WHERE unread = true AND | |
2027 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
2028 | $age_qpart AND | |
2029 | ($match_part) AND | |
2030 | owner_uid = " . $_SESSION["uid"]); | |
4919fb42 AD |
2031 | |
2032 | $unread = 0; | |
2033 | ||
2034 | # this needs to be rewritten | |
2035 | while ($line = db_fetch_assoc($result)) { | |
2036 | $unread += $line["unread"]; | |
2037 | } | |
2038 | ||
2039 | return $unread; | |
2040 | ||
831ff047 AD |
2041 | } else { |
2042 | $match_part = "feed_id = '$n_feed'"; | |
2043 | } | |
a9cb1f83 | 2044 | } else if ($feed < -10) { |
318260cc | 2045 | |
a9cb1f83 AD |
2046 | $label_id = -$feed - 11; |
2047 | ||
2048 | $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE | |
2049 | id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); | |
2050 | ||
2051 | $match_part = db_fetch_result($result, 0, "sql_exp"); | |
2052 | } | |
2053 | ||
2054 | if ($match_part) { | |
2055 | ||
2056 | $result = db_query($link, "SELECT count(int_id) AS unread | |
88040f57 AD |
2057 | FROM ttrss_user_entries,ttrss_feeds,ttrss_entries WHERE |
2058 | ttrss_user_entries.feed_id = ttrss_feeds.id AND | |
2059 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
cfb02131 | 2060 | ttrss_feeds.hidden = false AND |
14073c0a | 2061 | $age_qpart AND |
88040f57 | 2062 | unread = true AND ($match_part) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); |
a9cb1f83 AD |
2063 | |
2064 | } else { | |
2065 | ||
2066 | $result = db_query($link, "SELECT COUNT(post_int_id) AS unread | |
14073c0a AD |
2067 | FROM ttrss_tags,ttrss_user_entries,ttrss_entries |
2068 | WHERE tag_name = '$feed' AND post_int_id = int_id AND ref_id = id | |
2069 | AND unread = true AND $age_qpart AND | |
a9cb1f83 AD |
2070 | ttrss_tags.owner_uid = " . $_SESSION["uid"]); |
2071 | } | |
2072 | ||
2073 | $unread = db_fetch_result($result, 0, "unread"); | |
cfb02131 | 2074 | |
a9cb1f83 AD |
2075 | return $unread; |
2076 | } | |
2077 | ||
2078 | /* FIXME this needs reworking */ | |
2079 | ||
f3acc32e AD |
2080 | function getGlobalUnread($link, $user_id = false) { |
2081 | ||
2082 | if (!$user_id) { | |
2083 | $user_id = $_SESSION["uid"]; | |
2084 | } | |
2085 | ||
14073c0a AD |
2086 | $age_qpart = getMaxAgeSubquery(); |
2087 | ||
3831db41 | 2088 | $result = db_query($link, "SELECT count(ttrss_entries.id) as c_id FROM ttrss_entries,ttrss_user_entries,ttrss_feeds |
a9cb1f83 | 2089 | WHERE unread = true AND |
3831db41 | 2090 | ttrss_user_entries.feed_id = ttrss_feeds.id AND |
a9cb1f83 | 2091 | ttrss_user_entries.ref_id = ttrss_entries.id AND |
3831db41 | 2092 | hidden = false AND |
14073c0a | 2093 | $age_qpart AND |
f3acc32e | 2094 | ttrss_user_entries.owner_uid = '$user_id'"); |
a9cb1f83 AD |
2095 | $c_id = db_fetch_result($result, 0, "c_id"); |
2096 | return $c_id; | |
2097 | } | |
2098 | ||
2099 | function getGlobalCounters($link, $global_unread = -1) { | |
2100 | if ($global_unread == -1) { | |
2101 | $global_unread = getGlobalUnread($link); | |
2102 | } | |
7bf7e4d3 AD |
2103 | print "<counter type=\"global\" id='global-unread' |
2104 | counter='$global_unread'/>"; | |
2105 | ||
2106 | $result = db_query($link, "SELECT COUNT(id) AS fn FROM | |
2107 | ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); | |
2108 | ||
2109 | $subscribed_feeds = db_fetch_result($result, 0, "fn"); | |
2110 | ||
2111 | print "<counter type=\"global\" id='subscribed-feeds' | |
2112 | counter='$subscribed_feeds'/>"; | |
2113 | ||
a9cb1f83 AD |
2114 | } |
2115 | ||
2116 | function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
2117 | ||
2118 | if ($smart_mode) { | |
2119 | if (!$_SESSION["tctr_last_value"]) { | |
2120 | $_SESSION["tctr_last_value"] = array(); | |
2121 | } | |
2122 | } | |
2123 | ||
2124 | $old_counters = $_SESSION["tctr_last_value"]; | |
2125 | ||
2126 | $tctrs_modified = false; | |
2127 | ||
2128 | /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
2129 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE | |
2130 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
2131 | ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND | |
2132 | post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name | |
2133 | UNION | |
2134 | select tag_name,0 as count FROM ttrss_tags | |
2135 | WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */ | |
2136 | ||
14073c0a AD |
2137 | $age_qpart = getMaxAgeSubquery(); |
2138 | ||
a9cb1f83 | 2139 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) |
14073c0a AD |
2140 | FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id |
2141 | AND ref_id = id AND $age_qpart | |
a9cb1f83 | 2142 | AND unread = true)) AS count FROM ttrss_tags |
ef1ac7c7 AD |
2143 | WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name |
2144 | ORDER BY count DESC LIMIT 55"); | |
a9cb1f83 AD |
2145 | |
2146 | $tags = array(); | |
2147 | ||
2148 | while ($line = db_fetch_assoc($result)) { | |
2149 | $tags[$line["tag_name"]] += $line["count"]; | |
2150 | } | |
2151 | ||
2152 | foreach (array_keys($tags) as $tag) { | |
2153 | $unread = $tags[$tag]; | |
2154 | ||
2155 | $tag = htmlspecialchars($tag); | |
2156 | ||
2157 | if (!$smart_mode || $old_counters[$tag] != $unread) { | |
2158 | $old_counters[$tag] = $unread; | |
2159 | $tctrs_modified = true; | |
2160 | print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>"; | |
2161 | } | |
2162 | ||
2163 | } | |
2164 | ||
2165 | if ($smart_mode && $tctrs_modified) { | |
2166 | $_SESSION["tctr_last_value"] = $old_counters; | |
2167 | } | |
2168 | ||
2169 | } | |
2170 | ||
ef393de7 | 2171 | function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) { |
a9cb1f83 | 2172 | |
14073c0a AD |
2173 | $age_qpart = getMaxAgeSubquery(); |
2174 | ||
a9cb1f83 AD |
2175 | if ($smart_mode) { |
2176 | if (!$_SESSION["lctr_last_value"]) { | |
2177 | $_SESSION["lctr_last_value"] = array(); | |
2178 | } | |
2179 | } | |
2180 | ||
ef393de7 AD |
2181 | $ret_arr = array(); |
2182 | ||
a9cb1f83 AD |
2183 | $old_counters = $_SESSION["lctr_last_value"]; |
2184 | $lctrs_modified = false; | |
2185 | ||
2d24f032 | 2186 | $count = getFeedUnread($link, -1); |
a9cb1f83 | 2187 | |
ef393de7 AD |
2188 | if (!$ret_mode) { |
2189 | print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>"; | |
2190 | } else { | |
2191 | $ret_arr["-1"]["counter"] = $count; | |
bba7c4bf | 2192 | $ret_arr["-1"]["description"] = __("Starred articles"); |
ef393de7 | 2193 | } |
a9cb1f83 | 2194 | |
2d24f032 | 2195 | $count = getFeedUnread($link, -2); |
e4f4b46f AD |
2196 | |
2197 | if (!$ret_mode) { | |
2198 | print "<counter type=\"label\" id=\"-2\" counter=\"$count\"/>"; | |
2199 | } else { | |
2200 | $ret_arr["-2"]["counter"] = $count; | |
bba7c4bf | 2201 | $ret_arr["-2"]["description"] = __("Published articles"); |
e4f4b46f AD |
2202 | } |
2203 | ||
2d24f032 AD |
2204 | $count = getFeedUnread($link, -3); |
2205 | ||
2206 | if (!$ret_mode) { | |
2207 | print "<counter type=\"label\" id=\"-3\" counter=\"$count\"/>"; | |
2208 | } else { | |
2209 | $ret_arr["-3"]["counter"] = $count; | |
2210 | $ret_arr["-3"]["description"] = __("Fresh articles"); | |
2211 | } | |
2212 | ||
e4f4b46f | 2213 | |
a9cb1f83 AD |
2214 | $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM |
2215 | ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description"); | |
2216 | ||
2217 | while ($line = db_fetch_assoc($result)) { | |
2218 | ||
2219 | $id = -$line["id"] - 11; | |
2220 | ||
ef393de7 AD |
2221 | $label_name = $line["description"]; |
2222 | ||
a9cb1f83 AD |
2223 | error_reporting (0); |
2224 | ||
88040f57 | 2225 | $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_user_entries,ttrss_entries,ttrss_feeds |
a9cb1f83 | 2226 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND |
cfb02131 | 2227 | ttrss_feeds.hidden = false AND |
14073c0a | 2228 | $age_qpart AND |
88040f57 | 2229 | ttrss_user_entries.feed_id = ttrss_feeds.id AND |
a9cb1f83 | 2230 | ttrss_user_entries.ref_id = ttrss_entries.id AND |
88040f57 | 2231 | ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); |
a9cb1f83 AD |
2232 | |
2233 | $count = db_fetch_result($tmp_result, 0, "count"); | |
2234 | ||
2235 | if (!$smart_mode || $old_counters[$id] != $count) { | |
2236 | $old_counters[$id] = $count; | |
2237 | $lctrs_modified = true; | |
ef393de7 AD |
2238 | if (!$ret_mode) { |
2239 | print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>"; | |
2240 | } else { | |
2241 | $ret_arr[$id]["counter"] = $count; | |
2242 | $ret_arr[$id]["description"] = $label_name; | |
2243 | } | |
a9cb1f83 AD |
2244 | } |
2245 | ||
2246 | error_reporting (DEFAULT_ERROR_LEVEL); | |
2247 | } | |
2248 | ||
2249 | if ($smart_mode && $lctrs_modified) { | |
2250 | $_SESSION["lctr_last_value"] = $old_counters; | |
2251 | } | |
ef393de7 AD |
2252 | |
2253 | return $ret_arr; | |
a9cb1f83 AD |
2254 | } |
2255 | ||
2256 | /* function getFeedCounter($link, $id) { | |
2257 | ||
2258 | $result = db_query($link, "SELECT | |
2259 | count(id) as count,last_error | |
2260 | FROM ttrss_entries,ttrss_user_entries,ttrss_feeds | |
2261 | WHERE feed_id = '$id' AND unread = true | |
2262 | AND ttrss_user_entries.feed_id = ttrss_feeds.id | |
2263 | AND ttrss_user_entries.ref_id = ttrss_entries.id"); | |
2264 | ||
2265 | $count = db_fetch_result($result, 0, "count"); | |
2266 | $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error")); | |
2267 | ||
2268 | print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>"; | |
2269 | } */ | |
2270 | ||
2271 | function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
2272 | ||
14073c0a AD |
2273 | $age_qpart = getMaxAgeSubquery(); |
2274 | ||
a9cb1f83 AD |
2275 | if ($smart_mode) { |
2276 | if (!$_SESSION["fctr_last_value"]) { | |
2277 | $_SESSION["fctr_last_value"] = array(); | |
2278 | } | |
2279 | } | |
2280 | ||
2281 | $old_counters = $_SESSION["fctr_last_value"]; | |
2282 | ||
1b1b8a7b | 2283 | /* $result = db_query($link, "SELECT id,last_error,parent_feed, |
fb1fb4ab | 2284 | SUBSTRING(last_updated,1,19) AS last_updated, |
a9cb1f83 AD |
2285 | (SELECT count(id) |
2286 | FROM ttrss_entries,ttrss_user_entries | |
2287 | WHERE feed_id = ttrss_feeds.id AND | |
2288 | ttrss_user_entries.ref_id = ttrss_entries.id | |
2289 | AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count | |
2290 | FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . " | |
1b1b8a7b AD |
2291 | AND parent_feed IS NULL"); */ |
2292 | ||
14073c0a AD |
2293 | $query = "SELECT ttrss_feeds.id, |
2294 | ttrss_feeds.title, | |
1b1b8a7b AD |
2295 | SUBSTRING(ttrss_feeds.last_updated,1,19) AS last_updated, |
2296 | last_error, | |
bc60fda3 | 2297 | COUNT(ttrss_entries.id) AS count |
1b1b8a7b AD |
2298 | FROM ttrss_feeds |
2299 | LEFT JOIN ttrss_user_entries ON (ttrss_user_entries.feed_id = ttrss_feeds.id | |
2300 | AND ttrss_user_entries.owner_uid = ttrss_feeds.owner_uid | |
2301 | AND ttrss_user_entries.unread = true) | |
14073c0a AD |
2302 | LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id AND |
2303 | $age_qpart) | |
2304 | WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]." | |
1b1b8a7b | 2305 | AND parent_feed IS NULL |
14073c0a | 2306 | GROUP BY ttrss_feeds.id, ttrss_feeds.title, ttrss_feeds.last_updated, last_error"; |
a9cb1f83 | 2307 | |
14073c0a | 2308 | $result = db_query($link, $query); |
a9cb1f83 AD |
2309 | $fctrs_modified = false; |
2310 | ||
fb1fb4ab AD |
2311 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); |
2312 | ||
a9cb1f83 AD |
2313 | while ($line = db_fetch_assoc($result)) { |
2314 | ||
2315 | $id = $line["id"]; | |
2316 | $count = $line["count"]; | |
2317 | $last_error = htmlspecialchars($line["last_error"]); | |
fb1fb4ab AD |
2318 | |
2319 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
2320 | $last_updated = smart_date_time(strtotime($line["last_updated"])); | |
2321 | } else { | |
2322 | $last_updated = date($short_date, strtotime($line["last_updated"])); | |
2323 | } | |
2324 | ||
588fb13b AD |
2325 | $last_updated = htmlspecialchars($last_updated); |
2326 | ||
a9cb1f83 AD |
2327 | $has_img = is_file(ICONS_DIR . "/$id.ico"); |
2328 | ||
2329 | $tmp_result = db_query($link, | |
14073c0a | 2330 | "SELECT ttrss_feeds.id,COUNT(unread) AS unread |
a9cb1f83 AD |
2331 | FROM ttrss_feeds LEFT JOIN ttrss_user_entries |
2332 | ON (ttrss_feeds.id = ttrss_user_entries.feed_id) | |
14073c0a AD |
2333 | LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id) |
2334 | WHERE parent_feed = '$id' AND $age_qpart AND unread = true GROUP BY ttrss_feeds.id"); | |
a9cb1f83 AD |
2335 | |
2336 | if (db_num_rows($tmp_result) > 0) { | |
2337 | while ($l = db_fetch_assoc($tmp_result)) { | |
2338 | $count += $l["unread"]; | |
2339 | } | |
2340 | } | |
2341 | ||
2342 | if (!$smart_mode || $old_counters[$id] != $count) { | |
2343 | $old_counters[$id] = $count; | |
2344 | $fctrs_modified = true; | |
2345 | ||
2346 | if ($last_error) { | |
2347 | $error_part = "error=\"$last_error\""; | |
2348 | } else { | |
2349 | $error_part = ""; | |
2350 | } | |
2351 | ||
2352 | if ($has_img) { | |
2353 | $has_img_part = "hi=\"$has_img\""; | |
2354 | } else { | |
2355 | $has_img_part = ""; | |
2356 | } | |
2357 | ||
fb1fb4ab | 2358 | print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part updated=\"$last_updated\"/>"; |
a9cb1f83 AD |
2359 | } |
2360 | } | |
2361 | ||
2362 | if ($smart_mode && $fctrs_modified) { | |
2363 | $_SESSION["fctr_last_value"] = $old_counters; | |
2364 | } | |
2365 | } | |
2366 | ||
1b758780 | 2367 | function get_script_dt_add() { |
34e420fb | 2368 | if (strpos(VERSION, ".99") === false) { |
1b758780 AD |
2369 | return VERSION; |
2370 | } else { | |
2371 | return time(); | |
2372 | } | |
2373 | } | |
2374 | ||
6e7f8d26 AD |
2375 | function get_pgsql_version($link) { |
2376 | $result = db_query($link, "SELECT version() AS version"); | |
2377 | $version = split(" ", db_fetch_result($result, 0, "version")); | |
2378 | return $version[1]; | |
2379 | } | |
2380 | ||
af106b0e AD |
2381 | function print_error_xml($code, $add_msg = "") { |
2382 | global $ERRORS; | |
2383 | ||
2384 | $error_msg = $ERRORS[$code]; | |
2385 | ||
2386 | if ($add_msg) { | |
2387 | $error_msg = "$error_msg; $add_msg"; | |
2388 | } | |
2389 | ||
4c2abbc1 | 2390 | print "<rpc-reply>"; |
af106b0e | 2391 | print "<error error-code=\"$code\" error-msg=\"$error_msg\"/>"; |
4c2abbc1 | 2392 | print "</rpc-reply>"; |
af106b0e | 2393 | } |
956c7629 | 2394 | |
f27de515 AD |
2395 | function subscribe_to_feed($link, $feed_link, $cat_id = 0, |
2396 | $auth_login = '', $auth_pass = '') { | |
bb0f29a4 | 2397 | |
b3dfe8ba | 2398 | # check for feed:http://url |
c91c2249 AD |
2399 | $feed_link = trim(preg_replace("/^feed:/", "", $feed_link)); |
2400 | ||
b3dfe8ba | 2401 | # check for feed://URL |
e2d84cdb | 2402 | if (strpos($feed_link, "//") === 0) { |
b3dfe8ba AD |
2403 | $feed_link = "http:$feed_link"; |
2404 | } | |
2405 | ||
c91c2249 | 2406 | if ($feed_link == "") return; |
bb0f29a4 | 2407 | |
956c7629 AD |
2408 | if ($cat_id == "0" || !$cat_id) { |
2409 | $cat_qpart = "NULL"; | |
2410 | } else { | |
2411 | $cat_qpart = "'$cat_id'"; | |
2412 | } | |
2413 | ||
2414 | $result = db_query($link, | |
2415 | "SELECT id FROM ttrss_feeds | |
2416 | WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); | |
2417 | ||
2418 | if (db_num_rows($result) == 0) { | |
2419 | ||
2420 | $result = db_query($link, | |
f27de515 AD |
2421 | "INSERT INTO ttrss_feeds |
2422 | (owner_uid,feed_url,title,cat_id, auth_login,auth_pass) | |
956c7629 | 2423 | VALUES ('".$_SESSION["uid"]."', '$feed_link', |
f27de515 | 2424 | '[Unknown]', $cat_qpart, '$auth_login', '$auth_pass')"); |
956c7629 AD |
2425 | |
2426 | $result = db_query($link, | |
2427 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' | |
f27de515 | 2428 | AND owner_uid = " . $_SESSION["uid"]); |
956c7629 AD |
2429 | |
2430 | $feed_id = db_fetch_result($result, 0, "id"); | |
2431 | ||
2432 | if ($feed_id) { | |
2433 | update_rss_feed($link, $feed_link, $feed_id, true); | |
2434 | } | |
2435 | ||
2436 | return true; | |
2437 | } else { | |
2438 | return false; | |
2439 | } | |
2440 | } | |
2441 | ||
673d54ca AD |
2442 | function print_feed_select($link, $id, $default_id = "", |
2443 | $attributes = "", $include_all_feeds = true) { | |
2444 | ||
79f3553b | 2445 | print "<select id=\"$id\" name=\"$id\" $attributes>"; |
673d54ca | 2446 | if ($include_all_feeds) { |
89cb787e | 2447 | print "<option value=\"0\">".__('All feeds')."</option>"; |
673d54ca AD |
2448 | } |
2449 | ||
2450 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2451 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2452 | ||
2453 | if (db_num_rows($result) > 0 && $include_all_feeds) { | |
2454 | print "<option disabled>--------</option>"; | |
2455 | } | |
2456 | ||
2457 | while ($line = db_fetch_assoc($result)) { | |
2458 | if ($line["id"] == $default_id) { | |
2459 | $is_selected = "selected"; | |
2460 | } else { | |
2461 | $is_selected = ""; | |
2462 | } | |
79f3553b | 2463 | printf("<option $is_selected value='%d'>%s</option>", |
47439031 | 2464 | $line["id"], htmlspecialchars($line["title"])); |
673d54ca AD |
2465 | } |
2466 | ||
2467 | print "</select>"; | |
2468 | } | |
2469 | ||
2470 | function print_feed_cat_select($link, $id, $default_id = "", | |
2471 | $attributes = "", $include_all_cats = true) { | |
2472 | ||
79f3553b | 2473 | print "<select id=\"$id\" name=\"$id\" $attributes>"; |
673d54ca AD |
2474 | |
2475 | if ($include_all_cats) { | |
d1db26aa | 2476 | print "<option value=\"0\">".__('Uncategorized')."</option>"; |
673d54ca AD |
2477 | } |
2478 | ||
2479 | $result = db_query($link, "SELECT id,title FROM ttrss_feed_categories | |
2480 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2481 | ||
2482 | if (db_num_rows($result) > 0 && $include_all_cats) { | |
2483 | print "<option disabled>--------</option>"; | |
2484 | } | |
2485 | ||
2486 | while ($line = db_fetch_assoc($result)) { | |
2487 | if ($line["id"] == $default_id) { | |
2488 | $is_selected = "selected"; | |
2489 | } else { | |
2490 | $is_selected = ""; | |
2491 | } | |
14f69488 | 2492 | printf("<option $is_selected value='%d'>%s</option>", |
47439031 | 2493 | $line["id"], htmlspecialchars($line["title"])); |
673d54ca AD |
2494 | } |
2495 | ||
2496 | print "</select>"; | |
2497 | } | |
2498 | ||
14f69488 AD |
2499 | function checkbox_to_sql_bool($val) { |
2500 | return ($val == "on") ? "true" : "false"; | |
2501 | } | |
86b682ce AD |
2502 | |
2503 | function getFeedCatTitle($link, $id) { | |
2504 | if ($id == -1) { | |
d1db26aa | 2505 | return __("Special"); |
86b682ce | 2506 | } else if ($id < -10) { |
d1db26aa | 2507 | return __("Labels"); |
86b682ce AD |
2508 | } else if ($id > 0) { |
2509 | $result = db_query($link, "SELECT ttrss_feed_categories.title | |
2510 | FROM ttrss_feeds, ttrss_feed_categories WHERE ttrss_feeds.id = '$id' AND | |
2511 | cat_id = ttrss_feed_categories.id"); | |
2512 | if (db_num_rows($result) == 1) { | |
2513 | return db_fetch_result($result, 0, "title"); | |
2514 | } else { | |
d1db26aa | 2515 | return __("Uncategorized"); |
86b682ce AD |
2516 | } |
2517 | } else { | |
2518 | return "getFeedCatTitle($id) failed"; | |
2519 | } | |
2520 | ||
2521 | } | |
2522 | ||
2523 | function getFeedTitle($link, $id) { | |
2524 | if ($id == -1) { | |
d1db26aa | 2525 | return __("Starred articles"); |
945c243e AD |
2526 | } else if ($id == -2) { |
2527 | return __("Published articles"); | |
2d24f032 AD |
2528 | } else if ($id == -3) { |
2529 | return __("Fresh articles"); | |
86b682ce AD |
2530 | } else if ($id < -10) { |
2531 | $label_id = -10 - $id; | |
2532 | $result = db_query($link, "SELECT description FROM ttrss_labels WHERE id = '$label_id'"); | |
2533 | if (db_num_rows($result) == 1) { | |
2534 | return db_fetch_result($result, 0, "description"); | |
2535 | } else { | |
2536 | return "Unknown label ($label_id)"; | |
2537 | } | |
2538 | ||
2539 | } else if ($id > 0) { | |
2540 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$id'"); | |
2541 | if (db_num_rows($result) == 1) { | |
2542 | return db_fetch_result($result, 0, "title"); | |
2543 | } else { | |
2544 | return "Unknown feed ($id)"; | |
2545 | } | |
2546 | } else { | |
2547 | return "getFeedTitle($id) failed"; | |
2548 | } | |
2549 | ||
2550 | } | |
3dd46f19 AD |
2551 | |
2552 | function get_session_cookie_name() { | |
2553 | return ((!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid" : TTRSS_SESSION_NAME); | |
2554 | } | |
3ac2b520 AD |
2555 | |
2556 | function print_init_params($link) { | |
2557 | print "<init-params>"; | |
2558 | if ($_SESSION["stored-params"]) { | |
2559 | foreach (array_keys($_SESSION["stored-params"]) as $key) { | |
5f57b06d AD |
2560 | if ($key) { |
2561 | $value = htmlspecialchars($_SESSION["stored-params"][$key]); | |
2562 | print "<param key=\"$key\" value=\"$value\"/>"; | |
2563 | } | |
3ac2b520 AD |
2564 | } |
2565 | } | |
2566 | ||
2567 | print "<param key=\"daemon_enabled\" value=\"" . ENABLE_UPDATE_DAEMON . "\"/>"; | |
2568 | print "<param key=\"feeds_frame_refresh\" value=\"" . FEEDS_FRAME_REFRESH . "\"/>"; | |
0d51e25d | 2569 | print "<param key=\"daemon_refresh_only\" value=\"" . DAEMON_REFRESH_ONLY . "\"/>"; |
3ac2b520 AD |
2570 | |
2571 | print "<param key=\"on_catchup_show_next_feed\" value=\"" . | |
2572 | get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED") . "\"/>"; | |
2573 | ||
e8bd0da9 | 2574 | print "<param key=\"hide_read_feeds\" value=\"" . |
465ff90b | 2575 | (int) get_pref($link, "HIDE_READ_FEEDS") . "\"/>"; |
e8bd0da9 | 2576 | |
c9268ed5 | 2577 | print "<param key=\"feeds_sort_by_unread\" value=\"" . |
465ff90b | 2578 | (int) get_pref($link, "FEEDS_SORT_BY_UNREAD") . "\"/>"; |
c9268ed5 | 2579 | |
f6d6e22f | 2580 | print "<param key=\"confirm_feed_catchup\" value=\"" . |
465ff90b | 2581 | (int) get_pref($link, "CONFIRM_FEED_CATCHUP") . "\"/>"; |
f6d6e22f | 2582 | |
ac7bcd71 | 2583 | print "<param key=\"cdm_auto_catchup\" value=\"" . |
465ff90b | 2584 | (int) get_pref($link, "CDM_AUTO_CATCHUP") . "\"/>"; |
ac7bcd71 | 2585 | |
8e9c121b AD |
2586 | print "<param key=\"icons_url\" value=\"" . ICONS_URL . "\"/>"; |
2587 | ||
be0801a1 AD |
2588 | print "<param key=\"cookie_lifetime\" value=\"" . SESSION_COOKIE_LIFETIME . "\"/>"; |
2589 | ||
40496720 AD |
2590 | print "<param key=\"default_view_mode\" value=\"" . |
2591 | get_pref($link, "_DEFAULT_VIEW_MODE") . "\"/>"; | |
2592 | ||
2593 | print "<param key=\"default_view_limit\" value=\"" . | |
465ff90b | 2594 | (int) get_pref($link, "_DEFAULT_VIEW_LIMIT") . "\"/>"; |
40496720 | 2595 | |
fe8d2059 AD |
2596 | print "<param key=\"prefs_active_tab\" value=\"" . |
2597 | get_pref($link, "_PREFS_ACTIVE_TAB") . "\"/>"; | |
2598 | ||
465ff90b AD |
2599 | print "<param key=\"infobox_disable_overlay\" value=\"" . |
2600 | get_pref($link, "_INFOBOX_DISABLE_OVERLAY") . "\"/>"; | |
2601 | ||
527c3bf0 AD |
2602 | print "<param key=\"icons_location\" value=\"" . |
2603 | ICONS_URL . "\"/>"; | |
2604 | ||
3ac2b520 AD |
2605 | print "</init-params>"; |
2606 | } | |
f54f515f AD |
2607 | |
2608 | function print_runtime_info($link) { | |
2609 | print "<runtime-info>"; | |
71ad883b AD |
2610 | if (ENABLE_UPDATE_DAEMON) { |
2611 | print "<param key=\"daemon_is_running\" value=\"". | |
2612 | sprintf("%d", file_is_locked("update_daemon.lock")) . "\"/>"; | |
8e00ae9b | 2613 | |
784b47a3 | 2614 | if ($_SESSION["daemon_stamp_check"] + 600 < time()) { |
8e00ae9b AD |
2615 | |
2616 | $stamp = (int)read_stampfile("update_daemon.stamp"); | |
2617 | ||
2618 | if ($stamp) { | |
2619 | if ($stamp + 86400*3 < time()) { | |
2620 | print "<param key=\"daemon_stamp_ok\" value=\"0\"/>"; | |
2621 | } else { | |
2622 | print "<param key=\"daemon_stamp_ok\" value=\"1\"/>"; | |
2623 | } | |
2624 | ||
2625 | $stamp_fmt = date("Y.m.d, G:i", $stamp); | |
2626 | ||
2627 | print "<param key=\"daemon_stamp\" value=\"$stamp_fmt\"/>"; | |
2628 | } | |
2629 | ||
2630 | $_SESSION["daemon_stamp_check"] = time(); | |
2631 | } | |
71ad883b | 2632 | } |
8e00ae9b | 2633 | |
d9fa39f1 AD |
2634 | if (CHECK_FOR_NEW_VERSION && $_SESSION["access_level"] >= 10) { |
2635 | ||
c04206e5 | 2636 | if ($_SESSION["last_version_check"] + 7200 < time()) { |
d9fa39f1 AD |
2637 | $new_version_details = check_for_update($link); |
2638 | ||
2639 | print "<param key=\"new_version_available\" value=\"". | |
2640 | sprintf("%d", $new_version_details != ""). "\"/>"; | |
2641 | ||
2642 | $_SESSION["last_version_check"] = time(); | |
2643 | } | |
2644 | } | |
2645 | ||
1c9df66e | 2646 | // print "<param key=\"new_version_available\" value=\"1\"/>"; |
b4507bc2 | 2647 | |
f54f515f AD |
2648 | print "</runtime-info>"; |
2649 | } | |
ef393de7 | 2650 | |
88040f57 | 2651 | function getSearchSql($search, $match_on) { |
ef393de7 | 2652 | |
88040f57 | 2653 | $search_query_part = ""; |
e20c9d88 | 2654 | |
88040f57 AD |
2655 | $keywords = split(" ", $search); |
2656 | $query_keywords = array(); | |
e20c9d88 | 2657 | |
88040f57 | 2658 | if ($match_on == "both") { |
e20c9d88 | 2659 | |
88040f57 AD |
2660 | foreach ($keywords as $k) { |
2661 | array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%') | |
2662 | OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))"); | |
2663 | } | |
e20c9d88 | 2664 | |
88040f57 | 2665 | $search_query_part = implode("AND", $query_keywords) . " AND "; |
e20c9d88 | 2666 | |
88040f57 | 2667 | } else if ($match_on == "title") { |
e20c9d88 | 2668 | |
88040f57 AD |
2669 | foreach ($keywords as $k) { |
2670 | array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))"); | |
2671 | } | |
e20c9d88 | 2672 | |
88040f57 | 2673 | $search_query_part = implode("AND", $query_keywords) . " AND "; |
e20c9d88 | 2674 | |
88040f57 AD |
2675 | } else if ($match_on == "content") { |
2676 | ||
2677 | foreach ($keywords as $k) { | |
2678 | array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))"); | |
2679 | } | |
2680 | } | |
2681 | ||
2682 | $search_query_part = implode("AND", $query_keywords); | |
2683 | ||
2684 | return $search_query_part; | |
2685 | } | |
2686 | ||
c36bf4d5 AD |
2687 | function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0) { |
2688 | ||
2689 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
c1a0b534 | 2690 | |
88040f57 AD |
2691 | if ($search) { |
2692 | ||
2693 | $search_query_part = getSearchSql($search, $match_on); | |
2694 | $search_query_part .= " AND "; | |
e20c9d88 | 2695 | |
ef393de7 AD |
2696 | } else { |
2697 | $search_query_part = ""; | |
2698 | } | |
2699 | ||
2700 | $view_query_part = ""; | |
2701 | ||
2702 | if ($view_mode == "adaptive") { | |
2703 | if ($search) { | |
2704 | $view_query_part = " "; | |
2705 | } else if ($feed != -1) { | |
f295c368 | 2706 | $unread = getFeedUnread($link, $feed, $cat_view); |
ef393de7 AD |
2707 | if ($unread > 0) { |
2708 | $view_query_part = " unread = true AND "; | |
2709 | } | |
2710 | } | |
2711 | } | |
2712 | ||
2713 | if ($view_mode == "marked") { | |
2714 | $view_query_part = " marked = true AND "; | |
2715 | } | |
2716 | ||
2717 | if ($view_mode == "unread") { | |
2718 | $view_query_part = " unread = true AND "; | |
2719 | } | |
2720 | ||
2721 | if ($limit > 0) { | |
2722 | $limit_query_part = "LIMIT " . $limit; | |
2723 | } | |
2724 | ||
2725 | $vfeed_query_part = ""; | |
2726 | ||
2727 | // override query strategy and enable feed display when searching globally | |
2728 | if ($search && $search_mode == "all_feeds") { | |
2729 | $query_strategy_part = "ttrss_entries.id > 0"; | |
2730 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
2731 | } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) { | |
2732 | $query_strategy_part = "ttrss_entries.id > 0"; | |
2733 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
2734 | id = feed_id) as feed_title,"; | |
2735 | } else if ($feed >= 0 && $search && $search_mode == "this_cat") { | |
2736 | ||
2737 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
0a6c4846 AD |
2738 | |
2739 | $tmp_result = false; | |
2740 | ||
2741 | if ($cat_view) { | |
2742 | $tmp_result = db_query($link, "SELECT id | |
2743 | FROM ttrss_feeds WHERE cat_id = '$feed'"); | |
2744 | } else { | |
2745 | $tmp_result = db_query($link, "SELECT id | |
2746 | FROM ttrss_feeds WHERE cat_id = (SELECT cat_id FROM ttrss_feeds | |
2747 | WHERE id = '$feed') AND id != '$feed'"); | |
2748 | } | |
ef393de7 AD |
2749 | |
2750 | $cat_siblings = array(); | |
2751 | ||
2752 | if (db_num_rows($tmp_result) > 0) { | |
2753 | while ($p = db_fetch_assoc($tmp_result)) { | |
2754 | array_push($cat_siblings, "feed_id = " . $p["id"]); | |
2755 | } | |
2756 | ||
2757 | $query_strategy_part = sprintf("(feed_id = %d OR %s)", | |
2758 | $feed, implode(" OR ", $cat_siblings)); | |
2759 | ||
2760 | } else { | |
2761 | $query_strategy_part = "ttrss_entries.id > 0"; | |
2762 | } | |
2763 | ||
2764 | } else if ($feed >= 0) { | |
2765 | ||
2766 | if ($cat_view) { | |
5c365f60 | 2767 | |
ef393de7 AD |
2768 | if ($feed > 0) { |
2769 | $query_strategy_part = "cat_id = '$feed'"; | |
2770 | } else { | |
2771 | $query_strategy_part = "cat_id IS NULL"; | |
2772 | } | |
2773 | ||
2774 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
5c365f60 | 2775 | |
ef393de7 AD |
2776 | } else { |
2777 | $tmp_result = db_query($link, "SELECT id | |
2778 | FROM ttrss_feeds WHERE parent_feed = '$feed' | |
2779 | ORDER BY cat_id,title"); | |
2780 | ||
2781 | $parent_ids = array(); | |
2782 | ||
2783 | if (db_num_rows($tmp_result) > 0) { | |
2784 | while ($p = db_fetch_assoc($tmp_result)) { | |
2785 | array_push($parent_ids, "feed_id = " . $p["id"]); | |
2786 | } | |
2787 | ||
2788 | $query_strategy_part = sprintf("(feed_id = %d OR %s)", | |
2789 | $feed, implode(" OR ", $parent_ids)); | |
2790 | ||
2791 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
2792 | } else { | |
2793 | $query_strategy_part = "feed_id = '$feed'"; | |
2794 | } | |
2795 | } | |
2796 | } else if ($feed == -1) { // starred virtual feed | |
2797 | $query_strategy_part = "marked = true"; | |
2798 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
e4f4b46f AD |
2799 | } else if ($feed == -2) { // published virtual feed |
2800 | $query_strategy_part = "published = true"; | |
2d24f032 AD |
2801 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
2802 | } else if ($feed == -3) { // fresh virtual feed | |
2803 | $query_strategy_part = "unread = true"; | |
2804 | ||
c1d7e6c3 AD |
2805 | $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE"); |
2806 | ||
2d24f032 | 2807 | if (DB_TYPE == "pgsql") { |
c1d7e6c3 | 2808 | $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; |
2d24f032 | 2809 | } else { |
c1d7e6c3 | 2810 | $query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; |
2d24f032 AD |
2811 | } |
2812 | ||
e4f4b46f | 2813 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
ef393de7 AD |
2814 | } else if ($feed <= -10) { // labels |
2815 | $label_id = -$feed - 11; | |
2816 | ||
2817 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
2818 | WHERE id = '$label_id'"); | |
2819 | ||
2820 | $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp"); | |
3de0261a AD |
2821 | |
2822 | if (!$query_strategy_part) { | |
2823 | return false; | |
2824 | } | |
2825 | ||
ef393de7 AD |
2826 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
2827 | } else { | |
2828 | $query_strategy_part = "id > 0"; // dumb | |
2829 | } | |
d6e5706d AD |
2830 | |
2831 | if (get_pref($link, 'REVERSE_HEADLINES')) { | |
2832 | $order_by = "updated"; | |
2833 | } else { | |
2834 | $order_by = "updated DESC"; | |
2835 | } | |
e939722a AD |
2836 | |
2837 | if ($override_order) { | |
2838 | $order_by = $override_order; | |
2839 | } | |
ef393de7 AD |
2840 | |
2841 | $feed_title = ""; | |
2842 | ||
2843 | if ($search && $search_mode == "all_feeds") { | |
b36e002f | 2844 | $feed_title = __("Search results")." ($search)"; |
ef393de7 | 2845 | } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { |
b36e002f | 2846 | $feed_title = __("Search results")." ($search, $feed)"; |
ef393de7 AD |
2847 | } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { |
2848 | $feed_title = $feed; | |
2849 | } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) { | |
2850 | ||
2851 | if ($cat_view) { | |
5c365f60 | 2852 | |
ef393de7 AD |
2853 | if ($feed != 0) { |
2854 | $result = db_query($link, "SELECT title FROM ttrss_feed_categories | |
c36bf4d5 | 2855 | WHERE id = '$feed' AND owner_uid = $owner_uid"); |
ef393de7 AD |
2856 | $feed_title = db_fetch_result($result, 0, "title"); |
2857 | } else { | |
d1db26aa | 2858 | $feed_title = __("Uncategorized"); |
ef393de7 | 2859 | } |
e1eb2147 AD |
2860 | |
2861 | if ($search) { | |
b36e002f | 2862 | $feed_title = __("Searched for")." $search ($feed_title)"; |
e1eb2147 AD |
2863 | } |
2864 | ||
ef393de7 AD |
2865 | } else { |
2866 | ||
2867 | $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds | |
c36bf4d5 | 2868 | WHERE id = '$feed' AND owner_uid = $owner_uid"); |
ef393de7 AD |
2869 | |
2870 | $feed_title = db_fetch_result($result, 0, "title"); | |
2871 | $feed_site_url = db_fetch_result($result, 0, "site_url"); | |
2872 | $last_error = db_fetch_result($result, 0, "last_error"); | |
e1eb2147 AD |
2873 | |
2874 | if ($search) { | |
b36e002f | 2875 | $feed_title = __("Searched for") . " $search ($feed_title)"; |
e1eb2147 | 2876 | } |
ef393de7 AD |
2877 | } |
2878 | ||
2879 | } else if ($feed == -1) { | |
d1db26aa | 2880 | $feed_title = __("Starred articles"); |
e4f4b46f AD |
2881 | } else if ($feed == -2) { |
2882 | $feed_title = __("Published articles"); | |
2d24f032 AD |
2883 | } else if ($feed == -3) { |
2884 | $feed_title = __("Fresh articles"); | |
ef393de7 AD |
2885 | } else if ($feed < -10) { |
2886 | $label_id = -$feed - 11; | |
2887 | $result = db_query($link, "SELECT description FROM ttrss_labels | |
2888 | WHERE id = '$label_id'"); | |
2889 | $feed_title = db_fetch_result($result, 0, "description"); | |
88040f57 AD |
2890 | |
2891 | if ($search) { | |
b36e002f | 2892 | $feed_title = __("Searched for") . " $search ($feed_title)"; |
88040f57 | 2893 | } |
ef393de7 AD |
2894 | } else { |
2895 | $feed_title = "?"; | |
2896 | } | |
2897 | ||
ef393de7 AD |
2898 | if ($feed < -10) error_reporting (0); |
2899 | ||
2900 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { | |
2901 | ||
2902 | if ($feed >= 0) { | |
2903 | $feed_kind = "Feeds"; | |
2904 | } else { | |
2905 | $feed_kind = "Labels"; | |
2906 | } | |
2907 | ||
2908 | $content_query_part = "content as content_preview,"; | |
203de776 | 2909 | |
95a82c08 AD |
2910 | if ($limit_query_part) { |
2911 | $offset_query_part = "OFFSET $offset"; | |
2912 | } | |
2913 | ||
ef393de7 | 2914 | $query = "SELECT |
1f64b1be | 2915 | guid, |
ef393de7 | 2916 | ttrss_entries.id,ttrss_entries.title, |
46921916 | 2917 | updated, |
e4f4b46f | 2918 | unread,feed_id,marked,published,link,last_read, |
ef393de7 AD |
2919 | SUBSTRING(last_read,1,19) as last_read_noms, |
2920 | $vfeed_query_part | |
2921 | $content_query_part | |
d4b4b9de AD |
2922 | SUBSTRING(updated,1,19) as updated_noms, |
2923 | author | |
ef393de7 AD |
2924 | FROM |
2925 | ttrss_entries,ttrss_user_entries,ttrss_feeds | |
2926 | WHERE | |
cfb02131 | 2927 | ttrss_feeds.hidden = false AND |
ef393de7 AD |
2928 | ttrss_user_entries.feed_id = ttrss_feeds.id AND |
2929 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
c36bf4d5 | 2930 | ttrss_user_entries.owner_uid = '$owner_uid' AND |
ef393de7 AD |
2931 | $search_query_part |
2932 | $view_query_part | |
2933 | $query_strategy_part ORDER BY $order_by | |
95a82c08 | 2934 | $limit_query_part $offset_query_part"; |
ef393de7 AD |
2935 | |
2936 | $result = db_query($link, $query); | |
2937 | ||
2938 | if ($_GET["debug"]) print $query; | |
2939 | ||
2940 | } else { | |
2941 | // browsing by tag | |
2942 | ||
2943 | $feed_kind = "Tags"; | |
2944 | ||
2945 | $result = db_query($link, "SELECT | |
1f64b1be | 2946 | guid, |
ef393de7 | 2947 | ttrss_entries.id as id,title, |
46921916 | 2948 | updated, |
ef393de7 AD |
2949 | unread,feed_id, |
2950 | marked,link,last_read, | |
2951 | SUBSTRING(last_read,1,19) as last_read_noms, | |
2952 | $vfeed_query_part | |
2953 | $content_query_part | |
2954 | SUBSTRING(updated,1,19) as updated_noms | |
2955 | FROM | |
2956 | ttrss_entries,ttrss_user_entries,ttrss_tags | |
2957 | WHERE | |
2958 | ref_id = ttrss_entries.id AND | |
c36bf4d5 | 2959 | ttrss_user_entries.owner_uid = '$owner_uid' AND |
ef393de7 AD |
2960 | post_int_id = int_id AND tag_name = '$feed' AND |
2961 | $view_query_part | |
2962 | $search_query_part | |
2963 | $query_strategy_part ORDER BY $order_by | |
2964 | $limit_query_part"); | |
2965 | } | |
2966 | ||
c7188969 | 2967 | return array($result, $feed_title, $feed_site_url, $last_error); |
ef393de7 AD |
2968 | |
2969 | } | |
2970 | ||
c36bf4d5 | 2971 | function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat, |
3baeeeca | 2972 | $search, $search_mode, $match_on) { |
18664970 AD |
2973 | |
2974 | $qfh_ret = queryFeedHeadlines($link, $feed, | |
c36bf4d5 AD |
2975 | 30, false, $is_cat, $search, $search_mode, $match_on, "updated DESC", 0, |
2976 | $owner_uid); | |
18664970 AD |
2977 | |
2978 | $result = $qfh_ret[0]; | |
59e2aab4 | 2979 | $feed_title = htmlspecialchars($qfh_ret[1]); |
18664970 AD |
2980 | $feed_site_url = $qfh_ret[2]; |
2981 | $last_error = $qfh_ret[3]; | |
2982 | ||
a5472764 | 2983 | // if (!$feed_site_url) $feed_site_url = "http://localhost/"; |
4bc64807 | 2984 | |
a5472764 AD |
2985 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?> |
2986 | <?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\"?> | |
2987 | <rss version=\"2.0\"> | |
3baeeeca AD |
2988 | <channel> |
2989 | <title>$feed_title</title> | |
4bc64807 AD |
2990 | <link>$feed_site_url</link> |
2991 | <description>Feed generated by Tiny Tiny RSS</description>"; | |
3baeeeca AD |
2992 | |
2993 | while ($line = db_fetch_assoc($result)) { | |
2994 | print "<item>"; | |
4bc64807 | 2995 | print "<guid>" . htmlspecialchars($line["guid"]) . "</guid>"; |
3baeeeca | 2996 | print "<link>" . htmlspecialchars($line["link"]) . "</link>"; |
0c3d1c68 | 2997 | |
bc976a8c | 2998 | $tags = get_article_tags($link, $line["id"], $owner_uid); |
0c3d1c68 AD |
2999 | |
3000 | foreach ($tags as $tag) { | |
3001 | print "<category>" . htmlspecialchars($tag) . "</category>"; | |
3002 | } | |
3003 | ||
3baeeeca AD |
3004 | $rfc822_date = date('r', strtotime($line["updated"])); |
3005 | ||
3006 | print "<pubDate>$rfc822_date</pubDate>"; | |
3007 | ||
3008 | print "<title>" . | |
3009 | htmlspecialchars($line["title"]) . "</title>"; | |
3010 | ||
0c3d1c68 AD |
3011 | print "<description><![CDATA[" . |
3012 | $line["content_preview"] . "]]></description>"; | |
3baeeeca AD |
3013 | |
3014 | print "</item>"; | |
3015 | } | |
3016 | ||
3017 | print "</channel></rss>"; | |
18664970 AD |
3018 | |
3019 | } | |
3020 | ||
0a6c4846 AD |
3021 | function getCategoryTitle($link, $cat_id) { |
3022 | ||
bba7c4bf AD |
3023 | if ($cat_id == -1) { |
3024 | return __("Special"); | |
3025 | } else if ($cat_id == -2) { | |
3026 | return __("Labels"); | |
0a6c4846 | 3027 | } else { |
bba7c4bf AD |
3028 | |
3029 | $result = db_query($link, "SELECT title FROM ttrss_feed_categories WHERE | |
3030 | id = '$cat_id'"); | |
3031 | ||
3032 | if (db_num_rows($result) == 1) { | |
3033 | return db_fetch_result($result, 0, "title"); | |
3034 | } else { | |
3035 | return "Uncategorized"; | |
3036 | } | |
0a6c4846 AD |
3037 | } |
3038 | } | |
3039 | ||
f738aef1 AD |
3040 | // http://ru2.php.net/strip-tags |
3041 | ||
3042 | function strip_tags_long($textstring, $allowed){ | |
3043 | while($textstring != strip_tags($textstring, $allowed)) | |
3044 | { | |
3045 | while (strlen($textstring) != 0) | |
3046 | { | |
3047 | if (strlen($textstring) > 1024) { | |
3048 | $otherlen = 1024; | |
3049 | } else { | |
3050 | $otherlen = strlen($textstring); | |
3051 | } | |
3052 | $temptext = strip_tags(substr($textstring,0,$otherlen), $allowed); | |
3053 | $safetext .= $temptext; | |
3054 | $textstring = substr_replace($textstring,'',0,$otherlen); | |
3055 | } | |
3056 | $textstring = $safetext; | |
3057 | } | |
3058 | return $textstring; | |
3059 | } | |
3060 | ||
3061 | ||
1ac0baf4 | 3062 | function sanitize_rss($link, $str, $force_strip_tags = false) { |
60452879 | 3063 | $res = $str; |
183ad07b | 3064 | |
1ac0baf4 | 3065 | if (get_pref($link, "STRIP_UNSAFE_TAGS") || $force_strip_tags) { |
f738aef1 AD |
3066 | global $tw_parser; |
3067 | global $tw_paranoya_setup; | |
3068 | ||
3069 | $res = $tw_parser->strip_tags($res, $tw_paranoya_setup); | |
3070 | ||
3071 | // $res = preg_replace("/\r\n|\n|\r/", "", $res); | |
3072 | // $res = strip_tags_long($res, "<p><a><i><em><b><strong><blockquote><br><img><div><span>"); | |
f826eee1 AD |
3073 | } |
3074 | ||
183ad07b AD |
3075 | return $res; |
3076 | } | |
b72c3ef8 | 3077 | |
9cd7c995 AD |
3078 | function send_headlines_digests($link, $limit = 100) { |
3079 | ||
1ddba275 AD |
3080 | if (!DIGEST_ENABLE) return false; |
3081 | ||
9cd7c995 | 3082 | $user_limit = DIGEST_EMAIL_LIMIT; |
5430c959 | 3083 | $days = 1; |
9cd7c995 AD |
3084 | |
3085 | print "Sending digests, batch of max $user_limit users, days = $days, headline limit = $limit\n\n"; | |
3086 | ||
3087 | if (DB_TYPE == "pgsql") { | |
3088 | $interval_query = "last_digest_sent < NOW() - INTERVAL '$days days'"; | |
3089 | } else if (DB_TYPE == "mysql") { | |
3090 | $interval_query = "last_digest_sent < DATE_SUB(NOW(), INTERVAL $days DAY)"; | |
3091 | } | |
3092 | ||
3093 | $result = db_query($link, "SELECT id,email FROM ttrss_users | |
3094 | WHERE email != '' AND (last_digest_sent IS NULL OR $interval_query)"); | |
3095 | ||
3096 | while ($line = db_fetch_assoc($result)) { | |
3097 | if (get_pref($link, 'DIGEST_ENABLE', $line['id'], false)) { | |
3098 | print "Sending digest for UID:" . $line['id'] . " - " . $line["email"] . " ... "; | |
3099 | ||
3100 | $tuple = prepare_headlines_digest($link, $line["id"], $days, $limit); | |
3101 | $digest = $tuple[0]; | |
3102 | $headlines_count = $tuple[1]; | |
3103 | ||
3104 | if ($headlines_count > 0) { | |
3105 | $rc = mail($line["login"] . " <" . $line["email"] . ">", | |
3106 | "[tt-rss] New headlines for last 24 hours", $digest, | |
3ab3c1f0 AD |
3107 | "From: " . MAIL_FROM . "\n". |
3108 | "Content-Type: text/plain; charset=\"utf-8\"\n". | |
3109 | "Content-Transfer-Encoding: 8bit\n"); | |
9cd7c995 AD |
3110 | print "RC=$rc\n"; |
3111 | db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW() | |
3112 | WHERE id = " . $line["id"]); | |
3113 | } else { | |
3114 | print "No headlines\n"; | |
3115 | } | |
3116 | } | |
3117 | } | |
3118 | ||
3119 | // $digest = prepare_headlines_digest($link, $user_id, $days, $limit); | |
3120 | ||
3121 | } | |
3122 | ||
7e3634d9 | 3123 | function prepare_headlines_digest($link, $user_id, $days = 1, $limit = 100) { |
d1db26aa | 3124 | $tmp = __("New headlines for last 24 hours, as of ") . date("Y/m/d H:m") . "\n"; |
7e3634d9 AD |
3125 | $tmp .= "=======================================================\n\n"; |
3126 | ||
3127 | if (DB_TYPE == "pgsql") { | |
9cd7c995 | 3128 | $interval_query = "ttrss_entries.date_entered > NOW() - INTERVAL '$days days'"; |
7e3634d9 AD |
3129 | } else if (DB_TYPE == "mysql") { |
3130 | $interval_query = "ttrss_entries.date_entered > DATE_SUB(NOW(), INTERVAL $days DAY)"; | |
3131 | } | |
3132 | ||
3133 | $result = db_query($link, "SELECT ttrss_entries.title, | |
3134 | ttrss_feeds.title AS feed_title, | |
3135 | date_entered, | |
3136 | link, | |
3137 | SUBSTRING(last_updated,1,19) AS last_updated | |
3138 | FROM | |
3139 | ttrss_user_entries,ttrss_entries,ttrss_feeds | |
3140 | WHERE | |
3141 | ref_id = ttrss_entries.id AND feed_id = ttrss_feeds.id | |
3dd9183c | 3142 | AND include_in_digest = true |
7e3634d9 | 3143 | AND $interval_query |
448b0abd | 3144 | AND ttrss_user_entries.owner_uid = $user_id |
7e3634d9 AD |
3145 | AND unread = true ORDER BY ttrss_feeds.title, date_entered DESC |
3146 | LIMIT $limit"); | |
3147 | ||
3148 | $cur_feed_title = ""; | |
3149 | ||
9cd7c995 AD |
3150 | $headlines_count = db_num_rows($result); |
3151 | ||
7e3634d9 AD |
3152 | while ($line = db_fetch_assoc($result)) { |
3153 | $updated = smart_date_time(strtotime($line["last_updated"])); | |
3154 | $feed_title = $line["feed_title"]; | |
3155 | ||
3156 | if ($cur_feed_title != $feed_title) { | |
3157 | $cur_feed_title = $feed_title; | |
3158 | ||
3159 | $tmp .= "$feed_title\n\n"; | |
3160 | } | |
3161 | ||
3162 | $tmp .= " * " . trim($line["title"]) . " - $updated\n"; | |
3163 | $tmp .= " " . trim($line["link"]) . "\n"; | |
3164 | $tmp .= "\n"; | |
3165 | } | |
3166 | ||
3167 | $tmp .= "--- \n"; | |
d1db26aa | 3168 | $tmp .= __("You have been sent this email because you have enabled daily digests in Tiny Tiny RSS at ") . |
dfe6f833 | 3169 | DIGEST_HOSTNAME . "\n". |
d1db26aa | 3170 | __("To unsubscribe, visit your configuration options or contact instance owner.\n"); |
7e3634d9 AD |
3171 | |
3172 | ||
9cd7c995 | 3173 | return array($tmp, $headlines_count); |
7e3634d9 AD |
3174 | } |
3175 | ||
d9fa39f1 | 3176 | function check_for_update($link, $brief_fmt = true) { |
b72c3ef8 AD |
3177 | $releases_feed = "http://tt-rss.spb.ru/releases.rss"; |
3178 | ||
3179 | if (!CHECK_FOR_NEW_VERSION || $_SESSION["access_level"] < 10) { | |
3180 | return; | |
3181 | } | |
3182 | ||
3183 | error_reporting(0); | |
f67d9754 AD |
3184 | if (ENABLE_SIMPLEPIE) { |
3185 | $rss = new SimplePie(); | |
3186 | $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT); | |
3187 | $rss->set_timeout(MAGPIE_FETCH_TIME_OUT); | |
3188 | $rss->set_feed_url($fetch_url); | |
3189 | $rss->set_output_encoding('UTF-8'); | |
3190 | $rss->init(); | |
3191 | } else { | |
3192 | $rss = fetch_rss($releases_feed); | |
3193 | } | |
b72c3ef8 AD |
3194 | error_reporting (DEFAULT_ERROR_LEVEL); |
3195 | ||
3196 | if ($rss) { | |
3197 | ||
f67d9754 AD |
3198 | if (ENABLE_SIMPLEPIE) { |
3199 | $items = $rss->get_items(); | |
3200 | } else { | |
3201 | $items = $rss->items; | |
b72c3ef8 | 3202 | |
f67d9754 AD |
3203 | if (!$items || !is_array($items)) $items = $rss->entries; |
3204 | if (!$items || !is_array($items)) $items = $rss; | |
3205 | } | |
b72c3ef8 | 3206 | |
da412ad3 | 3207 | if (!is_array($items) || count($items) == 0) { |
b72c3ef8 | 3208 | return; |
da412ad3 | 3209 | } |
b72c3ef8 | 3210 | |
a41d2c65 | 3211 | $latest_item = $items[0]; |
b72c3ef8 | 3212 | |
f67d9754 AD |
3213 | if (ENABLE_SIMPLEPIE) { |
3214 | $last_title = $latest_item->get_title(); | |
3215 | } else { | |
3216 | $last_title = $latest_item["title"]; | |
3217 | } | |
b72c3ef8 | 3218 | |
f67d9754 AD |
3219 | $latest_version = trim(preg_replace("/(Milestone)|(completed)/", "", $last_title)); |
3220 | ||
3221 | if (ENABLE_SIMPLEPIE) { | |
dcf7fd08 AD |
3222 | $release_url = sanitize_rss($link, $latest_item->get_link()); |
3223 | $content = sanitize_rss($link, $latest_item->get_description()); | |
f67d9754 AD |
3224 | } else { |
3225 | $release_url = sanitize_rss($link, $latest_item["link"]); | |
3226 | $content = sanitize_rss($link, $latest_item["description"]); | |
3227 | } | |
48e1a342 | 3228 | |
a41d2c65 | 3229 | if (version_compare(VERSION, $latest_version) == -1) { |
d9fa39f1 | 3230 | if ($brief_fmt) { |
0d32b41e | 3231 | return format_notice("<a href=\"javascript:showBlockElement('milestoneDetails')\"> |
d9fa39f1 | 3232 | New version of Tiny-Tiny RSS ($latest_version) is available (click for details)</a> |
0d32b41e | 3233 | <div id=\"milestoneDetails\">$content</div>"); |
d9fa39f1 | 3234 | } else { |
92625568 AD |
3235 | return "New version of Tiny-Tiny RSS ($latest_version) is available: |
3236 | <div class='milestoneDetails'>$content</div> | |
3237 | Visit <a target=\"_new\" href=\"http://tt-rss.spb.ru/\">official site</a> for | |
3238 | download and update information."; | |
d9fa39f1 AD |
3239 | } |
3240 | ||
da412ad3 | 3241 | } |
b72c3ef8 AD |
3242 | } |
3243 | } | |
472782e8 | 3244 | |
18eddb2c AD |
3245 | function markArticlesById($link, $ids, $cmode) { |
3246 | ||
3247 | $tmp_ids = array(); | |
3248 | ||
3249 | foreach ($ids as $id) { | |
3250 | array_push($tmp_ids, "ref_id = '$id'"); | |
3251 | } | |
3252 | ||
3253 | $ids_qpart = join(" OR ", $tmp_ids); | |
3254 | ||
3255 | if ($cmode == 0) { | |
3256 | db_query($link, "UPDATE ttrss_user_entries SET | |
3257 | marked = false,last_read = NOW() | |
3258 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3259 | } else if ($cmode == 1) { | |
3260 | db_query($link, "UPDATE ttrss_user_entries SET | |
3261 | marked = true | |
3262 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3263 | } else { | |
3264 | db_query($link, "UPDATE ttrss_user_entries SET | |
3265 | marked = NOT marked,last_read = NOW() | |
3266 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3267 | } | |
3268 | } | |
3269 | ||
e4f4b46f AD |
3270 | function publishArticlesById($link, $ids, $cmode) { |
3271 | ||
3272 | $tmp_ids = array(); | |
3273 | ||
3274 | foreach ($ids as $id) { | |
3275 | array_push($tmp_ids, "ref_id = '$id'"); | |
3276 | } | |
3277 | ||
3278 | $ids_qpart = join(" OR ", $tmp_ids); | |
3279 | ||
3280 | if ($cmode == 0) { | |
3281 | db_query($link, "UPDATE ttrss_user_entries SET | |
3282 | published = false,last_read = NOW() | |
3283 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3284 | } else if ($cmode == 1) { | |
3285 | db_query($link, "UPDATE ttrss_user_entries SET | |
3286 | published = true | |
3287 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3288 | } else { | |
3289 | db_query($link, "UPDATE ttrss_user_entries SET | |
3290 | published = NOT published,last_read = NOW() | |
3291 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3292 | } | |
3293 | } | |
3294 | ||
472782e8 AD |
3295 | function catchupArticlesById($link, $ids, $cmode) { |
3296 | ||
3297 | $tmp_ids = array(); | |
3298 | ||
3299 | foreach ($ids as $id) { | |
3300 | array_push($tmp_ids, "ref_id = '$id'"); | |
3301 | } | |
3302 | ||
3303 | $ids_qpart = join(" OR ", $tmp_ids); | |
3304 | ||
3305 | if ($cmode == 0) { | |
3306 | db_query($link, "UPDATE ttrss_user_entries SET | |
3307 | unread = false,last_read = NOW() | |
3308 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3309 | } else if ($cmode == 1) { | |
3310 | db_query($link, "UPDATE ttrss_user_entries SET | |
3311 | unread = true | |
3312 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3313 | } else { | |
3314 | db_query($link, "UPDATE ttrss_user_entries SET | |
3315 | unread = NOT unread,last_read = NOW() | |
3316 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3317 | } | |
3318 | } | |
3319 | ||
e097e8be AD |
3320 | function catchupArticleById($link, $id, $cmode) { |
3321 | ||
3322 | if ($cmode == 0) { | |
3323 | db_query($link, "UPDATE ttrss_user_entries SET | |
3324 | unread = false,last_read = NOW() | |
3325 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
3326 | } else if ($cmode == 1) { | |
3327 | db_query($link, "UPDATE ttrss_user_entries SET | |
3328 | unread = true | |
3329 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
3330 | } else { | |
3331 | db_query($link, "UPDATE ttrss_user_entries SET | |
3332 | unread = NOT unread,last_read = NOW() | |
3333 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
3334 | } | |
3335 | } | |
3336 | ||
1f64b1be AD |
3337 | function make_guid_from_title($title) { |
3338 | return preg_replace("/[ \"\',.:;]/", "-", | |
fefef828 | 3339 | mb_strtolower(strip_tags($title), 'utf-8')); |
1f64b1be AD |
3340 | } |
3341 | ||
11befbb2 AD |
3342 | function print_headline_subtoolbar($link, $feed_site_url, $feed_title, |
3343 | $bottom = false, $rtl_content = false, $feed_id = 0, | |
3344 | $is_cat = false, $search = false, $match_on = false, | |
95a82c08 | 3345 | $search_mode = false, $offset = 0, $limit = 0) { |
11befbb2 | 3346 | |
e6c115b2 AD |
3347 | $user_page_offset = $offset + 1; |
3348 | ||
11befbb2 AD |
3349 | if (!$bottom) { |
3350 | $class = "headlinesSubToolbar"; | |
3351 | $tid = "headlineActionsTop"; | |
3352 | } else { | |
3353 | $class = "headlinesSubToolbar"; | |
3354 | $tid = "headlineActionsBottom"; | |
3355 | } | |
3356 | ||
3357 | print "<table class=\"$class\" id=\"$tid\" | |
3358 | width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>"; | |
3359 | ||
3360 | if ($rtl_content) { | |
3361 | $rtl_cpart = "RTL"; | |
3362 | } else { | |
3363 | $rtl_cpart = ""; | |
3364 | } | |
3365 | ||
e6c115b2 AD |
3366 | $page_prev_link = "javascript:viewFeedGoPage(-1)"; |
3367 | $page_next_link = "javascript:viewFeedGoPage(1)"; | |
3368 | $page_first_link = "javascript:viewFeedGoPage(0)"; | |
203de776 | 3369 | |
eb28b131 AD |
3370 | $catchup_page_link = "javascript:catchupPage()"; |
3371 | $catchup_feed_link = "javascript:catchupCurrentFeed()"; | |
a5ae125a | 3372 | $catchup_sel_link = "javascript:catchupSelection()"; |
c6008b62 | 3373 | |
11befbb2 AD |
3374 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { |
3375 | ||
c6008b62 AD |
3376 | $sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)"; |
3377 | $sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)"; | |
3378 | $sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)"; | |
11befbb2 | 3379 | |
c6008b62 AD |
3380 | $tog_unread_link = "javascript:selectionToggleUnread()"; |
3381 | $tog_marked_link = "javascript:selectionToggleMarked()"; | |
e4f4b46f | 3382 | $tog_published_link = "javascript:selectionTogglePublished()"; |
11befbb2 | 3383 | |
c6008b62 | 3384 | } else { |
11befbb2 | 3385 | |
c6008b62 AD |
3386 | $sel_all_link = "javascript:cdmSelectArticles('all')"; |
3387 | $sel_unread_link = "javascript:cdmSelectArticles('unread')"; | |
3388 | $sel_none_link = "javascript:cdmSelectArticles('none')"; | |
3389 | ||
3390 | $tog_unread_link = "javascript:selectionToggleUnread(true)"; | |
3391 | $tog_marked_link = "javascript:selectionToggleMarked(true)"; | |
e4f4b46f | 3392 | $tog_published_link = "javascript:selectionTogglePublished(true)"; |
c6008b62 AD |
3393 | |
3394 | } | |
3395 | ||
d420f2ee | 3396 | if (strpos($_SESSION["client.userAgent"], "MSIE") === false) { |
c6008b62 | 3397 | |
2dd2c13b AD |
3398 | print "<td class=\"headlineActions$rtl_cpart\"> |
3399 | <ul class=\"headlineDropdownMenu\"> | |
3400 | <li class=\"top2\"> | |
3692e98f | 3401 | ".__('Select:')." |
1025ad87 AD |
3402 | <a href=\"$sel_all_link\">".__('All')."</a>, |
3403 | <a href=\"$sel_unread_link\">".__('Unread')."</a>, | |
3404 | <a href=\"$sel_none_link\">".__('None')."</a></li> | |
2dd2c13b | 3405 | <li class=\"vsep\"> </li> |
89cb787e | 3406 | <li class=\"top\">".__('Toggle')."<ul> |
9cc600d1 | 3407 | <li onclick=\"$tog_unread_link\">".__('Unread')."</li> |
e4f4b46f AD |
3408 | <li onclick=\"$tog_marked_link\">".__('Starred')."</li> |
3409 | <li onclick=\"$tog_published_link\">".__('Published')."</li> | |
3410 | </ul></li> | |
2dd2c13b | 3411 | <li class=\"vsep\"> </li> |
1025ad87 | 3412 | <li class=\"top\"><a href=\"$catchup_page_link\">".__('Mark as read')."</a><ul> |
a5ae125a | 3413 | <li onclick=\"$catchup_sel_link\">".__('Selection')."</li> |
8be83f42 AD |
3414 | <!-- <li onclick=\"$catchup_page_link\">".__('This page')."</li> --> |
3415 | <li><span class=\"insensitive\">--------</span></li> | |
3416 | <li onclick=\"catchupRelativeToArticle(0)\">".__("Above active article")."</li> | |
3417 | <li onclick=\"catchupRelativeToArticle(1)\">".__("Below active article")."</li> | |
3418 | <li><span class=\"insensitive\">--------</span></li> | |
1025ad87 | 3419 | <li onclick=\"$catchup_feed_link\">".__('Entire feed')."</li></ul></li> |
237ec2ad | 3420 | "; |
95a82c08 | 3421 | |
237ec2ad AD |
3422 | $enable_pagination = get_pref($link, "_PREFS_ENABLE_PAGINATION"); |
3423 | ||
3424 | if ($limit != 0 && !$search && $enable_pagination) { | |
95a82c08 | 3425 | print " |
237ec2ad | 3426 | <li class=\"vsep\"> </li> |
1025ad87 AD |
3427 | <li class=\"top\"><a href=\"$page_next_link\">".__('Next page')."</a><ul> |
3428 | <li onclick=\"$page_prev_link\">".__('Previous page')."</li> | |
3429 | <li onclick=\"$page_first_link\">".__('First page')."</li></ul></li> | |
95a82c08 | 3430 | </ul>"; |
d420f2ee | 3431 | } |
95a82c08 | 3432 | |
d420f2ee | 3433 | if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) { |
237ec2ad AD |
3434 | print " |
3435 | <li class=\"vsep\"> </li> | |
3436 | <li class=\"top3\"> | |
d420f2ee AD |
3437 | <a href=\"javascript:labelFromSearch('$search', '$search_mode', |
3438 | '$match_on', '$feed_id', '$is_cat');\"> | |
b36e002f | 3439 | ".__('Convert to label')."</a></td>"; |
d420f2ee | 3440 | } |
95a82c08 | 3441 | print " |
2dd2c13b AD |
3442 | </td>"; |
3443 | ||
3444 | } else { | |
e6c115b2 AD |
3445 | // old style subtoolbar: |
3446 | ||
2dd2c13b | 3447 | print "<td class=\"headlineActions$rtl_cpart\">". |
d1db26aa | 3448 | __('Select:')." |
1025ad87 AD |
3449 | <a href=\"$sel_all_link\">".__('All')."</a>, |
3450 | <a href=\"$sel_unread_link\">".__('Unread')."</a>, | |
3451 | <a href=\"$sel_none_link\">".__('None')."</a> | |
2dd2c13b | 3452 | ". |
1025ad87 AD |
3453 | __('Toggle:')." <a href=\"$tog_unread_link\">".__('Unread')."</a>, |
3454 | <a href=\"$tog_marked_link\">".__('Starred')."</a> | |
2dd2c13b | 3455 | ". |
d1db26aa | 3456 | __('Mark as read:')." |
1025ad87 AD |
3457 | <a href=\"#\" onclick=\"$catchup_page_link\">".__('Page')."</a>, |
3458 | <a href=\"#\" onclick=\"$catchup_feed_link\">".__('Feed')."</a>"; | |
d420f2ee AD |
3459 | |
3460 | if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) { | |
3461 | ||
3462 | print " | |
3463 | <a href=\"javascript:labelFromSearch('$search', '$search_mode', | |
3464 | '$match_on', '$feed_id', '$is_cat');\"> | |
b36e002f | 3465 | ".__('Convert to label')."</a>"; |
d420f2ee AD |
3466 | } |
3467 | ||
2dd2c13b AD |
3468 | print "</td>"; |
3469 | ||
3470 | } | |
c6008b62 | 3471 | |
d420f2ee | 3472 | /* if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) { |
c6008b62 AD |
3473 | print "<td class=\"headlineActions$rtl_cpart\"> |
3474 | <a href=\"javascript:labelFromSearch('$search', '$search_mode', | |
3475 | '$match_on', '$feed_id', '$is_cat');\"> | |
d1db26aa | 3476 | ".__('Convert to Label')."</a></td>"; |
d420f2ee | 3477 | } */ |
11befbb2 AD |
3478 | |
3479 | print "<td class=\"headlineTitle$rtl_cpart\">"; | |
3480 | ||
3481 | if ($feed_site_url) { | |
3482 | if (!$bottom) { | |
3fc2eed5 | 3483 | $target = "target=\"_new\""; |
11befbb2 | 3484 | } |
02815555 AD |
3485 | print "<a $target href=\"$feed_site_url\">". |
3486 | truncate_string($feed_title,30)."</a>"; | |
11befbb2 AD |
3487 | } else { |
3488 | print $feed_title; | |
3489 | } | |
3490 | ||
3491 | if ($search) { | |
3492 | $search_q = "&q=$search&m=$match_on&smode=$search_mode"; | |
3493 | } | |
3494 | ||
e6c115b2 AD |
3495 | if ($user_page_offset > 1) { |
3496 | print " [$user_page_offset] "; | |
3497 | } | |
3498 | ||
11befbb2 | 3499 | if (!$bottom) { |
e6c115b2 | 3500 | print " |
11befbb2 AD |
3501 | <a target=\"_new\" |
3502 | href=\"backend.php?op=rss&id=$feed_id&is_cat=$is_cat$search_q\"> | |
3503 | <img class=\"noborder\" | |
1025ad87 | 3504 | alt=\"".__('Generated feed')."\" src=\"images/feed-icon-12x12.png\"> |
11befbb2 AD |
3505 | </a>"; |
3506 | } | |
3507 | ||
3508 | print "</td>"; | |
3509 | print "</tr></table>"; | |
3510 | ||
3511 | } | |
3512 | ||
bba7c4bf AD |
3513 | function printCategoryHeader($link, $cat_id, $hidden = false, $can_browse = true) { |
3514 | ||
3515 | $tmp_category = getCategoryTitle($link, $cat_id); | |
3516 | $cat_unread = getCategoryUnread($link, $cat_id); | |
3517 | ||
3518 | if ($hidden) { | |
3519 | $holder_style = "display:none;"; | |
3520 | $ellipsis = "..."; | |
3521 | } else { | |
3522 | $holder_style = ""; | |
3523 | $ellipsis = ""; | |
3524 | } | |
3525 | ||
3526 | $catctr_class = ($cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread"; | |
3527 | ||
3528 | print "<li class=\"feedCat\" id=\"FCAT-$cat_id\"> | |
3529 | <a id=\"FCATN-$cat_id\" href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>"; | |
3530 | ||
3531 | if ($can_browse) { | |
3532 | print "<a href=\"#\" onclick=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">"; | |
3533 | } else { | |
3534 | print "<span id=\"FCAP-$cat_id\">"; | |
3535 | } | |
3536 | ||
3537 | print " <span id=\"FCATCTR-$cat_id\" title=\"Click to browse category\" | |
3538 | class=\"$catctr_class\">($cat_unread)</span> $ellipsis"; | |
3539 | ||
3540 | if ($can_browse) { | |
3541 | print "</a>"; | |
3542 | } else { | |
3543 | print "</span>"; | |
3544 | } | |
3545 | ||
3546 | print "</li>"; | |
3547 | ||
3548 | print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\" style='$holder_style'>"; | |
3549 | } | |
3550 | ||
f407c086 AD |
3551 | function outputFeedList($link, $tags = false) { |
3552 | ||
3bd9a780 | 3553 | print "<ul class=\"feedList\" id=\"feedList\">"; |
f407c086 AD |
3554 | |
3555 | $owner_uid = $_SESSION["uid"]; | |
3556 | ||
cf4d339c | 3557 | /* virtual feeds */ |
f407c086 | 3558 | |
cf4d339c | 3559 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
3b086176 AD |
3560 | |
3561 | if ($_COOKIE["ttrss_vf_vclps"] == 1) { | |
bba7c4bf | 3562 | $cat_hidden = true; |
3b086176 | 3563 | } else { |
bba7c4bf | 3564 | $cat_hidden = false; |
3b086176 AD |
3565 | } |
3566 | ||
3567 | # print "<li class=\"feedCat\">".__('Special')."</li>"; | |
3568 | # print "<li id=\"feedCatHolder\" class=\"feedCatHolder\"><ul class=\"feedCatList\">"; | |
bba7c4bf AD |
3569 | # print "<li class=\"feedCat\">". |
3570 | # "<a id=\"FCATN--1\" href=\"javascript:toggleCollapseCat(-1)\">". | |
3571 | # __('Special')."</a> <span id='FCAP--1'>$ellipsis</span></li>"; | |
3572 | # | |
3573 | # print "<li id=\"feedCatHolder\" class=\"feedCatHolder\"> | |
3574 | # <ul class=\"feedCatList\" id='FCATLIST--1' style='$holder_style'>"; | |
3b086176 | 3575 | |
bba7c4bf AD |
3576 | # $cat_unread = getCategoryUnread($link, -1); |
3577 | # $tmp_category = __("Special"); | |
3578 | # $catctr_class = ($cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread"; | |
3b086176 | 3579 | |
bba7c4bf | 3580 | printCategoryHeader($link, -1, $cat_hidden, false); |
cf4d339c | 3581 | } |
f407c086 | 3582 | |
cf4d339c | 3583 | $num_starred = getFeedUnread($link, -1); |
e4f4b46f | 3584 | $num_published = getFeedUnread($link, -2); |
2d24f032 AD |
3585 | $num_fresh = getFeedUnread($link, -3); |
3586 | ||
3587 | $class = "virt"; | |
3588 | ||
3589 | if ($num_fresh > 0) $class .= "Unread"; | |
3590 | ||
3591 | printFeedEntry(-3, $class, __("Fresh articles"), $num_fresh, | |
3592 | "images/fresh.png", $link); | |
f407c086 | 3593 | |
cf4d339c | 3594 | $class = "virt"; |
f407c086 | 3595 | |
cf4d339c | 3596 | if ($num_starred > 0) $class .= "Unread"; |
f407c086 | 3597 | |
abd8a516 AD |
3598 | $is_ie = (strpos($_SESSION["client.userAgent"], "MSIE") !== false); |
3599 | ||
3600 | if ($is_ie) { | |
3601 | $mark_img_ext = "gif"; | |
3602 | } else { | |
3603 | $mark_img_ext = "png"; | |
3604 | } | |
3605 | ||
d1db26aa | 3606 | printFeedEntry(-1, $class, __("Starred articles"), $num_starred, |
abd8a516 | 3607 | "images/mark_set.$mark_img_ext", $link); |
f407c086 | 3608 | |
e4f4b46f AD |
3609 | $class = "virt"; |
3610 | ||
3611 | if ($num_published > 0) $class .= "Unread"; | |
3612 | ||
3613 | printFeedEntry(-2, $class, __("Published articles"), $num_published, | |
f5e0338d | 3614 | "images/pub_set.gif", $link); |
e4f4b46f | 3615 | |
cf4d339c | 3616 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
3bd9a780 | 3617 | print "</ul>"; |
cf4d339c | 3618 | } |
f407c086 | 3619 | |
cf4d339c | 3620 | if (!$tags) { |
f407c086 AD |
3621 | |
3622 | if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) { | |
3623 | ||
3624 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
3625 | ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description"); | |
3626 | ||
3627 | if (db_num_rows($result) > 0) { | |
3628 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
bd64489f AD |
3629 | |
3630 | if ($_COOKIE["ttrss_vf_lclps"] == 1) { | |
bba7c4bf | 3631 | $cat_hidden = true; |
bd64489f | 3632 | } else { |
bba7c4bf | 3633 | $cat_hidden = false; |
bd64489f AD |
3634 | } |
3635 | ||
bba7c4bf | 3636 | printCategoryHeader($link, -2, $cat_hidden, false); |
bd64489f | 3637 | |
bba7c4bf AD |
3638 | # print "<li class=\"feedCat\">". |
3639 | # "<a id=\"FCATN--2\" href=\"javascript:toggleCollapseCat(-2)\">". | |
3640 | # __('Labels')."</a> <span id='FCAP--2'>$ellipsis</span></li>"; | |
3641 | # | |
3642 | # print "<li id=\"feedCatHolder\" class=\"feedCatHolder\"><ul class=\"feedCatList\" id='FCATLIST--2' style='$holder_style'>"; | |
f407c086 | 3643 | } else { |
3bd9a780 | 3644 | print "<li><hr></li>"; |
f407c086 AD |
3645 | } |
3646 | } | |
3647 | ||
3648 | while ($line = db_fetch_assoc($result)) { | |
3649 | ||
3650 | error_reporting (0); | |
3651 | ||
3652 | $label_id = -$line['id'] - 11; | |
3653 | $count = getFeedUnread($link, $label_id); | |
3654 | ||
3655 | $class = "label"; | |
3656 | ||
3657 | if ($count > 0) { | |
3658 | $class .= "Unread"; | |
3659 | } | |
3660 | ||
3661 | error_reporting (DEFAULT_ERROR_LEVEL); | |
3662 | ||
3663 | printFeedEntry($label_id, | |
47439031 | 3664 | $class, $line["description"], |
f407c086 AD |
3665 | $count, "images/label.png", $link); |
3666 | ||
3667 | } | |
3668 | ||
3669 | if (db_num_rows($result) > 0) { | |
3670 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
3671 | print "</ul>"; | |
3672 | } | |
3673 | } | |
3674 | ||
3675 | } | |
3676 | ||
3677 | if (!get_pref($link, 'ENABLE_FEED_CATS')) { | |
3bd9a780 | 3678 | print "<li><hr></li>"; |
f407c086 AD |
3679 | } |
3680 | ||
3681 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
3682 | if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) { | |
3683 | $order_by_qpart = "category,unread DESC,title"; | |
3684 | } else { | |
3685 | $order_by_qpart = "category,title"; | |
3686 | } | |
3687 | } else { | |
3688 | if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) { | |
3689 | $order_by_qpart = "unread DESC,title"; | |
3690 | } else { | |
3691 | $order_by_qpart = "title"; | |
3692 | } | |
3693 | } | |
3694 | ||
14073c0a AD |
3695 | $age_qpart = getMaxAgeSubquery(); |
3696 | ||
f407c086 AD |
3697 | $result = db_query($link, "SELECT ttrss_feeds.*, |
3698 | SUBSTRING(last_updated,1,19) AS last_updated_noms, | |
3699 | (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries | |
3700 | WHERE feed_id = ttrss_feeds.id AND unread = true | |
14073c0a | 3701 | AND $age_qpart |
f407c086 AD |
3702 | AND ttrss_user_entries.ref_id = ttrss_entries.id |
3703 | AND owner_uid = '$owner_uid') as unread, | |
3704 | cat_id,last_error, | |
3705 | ttrss_feed_categories.title AS category, | |
3706 | ttrss_feed_categories.collapsed | |
3707 | FROM ttrss_feeds LEFT JOIN ttrss_feed_categories | |
3708 | ON (ttrss_feed_categories.id = cat_id) | |
3709 | WHERE | |
3710 | ttrss_feeds.hidden = false AND | |
3711 | ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL | |
3712 | ORDER BY $order_by_qpart"); | |
3713 | ||
3714 | $actid = $_GET["actid"]; | |
3715 | ||
3716 | /* real feeds */ | |
3717 | ||
3718 | $lnum = 0; | |
3719 | ||
3720 | $total_unread = 0; | |
3721 | ||
3722 | $category = ""; | |
3723 | ||
3724 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
3725 | ||
3726 | while ($line = db_fetch_assoc($result)) { | |
3727 | ||
47439031 | 3728 | $feed = trim($line["title"]); |
0f39ae20 AD |
3729 | |
3730 | if (!$feed) $feed = "[Untitled]"; | |
3731 | ||
f407c086 AD |
3732 | $feed_id = $line["id"]; |
3733 | ||
3734 | $subop = $_GET["subop"]; | |
3735 | ||
3736 | $unread = $line["unread"]; | |
3737 | ||
3738 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
3739 | $last_updated = smart_date_time(strtotime($line["last_updated_noms"])); | |
3740 | } else { | |
3741 | $last_updated = date($short_date, strtotime($line["last_updated_noms"])); | |
3742 | } | |
3743 | ||
3744 | $rtl_content = sql_bool_to_bool($line["rtl_content"]); | |
3745 | ||
3746 | if ($rtl_content) { | |
3747 | $rtl_tag = "dir=\"RTL\""; | |
3748 | } else { | |
3749 | $rtl_tag = ""; | |
3750 | } | |
3751 | ||
3752 | $tmp_result = db_query($link, | |
3753 | "SELECT id,COUNT(unread) AS unread | |
3754 | FROM ttrss_feeds LEFT JOIN ttrss_user_entries | |
3755 | ON (ttrss_feeds.id = ttrss_user_entries.feed_id) | |
3756 | WHERE parent_feed = '$feed_id' AND unread = true | |
3757 | GROUP BY ttrss_feeds.id"); | |
3758 | ||
3759 | if (db_num_rows($tmp_result) > 0) { | |
3760 | while ($l = db_fetch_assoc($tmp_result)) { | |
3761 | $unread += $l["unread"]; | |
3762 | } | |
3763 | } | |
3764 | ||
3765 | $cat_id = $line["cat_id"]; | |
3766 | ||
3767 | $tmp_category = $line["category"]; | |
3768 | ||
3769 | if (!$tmp_category) { | |
d1db26aa | 3770 | $tmp_category = __("Uncategorized"); |
f407c086 AD |
3771 | } |
3772 | ||
3773 | // $class = ($lnum % 2) ? "even" : "odd"; | |
3774 | ||
3775 | if ($line["last_error"]) { | |
3776 | $class = "error"; | |
3777 | } else { | |
3778 | $class = "feed"; | |
3779 | } | |
3780 | ||
3781 | if ($unread > 0) $class .= "Unread"; | |
3782 | ||
3783 | if ($actid == $feed_id) { | |
3784 | $class .= "Selected"; | |
3785 | } | |
3786 | ||
3787 | $total_unread += $unread; | |
3788 | ||
3789 | if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) { | |
3790 | ||
3791 | if ($category) { | |
3792 | print "</ul></li>"; | |
3793 | } | |
3794 | ||
3795 | $category = $tmp_category; | |
3796 | ||
3797 | $collapsed = $line["collapsed"]; | |
3798 | ||
3799 | // workaround for NULL category | |
d1db26aa | 3800 | if ($category == __("Uncategorized")) { |
f407c086 AD |
3801 | if ($_COOKIE["ttrss_vf_uclps"] == 1) { |
3802 | $collapsed = "t"; | |
3803 | } | |
3804 | } | |
3805 | ||
3806 | if ($collapsed == "t" || $collapsed == "1") { | |
225ec0d4 AD |
3807 | $holder_class = "feedCatHolder"; |
3808 | $holder_style = "display:none;"; | |
f407c086 AD |
3809 | $ellipsis = "..."; |
3810 | } else { | |
be5b75da | 3811 | $holder_class = "feedCatHolder"; |
225ec0d4 | 3812 | $holder_style = ""; |
f407c086 AD |
3813 | $ellipsis = ""; |
3814 | } | |
3815 | ||
3816 | $cat_id = sprintf("%d", $cat_id); | |
3817 | ||
3818 | $cat_unread = getCategoryUnread($link, $cat_id); | |
67dabe1a AD |
3819 | |
3820 | $catctr_class = ($cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread"; | |
3821 | ||
3bd9a780 | 3822 | print "<li class=\"feedCat\" id=\"FCAT-$cat_id\"> |
439bbe63 | 3823 | <a id=\"FCATN-$cat_id\" href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a> |
7210613a | 3824 | <a href=\"#\" onclick=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\"> |
67dabe1a AD |
3825 | <span id=\"FCATCTR-$cat_id\" title=\"Click to browse category\" |
3826 | class=\"$catctr_class\">($cat_unread)</span> $ellipsis | |
3bd9a780 | 3827 | </a></li>"; |
f407c086 | 3828 | |
225ec0d4 | 3829 | print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\" style='$holder_style'>"; |
f407c086 AD |
3830 | } |
3831 | ||
3832 | printFeedEntry($feed_id, $class, $feed, $unread, | |
99e37e09 | 3833 | ICONS_DIR."/$feed_id.ico", $link, $rtl_content, |
f407c086 AD |
3834 | $last_updated, $line["last_error"]); |
3835 | ||
3836 | ++$lnum; | |
3837 | } | |
3838 | ||
3839 | if (db_num_rows($result) == 0) { | |
3bd9a780 | 3840 | print "<li>".__('No feeds to display.')."</li>"; |
f407c086 AD |
3841 | } |
3842 | ||
3843 | } else { | |
3844 | ||
3845 | // tags | |
3846 | ||
3847 | /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
3848 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE | |
3849 | post_int_id = ttrss_user_entries.int_id AND | |
3850 | unread = true AND ref_id = ttrss_entries.id | |
3851 | AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name | |
3852 | UNION | |
3853 | select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid' | |
3854 | ORDER BY tag_name"); */ | |
3855 | ||
3856 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
d1db26aa | 3857 | print "<li class=\"feedCat\">".__('Tags')."</li>"; |
f407c086 AD |
3858 | print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">"; |
3859 | } | |
3860 | ||
14073c0a AD |
3861 | $age_qpart = getMaxAgeSubquery(); |
3862 | ||
f407c086 | 3863 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) |
14073c0a AD |
3864 | FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id |
3865 | AND ref_id = id AND $age_qpart | |
f407c086 | 3866 | AND unread = true)) AS count FROM ttrss_tags |
ef1ac7c7 AD |
3867 | WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name |
3868 | ORDER BY count DESC LIMIT 50"); | |
f407c086 AD |
3869 | |
3870 | $tags = array(); | |
3871 | ||
3872 | while ($line = db_fetch_assoc($result)) { | |
3873 | $tags[$line["tag_name"]] += $line["count"]; | |
3874 | } | |
3875 | ||
3876 | foreach (array_keys($tags) as $tag) { | |
3877 | ||
3878 | $unread = $tags[$tag]; | |
3879 | ||
3880 | $class = "tag"; | |
3881 | ||
3882 | if ($unread > 0) { | |
3883 | $class .= "Unread"; | |
3884 | } | |
3885 | ||
3886 | printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link); | |
3887 | ||
3888 | } | |
3889 | ||
3890 | if (db_num_rows($result) == 0) { | |
3891 | print "<li>No tags to display.</li>"; | |
3892 | } | |
3893 | ||
3894 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
3bd9a780 | 3895 | print "</ul>"; |
f407c086 AD |
3896 | } |
3897 | ||
3898 | } | |
3899 | ||
3900 | print "</ul>"; | |
3901 | ||
3902 | } | |
3903 | ||
bc976a8c | 3904 | function get_article_tags($link, $id, $owner_uid = 0) { |
0b126ac2 AD |
3905 | |
3906 | $a_id = db_escape_string($id); | |
3907 | ||
bc976a8c AD |
3908 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
3909 | ||
0c3d1c68 AD |
3910 | $tmp_result = db_query($link, "SELECT DISTINCT tag_name, |
3911 | owner_uid as owner FROM | |
0b126ac2 | 3912 | ttrss_tags WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE |
bc976a8c | 3913 | ref_id = '$a_id' AND owner_uid = '$owner_uid' LIMIT 1) ORDER BY tag_name"); |
0b126ac2 AD |
3914 | |
3915 | $tags = array(); | |
3916 | ||
3917 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
3918 | array_push($tags, $tmp_line["tag_name"]); | |
3919 | } | |
3920 | ||
3921 | return $tags; | |
3922 | } | |
3923 | ||
d62a3b63 AD |
3924 | function trim_value(&$value) { |
3925 | $value = trim($value); | |
3926 | } | |
3927 | ||
3928 | function trim_array($array) { | |
3929 | $tmp = $array; | |
3930 | array_walk($tmp, 'trim_value'); | |
3931 | return $tmp; | |
3932 | } | |
3933 | ||
be832a1a | 3934 | function tag_is_valid($tag) { |
ef063748 AD |
3935 | if ($tag == '') return false; |
3936 | if (preg_match("/^[0-9]*$/", $tag)) return false; | |
3937 | ||
3938 | $tag = iconv("utf-8", "utf-8", $tag); | |
3939 | if (!$tag) return false; | |
3940 | ||
3941 | return true; | |
be832a1a AD |
3942 | } |
3943 | ||
793185a9 AD |
3944 | function render_login_form($link, $mobile = false) { |
3945 | if (!$mobile) { | |
3946 | require_once "login_form.php"; | |
3947 | } else { | |
3948 | require_once "mobile/login_form.php"; | |
3949 | } | |
01a87dff AD |
3950 | } |
3951 | ||
dc56b3b7 AD |
3952 | // from http://developer.apple.com/internet/safari/faq.html |
3953 | function no_cache_incantation() { | |
3954 | header("Expires: Mon, 22 Dec 1980 00:00:00 GMT"); // Happy birthday to me :) | |
3955 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified | |
3956 | header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1 | |
3957 | header("Cache-Control: post-check=0, pre-check=0", false); | |
3958 | header("Pragma: no-cache"); // HTTP/1.0 | |
3959 | } | |
3960 | ||
42395d28 AD |
3961 | function format_warning($msg, $id = "") { |
3962 | return "<div class=\"warning\" id=\"$id\"> | |
e780d1d2 | 3963 | <img src=\"images/sign_excl.gif\">$msg</div>"; |
0d32b41e AD |
3964 | } |
3965 | ||
3966 | function format_notice($msg) { | |
3967 | return "<div class=\"notice\"> | |
e780d1d2 | 3968 | <img src=\"images/sign_info.gif\">$msg</div>"; |
0d32b41e AD |
3969 | } |
3970 | ||
68d2f95e AD |
3971 | function format_error($msg) { |
3972 | return "<div class=\"error\"> | |
e780d1d2 | 3973 | <img src=\"images/sign_excl.gif\">$msg</div>"; |
68d2f95e AD |
3974 | } |
3975 | ||
4dccf1ed AD |
3976 | function print_notice($msg) { |
3977 | return print format_notice($msg); | |
3978 | } | |
3979 | ||
3980 | function print_warning($msg) { | |
3981 | return print format_warning($msg); | |
3982 | } | |
3983 | ||
68d2f95e AD |
3984 | function print_error($msg) { |
3985 | return print format_error($msg); | |
3986 | } | |
3987 | ||
3988 | ||
4dccf1ed AD |
3989 | function T_sprintf() { |
3990 | $args = func_get_args(); | |
3991 | return vsprintf(__(array_shift($args)), $args); | |
3992 | } | |
3993 | ||
3de0261a AD |
3994 | function outputArticleXML($link, $id, $feed_id, $mark_as_read = true) { |
3995 | ||
10eb9da8 AD |
3996 | /* we can figure out feed_id from article id anyway, why do we |
3997 | * pass feed_id here? */ | |
3998 | ||
3999 | $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries | |
4000 | WHERE ref_id = '$id'"); | |
4001 | ||
4002 | $feed_id = db_fetch_result($result, 0, "feed_id"); | |
4003 | ||
3de0261a AD |
4004 | print "<article id='$id'><![CDATA["; |
4005 | ||
4006 | $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds | |
4007 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
4008 | ||
4009 | if (db_num_rows($result) == 1) { | |
4010 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); | |
4011 | } else { | |
4012 | $rtl_content = false; | |
4013 | } | |
4014 | ||
4015 | if ($rtl_content) { | |
4016 | $rtl_tag = "dir=\"RTL\""; | |
4017 | $rtl_class = "RTL"; | |
4018 | } else { | |
4019 | $rtl_tag = ""; | |
4020 | $rtl_class = ""; | |
4021 | } | |
4022 | ||
4023 | if ($mark_as_read) { | |
4024 | $result = db_query($link, "UPDATE ttrss_user_entries | |
4025 | SET unread = false,last_read = NOW() | |
4026 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
4027 | } | |
4028 | ||
4029 | $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id, | |
4030 | SUBSTRING(updated,1,16) as updated, | |
4031 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url, | |
4032 | num_comments, | |
4033 | author | |
4034 | FROM ttrss_entries,ttrss_user_entries | |
4035 | WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]); | |
4036 | ||
4037 | if ($result) { | |
4038 | ||
4039 | $link_target = ""; | |
4040 | ||
4041 | if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { | |
4042 | $link_target = "target=\"_new\""; | |
4043 | } | |
4044 | ||
4045 | $line = db_fetch_assoc($result); | |
4046 | ||
4047 | if ($line["icon_url"]) { | |
4048 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
4049 | } else { | |
4050 | $feed_icon = " "; | |
4051 | } | |
4052 | ||
4053 | /* if ($line["comments"] && $line["link"] != $line["comments"]) { | |
4054 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
4055 | } else { | |
4056 | $entry_comments = ""; | |
4057 | } */ | |
4058 | ||
4059 | $num_comments = $line["num_comments"]; | |
4060 | $entry_comments = ""; | |
4061 | ||
4062 | if ($num_comments > 0) { | |
4063 | if ($line["comments"]) { | |
4064 | $comments_url = $line["comments"]; | |
4065 | } else { | |
4066 | $comments_url = $line["link"]; | |
4067 | } | |
4068 | $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>"; | |
4069 | } else { | |
4070 | if ($line["comments"] && $line["link"] != $line["comments"]) { | |
4071 | $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>"; | |
4072 | } | |
4073 | } | |
4074 | ||
4075 | print "<div class=\"postReply\">"; | |
4076 | ||
4077 | print "<div class=\"postHeader\">"; | |
4078 | ||
4079 | $entry_author = $line["author"]; | |
4080 | ||
4081 | if ($entry_author) { | |
4082 | $entry_author = __(" - by ") . $entry_author; | |
4083 | } | |
4084 | ||
4085 | $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
4086 | strtotime($line["updated"])); | |
4087 | ||
4088 | print "<div class=\"postDate$rtl_class\">$parsed_updated</div>"; | |
4089 | ||
4090 | if ($line["link"]) { | |
4091 | print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" . | |
06202d88 | 4092 | $line["title"] . "</a><span class='author'>$entry_author</span></div>"; |
3de0261a AD |
4093 | } else { |
4094 | print "<div clear='both'>" . $line["title"] . "$entry_author</div>"; | |
4095 | } | |
4096 | ||
9cfd409d | 4097 | /* $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM |
3de0261a | 4098 | ttrss_tags WHERE post_int_id = " . $line["int_id"] . " |
9cfd409d AD |
4099 | ORDER BY tag_name"); */ |
4100 | ||
4101 | $tags = get_article_tags($link, $id); | |
3de0261a AD |
4102 | |
4103 | $tags_str = ""; | |
4104 | $f_tags_str = ""; | |
4105 | ||
4106 | $num_tags = 0; | |
4107 | ||
9cfd409d | 4108 | foreach ($tags as $tag) { |
3de0261a | 4109 | $num_tags++; |
14b6c54b AD |
4110 | $tag_escaped = str_replace("'", "\\'", $tag); |
4111 | ||
4112 | $tag_str = "<a href=\"javascript:viewfeed('$tag_escaped')\">$tag</a>, "; | |
3de0261a AD |
4113 | |
4114 | if ($num_tags == 6) { | |
e7544143 AD |
4115 | $tags_str .= "..."; |
4116 | ||
3de0261a AD |
4117 | } else if ($num_tags < 6) { |
4118 | $tags_str .= $tag_str; | |
4119 | } | |
4120 | $f_tags_str .= $tag_str; | |
4121 | } | |
4122 | ||
4123 | $tags_str = preg_replace("/, $/", "", $tags_str); | |
4124 | $f_tags_str = preg_replace("/, $/", "", $f_tags_str); | |
4125 | ||
e7544143 AD |
4126 | $all_tags_div = "<span class='cdmAllTagsCtr'>...<div class='cdmAllTags'>All Tags: $f_tags_str</div></span>"; |
4127 | $tags_str = preg_replace("/\.\.\.$/", "$all_tags_div", $tags_str); | |
4128 | ||
3de0261a AD |
4129 | if (!$entry_comments) $entry_comments = " "; # placeholder |
4130 | ||
4131 | if (!$tags_str) $tags_str = '<span class="tagList">'.__('no tags').'</span>'; | |
4132 | ||
5f014cf1 AD |
4133 | print "<div style='float : right'> |
4134 | <img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'> | |
4135 | $tags_str | |
3de0261a AD |
4136 | <a title=\"Edit tags for this article\" |
4137 | href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a></div> | |
4138 | <div clear='both'>$entry_comments</div>"; | |
4139 | ||
4140 | print "</div>"; | |
4141 | ||
4142 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
4143 | print "<div class=\"postContent\">"; | |
4144 | ||
e7544143 | 4145 | #print "<div id=\"allEntryTags\">".__('Tags:')." $f_tags_str</div>"; |
3de0261a | 4146 | |
c41890b0 AD |
4147 | $line["content"] = sanitize_rss($link, $line["content"]); |
4148 | ||
3de0261a AD |
4149 | if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { |
4150 | $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]); | |
4151 | } | |
4152 | ||
3de0261a AD |
4153 | print $line["content"] . "</div>"; |
4154 | ||
4155 | print "</div>"; | |
4156 | ||
4157 | } | |
4158 | ||
4159 | print "]]></article>"; | |
4160 | ||
4161 | } | |
4162 | ||
4163 | function outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view, | |
4164 | $next_unread_feed, $offset) { | |
4165 | ||
46921916 AD |
4166 | $timing_info = getmicrotime(); |
4167 | ||
961f4c73 AD |
4168 | $topmost_article_ids = array(); |
4169 | ||
ac541432 AD |
4170 | if (!$offset) { |
4171 | $offset = 0; | |
4172 | } | |
3de0261a AD |
4173 | |
4174 | if ($subop == "undefined") $subop = ""; | |
4175 | ||
4176 | if ($subop == "CatchupSelected") { | |
4177 | $ids = split(",", db_escape_string($_GET["ids"])); | |
4178 | $cmode = sprintf("%d", $_GET["cmode"]); | |
4179 | ||
4180 | catchupArticlesById($link, $ids, $cmode); | |
4181 | } | |
4182 | ||
4183 | if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) { | |
4184 | update_generic_feed($link, $feed, $cat_view); | |
4185 | } | |
4186 | ||
4187 | if ($subop == "MarkAllRead") { | |
4188 | catchup_feed($link, $feed, $cat_view); | |
4189 | ||
4190 | if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) { | |
4191 | if ($next_unread_feed) { | |
4192 | $feed = $next_unread_feed; | |
4193 | } | |
4194 | } | |
4195 | } | |
4196 | ||
4197 | if ($feed_id > 0) { | |
4198 | $result = db_query($link, | |
4199 | "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1"); | |
4200 | ||
4201 | if (db_num_rows($result) == 0) { | |
4202 | print "<div align='center'>".__('Feed not found.')."</div>"; | |
4203 | return; | |
4204 | } | |
4205 | } | |
4206 | ||
4207 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { | |
10eb9da8 | 4208 | |
3de0261a AD |
4209 | $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds |
4210 | WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
4211 | ||
4212 | if (db_num_rows($result) == 1) { | |
4213 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); | |
4214 | } else { | |
4215 | $rtl_content = false; | |
4216 | } | |
4217 | ||
4218 | if ($rtl_content) { | |
4219 | $rtl_tag = "dir=\"RTL\""; | |
4220 | } else { | |
4221 | $rtl_tag = ""; | |
4222 | } | |
4223 | } else { | |
4224 | $rtl_tag = ""; | |
4225 | $rtl_content = false; | |
4226 | } | |
4227 | ||
4228 | $script_dt_add = get_script_dt_add(); | |
4229 | ||
4230 | /// START ///////////////////////////////////////////////////////////////////////////////// | |
4231 | ||
4232 | $search = db_escape_string($_GET["query"]); | |
4233 | $search_mode = db_escape_string($_GET["search_mode"]); | |
4234 | $match_on = db_escape_string($_GET["match_on"]); | |
4235 | ||
4236 | if (!$match_on) { | |
4237 | $match_on = "both"; | |
4238 | } | |
4239 | ||
4240 | $real_offset = $offset * $limit; | |
4241 | ||
46921916 AD |
4242 | if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info); |
4243 | ||
3de0261a AD |
4244 | $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, |
4245 | $search, $search_mode, $match_on, false, $real_offset); | |
4246 | ||
46921916 AD |
4247 | if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info); |
4248 | ||
3de0261a AD |
4249 | $result = $qfh_ret[0]; |
4250 | $feed_title = $qfh_ret[1]; | |
4251 | $feed_site_url = $qfh_ret[2]; | |
4252 | $last_error = $qfh_ret[3]; | |
f56e3080 AD |
4253 | |
4254 | if ($feed == -2) { | |
4255 | $feed_site_url = article_publish_url($link); | |
4256 | } | |
4257 | ||
3de0261a AD |
4258 | /// STOP ////////////////////////////////////////////////////////////////////////////////// |
4259 | ||
ac541432 AD |
4260 | if (!$offset) { |
4261 | print "<div id=\"headlinesContainer\" $rtl_tag>"; | |
3de0261a | 4262 | |
ac541432 AD |
4263 | if (!$result) { |
4264 | print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>"; | |
4265 | return; | |
4266 | } | |
3de0261a | 4267 | |
ac541432 AD |
4268 | print_headline_subtoolbar($link, $feed_site_url, $feed_title, false, |
4269 | $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode, | |
4270 | $offset, $limit); | |
3de0261a | 4271 | |
ac541432 AD |
4272 | print "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">"; |
4273 | } | |
3de0261a | 4274 | |
29dfb258 AD |
4275 | $headlines_count = db_num_rows($result); |
4276 | ||
3de0261a AD |
4277 | if (db_num_rows($result) > 0) { |
4278 | ||
4279 | # print "\{$offset}"; | |
4280 | ||
ac541432 | 4281 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) { |
3de0261a AD |
4282 | print "<table class=\"headlinesList\" id=\"headlinesList\" |
4283 | cellspacing=\"0\">"; | |
4284 | } | |
4285 | ||
4ab4d364 AD |
4286 | $lnum = $limit*$offset; |
4287 | ||
3de0261a AD |
4288 | error_reporting (DEFAULT_ERROR_LEVEL); |
4289 | ||
4290 | $num_unread = 0; | |
4291 | ||
4292 | while ($line = db_fetch_assoc($result)) { | |
4293 | ||
4294 | $class = ($lnum % 2) ? "even" : "odd"; | |
4295 | ||
4296 | $id = $line["id"]; | |
4297 | $feed_id = $line["feed_id"]; | |
961f4c73 AD |
4298 | |
4299 | if (count($topmost_article_ids) < 5) { | |
4300 | array_push($topmost_article_ids, $id); | |
4301 | } | |
4302 | ||
3de0261a AD |
4303 | if ($line["last_read"] == "" && |
4304 | ($line["unread"] != "t" && $line["unread"] != "1")) { | |
4305 | ||
4306 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
4307 | alt=\"Updated\">"; | |
4308 | } else { | |
4309 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
4310 | alt=\"Updated\">"; | |
4311 | } | |
4312 | ||
4313 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
4314 | $class .= "Unread"; | |
4315 | ++$num_unread; | |
4316 | $is_unread = true; | |
4317 | } else { | |
4318 | $is_unread = false; | |
4319 | } | |
abd8a516 AD |
4320 | |
4321 | $is_ie = (strpos($_SESSION["client.userAgent"], "MSIE") !== false); | |
4322 | ||
4323 | if ($is_ie) { | |
4324 | $mark_img_ext = "gif"; | |
4325 | } else { | |
4326 | $mark_img_ext = "png"; | |
4327 | } | |
4328 | ||
3de0261a | 4329 | if ($line["marked"] == "t" || $line["marked"] == "1") { |
abd8a516 | 4330 | $marked_pic = "<img id=\"FMPIC-$id\" src=\"images/mark_set.$mark_img_ext\" |
3de0261a | 4331 | class=\"markedPic\" |
f5e0338d | 4332 | alt=\"Unstar article\" onclick='javascript:tMark($id)'>"; |
3de0261a | 4333 | } else { |
abd8a516 | 4334 | $marked_pic = "<img id=\"FMPIC-$id\" src=\"images/mark_unset.$mark_img_ext\" |
3de0261a | 4335 | class=\"markedPic\" |
f5e0338d | 4336 | alt=\"Star article\" onclick='javascript:tMark($id)'>"; |
3de0261a AD |
4337 | } |
4338 | ||
e4f4b46f | 4339 | if ($line["published"] == "t" || $line["published"] == "1") { |
f5e0338d | 4340 | $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_set.gif\" |
e4f4b46f | 4341 | class=\"markedPic\" |
f5e0338d | 4342 | alt=\"Unpublish article\" onclick='javascript:tPub($id)'>"; |
e4f4b46f | 4343 | } else { |
f5e0338d | 4344 | $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_unset.gif\" |
e4f4b46f | 4345 | class=\"markedPic\" |
f5e0338d | 4346 | alt=\"Publish article\" onclick='javascript:tPub($id)'>"; |
e4f4b46f AD |
4347 | } |
4348 | ||
3de0261a AD |
4349 | # $content_link = "<a target=\"_new\" href=\"".$line["link"]."\">" . |
4350 | # $line["title"] . "</a>"; | |
4351 | ||
4352 | $content_link = "<a href=\"javascript:view($id,$feed_id);\">" . | |
4353 | $line["title"] . "</a>"; | |
4354 | ||
4355 | # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" . | |
4356 | # $line["title"] . "</a>"; | |
4357 | ||
4358 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
46921916 | 4359 | $updated_fmt = smart_date_time(strtotime($line["updated_noms"])); |
3de0261a AD |
4360 | } else { |
4361 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
46921916 | 4362 | $updated_fmt = date($short_date, strtotime($line["updated_noms"])); |
3de0261a AD |
4363 | } |
4364 | ||
4365 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
4366 | $content_preview = truncate_string(strip_tags($line["content_preview"]), | |
4367 | 100); | |
4368 | } | |
4369 | ||
4370 | $entry_author = $line["author"]; | |
4371 | ||
4372 | if ($entry_author) { | |
4373 | $entry_author = " - by $entry_author"; | |
4374 | } | |
4375 | ||
4376 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { | |
4377 | ||
4378 | print "<tr class='$class' id='RROW-$id'>"; | |
4379 | ||
67343d9f | 4380 | print "<td class='hlUpdPic'>$update_pic</td>"; |
3de0261a AD |
4381 | |
4382 | print "<td class='hlSelectRow'> | |
67343d9f AD |
4383 | <input type=\"checkbox\" onclick=\"tSR(this)\" |
4384 | id=\"RCHK-$id\"> | |
3de0261a AD |
4385 | </td>"; |
4386 | ||
4387 | print "<td class='hlMarkedPic'>$marked_pic</td>"; | |
e4f4b46f | 4388 | print "<td class='hlMarkedPic'>$published_pic</td>"; |
3de0261a | 4389 | |
df456bb0 AD |
4390 | # if ($line["feed_title"]) { |
4391 | # print "<td class='hlContent'>$content_link</td>"; | |
4392 | # print "<td class='hlFeed'> | |
4393 | # <a href=\"javascript:viewfeed($feed_id, '', false)\">". | |
4394 | # truncate_string($line["feed_title"],30)."</a> </td>"; | |
4395 | # } else { | |
4396 | ||
4397 | print "<td class='hlContent' valign='middle'>"; | |
4398 | ||
4399 | print "<a href=\"javascript:view($id,$feed_id);\">" . | |
4400 | $line["title"]; | |
4401 | ||
4402 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
4403 | if ($content_preview) { | |
4404 | print "<span class=\"contentPreview\"> - $content_preview</span>"; | |
3de0261a | 4405 | } |
3de0261a | 4406 | } |
df456bb0 AD |
4407 | |
4408 | print "</a>"; | |
4409 | ||
4410 | # <a href=\"javascript:viewfeed($feed_id, '', false)\">". | |
4411 | # $line["feed_title"]."</a> | |
4412 | ||
4413 | if ($line["feed_title"]) { | |
4414 | print "<span class=\"hlFeed\"> | |
4415 | (<a href=\"javascript:viewfeed($feed_id, '', false)\">". | |
4416 | $line["feed_title"]."</a>) | |
4417 | </span>"; | |
4418 | } | |
4419 | ||
4420 | ||
4421 | print "</td>"; | |
4422 | ||
4423 | # } | |
3de0261a AD |
4424 | |
4425 | print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>"; | |
4426 | ||
4427 | print "</tr>"; | |
4428 | ||
4429 | } else { | |
4430 | ||
4431 | if ($is_unread) { | |
4432 | $add_class = "Unread"; | |
4433 | } else { | |
4434 | $add_class = ""; | |
4435 | } | |
4436 | ||
e4914b62 AD |
4437 | print "<div class=\"cdmArticle$add_class\" |
4438 | id=\"RROW-$id\" onmouseover='cdmMouseIn(this)' | |
4439 | onmouseout='cdmMouseOut(this)'>"; | |
3de0261a AD |
4440 | |
4441 | print "<div class=\"cdmHeader\">"; | |
4442 | ||
4443 | print "<div class=\"articleUpdated\">$updated_fmt</div>"; | |
4444 | ||
4445 | print "<a class=\"title\" | |
4446 | onclick=\"javascript:toggleUnread($id, 0)\" | |
3fc2eed5 | 4447 | target=\"_new\" href=\"".$line["link"]."\">".$line["title"]."</a>"; |
3de0261a AD |
4448 | |
4449 | print $entry_author; | |
4450 | ||
4451 | if ($line["feed_title"]) { | |
4452 | print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)"; | |
4453 | } | |
4454 | ||
4455 | print "</div>"; | |
4456 | ||
3fc2eed5 AD |
4457 | if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { |
4458 | $line["content_preview"] = preg_replace("/href=/i", | |
4459 | "target=\"_new\" href=", $line["content_preview"]); | |
4460 | } | |
4461 | ||
3de0261a AD |
4462 | print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">"; |
4463 | ||
e2ccbfab | 4464 | print "<div class=\"cdmFooter\"><span class='s0'>"; |
3de0261a | 4465 | |
e2ccbfab | 4466 | /* print "<div class=\"markedPic\">Star it: $marked_pic</div>"; */ |
3de0261a | 4467 | |
e2ccbfab AD |
4468 | print __("Select:"). |
4469 | " <input type=\"checkbox\" onclick=\"toggleSelectRowById(this, | |
3de0261a AD |
4470 | 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">"; |
4471 | ||
e2ccbfab | 4472 | print "</span><span class='s1'>$marked_pic</span> "; |
e4f4b46f | 4473 | print "<span class='s1'>$published_pic</span> "; |
e2ccbfab | 4474 | |
3de0261a AD |
4475 | $tags = get_article_tags($link, $id); |
4476 | ||
4477 | $tags_str = ""; | |
22d1f3db | 4478 | $full_tags_str = ""; |
d735ebd2 | 4479 | $num_tags = 0; |
3de0261a AD |
4480 | |
4481 | foreach ($tags as $tag) { | |
4482 | $num_tags++; | |
22d1f3db AD |
4483 | $full_tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, "; |
4484 | if ($num_tags < 5) { | |
4485 | $tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, "; | |
4486 | } else if ($num_tags == 5) { | |
4487 | $tags_str .= "..."; | |
4488 | } | |
3de0261a AD |
4489 | } |
4490 | ||
4491 | $tags_str = preg_replace("/, $/", "", $tags_str); | |
22d1f3db AD |
4492 | $full_tags_str = preg_replace("/, $/", "", $full_tags_str); |
4493 | ||
4494 | $all_tags_div = "<span class='cdmAllTagsCtr'>...<div class='cdmAllTags'>All Tags: $full_tags_str</div></span>"; | |
4495 | ||
4496 | $tags_str = preg_replace("/\.\.\.$/", "$all_tags_div", $tags_str); | |
4497 | ||
3de0261a AD |
4498 | |
4499 | if ($tags_str == "") $tags_str = "no tags"; | |
e2ccbfab AD |
4500 | |
4501 | // print "<img src='images/tag.png' class='markedPic'>"; | |
4502 | ||
5f014cf1 AD |
4503 | print "<span class='s1'> |
4504 | <img class='tagsPic' src='images/tag.png' alt='Tags' | |
4505 | title='Tags'> $tags_str <a title=\"Edit tags for this article\" | |
3de0261a AD |
4506 | href=\"javascript:editArticleTags($id, $feed_id, true)\">(+)</a>"; |
4507 | ||
e2ccbfab | 4508 | print "</span>"; |
3de0261a | 4509 | |
e2ccbfab AD |
4510 | print "<span class='s2'>Toggle: <a class=\"cdmToggleLink\" |
4511 | href=\"javascript:toggleUnread($id)\"> | |
4512 | Unread</a></span>"; | |
3de0261a | 4513 | |
e2ccbfab | 4514 | print "</div>"; |
3de0261a AD |
4515 | print "</div>"; |
4516 | ||
4517 | } | |
4518 | ||
4519 | ++$lnum; | |
4520 | } | |
4521 | ||
ac541432 | 4522 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) { |
3de0261a AD |
4523 | print "</table>"; |
4524 | } | |
4525 | ||
4526 | // print_headline_subtoolbar($link, | |
4527 | // "javascript:catchupPage()", "Mark page as read", true, $rtl_content); | |
4528 | ||
4529 | ||
4530 | } else { | |
ac541432 | 4531 | if (!$offset) print "<div class='whiteBox'>".__('No articles found.')."</div>"; |
3de0261a AD |
4532 | } |
4533 | ||
ac541432 AD |
4534 | if (!$offset) { |
4535 | print "</div>"; | |
4536 | print "</div>"; | |
4537 | } | |
3de0261a | 4538 | |
29dfb258 | 4539 | return array($topmost_article_ids, $headlines_count); |
3de0261a | 4540 | } |
0979b696 AD |
4541 | |
4542 | // from here: http://www.roscripts.com/Create_tag_cloud-71.html | |
4543 | ||
4544 | function printTagCloud($link) { | |
35a03bdd AD |
4545 | |
4546 | /* get first ref_id to count from */ | |
4547 | ||
dcac082b AD |
4548 | /* |
4549 | ||
35a03bdd AD |
4550 | $query = ""; |
4551 | ||
4552 | if (DB_TYPE == "pgsql") { | |
4553 | $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries | |
4554 | WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]." | |
4555 | AND date_entered > NOW() - INTERVAL '30 days'"; | |
4556 | } else { | |
4557 | $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries | |
4558 | WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]." | |
4559 | AND date_entered > DATE_SUB(NOW(), INTERVAL 30 DAY)"; | |
4560 | } | |
4561 | ||
4562 | $result = db_query($link, $query); | |
dcac082b | 4563 | $first_id = db_fetch_result($result, 0, "id"); */ |
35a03bdd | 4564 | |
dcac082b | 4565 | //AND post_int_id >= '$first_id' |
0979b696 AD |
4566 | $query = "SELECT tag_name, COUNT(post_int_id) AS count |
4567 | FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]." | |
b31af972 | 4568 | GROUP BY tag_name ORDER BY count DESC LIMIT 50"; |
0979b696 AD |
4569 | |
4570 | $result = db_query($link, $query); | |
4571 | ||
4572 | $tags = array(); | |
4573 | ||
4574 | while ($line = db_fetch_assoc($result)) { | |
4575 | $tags[$line["tag_name"]] = $line["count"]; | |
4576 | } | |
4577 | ||
4578 | ksort($tags); | |
4579 | ||
4580 | $max_size = 32; // max font size in pixels | |
4548a580 | 4581 | $min_size = 11; // min font size in pixels |
0979b696 AD |
4582 | |
4583 | // largest and smallest array values | |
4584 | $max_qty = max(array_values($tags)); | |
4585 | $min_qty = min(array_values($tags)); | |
4586 | ||
4587 | // find the range of values | |
4588 | $spread = $max_qty - $min_qty; | |
4589 | if ($spread == 0) { // we don't want to divide by zero | |
4590 | $spread = 1; | |
4591 | } | |
4592 | ||
4593 | // set the font-size increment | |
4594 | $step = ($max_size - $min_size) / ($spread); | |
4595 | ||
4596 | // loop through the tag array | |
4597 | foreach ($tags as $key => $value) { | |
4598 | // calculate font-size | |
4599 | // find the $value in excess of $min_qty | |
4600 | // multiply by the font-size increment ($size) | |
4601 | // and add the $min_size set above | |
4602 | $size = round($min_size + (($value - $min_qty) * $step)); | |
546ffab4 AD |
4603 | |
4604 | $key_escaped = str_replace("'", "\\'", $key); | |
4605 | ||
4606 | echo "<a href=\"javascript:viewfeed('$key_escaped') \" style=\"font-size: " . | |
0979b696 AD |
4607 | $size . "px\" title=\"$value articles tagged with " . |
4608 | $key . '">' . $key . '</a> '; | |
4609 | } | |
4610 | } | |
46921916 AD |
4611 | |
4612 | function print_checkpoint($n, $s) { | |
4613 | $ts = getmicrotime(); | |
4614 | echo sprintf("<!-- CP[$n] %.4f seconds -->", $ts - $s); | |
4615 | return $ts; | |
4616 | } | |
14b6c54b AD |
4617 | |
4618 | function sanitize_tag($tag) { | |
4619 | $tag = trim($tag); | |
4620 | ||
4621 | $tag = mb_strtolower($tag, 'utf-8'); | |
4622 | ||
0c3d1c68 AD |
4623 | $tag = preg_replace('/[\"\+\>\<]/', "", $tag); |
4624 | ||
4625 | // $tag = str_replace('"', "", $tag); | |
4626 | // $tag = str_replace("+", " ", $tag); | |
14b6c54b AD |
4627 | $tag = str_replace("technorati tag: ", "", $tag); |
4628 | ||
4629 | return $tag; | |
4630 | } | |
e4f4b46f AD |
4631 | |
4632 | function generate_publish_key() { | |
4633 | return sha1(uniqid(rand(), true)); | |
4634 | } | |
4635 | ||
f56e3080 AD |
4636 | function article_publish_url($link) { |
4637 | ||
17a756d1 | 4638 | $url_path = 'http://' . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); |
f56e3080 AD |
4639 | |
4640 | $url_path .= "?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY"); | |
4641 | ||
4642 | return $url_path; | |
4643 | } | |
4644 | ||
40d13c28 | 4645 | ?> |