]>
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 | |
fc2b26a6 AD |
11 | if (DB_TYPE == "pgsql") { |
12 | define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE'); | |
13 | } else { | |
14 | define('SUBSTRING_FOR_DATE', 'SUBSTRING'); | |
15 | } | |
16 | ||
9632f884 AD |
17 | /** |
18 | * Return available translations names. | |
19 | * | |
20 | * @access public | |
21 | * @return array A array of available translations. | |
22 | */ | |
f8c612d4 | 23 | function get_translations() { |
6a214f92 | 24 | $tr = array( |
019bd5a9 | 25 | "auto" => "Detect automatically", |
6a214f92 AD |
26 | "en_US" => "English", |
27 | "fr_FR" => "Français", | |
e78fd196 | 28 | "hu_HU" => "Magyar (Hungarian)", |
bb5d3960 | 29 | "it_IT" => "Italiano", |
1d004f12 | 30 | "ja_JP" => "日本語 (Japanese)", |
592535d7 | 31 | "nb_NO" => "Norwegian bokmål", |
6a214f92 | 32 | "ru_RU" => "Русский", |
9a063469 | 33 | "pt_BR" => "Portuguese/Brazil", |
6a214f92 | 34 | "zh_CN" => "Simplified Chinese"); |
f8c612d4 AD |
35 | |
36 | return $tr; | |
37 | } | |
38 | ||
9632f884 | 39 | if (ENABLE_TRANSLATIONS == true) { // If translations are enabled. |
865220a4 AD |
40 | require_once "accept-to-gettext.php"; |
41 | require_once "gettext/gettext.inc"; | |
aba609e0 | 42 | |
8d039718 AD |
43 | function startup_gettext() { |
44 | ||
45 | # Get locale from Accept-Language header | |
6a214f92 | 46 | $lang = al2gt(array_keys(get_translations()), "text/html"); |
89cb787e AD |
47 | |
48 | if (defined('_TRANSLATION_OVERRIDE_DEFAULT')) { | |
49 | $lang = _TRANSLATION_OVERRIDE_DEFAULT; | |
50 | } | |
51 | ||
672f3f3c | 52 | if ($_COOKIE["ttrss_lang"] && $_COOKIE["ttrss_lang"] != "auto") { |
68659d98 AD |
53 | $lang = $_COOKIE["ttrss_lang"]; |
54 | } | |
55 | ||
7c33dbd4 AD |
56 | /* In login action of mobile version */ |
57 | if ($_POST["language"] && defined('MOBILE_VERSION')) { | |
58 | $lang = $_POST["language"]; | |
59 | $_COOKIE["ttrss_lang"] = $lang; | |
60 | } | |
61 | ||
8d039718 | 62 | if ($lang) { |
86e2e1b9 AD |
63 | if (defined('LC_MESSAGES')) { |
64 | _setlocale(LC_MESSAGES, $lang); | |
65 | } else if (defined('LC_ALL')) { | |
66 | _setlocale(LC_ALL, $lang); | |
67 | } else { | |
68 | die("can't setlocale(): please set ENABLE_TRANSLATIONS to false in config.php"); | |
69 | } | |
7c33dbd4 AD |
70 | |
71 | if (defined('MOBILE_VERSION')) { | |
72 | _bindtextdomain("messages", "../locale"); | |
73 | } else { | |
74 | _bindtextdomain("messages", "locale"); | |
75 | } | |
76 | ||
8d039718 AD |
77 | _textdomain("messages"); |
78 | _bind_textdomain_codeset("messages", "UTF-8"); | |
79 | } | |
aba609e0 | 80 | } |
aba609e0 | 81 | |
cc17c205 | 82 | startup_gettext(); |
865220a4 | 83 | |
9632f884 | 84 | } else { // If translations are enabled. |
865220a4 AD |
85 | function __($msg) { |
86 | return $msg; | |
87 | } | |
88 | function startup_gettext() { | |
89 | // no-op | |
90 | return true; | |
91 | } | |
9632f884 | 92 | } // If translations are enabled. |
cc17c205 | 93 | |
b619ff15 | 94 | require_once 'db-prefs.php'; |
5bc0bd27 | 95 | require_once 'compat.php'; |
af106b0e | 96 | require_once 'errors.php'; |
8911ac8b | 97 | require_once 'version.php'; |
40d13c28 | 98 | |
a8931123 AD |
99 | require_once 'phpmailer/class.phpmailer.php'; |
100 | ||
49f9c923 | 101 | define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')'); |
a3ee2a38 | 102 | define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); |
ba0f7628 | 103 | define('MAGPIE_CACHE_AGE', 60*15); // 15 minutes |
a3ee2a38 | 104 | |
16211ddb AD |
105 | require_once "simplepie/simplepie.inc"; |
106 | require_once "magpierss/rss_fetch.inc"; | |
107 | require_once 'magpierss/rss_utils.inc'; | |
49f9c923 | 108 | |
45004d43 AD |
109 | /** |
110 | * Print a timestamped debug message. | |
111 | * | |
112 | * @param string $msg The debug message. | |
113 | * @return void | |
114 | */ | |
6f9e33e4 AD |
115 | function _debug($msg) { |
116 | $ts = strftime("%H:%M:%S", time()); | |
2a6a9395 AD |
117 | if (function_exists('posix_getpid')) { |
118 | $ts = "$ts/" . posix_getpid(); | |
119 | } | |
6f9e33e4 | 120 | print "[$ts] $msg\n"; |
45004d43 | 121 | } // function _debug |
6f9e33e4 | 122 | |
9632f884 AD |
123 | /** |
124 | * Purge a feed old posts. | |
125 | * | |
126 | * @param mixed $link A database connection. | |
127 | * @param mixed $feed_id The id of the purged feed. | |
128 | * @param mixed $purge_interval Olderness of purged posts. | |
129 | * @param boolean $debug Set to True to enable the debug. False by default. | |
130 | * @access public | |
131 | * @return void | |
132 | */ | |
ad507f85 AD |
133 | function purge_feed($link, $feed_id, $purge_interval, $debug = false) { |
134 | ||
07d0efe9 AD |
135 | if (!$purge_interval) $purge_interval = feed_purge_interval($link, $feed_id); |
136 | ||
ad507f85 | 137 | $rows = -1; |
4c193675 | 138 | |
07d0efe9 AD |
139 | $result = db_query($link, |
140 | "SELECT owner_uid FROM ttrss_feeds WHERE id = '$feed_id'"); | |
141 | ||
142 | $owner_uid = false; | |
143 | ||
144 | if (db_num_rows($result) == 1) { | |
145 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); | |
146 | } | |
147 | ||
148 | if (!$owner_uid) return; | |
149 | ||
150 | $purge_unread = get_pref($link, "PURGE_UNREAD_ARTICLES", | |
151 | $owner_uid, false); | |
152 | ||
153 | if (!$purge_unread) $query_limit = " unread = false AND "; | |
154 | ||
fefa6ca3 | 155 | if (DB_TYPE == "pgsql") { |
44e241cb | 156 | /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE |
fefa6ca3 | 157 | marked = false AND feed_id = '$feed_id' AND |
35d8cf43 | 158 | (SELECT date_entered FROM ttrss_entries WHERE |
44e241cb AD |
159 | id = ref_id) < NOW() - INTERVAL '$purge_interval days'"); */ |
160 | ||
6e7f8d26 AD |
161 | $pg_version = get_pgsql_version($link); |
162 | ||
163 | if (preg_match("/^7\./", $pg_version) || preg_match("/^8\.0/", $pg_version)) { | |
1e59ae35 AD |
164 | |
165 | $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE | |
166 | ttrss_entries.id = ref_id AND | |
167 | marked = false AND | |
168 | feed_id = '$feed_id' AND | |
07d0efe9 | 169 | $query_limit |
1e59ae35 AD |
170 | ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); |
171 | ||
172 | } else { | |
173 | ||
174 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
175 | USING ttrss_entries | |
176 | WHERE ttrss_entries.id = ref_id AND | |
177 | marked = false AND | |
178 | feed_id = '$feed_id' AND | |
07d0efe9 | 179 | $query_limit |
fc774155 | 180 | ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); |
1e59ae35 | 181 | } |
ad507f85 AD |
182 | |
183 | $rows = pg_affected_rows($result); | |
184 | ||
fefa6ca3 | 185 | } else { |
1e59ae35 | 186 | |
30f1746f | 187 | /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE |
fefa6ca3 | 188 | marked = false AND feed_id = '$feed_id' AND |
35d8cf43 | 189 | (SELECT date_entered FROM ttrss_entries WHERE |
30f1746f AD |
190 | id = ref_id) < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); */ |
191 | ||
192 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
193 | USING ttrss_user_entries, ttrss_entries | |
194 | WHERE ttrss_entries.id = ref_id AND | |
195 | marked = false AND | |
196 | feed_id = '$feed_id' AND | |
07d0efe9 | 197 | $query_limit |
30f1746f AD |
198 | ttrss_entries.date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); |
199 | ||
ad507f85 AD |
200 | $rows = mysql_affected_rows($link); |
201 | ||
202 | } | |
203 | ||
204 | if ($debug) { | |
6f9e33e4 | 205 | _debug("Purged feed $feed_id ($purge_interval): deleted $rows articles"); |
fefa6ca3 | 206 | } |
9632f884 | 207 | } // function purge_feed |
fefa6ca3 | 208 | |
9632f884 AD |
209 | /** |
210 | * Purge old posts from old feeds. | |
211 | * | |
212 | * @param mixed $link A database connection | |
213 | * @param boolean $do_output Set to true to enable printed output, false by default. | |
214 | * @param integer $limit The maximal number of removed posts. | |
215 | * @access public | |
216 | * @return void | |
217 | */ | |
44e241cb AD |
218 | function global_purge_old_posts($link, $do_output = false, $limit = false) { |
219 | ||
894ebcf5 | 220 | $random_qpart = sql_random_function(); |
fefa6ca3 | 221 | |
44e241cb AD |
222 | if ($limit) { |
223 | $limit_qpart = "LIMIT $limit"; | |
224 | } else { | |
225 | $limit_qpart = ""; | |
226 | } | |
227 | ||
fefa6ca3 | 228 | $result = db_query($link, |
44e241cb AD |
229 | "SELECT id,purge_interval,owner_uid FROM ttrss_feeds |
230 | ORDER BY $random_qpart $limit_qpart"); | |
fefa6ca3 AD |
231 | |
232 | while ($line = db_fetch_assoc($result)) { | |
233 | ||
234 | $feed_id = $line["id"]; | |
235 | $purge_interval = $line["purge_interval"]; | |
236 | $owner_uid = $line["owner_uid"]; | |
237 | ||
238 | if ($purge_interval == 0) { | |
239 | ||
240 | $tmp_result = db_query($link, | |
241 | "SELECT value FROM ttrss_user_prefs WHERE | |
242 | pref_name = 'PURGE_OLD_DAYS' AND owner_uid = '$owner_uid'"); | |
243 | ||
244 | if (db_num_rows($tmp_result) != 0) { | |
245 | $purge_interval = db_fetch_result($tmp_result, 0, "value"); | |
246 | } | |
247 | } | |
248 | ||
249 | if ($do_output) { | |
ad507f85 | 250 | // print "Feed $feed_id: purge interval = $purge_interval\n"; |
fefa6ca3 AD |
251 | } |
252 | ||
253 | if ($purge_interval > 0) { | |
ad507f85 | 254 | purge_feed($link, $feed_id, $purge_interval, $do_output); |
fefa6ca3 AD |
255 | } |
256 | } | |
257 | ||
71604ca4 | 258 | // purge orphaned posts in main content table |
dab52d7b | 259 | $result = db_query($link, "DELETE FROM ttrss_entries WHERE |
71604ca4 AD |
260 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); |
261 | ||
dab52d7b AD |
262 | if ($do_output) { |
263 | $rows = db_affected_rows($link, $result); | |
264 | _debug("Purged $rows orphaned posts."); | |
265 | } | |
266 | ||
9632f884 | 267 | } // function global_purge_old_posts |
fefa6ca3 | 268 | |
07d0efe9 AD |
269 | function feed_purge_interval($link, $feed_id) { |
270 | ||
271 | $result = db_query($link, "SELECT purge_interval, owner_uid FROM ttrss_feeds | |
272 | WHERE id = '$feed_id'"); | |
273 | ||
274 | if (db_num_rows($result) == 1) { | |
275 | $purge_interval = db_fetch_result($result, 0, "purge_interval"); | |
276 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); | |
277 | ||
278 | if ($purge_interval == 0) $purge_interval = get_pref($link, | |
279 | 'PURGE_OLD_DAYS', $user_id); | |
280 | ||
281 | return $purge_interval; | |
282 | ||
283 | } else { | |
284 | return -1; | |
285 | } | |
286 | } | |
287 | ||
b6eefba5 | 288 | function purge_old_posts($link) { |
5d73494a | 289 | |
f1a80dae AD |
290 | $user_id = $_SESSION["uid"]; |
291 | ||
292 | $result = db_query($link, "SELECT id,purge_interval FROM ttrss_feeds | |
293 | WHERE owner_uid = '$user_id'"); | |
5d73494a AD |
294 | |
295 | while ($line = db_fetch_assoc($result)) { | |
296 | ||
297 | $feed_id = $line["id"]; | |
298 | $purge_interval = $line["purge_interval"]; | |
299 | ||
b619ff15 | 300 | if ($purge_interval == 0) $purge_interval = get_pref($link, 'PURGE_OLD_DAYS'); |
5d73494a | 301 | |
140aae81 | 302 | if ($purge_interval > 0) { |
fefa6ca3 | 303 | purge_feed($link, $feed_id, $purge_interval); |
5d73494a AD |
304 | } |
305 | } | |
71604ca4 AD |
306 | |
307 | // purge orphaned posts in main content table | |
308 | db_query($link, "DELETE FROM ttrss_entries WHERE | |
309 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); | |
c3a8d71a AD |
310 | } |
311 | ||
c7d57b66 AD |
312 | function get_feed_update_interval($link, $feed_id) { |
313 | $result = db_query($link, "SELECT owner_uid, update_interval FROM | |
314 | ttrss_feeds WHERE id = '$feed_id'"); | |
315 | ||
316 | if (db_num_rows($result) == 1) { | |
317 | $update_interval = db_fetch_result($result, 0, "update_interval"); | |
318 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); | |
319 | ||
320 | if ($update_interval != 0) { | |
321 | return $update_interval; | |
322 | } else { | |
323 | return get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $owner_uid, false); | |
324 | } | |
325 | ||
326 | } else { | |
327 | return -1; | |
328 | } | |
329 | } | |
330 | ||
1f2b01ed | 331 | function update_all_feeds($link, $fetch, $user_id = false, $force_daemon = false) { |
40d13c28 | 332 | |
4769ddaf | 333 | if (WEB_DEMO_MODE) return; |
b0b4abcf | 334 | |
a2770077 AD |
335 | if (!$user_id) { |
336 | $user_id = $_SESSION["uid"]; | |
337 | purge_old_posts($link); | |
338 | } | |
339 | ||
25af8dad | 340 | // db_query($link, "BEGIN"); |
b82af8c3 | 341 | |
cbd8650d AD |
342 | if (MAX_UPDATE_TIME > 0) { |
343 | if (DB_TYPE == "mysql") { | |
344 | $q_order = "RAND()"; | |
345 | } else { | |
346 | $q_order = "RANDOM()"; | |
347 | } | |
348 | } else { | |
349 | $q_order = "last_updated DESC"; | |
350 | } | |
351 | ||
d148926e | 352 | $result = db_query($link, "SELECT feed_url,id, |
fc2b26a6 | 353 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, |
5c563acd | 354 | update_interval FROM ttrss_feeds WHERE owner_uid = '$user_id' |
cbd8650d AD |
355 | ORDER BY $q_order"); |
356 | ||
357 | $upd_start = time(); | |
40d13c28 | 358 | |
b6eefba5 | 359 | while ($line = db_fetch_assoc($result)) { |
d148926e AD |
360 | $upd_intl = $line["update_interval"]; |
361 | ||
b619ff15 | 362 | if (!$upd_intl || $upd_intl == 0) { |
e289ca71 | 363 | $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id, false); |
b619ff15 | 364 | } |
d148926e | 365 | |
c1e202b7 AD |
366 | if ($upd_intl < 0) { |
367 | // Updates for this feed are disabled | |
368 | continue; | |
369 | } | |
370 | ||
93d40f50 AD |
371 | if ($fetch || (!$line["last_updated"] || |
372 | time() - strtotime($line["last_updated"]) > ($upd_intl * 60))) { | |
c5142cca | 373 | |
cbd8650d AD |
374 | // print "<!-- feed: ".$line["feed_url"]." -->"; |
375 | ||
1f2b01ed | 376 | update_rss_feed($link, $line["feed_url"], $line["id"], $force_daemon); |
cbd8650d AD |
377 | |
378 | $upd_elapsed = time() - $upd_start; | |
379 | ||
380 | if (MAX_UPDATE_TIME > 0 && $upd_elapsed > MAX_UPDATE_TIME) { | |
381 | return; | |
382 | } | |
d148926e | 383 | } |
40d13c28 AD |
384 | } |
385 | ||
25af8dad | 386 | // db_query($link, "COMMIT"); |
b82af8c3 | 387 | |
40d13c28 AD |
388 | } |
389 | ||
4065b60b AD |
390 | function fetch_file_contents($url) { |
391 | if (USE_CURL_FOR_ICONS) { | |
392 | $tmpfile = tempnam(TMP_DIRECTORY, "ttrss-tmp"); | |
393 | ||
394 | $ch = curl_init($url); | |
395 | $fp = fopen($tmpfile, "w"); | |
396 | ||
397 | if ($fp) { | |
398 | curl_setopt($ch, CURLOPT_FILE, $fp); | |
dd966fed AD |
399 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); |
400 | curl_setopt($ch, CURLOPT_TIMEOUT, 45); | |
4065b60b AD |
401 | curl_exec($ch); |
402 | curl_close($ch); | |
403 | fclose($fp); | |
404 | } | |
405 | ||
406 | $contents = file_get_contents($tmpfile); | |
407 | unlink($tmpfile); | |
408 | ||
409 | return $contents; | |
410 | ||
411 | } else { | |
412 | return file_get_contents($url); | |
413 | } | |
414 | ||
415 | } | |
78800912 | 416 | |
9632f884 AD |
417 | /** |
418 | * Try to determine the favicon URL for a feed. | |
419 | * adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/) | |
420 | * http://dev.wp-plugins.org/file/favatars/trunk/favatars.php | |
421 | * | |
422 | * @param string $url A feed or page URL | |
423 | * @access public | |
424 | * @return mixed The favicon URL, or false if none was found. | |
425 | */ | |
4065b60b | 426 | function get_favicon_url($url) { |
99331724 | 427 | |
4065b60b | 428 | if ($html = @fetch_file_contents($url)) { |
78800912 | 429 | |
4065b60b AD |
430 | if ( preg_match('/<link[^>]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $html, $matches)) { |
431 | // Attempt to grab a favicon link from their webpage url | |
432 | $linkUrl = html_entity_decode($matches[1]); | |
c798704b | 433 | |
4065b60b AD |
434 | if (substr($linkUrl, 0, 1) == '/') { |
435 | $urlParts = parse_url($url); | |
436 | $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].$linkUrl; | |
437 | } else if (substr($linkUrl, 0, 7) == 'http://') { | |
438 | $faviconURL = $linkUrl; | |
439 | } else if (substr($url, -1, 1) == '/') { | |
440 | $faviconURL = $url.$linkUrl; | |
441 | } else { | |
442 | $faviconURL = $url.'/'.$linkUrl; | |
e695fdc8 | 443 | } |
717f5e64 | 444 | |
c798704b | 445 | } else { |
4065b60b AD |
446 | // If unsuccessful, attempt to "guess" the favicon location |
447 | $urlParts = parse_url($url); | |
448 | $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].'/favicon.ico'; | |
449 | } | |
450 | } | |
c798704b | 451 | |
4065b60b AD |
452 | // Run a test to see if what we have attempted to get actually exists. |
453 | if(USE_CURL_FOR_ICONS || url_validate($faviconURL)) { | |
454 | return $faviconURL; | |
455 | } else { | |
456 | return false; | |
457 | } | |
9632f884 | 458 | } // function get_favicon_url |
4065b60b | 459 | |
9632f884 AD |
460 | /** |
461 | * Check if a link is a valid and working URL. | |
462 | * | |
463 | * @param mixed $link A URL to check | |
464 | * @access public | |
465 | * @return boolean True if the URL is valid, false otherwise. | |
466 | */ | |
4065b60b AD |
467 | function url_validate($link) { |
468 | ||
469 | $url_parts = @parse_url($link); | |
470 | ||
471 | if ( empty( $url_parts["host"] ) ) | |
472 | return false; | |
473 | ||
474 | if ( !empty( $url_parts["path"] ) ) { | |
475 | $documentpath = $url_parts["path"]; | |
476 | } else { | |
477 | $documentpath = "/"; | |
478 | } | |
479 | ||
480 | if ( !empty( $url_parts["query"] ) ) | |
481 | $documentpath .= "?" . $url_parts["query"]; | |
482 | ||
483 | $host = $url_parts["host"]; | |
484 | $port = $url_parts["port"]; | |
485 | ||
486 | if ( empty($port) ) | |
487 | $port = "80"; | |
488 | ||
489 | $socket = @fsockopen( $host, $port, $errno, $errstr, 30 ); | |
490 | ||
491 | if ( !$socket ) | |
492 | return false; | |
c798704b | 493 | |
4065b60b AD |
494 | fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n"); |
495 | ||
496 | $http_response = fgets( $socket, 22 ); | |
497 | ||
498 | $responses = "/(200 OK)|(30[0-9] Moved)/"; | |
499 | if ( preg_match($responses, $http_response) ) { | |
500 | fclose($socket); | |
501 | return true; | |
502 | } else { | |
503 | return false; | |
504 | } | |
505 | ||
9632f884 | 506 | } // function url_validate |
4065b60b AD |
507 | |
508 | function check_feed_favicon($site_url, $feed, $link) { | |
509 | $favicon_url = get_favicon_url($site_url); | |
510 | ||
511 | # print "FAVICON [$site_url]: $favicon_url\n"; | |
512 | ||
513 | error_reporting(0); | |
514 | ||
515 | $icon_file = ICONS_DIR . "/$feed.ico"; | |
516 | ||
517 | if ($favicon_url && !file_exists($icon_file)) { | |
518 | $contents = fetch_file_contents($favicon_url); | |
519 | ||
520 | $fp = fopen($icon_file, "w"); | |
78800912 | 521 | |
4065b60b AD |
522 | if ($fp) { |
523 | fwrite($fp, $contents); | |
524 | fclose($fp); | |
525 | chmod($icon_file, 0644); | |
526 | } | |
78800912 | 527 | } |
4065b60b AD |
528 | |
529 | error_reporting(DEFAULT_ERROR_LEVEL); | |
530 | ||
78800912 AD |
531 | } |
532 | ||
ddb68b81 | 533 | function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) { |
40d13c28 | 534 | |
17c0eeba | 535 | if (!$_GET["daemon"] && !$ignore_daemon) { |
45004d43 | 536 | return false; |
21cfcdf2 AD |
537 | } |
538 | ||
4bc64807 | 539 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb | 540 | _debug("update_rss_feed: start"); |
219bd8fc AD |
541 | } |
542 | ||
39a52499 AD |
543 | if (!$ignore_daemon) { |
544 | ||
545 | if (DB_TYPE == "pgsql") { | |
546 | $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')"; | |
547 | } else { | |
548 | $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))"; | |
549 | } | |
550 | ||
551 | $result = db_query($link, "SELECT id,update_interval,auth_login, | |
16211ddb | 552 | auth_pass,cache_images,update_method |
39a52499 | 553 | FROM ttrss_feeds WHERE id = '$feed' AND $updstart_thresh_qpart"); |
02008cb1 | 554 | |
39a52499 AD |
555 | } else { |
556 | ||
557 | $result = db_query($link, "SELECT id,update_interval,auth_login, | |
16211ddb | 558 | auth_pass,cache_images,update_method |
39a52499 AD |
559 | FROM ttrss_feeds WHERE id = '$feed'"); |
560 | ||
561 | } | |
a88c1f36 | 562 | |
5370d37f AD |
563 | if (db_num_rows($result) == 0) { |
564 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
02008cb1 | 565 | _debug("update_rss_feed: feed $feed [$feed_url] NOT FOUND/SKIPPED"); |
5370d37f | 566 | } |
45004d43 | 567 | return false; |
5370d37f AD |
568 | } |
569 | ||
16211ddb AD |
570 | $update_method = db_fetch_result($result, 0, "update_method"); |
571 | ||
3c50da83 AD |
572 | db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW() |
573 | WHERE id = '$feed'"); | |
574 | ||
464bd61e AD |
575 | $auth_login = db_fetch_result($result, 0, "auth_login"); |
576 | $auth_pass = db_fetch_result($result, 0, "auth_pass"); | |
577 | ||
34459667 AD |
578 | if (ALLOW_SELECT_UPDATE_METHOD) { |
579 | if (ENABLE_SIMPLEPIE) { | |
580 | $use_simplepie = $update_method != 1; | |
581 | } else { | |
582 | $use_simplepie = $update_method == 2; | |
583 | } | |
16211ddb | 584 | } else { |
34459667 | 585 | $use_simplepie = ENABLE_SIMPLEPIE; |
16211ddb AD |
586 | } |
587 | ||
588 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
589 | _debug("use simplepie: $use_simplepie (feed setting: $update_method)\n"); | |
590 | } | |
591 | ||
592 | if (!$use_simplepie) { | |
464bd61e AD |
593 | $auth_login = urlencode($auth_login); |
594 | $auth_pass = urlencode($auth_pass); | |
595 | } | |
47c6c988 | 596 | |
a88c1f36 | 597 | $update_interval = db_fetch_result($result, 0, "update_interval"); |
bc0f0785 | 598 | $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); |
a88c1f36 AD |
599 | |
600 | if ($update_interval < 0) { return; } | |
601 | ||
ab3d0b99 AD |
602 | $feed = db_escape_string($feed); |
603 | ||
47c6c988 AD |
604 | $fetch_url = $feed_url; |
605 | ||
606 | if ($auth_login && $auth_pass) { | |
607 | $url_parts = array(); | |
608 | preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts); | |
609 | ||
610 | if ($url_parts[1] && $url_parts[2]) { | |
611 | $fetch_url = $url_parts[1] . "://$auth_login:$auth_pass@" . $url_parts[2]; | |
612 | } | |
613 | ||
614 | } | |
ab3d0b99 | 615 | |
4bc64807 | 616 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
ca872b9d | 617 | _debug("update_rss_feed: fetching [$fetch_url]..."); |
219bd8fc AD |
618 | } |
619 | ||
9fdf7824 | 620 | if (!defined('DAEMON_EXTENDED_DEBUG') && !$_GET['xdebug']) { |
219bd8fc AD |
621 | error_reporting(0); |
622 | } | |
623 | ||
16211ddb | 624 | if (!$use_simplepie) { |
9fdf7824 AD |
625 | $rss = fetch_rss($fetch_url); |
626 | } else { | |
c7d57b66 AD |
627 | if (!is_dir(SIMPLEPIE_CACHE_DIR)) { |
628 | mkdir(SIMPLEPIE_CACHE_DIR); | |
629 | } | |
630 | ||
ca872b9d AD |
631 | $rss = new SimplePie(); |
632 | $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT); | |
16211ddb | 633 | # $rss->set_timeout(10); |
ca872b9d AD |
634 | $rss->set_feed_url($fetch_url); |
635 | $rss->set_output_encoding('UTF-8'); | |
c7d57b66 | 636 | |
bc0f0785 AD |
637 | if (SIMPLEPIE_CACHE_IMAGES && $cache_images) { |
638 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
639 | _debug("enabling image cache"); | |
640 | } | |
641 | ||
dab52d7b | 642 | $rss->set_image_handler('./image.php', 'i'); |
bc0f0785 | 643 | } |
dab52d7b | 644 | |
c7d57b66 AD |
645 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
646 | _debug("feed update interval (sec): " . | |
647 | get_feed_update_interval($link, $feed)*60); | |
648 | } | |
649 | ||
650 | if (is_dir(SIMPLEPIE_CACHE_DIR)) { | |
651 | $rss->set_cache_location(SIMPLEPIE_CACHE_DIR); | |
652 | $rss->set_cache_duration(get_feed_update_interval($link, $feed) * 60); | |
653 | } | |
654 | ||
9fdf7824 | 655 | $rss->init(); |
9fdf7824 AD |
656 | } |
657 | ||
658 | // print_r($rss); | |
219bd8fc | 659 | |
4bc64807 | 660 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb | 661 | _debug("update_rss_feed: fetch done, parsing..."); |
219bd8fc AD |
662 | } else { |
663 | error_reporting (DEFAULT_ERROR_LEVEL); | |
664 | } | |
665 | ||
b6eefba5 | 666 | $feed = db_escape_string($feed); |
dcee8f61 | 667 | |
16211ddb | 668 | if ($use_simplepie) { |
ca872b9d AD |
669 | $fetch_ok = !$rss->error(); |
670 | } else { | |
671 | $fetch_ok = !!$rss; | |
672 | } | |
673 | ||
674 | if ($fetch_ok) { | |
50b62214 | 675 | |
4bc64807 | 676 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
677 | _debug("update_rss_feed: processing feed data..."); |
678 | } | |
679 | ||
44e241cb | 680 | // db_query($link, "BEGIN"); |
dd8c76a9 | 681 | |
a88c1f36 | 682 | $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid |
f324892e | 683 | FROM ttrss_feeds WHERE id = '$feed'"); |
331900c6 | 684 | |
b6eefba5 AD |
685 | $registered_title = db_fetch_result($result, 0, "title"); |
686 | $orig_icon_url = db_fetch_result($result, 0, "icon_url"); | |
f324892e | 687 | $orig_site_url = db_fetch_result($result, 0, "site_url"); |
331900c6 | 688 | |
7fed1940 AD |
689 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); |
690 | ||
16211ddb | 691 | if ($use_simplepie) { |
9fdf7824 AD |
692 | $site_url = $rss->get_link(); |
693 | } else { | |
694 | $site_url = $rss->channel["link"]; | |
695 | } | |
696 | ||
8d0ec6fd | 697 | if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid, false)) { |
4bc64807 | 698 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
699 | _debug("update_rss_feed: checking favicon..."); |
700 | } | |
9fdf7824 AD |
701 | |
702 | check_feed_favicon($site_url, $feed, $link); | |
a2770077 AD |
703 | } |
704 | ||
746b249f | 705 | if (!$registered_title || $registered_title == "[Unknown]") { |
4bc64807 | 706 | |
16211ddb | 707 | if ($use_simplepie) { |
c2f8aac4 | 708 | $feed_title = db_escape_string($rss->get_title()); |
fb486a33 AD |
709 | } else { |
710 | $feed_title = db_escape_string($rss->channel["title"]); | |
711 | } | |
4bc64807 AD |
712 | |
713 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
714 | _debug("update_rss_feed: registering title: $feed_title"); | |
715 | } | |
7c5a308d | 716 | |
f324892e AD |
717 | db_query($link, "UPDATE ttrss_feeds SET |
718 | title = '$feed_title' WHERE id = '$feed'"); | |
719 | } | |
720 | ||
49f9c923 | 721 | // weird, weird Magpie |
16211ddb | 722 | if (!$use_simplepie) { |
9fdf7824 AD |
723 | if (!$site_url) $site_url = db_escape_string($rss->channel["link_"]); |
724 | } | |
147f7691 AD |
725 | |
726 | if ($site_url && $orig_site_url != db_escape_string($site_url)) { | |
f324892e AD |
727 | db_query($link, "UPDATE ttrss_feeds SET |
728 | site_url = '$site_url' WHERE id = '$feed'"); | |
331900c6 | 729 | } |
40d13c28 | 730 | |
b7f4bda2 AD |
731 | // print "I: " . $rss->channel["image"]["url"]; |
732 | ||
16211ddb | 733 | if (!$use_simplepie) { |
9fdf7824 AD |
734 | $icon_url = $rss->image["url"]; |
735 | } else { | |
736 | $icon_url = $rss->get_image_url(); | |
737 | } | |
b7f4bda2 | 738 | |
147f7691 | 739 | if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) { |
b6eefba5 AD |
740 | $icon_url = db_escape_string($icon_url); |
741 | db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'"); | |
b7f4bda2 AD |
742 | } |
743 | ||
51e456d6 | 744 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
745 | _debug("update_rss_feed: loading filters..."); |
746 | } | |
e6155a06 | 747 | |
5daa24f2 | 748 | $filters = load_filters($link, $feed, $owner_uid); |
e6155a06 | 749 | |
16211ddb | 750 | if ($use_simplepie) { |
9fdf7824 AD |
751 | $iterator = $rss->get_items(); |
752 | } else { | |
753 | $iterator = $rss->items; | |
754 | if (!$iterator || !is_array($iterator)) $iterator = $rss->entries; | |
755 | if (!$iterator || !is_array($iterator)) $iterator = $rss; | |
756 | } | |
c22789da AD |
757 | |
758 | if (!is_array($iterator)) { | |
39541e74 | 759 | /* db_query($link, "UPDATE ttrss_feeds |
75bd0669 | 760 | SET last_error = 'Parse error: can\'t find any articles.' |
77f0a2a7 AD |
761 | WHERE id = '$feed'"); */ |
762 | ||
763 | // clear any errors and mark feed as updated if fetched okay | |
764 | // even if it's blank | |
765 | ||
51e456d6 | 766 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
844012bc AD |
767 | _debug("update_rss_feed: entry iterator is not an array, no articles?"); |
768 | } | |
769 | ||
77f0a2a7 AD |
770 | db_query($link, "UPDATE ttrss_feeds |
771 | SET last_updated = NOW(), last_error = '' WHERE id = '$feed'"); | |
772 | ||
773 | return; // no articles | |
c22789da | 774 | } |
ddb68b81 | 775 | |
51e456d6 | 776 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
777 | _debug("update_rss_feed: processing articles..."); |
778 | } | |
779 | ||
ddb68b81 | 780 | foreach ($iterator as $item) { |
7c5a308d | 781 | |
40ce98f4 AD |
782 | if ($_GET['xdebug']) { |
783 | print_r($item); | |
ea322415 | 784 | |
40ce98f4 | 785 | } |
71bd29f6 | 786 | |
16211ddb | 787 | if ($use_simplepie) { |
9fdf7824 AD |
788 | $entry_guid = $item->get_id(); |
789 | if (!$entry_guid) $entry_guid = $item->get_link(); | |
790 | if (!$entry_guid) $entry_guid = make_guid_from_title($item->get_title()); | |
791 | ||
792 | } else { | |
793 | ||
794 | $entry_guid = $item["id"]; | |
34e420fb | 795 | |
9fdf7824 AD |
796 | if (!$entry_guid) $entry_guid = $item["guid"]; |
797 | if (!$entry_guid) $entry_guid = $item["link"]; | |
798 | if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]); | |
799 | } | |
be832a1a | 800 | |
9fdf7824 | 801 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
802 | _debug("update_rss_feed: guid $entry_guid"); |
803 | } | |
804 | ||
be832a1a AD |
805 | if (!$entry_guid) continue; |
806 | ||
807 | $entry_timestamp = ""; | |
808 | ||
16211ddb | 809 | if ($use_simplepie) { |
9fdf7824 AD |
810 | $entry_timestamp = strtotime($item->get_date()); |
811 | } else { | |
812 | $rss_2_date = $item['pubdate']; | |
813 | $rss_1_date = $item['dc']['date']; | |
814 | $atom_date = $item['issued']; | |
815 | if (!$atom_date) $atom_date = $item['updated']; | |
be832a1a | 816 | |
9fdf7824 AD |
817 | if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date); |
818 | if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date); | |
819 | if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date); | |
820 | } | |
9bb36aa0 | 821 | |
2e930846 | 822 | if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) { |
be832a1a AD |
823 | $entry_timestamp = time(); |
824 | $no_orig_date = 'true'; | |
825 | } else { | |
826 | $no_orig_date = 'false'; | |
827 | } | |
828 | ||
829 | $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); | |
830 | ||
44d0e774 AD |
831 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
832 | _debug("update_rss_feed: date $entry_timestamp [$entry_timestamp_fmt]"); | |
833 | } | |
834 | ||
16211ddb | 835 | if ($use_simplepie) { |
9fdf7824 AD |
836 | $entry_title = $item->get_title(); |
837 | } else { | |
838 | $entry_title = trim(strip_tags($item["title"])); | |
839 | } | |
be832a1a | 840 | |
16211ddb | 841 | if ($use_simplepie) { |
9fdf7824 AD |
842 | $entry_link = $item->get_link(); |
843 | } else { | |
844 | // strange Magpie workaround | |
845 | $entry_link = $item["link_"]; | |
846 | if (!$entry_link) $entry_link = $item["link"]; | |
847 | } | |
be832a1a | 848 | |
9bb36aa0 AD |
849 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
850 | _debug("update_rss_feed: title $entry_title"); | |
851 | } | |
852 | ||
853 | if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);; | |
7d3ab0dd | 854 | |
be832a1a | 855 | $entry_link = strip_tags($entry_link); |
7d3ab0dd | 856 | |
16211ddb | 857 | if ($use_simplepie) { |
4af7a36a AD |
858 | $entry_content = $item->get_content(); |
859 | if (!$entry_content) $entry_content = $item->get_description(); | |
9fdf7824 AD |
860 | } else { |
861 | $entry_content = $item["content:escaped"]; | |
862 | ||
863 | if (!$entry_content) $entry_content = $item["content:encoded"]; | |
e91ab107 | 864 | if (!$entry_content) $entry_content = $item["content"]["encoded"]; |
9fdf7824 | 865 | if (!$entry_content) $entry_content = $item["content"]; |
ea322415 AD |
866 | |
867 | // Magpie bugs are getting ridiculous | |
868 | if (trim($entry_content) == "Array") $entry_content = false; | |
869 | ||
9fdf7824 AD |
870 | if (!$entry_content) $entry_content = $item["atom_content"]; |
871 | if (!$entry_content) $entry_content = $item["summary"]; | |
e91ab107 AD |
872 | |
873 | if (!$entry_content || | |
874 | strlen($entry_content) < strlen($item["description"])) { | |
875 | $entry_content = $item["description"]; | |
876 | }; | |
9fdf7824 AD |
877 | |
878 | // WTF | |
879 | if (is_array($entry_content)) { | |
880 | $entry_content = $entry_content["encoded"]; | |
881 | if (!$entry_content) $entry_content = $entry_content["escaped"]; | |
ea322415 | 882 | } |
be832a1a AD |
883 | } |
884 | ||
ea322415 AD |
885 | if ($_GET["xdebug"]) { |
886 | print "update_rss_feed: content: "; | |
887 | print_r(htmlspecialchars($entry_content)); | |
888 | } | |
be832a1a AD |
889 | |
890 | $entry_content_unescaped = $entry_content; | |
be832a1a | 891 | |
16211ddb | 892 | if ($use_simplepie) { |
9fdf7824 | 893 | $entry_comments = strip_tags($item->data["comments"]); |
30cf38dd | 894 | if ($item->get_author()) { |
e1d600f0 | 895 | $entry_author_item = $item->get_author(); |
a0c6eafb AD |
896 | $entry_author = $entry_author_item->get_name(); |
897 | if (!$entry_author) $entry_author = $entry_author_item->get_email(); | |
d1ee9106 AD |
898 | |
899 | $entry_author = db_escape_string($entry_author); | |
30cf38dd | 900 | } |
9fdf7824 AD |
901 | } else { |
902 | $entry_comments = strip_tags($item["comments"]); | |
903 | ||
904 | $entry_author = db_escape_string(strip_tags($item['dc']['creator'])); | |
4d6e9157 | 905 | |
9fdf7824 AD |
906 | if ($item['author']) { |
907 | ||
908 | if (is_array($item['author'])) { | |
909 | ||
910 | if (!$entry_author) { | |
911 | $entry_author = db_escape_string(strip_tags($item['author']['name'])); | |
912 | } | |
913 | ||
914 | if (!$entry_author) { | |
915 | $entry_author = db_escape_string(strip_tags($item['author']['email'])); | |
916 | } | |
4d6e9157 | 917 | } |
9fdf7824 | 918 | |
4d6e9157 | 919 | if (!$entry_author) { |
9fdf7824 | 920 | $entry_author = db_escape_string(strip_tags($item['author'])); |
4d6e9157 | 921 | } |
83f114c8 | 922 | } |
be832a1a AD |
923 | } |
924 | ||
83f114c8 AD |
925 | if (preg_match('/^[\t\n\r ]*$/', $entry_author)) $entry_author = ''; |
926 | ||
be832a1a | 927 | $entry_guid = db_escape_string(strip_tags($entry_guid)); |
2ad9ee56 | 928 | $entry_guid = mb_substr($entry_guid, 0, 250); |
be832a1a AD |
929 | |
930 | $result = db_query($link, "SELECT id FROM ttrss_entries | |
931 | WHERE guid = '$entry_guid'"); | |
932 | ||
933 | $entry_content = db_escape_string($entry_content); | |
7e43ad58 AD |
934 | |
935 | $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); | |
936 | ||
be832a1a AD |
937 | $entry_title = db_escape_string($entry_title); |
938 | $entry_link = db_escape_string($entry_link); | |
2544f36b AD |
939 | $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250); |
940 | $entry_author = mb_substr($entry_author, 0, 250); | |
be832a1a | 941 | |
16211ddb | 942 | if ($use_simplepie) { |
9fdf7824 AD |
943 | $num_comments = 0; #FIXME# |
944 | } else { | |
945 | $num_comments = db_escape_string($item["slash"]["comments"]); | |
946 | } | |
be832a1a AD |
947 | |
948 | if (!$num_comments) $num_comments = 0; | |
949 | ||
fefef828 | 950 | // parse <category> entries into tags |
be832a1a | 951 | |
16211ddb | 952 | if ($use_simplepie) { |
be832a1a | 953 | |
fefef828 | 954 | $additional_tags = array(); |
9fdf7824 | 955 | $additional_tags_src = $item->get_categories(); |
3b9e5af4 | 956 | |
a702e931 AD |
957 | if (is_array($additional_tags_src)) { |
958 | foreach ($additional_tags_src as $tobj) { | |
959 | array_push($additional_tags, $tobj->get_term()); | |
960 | } | |
fefef828 | 961 | } |
fefef828 | 962 | |
6af621c7 AD |
963 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
964 | _debug("update_rss_feed: category tags:"); | |
965 | print_r($additional_tags); | |
966 | } | |
967 | ||
9fdf7824 | 968 | } else { |
fefef828 | 969 | |
9fdf7824 | 970 | $t_ctr = $item['category#']; |
fefef828 | 971 | |
9fdf7824 AD |
972 | $additional_tags = false; |
973 | ||
974 | if ($t_ctr == 0) { | |
975 | $additional_tags = false; | |
71bd29f6 | 976 | } else if ($t_ctr > 0) { |
9fdf7824 | 977 | $additional_tags = array($item['category']); |
71bd29f6 AD |
978 | |
979 | if ($item['category@term']) { | |
980 | array_push($additional_tags, $item['category@term']); | |
981 | } | |
982 | ||
9fdf7824 AD |
983 | for ($i = 0; $i <= $t_ctr; $i++ ) { |
984 | if ($item["category#$i"]) { | |
985 | array_push($additional_tags, $item["category#$i"]); | |
986 | } | |
71bd29f6 AD |
987 | |
988 | if ($item["category#$i@term"]) { | |
989 | array_push($additional_tags, $item["category#$i@term"]); | |
990 | } | |
9fdf7824 AD |
991 | } |
992 | } | |
993 | ||
994 | // parse <dc:subject> elements | |
995 | ||
996 | $t_ctr = $item['dc']['subject#']; | |
997 | ||
71bd29f6 | 998 | if ($t_ctr > 0) { |
9fdf7824 | 999 | $additional_tags = array($item['dc']['subject']); |
71bd29f6 | 1000 | |
9fdf7824 AD |
1001 | for ($i = 0; $i <= $t_ctr; $i++ ) { |
1002 | if ($item['dc']["subject#$i"]) { | |
1003 | array_push($additional_tags, $item['dc']["subject#$i"]); | |
1004 | } | |
fefef828 AD |
1005 | } |
1006 | } | |
1007 | } | |
8add756a | 1008 | |
ce53e200 AD |
1009 | // enclosures |
1010 | ||
1011 | $enclosures = array(); | |
1012 | ||
16211ddb | 1013 | if ($use_simplepie) { |
ce53e200 AD |
1014 | $encs = $item->get_enclosures(); |
1015 | ||
3b9e5af4 AD |
1016 | if (is_array($encs)) { |
1017 | foreach ($encs as $e) { | |
1018 | $e_item = array( | |
1019 | $e->link, $e->type, $e->length); | |
1020 | ||
1021 | array_push($enclosures, $e_item); | |
1022 | } | |
ce53e200 AD |
1023 | } |
1024 | ||
1025 | } else { | |
e91ab107 AD |
1026 | // <enclosure> |
1027 | ||
ce53e200 AD |
1028 | $e_ctr = $item['enclosure#']; |
1029 | ||
1030 | if ($e_ctr > 0) { | |
1031 | $e_item = array($item['enclosure@url'], | |
1032 | $item['enclosure@type'], | |
1033 | $item['enclosure@length']); | |
1034 | ||
1035 | array_push($enclosures, $e_item); | |
1036 | ||
71bd29f6 AD |
1037 | for ($i = 0; $i <= $e_ctr; $i++ ) { |
1038 | ||
1039 | if ($item["enclosure#$i@url"]) { | |
1040 | $e_item = array($item["enclosure#$i@url"], | |
1041 | $item["enclosure#$i@type"], | |
1042 | $item["enclosure#$i@length"]); | |
1043 | array_push($enclosures, $e_item); | |
1044 | } | |
ce53e200 AD |
1045 | } |
1046 | } | |
1047 | ||
e91ab107 | 1048 | // <media:content> |
b652fdae | 1049 | // can there be many of those? yes -fox |
e91ab107 AD |
1050 | |
1051 | $m_ctr = $item['media']['content#']; | |
1052 | ||
1053 | if ($m_ctr > 0) { | |
1054 | $e_item = array($item['media']['content@url'], | |
1055 | $item['media']['content@medium'], | |
1056 | $item['media']['content@length']); | |
1057 | ||
1058 | array_push($enclosures, $e_item); | |
e91ab107 | 1059 | |
b652fdae AD |
1060 | for ($i = 0; $i <= $m_ctr; $i++ ) { |
1061 | ||
1062 | if ($item["media"]["content#$i@url"]) { | |
1063 | $e_item = array($item["media"]["content#$i@url"], | |
1064 | $item["media"]["content#$i@medium"], | |
1065 | $item["media"]["content#$i@length"]); | |
1066 | array_push($enclosures, $e_item); | |
1067 | } | |
1068 | } | |
1069 | ||
1070 | } | |
ce53e200 AD |
1071 | } |
1072 | ||
d48d160c | 1073 | # sanitize content |
183ad07b | 1074 | |
621ffb00 AD |
1075 | $entry_content = sanitize_article_content($entry_content); |
1076 | $entry_title = sanitize_article_content($entry_title); | |
d48d160c | 1077 | |
9fdf7824 | 1078 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
1079 | _debug("update_rss_feed: done collecting data [TITLE:$entry_title]"); |
1080 | } | |
1081 | ||
44e241cb AD |
1082 | db_query($link, "BEGIN"); |
1083 | ||
4c193675 AD |
1084 | if (db_num_rows($result) == 0) { |
1085 | ||
9fdf7824 | 1086 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
1087 | _debug("update_rss_feed: base guid not found"); |
1088 | } | |
1089 | ||
4c193675 AD |
1090 | // base post entry does not exist, create it |
1091 | ||
4c193675 AD |
1092 | $result = db_query($link, |
1093 | "INSERT INTO ttrss_entries | |
1094 | (title, | |
1095 | guid, | |
1096 | link, | |
1097 | updated, | |
1098 | content, | |
1099 | content_hash, | |
1100 | no_orig_date, | |
1101 | date_entered, | |
11b0dce2 | 1102 | comments, |
b6104dee AD |
1103 | num_comments, |
1104 | author) | |
4c193675 AD |
1105 | VALUES |
1106 | ('$entry_title', | |
1107 | '$entry_guid', | |
1108 | '$entry_link', | |
1109 | '$entry_timestamp_fmt', | |
1110 | '$entry_content', | |
1111 | '$content_hash', | |
1112 | $no_orig_date, | |
1113 | NOW(), | |
11b0dce2 | 1114 | '$entry_comments', |
b6104dee AD |
1115 | '$num_comments', |
1116 | '$entry_author')"); | |
8926aab8 AD |
1117 | } else { |
1118 | // we keep encountering the entry in feeds, so we need to | |
1119 | // update date_entered column so that we don't get horrible | |
1120 | // dupes when the entry gets purged and reinserted again e.g. | |
1121 | // in the case of SLOW SLOW OMG SLOW updating feeds | |
1122 | ||
1123 | $base_entry_id = db_fetch_result($result, 0, "id"); | |
1124 | ||
1125 | db_query($link, "UPDATE ttrss_entries SET date_entered = NOW() | |
1126 | WHERE id = '$base_entry_id'"); | |
4c193675 AD |
1127 | } |
1128 | ||
1129 | // now it should exist, if not - bad luck then | |
1130 | ||
6385315d AD |
1131 | $result = db_query($link, "SELECT |
1132 | id,content_hash,no_orig_date,title, | |
2ac6b765 AD |
1133 | ".SUBSTRING_FOR_DATE."(date_entered,1,19) as date_entered, |
1134 | ".SUBSTRING_FOR_DATE."(updated,1,19) as updated, | |
11b0dce2 | 1135 | num_comments |
6385315d AD |
1136 | FROM |
1137 | ttrss_entries | |
1138 | WHERE guid = '$entry_guid'"); | |
4c193675 | 1139 | |
ce53e200 AD |
1140 | $entry_ref_id = 0; |
1141 | $entry_int_id = 0; | |
1142 | ||
4c193675 AD |
1143 | if (db_num_rows($result) == 1) { |
1144 | ||
9fdf7824 | 1145 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
7ca91eb3 | 1146 | _debug("update_rss_feed: base guid found, checking for user record"); |
34e420fb AD |
1147 | } |
1148 | ||
11b0dce2 AD |
1149 | // this will be used below in update handler |
1150 | $orig_content_hash = db_fetch_result($result, 0, "content_hash"); | |
1151 | $orig_title = db_fetch_result($result, 0, "title"); | |
1152 | $orig_num_comments = db_fetch_result($result, 0, "num_comments"); | |
8926aab8 AD |
1153 | $orig_date_entered = strtotime(db_fetch_result($result, |
1154 | 0, "date_entered")); | |
6385315d | 1155 | |
11b0dce2 | 1156 | $ref_id = db_fetch_result($result, 0, "id"); |
ce53e200 | 1157 | $entry_ref_id = $ref_id; |
4c193675 | 1158 | |
11b0dce2 | 1159 | // check for user post link to main table |
4c193675 | 1160 | |
11b0dce2 | 1161 | // do we allow duplicate posts with same GUID in different feeds? |
8d0ec6fd | 1162 | if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) { |
11b0dce2 AD |
1163 | $dupcheck_qpart = "AND feed_id = '$feed'"; |
1164 | } else { | |
1165 | $dupcheck_qpart = ""; | |
1166 | } | |
71604ca4 | 1167 | |
11b0dce2 | 1168 | // error_reporting(0); |
19c9cb11 | 1169 | |
f8382011 | 1170 | $article_filters = get_article_filters($filters, $entry_title, |
44d0e774 | 1171 | $entry_content, $entry_link, $entry_timestamp); |
19c9cb11 | 1172 | |
9fdf7824 | 1173 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
7ca91eb3 AD |
1174 | _debug("update_rss_feed: article filters: "); |
1175 | if (count($article_filters) != 0) { | |
1176 | print_r($article_filters); | |
1177 | } | |
1178 | } | |
1179 | ||
f8382011 | 1180 | if (find_article_filter($article_filters, "filter")) { |
ee4a9812 | 1181 | db_query($link, "COMMIT"); // close transaction in progress |
11b0dce2 AD |
1182 | continue; |
1183 | } | |
19c9cb11 | 1184 | |
11b0dce2 | 1185 | // error_reporting (DEFAULT_ERROR_LEVEL); |
3a933f22 | 1186 | |
ff6e357a AD |
1187 | $score = calculate_article_score($article_filters); |
1188 | ||
1189 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1190 | _debug("update_rss_feed: initial score: $score"); | |
1191 | } | |
1192 | ||
11b0dce2 | 1193 | $result = db_query($link, |
ce53e200 | 1194 | "SELECT ref_id, int_id FROM ttrss_user_entries WHERE |
11b0dce2 AD |
1195 | ref_id = '$ref_id' AND owner_uid = '$owner_uid' |
1196 | $dupcheck_qpart"); | |
7ca91eb3 | 1197 | |
11b0dce2 AD |
1198 | // okay it doesn't exist - create user entry |
1199 | if (db_num_rows($result) == 0) { | |
1200 | ||
9fdf7824 | 1201 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
7ca91eb3 AD |
1202 | _debug("update_rss_feed: user record not found, creating..."); |
1203 | } | |
1204 | ||
24605713 | 1205 | if ($score >= -500 && !find_article_filter($article_filters, 'catchup')) { |
11b0dce2 AD |
1206 | $unread = 'true'; |
1207 | $last_read_qpart = 'NULL'; | |
1208 | } else { | |
1209 | $unread = 'false'; | |
1210 | $last_read_qpart = 'NOW()'; | |
1211 | } | |
dd7d3187 | 1212 | |
32d59314 | 1213 | if (find_article_filter($article_filters, 'mark') || $score > 1000) { |
dd7d3187 AD |
1214 | $marked = 'true'; |
1215 | } else { | |
1216 | $marked = 'false'; | |
1217 | } | |
a36c0dfe AD |
1218 | |
1219 | if (find_article_filter($article_filters, 'publish')) { | |
1220 | $published = 'true'; | |
1221 | } else { | |
1222 | $published = 'false'; | |
1223 | } | |
1224 | ||
11b0dce2 AD |
1225 | $result = db_query($link, |
1226 | "INSERT INTO ttrss_user_entries | |
ff6e357a AD |
1227 | (ref_id, owner_uid, feed_id, unread, last_read, marked, |
1228 | published, score) | |
11b0dce2 | 1229 | VALUES ('$ref_id', '$owner_uid', '$feed', $unread, |
ff6e357a | 1230 | $last_read_qpart, $marked, $published, '$score')"); |
ce53e200 AD |
1231 | |
1232 | $result = db_query($link, | |
1233 | "SELECT int_id FROM ttrss_user_entries WHERE | |
1234 | ref_id = '$ref_id' AND owner_uid = '$owner_uid' AND | |
1235 | feed_id = '$feed' LIMIT 1"); | |
1236 | ||
1237 | if (db_num_rows($result) == 1) { | |
1238 | $entry_int_id = db_fetch_result($result, 0, "int_id"); | |
1239 | } | |
1240 | } else { | |
1241 | $entry_ref_id = db_fetch_result($result, 0, "ref_id"); | |
1242 | $entry_int_id = db_fetch_result($result, 0, "int_id"); | |
11b0dce2 | 1243 | } |
ce53e200 AD |
1244 | |
1245 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1246 | _debug("update_rss_feed: RID: $entry_ref_id, IID: $entry_int_id"); | |
1247 | } | |
1248 | ||
6385315d AD |
1249 | $post_needs_update = false; |
1250 | ||
8d0ec6fd | 1251 | if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid, false) && |
6385315d | 1252 | ($content_hash != $orig_content_hash)) { |
7e43ad58 | 1253 | // print "<!-- [$entry_title] $content_hash vs $orig_content_hash -->"; |
6385315d AD |
1254 | $post_needs_update = true; |
1255 | } | |
1256 | ||
7e43ad58 | 1257 | if (db_escape_string($orig_title) != $entry_title) { |
6385315d AD |
1258 | $post_needs_update = true; |
1259 | } | |
1260 | ||
11b0dce2 AD |
1261 | if ($orig_num_comments != $num_comments) { |
1262 | $post_needs_update = true; | |
1263 | } | |
1264 | ||
6385315d AD |
1265 | // this doesn't seem to be very reliable |
1266 | // | |
1267 | // if ($orig_timestamp != $entry_timestamp && !$orig_no_orig_date) { | |
1268 | // $post_needs_update = true; | |
1269 | // } | |
1270 | ||
1271 | // if post needs update, update it and mark all user entries | |
1c73bc0c | 1272 | // linking to this post as updated |
6385315d AD |
1273 | if ($post_needs_update) { |
1274 | ||
7ca91eb3 AD |
1275 | if (defined('DAEMON_EXTENDED_DEBUG')) { |
1276 | _debug("update_rss_feed: post $entry_guid needs update..."); | |
1277 | } | |
1278 | ||
6385315d AD |
1279 | // print "<!-- post $orig_title needs update : $post_needs_update -->"; |
1280 | ||
6385315d | 1281 | db_query($link, "UPDATE ttrss_entries |
11b0dce2 | 1282 | SET title = '$entry_title', content = '$entry_content', |
7e43ad58 | 1283 | content_hash = '$content_hash', |
11b0dce2 | 1284 | num_comments = '$num_comments' |
6385315d AD |
1285 | WHERE id = '$ref_id'"); |
1286 | ||
8d0ec6fd | 1287 | if (get_pref($link, "MARK_UNREAD_ON_UPDATE", $owner_uid, false)) { |
4919fb42 AD |
1288 | db_query($link, "UPDATE ttrss_user_entries |
1289 | SET last_read = null, unread = true WHERE ref_id = '$ref_id'"); | |
1290 | } else { | |
1291 | db_query($link, "UPDATE ttrss_user_entries | |
1292 | SET last_read = null WHERE ref_id = '$ref_id' AND unread = false"); | |
1293 | } | |
6385315d AD |
1294 | |
1295 | } | |
4c193675 AD |
1296 | } |
1297 | ||
44e241cb AD |
1298 | db_query($link, "COMMIT"); |
1299 | ||
ce53e200 AD |
1300 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
1301 | _debug("update_rss_feed: looking for enclosures..."); | |
1302 | } | |
1303 | ||
1304 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1305 | print_r($enclosures); | |
1306 | } | |
1307 | ||
1308 | db_query($link, "BEGIN"); | |
1309 | ||
1310 | foreach ($enclosures as $enc) { | |
1311 | $enc_url = db_escape_string($enc[0]); | |
1312 | $enc_type = db_escape_string($enc[1]); | |
1313 | $enc_dur = db_escape_string($enc[2]); | |
1314 | ||
1315 | $result = db_query($link, "SELECT id FROM ttrss_enclosures | |
1316 | WHERE content_url = '$enc_url' AND post_id = '$entry_ref_id'"); | |
1317 | ||
1318 | if (db_num_rows($result) == 0) { | |
1319 | db_query($link, "INSERT INTO ttrss_enclosures | |
1320 | (content_url, content_type, title, duration, post_id) VALUES | |
1321 | ('$enc_url', '$enc_type', '', '$enc_dur', '$entry_ref_id')"); | |
1322 | } | |
1323 | } | |
1324 | ||
1325 | db_query($link, "COMMIT"); | |
1326 | ||
9fdf7824 | 1327 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
1328 | _debug("update_rss_feed: looking for tags..."); |
1329 | } | |
1330 | ||
eb36b4eb | 1331 | /* taaaags */ |
40e1a95b | 1332 | // <a href="..." rel="tag">Xorg</a>, // |
eb36b4eb | 1333 | |
05732aa0 | 1334 | $entry_tags = null; |
eb36b4eb | 1335 | |
40e1a95b | 1336 | preg_match_all("/<a.*?rel=['\"]tag['\"].*?>([^<]+)<\/a>/i", |
ee2c3050 AD |
1337 | $entry_content_unescaped, $entry_tags); |
1338 | ||
fefef828 AD |
1339 | /* print "<p><br/>$entry_title : $entry_content_unescaped<br>"; |
1340 | print_r($entry_tags); | |
1341 | print "<br/></p>"; */ | |
eb36b4eb AD |
1342 | |
1343 | $entry_tags = $entry_tags[1]; | |
1344 | ||
073ca0e6 AD |
1345 | # check for manual tags |
1346 | ||
f8382011 AD |
1347 | $tag_filter = find_article_filter($article_filters, "tag"); |
1348 | ||
1349 | if ($tag_filter) { | |
073ca0e6 | 1350 | |
f8382011 | 1351 | $manual_tags = trim_array(split(",", $tag_filter[1])); |
073ca0e6 | 1352 | |
f8382011 | 1353 | foreach ($manual_tags as $tag) { |
be832a1a AD |
1354 | if (tag_is_valid($tag)) { |
1355 | array_push($entry_tags, $tag); | |
1356 | } | |
1357 | } | |
1358 | } | |
1359 | ||
11c9ea1f AD |
1360 | $boring_tags = trim_array(split(",", mb_strtolower(get_pref($link, |
1361 | 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); | |
8fc70781 | 1362 | |
fefef828 AD |
1363 | if ($additional_tags && is_array($additional_tags)) { |
1364 | foreach ($additional_tags as $tag) { | |
156a785d AD |
1365 | if (tag_is_valid($tag) && |
1366 | array_search($tag, $boring_tags) === FALSE) { | |
073ca0e6 AD |
1367 | array_push($entry_tags, $tag); |
1368 | } | |
1369 | } | |
fefef828 AD |
1370 | } |
1371 | ||
fcc95e24 | 1372 | // print "<p>TAGS: "; print_r($entry_tags); print "</p>"; |
073ca0e6 | 1373 | |
9fdf7824 AD |
1374 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
1375 | print_r($entry_tags); | |
1376 | } | |
1377 | ||
eb36b4eb AD |
1378 | if (count($entry_tags) > 0) { |
1379 | ||
44e241cb AD |
1380 | db_query($link, "BEGIN"); |
1381 | ||
fe99ab12 | 1382 | foreach ($entry_tags as $tag) { |
fefef828 | 1383 | |
14b6c54b | 1384 | $tag = sanitize_tag($tag); |
fefef828 | 1385 | $tag = db_escape_string($tag); |
31483fc1 | 1386 | |
ef063748 AD |
1387 | if (!tag_is_valid($tag)) continue; |
1388 | ||
fe99ab12 AD |
1389 | $result = db_query($link, "SELECT id FROM ttrss_tags |
1390 | WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND | |
1391 | owner_uid = '$owner_uid' LIMIT 1"); | |
1392 | ||
1393 | // print db_fetch_result($result, 0, "id"); | |
1394 | ||
1395 | if ($result && db_num_rows($result) == 0) { | |
1396 | ||
fe99ab12 AD |
1397 | db_query($link, "INSERT INTO ttrss_tags |
1398 | (owner_uid,tag_name,post_int_id) | |
1399 | VALUES ('$owner_uid','$tag', '$entry_int_id')"); | |
1400 | } | |
1401 | } | |
ce53e200 | 1402 | |
44e241cb | 1403 | db_query($link, "COMMIT"); |
05732aa0 | 1404 | } |
9fdf7824 AD |
1405 | |
1406 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1407 | _debug("update_rss_feed: article processed"); | |
1408 | } | |
4c193675 | 1409 | } |
40d13c28 | 1410 | |
2627f2d0 AD |
1411 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
1412 | _debug("update_rss_feed: updating counters cache..."); | |
1413 | } | |
1414 | ||
1415 | ccache_update($link, $feed, $owner_uid); | |
1416 | ||
ab3d0b99 AD |
1417 | db_query($link, "UPDATE ttrss_feeds |
1418 | SET last_updated = NOW(), last_error = '' WHERE id = '$feed'"); | |
eb36b4eb | 1419 | |
44e241cb | 1420 | // db_query($link, "COMMIT"); |
dd8c76a9 | 1421 | |
ab3d0b99 | 1422 | } else { |
ca872b9d | 1423 | |
16211ddb | 1424 | if ($use_simplepie) { |
ca872b9d | 1425 | $error_msg = mb_substr($rss->error(), 0, 250); |
9fdf7824 | 1426 | } else { |
ca872b9d | 1427 | $error_msg = mb_substr(magpie_error(), 0, 250); |
9fdf7824 | 1428 | } |
ca872b9d AD |
1429 | |
1430 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1431 | _debug("update_rss_feed: error fetching feed: $error_msg"); | |
1432 | } | |
1433 | ||
1434 | $error_msg = db_escape_string($error_msg); | |
1435 | ||
ab3d0b99 | 1436 | db_query($link, |
aa5f9f5f AD |
1437 | "UPDATE ttrss_feeds SET last_error = '$error_msg', |
1438 | last_updated = NOW() WHERE id = '$feed'"); | |
40d13c28 AD |
1439 | } |
1440 | ||
16211ddb | 1441 | if ($use_simplepie) { |
ac6ebdb3 AD |
1442 | unset($rss); |
1443 | } | |
1444 | ||
9fdf7824 | 1445 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb | 1446 | _debug("update_rss_feed: done"); |
219bd8fc AD |
1447 | } |
1448 | ||
40d13c28 AD |
1449 | } |
1450 | ||
f175937c | 1451 | function print_select($id, $default, $values, $attributes = "") { |
79f3553b | 1452 | print "<select name=\"$id\" id=\"$id\" $attributes>"; |
a0d53889 AD |
1453 | foreach ($values as $v) { |
1454 | if ($v == $default) | |
1455 | $sel = " selected"; | |
1456 | else | |
1457 | $sel = ""; | |
1458 | ||
1459 | print "<option$sel>$v</option>"; | |
1460 | } | |
1461 | print "</select>"; | |
1462 | } | |
40d13c28 | 1463 | |
79f3553b AD |
1464 | function print_select_hash($id, $default, $values, $attributes = "") { |
1465 | print "<select name=\"$id\" id='$id' $attributes>"; | |
673d54ca AD |
1466 | foreach (array_keys($values) as $v) { |
1467 | if ($v == $default) | |
74d5c8fa | 1468 | $sel = 'selected="selected"'; |
673d54ca AD |
1469 | else |
1470 | $sel = ""; | |
1471 | ||
1472 | print "<option $sel value=\"$v\">".$values[$v]."</option>"; | |
1473 | } | |
1474 | ||
1475 | print "</select>"; | |
1476 | } | |
1477 | ||
44d0e774 | 1478 | function get_article_filters($filters, $title, $content, $link, $timestamp) { |
240054f1 | 1479 | $matches = array(); |
c2d9322b | 1480 | |
240054f1 AD |
1481 | if ($filters["title"]) { |
1482 | foreach ($filters["title"] as $filter) { | |
c2d9322b AD |
1483 | $reg_exp = $filter["reg_exp"]; |
1484 | $inverse = $filter["inverse"]; | |
1485 | if ((!$inverse && preg_match("/$reg_exp/i", $title)) || | |
1486 | ($inverse && !preg_match("/$reg_exp/i", $title))) { | |
1487 | ||
240054f1 AD |
1488 | array_push($matches, array($filter["action"], $filter["action_param"])); |
1489 | } | |
1490 | } | |
1491 | } | |
1492 | ||
1493 | if ($filters["content"]) { | |
1494 | foreach ($filters["content"] as $filter) { | |
c2d9322b AD |
1495 | $reg_exp = $filter["reg_exp"]; |
1496 | $inverse = $filter["inverse"]; | |
1497 | ||
1498 | if ((!$inverse && preg_match("/$reg_exp/i", $content)) || | |
1499 | ($inverse && !preg_match("/$reg_exp/i", $content))) { | |
1500 | ||
240054f1 AD |
1501 | array_push($matches, array($filter["action"], $filter["action_param"])); |
1502 | } | |
1503 | } | |
1504 | } | |
1505 | ||
1506 | if ($filters["both"]) { | |
1507 | foreach ($filters["both"] as $filter) { | |
1508 | $reg_exp = $filter["reg_exp"]; | |
c2d9322b AD |
1509 | $inverse = $filter["inverse"]; |
1510 | ||
1511 | if ($inverse) { | |
1512 | if (!preg_match("/$reg_exp/i", $title) || !preg_match("/$reg_exp/i", $content)) { | |
1513 | array_push($matches, array($filter["action"], $filter["action_param"])); | |
1514 | } | |
1515 | } else { | |
1516 | if (preg_match("/$reg_exp/i", $title) || preg_match("/$reg_exp/i", $content)) { | |
1517 | array_push($matches, array($filter["action"], $filter["action_param"])); | |
1518 | } | |
240054f1 AD |
1519 | } |
1520 | } | |
1521 | } | |
1522 | ||
1523 | if ($filters["link"]) { | |
1524 | $reg_exp = $filter["reg_exp"]; | |
1525 | foreach ($filters["link"] as $filter) { | |
1526 | $reg_exp = $filter["reg_exp"]; | |
c2d9322b AD |
1527 | $inverse = $filter["inverse"]; |
1528 | ||
1529 | if ((!$inverse && preg_match("/$reg_exp/i", $link)) || | |
1530 | ($inverse && !preg_match("/$reg_exp/i", $link))) { | |
1531 | ||
240054f1 AD |
1532 | array_push($matches, array($filter["action"], $filter["action_param"])); |
1533 | } | |
1534 | } | |
1535 | } | |
1536 | ||
44d0e774 AD |
1537 | if ($filters["date"]) { |
1538 | $reg_exp = $filter["reg_exp"]; | |
1539 | foreach ($filters["date"] as $filter) { | |
1540 | $date_modifier = $filter["filter_param"]; | |
1541 | $inverse = $filter["inverse"]; | |
1542 | $check_timestamp = strtotime($filter["reg_exp"]); | |
1543 | ||
1544 | # no-op when timestamp doesn't parse to prevent misfires | |
1545 | ||
1546 | if ($check_timestamp) { | |
1547 | $match_ok = false; | |
1548 | ||
1549 | if ($date_modifier == "before" && $timestamp < $check_timestamp || | |
1550 | $date_modifier == "after" && $timestamp > $check_timestamp) { | |
1551 | $match_ok = true; | |
1552 | } | |
1553 | ||
1554 | if ($inverse) $match_ok = !$match_ok; | |
1555 | ||
1556 | if ($match_ok) { | |
1557 | array_push($matches, array($filter["action"], $filter["action_param"])); | |
1558 | } | |
1559 | } | |
1560 | } | |
1561 | } | |
1562 | ||
240054f1 AD |
1563 | return $matches; |
1564 | } | |
1565 | ||
f8382011 AD |
1566 | function find_article_filter($filters, $filter_name) { |
1567 | foreach ($filters as $f) { | |
1568 | if ($f[0] == $filter_name) { | |
1569 | return $f; | |
1570 | }; | |
1571 | } | |
1572 | return false; | |
1573 | } | |
1574 | ||
ff6e357a AD |
1575 | function calculate_article_score($filters) { |
1576 | $score = 0; | |
1577 | ||
1578 | foreach ($filters as $f) { | |
1579 | if ($f[0] == "score") { | |
1580 | $score += $f[1]; | |
1581 | }; | |
1582 | } | |
1583 | return $score; | |
1584 | } | |
1585 | ||
1586 | ||
9323147e | 1587 | function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link, |
fb1fb4ab | 1588 | $rtl_content = false, $last_updated = false, $last_error = false) { |
254e0e4b AD |
1589 | |
1590 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
023fe037 | 1591 | $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"$icon_file\">"; |
254e0e4b | 1592 | } else { |
023fe037 | 1593 | $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"images/blank_icon.gif\">"; |
254e0e4b AD |
1594 | } |
1595 | ||
9323147e AD |
1596 | if ($rtl_content) { |
1597 | $rtl_tag = "dir=\"rtl\""; | |
1598 | } else { | |
1599 | $rtl_tag = "dir=\"ltr\""; | |
1600 | } | |
1601 | ||
78d5212c AD |
1602 | $error_notify_msg = ""; |
1603 | ||
fb1fb4ab AD |
1604 | if ($last_error) { |
1605 | $link_title = "Error: $last_error ($last_updated)"; | |
78d5212c | 1606 | $error_notify_msg = "(Error)"; |
ad780e9c | 1607 | } else if ($last_updated) { |
fb1fb4ab AD |
1608 | $link_title = "Updated: $last_updated"; |
1609 | } | |
1610 | ||
7210613a | 1611 | $feed = "<a title=\"$link_title\" id=\"FEEDL-$feed_id\" |
c50e2b30 | 1612 | href=\"javascript:viewfeed('$feed_id', '', false, '', false, 0);\">$feed_title</a>"; |
254e0e4b | 1613 | |
8836613c | 1614 | print "<li id=\"FEEDR-$feed_id\" class=\"$class\">"; |
b619ff15 | 1615 | if (get_pref($link, 'ENABLE_FEED_ICONS')) { |
254e0e4b AD |
1616 | print "$feed_icon"; |
1617 | } | |
1618 | ||
9323147e | 1619 | print "<span $rtl_tag id=\"FEEDN-$feed_id\">$feed</span>"; |
254e0e4b AD |
1620 | |
1621 | if ($unread != 0) { | |
d7e83df7 | 1622 | $fctr_class = "class=\"feedCtrHasUnread\""; |
254e0e4b | 1623 | } else { |
d7e83df7 | 1624 | $fctr_class = "class=\"feedCtrNoUnread\""; |
254e0e4b AD |
1625 | } |
1626 | ||
9323147e | 1627 | print " <span $rtl_tag $fctr_class id=\"FEEDCTR-$feed_id\"> |
254e0e4b | 1628 | (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>"; |
78d5212c AD |
1629 | |
1630 | if (get_pref($link, "EXTENDED_FEEDLIST")) { | |
bdb7369b | 1631 | $total = getFeedArticles($link, $feed_id); |
78d5212c | 1632 | print "<div class=\"feedExtInfo\"> |
bdb7369b | 1633 | <span id=\"FLUPD-$feed_id\">$last_updated ($total total) $error_notify_msg</span></div>"; |
78d5212c AD |
1634 | } |
1635 | ||
254e0e4b AD |
1636 | print "</li>"; |
1637 | ||
1638 | } | |
1639 | ||
406d9489 AD |
1640 | function getmicrotime() { |
1641 | list($usec, $sec) = explode(" ",microtime()); | |
1642 | return ((float)$usec + (float)$sec); | |
1643 | } | |
1644 | ||
f541eb78 | 1645 | function print_radio($id, $default, $true_is, $values, $attributes = "") { |
77e96719 AD |
1646 | foreach ($values as $v) { |
1647 | ||
1648 | if ($v == $default) | |
5da169d9 | 1649 | $sel = "checked"; |
77e96719 | 1650 | else |
5da169d9 AD |
1651 | $sel = ""; |
1652 | ||
f541eb78 | 1653 | if ($v == $true_is) { |
5da169d9 AD |
1654 | $sel .= " value=\"1\""; |
1655 | } else { | |
1656 | $sel .= " value=\"0\""; | |
1657 | } | |
77e96719 | 1658 | |
69654950 AD |
1659 | print "<input class=\"noborder\" |
1660 | type=\"radio\" $sel $attributes name=\"$id\"> $v "; | |
77e96719 AD |
1661 | |
1662 | } | |
1663 | } | |
1664 | ||
ff485f1d AD |
1665 | function initialize_user_prefs($link, $uid) { |
1666 | ||
1667 | $uid = db_escape_string($uid); | |
1668 | ||
1669 | db_query($link, "BEGIN"); | |
1670 | ||
1671 | $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs"); | |
1672 | ||
1673 | $u_result = db_query($link, "SELECT pref_name | |
1674 | FROM ttrss_user_prefs WHERE owner_uid = '$uid'"); | |
1675 | ||
1676 | $active_prefs = array(); | |
1677 | ||
1678 | while ($line = db_fetch_assoc($u_result)) { | |
1679 | array_push($active_prefs, $line["pref_name"]); | |
1680 | } | |
1681 | ||
1682 | while ($line = db_fetch_assoc($result)) { | |
1683 | if (array_search($line["pref_name"], $active_prefs) === FALSE) { | |
1684 | // print "adding " . $line["pref_name"] . "<br>"; | |
1685 | ||
1686 | db_query($link, "INSERT INTO ttrss_user_prefs | |
1687 | (owner_uid,pref_name,value) VALUES | |
1688 | ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')"); | |
1689 | ||
1690 | } | |
1691 | } | |
1692 | ||
1693 | db_query($link, "COMMIT"); | |
1694 | ||
1695 | } | |
956c7629 AD |
1696 | |
1697 | function lookup_user_id($link, $user) { | |
1698 | ||
1699 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
1700 | login = '$login'"); | |
1701 | ||
1702 | if (db_num_rows($result) == 1) { | |
1703 | return db_fetch_result($result, 0, "id"); | |
1704 | } else { | |
1705 | return false; | |
1706 | } | |
1707 | } | |
1708 | ||
18664970 AD |
1709 | function http_authenticate_user($link) { |
1710 | ||
4bc64807 AD |
1711 | error_log("http_authenticate_user: ".$_SERVER["PHP_AUTH_USER"]."\n", 3, '/tmp/tt-rss.log'); |
1712 | ||
18664970 AD |
1713 | if (!$_SERVER["PHP_AUTH_USER"]) { |
1714 | ||
1715 | header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"'); | |
1716 | header('HTTP/1.0 401 Unauthorized'); | |
1717 | exit; | |
1718 | ||
1719 | } else { | |
1720 | $auth_result = authenticate_user($link, | |
1721 | $_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]); | |
1722 | ||
1723 | if (!$auth_result) { | |
1724 | header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"'); | |
1725 | header('HTTP/1.0 401 Unauthorized'); | |
1726 | exit; | |
1727 | } | |
1728 | } | |
1729 | ||
1730 | return true; | |
1731 | } | |
1732 | ||
461766f3 | 1733 | function authenticate_user($link, $login, $password, $force_auth = false) { |
c8437f35 | 1734 | |
131b01b3 | 1735 | if (!SINGLE_USER_MODE) { |
c8437f35 | 1736 | |
1a9f4d3c AD |
1737 | $pwd_hash1 = encrypt_password($password); |
1738 | $pwd_hash2 = encrypt_password($password, $login); | |
461766f3 | 1739 | |
66917e70 | 1740 | if (defined('ALLOW_REMOTE_USER_AUTH') && ALLOW_REMOTE_USER_AUTH |
73f5f114 | 1741 | && $_SERVER["REMOTE_USER"] && $login != "admin") { |
66917e70 AD |
1742 | |
1743 | $login = db_escape_string($_SERVER["REMOTE_USER"]); | |
1744 | ||
73f5f114 | 1745 | $query = "SELECT id,login,access_level,pwd_hash |
461766f3 | 1746 | FROM ttrss_users WHERE |
66917e70 AD |
1747 | login = '$login'"; |
1748 | ||
461766f3 | 1749 | } else { |
1a9f4d3c | 1750 | $query = "SELECT id,login,access_level,pwd_hash |
461766f3 | 1751 | FROM ttrss_users WHERE |
1a9f4d3c AD |
1752 | login = '$login' AND (pwd_hash = '$pwd_hash1' OR |
1753 | pwd_hash = '$pwd_hash2')"; | |
461766f3 AD |
1754 | } |
1755 | ||
1756 | $result = db_query($link, $query); | |
131b01b3 AD |
1757 | |
1758 | if (db_num_rows($result) == 1) { | |
1759 | $_SESSION["uid"] = db_fetch_result($result, 0, "id"); | |
1760 | $_SESSION["name"] = db_fetch_result($result, 0, "login"); | |
1761 | $_SESSION["access_level"] = db_fetch_result($result, 0, "access_level"); | |
1762 | ||
1763 | db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . | |
1764 | $_SESSION["uid"]); | |
1765 | ||
1766 | $user_theme = get_user_theme_path($link); | |
1767 | ||
1768 | $_SESSION["theme"] = $user_theme; | |
1769 | $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; | |
1a9f4d3c | 1770 | $_SESSION["pwd_hash"] = db_fetch_result($result, 0, "pwd_hash"); |
131b01b3 AD |
1771 | |
1772 | initialize_user_prefs($link, $_SESSION["uid"]); | |
1773 | ||
1774 | return true; | |
1775 | } | |
1776 | ||
1777 | return false; | |
503eb349 | 1778 | |
131b01b3 | 1779 | } else { |
503eb349 | 1780 | |
131b01b3 AD |
1781 | $_SESSION["uid"] = 1; |
1782 | $_SESSION["name"] = "admin"; | |
f557cd78 | 1783 | |
0bbba72d AD |
1784 | $user_theme = get_user_theme_path($link); |
1785 | ||
1786 | $_SESSION["theme"] = $user_theme; | |
1787 | $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; | |
1788 | ||
1789 | initialize_user_prefs($link, $_SESSION["uid"]); | |
1790 | ||
c8437f35 AD |
1791 | return true; |
1792 | } | |
c8437f35 AD |
1793 | } |
1794 | ||
e6cb77a0 AD |
1795 | function make_password($length = 8) { |
1796 | ||
1797 | $password = ""; | |
798f722b AD |
1798 | $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ"; |
1799 | ||
1800 | $i = 0; | |
e6cb77a0 AD |
1801 | |
1802 | while ($i < $length) { | |
1803 | $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); | |
1804 | ||
1805 | if (!strstr($password, $char)) { | |
1806 | $password .= $char; | |
1807 | $i++; | |
1808 | } | |
1809 | } | |
1810 | return $password; | |
1811 | } | |
1812 | ||
1813 | // this is called after user is created to initialize default feeds, labels | |
1814 | // or whatever else | |
1815 | ||
1816 | // user preferences are checked on every login, not here | |
1817 | ||
1818 | function initialize_user($link, $uid) { | |
1819 | ||
1820 | db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description) | |
1821 | values ('$uid','unread = true', 'Unread articles')"); | |
1822 | ||
1823 | db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description) | |
1824 | values ('$uid','last_read is null and unread = false', 'Updated articles')"); | |
e603a0fa | 1825 | |
e6cb77a0 | 1826 | db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url) |
74bff337 | 1827 | values ('$uid', 'Tiny Tiny RSS: New Releases', |
b6d486a3 | 1828 | 'http://tt-rss.org/releases.rss')"); |
3b0feb9b | 1829 | |
cd2cd415 AD |
1830 | db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url) |
1831 | values ('$uid', 'Tiny Tiny RSS: Forum', | |
b6d486a3 | 1832 | 'http://tt-rss.org/forum/rss.php')"); |
3b0feb9b | 1833 | } |
e6cb77a0 | 1834 | |
b8aa49bc | 1835 | function logout_user() { |
5ccc1cf5 AD |
1836 | session_destroy(); |
1837 | if (isset($_COOKIE[session_name()])) { | |
1838 | setcookie(session_name(), '', time()-42000, '/'); | |
1839 | } | |
b8aa49bc AD |
1840 | } |
1841 | ||
75836f33 | 1842 | function get_script_urlpath() { |
87a79fa4 | 1843 | return preg_replace('/\/[^\/]*$/', "", $_SERVER["REQUEST_URI"]); |
75836f33 AD |
1844 | } |
1845 | ||
916f788a | 1846 | function validate_session($link) { |
741edab2 AD |
1847 | if (SINGLE_USER_MODE) { |
1848 | return true; | |
1849 | } | |
1850 | ||
a2e9b457 | 1851 | if (SESSION_CHECK_ADDRESS && $_SESSION["uid"]) { |
916f788a AD |
1852 | if ($_SESSION["ip_address"]) { |
1853 | if ($_SESSION["ip_address"] != $_SERVER["REMOTE_ADDR"]) { | |
7f0acba7 | 1854 | $_SESSION["login_error_msg"] = "Session failed to validate (incorrect IP)"; |
916f788a AD |
1855 | return false; |
1856 | } | |
1857 | } | |
1858 | } | |
d620cfe7 | 1859 | |
e6684130 AD |
1860 | if ($_SESSION["uid"]) { |
1861 | ||
1862 | $result = db_query($link, | |
1863 | "SELECT pwd_hash FROM ttrss_users WHERE id = '".$_SESSION["uid"]."'"); | |
1864 | ||
1865 | $pwd_hash = db_fetch_result($result, 0, "pwd_hash"); | |
1866 | ||
1867 | if ($pwd_hash != $_SESSION["pwd_hash"]) { | |
1868 | return false; | |
1869 | } | |
1870 | } | |
1871 | ||
a885f0ec | 1872 | /* if ($_SESSION["cookie_lifetime"] && $_SESSION["uid"]) { |
d620cfe7 | 1873 | |
8e849206 | 1874 | //print_r($_SESSION); |
d620cfe7 AD |
1875 | |
1876 | if (time() > $_SESSION["cookie_lifetime"]) { | |
1877 | return false; | |
1878 | } | |
a885f0ec AD |
1879 | } */ |
1880 | ||
916f788a AD |
1881 | return true; |
1882 | } | |
1883 | ||
793185a9 | 1884 | function login_sequence($link, $mobile = false) { |
b8aa49bc | 1885 | if (!SINGLE_USER_MODE) { |
75836f33 | 1886 | |
461766f3 AD |
1887 | if (defined('_DEBUG_USER_SWITCH') && $_SESSION["uid"]) { |
1888 | $swu = db_escape_string($_REQUEST["swu"]); | |
1889 | if ($swu) { | |
1890 | $_SESSION["prefs_cache"] = false; | |
1891 | return authenticate_user($link, $swu, null, true); | |
1892 | } | |
1893 | } | |
1894 | ||
7f0acba7 | 1895 | $login_action = $_POST["login_action"]; |
a885f0ec | 1896 | |
01a87dff | 1897 | # try to authenticate user if called from login form |
7f0acba7 | 1898 | if ($login_action == "do_login") { |
01a87dff AD |
1899 | $login = $_POST["login"]; |
1900 | $password = $_POST["password"]; | |
d620cfe7 | 1901 | $remember_me = $_POST["remember_me"]; |
f557cd78 | 1902 | |
01a87dff AD |
1903 | if (authenticate_user($link, $login, $password)) { |
1904 | $_POST["password"] = ""; | |
d620cfe7 | 1905 | |
f8c612d4 | 1906 | $_SESSION["language"] = $_POST["language"]; |
a598370d | 1907 | $_SESSION["bw_limit"] = !!$_POST["bw_limit"]; |
f8c612d4 | 1908 | |
d620cfe7 AD |
1909 | header("Location: " . $_SERVER["REQUEST_URI"]); |
1910 | exit; | |
1911 | ||
01a87dff | 1912 | return; |
7f0acba7 AD |
1913 | } else { |
1914 | $_SESSION["login_error_msg"] = "Incorrect username or password"; | |
01a87dff AD |
1915 | } |
1916 | } | |
1917 | ||
1df0f48b AD |
1918 | // print session_id(); |
1919 | // print_r($_SESSION); | |
7f0acba7 AD |
1920 | |
1921 | if (!$_SESSION["uid"] || !validate_session($link)) { | |
793185a9 | 1922 | render_login_form($link, $mobile); |
01a87dff | 1923 | exit; |
d3687e7a AD |
1924 | } else { |
1925 | /* bump login timestamp */ | |
1926 | db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . | |
1927 | $_SESSION["uid"]); | |
019bd5a9 | 1928 | |
d54780bc | 1929 | if ($_SESSION["language"] && SESSION_COOKIE_LIFETIME > 0) { |
019bd5a9 AD |
1930 | setcookie("ttrss_lang", $_SESSION["language"], |
1931 | time() + SESSION_COOKIE_LIFETIME); | |
1932 | } | |
4fdb0476 AD |
1933 | |
1934 | /* bump counters stamp since we're getting reloaded anyway */ | |
1935 | ||
1936 | $_SESSION["get_all_counters_stamp"] = time(); | |
b8aa49bc | 1937 | } |
d620cfe7 | 1938 | |
b8aa49bc | 1939 | } else { |
0bbba72d | 1940 | return authenticate_user($link, "admin", null); |
b8aa49bc AD |
1941 | } |
1942 | } | |
3547842a AD |
1943 | |
1944 | function truncate_string($str, $max_len) { | |
12db369c | 1945 | if (mb_strlen($str, "utf-8") > $max_len - 3) { |
66a251f9 | 1946 | return mb_substr($str, 0, $max_len, "utf-8") . "…"; |
3547842a AD |
1947 | } else { |
1948 | return $str; | |
1949 | } | |
1950 | } | |
54a60e1a AD |
1951 | |
1952 | function get_user_theme_path($link) { | |
798f722b AD |
1953 | $result = db_query($link, "SELECT theme_path |
1954 | FROM | |
1955 | ttrss_themes,ttrss_users | |
1956 | WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]); | |
54a60e1a AD |
1957 | if (db_num_rows($result) != 0) { |
1958 | return db_fetch_result($result, 0, "theme_path"); | |
1959 | } else { | |
1960 | return null; | |
1961 | } | |
1962 | } | |
be773442 AD |
1963 | |
1964 | function smart_date_time($timestamp) { | |
1965 | if (date("Y.m.d", $timestamp) == date("Y.m.d")) { | |
1966 | return date("G:i", $timestamp); | |
f26450f1 | 1967 | } else if (date("Y", $timestamp) == date("Y")) { |
be773442 AD |
1968 | return date("M d, G:i", $timestamp); |
1969 | } else { | |
7d7e0509 | 1970 | return date("Y/m/d, G:i", $timestamp); |
be773442 AD |
1971 | } |
1972 | } | |
1973 | ||
1974 | function smart_date($timestamp) { | |
1975 | if (date("Y.m.d", $timestamp) == date("Y.m.d")) { | |
1976 | return "Today"; | |
f26450f1 | 1977 | } else if (date("Y", $timestamp) == date("Y")) { |
be773442 AD |
1978 | return date("D m", $timestamp); |
1979 | } else { | |
b02111c2 | 1980 | return date("Y/m/d", $timestamp); |
be773442 AD |
1981 | } |
1982 | } | |
a654a595 AD |
1983 | |
1984 | function sql_bool_to_string($s) { | |
1985 | if ($s == "t" || $s == "1") { | |
1986 | return "true"; | |
1987 | } else { | |
1988 | return "false"; | |
1989 | } | |
1990 | } | |
e3c99f3b AD |
1991 | |
1992 | function sql_bool_to_bool($s) { | |
1993 | if ($s == "t" || $s == "1") { | |
1994 | return true; | |
1995 | } else { | |
1996 | return false; | |
1997 | } | |
1998 | } | |
0ea4fb50 | 1999 | |
e3c99f3b | 2000 | |
0ea4fb50 AD |
2001 | function toggleEvenOdd($a) { |
2002 | if ($a == "even") | |
2003 | return "odd"; | |
2004 | else | |
2005 | return "even"; | |
2006 | } | |
6043fb7e AD |
2007 | |
2008 | function sanity_check($link) { | |
9cbca41f | 2009 | |
aec3ce39 AD |
2010 | error_reporting(0); |
2011 | ||
6043fb7e AD |
2012 | $error_code = 0; |
2013 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
2014 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
2015 | ||
2016 | if ($schema_version != SCHEMA_VERSION) { | |
2017 | $error_code = 5; | |
2018 | } | |
2019 | ||
aec3ce39 AD |
2020 | if (DB_TYPE == "mysql") { |
2021 | $result = db_query($link, "SELECT true", false); | |
2022 | if (db_num_rows($result) != 1) { | |
2023 | $error_code = 10; | |
2024 | } | |
2025 | } | |
2026 | ||
f29ba148 AD |
2027 | if (db_escape_string("testTEST") != "testTEST") { |
2028 | $error_code = 12; | |
2029 | } | |
2030 | ||
aec3ce39 AD |
2031 | error_reporting (DEFAULT_ERROR_LEVEL); |
2032 | ||
6043fb7e | 2033 | if ($error_code != 0) { |
aec3ce39 | 2034 | print_error_xml($error_code); |
6043fb7e AD |
2035 | return false; |
2036 | } else { | |
2037 | return true; | |
4220d6b0 | 2038 | } |
6043fb7e AD |
2039 | } |
2040 | ||
27981ca3 | 2041 | function file_is_locked($filename) { |
31a6d42d AD |
2042 | if (function_exists('flock')) { |
2043 | error_reporting(0); | |
cfa43e02 | 2044 | $fp = fopen(LOCK_DIRECTORY . "/$filename", "r"); |
31a6d42d AD |
2045 | error_reporting(DEFAULT_ERROR_LEVEL); |
2046 | if ($fp) { | |
2047 | if (flock($fp, LOCK_EX | LOCK_NB)) { | |
2048 | flock($fp, LOCK_UN); | |
2049 | fclose($fp); | |
2050 | return false; | |
2051 | } | |
27981ca3 | 2052 | fclose($fp); |
31a6d42d | 2053 | return true; |
e89aed7b AD |
2054 | } else { |
2055 | return false; | |
27981ca3 | 2056 | } |
27981ca3 | 2057 | } |
c1fb4a5e | 2058 | return true; // consider the file always locked and skip the test |
27981ca3 AD |
2059 | } |
2060 | ||
fcb4c0c9 | 2061 | function make_lockfile($filename) { |
cfa43e02 | 2062 | $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); |
fcb4c0c9 AD |
2063 | |
2064 | if (flock($fp, LOCK_EX | LOCK_NB)) { | |
2065 | return $fp; | |
2066 | } else { | |
2067 | return false; | |
2068 | } | |
2069 | } | |
2070 | ||
bf7fcde8 | 2071 | function make_stampfile($filename) { |
cfa43e02 | 2072 | $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); |
bf7fcde8 | 2073 | |
8e00ae9b | 2074 | if (flock($fp, LOCK_EX | LOCK_NB)) { |
bf7fcde8 | 2075 | fwrite($fp, time() . "\n"); |
8e00ae9b | 2076 | flock($fp, LOCK_UN); |
bf7fcde8 AD |
2077 | fclose($fp); |
2078 | return true; | |
2079 | } else { | |
2080 | return false; | |
2081 | } | |
2082 | } | |
2083 | ||
8e00ae9b AD |
2084 | function read_stampfile($filename) { |
2085 | ||
2086 | error_reporting(0); | |
cfa43e02 | 2087 | $fp = fopen(LOCK_DIRECTORY . "/$filename", "r"); |
8e00ae9b AD |
2088 | error_reporting (DEFAULT_ERROR_LEVEL); |
2089 | ||
e89aed7b AD |
2090 | if ($fp) { |
2091 | if (flock($fp, LOCK_EX)) { | |
2092 | $stamp = fgets($fp); | |
2093 | flock($fp, LOCK_UN); | |
2094 | fclose($fp); | |
2095 | return $stamp; | |
2096 | } else { | |
2097 | return false; | |
2098 | } | |
8e00ae9b AD |
2099 | } else { |
2100 | return false; | |
2101 | } | |
2102 | } | |
bf7fcde8 | 2103 | |
894ebcf5 AD |
2104 | function sql_random_function() { |
2105 | if (DB_TYPE == "mysql") { | |
2106 | return "RAND()"; | |
2107 | } else { | |
2108 | return "RANDOM()"; | |
2109 | } | |
2110 | } | |
2111 | ||
23aa0d16 | 2112 | function catchup_feed($link, $feed, $cat_view) { |
88040f57 AD |
2113 | |
2114 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { | |
23aa0d16 AD |
2115 | |
2116 | if ($cat_view) { | |
2117 | ||
2118 | if ($feed > 0) { | |
2119 | $cat_qpart = "cat_id = '$feed'"; | |
2120 | } else { | |
2121 | $cat_qpart = "cat_id IS NULL"; | |
2122 | } | |
2123 | ||
2124 | $tmp_result = db_query($link, "SELECT id | |
2125 | FROM ttrss_feeds WHERE $cat_qpart AND owner_uid = " . | |
2126 | $_SESSION["uid"]); | |
2127 | ||
2128 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
2129 | ||
2130 | $tmp_feed = $tmp_line["id"]; | |
2131 | ||
2132 | db_query($link, "UPDATE ttrss_user_entries | |
2133 | SET unread = false,last_read = NOW() | |
2134 | WHERE feed_id = '$tmp_feed' AND owner_uid = " . $_SESSION["uid"]); | |
2135 | } | |
2136 | ||
2137 | } else if ($feed > 0) { | |
2138 | ||
2139 | $tmp_result = db_query($link, "SELECT id | |
2140 | FROM ttrss_feeds WHERE parent_feed = '$feed' | |
2141 | ORDER BY cat_id,title"); | |
2142 | ||
2143 | $parent_ids = array(); | |
2144 | ||
2145 | if (db_num_rows($tmp_result) > 0) { | |
2146 | while ($p = db_fetch_assoc($tmp_result)) { | |
2147 | array_push($parent_ids, "feed_id = " . $p["id"]); | |
2148 | } | |
2149 | ||
2150 | $children_qpart = implode(" OR ", $parent_ids); | |
2151 | ||
2152 | db_query($link, "UPDATE ttrss_user_entries | |
2153 | SET unread = false,last_read = NOW() | |
2154 | WHERE (feed_id = '$feed' OR $children_qpart) | |
2155 | AND owner_uid = " . $_SESSION["uid"]); | |
2156 | ||
2157 | } else { | |
2158 | db_query($link, "UPDATE ttrss_user_entries | |
2159 | SET unread = false,last_read = NOW() | |
2160 | WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
2161 | } | |
2162 | ||
2163 | } else if ($feed < 0 && $feed > -10) { // special, like starred | |
2164 | ||
2165 | if ($feed == -1) { | |
2166 | db_query($link, "UPDATE ttrss_user_entries | |
2167 | SET unread = false,last_read = NOW() | |
2168 | WHERE marked = true AND owner_uid = ".$_SESSION["uid"]); | |
2169 | } | |
e4f4b46f AD |
2170 | |
2171 | if ($feed == -2) { | |
2172 | db_query($link, "UPDATE ttrss_user_entries | |
2173 | SET unread = false,last_read = NOW() | |
2174 | WHERE published = true AND owner_uid = ".$_SESSION["uid"]); | |
2175 | } | |
2176 | ||
2d24f032 AD |
2177 | if ($feed == -3) { |
2178 | ||
c1d7e6c3 AD |
2179 | $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE"); |
2180 | ||
2d24f032 | 2181 | if (DB_TYPE == "pgsql") { |
7608b38a | 2182 | $match_part = "updated > NOW() - INTERVAL '$intl hour' "; |
2d24f032 | 2183 | } else { |
7608b38a | 2184 | $match_part = "updated > DATE_SUB(NOW(), |
c1d7e6c3 | 2185 | INTERVAL $intl HOUR) "; |
2d24f032 AD |
2186 | } |
2187 | ||
1f3335dc AD |
2188 | $result = db_query($link, "SELECT id FROM ttrss_entries, |
2189 | ttrss_user_entries WHERE $match_part AND | |
2190 | unread = true AND | |
2191 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
2192 | owner_uid = ".$_SESSION["uid"]); | |
2193 | ||
2194 | $affected_ids = array(); | |
2195 | ||
2196 | while ($line = db_fetch_assoc($result)) { | |
2197 | array_push($affected_ids, $line["id"]); | |
2198 | } | |
2199 | ||
2200 | catchupArticlesById($link, $affected_ids, 0); | |
2d24f032 AD |
2201 | } |
2202 | ||
23aa0d16 AD |
2203 | } else if ($feed < -10) { // label |
2204 | ||
2205 | // TODO make this more efficient | |
2206 | ||
2207 | $label_id = -$feed - 11; | |
2208 | ||
2209 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
2210 | WHERE id = '$label_id'"); | |
2211 | ||
2212 | if ($tmp_result) { | |
2213 | $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp"); | |
2214 | ||
2215 | db_query($link, "BEGIN"); | |
2216 | ||
2217 | $tmp2_result = db_query($link, | |
2218 | "SELECT | |
2219 | int_id | |
2220 | FROM | |
88040f57 | 2221 | ttrss_user_entries,ttrss_entries,ttrss_feeds |
23aa0d16 | 2222 | WHERE |
88040f57 AD |
2223 | ref_id = ttrss_entries.id AND |
2224 | ttrss_user_entries.feed_id = ttrss_feeds.id AND | |
23aa0d16 | 2225 | $sql_exp AND |
88040f57 | 2226 | ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); |
23aa0d16 AD |
2227 | |
2228 | while ($tmp_line = db_fetch_assoc($tmp2_result)) { | |
2229 | db_query($link, "UPDATE | |
2230 | ttrss_user_entries | |
2231 | SET | |
2232 | unread = false, last_read = NOW() | |
2233 | WHERE | |
2234 | int_id = " . $tmp_line["int_id"]); | |
2235 | } | |
2236 | ||
2237 | db_query($link, "COMMIT"); | |
2238 | ||
2239 | /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries | |
2240 | SET unread = false,last_read = NOW() | |
2241 | WHERE $sql_exp | |
2242 | AND ref_id = id | |
2243 | AND owner_uid = ".$_SESSION["uid"]); */ | |
2244 | } | |
2245 | } | |
ad0056a8 AD |
2246 | |
2247 | ccache_update($link, $feed, $_SESSION["uid"], $cat_view); | |
2248 | ||
23aa0d16 AD |
2249 | } else { // tag |
2250 | db_query($link, "BEGIN"); | |
2251 | ||
2252 | $tag_name = db_escape_string($feed); | |
2253 | ||
2254 | $result = db_query($link, "SELECT post_int_id FROM ttrss_tags | |
2255 | WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]); | |
2256 | ||
2257 | while ($line = db_fetch_assoc($result)) { | |
2258 | db_query($link, "UPDATE ttrss_user_entries SET | |
2259 | unread = false, last_read = NOW() | |
2260 | WHERE int_id = " . $line["post_int_id"]); | |
2261 | } | |
2262 | db_query($link, "COMMIT"); | |
2263 | } | |
2264 | } | |
2265 | ||
35bf080c | 2266 | function update_generic_feed($link, $feed, $cat_view, $force_update = false) { |
23aa0d16 AD |
2267 | if ($cat_view) { |
2268 | ||
2269 | if ($feed > 0) { | |
2270 | $cat_qpart = "cat_id = '$feed'"; | |
2271 | } else { | |
2272 | $cat_qpart = "cat_id IS NULL"; | |
2273 | } | |
2274 | ||
571dad82 | 2275 | $tmp_result = db_query($link, "SELECT id,feed_url FROM ttrss_feeds |
23aa0d16 AD |
2276 | WHERE $cat_qpart AND owner_uid = " . $_SESSION["uid"]); |
2277 | ||
2278 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
2279 | $feed_url = $tmp_line["feed_url"]; | |
571dad82 | 2280 | $feed_id = $tmp_line["id"]; |
35bf080c | 2281 | update_rss_feed($link, $feed_url, $feed_id, $force_update); |
23aa0d16 AD |
2282 | } |
2283 | ||
2284 | } else { | |
2285 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
2286 | WHERE id = '$feed'"); | |
2287 | $feed_url = db_fetch_result($tmp_result, 0, "feed_url"); | |
35bf080c | 2288 | update_rss_feed($link, $feed_url, $feed, $force_update); |
23aa0d16 AD |
2289 | } |
2290 | } | |
a9cb1f83 | 2291 | |
4ffa126e | 2292 | function getAllCounters($link, $omode = "flc", $active_feed = false) { |
cf4d339c | 2293 | |
d9e4bba0 AD |
2294 | /* getting all counters is a resource intensive operation, so we |
2295 | * rate limit it a little bit */ | |
cf4d339c | 2296 | |
d234a2e3 AD |
2297 | |
2298 | ||
bd090ab4 AD |
2299 | // if (get_pref($link, "SYNC_COUNTERS") || |
2300 | // time() - $_SESSION["get_all_counters_stamp"] > 5) { | |
cf4d339c | 2301 | |
d9e4bba0 AD |
2302 | if (!$omode) $omode = "flc"; |
2303 | ||
2304 | getGlobalCounters($link); | |
2305 | ||
2306 | if (strchr($omode, "l")) getLabelCounters($link); | |
2307 | if (strchr($omode, "f")) getFeedCounters($link, SMART_RPC_COUNTERS, $active_feed); | |
2308 | if (strchr($omode, "t")) getTagCounters($link); | |
2309 | if (strchr($omode, "c")) { | |
2310 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2311 | getCategoryCounters($link); | |
2312 | } | |
cf4d339c | 2313 | } |
d9e4bba0 AD |
2314 | |
2315 | $_SESSION["get_all_counters_stamp"] = time(); | |
bd090ab4 | 2316 | // } |
d9e4bba0 | 2317 | |
a9cb1f83 AD |
2318 | } |
2319 | ||
2320 | function getCategoryCounters($link) { | |
bba7c4bf AD |
2321 | # two special categories are -1 and -2 (all virtuals; all labels) |
2322 | ||
2323 | $ctr = getCategoryUnread($link, -1); | |
2324 | ||
2325 | print "<counter type=\"category\" id=\"-1\" counter=\"$ctr\"/>"; | |
2326 | ||
2327 | $ctr = getCategoryUnread($link, -2); | |
2328 | ||
2329 | print "<counter type=\"category\" id=\"-2\" counter=\"$ctr\"/>"; | |
2330 | ||
14073c0a AD |
2331 | $age_qpart = getMaxAgeSubquery(); |
2332 | ||
31375163 AD |
2333 | $result = db_query($link, "SELECT id AS cat_id, value AS unread |
2334 | FROM ttrss_feed_categories, ttrss_cat_counters_cache | |
2335 | WHERE ttrss_cat_counters_cache.feed_id = id AND | |
2336 | ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]); | |
a9cb1f83 AD |
2337 | |
2338 | while ($line = db_fetch_assoc($result)) { | |
2339 | $line["cat_id"] = sprintf("%d", $line["cat_id"]); | |
8a4c759e | 2340 | |
a9cb1f83 AD |
2341 | print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"". |
2342 | $line["unread"]."\"/>"; | |
2343 | } | |
d232a40f AD |
2344 | |
2345 | /* Special case: NULL category doesn't actually exist in the DB */ | |
2346 | ||
2347 | print "<counter type=\"category\" id=\"0\" counter=\"". | |
2348 | ccache_find($link, 0, $_SESSION["uid"], true)."\"/>"; | |
2349 | ||
a9cb1f83 AD |
2350 | } |
2351 | ||
b6d486a3 AD |
2352 | function getCategoryUnread($link, $cat, $owner_uid = false) { |
2353 | ||
2354 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
f295c368 | 2355 | |
bba7c4bf | 2356 | if ($cat >= 0) { |
18664970 | 2357 | |
bba7c4bf AD |
2358 | if ($cat != 0) { |
2359 | $cat_query = "cat_id = '$cat'"; | |
2360 | } else { | |
2361 | $cat_query = "cat_id IS NULL"; | |
2362 | } | |
14073c0a AD |
2363 | |
2364 | $age_qpart = getMaxAgeSubquery(); | |
2365 | ||
bba7c4bf AD |
2366 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query |
2367 | AND hidden = false | |
b6d486a3 | 2368 | AND owner_uid = " . $owner_uid); |
bba7c4bf AD |
2369 | |
2370 | $cat_feeds = array(); | |
2371 | while ($line = db_fetch_assoc($result)) { | |
2372 | array_push($cat_feeds, "feed_id = " . $line["id"]); | |
2373 | } | |
2374 | ||
2375 | if (count($cat_feeds) == 0) return 0; | |
2376 | ||
2377 | $match_part = implode(" OR ", $cat_feeds); | |
2378 | ||
2379 | $result = db_query($link, "SELECT COUNT(int_id) AS unread | |
14073c0a AD |
2380 | FROM ttrss_user_entries,ttrss_entries |
2381 | WHERE unread = true AND ($match_part) AND id = ref_id | |
b6d486a3 | 2382 | AND $age_qpart AND owner_uid = " . $owner_uid); |
bba7c4bf AD |
2383 | |
2384 | $unread = 0; | |
2385 | ||
2386 | # this needs to be rewritten | |
2387 | while ($line = db_fetch_assoc($result)) { | |
2388 | $unread += $line["unread"]; | |
2389 | } | |
2390 | ||
2391 | return $unread; | |
2392 | } else if ($cat == -1) { | |
2d24f032 | 2393 | return getFeedUnread($link, -1) + getFeedUnread($link, -2) + getFeedUnread($link, -3); |
bba7c4bf | 2394 | } else if ($cat == -2) { |
f295c368 | 2395 | |
bba7c4bf AD |
2396 | $rv = getLabelCounters($link, false, true); |
2397 | $ctr = 0; | |
f295c368 | 2398 | |
bba7c4bf AD |
2399 | foreach (array_keys($rv) as $k) { |
2400 | if ($k < -10) { | |
2401 | $ctr += $rv[$k]["counter"]; | |
2402 | } | |
2403 | } | |
f295c368 | 2404 | |
bba7c4bf | 2405 | return $ctr; |
f295c368 | 2406 | } |
f295c368 AD |
2407 | } |
2408 | ||
14073c0a AD |
2409 | function getMaxAgeSubquery($days = COUNTERS_MAX_AGE) { |
2410 | if (DB_TYPE == "pgsql") { | |
2411 | return "ttrss_entries.date_entered > | |
2412 | NOW() - INTERVAL '$days days'"; | |
2413 | } else { | |
2414 | return "ttrss_entries.date_entered > | |
2415 | DATE_SUB(NOW(), INTERVAL $days DAY)"; | |
2416 | } | |
2417 | } | |
2418 | ||
f295c368 | 2419 | function getFeedUnread($link, $feed, $is_cat = false) { |
2627f2d0 | 2420 | return getFeedArticles($link, $feed, $is_cat, true, $_SESSION["uid"]); |
bdb7369b AD |
2421 | } |
2422 | ||
2627f2d0 AD |
2423 | function getFeedArticles($link, $feed, $is_cat = false, $unread_only = false, |
2424 | $owner_uid = false) { | |
2425 | ||
a9cb1f83 | 2426 | $n_feed = sprintf("%d", $feed); |
f295c368 | 2427 | |
2627f2d0 AD |
2428 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
2429 | ||
bdb7369b AD |
2430 | if ($unread_only) { |
2431 | $unread_qpart = "unread = true"; | |
2432 | } else { | |
2433 | $unread_qpart = "true"; | |
2434 | } | |
2435 | ||
14073c0a AD |
2436 | $age_qpart = getMaxAgeSubquery(); |
2437 | ||
f295c368 | 2438 | if ($is_cat) { |
b6d486a3 | 2439 | return getCategoryUnread($link, $n_feed, $owner_uid); |
f295c368 | 2440 | } else if ($n_feed == -1) { |
a9cb1f83 | 2441 | $match_part = "marked = true"; |
e4f4b46f AD |
2442 | } else if ($n_feed == -2) { |
2443 | $match_part = "published = true"; | |
2d24f032 AD |
2444 | } else if ($n_feed == -3) { |
2445 | $match_part = "unread = true"; | |
2446 | ||
b71e188e | 2447 | $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE", $owner_uid); |
c1d7e6c3 | 2448 | |
2d24f032 | 2449 | if (DB_TYPE == "pgsql") { |
7608b38a | 2450 | $match_part .= " AND updated > NOW() - INTERVAL '$intl hour' "; |
2d24f032 | 2451 | } else { |
7608b38a | 2452 | $match_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; |
2d24f032 AD |
2453 | } |
2454 | ||
4919fb42 | 2455 | } else if ($n_feed > 0) { |
831ff047 | 2456 | |
e8b8485f AD |
2457 | $result = db_query($link, "SELECT id FROM ttrss_feeds |
2458 | WHERE parent_feed = '$n_feed' | |
318260cc | 2459 | AND hidden = false |
2627f2d0 | 2460 | AND owner_uid = " . $owner_uid); |
831ff047 AD |
2461 | |
2462 | if (db_num_rows($result) > 0) { | |
4919fb42 | 2463 | |
831ff047 AD |
2464 | $linked_feeds = array(); |
2465 | while ($line = db_fetch_assoc($result)) { | |
2466 | array_push($linked_feeds, "feed_id = " . $line["id"]); | |
2467 | } | |
e8b8485f AD |
2468 | |
2469 | array_push($linked_feeds, "feed_id = $n_feed"); | |
831ff047 AD |
2470 | |
2471 | $match_part = implode(" OR ", $linked_feeds); | |
2472 | ||
4919fb42 | 2473 | $result = db_query($link, "SELECT COUNT(int_id) AS unread |
14073c0a | 2474 | FROM ttrss_user_entries,ttrss_entries |
bdb7369b | 2475 | WHERE $unread_qpart AND |
14073c0a AD |
2476 | ttrss_user_entries.ref_id = ttrss_entries.id AND |
2477 | $age_qpart AND | |
2478 | ($match_part) AND | |
2627f2d0 | 2479 | owner_uid = " . $owner_uid); |
4919fb42 AD |
2480 | |
2481 | $unread = 0; | |
2482 | ||
2483 | # this needs to be rewritten | |
2484 | while ($line = db_fetch_assoc($result)) { | |
2485 | $unread += $line["unread"]; | |
2486 | } | |
2487 | ||
2488 | return $unread; | |
2489 | ||
831ff047 AD |
2490 | } else { |
2491 | $match_part = "feed_id = '$n_feed'"; | |
2492 | } | |
a9cb1f83 | 2493 | } else if ($feed < -10) { |
318260cc | 2494 | |
a9cb1f83 AD |
2495 | $label_id = -$feed - 11; |
2496 | ||
2497 | $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE | |
2627f2d0 | 2498 | id = '$label_id' AND owner_uid = " . $owner_uid); |
a9cb1f83 AD |
2499 | |
2500 | $match_part = db_fetch_result($result, 0, "sql_exp"); | |
2501 | } | |
2502 | ||
2503 | if ($match_part) { | |
2504 | ||
2505 | $result = db_query($link, "SELECT count(int_id) AS unread | |
88040f57 AD |
2506 | FROM ttrss_user_entries,ttrss_feeds,ttrss_entries WHERE |
2507 | ttrss_user_entries.feed_id = ttrss_feeds.id AND | |
2508 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
cfb02131 | 2509 | ttrss_feeds.hidden = false AND |
14073c0a | 2510 | $age_qpart AND |
2627f2d0 | 2511 | $unread_qpart AND ($match_part) AND ttrss_user_entries.owner_uid = " . $owner_uid); |
a9cb1f83 AD |
2512 | |
2513 | } else { | |
2514 | ||
2515 | $result = db_query($link, "SELECT COUNT(post_int_id) AS unread | |
14073c0a | 2516 | FROM ttrss_tags,ttrss_user_entries,ttrss_entries |
828f22b7 | 2517 | WHERE tag_name = '$feed' AND post_int_id = int_id AND ref_id = ttrss_entries.id |
bdb7369b | 2518 | AND $unread_qpart AND $age_qpart AND |
2627f2d0 | 2519 | ttrss_tags.owner_uid = " . $owner_uid); |
a9cb1f83 AD |
2520 | } |
2521 | ||
2522 | $unread = db_fetch_result($result, 0, "unread"); | |
cfb02131 | 2523 | |
a9cb1f83 AD |
2524 | return $unread; |
2525 | } | |
2526 | ||
f3acc32e AD |
2527 | function getGlobalUnread($link, $user_id = false) { |
2528 | ||
2529 | if (!$user_id) { | |
2530 | $user_id = $_SESSION["uid"]; | |
2531 | } | |
2532 | ||
8a4c759e AD |
2533 | $result = db_query($link, "SELECT SUM(value) AS c_id FROM ttrss_counters_cache |
2534 | WHERE owner_uid = '$user_id' AND feed_id > 0"); | |
2535 | ||
2536 | $c_id = db_fetch_result($result, 0, "c_id"); | |
2537 | ||
a9cb1f83 AD |
2538 | return $c_id; |
2539 | } | |
2540 | ||
2541 | function getGlobalCounters($link, $global_unread = -1) { | |
2542 | if ($global_unread == -1) { | |
2543 | $global_unread = getGlobalUnread($link); | |
2544 | } | |
7bf7e4d3 AD |
2545 | print "<counter type=\"global\" id='global-unread' |
2546 | counter='$global_unread'/>"; | |
2547 | ||
2548 | $result = db_query($link, "SELECT COUNT(id) AS fn FROM | |
2549 | ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); | |
2550 | ||
2551 | $subscribed_feeds = db_fetch_result($result, 0, "fn"); | |
2552 | ||
2553 | print "<counter type=\"global\" id='subscribed-feeds' | |
2554 | counter='$subscribed_feeds'/>"; | |
2555 | ||
a9cb1f83 AD |
2556 | } |
2557 | ||
2558 | function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
2559 | ||
2560 | if ($smart_mode) { | |
2561 | if (!$_SESSION["tctr_last_value"]) { | |
2562 | $_SESSION["tctr_last_value"] = array(); | |
2563 | } | |
2564 | } | |
2565 | ||
2566 | $old_counters = $_SESSION["tctr_last_value"]; | |
2567 | ||
2568 | $tctrs_modified = false; | |
2569 | ||
2570 | /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
2571 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE | |
2572 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
2573 | ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND | |
2574 | post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name | |
2575 | UNION | |
2576 | select tag_name,0 as count FROM ttrss_tags | |
2577 | WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */ | |
2578 | ||
14073c0a AD |
2579 | $age_qpart = getMaxAgeSubquery(); |
2580 | ||
a9cb1f83 | 2581 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) |
14073c0a AD |
2582 | FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id |
2583 | AND ref_id = id AND $age_qpart | |
a9cb1f83 | 2584 | AND unread = true)) AS count FROM ttrss_tags |
ef1ac7c7 AD |
2585 | WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name |
2586 | ORDER BY count DESC LIMIT 55"); | |
a9cb1f83 AD |
2587 | |
2588 | $tags = array(); | |
2589 | ||
2590 | while ($line = db_fetch_assoc($result)) { | |
2591 | $tags[$line["tag_name"]] += $line["count"]; | |
2592 | } | |
2593 | ||
2594 | foreach (array_keys($tags) as $tag) { | |
2595 | $unread = $tags[$tag]; | |
2596 | ||
2597 | $tag = htmlspecialchars($tag); | |
2598 | ||
2599 | if (!$smart_mode || $old_counters[$tag] != $unread) { | |
2600 | $old_counters[$tag] = $unread; | |
2601 | $tctrs_modified = true; | |
2602 | print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>"; | |
2603 | } | |
2604 | ||
2605 | } | |
2606 | ||
2607 | if ($smart_mode && $tctrs_modified) { | |
2608 | $_SESSION["tctr_last_value"] = $old_counters; | |
2609 | } | |
2610 | ||
2611 | } | |
2612 | ||
ef393de7 | 2613 | function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) { |
a9cb1f83 | 2614 | |
14073c0a AD |
2615 | $age_qpart = getMaxAgeSubquery(); |
2616 | ||
a9cb1f83 AD |
2617 | if ($smart_mode) { |
2618 | if (!$_SESSION["lctr_last_value"]) { | |
2619 | $_SESSION["lctr_last_value"] = array(); | |
2620 | } | |
2621 | } | |
2622 | ||
ef393de7 AD |
2623 | $ret_arr = array(); |
2624 | ||
a9cb1f83 AD |
2625 | $old_counters = $_SESSION["lctr_last_value"]; |
2626 | $lctrs_modified = false; | |
2627 | ||
2d24f032 | 2628 | $count = getFeedUnread($link, -1); |
a9cb1f83 | 2629 | |
ef393de7 | 2630 | if (!$ret_mode) { |
bdb7369b AD |
2631 | |
2632 | if (get_pref($link, 'EXTENDED_FEEDLIST')) { | |
2633 | $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; | |
2634 | } else { | |
2635 | $xmsg_part = ""; | |
2636 | } | |
2637 | ||
2638 | print "<counter type=\"label\" id=\"-1\" counter=\"$count\" $xmsg_part/>"; | |
ef393de7 AD |
2639 | } else { |
2640 | $ret_arr["-1"]["counter"] = $count; | |
bba7c4bf | 2641 | $ret_arr["-1"]["description"] = __("Starred articles"); |
ef393de7 | 2642 | } |
a9cb1f83 | 2643 | |
2d24f032 | 2644 | $count = getFeedUnread($link, -2); |
e4f4b46f AD |
2645 | |
2646 | if (!$ret_mode) { | |
bdb7369b AD |
2647 | |
2648 | if (get_pref($link, 'EXTENDED_FEEDLIST')) { | |
2649 | $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; | |
2650 | } else { | |
2651 | $xmsg_part = ""; | |
2652 | } | |
2653 | ||
2654 | print "<counter type=\"label\" id=\"-2\" counter=\"$count\" $xmsg_part/>"; | |
e4f4b46f AD |
2655 | } else { |
2656 | $ret_arr["-2"]["counter"] = $count; | |
bba7c4bf | 2657 | $ret_arr["-2"]["description"] = __("Published articles"); |
e4f4b46f AD |
2658 | } |
2659 | ||
2d24f032 AD |
2660 | $count = getFeedUnread($link, -3); |
2661 | ||
2662 | if (!$ret_mode) { | |
bdb7369b AD |
2663 | |
2664 | if (get_pref($link, 'EXTENDED_FEEDLIST')) { | |
2665 | $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; | |
2666 | } else { | |
2667 | $xmsg_part = ""; | |
2668 | } | |
2669 | ||
2670 | print "<counter type=\"label\" id=\"-3\" counter=\"$count\" $xmsg_part/>"; | |
2d24f032 AD |
2671 | } else { |
2672 | $ret_arr["-3"]["counter"] = $count; | |
2673 | $ret_arr["-3"]["description"] = __("Fresh articles"); | |
2674 | } | |
2675 | ||
e4f4b46f | 2676 | |
a9cb1f83 AD |
2677 | $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM |
2678 | ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description"); | |
2679 | ||
2680 | while ($line = db_fetch_assoc($result)) { | |
2681 | ||
2682 | $id = -$line["id"] - 11; | |
2683 | ||
ef393de7 AD |
2684 | $label_name = $line["description"]; |
2685 | ||
a9cb1f83 AD |
2686 | error_reporting (0); |
2687 | ||
5f4f7adf | 2688 | $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_user_entries,ttrss_entries,ttrss_feeds |
a9cb1f83 | 2689 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND |
cfb02131 | 2690 | ttrss_feeds.hidden = false AND |
14073c0a | 2691 | $age_qpart AND |
88040f57 | 2692 | ttrss_user_entries.feed_id = ttrss_feeds.id AND |
a9cb1f83 | 2693 | ttrss_user_entries.ref_id = ttrss_entries.id AND |
88040f57 | 2694 | ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); |
a9cb1f83 AD |
2695 | |
2696 | $count = db_fetch_result($tmp_result, 0, "count"); | |
2697 | ||
2698 | if (!$smart_mode || $old_counters[$id] != $count) { | |
2699 | $old_counters[$id] = $count; | |
2700 | $lctrs_modified = true; | |
ef393de7 | 2701 | if (!$ret_mode) { |
bdb7369b AD |
2702 | |
2703 | if (get_pref($link, 'EXTENDED_FEEDLIST')) { | |
2704 | $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; | |
2705 | } else { | |
2706 | $xmsg_part = ""; | |
2707 | } | |
2708 | ||
2709 | print "<counter type=\"label\" id=\"$id\" counter=\"$count\" $xmsg_part/>"; | |
ef393de7 AD |
2710 | } else { |
2711 | $ret_arr[$id]["counter"] = $count; | |
2712 | $ret_arr[$id]["description"] = $label_name; | |
2713 | } | |
5f4f7adf | 2714 | } |
a9cb1f83 AD |
2715 | |
2716 | error_reporting (DEFAULT_ERROR_LEVEL); | |
5f4f7adf | 2717 | } |
a9cb1f83 AD |
2718 | |
2719 | if ($smart_mode && $lctrs_modified) { | |
2720 | $_SESSION["lctr_last_value"] = $old_counters; | |
2721 | } | |
ef393de7 AD |
2722 | |
2723 | return $ret_arr; | |
a9cb1f83 AD |
2724 | } |
2725 | ||
4ffa126e | 2726 | function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS, $active_feed = false) { |
a9cb1f83 | 2727 | |
14073c0a AD |
2728 | $age_qpart = getMaxAgeSubquery(); |
2729 | ||
a9cb1f83 AD |
2730 | if ($smart_mode) { |
2731 | if (!$_SESSION["fctr_last_value"]) { | |
2732 | $_SESSION["fctr_last_value"] = array(); | |
2733 | } | |
2734 | } | |
2735 | ||
2736 | $old_counters = $_SESSION["fctr_last_value"]; | |
2737 | ||
8a4c759e | 2738 | /* $query = "SELECT ttrss_feeds.id, |
14073c0a | 2739 | ttrss_feeds.title, |
fc2b26a6 | 2740 | ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, |
1b1b8a7b | 2741 | last_error, |
bc60fda3 | 2742 | COUNT(ttrss_entries.id) AS count |
1b1b8a7b AD |
2743 | FROM ttrss_feeds |
2744 | LEFT JOIN ttrss_user_entries ON (ttrss_user_entries.feed_id = ttrss_feeds.id | |
2745 | AND ttrss_user_entries.owner_uid = ttrss_feeds.owner_uid | |
2746 | AND ttrss_user_entries.unread = true) | |
14073c0a AD |
2747 | LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id AND |
2748 | $age_qpart) | |
2749 | WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]." | |
1b1b8a7b | 2750 | AND parent_feed IS NULL |
8a4c759e AD |
2751 | GROUP BY ttrss_feeds.id, ttrss_feeds.title, ttrss_feeds.last_updated, last_error"; */ |
2752 | ||
2753 | $query = "SELECT ttrss_feeds.id, | |
2754 | ttrss_feeds.title, | |
2755 | ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, | |
de0a2122 AD |
2756 | last_error, value AS count |
2757 | FROM ttrss_feeds, ttrss_counters_cache | |
8a4c759e AD |
2758 | WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]." |
2759 | AND parent_feed IS NULL | |
55e01d7e | 2760 | AND ttrss_counters_cache.feed_id = id"; |
a9cb1f83 | 2761 | |
14073c0a | 2762 | $result = db_query($link, $query); |
a9cb1f83 AD |
2763 | $fctrs_modified = false; |
2764 | ||
fb1fb4ab AD |
2765 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); |
2766 | ||
a9cb1f83 AD |
2767 | while ($line = db_fetch_assoc($result)) { |
2768 | ||
2769 | $id = $line["id"]; | |
de0a2122 | 2770 | $count = $line["count"]; |
a9cb1f83 | 2771 | $last_error = htmlspecialchars($line["last_error"]); |
fb1fb4ab AD |
2772 | |
2773 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
2774 | $last_updated = smart_date_time(strtotime($line["last_updated"])); | |
2775 | } else { | |
2776 | $last_updated = date($short_date, strtotime($line["last_updated"])); | |
2777 | } | |
2778 | ||
588fb13b AD |
2779 | $last_updated = htmlspecialchars($last_updated); |
2780 | ||
7defa089 | 2781 | $has_img = feed_has_icon($id); |
a9cb1f83 | 2782 | |
de0a2122 | 2783 | /* $tmp_result = db_query($link, |
14073c0a | 2784 | "SELECT ttrss_feeds.id,COUNT(unread) AS unread |
a9cb1f83 AD |
2785 | FROM ttrss_feeds LEFT JOIN ttrss_user_entries |
2786 | ON (ttrss_feeds.id = ttrss_user_entries.feed_id) | |
14073c0a | 2787 | LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id) |
de0a2122 AD |
2788 | WHERE parent_feed = '$id' AND $age_qpart AND unread = true GROUP BY ttrss_feeds.id"); */ |
2789 | ||
2790 | $tmp_result = db_query($link, | |
2791 | "SELECT SUM(value) AS unread FROM ttrss_feeds, ttrss_counters_cache | |
2792 | WHERE parent_feed = '$id' AND feed_id = id"); | |
2793 | ||
2794 | $count += db_fetch_result($tmp_result, 0, "unread"); | |
a9cb1f83 AD |
2795 | |
2796 | if (!$smart_mode || $old_counters[$id] != $count) { | |
2797 | $old_counters[$id] = $count; | |
2798 | $fctrs_modified = true; | |
2799 | ||
2800 | if ($last_error) { | |
2801 | $error_part = "error=\"$last_error\""; | |
2802 | } else { | |
2803 | $error_part = ""; | |
2804 | } | |
2805 | ||
2806 | if ($has_img) { | |
2807 | $has_img_part = "hi=\"$has_img\""; | |
2808 | } else { | |
2809 | $has_img_part = ""; | |
2810 | } | |
2811 | ||
4ffa126e AD |
2812 | if ($active_feed && $id == $active_feed) { |
2813 | $has_title_part = "title=\"" . htmlspecialchars($line["title"]) . "\""; | |
2814 | } else { | |
2815 | $has_title_part = ""; | |
2816 | } | |
2817 | ||
bdb7369b AD |
2818 | if (get_pref($link, 'EXTENDED_FEEDLIST')) { |
2819 | $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; | |
2820 | } | |
2821 | ||
2822 | print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part updated=\"$last_updated\" $xmsg_part $has_title_part/>"; | |
a9cb1f83 AD |
2823 | } |
2824 | } | |
2825 | ||
2826 | if ($smart_mode && $fctrs_modified) { | |
2827 | $_SESSION["fctr_last_value"] = $old_counters; | |
2828 | } | |
2829 | } | |
2830 | ||
1b758780 | 2831 | function get_script_dt_add() { |
34e420fb | 2832 | if (strpos(VERSION, ".99") === false) { |
1b758780 AD |
2833 | return VERSION; |
2834 | } else { | |
2835 | return time(); | |
2836 | } | |
2837 | } | |
2838 | ||
6e7f8d26 AD |
2839 | function get_pgsql_version($link) { |
2840 | $result = db_query($link, "SELECT version() AS version"); | |
2841 | $version = split(" ", db_fetch_result($result, 0, "version")); | |
2842 | return $version[1]; | |
2843 | } | |
2844 | ||
af106b0e AD |
2845 | function print_error_xml($code, $add_msg = "") { |
2846 | global $ERRORS; | |
2847 | ||
2848 | $error_msg = $ERRORS[$code]; | |
2849 | ||
2850 | if ($add_msg) { | |
2851 | $error_msg = "$error_msg; $add_msg"; | |
2852 | } | |
2853 | ||
4c2abbc1 | 2854 | print "<rpc-reply>"; |
af106b0e | 2855 | print "<error error-code=\"$code\" error-msg=\"$error_msg\"/>"; |
4c2abbc1 | 2856 | print "</rpc-reply>"; |
af106b0e | 2857 | } |
956c7629 | 2858 | |
f27de515 AD |
2859 | function subscribe_to_feed($link, $feed_link, $cat_id = 0, |
2860 | $auth_login = '', $auth_pass = '') { | |
bb0f29a4 | 2861 | |
b3dfe8ba | 2862 | # check for feed:http://url |
c91c2249 AD |
2863 | $feed_link = trim(preg_replace("/^feed:/", "", $feed_link)); |
2864 | ||
b3dfe8ba | 2865 | # check for feed://URL |
e2d84cdb | 2866 | if (strpos($feed_link, "//") === 0) { |
b3dfe8ba AD |
2867 | $feed_link = "http:$feed_link"; |
2868 | } | |
2869 | ||
c91c2249 | 2870 | if ($feed_link == "") return; |
bb0f29a4 | 2871 | |
956c7629 AD |
2872 | if ($cat_id == "0" || !$cat_id) { |
2873 | $cat_qpart = "NULL"; | |
2874 | } else { | |
2875 | $cat_qpart = "'$cat_id'"; | |
2876 | } | |
2877 | ||
2878 | $result = db_query($link, | |
2879 | "SELECT id FROM ttrss_feeds | |
2880 | WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); | |
2881 | ||
2882 | if (db_num_rows($result) == 0) { | |
2883 | ||
2884 | $result = db_query($link, | |
f27de515 AD |
2885 | "INSERT INTO ttrss_feeds |
2886 | (owner_uid,feed_url,title,cat_id, auth_login,auth_pass) | |
956c7629 | 2887 | VALUES ('".$_SESSION["uid"]."', '$feed_link', |
f27de515 | 2888 | '[Unknown]', $cat_qpart, '$auth_login', '$auth_pass')"); |
956c7629 AD |
2889 | |
2890 | $result = db_query($link, | |
2891 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' | |
f27de515 | 2892 | AND owner_uid = " . $_SESSION["uid"]); |
956c7629 AD |
2893 | |
2894 | $feed_id = db_fetch_result($result, 0, "id"); | |
2895 | ||
2896 | if ($feed_id) { | |
2897 | update_rss_feed($link, $feed_link, $feed_id, true); | |
2898 | } | |
2899 | ||
2900 | return true; | |
2901 | } else { | |
2902 | return false; | |
2903 | } | |
2904 | } | |
2905 | ||
673d54ca AD |
2906 | function print_feed_select($link, $id, $default_id = "", |
2907 | $attributes = "", $include_all_feeds = true) { | |
2908 | ||
79f3553b | 2909 | print "<select id=\"$id\" name=\"$id\" $attributes>"; |
673d54ca | 2910 | if ($include_all_feeds) { |
89cb787e | 2911 | print "<option value=\"0\">".__('All feeds')."</option>"; |
673d54ca AD |
2912 | } |
2913 | ||
2914 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2915 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2916 | ||
2917 | if (db_num_rows($result) > 0 && $include_all_feeds) { | |
2918 | print "<option disabled>--------</option>"; | |
2919 | } | |
2920 | ||
2921 | while ($line = db_fetch_assoc($result)) { | |
2922 | if ($line["id"] == $default_id) { | |
2923 | $is_selected = "selected"; | |
2924 | } else { | |
2925 | $is_selected = ""; | |
2926 | } | |
79f3553b | 2927 | printf("<option $is_selected value='%d'>%s</option>", |
47439031 | 2928 | $line["id"], htmlspecialchars($line["title"])); |
673d54ca AD |
2929 | } |
2930 | ||
2931 | print "</select>"; | |
2932 | } | |
2933 | ||
2934 | function print_feed_cat_select($link, $id, $default_id = "", | |
2935 | $attributes = "", $include_all_cats = true) { | |
2936 | ||
79f3553b | 2937 | print "<select id=\"$id\" name=\"$id\" $attributes>"; |
673d54ca AD |
2938 | |
2939 | if ($include_all_cats) { | |
d1db26aa | 2940 | print "<option value=\"0\">".__('Uncategorized')."</option>"; |
673d54ca AD |
2941 | } |
2942 | ||
2943 | $result = db_query($link, "SELECT id,title FROM ttrss_feed_categories | |
2944 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2945 | ||
2946 | if (db_num_rows($result) > 0 && $include_all_cats) { | |
2947 | print "<option disabled>--------</option>"; | |
2948 | } | |
2949 | ||
2950 | while ($line = db_fetch_assoc($result)) { | |
2951 | if ($line["id"] == $default_id) { | |
2952 | $is_selected = "selected"; | |
2953 | } else { | |
2954 | $is_selected = ""; | |
2955 | } | |
14f69488 | 2956 | printf("<option $is_selected value='%d'>%s</option>", |
47439031 | 2957 | $line["id"], htmlspecialchars($line["title"])); |
673d54ca AD |
2958 | } |
2959 | ||
2960 | print "</select>"; | |
2961 | } | |
2962 | ||
14f69488 AD |
2963 | function checkbox_to_sql_bool($val) { |
2964 | return ($val == "on") ? "true" : "false"; | |
2965 | } | |
86b682ce AD |
2966 | |
2967 | function getFeedCatTitle($link, $id) { | |
2968 | if ($id == -1) { | |
d1db26aa | 2969 | return __("Special"); |
86b682ce | 2970 | } else if ($id < -10) { |
d1db26aa | 2971 | return __("Labels"); |
86b682ce AD |
2972 | } else if ($id > 0) { |
2973 | $result = db_query($link, "SELECT ttrss_feed_categories.title | |
2974 | FROM ttrss_feeds, ttrss_feed_categories WHERE ttrss_feeds.id = '$id' AND | |
2975 | cat_id = ttrss_feed_categories.id"); | |
2976 | if (db_num_rows($result) == 1) { | |
2977 | return db_fetch_result($result, 0, "title"); | |
2978 | } else { | |
d1db26aa | 2979 | return __("Uncategorized"); |
86b682ce AD |
2980 | } |
2981 | } else { | |
2982 | return "getFeedCatTitle($id) failed"; | |
2983 | } | |
2984 | ||
2985 | } | |
2986 | ||
2987 | function getFeedTitle($link, $id) { | |
2988 | if ($id == -1) { | |
d1db26aa | 2989 | return __("Starred articles"); |
945c243e AD |
2990 | } else if ($id == -2) { |
2991 | return __("Published articles"); | |
2d24f032 AD |
2992 | } else if ($id == -3) { |
2993 | return __("Fresh articles"); | |
86b682ce | 2994 | } else if ($id < -10) { |
76626c72 | 2995 | $label_id = -$id - 11; |
86b682ce AD |
2996 | $result = db_query($link, "SELECT description FROM ttrss_labels WHERE id = '$label_id'"); |
2997 | if (db_num_rows($result) == 1) { | |
2998 | return db_fetch_result($result, 0, "description"); | |
2999 | } else { | |
3000 | return "Unknown label ($label_id)"; | |
3001 | } | |
3002 | ||
3003 | } else if ($id > 0) { | |
3004 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$id'"); | |
3005 | if (db_num_rows($result) == 1) { | |
3006 | return db_fetch_result($result, 0, "title"); | |
3007 | } else { | |
3008 | return "Unknown feed ($id)"; | |
3009 | } | |
3010 | } else { | |
3011 | return "getFeedTitle($id) failed"; | |
3012 | } | |
3013 | ||
3014 | } | |
3dd46f19 AD |
3015 | |
3016 | function get_session_cookie_name() { | |
3017 | return ((!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid" : TTRSS_SESSION_NAME); | |
3018 | } | |
3ac2b520 AD |
3019 | |
3020 | function print_init_params($link) { | |
3021 | print "<init-params>"; | |
3022 | if ($_SESSION["stored-params"]) { | |
3023 | foreach (array_keys($_SESSION["stored-params"]) as $key) { | |
5f57b06d AD |
3024 | if ($key) { |
3025 | $value = htmlspecialchars($_SESSION["stored-params"][$key]); | |
3026 | print "<param key=\"$key\" value=\"$value\"/>"; | |
3027 | } | |
3ac2b520 AD |
3028 | } |
3029 | } | |
3030 | ||
20361063 | 3031 | print "<param key=\"theme\" value=\"".$_SESSION["theme"]."\"/>"; |
3ac2b520 AD |
3032 | print "<param key=\"daemon_enabled\" value=\"" . ENABLE_UPDATE_DAEMON . "\"/>"; |
3033 | print "<param key=\"feeds_frame_refresh\" value=\"" . FEEDS_FRAME_REFRESH . "\"/>"; | |
17c0eeba | 3034 | print "<param key=\"daemon_refresh_only\" value=\"true\"/>"; |
3ac2b520 AD |
3035 | |
3036 | print "<param key=\"on_catchup_show_next_feed\" value=\"" . | |
3037 | get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED") . "\"/>"; | |
3038 | ||
e8bd0da9 | 3039 | print "<param key=\"hide_read_feeds\" value=\"" . |
465ff90b | 3040 | (int) get_pref($link, "HIDE_READ_FEEDS") . "\"/>"; |
e8bd0da9 | 3041 | |
c9268ed5 | 3042 | print "<param key=\"feeds_sort_by_unread\" value=\"" . |
465ff90b | 3043 | (int) get_pref($link, "FEEDS_SORT_BY_UNREAD") . "\"/>"; |
c9268ed5 | 3044 | |
f6d6e22f | 3045 | print "<param key=\"confirm_feed_catchup\" value=\"" . |
465ff90b | 3046 | (int) get_pref($link, "CONFIRM_FEED_CATCHUP") . "\"/>"; |
f6d6e22f | 3047 | |
ac7bcd71 | 3048 | print "<param key=\"cdm_auto_catchup\" value=\"" . |
465ff90b | 3049 | (int) get_pref($link, "CDM_AUTO_CATCHUP") . "\"/>"; |
ac7bcd71 | 3050 | |
8e9c121b AD |
3051 | print "<param key=\"icons_url\" value=\"" . ICONS_URL . "\"/>"; |
3052 | ||
be0801a1 AD |
3053 | print "<param key=\"cookie_lifetime\" value=\"" . SESSION_COOKIE_LIFETIME . "\"/>"; |
3054 | ||
40496720 AD |
3055 | print "<param key=\"default_view_mode\" value=\"" . |
3056 | get_pref($link, "_DEFAULT_VIEW_MODE") . "\"/>"; | |
3057 | ||
3058 | print "<param key=\"default_view_limit\" value=\"" . | |
465ff90b | 3059 | (int) get_pref($link, "_DEFAULT_VIEW_LIMIT") . "\"/>"; |
40496720 | 3060 | |
7b4d02a8 AD |
3061 | print "<param key=\"default_view_order_by\" value=\"" . |
3062 | get_pref($link, "_DEFAULT_VIEW_ORDER_BY") . "\"/>"; | |
3063 | ||
fe8d2059 AD |
3064 | print "<param key=\"prefs_active_tab\" value=\"" . |
3065 | get_pref($link, "_PREFS_ACTIVE_TAB") . "\"/>"; | |
3066 | ||
465ff90b AD |
3067 | print "<param key=\"infobox_disable_overlay\" value=\"" . |
3068 | get_pref($link, "_INFOBOX_DISABLE_OVERLAY") . "\"/>"; | |
3069 | ||
527c3bf0 AD |
3070 | print "<param key=\"icons_location\" value=\"" . |
3071 | ICONS_URL . "\"/>"; | |
3072 | ||
22f3e356 AD |
3073 | print "<param key=\"hide_read_shows_special\" value=\"" . |
3074 | (int) get_pref($link, "HIDE_READ_SHOWS_SPECIAL") . "\"/>"; | |
3075 | ||
fca93350 AD |
3076 | print "<param key=\"hide_feedlist\" value=\"" . |
3077 | (int) get_pref($link, "HIDE_FEEDLIST") . "\"/>"; | |
24c1e1c1 | 3078 | |
a598370d AD |
3079 | print "<param key=\"bw_limit\" value=\"". |
3080 | (int) $_SESSION["bw_limit"]."\"/>"; | |
3081 | ||
bd090ab4 AD |
3082 | // print "<param key=\"sync_counters\" value=\"" . |
3083 | // (int) get_pref($link, "SYNC_COUNTERS") . "\"/>"; | |
3084 | ||
3085 | print "<param key=\"sync_counters\" value=\"1\"/>"; | |
d234a2e3 | 3086 | |
3ac2b520 AD |
3087 | print "</init-params>"; |
3088 | } | |
f54f515f AD |
3089 | |
3090 | function print_runtime_info($link) { | |
3091 | print "<runtime-info>"; | |
20361063 | 3092 | |
71ad883b AD |
3093 | if (ENABLE_UPDATE_DAEMON) { |
3094 | print "<param key=\"daemon_is_running\" value=\"". | |
3095 | sprintf("%d", file_is_locked("update_daemon.lock")) . "\"/>"; | |
8e00ae9b | 3096 | |
9041f58b | 3097 | if (time() - $_SESSION["daemon_stamp_check"] > 30) { |
8e00ae9b AD |
3098 | |
3099 | $stamp = (int)read_stampfile("update_daemon.stamp"); | |
3100 | ||
fbae93d8 AD |
3101 | // print "<param key=\"daemon_stamp_delta\" value=\"$stamp_delta\"/>"; |
3102 | ||
8e00ae9b | 3103 | if ($stamp) { |
9041f58b AD |
3104 | $stamp_delta = time() - $stamp; |
3105 | ||
3106 | if ($stamp_delta > 1800) { | |
f6854e44 | 3107 | $stamp_check = 0; |
8e00ae9b | 3108 | } else { |
f6854e44 AD |
3109 | $stamp_check = 1; |
3110 | $_SESSION["daemon_stamp_check"] = time(); | |
8e00ae9b AD |
3111 | } |
3112 | ||
f6854e44 AD |
3113 | print "<param key=\"daemon_stamp_ok\" value=\"$stamp_check\"/>"; |
3114 | ||
8e00ae9b AD |
3115 | $stamp_fmt = date("Y.m.d, G:i", $stamp); |
3116 | ||
3117 | print "<param key=\"daemon_stamp\" value=\"$stamp_fmt\"/>"; | |
3118 | } | |
8e00ae9b | 3119 | } |
71ad883b | 3120 | } |
8e00ae9b | 3121 | |
d9fa39f1 AD |
3122 | if (CHECK_FOR_NEW_VERSION && $_SESSION["access_level"] >= 10) { |
3123 | ||
2d1d59c7 | 3124 | if ($_SESSION["last_version_check"] + 86400 < time()) { |
d9fa39f1 AD |
3125 | $new_version_details = check_for_update($link); |
3126 | ||
3127 | print "<param key=\"new_version_available\" value=\"". | |
3128 | sprintf("%d", $new_version_details != ""). "\"/>"; | |
3129 | ||
3130 | $_SESSION["last_version_check"] = time(); | |
3131 | } | |
3132 | } | |
3133 | ||
1c9df66e | 3134 | // print "<param key=\"new_version_available\" value=\"1\"/>"; |
b4507bc2 | 3135 | |
f54f515f AD |
3136 | print "</runtime-info>"; |
3137 | } | |
ef393de7 | 3138 | |
88040f57 | 3139 | function getSearchSql($search, $match_on) { |
ef393de7 | 3140 | |
88040f57 | 3141 | $search_query_part = ""; |
e20c9d88 | 3142 | |
88040f57 AD |
3143 | $keywords = split(" ", $search); |
3144 | $query_keywords = array(); | |
e20c9d88 | 3145 | |
88040f57 | 3146 | if ($match_on == "both") { |
e20c9d88 | 3147 | |
88040f57 AD |
3148 | foreach ($keywords as $k) { |
3149 | array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%') | |
3150 | OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))"); | |
3151 | } | |
e20c9d88 | 3152 | |
88040f57 | 3153 | $search_query_part = implode("AND", $query_keywords) . " AND "; |
e20c9d88 | 3154 | |
88040f57 | 3155 | } else if ($match_on == "title") { |
e20c9d88 | 3156 | |
88040f57 AD |
3157 | foreach ($keywords as $k) { |
3158 | array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))"); | |
3159 | } | |
e20c9d88 | 3160 | |
88040f57 | 3161 | $search_query_part = implode("AND", $query_keywords) . " AND "; |
e20c9d88 | 3162 | |
88040f57 AD |
3163 | } else if ($match_on == "content") { |
3164 | ||
3165 | foreach ($keywords as $k) { | |
3166 | array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))"); | |
3167 | } | |
3168 | } | |
3169 | ||
3170 | $search_query_part = implode("AND", $query_keywords); | |
3171 | ||
3172 | return $search_query_part; | |
3173 | } | |
3174 | ||
c36bf4d5 AD |
3175 | function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0) { |
3176 | ||
3177 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
c1a0b534 | 3178 | |
88040f57 AD |
3179 | if ($search) { |
3180 | ||
3181 | $search_query_part = getSearchSql($search, $match_on); | |
3182 | $search_query_part .= " AND "; | |
e20c9d88 | 3183 | |
ef393de7 AD |
3184 | } else { |
3185 | $search_query_part = ""; | |
3186 | } | |
3187 | ||
3188 | $view_query_part = ""; | |
3189 | ||
7b4d02a8 | 3190 | if ($view_mode == "adaptive" || $view_query_part == "noscores") { |
ef393de7 AD |
3191 | if ($search) { |
3192 | $view_query_part = " "; | |
3193 | } else if ($feed != -1) { | |
f295c368 | 3194 | $unread = getFeedUnread($link, $feed, $cat_view); |
ef393de7 AD |
3195 | if ($unread > 0) { |
3196 | $view_query_part = " unread = true AND "; | |
3197 | } | |
3198 | } | |
3199 | } | |
3200 | ||
3201 | if ($view_mode == "marked") { | |
3202 | $view_query_part = " marked = true AND "; | |
3203 | } | |
3204 | ||
3205 | if ($view_mode == "unread") { | |
3206 | $view_query_part = " unread = true AND "; | |
3207 | } | |
3208 | ||
3209 | if ($limit > 0) { | |
3210 | $limit_query_part = "LIMIT " . $limit; | |
3211 | } | |
3212 | ||
3213 | $vfeed_query_part = ""; | |
3214 | ||
3215 | // override query strategy and enable feed display when searching globally | |
3216 | if ($search && $search_mode == "all_feeds") { | |
3217 | $query_strategy_part = "ttrss_entries.id > 0"; | |
3218 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
3219 | } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) { | |
3220 | $query_strategy_part = "ttrss_entries.id > 0"; | |
3221 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
3222 | id = feed_id) as feed_title,"; | |
3223 | } else if ($feed >= 0 && $search && $search_mode == "this_cat") { | |
3224 | ||
3225 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
0a6c4846 AD |
3226 | |
3227 | $tmp_result = false; | |
3228 | ||
3229 | if ($cat_view) { | |
3230 | $tmp_result = db_query($link, "SELECT id | |
3231 | FROM ttrss_feeds WHERE cat_id = '$feed'"); | |
3232 | } else { | |
3233 | $tmp_result = db_query($link, "SELECT id | |
3234 | FROM ttrss_feeds WHERE cat_id = (SELECT cat_id FROM ttrss_feeds | |
3235 | WHERE id = '$feed') AND id != '$feed'"); | |
3236 | } | |
ef393de7 AD |
3237 | |
3238 | $cat_siblings = array(); | |
3239 | ||
3240 | if (db_num_rows($tmp_result) > 0) { | |
3241 | while ($p = db_fetch_assoc($tmp_result)) { | |
3242 | array_push($cat_siblings, "feed_id = " . $p["id"]); | |
3243 | } | |
3244 | ||
3245 | $query_strategy_part = sprintf("(feed_id = %d OR %s)", | |
3246 | $feed, implode(" OR ", $cat_siblings)); | |
3247 | ||
3248 | } else { | |
3249 | $query_strategy_part = "ttrss_entries.id > 0"; | |
3250 | } | |
3251 | ||
3252 | } else if ($feed >= 0) { | |
3253 | ||
3254 | if ($cat_view) { | |
5c365f60 | 3255 | |
ef393de7 AD |
3256 | if ($feed > 0) { |
3257 | $query_strategy_part = "cat_id = '$feed'"; | |
3258 | } else { | |
3259 | $query_strategy_part = "cat_id IS NULL"; | |
3260 | } | |
3261 | ||
3262 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
5c365f60 | 3263 | |
ef393de7 AD |
3264 | } else { |
3265 | $tmp_result = db_query($link, "SELECT id | |
3266 | FROM ttrss_feeds WHERE parent_feed = '$feed' | |
3267 | ORDER BY cat_id,title"); | |
3268 | ||
3269 | $parent_ids = array(); | |
3270 | ||
3271 | if (db_num_rows($tmp_result) > 0) { | |
3272 | while ($p = db_fetch_assoc($tmp_result)) { | |
3273 | array_push($parent_ids, "feed_id = " . $p["id"]); | |
3274 | } | |
3275 | ||
3276 | $query_strategy_part = sprintf("(feed_id = %d OR %s)", | |
3277 | $feed, implode(" OR ", $parent_ids)); | |
3278 | ||
3279 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
3280 | } else { | |
3281 | $query_strategy_part = "feed_id = '$feed'"; | |
3282 | } | |
3283 | } | |
3284 | } else if ($feed == -1) { // starred virtual feed | |
3285 | $query_strategy_part = "marked = true"; | |
3286 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
e4f4b46f AD |
3287 | } else if ($feed == -2) { // published virtual feed |
3288 | $query_strategy_part = "published = true"; | |
2d24f032 AD |
3289 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
3290 | } else if ($feed == -3) { // fresh virtual feed | |
3291 | $query_strategy_part = "unread = true"; | |
3292 | ||
7a22dc2a | 3293 | $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE", $owner_uid); |
c1d7e6c3 | 3294 | |
2d24f032 | 3295 | if (DB_TYPE == "pgsql") { |
7608b38a | 3296 | $query_strategy_part .= " AND updated > NOW() - INTERVAL '$intl hour' "; |
2d24f032 | 3297 | } else { |
7608b38a | 3298 | $query_strategy_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; |
2d24f032 AD |
3299 | } |
3300 | ||
e4f4b46f | 3301 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
ef393de7 AD |
3302 | } else if ($feed <= -10) { // labels |
3303 | $label_id = -$feed - 11; | |
3304 | ||
3305 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
3306 | WHERE id = '$label_id'"); | |
3307 | ||
4bc311fc | 3308 | $query_strategy_part = "(" . db_fetch_result($tmp_result, 0, "sql_exp") . ")"; |
3de0261a AD |
3309 | |
3310 | if (!$query_strategy_part) { | |
3311 | return false; | |
3312 | } | |
3313 | ||
ef393de7 AD |
3314 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
3315 | } else { | |
3316 | $query_strategy_part = "id > 0"; // dumb | |
3317 | } | |
d6e5706d | 3318 | |
7a22dc2a | 3319 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { |
d6e5706d AD |
3320 | $order_by = "updated"; |
3321 | } else { | |
3322 | $order_by = "updated DESC"; | |
3323 | } | |
e939722a | 3324 | |
7b4d02a8 AD |
3325 | if ($view_mode != "noscores") { |
3326 | $order_by = "score DESC, $order_by"; | |
3327 | } | |
48b0c4ec | 3328 | |
e939722a AD |
3329 | if ($override_order) { |
3330 | $order_by = $override_order; | |
3331 | } | |
ef393de7 AD |
3332 | |
3333 | $feed_title = ""; | |
3334 | ||
3335 | if ($search && $search_mode == "all_feeds") { | |
b36e002f | 3336 | $feed_title = __("Search results")." ($search)"; |
ef393de7 | 3337 | } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { |
b36e002f | 3338 | $feed_title = __("Search results")." ($search, $feed)"; |
ef393de7 AD |
3339 | } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { |
3340 | $feed_title = $feed; | |
3341 | } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) { | |
3342 | ||
3343 | if ($cat_view) { | |
5c365f60 | 3344 | |
ef393de7 AD |
3345 | if ($feed != 0) { |
3346 | $result = db_query($link, "SELECT title FROM ttrss_feed_categories | |
c36bf4d5 | 3347 | WHERE id = '$feed' AND owner_uid = $owner_uid"); |
ef393de7 AD |
3348 | $feed_title = db_fetch_result($result, 0, "title"); |
3349 | } else { | |
d1db26aa | 3350 | $feed_title = __("Uncategorized"); |
ef393de7 | 3351 | } |
e1eb2147 AD |
3352 | |
3353 | if ($search) { | |
b36e002f | 3354 | $feed_title = __("Searched for")." $search ($feed_title)"; |
e1eb2147 AD |
3355 | } |
3356 | ||
ef393de7 AD |
3357 | } else { |
3358 | ||
3359 | $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds | |
c36bf4d5 | 3360 | WHERE id = '$feed' AND owner_uid = $owner_uid"); |
ef393de7 AD |
3361 | |
3362 | $feed_title = db_fetch_result($result, 0, "title"); | |
3363 | $feed_site_url = db_fetch_result($result, 0, "site_url"); | |
3364 | $last_error = db_fetch_result($result, 0, "last_error"); | |
e1eb2147 AD |
3365 | |
3366 | if ($search) { | |
b36e002f | 3367 | $feed_title = __("Searched for") . " $search ($feed_title)"; |
e1eb2147 | 3368 | } |
ef393de7 AD |
3369 | } |
3370 | ||
3371 | } else if ($feed == -1) { | |
d1db26aa | 3372 | $feed_title = __("Starred articles"); |
6cfa22dc | 3373 | if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } |
e4f4b46f AD |
3374 | } else if ($feed == -2) { |
3375 | $feed_title = __("Published articles"); | |
6cfa22dc | 3376 | if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } |
2d24f032 AD |
3377 | } else if ($feed == -3) { |
3378 | $feed_title = __("Fresh articles"); | |
6cfa22dc | 3379 | if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } |
ef393de7 AD |
3380 | } else if ($feed < -10) { |
3381 | $label_id = -$feed - 11; | |
3382 | $result = db_query($link, "SELECT description FROM ttrss_labels | |
3383 | WHERE id = '$label_id'"); | |
3384 | $feed_title = db_fetch_result($result, 0, "description"); | |
88040f57 AD |
3385 | |
3386 | if ($search) { | |
b36e002f | 3387 | $feed_title = __("Searched for") . " $search ($feed_title)"; |
88040f57 | 3388 | } |
ef393de7 AD |
3389 | } else { |
3390 | $feed_title = "?"; | |
3391 | } | |
3392 | ||
ef393de7 AD |
3393 | if ($feed < -10) error_reporting (0); |
3394 | ||
62129e67 AD |
3395 | $content_query_part = "content as content_preview,"; |
3396 | ||
ef393de7 AD |
3397 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { |
3398 | ||
3399 | if ($feed >= 0) { | |
3400 | $feed_kind = "Feeds"; | |
3401 | } else { | |
3402 | $feed_kind = "Labels"; | |
3403 | } | |
3404 | ||
95a82c08 AD |
3405 | if ($limit_query_part) { |
3406 | $offset_query_part = "OFFSET $offset"; | |
3407 | } | |
3408 | ||
d00f22ac | 3409 | if ($vfeed_query_part && get_pref($link, 'VFEED_GROUP_BY_FEED', $owner_uid)) { |
6cfea5c7 | 3410 | if (!$override_order) { |
43fc671f AD |
3411 | $order_by = "ttrss_feeds.title, $order_by"; |
3412 | } | |
3413 | ||
a91c7082 AD |
3414 | // Special output for Fresh feed |
3415 | ||
3416 | /* if ($feed == -3) { | |
43fc671f AD |
3417 | $group_limit_part = "(select count(*) from |
3418 | ttrss_user_entries AS t1, ttrss_entries AS t2 where | |
3419 | t1.ref_id = t2.id and t1.owner_uid = 2 and | |
3420 | t1.feed_id = ttrss_user_entries.feed_id and | |
3421 | t2.updated > ttrss_entries.updated) <= 5 AND"; | |
a91c7082 | 3422 | } */ |
6cfea5c7 AD |
3423 | } |
3424 | ||
ef393de7 | 3425 | $query = "SELECT |
1f64b1be | 3426 | guid, |
ef393de7 | 3427 | ttrss_entries.id,ttrss_entries.title, |
46921916 | 3428 | updated, |
e4f4b46f | 3429 | unread,feed_id,marked,published,link,last_read, |
fc2b26a6 | 3430 | ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms, |
ef393de7 AD |
3431 | $vfeed_query_part |
3432 | $content_query_part | |
fc2b26a6 | 3433 | ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms, |
ff6e357a | 3434 | author,score |
ef393de7 AD |
3435 | FROM |
3436 | ttrss_entries,ttrss_user_entries,ttrss_feeds | |
3437 | WHERE | |
43fc671f | 3438 | $group_limit_part |
546499a9 | 3439 | ttrss_feeds.hidden = false AND |
ef393de7 AD |
3440 | ttrss_user_entries.feed_id = ttrss_feeds.id AND |
3441 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
c36bf4d5 | 3442 | ttrss_user_entries.owner_uid = '$owner_uid' AND |
ef393de7 AD |
3443 | $search_query_part |
3444 | $view_query_part | |
3445 | $query_strategy_part ORDER BY $order_by | |
95a82c08 | 3446 | $limit_query_part $offset_query_part"; |
4bc311fc | 3447 | |
ef393de7 | 3448 | if ($_GET["debug"]) print $query; |
4bc311fc AD |
3449 | |
3450 | $result = db_query($link, $query); | |
ef393de7 AD |
3451 | |
3452 | } else { | |
3453 | // browsing by tag | |
3454 | ||
3455 | $feed_kind = "Tags"; | |
3456 | ||
3457 | $result = db_query($link, "SELECT | |
1f64b1be | 3458 | guid, |
ef393de7 | 3459 | ttrss_entries.id as id,title, |
46921916 | 3460 | updated, |
ef393de7 AD |
3461 | unread,feed_id, |
3462 | marked,link,last_read, | |
fc2b26a6 | 3463 | ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms, |
ef393de7 AD |
3464 | $vfeed_query_part |
3465 | $content_query_part | |
4d0b3607 AD |
3466 | ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms, |
3467 | score | |
ef393de7 AD |
3468 | FROM |
3469 | ttrss_entries,ttrss_user_entries,ttrss_tags | |
3470 | WHERE | |
546499a9 | 3471 | ref_id = ttrss_entries.id AND |
c36bf4d5 | 3472 | ttrss_user_entries.owner_uid = '$owner_uid' AND |
ef393de7 AD |
3473 | post_int_id = int_id AND tag_name = '$feed' AND |
3474 | $view_query_part | |
3475 | $search_query_part | |
3476 | $query_strategy_part ORDER BY $order_by | |
3477 | $limit_query_part"); | |
3478 | } | |
3479 | ||
c7188969 | 3480 | return array($result, $feed_title, $feed_site_url, $last_error); |
ef393de7 AD |
3481 | |
3482 | } | |
3483 | ||
c36bf4d5 | 3484 | function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat, |
ead2715d AD |
3485 | $limit, $search, $search_mode, $match_on) { |
3486 | ||
3487 | if (!$limit) $limit = 30; | |
18664970 AD |
3488 | |
3489 | $qfh_ret = queryFeedHeadlines($link, $feed, | |
ead2715d | 3490 | $limit, false, $is_cat, $search, $search_mode, $match_on, "updated DESC", 0, |
c36bf4d5 | 3491 | $owner_uid); |
18664970 AD |
3492 | |
3493 | $result = $qfh_ret[0]; | |
59e2aab4 | 3494 | $feed_title = htmlspecialchars($qfh_ret[1]); |
18664970 AD |
3495 | $feed_site_url = $qfh_ret[2]; |
3496 | $last_error = $qfh_ret[3]; | |
3497 | ||
a5472764 | 3498 | // if (!$feed_site_url) $feed_site_url = "http://localhost/"; |
4bc64807 | 3499 | |
a5472764 AD |
3500 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?> |
3501 | <?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\"?> | |
3502 | <rss version=\"2.0\"> | |
3baeeeca AD |
3503 | <channel> |
3504 | <title>$feed_title</title> | |
4bc64807 AD |
3505 | <link>$feed_site_url</link> |
3506 | <description>Feed generated by Tiny Tiny RSS</description>"; | |
3baeeeca AD |
3507 | |
3508 | while ($line = db_fetch_assoc($result)) { | |
3509 | print "<item>"; | |
4bc64807 | 3510 | print "<guid>" . htmlspecialchars($line["guid"]) . "</guid>"; |
3baeeeca | 3511 | print "<link>" . htmlspecialchars($line["link"]) . "</link>"; |
0c3d1c68 | 3512 | |
bc976a8c | 3513 | $tags = get_article_tags($link, $line["id"], $owner_uid); |
0c3d1c68 AD |
3514 | |
3515 | foreach ($tags as $tag) { | |
3516 | print "<category>" . htmlspecialchars($tag) . "</category>"; | |
3517 | } | |
3518 | ||
3baeeeca AD |
3519 | $rfc822_date = date('r', strtotime($line["updated"])); |
3520 | ||
3521 | print "<pubDate>$rfc822_date</pubDate>"; | |
3522 | ||
3523 | print "<title>" . | |
3524 | htmlspecialchars($line["title"]) . "</title>"; | |
3525 | ||
0c3d1c68 AD |
3526 | print "<description><![CDATA[" . |
3527 | $line["content_preview"] . "]]></description>"; | |
3baeeeca AD |
3528 | |
3529 | print "</item>"; | |
3530 | } | |
3531 | ||
3532 | print "</channel></rss>"; | |
18664970 AD |
3533 | |
3534 | } | |
3535 | ||
0a6c4846 AD |
3536 | function getCategoryTitle($link, $cat_id) { |
3537 | ||
bba7c4bf AD |
3538 | if ($cat_id == -1) { |
3539 | return __("Special"); | |
3540 | } else if ($cat_id == -2) { | |
3541 | return __("Labels"); | |
0a6c4846 | 3542 | } else { |
bba7c4bf AD |
3543 | |
3544 | $result = db_query($link, "SELECT title FROM ttrss_feed_categories WHERE | |
3545 | id = '$cat_id'"); | |
3546 | ||
3547 | if (db_num_rows($result) == 1) { | |
3548 | return db_fetch_result($result, 0, "title"); | |
3549 | } else { | |
3550 | return "Uncategorized"; | |
3551 | } | |
0a6c4846 AD |
3552 | } |
3553 | } | |
3554 | ||
f738aef1 AD |
3555 | // http://ru2.php.net/strip-tags |
3556 | ||
3557 | function strip_tags_long($textstring, $allowed){ | |
3558 | while($textstring != strip_tags($textstring, $allowed)) | |
3559 | { | |
3560 | while (strlen($textstring) != 0) | |
3561 | { | |
3562 | if (strlen($textstring) > 1024) { | |
3563 | $otherlen = 1024; | |
3564 | } else { | |
3565 | $otherlen = strlen($textstring); | |
3566 | } | |
3567 | $temptext = strip_tags(substr($textstring,0,$otherlen), $allowed); | |
3568 | $safetext .= $temptext; | |
3569 | $textstring = substr_replace($textstring,'',0,$otherlen); | |
3570 | } | |
3571 | $textstring = $safetext; | |
3572 | } | |
3573 | return $textstring; | |
3574 | } | |
3575 | ||
3576 | ||
1ac0baf4 | 3577 | function sanitize_rss($link, $str, $force_strip_tags = false) { |
60452879 | 3578 | $res = $str; |
183ad07b | 3579 | |
1ac0baf4 | 3580 | if (get_pref($link, "STRIP_UNSAFE_TAGS") || $force_strip_tags) { |
f738aef1 | 3581 | |
7e1265ed | 3582 | $res = strip_tags_long($res, |
4f376043 | 3583 | "<p><a><i><em><b><strong><code><pre><blockquote><br><img><ul><ol><li>"); |
f738aef1 AD |
3584 | |
3585 | // $res = preg_replace("/\r\n|\n|\r/", "", $res); | |
3586 | // $res = strip_tags_long($res, "<p><a><i><em><b><strong><blockquote><br><img><div><span>"); | |
f826eee1 AD |
3587 | } |
3588 | ||
8dccabed AD |
3589 | if (get_pref($link, "STRIP_IMAGES")) { |
3590 | ||
3591 | $res = preg_replace('/<img[^>]+>/is', '', $res); | |
3592 | ||
3593 | } | |
3594 | ||
183ad07b AD |
3595 | return $res; |
3596 | } | |
b72c3ef8 | 3597 | |
45004d43 AD |
3598 | /** |
3599 | * Send by mail a digest of last articles. | |
3600 | * | |
3601 | * @param mixed $link The database connection. | |
3602 | * @param integer $limit The maximum number of articles by digest. | |
3603 | * @return boolean Return false if digests are not enabled. | |
3604 | */ | |
9cd7c995 AD |
3605 | function send_headlines_digests($link, $limit = 100) { |
3606 | ||
1ddba275 AD |
3607 | if (!DIGEST_ENABLE) return false; |
3608 | ||
9cd7c995 | 3609 | $user_limit = DIGEST_EMAIL_LIMIT; |
5430c959 | 3610 | $days = 1; |
9cd7c995 AD |
3611 | |
3612 | print "Sending digests, batch of max $user_limit users, days = $days, headline limit = $limit\n\n"; | |
3613 | ||
3614 | if (DB_TYPE == "pgsql") { | |
3615 | $interval_query = "last_digest_sent < NOW() - INTERVAL '$days days'"; | |
3616 | } else if (DB_TYPE == "mysql") { | |
3617 | $interval_query = "last_digest_sent < DATE_SUB(NOW(), INTERVAL $days DAY)"; | |
3618 | } | |
3619 | ||
3620 | $result = db_query($link, "SELECT id,email FROM ttrss_users | |
3621 | WHERE email != '' AND (last_digest_sent IS NULL OR $interval_query)"); | |
3622 | ||
3623 | while ($line = db_fetch_assoc($result)) { | |
dc85be2b | 3624 | |
9cd7c995 AD |
3625 | if (get_pref($link, 'DIGEST_ENABLE', $line['id'], false)) { |
3626 | print "Sending digest for UID:" . $line['id'] . " - " . $line["email"] . " ... "; | |
3627 | ||
dc85be2b AD |
3628 | $do_catchup = get_pref($link, 'DIGEST_CATCHUP', $line['id'], false); |
3629 | ||
9cd7c995 AD |
3630 | $tuple = prepare_headlines_digest($link, $line["id"], $days, $limit); |
3631 | $digest = $tuple[0]; | |
3632 | $headlines_count = $tuple[1]; | |
dc85be2b | 3633 | $affected_ids = $tuple[2]; |
c62a2c21 | 3634 | $digest_text = $tuple[3]; |
9cd7c995 AD |
3635 | |
3636 | if ($headlines_count > 0) { | |
a8931123 | 3637 | |
c62a2c21 | 3638 | $mail = new PHPMailer(); |
a8931123 | 3639 | |
c62a2c21 AD |
3640 | $mail->PluginDir = "phpmailer/"; |
3641 | $mail->SetLanguage("en", "phpmailer/language/"); | |
a8931123 | 3642 | |
c62a2c21 | 3643 | $mail->CharSet = "UTF-8"; |
a8931123 | 3644 | |
c62a2c21 AD |
3645 | $mail->From = DIGEST_FROM_ADDRESS; |
3646 | $mail->FromName = DIGEST_FROM_NAME; | |
3647 | $mail->AddAddress($line["email"], $line["login"]); | |
c7ddac5c | 3648 | |
c62a2c21 | 3649 | if (DIGEST_SMTP_HOST) { |
a8931123 AD |
3650 | $mail->Host = DIGEST_SMTP_HOST; |
3651 | $mail->Mailer = "smtp"; | |
19a1da0d | 3652 | $mail->SMTPAuth = DIGEST_SMTP_LOGIN != ''; |
a8931123 AD |
3653 | $mail->Username = DIGEST_SMTP_LOGIN; |
3654 | $mail->Password = DIGEST_SMTP_PASSWORD; | |
c62a2c21 | 3655 | } |
a8931123 | 3656 | |
c62a2c21 | 3657 | $mail->IsHTML(true); |
163a295e | 3658 | $mail->Subject = DIGEST_SUBJECT; |
c62a2c21 AD |
3659 | $mail->Body = $digest; |
3660 | $mail->AltBody = $digest_text; | |
a8931123 | 3661 | |
c62a2c21 | 3662 | $rc = $mail->Send(); |
a8931123 | 3663 | |
c62a2c21 | 3664 | if (!$rc) print "ERROR: " . $mail->ErrorInfo; |
a8931123 | 3665 | |
9cd7c995 | 3666 | print "RC=$rc\n"; |
a8931123 | 3667 | |
c62a2c21 | 3668 | if ($rc && $do_catchup) { |
dc85be2b | 3669 | print "Marking affected articles as read...\n"; |
9968d46f | 3670 | catchupArticlesById($link, $affected_ids, 0, $line["id"]); |
dc85be2b AD |
3671 | } |
3672 | ||
9cd7c995 AD |
3673 | db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW() |
3674 | WHERE id = " . $line["id"]); | |
3675 | } else { | |
3676 | print "No headlines\n"; | |
3677 | } | |
3678 | } | |
3679 | } | |
3680 | ||
cedd3e89 AD |
3681 | print "All done.\n"; |
3682 | ||
9cd7c995 AD |
3683 | } |
3684 | ||
7e3634d9 | 3685 | function prepare_headlines_digest($link, $user_id, $days = 1, $limit = 100) { |
c62a2c21 AD |
3686 | |
3687 | require_once "MiniTemplator.class.php"; | |
3688 | ||
3689 | $tpl = new MiniTemplator; | |
3690 | $tpl_t = new MiniTemplator; | |
3691 | ||
3692 | $tpl->readTemplateFromFile("templates/digest_template_html.txt"); | |
3693 | $tpl_t->readTemplateFromFile("templates/digest_template.txt"); | |
3694 | ||
3695 | $tpl->setVariable('CUR_DATE', date('Y/m/d')); | |
3696 | $tpl->setVariable('CUR_TIME', date('G:i')); | |
3697 | ||
3698 | $tpl_t->setVariable('CUR_DATE', date('Y/m/d')); | |
3699 | $tpl_t->setVariable('CUR_TIME', date('G:i')); | |
7e3634d9 | 3700 | |
dc85be2b AD |
3701 | $affected_ids = array(); |
3702 | ||
7e3634d9 | 3703 | if (DB_TYPE == "pgsql") { |
9cd7c995 | 3704 | $interval_query = "ttrss_entries.date_entered > NOW() - INTERVAL '$days days'"; |
7e3634d9 AD |
3705 | } else if (DB_TYPE == "mysql") { |
3706 | $interval_query = "ttrss_entries.date_entered > DATE_SUB(NOW(), INTERVAL $days DAY)"; | |
3707 | } | |
3708 | ||
3709 | $result = db_query($link, "SELECT ttrss_entries.title, | |
3710 | ttrss_feeds.title AS feed_title, | |
3711 | date_entered, | |
dc85be2b | 3712 | ttrss_user_entries.ref_id, |
7e3634d9 | 3713 | link, |
c62a2c21 | 3714 | SUBSTRING(content, 1, 120) AS excerpt, |
fc2b26a6 | 3715 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
7e3634d9 AD |
3716 | FROM |
3717 | ttrss_user_entries,ttrss_entries,ttrss_feeds | |
3718 | WHERE | |
3719 | ref_id = ttrss_entries.id AND feed_id = ttrss_feeds.id | |
3dd9183c | 3720 | AND include_in_digest = true |
7e3634d9 | 3721 | AND $interval_query |
a8931123 | 3722 | AND hidden = false |
448b0abd | 3723 | AND ttrss_user_entries.owner_uid = $user_id |
c62a2c21 AD |
3724 | AND unread = true |
3725 | ORDER BY ttrss_feeds.title, date_entered DESC | |
7e3634d9 AD |
3726 | LIMIT $limit"); |
3727 | ||
3728 | $cur_feed_title = ""; | |
3729 | ||
9cd7c995 AD |
3730 | $headlines_count = db_num_rows($result); |
3731 | ||
c62a2c21 AD |
3732 | $headlines = array(); |
3733 | ||
7e3634d9 | 3734 | while ($line = db_fetch_assoc($result)) { |
c62a2c21 AD |
3735 | array_push($headlines, $line); |
3736 | } | |
3737 | ||
3738 | for ($i = 0; $i < sizeof($headlines); $i++) { | |
3739 | ||
3740 | $line = $headlines[$i]; | |
dc85be2b AD |
3741 | |
3742 | array_push($affected_ids, $line["ref_id"]); | |
3743 | ||
7e3634d9 | 3744 | $updated = smart_date_time(strtotime($line["last_updated"])); |
7e3634d9 | 3745 | |
c62a2c21 AD |
3746 | $tpl->setVariable('FEED_TITLE', $line["feed_title"]); |
3747 | $tpl->setVariable('ARTICLE_TITLE', $line["title"]); | |
3748 | $tpl->setVariable('ARTICLE_LINK', $line["link"]); | |
3749 | $tpl->setVariable('ARTICLE_UPDATED', $updated); | |
163a295e AD |
3750 | $tpl->setVariable('ARTICLE_EXCERPT', |
3751 | truncate_string(strip_tags($line["excerpt"]), 100)); | |
7e3634d9 | 3752 | |
c62a2c21 AD |
3753 | $tpl->addBlock('article'); |
3754 | ||
3755 | $tpl_t->setVariable('FEED_TITLE', $line["feed_title"]); | |
3756 | $tpl_t->setVariable('ARTICLE_TITLE', $line["title"]); | |
3757 | $tpl_t->setVariable('ARTICLE_LINK', $line["link"]); | |
3758 | $tpl_t->setVariable('ARTICLE_UPDATED', $updated); | |
3759 | // $tpl_t->setVariable('ARTICLE_EXCERPT', | |
3760 | // truncate_string(strip_tags($line["excerpt"]), 100)); | |
3761 | ||
3762 | $tpl_t->addBlock('article'); | |
3763 | ||
3764 | if ($headlines[$i]['feed_title'] != $headlines[$i+1]['feed_title']) { | |
3765 | $tpl->addBlock('feed'); | |
3766 | $tpl_t->addBlock('feed'); | |
7e3634d9 AD |
3767 | } |
3768 | ||
7e3634d9 AD |
3769 | } |
3770 | ||
c62a2c21 AD |
3771 | $tpl->addBlock('digest'); |
3772 | $tpl->generateOutputToString($tmp); | |
3773 | ||
3774 | $tpl_t->addBlock('digest'); | |
3775 | $tpl_t->generateOutputToString($tmp_t); | |
7e3634d9 | 3776 | |
c62a2c21 | 3777 | return array($tmp, $headlines_count, $affected_ids, $tmp_t); |
7e3634d9 AD |
3778 | } |
3779 | ||
d9fa39f1 | 3780 | function check_for_update($link, $brief_fmt = true) { |
b6d486a3 | 3781 | $releases_feed = "http://tt-rss.org/releases.rss"; |
b72c3ef8 AD |
3782 | |
3783 | if (!CHECK_FOR_NEW_VERSION || $_SESSION["access_level"] < 10) { | |
3784 | return; | |
3785 | } | |
3786 | ||
3787 | error_reporting(0); | |
f67d9754 AD |
3788 | if (ENABLE_SIMPLEPIE) { |
3789 | $rss = new SimplePie(); | |
3790 | $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT); | |
4148e809 | 3791 | // $rss->set_timeout(MAGPIE_FETCH_TIME_OUT); |
f67d9754 AD |
3792 | $rss->set_feed_url($fetch_url); |
3793 | $rss->set_output_encoding('UTF-8'); | |
3794 | $rss->init(); | |
3795 | } else { | |
3796 | $rss = fetch_rss($releases_feed); | |
3797 | } | |
b72c3ef8 AD |
3798 | error_reporting (DEFAULT_ERROR_LEVEL); |
3799 | ||
3800 | if ($rss) { | |
3801 | ||
f67d9754 AD |
3802 | if (ENABLE_SIMPLEPIE) { |
3803 | $items = $rss->get_items(); | |
3804 | } else { | |
3805 | $items = $rss->items; | |
b72c3ef8 | 3806 | |
f67d9754 AD |
3807 | if (!$items || !is_array($items)) $items = $rss->entries; |
3808 | if (!$items || !is_array($items)) $items = $rss; | |
3809 | } | |
b72c3ef8 | 3810 | |
da412ad3 | 3811 | if (!is_array($items) || count($items) == 0) { |
b72c3ef8 | 3812 | return; |
da412ad3 | 3813 | } |
b72c3ef8 | 3814 | |
a41d2c65 | 3815 | $latest_item = $items[0]; |
b72c3ef8 | 3816 | |
f67d9754 AD |
3817 | if (ENABLE_SIMPLEPIE) { |
3818 | $last_title = $latest_item->get_title(); | |
3819 | } else { | |
3820 | $last_title = $latest_item["title"]; | |
3821 | } | |
b72c3ef8 | 3822 | |
f67d9754 AD |
3823 | $latest_version = trim(preg_replace("/(Milestone)|(completed)/", "", $last_title)); |
3824 | ||
3825 | if (ENABLE_SIMPLEPIE) { | |
dcf7fd08 AD |
3826 | $release_url = sanitize_rss($link, $latest_item->get_link()); |
3827 | $content = sanitize_rss($link, $latest_item->get_description()); | |
f67d9754 AD |
3828 | } else { |
3829 | $release_url = sanitize_rss($link, $latest_item["link"]); | |
3830 | $content = sanitize_rss($link, $latest_item["description"]); | |
3831 | } | |
48e1a342 | 3832 | |
a41d2c65 | 3833 | if (version_compare(VERSION, $latest_version) == -1) { |
d9fa39f1 | 3834 | if ($brief_fmt) { |
0d32b41e | 3835 | return format_notice("<a href=\"javascript:showBlockElement('milestoneDetails')\"> |
d9fa39f1 | 3836 | New version of Tiny-Tiny RSS ($latest_version) is available (click for details)</a> |
0d32b41e | 3837 | <div id=\"milestoneDetails\">$content</div>"); |
d9fa39f1 | 3838 | } else { |
92625568 AD |
3839 | return "New version of Tiny-Tiny RSS ($latest_version) is available: |
3840 | <div class='milestoneDetails'>$content</div> | |
b6d486a3 | 3841 | Visit <a target=\"_blank\" href=\"http://tt-rss.org/\">official site</a> for |
92625568 | 3842 | download and update information."; |
d9fa39f1 AD |
3843 | } |
3844 | ||
da412ad3 | 3845 | } |
b72c3ef8 AD |
3846 | } |
3847 | } | |
472782e8 | 3848 | |
18eddb2c AD |
3849 | function markArticlesById($link, $ids, $cmode) { |
3850 | ||
3851 | $tmp_ids = array(); | |
3852 | ||
3853 | foreach ($ids as $id) { | |
3854 | array_push($tmp_ids, "ref_id = '$id'"); | |
3855 | } | |
3856 | ||
3857 | $ids_qpart = join(" OR ", $tmp_ids); | |
3858 | ||
3859 | if ($cmode == 0) { | |
3860 | db_query($link, "UPDATE ttrss_user_entries SET | |
3861 | marked = false,last_read = NOW() | |
3862 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3863 | } else if ($cmode == 1) { | |
3864 | db_query($link, "UPDATE ttrss_user_entries SET | |
3865 | marked = true | |
3866 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3867 | } else { | |
3868 | db_query($link, "UPDATE ttrss_user_entries SET | |
3869 | marked = NOT marked,last_read = NOW() | |
3870 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3871 | } | |
3872 | } | |
3873 | ||
e4f4b46f AD |
3874 | function publishArticlesById($link, $ids, $cmode) { |
3875 | ||
3876 | $tmp_ids = array(); | |
3877 | ||
3878 | foreach ($ids as $id) { | |
3879 | array_push($tmp_ids, "ref_id = '$id'"); | |
3880 | } | |
3881 | ||
3882 | $ids_qpart = join(" OR ", $tmp_ids); | |
3883 | ||
3884 | if ($cmode == 0) { | |
3885 | db_query($link, "UPDATE ttrss_user_entries SET | |
3886 | published = false,last_read = NOW() | |
3887 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3888 | } else if ($cmode == 1) { | |
3889 | db_query($link, "UPDATE ttrss_user_entries SET | |
3890 | published = true | |
3891 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3892 | } else { | |
3893 | db_query($link, "UPDATE ttrss_user_entries SET | |
3894 | published = NOT published,last_read = NOW() | |
3895 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3896 | } | |
3897 | } | |
3898 | ||
9968d46f AD |
3899 | function catchupArticlesById($link, $ids, $cmode, $owner_uid = false) { |
3900 | ||
3901 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
472782e8 AD |
3902 | |
3903 | $tmp_ids = array(); | |
3904 | ||
3905 | foreach ($ids as $id) { | |
3906 | array_push($tmp_ids, "ref_id = '$id'"); | |
3907 | } | |
3908 | ||
3909 | $ids_qpart = join(" OR ", $tmp_ids); | |
3910 | ||
3911 | if ($cmode == 0) { | |
3912 | db_query($link, "UPDATE ttrss_user_entries SET | |
3913 | unread = false,last_read = NOW() | |
9968d46f | 3914 | WHERE ($ids_qpart) AND owner_uid = $owner_uid"); |
472782e8 AD |
3915 | } else if ($cmode == 1) { |
3916 | db_query($link, "UPDATE ttrss_user_entries SET | |
3917 | unread = true | |
9968d46f | 3918 | WHERE ($ids_qpart) AND owner_uid = $owner_uid"); |
472782e8 AD |
3919 | } else { |
3920 | db_query($link, "UPDATE ttrss_user_entries SET | |
3921 | unread = NOT unread,last_read = NOW() | |
9968d46f | 3922 | WHERE ($ids_qpart) AND owner_uid = $owner_uid"); |
472782e8 | 3923 | } |
0737b95a AD |
3924 | |
3925 | /* update ccache */ | |
3926 | ||
3927 | $result = db_query($link, "SELECT DISTINCT feed_id FROM ttrss_user_entries | |
3928 | WHERE ($ids_qpart) AND owner_uid = $owner_uid"); | |
3929 | ||
3930 | while ($line = db_fetch_assoc($result)) { | |
3931 | ccache_update($link, $line["feed_id"], $owner_uid); | |
3932 | } | |
472782e8 AD |
3933 | } |
3934 | ||
e097e8be AD |
3935 | function catchupArticleById($link, $id, $cmode) { |
3936 | ||
3937 | if ($cmode == 0) { | |
3938 | db_query($link, "UPDATE ttrss_user_entries SET | |
3939 | unread = false,last_read = NOW() | |
3940 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
3941 | } else if ($cmode == 1) { | |
3942 | db_query($link, "UPDATE ttrss_user_entries SET | |
3943 | unread = true | |
3944 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
3945 | } else { | |
3946 | db_query($link, "UPDATE ttrss_user_entries SET | |
3947 | unread = NOT unread,last_read = NOW() | |
3948 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
3949 | } | |
3950 | } | |
3951 | ||
1f64b1be AD |
3952 | function make_guid_from_title($title) { |
3953 | return preg_replace("/[ \"\',.:;]/", "-", | |
fefef828 | 3954 | mb_strtolower(strip_tags($title), 'utf-8')); |
1f64b1be AD |
3955 | } |
3956 | ||
11befbb2 AD |
3957 | function print_headline_subtoolbar($link, $feed_site_url, $feed_title, |
3958 | $bottom = false, $rtl_content = false, $feed_id = 0, | |
3959 | $is_cat = false, $search = false, $match_on = false, | |
1681df97 AD |
3960 | $search_mode = false, $offset = 0, $limit = 0, |
3961 | $dashboard_menu = 0, $disable_feed = 0, $feed_small_icon = 0) { | |
11befbb2 | 3962 | |
e6c115b2 AD |
3963 | $user_page_offset = $offset + 1; |
3964 | ||
11befbb2 AD |
3965 | if (!$bottom) { |
3966 | $class = "headlinesSubToolbar"; | |
3967 | $tid = "headlineActionsTop"; | |
3968 | } else { | |
3969 | $class = "headlinesSubToolbar"; | |
3970 | $tid = "headlineActionsBottom"; | |
3971 | } | |
3972 | ||
ecf2a265 | 3973 | print "<nobr><table class=\"$class\" id=\"$tid\" |
11befbb2 AD |
3974 | width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>"; |
3975 | ||
3976 | if ($rtl_content) { | |
3977 | $rtl_cpart = "RTL"; | |
3978 | } else { | |
3979 | $rtl_cpart = ""; | |
3980 | } | |
3981 | ||
e6c115b2 AD |
3982 | $page_prev_link = "javascript:viewFeedGoPage(-1)"; |
3983 | $page_next_link = "javascript:viewFeedGoPage(1)"; | |
3984 | $page_first_link = "javascript:viewFeedGoPage(0)"; | |
203de776 | 3985 | |
eb28b131 AD |
3986 | $catchup_page_link = "javascript:catchupPage()"; |
3987 | $catchup_feed_link = "javascript:catchupCurrentFeed()"; | |
a5ae125a | 3988 | $catchup_sel_link = "javascript:catchupSelection()"; |
c6008b62 | 3989 | |
11befbb2 AD |
3990 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { |
3991 | ||
c6008b62 AD |
3992 | $sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)"; |
3993 | $sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)"; | |
3994 | $sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)"; | |
e75d70b5 | 3995 | $sel_inv_link = "javascript:invertHeadlineSelection()"; |
11befbb2 | 3996 | |
c6008b62 AD |
3997 | $tog_unread_link = "javascript:selectionToggleUnread()"; |
3998 | $tog_marked_link = "javascript:selectionToggleMarked()"; | |
e4f4b46f | 3999 | $tog_published_link = "javascript:selectionTogglePublished()"; |
11befbb2 | 4000 | |
c6008b62 | 4001 | } else { |
11befbb2 | 4002 | |
c6008b62 AD |
4003 | $sel_all_link = "javascript:cdmSelectArticles('all')"; |
4004 | $sel_unread_link = "javascript:cdmSelectArticles('unread')"; | |
4005 | $sel_none_link = "javascript:cdmSelectArticles('none')"; | |
4006 | ||
e75d70b5 AD |
4007 | $sel_inv_link = "javascript:invertHeadlineSelection()"; |
4008 | ||
c6008b62 AD |
4009 | $tog_unread_link = "javascript:selectionToggleUnread(true)"; |
4010 | $tog_marked_link = "javascript:selectionToggleMarked(true)"; | |
e4f4b46f | 4011 | $tog_published_link = "javascript:selectionTogglePublished(true)"; |
c6008b62 AD |
4012 | |
4013 | } | |
4014 | ||
1681df97 | 4015 | if (strpos($_SESSION["client.userAgent"], "MSIE") === false) { |
6cfa22dc | 4016 | |
1681df97 | 4017 | print "<td class=\"headlineActions$rtl_cpart\"> |
6cfa22dc AD |
4018 | <ul class=\"headlineDropdownMenu\"> |
4019 | <li class=\"top2\"> | |
4020 | ".__('Select:')." | |
4021 | <a href=\"$sel_all_link\">".__('All')."</a>, | |
4022 | <a href=\"$sel_unread_link\">".__('Unread')."</a>, | |
e75d70b5 | 4023 | <a href=\"$sel_inv_link\">".__('Invert')."</a>, |
6cfa22dc AD |
4024 | <a href=\"$sel_none_link\">".__('None')."</a></li> |
4025 | <li class=\"vsep\"> </li> | |
4026 | <li class=\"top\">".__('Actions...')."<ul> | |
4027 | <li><span class=\"insensitive\">".__('Selection toggle:')."</span></li> | |
4028 | <li onclick=\"$tog_unread_link\"> ".__('Unread')."</li> | |
4029 | <li onclick=\"$tog_marked_link\"> ".__('Starred')."</li> | |
4030 | <li onclick=\"$tog_published_link\"> ".__('Published')."</li> | |
eee80a87 | 4031 | <li><span class=\"insensitive\">--------</span></li> |
6cfa22dc AD |
4032 | <li><span class=\"insensitive\">".__('Mark as read:')."</span></li> |
4033 | <li onclick=\"$catchup_sel_link\"> ".__('Selection')."</li>"; | |
4034 | ||
6cfa22dc AD |
4035 | /* if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { |
4036 | ||
4037 | print " | |
4038 | <li onclick=\"catchupRelativeToArticle(0)\"> ".__("Above active article")."</li> | |
4039 | <li onclick=\"catchupRelativeToArticle(1)\"> ".__("Below active article")."</li>"; | |
4040 | } else { | |
4041 | print " | |
4042 | <li><span class=\"insensitive\"> ".__("Above active article")."</span></li> | |
4043 | <li><span class=\"insensitive\"> ".__("Below active article")."</span></li>"; | |
4044 | ||
4045 | } */ | |
4046 | ||
4047 | print "<li onclick=\"$catchup_feed_link\"> ".__('Entire feed')."</li>"; | |
4048 | ||
eee80a87 | 4049 | print "<li><span class=\"insensitive\">--------</span></li>"; |
6cfa22dc AD |
4050 | print "<li><span class=\"insensitive\">".__('Other actions:')."</span></li>"; |
4051 | ||
4052 | ||
4053 | if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) { | |
4054 | print " | |
4055 | <li onclick=\"javascript:labelFromSearch('$search', '$search_mode', | |
4056 | '$match_on', '$feed_id', '$is_cat');\"> | |
4057 | ".__('Search to label')."</li>"; | |
4058 | } else { | |
4059 | print "<li><span class=\"insensitive\"> ".__('Search to label')."</li>"; | |
4060 | ||
4061 | } | |
4062 | ||
4063 | print "</ul></li></ul>"; | |
ff284aa0 | 4064 | print "</td>"; |
1681df97 AD |
4065 | |
4066 | } else { | |
ff284aa0 | 4067 | // old style subtoolbar: |
1681df97 AD |
4068 | |
4069 | print "<td class=\"headlineActions$rtl_cpart\">". | |
4070 | __('Select:')." | |
4071 | <a href=\"$sel_all_link\">".__('All')."</a>, | |
4072 | <a href=\"$sel_unread_link\">".__('Unread')."</a>, | |
4073 | <a href=\"$sel_none_link\">".__('None')."</a> | |
4074 | ". | |
4075 | __('Toggle:')." <a href=\"$tog_unread_link\">".__('Unread')."</a>, | |
4076 | <a href=\"$tog_marked_link\">".__('Starred')."</a> | |
4077 | ". | |
4078 | __('Mark as read:')." | |
4079 | <a href=\"#\" onclick=\"$catchup_page_link\">".__('Page')."</a>, | |
4080 | <a href=\"#\" onclick=\"$catchup_feed_link\">".__('Feed')."</a>"; | |
4081 | ||
d420f2ee | 4082 | if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) { |
1681df97 AD |
4083 | |
4084 | print " | |
4085 | <a href=\"javascript:labelFromSearch('$search', '$search_mode', | |
4086 | '$match_on', '$feed_id', '$is_cat');\"> | |
4087 | ".__('Convert to label')."</a>"; | |
d420f2ee | 4088 | } |
1681df97 AD |
4089 | |
4090 | print "</td>"; | |
4091 | ||
d420f2ee | 4092 | } |
c6008b62 | 4093 | |
11befbb2 | 4094 | print "<td class=\"headlineTitle$rtl_cpart\">"; |
11befbb2 | 4095 | |
7a822893 | 4096 | print "<span id=\"subtoolbar_search\" |
abe6d934 | 4097 | style=\"display : none\"><input |
7a822893 AD |
4098 | id=\"subtoolbar_search_box\" |
4099 | onblur=\"javascript:enableHotkeys();\" | |
4100 | onfocus=\"javascript:disableHotkeys();\" | |
4101 | onchange=\"subtoolbarSearch()\" | |
4102 | onkeyup=\"subtoolbarSearch()\" type=\"search\"></span>"; | |
4103 | ||
4104 | print "<span id=\"subtoolbar_ftitle\">"; | |
11befbb2 | 4105 | |
b27967ac AD |
4106 | if ($feed_site_url) { |
4107 | if (!$bottom) { | |
e944346c | 4108 | $target = "target=\"_blank\""; |
20361063 | 4109 | } |
b27967ac AD |
4110 | print "<a $target href=\"$feed_site_url\">". |
4111 | truncate_string($feed_title,30)."</a>"; | |
4112 | } else { | |
4113 | print $feed_title; | |
4114 | } | |
4115 | ||
4116 | if ($search) { | |
4117 | $search_q = "&q=$search&m=$match_on&smode=$search_mode"; | |
e6c115b2 AD |
4118 | } |
4119 | ||
b27967ac AD |
4120 | if ($user_page_offset > 1) { |
4121 | print " [$user_page_offset] "; | |
4122 | } | |
4123 | ||
1681df97 | 4124 | if (!$bottom && !$disable_feed) { |
e6c115b2 | 4125 | print " |
e944346c | 4126 | <a target=\"_blank\" |
11befbb2 AD |
4127 | href=\"backend.php?op=rss&id=$feed_id&is_cat=$is_cat$search_q\"> |
4128 | <img class=\"noborder\" | |
1025ad87 | 4129 | alt=\"".__('Generated feed')."\" src=\"images/feed-icon-12x12.png\"> |
11befbb2 | 4130 | </a>"; |
1681df97 AD |
4131 | } else if ($feed_small_icon) { |
4132 | print "<img class=\"noborder\" alt=\"\" src=\"images/$feed_small_icon\">"; | |
11befbb2 | 4133 | } |
7a822893 AD |
4134 | |
4135 | print "</span>"; | |
4136 | ||
11befbb2 | 4137 | print "</td>"; |
ecf2a265 | 4138 | print "</tr></table></nobr>"; |
11befbb2 AD |
4139 | |
4140 | } | |
4141 | ||
bba7c4bf AD |
4142 | function printCategoryHeader($link, $cat_id, $hidden = false, $can_browse = true) { |
4143 | ||
4144 | $tmp_category = getCategoryTitle($link, $cat_id); | |
cc914918 AD |
4145 | |
4146 | if ($cat_id > 0) { | |
4147 | $cat_unread = ccache_find($link, $cat_id, $_SESSION["uid"], true); | |
4148 | } else { | |
4149 | $cat_unread = getCategoryUnread($link, $cat_id); | |
4150 | } | |
bba7c4bf AD |
4151 | |
4152 | if ($hidden) { | |
4153 | $holder_style = "display:none;"; | |
66a251f9 | 4154 | $ellipsis = "…"; |
bba7c4bf AD |
4155 | } else { |
4156 | $holder_style = ""; | |
4157 | $ellipsis = ""; | |
4158 | } | |
4159 | ||
4160 | $catctr_class = ($cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread"; | |
4161 | ||
bba7c4bf | 4162 | if ($can_browse) { |
4c41e58f AD |
4163 | $browse_cat_link = "onclick=\"javascript:viewCategory($cat_id)\""; |
4164 | $inner_title_class = "catTitle"; | |
bba7c4bf | 4165 | } else { |
4c41e58f AD |
4166 | $browse_cat_link = ""; |
4167 | $inner_title_class = "catTitleNL"; | |
bba7c4bf AD |
4168 | } |
4169 | ||
3d72bbdb | 4170 | if ($cat_id >= 0) { |
364e391e AD |
4171 | $cat_class = "feedCat"; |
4172 | } else { | |
4173 | $cat_class = "virtCat"; | |
4174 | } | |
4175 | ||
4176 | print "<li class=\"$cat_class\" id=\"FCAT-$cat_id\"> | |
98fb6193 | 4177 | <img onclick=\"toggleCollapseCat($cat_id)\" class=\"catCollapse\" |
4c41e58f AD |
4178 | title=\"".__('Click to collapse category')."\" |
4179 | src=\"images/cat-collapse.png\"><span class=\"$inner_title_class\" | |
4180 | id=\"FCATN-$cat_id\" $browse_cat_link | |
4181 | \">$tmp_category</span>"; | |
4182 | ||
4183 | print "<span id=\"FCAP-$cat_id\">"; | |
4184 | ||
dda1396f | 4185 | print " <span id=\"FCATCTR-$cat_id\" |
bba7c4bf AD |
4186 | class=\"$catctr_class\">($cat_unread)</span> $ellipsis"; |
4187 | ||
4c41e58f | 4188 | print "</span>"; |
bba7c4bf | 4189 | |
782ddd70 | 4190 | //print "</li>"; |
bba7c4bf | 4191 | |
60ea2377 | 4192 | print "<ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\" style='$holder_style'>"; |
7abee14f | 4193 | |
bba7c4bf AD |
4194 | } |
4195 | ||
f407c086 AD |
4196 | function outputFeedList($link, $tags = false) { |
4197 | ||
3bd9a780 | 4198 | print "<ul class=\"feedList\" id=\"feedList\">"; |
f407c086 AD |
4199 | |
4200 | $owner_uid = $_SESSION["uid"]; | |
4201 | ||
cf4d339c | 4202 | /* virtual feeds */ |
f407c086 | 4203 | |
cf4d339c | 4204 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
3b086176 AD |
4205 | |
4206 | if ($_COOKIE["ttrss_vf_vclps"] == 1) { | |
bba7c4bf | 4207 | $cat_hidden = true; |
3b086176 | 4208 | } else { |
bba7c4bf | 4209 | $cat_hidden = false; |
3b086176 AD |
4210 | } |
4211 | ||
bba7c4bf | 4212 | printCategoryHeader($link, -1, $cat_hidden, false); |
cf4d339c | 4213 | } |
f407c086 | 4214 | |
cf4d339c | 4215 | $num_starred = getFeedUnread($link, -1); |
e4f4b46f | 4216 | $num_published = getFeedUnread($link, -2); |
2d24f032 AD |
4217 | $num_fresh = getFeedUnread($link, -3); |
4218 | ||
4219 | $class = "virt"; | |
4220 | ||
4221 | if ($num_fresh > 0) $class .= "Unread"; | |
4222 | ||
4223 | printFeedEntry(-3, $class, __("Fresh articles"), $num_fresh, | |
4224 | "images/fresh.png", $link); | |
f407c086 | 4225 | |
cf4d339c | 4226 | $class = "virt"; |
f407c086 | 4227 | |
cf4d339c | 4228 | if ($num_starred > 0) $class .= "Unread"; |
f407c086 | 4229 | |
abd8a516 AD |
4230 | $is_ie = (strpos($_SESSION["client.userAgent"], "MSIE") !== false); |
4231 | ||
4232 | if ($is_ie) { | |
4233 | $mark_img_ext = "gif"; | |
4234 | } else { | |
4235 | $mark_img_ext = "png"; | |
4236 | } | |
4237 | ||
d1db26aa | 4238 | printFeedEntry(-1, $class, __("Starred articles"), $num_starred, |
abd8a516 | 4239 | "images/mark_set.$mark_img_ext", $link); |
f407c086 | 4240 | |
e4f4b46f AD |
4241 | $class = "virt"; |
4242 | ||
4243 | if ($num_published > 0) $class .= "Unread"; | |
4244 | ||
4245 | printFeedEntry(-2, $class, __("Published articles"), $num_published, | |
f5e0338d | 4246 | "images/pub_set.gif", $link); |
e4f4b46f | 4247 | |
cf4d339c | 4248 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
8b803aa2 | 4249 | print "</ul></li>"; |
cf4d339c | 4250 | } |
f407c086 | 4251 | |
cf4d339c | 4252 | if (!$tags) { |
f407c086 AD |
4253 | |
4254 | if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) { | |
4255 | ||
4256 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
4257 | ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description"); | |
4258 | ||
4259 | if (db_num_rows($result) > 0) { | |
4260 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
bd64489f AD |
4261 | |
4262 | if ($_COOKIE["ttrss_vf_lclps"] == 1) { | |
bba7c4bf | 4263 | $cat_hidden = true; |
bd64489f | 4264 | } else { |
bba7c4bf | 4265 | $cat_hidden = false; |
bd64489f AD |
4266 | } |
4267 | ||
bba7c4bf | 4268 | printCategoryHeader($link, -2, $cat_hidden, false); |
bd64489f | 4269 | |
f407c086 | 4270 | } else { |
3bd9a780 | 4271 | print "<li><hr></li>"; |
f407c086 AD |
4272 | } |
4273 | } | |
4274 | ||
4275 | while ($line = db_fetch_assoc($result)) { | |
4276 | ||
4277 | error_reporting (0); | |
4278 | ||
4279 | $label_id = -$line['id'] - 11; | |
4280 | $count = getFeedUnread($link, $label_id); | |
4281 | ||
4282 | $class = "label"; | |
4283 | ||
4284 | if ($count > 0) { | |
4285 | $class .= "Unread"; | |
4286 | } | |
4287 | ||
4288 | error_reporting (DEFAULT_ERROR_LEVEL); | |
4289 | ||
4290 | printFeedEntry($label_id, | |
47439031 | 4291 | $class, $line["description"], |
f407c086 AD |
4292 | $count, "images/label.png", $link); |
4293 | ||
4294 | } | |
4295 | ||
4296 | if (db_num_rows($result) > 0) { | |
4297 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
4298 | print "</ul>"; | |
4299 | } | |
4300 | } | |
4301 | ||
4302 | } | |
4303 | ||
4304 | if (!get_pref($link, 'ENABLE_FEED_CATS')) { | |
3bd9a780 | 4305 | print "<li><hr></li>"; |
f407c086 AD |
4306 | } |
4307 | ||
4308 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
4309 | if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) { | |
9d393c84 | 4310 | $order_by_qpart = "order_id,category,unread DESC,title"; |
f407c086 | 4311 | } else { |
9d393c84 | 4312 | $order_by_qpart = "order_id,category,title"; |
f407c086 AD |
4313 | } |
4314 | } else { | |
4315 | if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) { | |
4316 | $order_by_qpart = "unread DESC,title"; | |
4317 | } else { | |
4318 | $order_by_qpart = "title"; | |
4319 | } | |
4320 | } | |
4321 | ||
14073c0a AD |
4322 | $age_qpart = getMaxAgeSubquery(); |
4323 | ||
99509451 | 4324 | $query = "SELECT ttrss_feeds.*, |
fc2b26a6 | 4325 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms, |
f407c086 AD |
4326 | cat_id,last_error, |
4327 | ttrss_feed_categories.title AS category, | |
4328 | ttrss_feed_categories.collapsed | |
4329 | FROM ttrss_feeds LEFT JOIN ttrss_feed_categories | |
4330 | ON (ttrss_feed_categories.id = cat_id) | |
4331 | WHERE | |
4332 | ttrss_feeds.hidden = false AND | |
4333 | ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL | |
99509451 AD |
4334 | ORDER BY $order_by_qpart"; |
4335 | ||
4336 | $result = db_query($link, $query); | |
f407c086 AD |
4337 | |
4338 | $actid = $_GET["actid"]; | |
4339 | ||
4340 | /* real feeds */ | |
4341 | ||
4342 | $lnum = 0; | |
4343 | ||
4344 | $total_unread = 0; | |
4345 | ||
4346 | $category = ""; | |
4347 | ||
4348 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
4349 | ||
4350 | while ($line = db_fetch_assoc($result)) { | |
4351 | ||
47439031 | 4352 | $feed = trim($line["title"]); |
0f39ae20 AD |
4353 | |
4354 | if (!$feed) $feed = "[Untitled]"; | |
4355 | ||
f407c086 AD |
4356 | $feed_id = $line["id"]; |
4357 | ||
4358 | $subop = $_GET["subop"]; | |
4359 | ||
8a4c759e | 4360 | $unread = ccache_find($link, $feed_id, $_SESSION["uid"]); |
f407c086 AD |
4361 | |
4362 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
4363 | $last_updated = smart_date_time(strtotime($line["last_updated_noms"])); | |
4364 | } else { | |
4365 | $last_updated = date($short_date, strtotime($line["last_updated_noms"])); | |
4366 | } | |
4367 | ||
4368 | $rtl_content = sql_bool_to_bool($line["rtl_content"]); | |
4369 | ||
4370 | if ($rtl_content) { | |
4371 | $rtl_tag = "dir=\"RTL\""; | |
4372 | } else { | |
4373 | $rtl_tag = ""; | |
4374 | } | |
4375 | ||
4376 | $tmp_result = db_query($link, | |
de0a2122 AD |
4377 | "SELECT SUM(value) AS unread FROM ttrss_feeds, ttrss_counters_cache |
4378 | WHERE parent_feed = '$feed_id' AND feed_id = id"); | |
f407c086 | 4379 | |
de0a2122 AD |
4380 | $unread += db_fetch_result($tmp_result, 0, "unread"); |
4381 | ||
f407c086 AD |
4382 | $cat_id = $line["cat_id"]; |
4383 | ||
4384 | $tmp_category = $line["category"]; | |
4385 | ||
4386 | if (!$tmp_category) { | |
d1db26aa | 4387 | $tmp_category = __("Uncategorized"); |
f407c086 AD |
4388 | } |
4389 | ||
4390 | // $class = ($lnum % 2) ? "even" : "odd"; | |
4391 | ||
4392 | if ($line["last_error"]) { | |
4393 | $class = "error"; | |
4394 | } else { | |
4395 | $class = "feed"; | |
4396 | } | |
4397 | ||
4398 | if ($unread > 0) $class .= "Unread"; | |
4399 | ||
4400 | if ($actid == $feed_id) { | |
4401 | $class .= "Selected"; | |
4402 | } | |
4403 | ||
4404 | $total_unread += $unread; | |
4405 | ||
4406 | if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) { | |
4407 | ||
4408 | if ($category) { | |
8b803aa2 | 4409 | print "</ul></li>"; |
f407c086 AD |
4410 | } |
4411 | ||
4412 | $category = $tmp_category; | |
4413 | ||
7abee14f | 4414 | $collapsed = sql_bool_to_bool($line["collapsed"]); |
f407c086 AD |
4415 | |
4416 | // workaround for NULL category | |
d1db26aa | 4417 | if ($category == __("Uncategorized")) { |
f407c086 AD |
4418 | if ($_COOKIE["ttrss_vf_uclps"] == 1) { |
4419 | $collapsed = "t"; | |
4420 | } | |
4421 | } | |
4422 | ||
f407c086 AD |
4423 | $cat_id = sprintf("%d", $cat_id); |
4424 | ||
7abee14f AD |
4425 | printCategoryHeader($link, $cat_id, $collapsed, true); |
4426 | ||
f407c086 AD |
4427 | } |
4428 | ||
4429 | printFeedEntry($feed_id, $class, $feed, $unread, | |
68dcbd31 | 4430 | ICONS_URL."/$feed_id.ico", $link, $rtl_content, |
f407c086 AD |
4431 | $last_updated, $line["last_error"]); |
4432 | ||
4433 | ++$lnum; | |
4434 | } | |
4435 | ||
4436 | if (db_num_rows($result) == 0) { | |
3bd9a780 | 4437 | print "<li>".__('No feeds to display.')."</li>"; |
f407c086 AD |
4438 | } |
4439 | ||
4440 | } else { | |
4441 | ||
4442 | // tags | |
4443 | ||
4444 | /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
4445 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE | |
4446 | post_int_id = ttrss_user_entries.int_id AND | |
4447 | unread = true AND ref_id = ttrss_entries.id | |
4448 | AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name | |
4449 | UNION | |
4450 | select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid' | |
4451 | ORDER BY tag_name"); */ | |
4452 | ||
4453 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
d1db26aa | 4454 | print "<li class=\"feedCat\">".__('Tags')."</li>"; |
60ea2377 | 4455 | print "<ul class=\"feedCatList\">"; |
f407c086 AD |
4456 | } |
4457 | ||
14073c0a AD |
4458 | $age_qpart = getMaxAgeSubquery(); |
4459 | ||
f407c086 | 4460 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) |
14073c0a AD |
4461 | FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id |
4462 | AND ref_id = id AND $age_qpart | |
f407c086 | 4463 | AND unread = true)) AS count FROM ttrss_tags |
ef1ac7c7 AD |
4464 | WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name |
4465 | ORDER BY count DESC LIMIT 50"); | |
f407c086 AD |
4466 | |
4467 | $tags = array(); | |
4468 | ||
4469 | while ($line = db_fetch_assoc($result)) { | |
4470 | $tags[$line["tag_name"]] += $line["count"]; | |
4471 | } | |
4472 | ||
4473 | foreach (array_keys($tags) as $tag) { | |
4474 | ||
4475 | $unread = $tags[$tag]; | |
4476 | ||
4477 | $class = "tag"; | |
4478 | ||
4479 | if ($unread > 0) { | |
4480 | $class .= "Unread"; | |
4481 | } | |
4482 | ||
4483 | printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link); | |
4484 | ||
4485 | } | |
4486 | ||
4487 | if (db_num_rows($result) == 0) { | |
4488 | print "<li>No tags to display.</li>"; | |
4489 | } | |
4490 | ||
4491 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
3bd9a780 | 4492 | print "</ul>"; |
f407c086 AD |
4493 | } |
4494 | ||
4495 | } | |
4496 | ||
4497 | print "</ul>"; | |
4498 | ||
4499 | } | |
4500 | ||
bc976a8c | 4501 | function get_article_tags($link, $id, $owner_uid = 0) { |
0b126ac2 AD |
4502 | |
4503 | $a_id = db_escape_string($id); | |
4504 | ||
bc976a8c AD |
4505 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
4506 | ||
0c3d1c68 AD |
4507 | $tmp_result = db_query($link, "SELECT DISTINCT tag_name, |
4508 | owner_uid as owner FROM | |
0b126ac2 | 4509 | ttrss_tags WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE |
bc976a8c | 4510 | ref_id = '$a_id' AND owner_uid = '$owner_uid' LIMIT 1) ORDER BY tag_name"); |
0b126ac2 AD |
4511 | |
4512 | $tags = array(); | |
4513 | ||
4514 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
4515 | array_push($tags, $tmp_line["tag_name"]); | |
4516 | } | |
4517 | ||
4518 | return $tags; | |
4519 | } | |
4520 | ||
d62a3b63 AD |
4521 | function trim_value(&$value) { |
4522 | $value = trim($value); | |
4523 | } | |
4524 | ||
4525 | function trim_array($array) { | |
4526 | $tmp = $array; | |
4527 | array_walk($tmp, 'trim_value'); | |
4528 | return $tmp; | |
4529 | } | |
4530 | ||
be832a1a | 4531 | function tag_is_valid($tag) { |
ef063748 AD |
4532 | if ($tag == '') return false; |
4533 | if (preg_match("/^[0-9]*$/", $tag)) return false; | |
4534 | ||
31365729 AD |
4535 | if (function_exists('iconv')) { |
4536 | $tag = iconv("utf-8", "utf-8", $tag); | |
4537 | } | |
4538 | ||
ef063748 AD |
4539 | if (!$tag) return false; |
4540 | ||
4541 | return true; | |
be832a1a AD |
4542 | } |
4543 | ||
793185a9 AD |
4544 | function render_login_form($link, $mobile = false) { |
4545 | if (!$mobile) { | |
4546 | require_once "login_form.php"; | |
4547 | } else { | |
4548 | require_once "mobile/login_form.php"; | |
4549 | } | |
01a87dff AD |
4550 | } |
4551 | ||
dc56b3b7 AD |
4552 | // from http://developer.apple.com/internet/safari/faq.html |
4553 | function no_cache_incantation() { | |
4554 | header("Expires: Mon, 22 Dec 1980 00:00:00 GMT"); // Happy birthday to me :) | |
4555 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified | |
4556 | header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1 | |
4557 | header("Cache-Control: post-check=0, pre-check=0", false); | |
4558 | header("Pragma: no-cache"); // HTTP/1.0 | |
4559 | } | |
4560 | ||
42395d28 AD |
4561 | function format_warning($msg, $id = "") { |
4562 | return "<div class=\"warning\" id=\"$id\"> | |
e780d1d2 | 4563 | <img src=\"images/sign_excl.gif\">$msg</div>"; |
0d32b41e AD |
4564 | } |
4565 | ||
4566 | function format_notice($msg) { | |
4567 | return "<div class=\"notice\"> | |
e780d1d2 | 4568 | <img src=\"images/sign_info.gif\">$msg</div>"; |
0d32b41e AD |
4569 | } |
4570 | ||
68d2f95e AD |
4571 | function format_error($msg) { |
4572 | return "<div class=\"error\"> | |
e780d1d2 | 4573 | <img src=\"images/sign_excl.gif\">$msg</div>"; |
68d2f95e AD |
4574 | } |
4575 | ||
4dccf1ed AD |
4576 | function print_notice($msg) { |
4577 | return print format_notice($msg); | |
4578 | } | |
4579 | ||
4580 | function print_warning($msg) { | |
4581 | return print format_warning($msg); | |
4582 | } | |
4583 | ||
68d2f95e AD |
4584 | function print_error($msg) { |
4585 | return print format_error($msg); | |
4586 | } | |
4587 | ||
4588 | ||
4dccf1ed AD |
4589 | function T_sprintf() { |
4590 | $args = func_get_args(); | |
4591 | return vsprintf(__(array_shift($args)), $args); | |
4592 | } | |
4593 | ||
eedfb635 AD |
4594 | function outputArticleXML($link, $id, $feed_id, $mark_as_read = true, |
4595 | $zoom_mode = false) { | |
3de0261a | 4596 | |
10eb9da8 AD |
4597 | /* we can figure out feed_id from article id anyway, why do we |
4598 | * pass feed_id here? */ | |
4599 | ||
4600 | $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries | |
4601 | WHERE ref_id = '$id'"); | |
4602 | ||
4603 | $feed_id = db_fetch_result($result, 0, "feed_id"); | |
4604 | ||
eedfb635 | 4605 | if (!$zoom_mode) { print "<article id='$id'><![CDATA["; }; |
3de0261a AD |
4606 | |
4607 | $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds | |
4608 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
4609 | ||
4610 | if (db_num_rows($result) == 1) { | |
4611 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); | |
4612 | } else { | |
4613 | $rtl_content = false; | |
4614 | } | |
4615 | ||
4616 | if ($rtl_content) { | |
4617 | $rtl_tag = "dir=\"RTL\""; | |
4618 | $rtl_class = "RTL"; | |
4619 | } else { | |
4620 | $rtl_tag = ""; | |
4621 | $rtl_class = ""; | |
4622 | } | |
4623 | ||
4624 | if ($mark_as_read) { | |
4625 | $result = db_query($link, "UPDATE ttrss_user_entries | |
4626 | SET unread = false,last_read = NOW() | |
4627 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
8a4c759e AD |
4628 | |
4629 | ccache_update($link, $feed_id, $_SESSION["uid"]); | |
3de0261a AD |
4630 | } |
4631 | ||
4632 | $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id, | |
fc2b26a6 | 4633 | ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, |
3de0261a AD |
4634 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url, |
4635 | num_comments, | |
4636 | author | |
4637 | FROM ttrss_entries,ttrss_user_entries | |
4638 | WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]); | |
4639 | ||
4640 | if ($result) { | |
4641 | ||
4642 | $link_target = ""; | |
4643 | ||
4644 | if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { | |
e944346c | 4645 | $link_target = "target=\"_blank\""; |
3de0261a AD |
4646 | } |
4647 | ||
4648 | $line = db_fetch_assoc($result); | |
4649 | ||
4650 | if ($line["icon_url"]) { | |
4651 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
4652 | } else { | |
4653 | $feed_icon = " "; | |
4654 | } | |
4655 | ||
4656 | /* if ($line["comments"] && $line["link"] != $line["comments"]) { | |
4657 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
4658 | } else { | |
4659 | $entry_comments = ""; | |
4660 | } */ | |
4661 | ||
4662 | $num_comments = $line["num_comments"]; | |
4663 | $entry_comments = ""; | |
4664 | ||
4665 | if ($num_comments > 0) { | |
4666 | if ($line["comments"]) { | |
4667 | $comments_url = $line["comments"]; | |
4668 | } else { | |
4669 | $comments_url = $line["link"]; | |
4670 | } | |
4671 | $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>"; | |
4672 | } else { | |
4673 | if ($line["comments"] && $line["link"] != $line["comments"]) { | |
4674 | $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>"; | |
4675 | } | |
4676 | } | |
4677 | ||
eedfb635 AD |
4678 | if ($zoom_mode) { |
4679 | header("Content-Type: text/html"); | |
4680 | print "<html><head> | |
5bb0cc8e | 4681 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> |
eedfb635 AD |
4682 | <title>Tiny Tiny RSS - ".$line["title"]."</title> |
4683 | <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss.css\"> | |
4684 | </head><body>"; | |
4685 | } | |
4686 | ||
4687 | ||
3de0261a AD |
4688 | print "<div class=\"postReply\">"; |
4689 | ||
94047498 AD |
4690 | print "<div class=\"postHeader\" onmouseover=\"enable_resize(true)\" |
4691 | onmouseout=\"enable_resize(false)\">"; | |
3de0261a AD |
4692 | |
4693 | $entry_author = $line["author"]; | |
4694 | ||
4695 | if ($entry_author) { | |
60164936 | 4696 | $entry_author = __(" - ") . $entry_author; |
3de0261a AD |
4697 | } |
4698 | ||
4699 | $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
4700 | strtotime($line["updated"])); | |
4701 | ||
4702 | print "<div class=\"postDate$rtl_class\">$parsed_updated</div>"; | |
4703 | ||
4704 | if ($line["link"]) { | |
4705 | print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" . | |
06202d88 | 4706 | $line["title"] . "</a><span class='author'>$entry_author</span></div>"; |
3de0261a AD |
4707 | } else { |
4708 | print "<div clear='both'>" . $line["title"] . "$entry_author</div>"; | |
4709 | } | |
4710 | ||
9cfd409d | 4711 | /* $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM |
3de0261a | 4712 | ttrss_tags WHERE post_int_id = " . $line["int_id"] . " |
9cfd409d AD |
4713 | ORDER BY tag_name"); */ |
4714 | ||
4715 | $tags = get_article_tags($link, $id); | |
3de0261a AD |
4716 | |
4717 | $tags_str = ""; | |
eedfb635 | 4718 | $tags_nolinks_str = ""; |
3de0261a AD |
4719 | $f_tags_str = ""; |
4720 | ||
4721 | $num_tags = 0; | |
4722 | ||
20361063 AD |
4723 | if ($_SESSION["theme"] == "3pane") { |
4724 | $tag_limit = 3; | |
4725 | } else { | |
4726 | $tag_limit = 6; | |
4727 | } | |
4728 | ||
9cfd409d | 4729 | foreach ($tags as $tag) { |
3de0261a | 4730 | $num_tags++; |
14b6c54b AD |
4731 | $tag_escaped = str_replace("'", "\\'", $tag); |
4732 | ||
4733 | $tag_str = "<a href=\"javascript:viewfeed('$tag_escaped')\">$tag</a>, "; | |
3de0261a | 4734 | |
20361063 | 4735 | if ($num_tags == $tag_limit) { |
66a251f9 | 4736 | $tags_str .= "…"; |
eedfb635 | 4737 | $tags_nolinks_str .= "…"; |
e7544143 | 4738 | |
20361063 | 4739 | } else if ($num_tags < $tag_limit) { |
3de0261a | 4740 | $tags_str .= $tag_str; |
eedfb635 | 4741 | $tags_nolinks_str .= "$tag, "; |
3de0261a AD |
4742 | } |
4743 | $f_tags_str .= $tag_str; | |
4744 | } | |
4745 | ||
4746 | $tags_str = preg_replace("/, $/", "", $tags_str); | |
eedfb635 | 4747 | $tags_nolinks_str = preg_replace("/, $/", "", $tags_nolinks_str); |
3de0261a AD |
4748 | $f_tags_str = preg_replace("/, $/", "", $f_tags_str); |
4749 | ||
66a251f9 | 4750 | $all_tags_div = "<span class='cdmAllTagsCtr'>…<div class='cdmAllTags'>All Tags: $f_tags_str</div></span>"; |
e7544143 AD |
4751 | $tags_str = preg_replace("/\.\.\.$/", "$all_tags_div", $tags_str); |
4752 | ||
3de0261a AD |
4753 | if (!$entry_comments) $entry_comments = " "; # placeholder |
4754 | ||
4755 | if (!$tags_str) $tags_str = '<span class="tagList">'.__('no tags').'</span>'; | |
eedfb635 | 4756 | if (!$tags_nolinks_str) $tags_nolinks_str = '<span class="tagList">'.__('no tags').'</span>'; |
3de0261a | 4757 | |
5f014cf1 | 4758 | print "<div style='float : right'> |
eedfb635 AD |
4759 | <img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'>"; |
4760 | ||
4761 | if (!$zoom_mode) { | |
4762 | print "$tags_str | |
4763 | <a title=\"".__('Edit tags for this article')."\" | |
4710e3dc AD |
4764 | href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a>"; |
4765 | ||
4766 | if (defined('_ENABLE_INLINE_VIEW')) { | |
4767 | ||
4768 | print "<img src=\"images/art-inline.png\" class='tagsPic' | |
98fe7044 | 4769 | style=\"cursor : pointer\" style=\"cursor : pointer\" |
4710e3dc AD |
4770 | onclick=\"showOriginalArticleInline($id)\" |
4771 | alt='Inline' title='".__('Display original article content')."'>"; | |
4772 | ||
4773 | } | |
4774 | ||
4775 | print "<img src=\"images/art-zoom.png\" class='tagsPic' | |
98fe7044 | 4776 | style=\"cursor : pointer\" style=\"cursor : pointer\" |
eedfb635 AD |
4777 | onclick=\"zoomToArticle($id)\" |
4778 | alt='Zoom' title='".__('Show article summary in new window')."'>"; | |
4779 | } else { | |
4780 | print "$tags_nolinks_str"; | |
4781 | } | |
4782 | print "</div>"; | |
4783 | print "<div clear='both'>$entry_comments</div>"; | |
3de0261a AD |
4784 | |
4785 | print "</div>"; | |
4786 | ||
4787 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
4788 | print "<div class=\"postContent\">"; | |
4789 | ||
e7544143 | 4790 | #print "<div id=\"allEntryTags\">".__('Tags:')." $f_tags_str</div>"; |
3de0261a | 4791 | |
c54526fe | 4792 | $article_content = sanitize_rss($link, $line["content"]); |
c41890b0 | 4793 | |
3de0261a | 4794 | if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { |
c54526fe AD |
4795 | $article_content = preg_replace("/href=/i", "target=\"_blank\" href=", |
4796 | $article_content); | |
3de0261a AD |
4797 | } |
4798 | ||
c54526fe | 4799 | print $article_content; |
ce53e200 AD |
4800 | |
4801 | $result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE | |
4752b041 | 4802 | post_id = '$id' AND content_url != ''"); |
ce53e200 AD |
4803 | |
4804 | if (db_num_rows($result) > 0) { | |
ce53e200 | 4805 | |
9c5ee7e1 | 4806 | $entries_html = array(); |
ce53e200 AD |
4807 | $entries = array(); |
4808 | ||
4809 | while ($line = db_fetch_assoc($result)) { | |
4810 | ||
4811 | $url = $line["content_url"]; | |
4752b041 AD |
4812 | $ctype = $line["content_type"]; |
4813 | ||
4814 | if (!$ctype) $ctype = __("unknown type"); | |
ce53e200 AD |
4815 | |
4816 | $filename = substr($url, strrpos($url, "/")+1); | |
4817 | ||
8dccabed AD |
4818 | $entry = ""; |
4819 | ||
b84b68d9 | 4820 | if (($ctype == __("audio/mpeg")) && |
8dccabed AD |
4821 | (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { |
4822 | ||
39e865fa | 4823 | $entry .= "<object type=\"application/x-shockwave-flash\" data=\"extras/button/musicplayer.swf?song_url=$url\" width=\"17\" height=\"17\"> <param name=\"movie\" value=\"extras/button/musicplayer.swf?song_url=$url\" /> </object> "; |
8dccabed AD |
4824 | |
4825 | } | |
4826 | ||
4827 | $entry .= "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" . | |
4752b041 | 4828 | $filename . " (" . $ctype . ")" . "</a>"; |
ce53e200 | 4829 | |
9c5ee7e1 AD |
4830 | array_push($entries_html, $entry); |
4831 | ||
4832 | $entry = array(); | |
4833 | ||
4834 | $entry["type"] = $ctype; | |
4835 | $entry["filename"] = $filename; | |
4836 | $entry["url"] = $url; | |
4837 | ||
ce53e200 AD |
4838 | array_push($entries, $entry); |
4839 | } | |
4840 | ||
9c5ee7e1 AD |
4841 | print "<div class=\"postEnclosures\">"; |
4842 | ||
c54526fe | 4843 | if (!preg_match("/img/i", $article_content)) { |
9c5ee7e1 AD |
4844 | foreach ($entries as $entry) { |
4845 | if (preg_match("/image/", $entry["type"])) { | |
4846 | print "<p><img | |
4847 | alt=\"".htmlspecialchars($entry["filename"])."\" | |
4848 | src=\"" .htmlspecialchars($entry["url"]) . "\"></p>"; | |
4849 | } | |
4850 | } | |
4851 | } | |
4852 | ||
4853 | print "<div class=\"postEnclosures\">"; | |
4854 | ||
4855 | if (db_num_rows($result) == 1) { | |
4856 | print __("Attachment:") . " "; | |
4857 | } else { | |
4858 | print __("Attachments:") . " "; | |
4859 | } | |
4860 | ||
4861 | print join(", ", $entries_html); | |
ce53e200 AD |
4862 | |
4863 | print "</div>"; | |
4864 | } | |
4865 | ||
4866 | print "</div>"; | |
3de0261a AD |
4867 | |
4868 | print "</div>"; | |
4869 | ||
4870 | } | |
4871 | ||
eedfb635 AD |
4872 | if (!$zoom_mode) { |
4873 | print "]]></article>"; | |
4874 | } else { | |
4875 | print " | |
4876 | <div style=\"text-align : center\"> | |
4877 | <input type=\"submit\" onclick=\"return window.close()\" | |
4878 | value=\"".__("Close this window")."\"></div>"; | |
4879 | print "</body></html>"; | |
4880 | ||
4881 | } | |
3de0261a AD |
4882 | |
4883 | } | |
4884 | ||
4885 | function outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view, | |
7b4d02a8 AD |
4886 | $next_unread_feed, $offset, $vgr_last_feed = false, |
4887 | $override_order = false) { | |
3de0261a | 4888 | |
52d7e7da AD |
4889 | $disable_cache = false; |
4890 | ||
46921916 AD |
4891 | $timing_info = getmicrotime(); |
4892 | ||
961f4c73 AD |
4893 | $topmost_article_ids = array(); |
4894 | ||
ac541432 AD |
4895 | if (!$offset) { |
4896 | $offset = 0; | |
4897 | } | |
3de0261a AD |
4898 | |
4899 | if ($subop == "undefined") $subop = ""; | |
4900 | ||
a9bcfb8f AD |
4901 | $subop_split = split(":", $subop); |
4902 | ||
3de0261a AD |
4903 | if ($subop == "CatchupSelected") { |
4904 | $ids = split(",", db_escape_string($_GET["ids"])); | |
4905 | $cmode = sprintf("%d", $_GET["cmode"]); | |
4906 | ||
4907 | catchupArticlesById($link, $ids, $cmode); | |
4908 | } | |
4909 | ||
4910 | if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) { | |
35bf080c | 4911 | update_generic_feed($link, $feed, $cat_view, true); |
3de0261a AD |
4912 | } |
4913 | ||
4914 | if ($subop == "MarkAllRead") { | |
4915 | catchup_feed($link, $feed, $cat_view); | |
4916 | ||
4917 | if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) { | |
4918 | if ($next_unread_feed) { | |
4919 | $feed = $next_unread_feed; | |
4920 | } | |
4921 | } | |
4922 | } | |
4923 | ||
a9bcfb8f AD |
4924 | if ($subop_split[0] == "MarkAllReadGR") { |
4925 | catchup_feed($link, $subop_split[1], false); | |
4926 | } | |
4927 | ||
4928 | ||
3de0261a AD |
4929 | if ($feed_id > 0) { |
4930 | $result = db_query($link, | |
4931 | "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1"); | |
4932 | ||
4933 | if (db_num_rows($result) == 0) { | |
4934 | print "<div align='center'>".__('Feed not found.')."</div>"; | |
4935 | return; | |
4936 | } | |
4937 | } | |
4938 | ||
4939 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { | |
10eb9da8 | 4940 | |
3de0261a AD |
4941 | $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds |
4942 | WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
4943 | ||
4944 | if (db_num_rows($result) == 1) { | |
4945 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); | |
4946 | } else { | |
4947 | $rtl_content = false; | |
4948 | } | |
4949 | ||
4950 | if ($rtl_content) { | |
4951 | $rtl_tag = "dir=\"RTL\""; | |
4952 | } else { | |
4953 | $rtl_tag = ""; | |
4954 | } | |
4955 | } else { | |
4956 | $rtl_tag = ""; | |
4957 | $rtl_content = false; | |
4958 | } | |
4959 | ||
4960 | $script_dt_add = get_script_dt_add(); | |
4961 | ||
4962 | /// START ///////////////////////////////////////////////////////////////////////////////// | |
4963 | ||
4964 | $search = db_escape_string($_GET["query"]); | |
52d7e7da AD |
4965 | |
4966 | if ($search) { | |
4967 | $disable_cache = true; | |
4968 | } | |
4969 | ||
3de0261a AD |
4970 | $search_mode = db_escape_string($_GET["search_mode"]); |
4971 | $match_on = db_escape_string($_GET["match_on"]); | |
4972 | ||
4973 | if (!$match_on) { | |
4974 | $match_on = "both"; | |
4975 | } | |
4976 | ||
4977 | $real_offset = $offset * $limit; | |
4978 | ||
46921916 AD |
4979 | if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info); |
4980 | ||
3de0261a | 4981 | $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, |
7b4d02a8 | 4982 | $search, $search_mode, $match_on, $override_order, $real_offset); |
3de0261a | 4983 | |
46921916 AD |
4984 | if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info); |
4985 | ||
3de0261a AD |
4986 | $result = $qfh_ret[0]; |
4987 | $feed_title = $qfh_ret[1]; | |
4988 | $feed_site_url = $qfh_ret[2]; | |
4989 | $last_error = $qfh_ret[3]; | |
f56e3080 | 4990 | |
081e527d AD |
4991 | $vgroup_last_feed = $vgr_last_feed; |
4992 | ||
f56e3080 AD |
4993 | if ($feed == -2) { |
4994 | $feed_site_url = article_publish_url($link); | |
4995 | } | |
4996 | ||
3de0261a AD |
4997 | /// STOP ////////////////////////////////////////////////////////////////////////////////// |
4998 | ||
ac541432 AD |
4999 | if (!$offset) { |
5000 | print "<div id=\"headlinesContainer\" $rtl_tag>"; | |
3de0261a | 5001 | |
ac541432 AD |
5002 | if (!$result) { |
5003 | print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>"; | |
5004 | return; | |
5005 | } | |
3de0261a | 5006 | |
ac541432 AD |
5007 | print_headline_subtoolbar($link, $feed_site_url, $feed_title, false, |
5008 | $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode, | |
5009 | $offset, $limit); | |
3de0261a | 5010 | |
ac541432 AD |
5011 | print "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">"; |
5012 | } | |
3de0261a | 5013 | |
29dfb258 AD |
5014 | $headlines_count = db_num_rows($result); |
5015 | ||
3de0261a AD |
5016 | if (db_num_rows($result) > 0) { |
5017 | ||
5018 | # print "\{$offset}"; | |
5019 | ||
ac541432 | 5020 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) { |
3de0261a AD |
5021 | print "<table class=\"headlinesList\" id=\"headlinesList\" |
5022 | cellspacing=\"0\">"; | |
5023 | } | |
5024 | ||
4ab4d364 AD |
5025 | $lnum = $limit*$offset; |
5026 | ||
3de0261a AD |
5027 | error_reporting (DEFAULT_ERROR_LEVEL); |
5028 | ||
5029 | $num_unread = 0; | |
6cfea5c7 AD |
5030 | $cur_feed_title = ''; |
5031 | ||
3de0261a AD |
5032 | while ($line = db_fetch_assoc($result)) { |
5033 | ||
5034 | $class = ($lnum % 2) ? "even" : "odd"; | |
5035 | ||
5036 | $id = $line["id"]; | |
5037 | $feed_id = $line["feed_id"]; | |
961f4c73 AD |
5038 | |
5039 | if (count($topmost_article_ids) < 5) { | |
5040 | array_push($topmost_article_ids, $id); | |
5041 | } | |
5042 | ||
3de0261a AD |
5043 | if ($line["last_read"] == "" && |
5044 | ($line["unread"] != "t" && $line["unread"] != "1")) { | |
5045 | ||
5046 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
5047 | alt=\"Updated\">"; | |
5048 | } else { | |
5049 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
5050 | alt=\"Updated\">"; | |
5051 | } | |
5052 | ||
5053 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
5054 | $class .= "Unread"; | |
5055 | ++$num_unread; | |
5056 | $is_unread = true; | |
5057 | } else { | |
5058 | $is_unread = false; | |
5059 | } | |
abd8a516 AD |
5060 | |
5061 | $is_ie = (strpos($_SESSION["client.userAgent"], "MSIE") !== false); | |
5062 | ||
5063 | if ($is_ie) { | |
5064 | $mark_img_ext = "gif"; | |
5065 | } else { | |
5066 | $mark_img_ext = "png"; | |
5067 | } | |
5068 | ||
3de0261a | 5069 | if ($line["marked"] == "t" || $line["marked"] == "1") { |
abd8a516 | 5070 | $marked_pic = "<img id=\"FMPIC-$id\" src=\"images/mark_set.$mark_img_ext\" |
3de0261a | 5071 | class=\"markedPic\" |
f5e0338d | 5072 | alt=\"Unstar article\" onclick='javascript:tMark($id)'>"; |
3de0261a | 5073 | } else { |
abd8a516 | 5074 | $marked_pic = "<img id=\"FMPIC-$id\" src=\"images/mark_unset.$mark_img_ext\" |
3de0261a | 5075 | class=\"markedPic\" |
f5e0338d | 5076 | alt=\"Star article\" onclick='javascript:tMark($id)'>"; |
3de0261a AD |
5077 | } |
5078 | ||
e4f4b46f | 5079 | if ($line["published"] == "t" || $line["published"] == "1") { |
f5e0338d | 5080 | $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_set.gif\" |
e4f4b46f | 5081 | class=\"markedPic\" |
f5e0338d | 5082 | alt=\"Unpublish article\" onclick='javascript:tPub($id)'>"; |
e4f4b46f | 5083 | } else { |
f5e0338d | 5084 | $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_unset.gif\" |
e4f4b46f | 5085 | class=\"markedPic\" |
f5e0338d | 5086 | alt=\"Publish article\" onclick='javascript:tPub($id)'>"; |
e4f4b46f AD |
5087 | } |
5088 | ||
e944346c | 5089 | # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" . |
3de0261a AD |
5090 | # $line["title"] . "</a>"; |
5091 | ||
f0971fc1 AD |
5092 | # $content_link = "<a |
5093 | # href=\"" . htmlspecialchars($line["link"]) . "\" | |
5094 | # onclick=\"view($id,$feed_id);\">" . | |
5095 | # $line["title"] . "</a>"; | |
3de0261a AD |
5096 | |
5097 | # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" . | |
5098 | # $line["title"] . "</a>"; | |
5099 | ||
5100 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
46921916 | 5101 | $updated_fmt = smart_date_time(strtotime($line["updated_noms"])); |
3de0261a AD |
5102 | } else { |
5103 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
46921916 | 5104 | $updated_fmt = date($short_date, strtotime($line["updated_noms"])); |
3de0261a AD |
5105 | } |
5106 | ||
5107 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
5108 | $content_preview = truncate_string(strip_tags($line["content_preview"]), | |
5109 | 100); | |
5110 | } | |
5111 | ||
ff6e357a AD |
5112 | $score = $line["score"]; |
5113 | ||
1e36af0c | 5114 | $score_pic = get_score_pic($score); |
546499a9 AD |
5115 | |
5116 | $score_title = __("(Click to change)"); | |
5117 | ||
5daa24f2 | 5118 | $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\" |
546499a9 | 5119 | onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; |
ff6e357a | 5120 | |
5daa24f2 AD |
5121 | if ($score > 500) { |
5122 | $hlc_suffix = "H"; | |
5123 | } else if ($score < -100) { | |
5124 | $hlc_suffix = "L"; | |
5125 | } else { | |
5126 | $hlc_suffix = ""; | |
5127 | } | |
5128 | ||
3de0261a AD |
5129 | $entry_author = $line["author"]; |
5130 | ||
5131 | if ($entry_author) { | |
60164936 | 5132 | $entry_author = " - $entry_author"; |
3de0261a AD |
5133 | } |
5134 | ||
7defa089 | 5135 | $has_feed_icon = feed_has_icon($feed_id); |
bd51294a AD |
5136 | |
5137 | if ($has_feed_icon) { | |
5138 | $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">"; | |
5139 | } else { | |
5140 | //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">"; | |
20be0cf8 | 5141 | $feed_icon_img = ""; |
bd51294a AD |
5142 | } |
5143 | ||
3de0261a | 5144 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { |
6cfea5c7 | 5145 | |
d00f22ac | 5146 | if (get_pref($link, 'VFEED_GROUP_BY_FEED')) { |
bb031f91 | 5147 | if ($feed_id != $vgroup_last_feed && $line["feed_title"]) { |
a9bcfb8f AD |
5148 | |
5149 | $cur_feed_title = $line["feed_title"]; | |
081e527d | 5150 | $vgroup_last_feed = $feed_id; |
a9bcfb8f | 5151 | |
962d8ba4 | 5152 | $cur_feed_title = htmlspecialchars($cur_feed_title); |
43fc671f | 5153 | |
338ce36c | 5154 | $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>mark as read</a>)"; |
a9bcfb8f | 5155 | |
6cfea5c7 | 5156 | print "<tr class='feedTitle'><td colspan='7'>". |
dc803347 | 5157 | "<div style=\"float : right\">$feed_icon_img</div>". |
6cfea5c7 | 5158 | "<a href=\"javascript:viewfeed($feed_id, '', false)\">". |
965fb2af | 5159 | $line["feed_title"]."</a> $vf_catchup_link</td></tr>"; |
6cfea5c7 AD |
5160 | } |
5161 | } | |
314fcd2b AD |
5162 | |
5163 | $mouseover_attrs = "onmouseover='postMouseIn($id)' | |
5164 | onmouseout='postMouseOut($id)'"; | |
5165 | ||
5166 | print "<tr class='$class' id='RROW-$id' $mouseover_attrs>"; | |
3de0261a | 5167 | |
67343d9f | 5168 | print "<td class='hlUpdPic'>$update_pic</td>"; |
3de0261a AD |
5169 | |
5170 | print "<td class='hlSelectRow'> | |
67343d9f AD |
5171 | <input type=\"checkbox\" onclick=\"tSR(this)\" |
5172 | id=\"RCHK-$id\"> | |
3de0261a AD |
5173 | </td>"; |
5174 | ||
5175 | print "<td class='hlMarkedPic'>$marked_pic</td>"; | |
e4f4b46f | 5176 | print "<td class='hlMarkedPic'>$published_pic</td>"; |
3de0261a | 5177 | |
df456bb0 AD |
5178 | # if ($line["feed_title"]) { |
5179 | # print "<td class='hlContent'>$content_link</td>"; | |
5180 | # print "<td class='hlFeed'> | |
5181 | # <a href=\"javascript:viewfeed($feed_id, '', false)\">". | |
5182 | # truncate_string($line["feed_title"],30)."</a> </td>"; | |
5183 | # } else { | |
5184 | ||
f0971fc1 | 5185 | print "<td onclick='view($id,$feed_id)' class='hlContent$hlc_suffix' valign='middle'>"; |
df456bb0 | 5186 | |
f0971fc1 AD |
5187 | print "<a id=\"RTITLE-$id\" |
5188 | href=\"" . htmlspecialchars($line["link"]) . "\" | |
a7764e51 | 5189 | onclick=\"return view($id,$feed_id);\">" . |
df456bb0 AD |
5190 | $line["title"]; |
5191 | ||
5192 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
5193 | if ($content_preview) { | |
5194 | print "<span class=\"contentPreview\"> - $content_preview</span>"; | |
3de0261a | 5195 | } |
3de0261a | 5196 | } |
df456bb0 AD |
5197 | |
5198 | print "</a>"; | |
5199 | ||
5200 | # <a href=\"javascript:viewfeed($feed_id, '', false)\">". | |
5201 | # $line["feed_title"]."</a> | |
5202 | ||
d00f22ac | 5203 | if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) { |
6cfea5c7 AD |
5204 | if ($line["feed_title"]) { |
5205 | print "<span class=\"hlFeed\"> | |
5206 | (<a href=\"javascript:viewfeed($feed_id, '', false)\">". | |
5207 | $line["feed_title"]."</a>) | |
5208 | </span>"; | |
5209 | } | |
df456bb0 | 5210 | } |
df456bb0 | 5211 | print "</td>"; |
bd51294a | 5212 | |
df456bb0 | 5213 | # } |
3de0261a | 5214 | |
d7e83df7 | 5215 | print "<td class=\"hlUpdated\" onclick='view($id,$feed_id)'><nobr>$updated_fmt </nobr></td>"; |
546499a9 AD |
5216 | |
5217 | print "<td class='hlMarkedPic'>$score_pic</td>"; | |
bd51294a AD |
5218 | |
5219 | if ($line["feed_title"] && !get_pref($link, 'VFEED_GROUP_BY_FEED')) { | |
d7e83df7 | 5220 | print "<td onclick=\"viewfeed($feed_id)\" class=\"hlFeedIcon\">$feed_icon_img</td>"; |
bd51294a AD |
5221 | } |
5222 | ||
3de0261a AD |
5223 | print "</tr>"; |
5224 | ||
5225 | } else { | |
6cfea5c7 | 5226 | |
bb031f91 | 5227 | if (get_pref($link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) { |
081e527d AD |
5228 | if ($feed_id != $vgroup_last_feed) { |
5229 | ||
5230 | $cur_feed_title = $line["feed_title"]; | |
5231 | $vgroup_last_feed = $feed_id; | |
5232 | ||
962d8ba4 AD |
5233 | $cur_feed_title = htmlspecialchars($cur_feed_title); |
5234 | ||
338ce36c | 5235 | $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>mark as read</a>)"; |
081e527d | 5236 | |
7defa089 | 5237 | $has_feed_icon = feed_has_icon($feed_id); |
dc803347 AD |
5238 | |
5239 | if ($has_feed_icon) { | |
5240 | $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">"; | |
5241 | } else { | |
5242 | //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">"; | |
5243 | } | |
5244 | ||
6cfea5c7 | 5245 | print "<div class='cdmFeedTitle'>". |
dc803347 | 5246 | "<div style=\"float : right\">$feed_icon_img</div>". |
6cfea5c7 | 5247 | "<a href=\"javascript:viewfeed($feed_id, '', false)\">". |
081e527d | 5248 | $line["feed_title"]."</a> $vf_catchup_link</div>"; |
6cfea5c7 AD |
5249 | } |
5250 | } | |
5251 | ||
3de0261a AD |
5252 | if ($is_unread) { |
5253 | $add_class = "Unread"; | |
5254 | } else { | |
5255 | $add_class = ""; | |
5256 | } | |
0cacc891 AD |
5257 | |
5258 | $expand_cdm = get_pref($link, 'CDM_EXPANDED'); | |
3cd4239a | 5259 | $show_excerpt = false; |
0cacc891 | 5260 | |
5daa24f2 | 5261 | if ($expand_cdm && $score >= -100) { |
0cacc891 | 5262 | $cdm_cstyle = ""; |
3cd4239a | 5263 | $show_excerpt = false; |
0cacc891 AD |
5264 | } else { |
5265 | $cdm_cstyle = "style=\"display : none\""; | |
3cd4239a | 5266 | $show_excerpt = true; |
0cacc891 AD |
5267 | } |
5268 | ||
314fcd2b AD |
5269 | $mouseover_attrs = "onmouseover='postMouseIn($id)' |
5270 | onmouseout='postMouseOut($id)'"; | |
5271 | ||
e4914b62 | 5272 | print "<div class=\"cdmArticle$add_class\" |
3cd4239a | 5273 | id=\"RROW-$id\" |
314fcd2b | 5274 | $mouseover_attrs'>"; |
3de0261a AD |
5275 | |
5276 | print "<div class=\"cdmHeader\">"; | |
5277 | ||
965fb2af AD |
5278 | if (!get_pref($link, "VFEED_GROUP_BY_FEED") || !$line["feed_title"]) { |
5279 | $cdm_feed_icon = "<span style=\"cursor : pointer\" onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>"; | |
5280 | } | |
5281 | ||
5282 | print "<div class=\"articleUpdated\">$updated_fmt $score_pic $cdm_feed_icon | |
b3296d36 | 5283 | </div>"; |
5daa24f2 | 5284 | |
9617eb94 | 5285 | print "<span id=\"RTITLE-$id\" class=\"titleWrap$hlc_suffix\"><a class=\"title\" |
3de0261a | 5286 | onclick=\"javascript:toggleUnread($id, 0)\" |
5daa24f2 AD |
5287 | target=\"_blank\" href=\"".$line["link"]."\">".$line["title"]."</a> |
5288 | "; | |
3de0261a AD |
5289 | |
5290 | print $entry_author; | |
5291 | ||
3cd4239a | 5292 | /* if (!$expand_cdm || $score < -100) { |
0cacc891 AD |
5293 | print " <a id=\"CICH-$id\" |
5294 | href=\"javascript:cdmExpandArticle($id)\"> | |
5295 | (".__('Show article').")</a>"; | |
3cd4239a | 5296 | } */ |
0cacc891 AD |
5297 | |
5298 | ||
d00f22ac | 5299 | if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) { |
6cfea5c7 AD |
5300 | if ($line["feed_title"]) { |
5301 | print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)"; | |
5302 | } | |
3de0261a AD |
5303 | } |
5304 | ||
5daa24f2 | 5305 | print "</span></div>"; |
3de0261a | 5306 | |
3fc2eed5 AD |
5307 | if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { |
5308 | $line["content_preview"] = preg_replace("/href=/i", | |
e944346c | 5309 | "target=\"_blank\" href=", $line["content_preview"]); |
3fc2eed5 AD |
5310 | } |
5311 | ||
3cd4239a AD |
5312 | if ($show_excerpt) { |
5313 | print "<div class=\"cdmExcerpt\" id=\"CEXC-$id\" | |
5314 | onclick=\"cdmExpandArticle($id)\" | |
5315 | title=\"".__('Click to expand article')."\">"; | |
5316 | print truncate_string(strip_tags($line["content_preview"]), 100); | |
5317 | print "</div>"; | |
5318 | } | |
5319 | ||
5320 | print "<div class=\"cdmContent\" | |
5321 | onclick=\"cdmClicked($id)\" | |
5322 | id=\"CICD-$id\" $cdm_cstyle>"; | |
a04c8e8d | 5323 | |
0cacc891 | 5324 | // print "<div class=\"cdmInnerContent\" id=\"CICD-$id\" $cdm_cstyle>"; |
621ffb00 | 5325 | |
b2d5d145 | 5326 | print sanitize_rss($link, $line["content_preview"]); |
c54526fe | 5327 | $article_content = $line["content_preview"]; |
3c66b582 AD |
5328 | |
5329 | $e_result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE | |
4752b041 | 5330 | post_id = '$id' AND content_url != ''"); |
3c66b582 AD |
5331 | |
5332 | if (db_num_rows($e_result) > 0) { | |
3c66b582 | 5333 | |
a3eeb471 | 5334 | $entries_html = array(); |
3c66b582 AD |
5335 | $entries = array(); |
5336 | ||
5337 | while ($e_line = db_fetch_assoc($e_result)) { | |
5338 | ||
5339 | $url = $e_line["content_url"]; | |
4752b041 AD |
5340 | $ctype = $e_line["content_type"]; |
5341 | if (!$ctype) $ctype = __("unknown type"); | |
3c66b582 AD |
5342 | |
5343 | $filename = substr($url, strrpos($url, "/")+1); | |
5344 | ||
8dccabed AD |
5345 | $entry = ""; |
5346 | ||
b84b68d9 | 5347 | if (($ctype == __("audio/mpeg")) && |
8dccabed AD |
5348 | (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { |
5349 | ||
39e865fa | 5350 | $entry .= "<object type=\"application/x-shockwave-flash\" data=\"extras/button/musicplayer.swf?song_url=$url\" width=\"17\" height=\"17\"> <param name=\"movie\" value=\"extras/button/musicplayer.swf?song_url=$url\" /> </object> "; |
8dccabed AD |
5351 | |
5352 | } | |
5353 | ||
5354 | $entry .= "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" . | |
4752b041 | 5355 | $filename . " (" . $ctype . ")" . "</a>"; |
3c66b582 | 5356 | |
a3eeb471 AD |
5357 | array_push($entries_html, $entry); |
5358 | ||
5359 | $entry = array(); | |
5360 | ||
5361 | $entry["type"] = $ctype; | |
5362 | $entry["filename"] = $filename; | |
5363 | $entry["url"] = $url; | |
5364 | ||
3c66b582 AD |
5365 | array_push($entries, $entry); |
5366 | } | |
5367 | ||
c54526fe | 5368 | if (!preg_match("/img/i", $article_content)) { |
a3eeb471 AD |
5369 | foreach ($entries as $entry) { |
5370 | if (preg_match("/image/", $entry["type"])) { | |
5371 | print "<p><img | |
5372 | alt=\"".htmlspecialchars($entry["filename"])."\" | |
5373 | src=\"" .htmlspecialchars($entry["url"]) . "\"></p>"; | |
5374 | } | |
5375 | } | |
5376 | } | |
5377 | ||
5378 | print "<div class=\"cdmEnclosures\">"; | |
5379 | ||
5380 | if (db_num_rows($e_result) == 1) { | |
5381 | print __("Attachment:") . " "; | |
5382 | } else { | |
5383 | print __("Attachments:") . " "; | |
5384 | } | |
5385 | ||
5386 | print join(", ", $entries_html); | |
3c66b582 AD |
5387 | |
5388 | print "</div>"; | |
5389 | } | |
5390 | ||
a3eeb471 | 5391 | |
0cacc891 AD |
5392 | print "<br clear='both'>"; |
5393 | // print "</div>"; | |
a04c8e8d | 5394 | |
0cacc891 | 5395 | /* if (!$expand_cdm) { |
12f5d8fe AD |
5396 | print "<a id=\"CICH-$id\" |
5397 | href=\"javascript:cdmExpandArticle($id)\"> | |
5398 | Show article</a>"; | |
0cacc891 | 5399 | } */ |
a04c8e8d | 5400 | |
0cacc891 | 5401 | print "</div>"; |
3de0261a | 5402 | |
e2ccbfab | 5403 | print "<div class=\"cdmFooter\"><span class='s0'>"; |
3de0261a | 5404 | |
e2ccbfab | 5405 | /* print "<div class=\"markedPic\">Star it: $marked_pic</div>"; */ |
3de0261a | 5406 | |
e2ccbfab AD |
5407 | print __("Select:"). |
5408 | " <input type=\"checkbox\" onclick=\"toggleSelectRowById(this, | |
3de0261a AD |
5409 | 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">"; |
5410 | ||
e2ccbfab | 5411 | print "</span><span class='s1'>$marked_pic</span> "; |
e4f4b46f | 5412 | print "<span class='s1'>$published_pic</span> "; |
eedfb635 AD |
5413 | print "<span class='s1'><img src=\"images/art-zoom.png\" class='tagsPic' |
5414 | onclick=\"zoomToArticle($id)\" | |
5415 | style=\"cursor : pointer\" | |
5416 | alt='Zoom' | |
5417 | title='".__('Show article summary in new window')."'></span>"; | |
e2ccbfab | 5418 | |
3de0261a AD |
5419 | $tags = get_article_tags($link, $id); |
5420 | ||
5421 | $tags_str = ""; | |
22d1f3db | 5422 | $full_tags_str = ""; |
d735ebd2 | 5423 | $num_tags = 0; |
3de0261a AD |
5424 | |
5425 | foreach ($tags as $tag) { | |
5426 | $num_tags++; | |
22d1f3db AD |
5427 | $full_tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, "; |
5428 | if ($num_tags < 5) { | |
5429 | $tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, "; | |
5430 | } else if ($num_tags == 5) { | |
66a251f9 | 5431 | $tags_str .= "…"; |
22d1f3db | 5432 | } |
3de0261a AD |
5433 | } |
5434 | ||
5435 | $tags_str = preg_replace("/, $/", "", $tags_str); | |
22d1f3db AD |
5436 | $full_tags_str = preg_replace("/, $/", "", $full_tags_str); |
5437 | ||
66a251f9 | 5438 | $all_tags_div = "<span class='cdmAllTagsCtr'>…<div class='cdmAllTags'>All Tags: $full_tags_str</div></span>"; |
22d1f3db AD |
5439 | |
5440 | $tags_str = preg_replace("/\.\.\.$/", "$all_tags_div", $tags_str); | |
5441 | ||
3de0261a AD |
5442 | |
5443 | if ($tags_str == "") $tags_str = "no tags"; | |
e2ccbfab AD |
5444 | |
5445 | // print "<img src='images/tag.png' class='markedPic'>"; | |
5446 | ||
5f014cf1 AD |
5447 | print "<span class='s1'> |
5448 | <img class='tagsPic' src='images/tag.png' alt='Tags' | |
5449 | title='Tags'> $tags_str <a title=\"Edit tags for this article\" | |
3de0261a AD |
5450 | href=\"javascript:editArticleTags($id, $feed_id, true)\">(+)</a>"; |
5451 | ||
e2ccbfab | 5452 | print "</span>"; |
3de0261a | 5453 | |
e2ccbfab AD |
5454 | print "<span class='s2'>Toggle: <a class=\"cdmToggleLink\" |
5455 | href=\"javascript:toggleUnread($id)\"> | |
5456 | Unread</a></span>"; | |
3de0261a | 5457 | |
e2ccbfab | 5458 | print "</div>"; |
3de0261a AD |
5459 | print "</div>"; |
5460 | ||
5461 | } | |
5462 | ||
5463 | ++$lnum; | |
5464 | } | |
5465 | ||
ac541432 | 5466 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) { |
3de0261a AD |
5467 | print "</table>"; |
5468 | } | |
5469 | ||
5470 | // print_headline_subtoolbar($link, | |
5471 | // "javascript:catchupPage()", "Mark page as read", true, $rtl_content); | |
5472 | ||
5473 | ||
5474 | } else { | |
93c841c4 AD |
5475 | $message = ""; |
5476 | ||
5477 | switch ($view_mode) { | |
5478 | case "unread": | |
5479 | $message = __("No unread articles found to display."); | |
5480 | break; | |
5481 | case "marked": | |
5482 | $message = __("No starred articles found to display."); | |
5483 | break; | |
5484 | default: | |
5485 | $message = __("No articles found to display."); | |
5486 | } | |
5487 | ||
5488 | if (!$offset) print "<div class='whiteBox'>$message</div>"; | |
3de0261a AD |
5489 | } |
5490 | ||
ac541432 AD |
5491 | if (!$offset) { |
5492 | print "</div>"; | |
5493 | print "</div>"; | |
5494 | } | |
3de0261a | 5495 | |
081e527d | 5496 | return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $vgroup_last_feed); |
3de0261a | 5497 | } |
0979b696 AD |
5498 | |
5499 | // from here: http://www.roscripts.com/Create_tag_cloud-71.html | |
5500 | ||
5501 | function printTagCloud($link) { | |
35a03bdd AD |
5502 | |
5503 | /* get first ref_id to count from */ | |
5504 | ||
dcac082b AD |
5505 | /* |
5506 | ||
35a03bdd AD |
5507 | $query = ""; |
5508 | ||
5509 | if (DB_TYPE == "pgsql") { | |
5510 | $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries | |
5511 | WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]." | |
5512 | AND date_entered > NOW() - INTERVAL '30 days'"; | |
5513 | } else { | |
5514 | $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries | |
5515 | WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]." | |
5516 | AND date_entered > DATE_SUB(NOW(), INTERVAL 30 DAY)"; | |
5517 | } | |
5518 | ||
5519 | $result = db_query($link, $query); | |
dcac082b | 5520 | $first_id = db_fetch_result($result, 0, "id"); */ |
35a03bdd | 5521 | |
dcac082b | 5522 | //AND post_int_id >= '$first_id' |
0979b696 AD |
5523 | $query = "SELECT tag_name, COUNT(post_int_id) AS count |
5524 | FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]." | |
b31af972 | 5525 | GROUP BY tag_name ORDER BY count DESC LIMIT 50"; |
0979b696 AD |
5526 | |
5527 | $result = db_query($link, $query); | |
5528 | ||
5529 | $tags = array(); | |
5530 | ||
5531 | while ($line = db_fetch_assoc($result)) { | |
5532 | $tags[$line["tag_name"]] = $line["count"]; | |
5533 | } | |
5534 | ||
5535 | ksort($tags); | |
5536 | ||
5537 | $max_size = 32; // max font size in pixels | |
4548a580 | 5538 | $min_size = 11; // min font size in pixels |
0979b696 AD |
5539 | |
5540 | // largest and smallest array values | |
5541 | $max_qty = max(array_values($tags)); | |
5542 | $min_qty = min(array_values($tags)); | |
5543 | ||
5544 | // find the range of values | |
5545 | $spread = $max_qty - $min_qty; | |
5546 | if ($spread == 0) { // we don't want to divide by zero | |
5547 | $spread = 1; | |
5548 | } | |
5549 | ||
5550 | // set the font-size increment | |
5551 | $step = ($max_size - $min_size) / ($spread); | |
5552 | ||
5553 | // loop through the tag array | |
5554 | foreach ($tags as $key => $value) { | |
5555 | // calculate font-size | |
5556 | // find the $value in excess of $min_qty | |
5557 | // multiply by the font-size increment ($size) | |
5558 | // and add the $min_size set above | |
5559 | $size = round($min_size + (($value - $min_qty) * $step)); | |
546ffab4 AD |
5560 | |
5561 | $key_escaped = str_replace("'", "\\'", $key); | |
5562 | ||
5563 | echo "<a href=\"javascript:viewfeed('$key_escaped') \" style=\"font-size: " . | |
0979b696 AD |
5564 | $size . "px\" title=\"$value articles tagged with " . |
5565 | $key . '">' . $key . '</a> '; | |
5566 | } | |
5567 | } | |
46921916 AD |
5568 | |
5569 | function print_checkpoint($n, $s) { | |
5570 | $ts = getmicrotime(); | |
5571 | echo sprintf("<!-- CP[$n] %.4f seconds -->", $ts - $s); | |
5572 | return $ts; | |
5573 | } | |
14b6c54b AD |
5574 | |
5575 | function sanitize_tag($tag) { | |
5576 | $tag = trim($tag); | |
5577 | ||
5578 | $tag = mb_strtolower($tag, 'utf-8'); | |
5579 | ||
0c3d1c68 AD |
5580 | $tag = preg_replace('/[\"\+\>\<]/', "", $tag); |
5581 | ||
5582 | // $tag = str_replace('"', "", $tag); | |
5583 | // $tag = str_replace("+", " ", $tag); | |
14b6c54b AD |
5584 | $tag = str_replace("technorati tag: ", "", $tag); |
5585 | ||
5586 | return $tag; | |
5587 | } | |
e4f4b46f AD |
5588 | |
5589 | function generate_publish_key() { | |
5590 | return sha1(uniqid(rand(), true)); | |
5591 | } | |
5592 | ||
f56e3080 AD |
5593 | function article_publish_url($link) { |
5594 | ||
e2749781 AD |
5595 | $url_path = ""; |
5596 | ||
5597 | ||
5598 | if ($_SERVER['HTTPS'] != "on") { | |
5599 | $url_path = "http://"; | |
5600 | } else { | |
5601 | $url_path = "https://"; | |
5602 | } | |
f56e3080 | 5603 | |
e2749781 AD |
5604 | $url_path .= $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); |
5605 | $url_path .= "/backend.php?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY"); | |
f56e3080 AD |
5606 | |
5607 | return $url_path; | |
5608 | } | |
5609 | ||
45004d43 AD |
5610 | /** |
5611 | * Purge a feed contents, marked articles excepted. | |
5612 | * | |
5613 | * @param mixed $link The database connection. | |
5614 | * @param integer $id The id of the feed to purge. | |
5615 | * @return void | |
5616 | */ | |
d1f0c584 AD |
5617 | function clear_feed_articles($link, $id) { |
5618 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
a8ae1b9a | 5619 | WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]); |
d1f0c584 AD |
5620 | |
5621 | $result = db_query($link, "DELETE FROM ttrss_entries WHERE | |
5622 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); | |
45004d43 AD |
5623 | } // function clear_feed_articles |
5624 | ||
5625 | /** | |
5626 | * Compute the Mozilla Firefox feed adding URL from server HOST and REQUEST_URI. | |
5627 | * | |
5628 | * @return string The Mozilla Firefox feed adding URL. | |
5629 | */ | |
5630 | function add_feed_url() { | |
d70c5ae4 | 5631 | $url_path = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); |
755a43ee AD |
5632 | $url_path .= "?op=pref-feeds&quiet=1&subop=add&feed_url=%s"; |
5633 | return $url_path; | |
45004d43 AD |
5634 | } // function add_feed_url |
5635 | ||
5636 | /** | |
5637 | * Encrypt a password in SHA1. | |
5638 | * | |
5639 | * @param string $pass The password to encrypt. | |
5640 | * @param string $login A optionnal login. | |
5641 | * @return string The encrypted password. | |
5642 | */ | |
1a9f4d3c AD |
5643 | function encrypt_password($pass, $login = '') { |
5644 | if ($login) { | |
5645 | return "SHA1X:" . sha1("$login:$pass"); | |
5646 | } else { | |
5647 | return "SHA1:" . sha1($pass); | |
5648 | } | |
45004d43 AD |
5649 | } // function encrypt_password |
5650 | ||
5651 | /** | |
5652 | * Update a feed batch. | |
5653 | * Used by daemons to update n feeds by run. | |
5654 | * Only update feed needing a update, and not being processed | |
5655 | * by another process. | |
5656 | * | |
5657 | * @param mixed $link Database link | |
5658 | * @param integer $limit Maximum number of feeds in update batch. Default to DAEMON_FEED_LIMIT. | |
5659 | * @param boolean $from_http Set to true if you call this function from http to disable cli specific code. | |
5660 | * @param boolean $debug Set to false to disable debug output. Default to true. | |
5661 | * @return void | |
5662 | */ | |
5663 | function update_daemon_common($link, $limit = DAEMON_FEED_LIMIT, $from_http = false, $debug = true) { | |
5664 | // Process all other feeds using last_updated and interval parameters | |
5665 | ||
5666 | // Test if the user has loggued in recently. If not, it does not update its feeds. | |
5667 | if (DAEMON_UPDATE_LOGIN_LIMIT > 0) { | |
5668 | if (DB_TYPE == "pgsql") { | |
5669 | $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'"; | |
5670 | } else { | |
5671 | $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".DAEMON_UPDATE_LOGIN_LIMIT." DAY)"; | |
5672 | } | |
5673 | } else { | |
5674 | $login_thresh_qpart = ""; | |
5675 | } | |
5676 | ||
5677 | // Test if the feed need a update (update interval exceded). | |
5678 | if (DB_TYPE == "pgsql") { | |
5679 | $update_limit_qpart = "AND (( | |
5680 | ttrss_feeds.update_interval = 0 | |
5681 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL) | |
5682 | ) OR ( | |
5683 | ttrss_feeds.update_interval > 0 | |
5684 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL) | |
da4caf5d | 5685 | ) OR ttrss_feeds.last_updated IS NULL)"; |
45004d43 AD |
5686 | } else { |
5687 | $update_limit_qpart = "AND (( | |
5688 | ttrss_feeds.update_interval = 0 | |
5689 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) | |
5690 | ) OR ( | |
5691 | ttrss_feeds.update_interval > 0 | |
5692 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE) | |
da4caf5d | 5693 | ) OR ttrss_feeds.last_updated IS NULL)"; |
45004d43 AD |
5694 | } |
5695 | ||
5696 | // Test if feed is currently being updated by another process. | |
5697 | if (DB_TYPE == "pgsql") { | |
5698 | $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')"; | |
5699 | } else { | |
5700 | $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))"; | |
5701 | } | |
5702 | ||
5703 | // Test if there is a limit to number of updated feeds | |
5704 | $query_limit = ""; | |
5705 | if($limit) $query_limit = sprintf("LIMIT %d", $limit); | |
5706 | ||
51b8c957 AD |
5707 | $random_qpart = sql_random_function(); |
5708 | ||
45004d43 AD |
5709 | // We search for feed needing update. |
5710 | $result = db_query($link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id, ttrss_feeds.owner_uid, | |
fc2b26a6 | 5711 | ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, |
45004d43 AD |
5712 | ttrss_feeds.update_interval |
5713 | FROM | |
5714 | ttrss_feeds, ttrss_users, ttrss_user_prefs | |
5715 | WHERE | |
5716 | ttrss_feeds.owner_uid = ttrss_users.id | |
5717 | AND ttrss_users.id = ttrss_user_prefs.owner_uid | |
5718 | AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL' | |
5719 | $login_thresh_qpart $update_limit_qpart | |
51b8c957 AD |
5720 | $updstart_thresh_qpart |
5721 | ORDER BY $random_qpart $query_limit"); | |
45004d43 AD |
5722 | |
5723 | $user_prefs_cache = array(); | |
5724 | ||
5725 | if($debug) _debug(sprintf("Scheduled %d feeds to update...\n", db_num_rows($result))); | |
5726 | ||
5727 | // Here is a little cache magic in order to minimize risk of double feed updates. | |
5728 | $feeds_to_update = array(); | |
5729 | while ($line = db_fetch_assoc($result)) { | |
5730 | $feeds_to_update[$line['id']] = $line; | |
5731 | } | |
5732 | ||
5733 | // We update the feed last update started date before anything else. | |
5734 | // There is no lag due to feed contents downloads | |
5735 | // It prevent an other process to update the same feed. | |
5736 | $feed_ids = array_keys($feeds_to_update); | |
5737 | if($feed_ids) { | |
5738 | db_query($link, sprintf("UPDATE ttrss_feeds SET last_update_started = NOW() | |
5739 | WHERE id IN (%s)", implode(',', $feed_ids))); | |
5740 | } | |
5741 | ||
5742 | // For each feed, we call the feed update function. | |
5743 | while ($line = array_pop($feeds_to_update)) { | |
5744 | ||
5745 | if($debug) _debug("Feed: " . $line["feed_url"] . ", " . $line["last_updated"]); | |
5746 | ||
5747 | // We setup a alarm to alert if the feed take more than 300s to update. | |
5748 | // => HANG alarm. | |
9a91a51e | 5749 | if(!$from_http && function_exists('pcntl_alarm')) pcntl_alarm(300); |
45004d43 AD |
5750 | update_rss_feed($link, $line["feed_url"], $line["id"], true); |
5751 | // Cancel the alarm (the update went well) | |
9a91a51e | 5752 | if(!$from_http && function_exists('pcntl_alarm')) pcntl_alarm(0); |
45004d43 AD |
5753 | |
5754 | sleep(1); // prevent flood (FIXME make this an option?) | |
5755 | } | |
5756 | ||
5757 | // Send feed digests by email if needed. | |
5758 | if (DAEMON_SENDS_DIGESTS) send_headlines_digests($link); | |
5759 | ||
5760 | } // function update_daemon_common | |
1a9f4d3c | 5761 | |
621ffb00 AD |
5762 | function sanitize_article_content($text) { |
5763 | # we don't support CDATA sections in articles, they break our own escaping | |
5764 | $text = preg_replace("/\[\[CDATA/", "", $text); | |
5765 | $text = preg_replace("/\]\]\>/", "", $text); | |
5766 | return $text; | |
5767 | } | |
fee840fb AD |
5768 | |
5769 | function load_filters($link, $feed, $owner_uid, $action_id = false) { | |
5770 | $filters = array(); | |
5771 | ||
5772 | if ($action_id) $ftype_query_part = "action_id = '$action_id' AND"; | |
5773 | ||
5774 | $result = db_query($link, "SELECT reg_exp, | |
5775 | ttrss_filter_types.name AS name, | |
5776 | ttrss_filter_actions.name AS action, | |
5777 | inverse, | |
44d0e774 AD |
5778 | action_param, |
5779 | filter_param | |
fee840fb AD |
5780 | FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE |
5781 | enabled = true AND | |
5782 | $ftype_query_part | |
5783 | owner_uid = $owner_uid AND | |
5784 | ttrss_filter_types.id = filter_type AND | |
5785 | ttrss_filter_actions.id = action_id AND | |
5786 | (feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp"); | |
5787 | ||
5788 | while ($line = db_fetch_assoc($result)) { | |
5789 | if (!$filters[$line["name"]]) $filters[$line["name"]] = array(); | |
5790 | $filter["reg_exp"] = $line["reg_exp"]; | |
5791 | $filter["action"] = $line["action"]; | |
5792 | $filter["action_param"] = $line["action_param"]; | |
44d0e774 | 5793 | $filter["filter_param"] = $line["filter_param"]; |
fee840fb AD |
5794 | $filter["inverse"] = sql_bool_to_bool($line["inverse"]); |
5795 | ||
5796 | array_push($filters[$line["name"]], $filter); | |
5797 | } | |
5798 | ||
5799 | return $filters; | |
5800 | } | |
1e36af0c AD |
5801 | |
5802 | function get_score_pic($score) { | |
1cce3aca | 5803 | if ($score > 100) { |
1e36af0c | 5804 | return "score_high.png"; |
1cce3aca AD |
5805 | } else if ($score > 0) { |
5806 | return "score_half_high.png"; | |
5807 | } else if ($score < -100) { | |
1e36af0c | 5808 | return "score_low.png"; |
1cce3aca AD |
5809 | } else if ($score < 0) { |
5810 | return "score_half_low.png"; | |
1e36af0c AD |
5811 | } else { |
5812 | return "score_neutral.png"; | |
5813 | } | |
5814 | } | |
ec92c9d1 | 5815 | |
0745839a | 5816 | function rounded_table_start($classname, $header = " ") { |
ec92c9d1 | 5817 | print "<table width='100%' class='$classname' cellspacing='0' cellpadding='0'>"; |
74d5c8fa | 5818 | print "<tr><td class='c1'> </td><td class='top'>$header</td><td class='c2'> </td></tr>"; |
ec92c9d1 AD |
5819 | print "<tr><td class='left'> </td><td class='content'>"; |
5820 | } | |
5821 | ||
0745839a | 5822 | function rounded_table_end($footer = " ") { |
ec92c9d1 | 5823 | print "</td><td class='right'> </td></tr>"; |
74d5c8fa | 5824 | print "<tr><td class='c4'> </td><td class='bottom'>$footer</td><td class='c3'> </td></tr>"; |
ec92c9d1 AD |
5825 | print "</table>"; |
5826 | } | |
5827 | ||
071ec48f AD |
5828 | function print_label_dlg_common_examples() { |
5829 | ||
5830 | print __("Match ") . " "; | |
5831 | ||
5be2805b AD |
5832 | /* print "<select name=\"label_andor\">"; |
5833 | print "<option value=\"and\">AND</option>"; | |
5834 | print "<option value=\"or\">OR</option>"; | |
5835 | print "</select>"; */ | |
5836 | ||
071ec48f AD |
5837 | print "<select name=\"label_fields\" onchange=\"labelFieldsCheck(this)\">"; |
5838 | print "<option value=\"unread\">".__("Unread articles")."</option>"; | |
5839 | print "<option value=\"updated\">".__("Updated articles")."</option>"; | |
5840 | print "<option value=\"kw_title\">".__("Title contains")."</option>"; | |
5841 | print "<option value=\"kw_content\">".__("Content contains")."</option>"; | |
8c96d4b1 AD |
5842 | print "<option value=\"scoreE\">".__("Score equals")."</option>"; |
5843 | print "<option value=\"scoreG\">".__("Score is greater than")."</option>"; | |
5844 | print "<option value=\"scoreL\">".__("Score is less than")."</option>"; | |
071ec48f AD |
5845 | print "<option value=\"newerH\">".__("Articles newer than X hours")."</option>"; |
5846 | print "<option value=\"newerD\">".__("Articles newer than X days")."</option>"; | |
5847 | ||
5848 | print "</select>"; | |
5849 | ||
5850 | print "<input style=\"display : none\" name=\"label_fields_param\" | |
5851 | size=\"10\">"; | |
5852 | ||
5853 | print " <input type=\"submit\" | |
5854 | onclick=\"return addLabelExample()\" | |
5855 | value=\"".__("Add")."\">"; | |
5856 | } | |
7defa089 AD |
5857 | |
5858 | function feed_has_icon($id) { | |
5859 | return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0; | |
5860 | } | |
f29ba148 AD |
5861 | |
5862 | function init_connection($link) { | |
5863 | if (DB_TYPE == "pgsql") { | |
6fc720fd | 5864 | pg_query($link, "set client_encoding = 'UTF-8'"); |
f29ba148 | 5865 | pg_set_client_encoding("UNICODE"); |
045d0ab8 | 5866 | pg_query($link, "set datestyle = 'ISO, european'"); |
f29ba148 AD |
5867 | } else { |
5868 | if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { | |
5869 | db_query($link, "SET NAMES " . MYSQL_CHARSET); | |
5870 | // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET); | |
5871 | } | |
5872 | } | |
5873 | } | |
5e96ca9d AD |
5874 | |
5875 | function update_feedbrowser_cache($link) { | |
5876 | ||
5877 | $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers | |
5878 | FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf | |
5879 | WHERE tf.feed_url = ttrss_feeds.feed_url | |
5880 | AND (private IS true OR feed_url LIKE '%:%@%/%')) | |
6f483f5f | 5881 | GROUP BY feed_url ORDER BY subscribers DESC LIMIT 200"); |
5e96ca9d AD |
5882 | |
5883 | db_query($link, "BEGIN"); | |
5884 | ||
5885 | db_query($link, "DELETE FROM ttrss_feedbrowser_cache"); | |
5886 | ||
5887 | $count = 0; | |
5888 | ||
5889 | while ($line = db_fetch_assoc($result)) { | |
5890 | $subscribers = db_escape_string($line["subscribers"]); | |
5891 | $feed_url = db_escape_string($line["feed_url"]); | |
5892 | ||
5893 | db_query($link, "INSERT INTO ttrss_feedbrowser_cache | |
5894 | (feed_url, subscribers) VALUES ('$feed_url', '$subscribers')"); | |
5895 | ||
5896 | ++$count; | |
5897 | } | |
5898 | ||
5899 | db_query($link, "COMMIT"); | |
5900 | ||
5901 | return $count; | |
5902 | ||
5903 | } | |
2627f2d0 | 5904 | |
8a4c759e | 5905 | function ccache_zero($link, $feed_id, $owner_uid) { |
2627f2d0 AD |
5906 | db_query($link, "UPDATE ttrss_counters_cache SET |
5907 | value = 0, updated = NOW() WHERE | |
5908 | feed_id = '$feed_id' AND owner_uid = '$owner_uid'"); | |
8a4c759e | 5909 | } |
2627f2d0 | 5910 | |
ad0056a8 AD |
5911 | function ccache_zero_all($link, $owner_uid) { |
5912 | db_query($link, "UPDATE ttrss_counters_cache SET | |
5913 | value = 0 WHERE owner_uid = '$owner_uid'"); | |
5914 | ||
5915 | db_query($link, "UPDATE ttrss_cat_counters_cache SET | |
5916 | value = 0 WHERE owner_uid = '$owner_uid'"); | |
5917 | } | |
5918 | ||
5f4f7adf AD |
5919 | function ccache_update_all($link, $owner_uid) { |
5920 | ||
5921 | if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid)) { | |
5922 | ||
5923 | $result = db_query($link, "SELECT feed_id FROM ttrss_cat_counters_cache | |
5924 | WHERE feed_id > 0 AND owner_uid = '$owner_uid'"); | |
5925 | ||
5926 | while ($line = db_fetch_assoc($result)) { | |
5927 | ccache_update($link, $line["feed_id"], $owner_uid, true); | |
5928 | } | |
5929 | ||
8a4c759e | 5930 | |
8a4c759e | 5931 | } else { |
5f4f7adf AD |
5932 | $result = db_query($link, "SELECT feed_id FROM ttrss_counters_cache |
5933 | WHERE feed_id > 0 AND owner_uid = '$owner_uid'"); | |
8a4c759e | 5934 | |
5f4f7adf AD |
5935 | while ($line = db_fetch_assoc($result)) { |
5936 | print ccache_update($link, $line["feed_id"], $owner_uid); | |
5937 | ||
5938 | } | |
5939 | ||
5940 | } | |
5941 | } | |
2627f2d0 | 5942 | |
6b49a3dd AD |
5943 | function ccache_find($link, $feed_id, $owner_uid, $is_cat = false, |
5944 | $no_update = false) { | |
8a4c759e AD |
5945 | |
5946 | if (!$is_cat) { | |
5947 | $table = "ttrss_counters_cache"; | |
5948 | } else { | |
5949 | $table = "ttrss_cat_counters_cache"; | |
5950 | } | |
5951 | ||
5952 | if (DB_TYPE == "pgsql") { | |
5953 | $date_qpart = "updated > NOW() - INTERVAL '15 minutes'"; | |
5954 | } else if (DB_TYPE == "mysql") { | |
5955 | $date_qpart = "updated > DATE_SUB(NOW(), INTERVAL 15 MINUTE)"; | |
5956 | } | |
5957 | ||
5958 | $result = db_query($link, "SELECT value FROM $table | |
5959 | WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id' | |
37fb651d | 5960 | LIMIT 1"); |
2627f2d0 AD |
5961 | |
5962 | if (db_num_rows($result) == 1) { | |
5963 | return db_fetch_result($result, 0, "value"); | |
5964 | } else { | |
6b49a3dd AD |
5965 | if ($no_update) { |
5966 | return -1; | |
5967 | } else { | |
5968 | return ccache_update($link, $feed_id, $owner_uid, $is_cat); | |
5969 | } | |
2627f2d0 AD |
5970 | } |
5971 | ||
5972 | } | |
5973 | ||
6c2a9b9e | 5974 | function ccache_update($link, $feed_id, $owner_uid, $is_cat = false, |
6b49a3dd AD |
5975 | $update_pcat = true) { |
5976 | ||
5977 | $prev_unread = ccache_find($link, $feed_id, $owner_uid, $is_cat, true); | |
2627f2d0 | 5978 | |
8a4c759e AD |
5979 | if (!$is_cat) { |
5980 | $table = "ttrss_counters_cache"; | |
5981 | } else { | |
5982 | $table = "ttrss_cat_counters_cache"; | |
5983 | } | |
5984 | ||
b6d486a3 | 5985 | if ($is_cat && $feed_id >= 0) { |
37fb651d AD |
5986 | if ($feed_id != 0) { |
5987 | $cat_qpart = "cat_id = '$feed_id'"; | |
5988 | } else { | |
5989 | $cat_qpart = "cat_id IS NULL"; | |
5990 | } | |
5991 | ||
6b49a3dd AD |
5992 | /* Recalculate counters for child feeds */ |
5993 | ||
5994 | $result = db_query($link, "SELECT id FROM ttrss_feeds | |
5995 | WHERE owner_uid = '$owner_uid' AND $cat_qpart"); | |
5996 | ||
5997 | while ($line = db_fetch_assoc($result)) { | |
5998 | ccache_update($link, $line["id"], $owner_uid, false, false); | |
5999 | } | |
6000 | ||
37fb651d AD |
6001 | $result = db_query($link, "SELECT SUM(value) AS sv |
6002 | FROM ttrss_counters_cache, ttrss_feeds | |
6003 | WHERE id = feed_id AND $cat_qpart AND | |
6004 | ttrss_feeds.owner_uid = '$owner_uid'"); | |
6005 | ||
6006 | $unread = db_fetch_result($result, 0, "sv"); | |
6007 | ||
f55b0b12 AD |
6008 | } else { |
6009 | $unread = (int) getFeedArticles($link, $feed_id, $is_cat, true, $owner_uid); | |
37fb651d | 6010 | } |
2627f2d0 | 6011 | |
8a4c759e | 6012 | $result = db_query($link, "SELECT feed_id FROM $table |
2627f2d0 AD |
6013 | WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id' LIMIT 1"); |
6014 | ||
6015 | if (db_num_rows($result) == 1) { | |
8a4c759e | 6016 | db_query($link, "UPDATE $table SET |
2627f2d0 AD |
6017 | value = '$unread', updated = NOW() WHERE |
6018 | feed_id = '$feed_id' AND owner_uid = '$owner_uid'"); | |
6019 | ||
6020 | } else { | |
8a4c759e | 6021 | db_query($link, "INSERT INTO $table |
2627f2d0 AD |
6022 | (feed_id, value, owner_uid, updated) |
6023 | VALUES | |
6024 | ($feed_id, $unread, $owner_uid, NOW())"); | |
6025 | ||
6026 | } | |
6027 | ||
6b49a3dd | 6028 | if ($feed_id > 0 && $prev_unread != $unread) { |
8a4c759e | 6029 | |
37fb651d | 6030 | if (!$is_cat) { |
8a4c759e | 6031 | |
6b49a3dd | 6032 | /* Update parent category */ |
8a4c759e | 6033 | |
6b49a3dd | 6034 | if ($update_pcat) { |
37fb651d | 6035 | |
6b49a3dd AD |
6036 | $result = db_query($link, "SELECT cat_id FROM ttrss_feeds |
6037 | WHERE owner_uid = '$owner_uid' AND id = '$feed_id'"); | |
8a4c759e | 6038 | |
6b49a3dd | 6039 | $cat_id = (int) db_fetch_result($result, 0, "cat_id"); |
37fb651d | 6040 | |
6b49a3dd | 6041 | ccache_update($link, $cat_id, $owner_uid, true); |
6c2a9b9e | 6042 | |
6c2a9b9e | 6043 | } |
8a4c759e | 6044 | } |
5f4f7adf AD |
6045 | } else if ($feed_id < 0) { |
6046 | ccache_update_all($link, $owner_uid); | |
8a4c759e AD |
6047 | } |
6048 | ||
6049 | return $unread; | |
2627f2d0 | 6050 | } |
40d13c28 | 6051 | ?> |