3 /* if ($_GET["debug"]) {
4 define('DEFAULT_ERROR_LEVEL', E_ALL);
6 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
9 require_once 'config.php';
11 function get_translations() {
13 "auto" => "Detect automatically",
15 "fr_FR" => "Français",
17 "zh_CN" => "Simplified Chinese");
22 if (ENABLE_TRANSLATIONS
== true) {
23 require_once "accept-to-gettext.php";
24 require_once "gettext/gettext.inc";
26 function startup_gettext() {
28 # Get locale from Accept-Language header
29 $lang = al2gt(array_keys(get_translations()), "text/html");
31 if (defined('_TRANSLATION_OVERRIDE_DEFAULT')) {
32 $lang = _TRANSLATION_OVERRIDE_DEFAULT
;
35 if ($_COOKIE["ttrss_lang"] && $_COOKIE["ttrss_lang"] != "auto") {
36 $lang = $_COOKIE["ttrss_lang"];
40 _setlocale(LC_MESSAGES
, $lang);
41 _bindtextdomain("messages", "locale");
42 _textdomain("messages");
43 _bind_textdomain_codeset("messages", "UTF-8");
53 function startup_gettext() {
59 require_once 'db-prefs.php';
60 require_once 'compat.php';
61 require_once 'errors.php';
62 require_once 'version.php';
64 define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION
. ')');
65 define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
67 require_once "magpierss/rss_fetch.inc";
68 require_once 'magpierss/rss_utils.inc';
70 include_once "tw/tw-config.php";
71 include_once "tw/tw.php";
72 include_once TW_SETUP
. "paranoya.php";
74 $tw_parser = new twParser();
76 function _debug($msg) {
77 $ts = strftime("%H:%M:%S", time());
81 function purge_feed($link, $feed_id, $purge_interval, $debug = false) {
85 if (DB_TYPE
== "pgsql") {
86 /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE
87 marked = false AND feed_id = '$feed_id' AND
88 (SELECT date_entered FROM ttrss_entries WHERE
89 id = ref_id) < NOW() - INTERVAL '$purge_interval days'"); */
91 $pg_version = get_pgsql_version($link);
93 if (preg_match("/^7\./", $pg_version) ||
preg_match("/^8\.0/", $pg_version)) {
95 $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE
96 ttrss_entries.id = ref_id AND
98 feed_id = '$feed_id' AND
99 ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'");
103 $result = db_query($link, "DELETE FROM ttrss_user_entries
105 WHERE ttrss_entries.id = ref_id AND
107 feed_id = '$feed_id' AND
108 ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'");
111 $rows = pg_affected_rows($result);
115 /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE
116 marked = false AND feed_id = '$feed_id' AND
117 (SELECT date_entered FROM ttrss_entries WHERE
118 id = ref_id) < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); */
120 $result = db_query($link, "DELETE FROM ttrss_user_entries
121 USING ttrss_user_entries, ttrss_entries
122 WHERE ttrss_entries.id = ref_id AND
124 feed_id = '$feed_id' AND
125 ttrss_entries.date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)");
127 $rows = mysql_affected_rows($link);
132 _debug("Purged feed $feed_id ($purge_interval): deleted $rows articles");
136 function global_purge_old_posts($link, $do_output = false, $limit = false) {
138 $random_qpart = sql_random_function();
141 $limit_qpart = "LIMIT $limit";
146 $result = db_query($link,
147 "SELECT id,purge_interval,owner_uid FROM ttrss_feeds
148 ORDER BY $random_qpart $limit_qpart");
150 while ($line = db_fetch_assoc($result)) {
152 $feed_id = $line["id"];
153 $purge_interval = $line["purge_interval"];
154 $owner_uid = $line["owner_uid"];
156 if ($purge_interval == 0) {
158 $tmp_result = db_query($link,
159 "SELECT value FROM ttrss_user_prefs WHERE
160 pref_name = 'PURGE_OLD_DAYS' AND owner_uid = '$owner_uid'");
162 if (db_num_rows($tmp_result) != 0) {
163 $purge_interval = db_fetch_result($tmp_result, 0, "value");
168 // print "Feed $feed_id: purge interval = $purge_interval\n";
171 if ($purge_interval > 0) {
172 purge_feed($link, $feed_id, $purge_interval, $do_output);
176 // purge orphaned posts in main content table
177 db_query($link, "DELETE FROM ttrss_entries WHERE
178 (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
182 function purge_old_posts($link) {
184 $user_id = $_SESSION["uid"];
186 $result = db_query($link, "SELECT id,purge_interval FROM ttrss_feeds
187 WHERE owner_uid = '$user_id'");
189 while ($line = db_fetch_assoc($result)) {
191 $feed_id = $line["id"];
192 $purge_interval = $line["purge_interval"];
194 if ($purge_interval == 0) $purge_interval = get_pref($link, 'PURGE_OLD_DAYS');
196 if ($purge_interval > 0) {
197 purge_feed($link, $feed_id, $purge_interval);
201 // purge orphaned posts in main content table
202 db_query($link, "DELETE FROM ttrss_entries WHERE
203 (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
206 function update_all_feeds($link, $fetch, $user_id = false, $force_daemon = false) {
208 if (WEB_DEMO_MODE
) return;
211 $user_id = $_SESSION["uid"];
212 purge_old_posts($link);
215 // db_query($link, "BEGIN");
217 if (MAX_UPDATE_TIME
> 0) {
218 if (DB_TYPE
== "mysql") {
221 $q_order = "RANDOM()";
224 $q_order = "last_updated DESC";
227 $result = db_query($link, "SELECT feed_url,id,
228 SUBSTRING(last_updated,1,19) AS last_updated,
229 update_interval FROM ttrss_feeds WHERE owner_uid = '$user_id'
234 while ($line = db_fetch_assoc($result)) {
235 $upd_intl = $line["update_interval"];
237 if (!$upd_intl ||
$upd_intl == 0) {
238 $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id, false);
242 // Updates for this feed are disabled
246 if ($fetch ||
(!$line["last_updated"] ||
247 time() - strtotime($line["last_updated"]) > ($upd_intl * 60))) {
249 // print "<!-- feed: ".$line["feed_url"]." -->";
251 update_rss_feed($link, $line["feed_url"], $line["id"], $force_daemon);
253 $upd_elapsed = time() - $upd_start;
255 if (MAX_UPDATE_TIME
> 0 && $upd_elapsed > MAX_UPDATE_TIME
) {
261 // db_query($link, "COMMIT");
265 function fetch_file_contents($url) {
266 if (USE_CURL_FOR_ICONS
) {
267 $tmpfile = tempnam(TMP_DIRECTORY
, "ttrss-tmp");
269 $ch = curl_init($url);
270 $fp = fopen($tmpfile, "w");
273 curl_setopt($ch, CURLOPT_FILE
, $fp);
274 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT
, 15);
275 curl_setopt($ch, CURLOPT_TIMEOUT
, 45);
281 $contents = file_get_contents($tmpfile);
287 return file_get_contents($url);
292 // adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/)
293 // http://dev.wp-plugins.org/file/favatars/trunk/favatars.php
295 function get_favicon_url($url) {
297 if ($html = @fetch_file_contents
($url)) {
299 if ( preg_match('/<link[^>]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $html, $matches)) {
300 // Attempt to grab a favicon link from their webpage url
301 $linkUrl = html_entity_decode($matches[1]);
303 if (substr($linkUrl, 0, 1) == '/') {
304 $urlParts = parse_url($url);
305 $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].$linkUrl;
306 } else if (substr($linkUrl, 0, 7) == 'http://') {
307 $faviconURL = $linkUrl;
308 } else if (substr($url, -1, 1) == '/') {
309 $faviconURL = $url.$linkUrl;
311 $faviconURL = $url.'/'.$linkUrl;
315 // If unsuccessful, attempt to "guess" the favicon location
316 $urlParts = parse_url($url);
317 $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].'/favicon.ico';
321 // Run a test to see if what we have attempted to get actually exists.
322 if(USE_CURL_FOR_ICONS ||
url_validate($faviconURL)) {
329 function url_validate($link) {
331 $url_parts = @parse_url
($link);
333 if ( empty( $url_parts["host"] ) )
336 if ( !empty( $url_parts["path"] ) ) {
337 $documentpath = $url_parts["path"];
342 if ( !empty( $url_parts["query"] ) )
343 $documentpath .= "?" . $url_parts["query"];
345 $host = $url_parts["host"];
346 $port = $url_parts["port"];
351 $socket = @fsockopen
( $host, $port, $errno, $errstr, 30 );
356 fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
358 $http_response = fgets( $socket, 22 );
360 $responses = "/(200 OK)|(30[0-9] Moved)/";
361 if ( preg_match($responses, $http_response) ) {
370 function check_feed_favicon($site_url, $feed, $link) {
371 $favicon_url = get_favicon_url($site_url);
373 # print "FAVICON [$site_url]: $favicon_url\n";
377 $icon_file = ICONS_DIR
. "/$feed.ico";
379 if ($favicon_url && !file_exists($icon_file)) {
380 $contents = fetch_file_contents($favicon_url);
382 $fp = fopen($icon_file, "w");
385 fwrite($fp, $contents);
387 chmod($icon_file, 0644);
391 error_reporting(DEFAULT_ERROR_LEVEL
);
395 function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) {
397 if (DAEMON_REFRESH_ONLY
&& !$_GET["daemon"] && !$ignore_daemon) {
401 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
402 _debug("update_rss_feed: start");
405 $result = db_query($link, "SELECT update_interval,auth_login,auth_pass
406 FROM ttrss_feeds WHERE id = '$feed'");
408 $auth_login = db_fetch_result($result, 0, "auth_login");
409 $auth_pass = db_fetch_result($result, 0, "auth_pass");
411 $update_interval = db_fetch_result($result, 0, "update_interval");
413 if ($update_interval < 0) { return; }
415 $feed = db_escape_string($feed);
417 $fetch_url = $feed_url;
419 if ($auth_login && $auth_pass) {
420 $url_parts = array();
421 preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts);
423 if ($url_parts[1] && $url_parts[2]) {
424 $fetch_url = $url_parts[1] . "://$auth_login:$auth_pass@" . $url_parts[2];
429 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
430 _debug("update_rss_feed: fetching...");
433 if (!defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
437 $rss = fetch_rss($fetch_url);
439 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
440 _debug("update_rss_feed: fetch done, parsing...");
442 error_reporting (DEFAULT_ERROR_LEVEL
);
445 $feed = db_escape_string($feed);
449 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
450 _debug("update_rss_feed: processing feed data...");
453 // db_query($link, "BEGIN");
455 $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid
456 FROM ttrss_feeds WHERE id = '$feed'");
458 $registered_title = db_fetch_result($result, 0, "title");
459 $orig_icon_url = db_fetch_result($result, 0, "icon_url");
460 $orig_site_url = db_fetch_result($result, 0, "site_url");
462 $owner_uid = db_fetch_result($result, 0, "owner_uid");
464 if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid, false)) {
465 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
466 _debug("update_rss_feed: checking favicon...");
468 check_feed_favicon($rss->channel
["link"], $feed, $link);
471 if (!$registered_title ||
$registered_title == "[Unknown]") {
473 $feed_title = db_escape_string($rss->channel
["title"]);
475 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
476 _debug("update_rss_feed: registering title: $feed_title");
479 db_query($link, "UPDATE ttrss_feeds SET
480 title = '$feed_title' WHERE id = '$feed'");
483 $site_url = $rss->channel
["link"];
484 // weird, weird Magpie
485 if (!$site_url) $site_url = db_escape_string($rss->channel
["link_"]);
487 if ($site_url && $orig_site_url != db_escape_string($site_url)) {
488 db_query($link, "UPDATE ttrss_feeds SET
489 site_url = '$site_url' WHERE id = '$feed'");
492 // print "I: " . $rss->channel["image"]["url"];
494 $icon_url = $rss->image
["url"];
496 if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) {
497 $icon_url = db_escape_string($icon_url);
498 db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'");
501 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
502 _debug("update_rss_feed: loading filters...");
507 $result = db_query($link, "SELECT reg_exp,
508 ttrss_filter_types.name AS name,
509 ttrss_filter_actions.name AS action,
512 FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE
514 owner_uid = $owner_uid AND
515 ttrss_filter_types.id = filter_type AND
516 ttrss_filter_actions.id = action_id AND
517 (feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp");
519 while ($line = db_fetch_assoc($result)) {
520 if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
522 $filter["reg_exp"] = $line["reg_exp"];
523 $filter["action"] = $line["action"];
524 $filter["action_param"] = $line["action_param"];
525 $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
527 array_push($filters[$line["name"]], $filter);
530 $iterator = $rss->items
;
532 if (!$iterator ||
!is_array($iterator)) $iterator = $rss->entries
;
533 if (!$iterator ||
!is_array($iterator)) $iterator = $rss;
535 if (!is_array($iterator)) {
536 /* db_query($link, "UPDATE ttrss_feeds
537 SET last_error = 'Parse error: can\'t find any articles.'
538 WHERE id = '$feed'"); */
540 // clear any errors and mark feed as updated if fetched okay
541 // even if it's blank
543 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
544 _debug("update_rss_feed: entry iterator is not an array, no articles?");
547 db_query($link, "UPDATE ttrss_feeds
548 SET last_updated = NOW(), last_error = '' WHERE id = '$feed'");
550 return; // no articles
553 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
554 _debug("update_rss_feed: processing articles...");
557 foreach ($iterator as $item) {
559 $entry_guid = $item["id"];
561 if (!$entry_guid) $entry_guid = $item["guid"];
562 if (!$entry_guid) $entry_guid = $item["link"];
563 if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]);
565 if (defined('DAEMON_EXTENDED_DEBUG')) {
566 _debug("update_rss_feed: guid $entry_guid");
569 if (!$entry_guid) continue;
571 $entry_timestamp = "";
573 $rss_2_date = $item['pubdate'];
574 $rss_1_date = $item['dc']['date'];
575 $atom_date = $item['issued'];
576 if (!$atom_date) $atom_date = $item['updated'];
578 if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date);
579 if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date);
580 if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date);
582 if ($entry_timestamp == "" ||
$entry_timestamp == -1 ||
!$entry_timestamp) {
583 $entry_timestamp = time();
584 $no_orig_date = 'true';
586 $no_orig_date = 'false';
589 $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
591 $entry_title = trim(strip_tags($item["title"]));
593 // strange Magpie workaround
594 $entry_link = $item["link_"];
595 if (!$entry_link) $entry_link = $item["link"];
597 if (!$entry_title) continue;
598 # if (!$entry_link) continue;
600 $entry_link = strip_tags($entry_link);
602 $entry_content = $item["content:escaped"];
604 if (!$entry_content) $entry_content = $item["content:encoded"];
605 if (!$entry_content) $entry_content = $item["content"];
606 if (!$entry_content) $entry_content = $item["atom_content"];
607 if (!$entry_content) $entry_content = $item["summary"];
608 if (!$entry_content) $entry_content = $item["description"];
610 // if (!$entry_content) continue;
613 if (is_array($entry_content)) {
614 $entry_content = $entry_content["encoded"];
615 if (!$entry_content) $entry_content = $entry_content["escaped"];
619 // print_r(htmlspecialchars($entry_content));
622 $entry_content_unescaped = $entry_content;
624 $entry_comments = strip_tags($item["comments"]);
626 $entry_author = db_escape_string(strip_tags($item['dc']['creator']));
628 if ($item['author']) {
630 if (is_array($item['author'])) {
632 if (!$entry_author) {
633 $entry_author = db_escape_string(strip_tags($item['author']['name']));
636 if (!$entry_author) {
637 $entry_author = db_escape_string(strip_tags($item['author']['email']));
641 if (!$entry_author) {
642 $entry_author = db_escape_string(strip_tags($item['author']));
646 if (preg_match('/^[\t\n\r ]*$/', $entry_author)) $entry_author = '';
648 $entry_guid = db_escape_string(strip_tags($entry_guid));
650 $result = db_query($link, "SELECT id FROM ttrss_entries
651 WHERE guid = '$entry_guid'");
653 $entry_content = db_escape_string($entry_content);
655 $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
657 $entry_title = db_escape_string($entry_title);
658 $entry_link = db_escape_string($entry_link);
659 $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250);
660 $entry_author = mb_substr($entry_author, 0, 250);
662 $num_comments = db_escape_string($item["slash"]["comments"]);
664 if (!$num_comments) $num_comments = 0;
666 // parse <category> entries into tags
668 $t_ctr = $item['category#'];
670 $additional_tags = false;
673 $additional_tags = false;
674 } else if ($t_ctr == 1) {
675 $additional_tags = array($item['category']);
677 $additional_tags = array();
678 for ($i = 0; $i <= $t_ctr; $i++
) {
679 if ($item["category#$i"]) {
680 array_push($additional_tags, $item["category#$i"]);
685 // parse <dc:subject> elements
687 $t_ctr = $item['dc']['subject#'];
690 $additional_tags = array($item['dc']['subject']);
691 } else if ($t_ctr > 1) {
692 $additional_tags = array();
693 for ($i = 0; $i <= $t_ctr; $i++
) {
694 if ($item['dc']["subject#$i"]) {
695 array_push($additional_tags, $item['dc']["subject#$i"]);
702 // $entry_content = sanitize_rss($entry_content);
704 if (defined('DAEMON_EXTENDED_DEBUG')) {
705 _debug("update_rss_feed: done collecting data [TITLE:$entry_title]");
708 db_query($link, "BEGIN");
710 if (db_num_rows($result) == 0) {
712 if (defined('DAEMON_EXTENDED_DEBUG')) {
713 _debug("update_rss_feed: base guid not found");
716 // base post entry does not exist, create it
718 $result = db_query($link,
719 "INSERT INTO ttrss_entries
735 '$entry_timestamp_fmt',
744 // we keep encountering the entry in feeds, so we need to
745 // update date_entered column so that we don't get horrible
746 // dupes when the entry gets purged and reinserted again e.g.
747 // in the case of SLOW SLOW OMG SLOW updating feeds
749 $base_entry_id = db_fetch_result($result, 0, "id");
751 db_query($link, "UPDATE ttrss_entries SET date_entered = NOW()
752 WHERE id = '$base_entry_id'");
755 // now it should exist, if not - bad luck then
757 $result = db_query($link, "SELECT
758 id,content_hash,no_orig_date,title,
759 substring(date_entered,1,19) as date_entered,
760 substring(updated,1,19) as updated,
764 WHERE guid = '$entry_guid'");
766 if (db_num_rows($result) == 1) {
768 if (defined('DAEMON_EXTENDED_DEBUG')) {
769 _debug("update_rss_feed: base guid found, checking for user record");
772 // this will be used below in update handler
773 $orig_content_hash = db_fetch_result($result, 0, "content_hash");
774 $orig_title = db_fetch_result($result, 0, "title");
775 $orig_num_comments = db_fetch_result($result, 0, "num_comments");
776 $orig_date_entered = strtotime(db_fetch_result($result,
779 $ref_id = db_fetch_result($result, 0, "id");
781 // check for user post link to main table
783 // do we allow duplicate posts with same GUID in different feeds?
784 if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
785 $dupcheck_qpart = "AND feed_id = '$feed'";
787 $dupcheck_qpart = "";
790 // error_reporting(0);
792 $article_filters = get_article_filters($filters, $entry_title,
793 $entry_content, $entry_link);
795 if (defined('DAEMON_EXTENDED_DEBUG')) {
796 _debug("update_rss_feed: article filters: ");
797 if (count($article_filters) != 0) {
798 print_r($article_filters);
802 if (find_article_filter($article_filters, "filter")) {
806 // error_reporting (DEFAULT_ERROR_LEVEL);
808 $result = db_query($link,
809 "SELECT ref_id FROM ttrss_user_entries WHERE
810 ref_id = '$ref_id' AND owner_uid = '$owner_uid'
813 // okay it doesn't exist - create user entry
814 if (db_num_rows($result) == 0) {
816 if (defined('DAEMON_EXTENDED_DEBUG')) {
817 _debug("update_rss_feed: user record not found, creating...");
820 if (!find_article_filter($article_filters, 'catchup')) {
822 $last_read_qpart = 'NULL';
825 $last_read_qpart = 'NOW()';
828 if (find_article_filter($article_filters, 'mark')) {
834 if (find_article_filter($article_filters, 'publish')) {
837 $published = 'false';
840 $result = db_query($link,
841 "INSERT INTO ttrss_user_entries
842 (ref_id, owner_uid, feed_id, unread, last_read, marked, published)
843 VALUES ('$ref_id', '$owner_uid', '$feed', $unread,
844 $last_read_qpart, $marked, $published)");
847 $post_needs_update = false;
849 if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid, false) &&
850 ($content_hash != $orig_content_hash)) {
851 // print "<!-- [$entry_title] $content_hash vs $orig_content_hash -->";
852 $post_needs_update = true;
855 if (db_escape_string($orig_title) != $entry_title) {
856 $post_needs_update = true;
859 if ($orig_num_comments != $num_comments) {
860 $post_needs_update = true;
863 // this doesn't seem to be very reliable
865 // if ($orig_timestamp != $entry_timestamp && !$orig_no_orig_date) {
866 // $post_needs_update = true;
869 // if post needs update, update it and mark all user entries
870 // linking to this post as updated
871 if ($post_needs_update) {
873 if (defined('DAEMON_EXTENDED_DEBUG')) {
874 _debug("update_rss_feed: post $entry_guid needs update...");
877 // print "<!-- post $orig_title needs update : $post_needs_update -->";
879 db_query($link, "UPDATE ttrss_entries
880 SET title = '$entry_title', content = '$entry_content',
881 content_hash = '$content_hash',
882 num_comments = '$num_comments'
883 WHERE id = '$ref_id'");
885 if (get_pref($link, "MARK_UNREAD_ON_UPDATE", $owner_uid, false)) {
886 db_query($link, "UPDATE ttrss_user_entries
887 SET last_read = null, unread = true WHERE ref_id = '$ref_id'");
889 db_query($link, "UPDATE ttrss_user_entries
890 SET last_read = null WHERE ref_id = '$ref_id' AND unread = false");
896 db_query($link, "COMMIT");
898 if (defined('DAEMON_EXTENDED_DEBUG')) {
899 _debug("update_rss_feed: looking for tags...");
903 // <a href="..." rel="tag">Xorg</a>, //
907 preg_match_all("/<a.*?rel=['\"]tag['\"].*?>([^<]+)<\/a>/i",
908 $entry_content_unescaped, $entry_tags);
910 /* print "<p><br/>$entry_title : $entry_content_unescaped<br>";
911 print_r($entry_tags);
912 print "<br/></p>"; */
914 $entry_tags = $entry_tags[1];
916 # check for manual tags
918 $tag_filter = find_article_filter($article_filters, "tag");
922 $manual_tags = trim_array(split(",", $tag_filter[1]));
924 foreach ($manual_tags as $tag) {
925 if (tag_is_valid($tag)) {
926 array_push($entry_tags, $tag);
931 $boring_tags = trim_array(split(",", mb_strtolower(get_pref($link,
932 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8')));
934 if ($additional_tags && is_array($additional_tags)) {
935 foreach ($additional_tags as $tag) {
936 if (tag_is_valid($tag) &&
937 array_search($tag, $boring_tags) === FALSE) {
938 array_push($entry_tags, $tag);
943 // print "<p>TAGS: "; print_r($entry_tags); print "</p>";
945 if (count($entry_tags) > 0) {
947 db_query($link, "BEGIN");
949 $result = db_query($link, "SELECT id,int_id
950 FROM ttrss_entries,ttrss_user_entries
951 WHERE guid = '$entry_guid'
952 AND feed_id = '$feed' AND ref_id = id
953 AND owner_uid = '$owner_uid'");
955 if (db_num_rows($result) == 1) {
957 $entry_id = db_fetch_result($result, 0, "id");
958 $entry_int_id = db_fetch_result($result, 0, "int_id");
960 foreach ($entry_tags as $tag) {
962 $tag = sanitize_tag($tag);
963 $tag = db_escape_string($tag);
965 if (!tag_is_valid($tag)) continue;
967 $result = db_query($link, "SELECT id FROM ttrss_tags
968 WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND
969 owner_uid = '$owner_uid' LIMIT 1");
971 // print db_fetch_result($result, 0, "id");
973 if ($result && db_num_rows($result) == 0) {
975 db_query($link, "INSERT INTO ttrss_tags
976 (owner_uid,tag_name,post_int_id)
977 VALUES ('$owner_uid','$tag', '$entry_int_id')");
981 db_query($link, "COMMIT");
985 db_query($link, "UPDATE ttrss_feeds
986 SET last_updated = NOW(), last_error = '' WHERE id = '$feed'");
988 // db_query($link, "COMMIT");
991 $error_msg = mb_substr(db_escape_string(magpie_error()), 0, 250);
993 "UPDATE ttrss_feeds SET last_error = '$error_msg',
994 last_updated = NOW() WHERE id = '$feed'");
997 if (defined('DAEMON_EXTENDED_DEBUG')) {
998 _debug("update_rss_feed: done");
1003 function print_select($id, $default, $values, $attributes = "") {
1004 print "<select name=\"$id\" id=\"$id\" $attributes>";
1005 foreach ($values as $v) {
1011 print "<option$sel>$v</option>";
1016 function print_select_hash($id, $default, $values, $attributes = "") {
1017 print "<select name=\"$id\" id='$id' $attributes>";
1018 foreach (array_keys($values) as $v) {
1024 print "<option $sel value=\"$v\">".$values[$v]."</option>";
1030 function get_article_filters($filters, $title, $content, $link) {
1033 if ($filters["title"]) {
1034 foreach ($filters["title"] as $filter) {
1035 $reg_exp = $filter["reg_exp"];
1036 $inverse = $filter["inverse"];
1037 if ((!$inverse && preg_match("/$reg_exp/i", $title)) ||
1038 ($inverse && !preg_match("/$reg_exp/i", $title))) {
1040 array_push($matches, array($filter["action"], $filter["action_param"]));
1045 if ($filters["content"]) {
1046 foreach ($filters["content"] as $filter) {
1047 $reg_exp = $filter["reg_exp"];
1048 $inverse = $filter["inverse"];
1050 if ((!$inverse && preg_match("/$reg_exp/i", $content)) ||
1051 ($inverse && !preg_match("/$reg_exp/i", $content))) {
1053 array_push($matches, array($filter["action"], $filter["action_param"]));
1058 if ($filters["both"]) {
1059 foreach ($filters["both"] as $filter) {
1060 $reg_exp = $filter["reg_exp"];
1061 $inverse = $filter["inverse"];
1064 if (!preg_match("/$reg_exp/i", $title) ||
!preg_match("/$reg_exp/i", $content)) {
1065 array_push($matches, array($filter["action"], $filter["action_param"]));
1068 if (preg_match("/$reg_exp/i", $title) ||
preg_match("/$reg_exp/i", $content)) {
1069 array_push($matches, array($filter["action"], $filter["action_param"]));
1075 if ($filters["link"]) {
1076 $reg_exp = $filter["reg_exp"];
1077 foreach ($filters["link"] as $filter) {
1078 $reg_exp = $filter["reg_exp"];
1079 $inverse = $filter["inverse"];
1081 if ((!$inverse && preg_match("/$reg_exp/i", $link)) ||
1082 ($inverse && !preg_match("/$reg_exp/i", $link))) {
1084 array_push($matches, array($filter["action"], $filter["action_param"]));
1092 function find_article_filter($filters, $filter_name) {
1093 foreach ($filters as $f) {
1094 if ($f[0] == $filter_name) {
1101 function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
1102 $rtl_content = false, $last_updated = false, $last_error = false) {
1104 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1105 $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"$icon_file\">";
1107 $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"images/blank_icon.gif\">";
1111 $rtl_tag = "dir=\"rtl\"";
1113 $rtl_tag = "dir=\"ltr\"";
1116 $error_notify_msg = "";
1119 $link_title = "Error: $last_error ($last_updated)";
1120 $error_notify_msg = "(Error)";
1121 } else if ($last_updated) {
1122 $link_title = "Updated: $last_updated";
1125 $feed = "<a title=\"$link_title\" id=\"FEEDL-$feed_id\"
1126 href=\"javascript:viewfeed('$feed_id', '', false, '', false, 0);\">$feed_title</a>";
1128 print "<li id=\"FEEDR-$feed_id\" class=\"$class\">";
1129 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1133 print "<span $rtl_tag id=\"FEEDN-$feed_id\">$feed</span>";
1138 $fctr_class = "class=\"invisible\"";
1141 print " <span $rtl_tag $fctr_class id=\"FEEDCTR-$feed_id\">
1142 (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>";
1144 if (get_pref($link, "EXTENDED_FEEDLIST")) {
1145 print "<div class=\"feedExtInfo\">
1146 <span id=\"FLUPD-$feed_id\">$last_updated $error_notify_msg</span></div>";
1153 function getmicrotime() {
1154 list($usec, $sec) = explode(" ",microtime());
1155 return ((float)$usec +
(float)$sec);
1158 function print_radio($id, $default, $true_is, $values, $attributes = "") {
1159 foreach ($values as $v) {
1166 if ($v == $true_is) {
1167 $sel .= " value=\"1\"";
1169 $sel .= " value=\"0\"";
1172 print "<input class=\"noborder\"
1173 type=\"radio\" $sel $attributes name=\"$id\"> $v ";
1178 function initialize_user_prefs($link, $uid) {
1180 $uid = db_escape_string($uid);
1182 db_query($link, "BEGIN");
1184 $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs");
1186 $u_result = db_query($link, "SELECT pref_name
1187 FROM ttrss_user_prefs WHERE owner_uid = '$uid'");
1189 $active_prefs = array();
1191 while ($line = db_fetch_assoc($u_result)) {
1192 array_push($active_prefs, $line["pref_name"]);
1195 while ($line = db_fetch_assoc($result)) {
1196 if (array_search($line["pref_name"], $active_prefs) === FALSE) {
1197 // print "adding " . $line["pref_name"] . "<br>";
1199 db_query($link, "INSERT INTO ttrss_user_prefs
1200 (owner_uid,pref_name,value) VALUES
1201 ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')");
1206 db_query($link, "COMMIT");
1210 function lookup_user_id($link, $user) {
1212 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1215 if (db_num_rows($result) == 1) {
1216 return db_fetch_result($result, 0, "id");
1222 function http_authenticate_user($link) {
1224 error_log("http_authenticate_user: ".$_SERVER["PHP_AUTH_USER"]."\n", 3, '/tmp/tt-rss.log');
1226 if (!$_SERVER["PHP_AUTH_USER"]) {
1228 header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"');
1229 header('HTTP/1.0 401 Unauthorized');
1233 $auth_result = authenticate_user($link,
1234 $_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]);
1236 if (!$auth_result) {
1237 header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"');
1238 header('HTTP/1.0 401 Unauthorized');
1246 function authenticate_user($link, $login, $password, $force_auth = false) {
1248 if (!SINGLE_USER_MODE
) {
1250 $pwd_hash = 'SHA1:' . sha1($password);
1252 if ($force_auth && defined('_DEBUG_USER_SWITCH')) {
1253 $query = "SELECT id,login,access_level
1254 FROM ttrss_users WHERE
1257 $query = "SELECT id,login,access_level
1258 FROM ttrss_users WHERE
1259 login = '$login' AND pwd_hash = '$pwd_hash'";
1262 $result = db_query($link, $query);
1264 if (db_num_rows($result) == 1) {
1265 $_SESSION["uid"] = db_fetch_result($result, 0, "id");
1266 $_SESSION["name"] = db_fetch_result($result, 0, "login");
1267 $_SESSION["access_level"] = db_fetch_result($result, 0, "access_level");
1269 db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
1272 $user_theme = get_user_theme_path($link);
1274 $_SESSION["theme"] = $user_theme;
1275 $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
1277 initialize_user_prefs($link, $_SESSION["uid"]);
1286 $_SESSION["uid"] = 1;
1287 $_SESSION["name"] = "admin";
1289 $user_theme = get_user_theme_path($link);
1291 $_SESSION["theme"] = $user_theme;
1292 $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
1294 initialize_user_prefs($link, $_SESSION["uid"]);
1300 function make_password($length = 8) {
1303 $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ";
1307 while ($i < $length) {
1308 $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
1310 if (!strstr($password, $char)) {
1318 // this is called after user is created to initialize default feeds, labels
1321 // user preferences are checked on every login, not here
1323 function initialize_user($link, $uid) {
1325 db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
1326 values ('$uid','unread = true', 'Unread articles')");
1328 db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
1329 values ('$uid','last_read is null and unread = false', 'Updated articles')");
1331 db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url)
1332 values ('$uid', 'Tiny Tiny RSS: New Releases',
1333 'http://tt-rss.spb.ru/releases.rss')");
1335 db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url)
1336 values ('$uid', 'Tiny Tiny RSS: Forum',
1337 'http://tt-rss.spb.ru/forum/rss.php')");
1340 function logout_user() {
1342 if (isset($_COOKIE[session_name()])) {
1343 setcookie(session_name(), '', time()-42000, '/');
1347 function get_script_urlpath() {
1348 return preg_replace('/\/[^\/]*$/', "", $_SERVER["REQUEST_URI"]);
1351 function validate_session($link) {
1352 if (SESSION_CHECK_ADDRESS
&& $_SESSION["uid"]) {
1353 if ($_SESSION["ip_address"]) {
1354 if ($_SESSION["ip_address"] != $_SERVER["REMOTE_ADDR"]) {
1355 $_SESSION["login_error_msg"] = "Session failed to validate (incorrect IP)";
1361 /* if ($_SESSION["cookie_lifetime"] && $_SESSION["uid"]) {
1363 //print_r($_SESSION);
1365 if (time() > $_SESSION["cookie_lifetime"]) {
1373 function login_sequence($link, $mobile = false) {
1374 if (!SINGLE_USER_MODE
) {
1376 if (defined('_DEBUG_USER_SWITCH') && $_SESSION["uid"]) {
1377 $swu = db_escape_string($_REQUEST["swu"]);
1379 $_SESSION["prefs_cache"] = false;
1380 return authenticate_user($link, $swu, null, true);
1384 $login_action = $_POST["login_action"];
1386 # try to authenticate user if called from login form
1387 if ($login_action == "do_login") {
1388 $login = $_POST["login"];
1389 $password = $_POST["password"];
1390 $remember_me = $_POST["remember_me"];
1392 if (authenticate_user($link, $login, $password)) {
1393 $_POST["password"] = "";
1395 $_SESSION["language"] = $_POST["language"];
1397 header("Location: " . $_SERVER["REQUEST_URI"]);
1402 $_SESSION["login_error_msg"] = "Incorrect username or password";
1406 // print session_id();
1407 // print_r($_SESSION);
1409 if (!$_SESSION["uid"] ||
!validate_session($link)) {
1410 render_login_form($link, $mobile);
1413 /* bump login timestamp */
1414 db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
1417 if ($_SESSION["language"] && SESSION_COOKIE_LIFETIME
> 0) {
1418 setcookie("ttrss_lang", $_SESSION["language"],
1419 time() + SESSION_COOKIE_LIFETIME
);
1424 return authenticate_user($link, "admin", null);
1428 function truncate_string($str, $max_len) {
1429 if (mb_strlen($str, "utf-8") > $max_len - 3) {
1430 return mb_substr($str, 0, $max_len, "utf-8") . "...";
1436 function get_user_theme_path($link) {
1437 $result = db_query($link, "SELECT theme_path
1439 ttrss_themes,ttrss_users
1440 WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]);
1441 if (db_num_rows($result) != 0) {
1442 return db_fetch_result($result, 0, "theme_path");
1448 function smart_date_time($timestamp) {
1449 if (date("Y.m.d", $timestamp) == date("Y.m.d")) {
1450 return date("G:i", $timestamp);
1451 } else if (date("Y", $timestamp) == date("Y")) {
1452 return date("M d, G:i", $timestamp);
1454 return date("Y/m/d, G:i", $timestamp);
1458 function smart_date($timestamp) {
1459 if (date("Y.m.d", $timestamp) == date("Y.m.d")) {
1461 } else if (date("Y", $timestamp) == date("Y")) {
1462 return date("D m", $timestamp);
1464 return date("Y/m/d", $timestamp);
1468 function sql_bool_to_string($s) {
1469 if ($s == "t" ||
$s == "1") {
1476 function sql_bool_to_bool($s) {
1477 if ($s == "t" ||
$s == "1") {
1485 function toggleEvenOdd($a) {
1492 function sanity_check($link) {
1497 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
1498 $schema_version = db_fetch_result($result, 0, "schema_version");
1500 if ($schema_version != SCHEMA_VERSION
) {
1504 if (DB_TYPE
== "mysql") {
1505 $result = db_query($link, "SELECT true", false);
1506 if (db_num_rows($result) != 1) {
1511 error_reporting (DEFAULT_ERROR_LEVEL
);
1513 if ($error_code != 0) {
1514 print_error_xml($error_code);
1521 function file_is_locked($filename) {
1523 $fp = fopen($filename, "r");
1524 error_reporting(DEFAULT_ERROR_LEVEL
);
1526 if (flock($fp, LOCK_EX | LOCK_NB
)) {
1527 flock($fp, LOCK_UN
);
1537 function make_lockfile($filename) {
1538 $fp = fopen($filename, "w");
1540 if (flock($fp, LOCK_EX | LOCK_NB
)) {
1547 function make_stampfile($filename) {
1548 $fp = fopen($filename, "w");
1550 if (flock($fp, LOCK_EX | LOCK_NB
)) {
1551 fwrite($fp, time() . "\n");
1552 flock($fp, LOCK_UN
);
1560 function read_stampfile($filename) {
1563 $fp = fopen($filename, "r");
1564 error_reporting (DEFAULT_ERROR_LEVEL
);
1566 if (flock($fp, LOCK_EX
)) {
1567 $stamp = fgets($fp);
1568 flock($fp, LOCK_UN
);
1576 function sql_random_function() {
1577 if (DB_TYPE
== "mysql") {
1584 function catchup_feed($link, $feed, $cat_view) {
1586 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
1591 $cat_qpart = "cat_id = '$feed'";
1593 $cat_qpart = "cat_id IS NULL";
1596 $tmp_result = db_query($link, "SELECT id
1597 FROM ttrss_feeds WHERE $cat_qpart AND owner_uid = " .
1600 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1602 $tmp_feed = $tmp_line["id"];
1604 db_query($link, "UPDATE ttrss_user_entries
1605 SET unread = false,last_read = NOW()
1606 WHERE feed_id = '$tmp_feed' AND owner_uid = " . $_SESSION["uid"]);
1609 } else if ($feed > 0) {
1611 $tmp_result = db_query($link, "SELECT id
1612 FROM ttrss_feeds WHERE parent_feed = '$feed'
1613 ORDER BY cat_id,title");
1615 $parent_ids = array();
1617 if (db_num_rows($tmp_result) > 0) {
1618 while ($p = db_fetch_assoc($tmp_result)) {
1619 array_push($parent_ids, "feed_id = " . $p["id"]);
1622 $children_qpart = implode(" OR ", $parent_ids);
1624 db_query($link, "UPDATE ttrss_user_entries
1625 SET unread = false,last_read = NOW()
1626 WHERE (feed_id = '$feed' OR $children_qpart)
1627 AND owner_uid = " . $_SESSION["uid"]);
1630 db_query($link, "UPDATE ttrss_user_entries
1631 SET unread = false,last_read = NOW()
1632 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1635 } else if ($feed < 0 && $feed > -10) { // special, like starred
1638 db_query($link, "UPDATE ttrss_user_entries
1639 SET unread = false,last_read = NOW()
1640 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
1644 db_query($link, "UPDATE ttrss_user_entries
1645 SET unread = false,last_read = NOW()
1646 WHERE published = true AND owner_uid = ".$_SESSION["uid"]);
1651 $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE");
1653 if (DB_TYPE
== "pgsql") {
1654 $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
1656 $match_part .= " AND date_entered > DATE_SUB(NOW(),
1657 INTERVAL $intl HOUR) ";
1660 db_query($link, "UPDATE ttrss_user_entries
1661 SET unread = false,last_read = NOW()
1662 WHERE $match_part AND owner_uid = ".$_SESSION["uid"]);
1665 } else if ($feed < -10) { // label
1667 // TODO make this more efficient
1669 $label_id = -$feed - 11;
1671 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1672 WHERE id = '$label_id'");
1675 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
1677 db_query($link, "BEGIN");
1679 $tmp2_result = db_query($link,
1683 ttrss_user_entries,ttrss_entries,ttrss_feeds
1685 ref_id = ttrss_entries.id AND
1686 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1688 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
1690 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
1691 db_query($link, "UPDATE
1694 unread = false, last_read = NOW()
1696 int_id = " . $tmp_line["int_id"]);
1699 db_query($link, "COMMIT");
1701 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
1702 SET unread = false,last_read = NOW()
1705 AND owner_uid = ".$_SESSION["uid"]); */
1709 db_query($link, "BEGIN");
1711 $tag_name = db_escape_string($feed);
1713 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
1714 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
1716 while ($line = db_fetch_assoc($result)) {
1717 db_query($link, "UPDATE ttrss_user_entries SET
1718 unread = false, last_read = NOW()
1719 WHERE int_id = " . $line["post_int_id"]);
1721 db_query($link, "COMMIT");
1725 function update_generic_feed($link, $feed, $cat_view) {
1729 $cat_qpart = "cat_id = '$feed'";
1731 $cat_qpart = "cat_id IS NULL";
1734 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
1735 WHERE $cat_qpart AND owner_uid = " . $_SESSION["uid"]);
1737 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1738 $feed_url = $tmp_line["feed_url"];
1739 update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON
);
1743 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
1744 WHERE id = '$feed'");
1745 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
1746 update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON
);
1750 function getAllCounters($link, $omode = "flc") {
1751 /* getLabelCounters($link);
1752 getFeedCounters($link);
1753 getTagCounters($link);
1754 getGlobalCounters($link);
1755 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1756 getCategoryCounters($link);
1759 if (!$omode) $omode = "flc";
1761 getGlobalCounters($link);
1763 if (strchr($omode, "l")) getLabelCounters($link);
1764 if (strchr($omode, "f")) getFeedCounters($link);
1765 if (strchr($omode, "t")) getTagCounters($link);
1766 if (strchr($omode, "c")) {
1767 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1768 getCategoryCounters($link);
1773 function getCategoryCounters($link) {
1774 # two special categories are -1 and -2 (all virtuals; all labels)
1776 $ctr = getCategoryUnread($link, -1);
1778 print "<counter type=\"category\" id=\"-1\" counter=\"$ctr\"/>";
1780 $ctr = getCategoryUnread($link, -2);
1782 print "<counter type=\"category\" id=\"-2\" counter=\"$ctr\"/>";
1784 $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id)
1785 FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id
1786 AND unread = true)) AS unread FROM ttrss_feeds
1788 hidden = false AND owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
1790 while ($line = db_fetch_assoc($result)) {
1791 $line["cat_id"] = sprintf("%d", $line["cat_id"]);
1792 print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"".
1793 $line["unread"]."\"/>";
1797 function getCategoryUnread($link, $cat) {
1802 $cat_query = "cat_id = '$cat'";
1804 $cat_query = "cat_id IS NULL";
1807 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query
1809 AND owner_uid = " . $_SESSION["uid"]);
1811 $cat_feeds = array();
1812 while ($line = db_fetch_assoc($result)) {
1813 array_push($cat_feeds, "feed_id = " . $line["id"]);
1816 if (count($cat_feeds) == 0) return 0;
1818 $match_part = implode(" OR ", $cat_feeds);
1820 $result = db_query($link, "SELECT COUNT(int_id) AS unread
1821 FROM ttrss_user_entries
1822 WHERE unread = true AND ($match_part) AND owner_uid = " . $_SESSION["uid"]);
1826 # this needs to be rewritten
1827 while ($line = db_fetch_assoc($result)) {
1828 $unread +
= $line["unread"];
1832 } else if ($cat == -1) {
1833 return getFeedUnread($link, -1) +
getFeedUnread($link, -2) +
getFeedUnread($link, -3);
1834 } else if ($cat == -2) {
1836 $rv = getLabelCounters($link, false, true);
1839 foreach (array_keys($rv) as $k) {
1841 $ctr +
= $rv[$k]["counter"];
1849 function getFeedUnread($link, $feed, $is_cat = false) {
1850 $n_feed = sprintf("%d", $feed);
1853 return getCategoryUnread($link, $n_feed);
1854 } else if ($n_feed == -1) {
1855 $match_part = "marked = true";
1856 } else if ($n_feed == -2) {
1857 $match_part = "published = true";
1858 } else if ($n_feed == -3) {
1859 $match_part = "unread = true";
1861 $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE");
1863 if (DB_TYPE
== "pgsql") {
1864 $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
1866 $match_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
1869 } else if ($n_feed > 0) {
1871 $result = db_query($link, "SELECT id FROM ttrss_feeds
1872 WHERE parent_feed = '$n_feed'
1874 AND owner_uid = " . $_SESSION["uid"]);
1876 if (db_num_rows($result) > 0) {
1878 $linked_feeds = array();
1879 while ($line = db_fetch_assoc($result)) {
1880 array_push($linked_feeds, "feed_id = " . $line["id"]);
1883 array_push($linked_feeds, "feed_id = $n_feed");
1885 $match_part = implode(" OR ", $linked_feeds);
1887 $result = db_query($link, "SELECT COUNT(int_id) AS unread
1888 FROM ttrss_user_entries
1889 WHERE unread = true AND ($match_part)
1890 AND owner_uid = " . $_SESSION["uid"]);
1894 # this needs to be rewritten
1895 while ($line = db_fetch_assoc($result)) {
1896 $unread +
= $line["unread"];
1902 $match_part = "feed_id = '$n_feed'";
1904 } else if ($feed < -10) {
1906 $label_id = -$feed - 11;
1908 $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE
1909 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
1911 $match_part = db_fetch_result($result, 0, "sql_exp");
1916 $result = db_query($link, "SELECT count(int_id) AS unread
1917 FROM ttrss_user_entries,ttrss_feeds,ttrss_entries WHERE
1918 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1919 ttrss_user_entries.ref_id = ttrss_entries.id AND
1920 ttrss_feeds.hidden = false AND
1921 unread = true AND ($match_part) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
1925 $result = db_query($link, "SELECT COUNT(post_int_id) AS unread
1926 FROM ttrss_tags,ttrss_user_entries
1927 WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND
1928 ttrss_tags.owner_uid = " . $_SESSION["uid"]);
1931 $unread = db_fetch_result($result, 0, "unread");
1936 /* FIXME this needs reworking */
1938 function getGlobalUnread($link, $user_id = false) {
1941 $user_id = $_SESSION["uid"];
1944 $result = db_query($link, "SELECT count(ttrss_entries.id) as c_id FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
1945 WHERE unread = true AND
1946 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1947 ttrss_user_entries.ref_id = ttrss_entries.id AND
1949 ttrss_user_entries.owner_uid = '$user_id'");
1950 $c_id = db_fetch_result($result, 0, "c_id");
1954 function getGlobalCounters($link, $global_unread = -1) {
1955 if ($global_unread == -1) {
1956 $global_unread = getGlobalUnread($link);
1958 print "<counter type=\"global\" id='global-unread'
1959 counter='$global_unread'/>";
1961 $result = db_query($link, "SELECT COUNT(id) AS fn FROM
1962 ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
1964 $subscribed_feeds = db_fetch_result($result, 0, "fn");
1966 print "<counter type=\"global\" id='subscribed-feeds'
1967 counter='$subscribed_feeds'/>";
1971 function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
1974 if (!$_SESSION["tctr_last_value"]) {
1975 $_SESSION["tctr_last_value"] = array();
1979 $old_counters = $_SESSION["tctr_last_value"];
1981 $tctrs_modified = false;
1983 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
1984 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
1985 ttrss_user_entries.ref_id = ttrss_entries.id AND
1986 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
1987 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
1989 select tag_name,0 as count FROM ttrss_tags
1990 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
1992 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
1993 FROM ttrss_user_entries WHERE int_id = post_int_id
1994 AND unread = true)) AS count FROM ttrss_tags
1995 WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name
1996 ORDER BY count DESC LIMIT 55");
2000 while ($line = db_fetch_assoc($result)) {
2001 $tags[$line["tag_name"]] +
= $line["count"];
2004 foreach (array_keys($tags) as $tag) {
2005 $unread = $tags[$tag];
2007 $tag = htmlspecialchars($tag);
2009 if (!$smart_mode ||
$old_counters[$tag] != $unread) {
2010 $old_counters[$tag] = $unread;
2011 $tctrs_modified = true;
2012 print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>";
2017 if ($smart_mode && $tctrs_modified) {
2018 $_SESSION["tctr_last_value"] = $old_counters;
2023 function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS
, $ret_mode = false) {
2026 if (!$_SESSION["lctr_last_value"]) {
2027 $_SESSION["lctr_last_value"] = array();
2033 $old_counters = $_SESSION["lctr_last_value"];
2034 $lctrs_modified = false;
2036 $count = getFeedUnread($link, -1);
2039 print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>";
2041 $ret_arr["-1"]["counter"] = $count;
2042 $ret_arr["-1"]["description"] = __("Starred articles");
2045 $count = getFeedUnread($link, -2);
2048 print "<counter type=\"label\" id=\"-2\" counter=\"$count\"/>";
2050 $ret_arr["-2"]["counter"] = $count;
2051 $ret_arr["-2"]["description"] = __("Published articles");
2054 $count = getFeedUnread($link, -3);
2057 print "<counter type=\"label\" id=\"-3\" counter=\"$count\"/>";
2059 $ret_arr["-3"]["counter"] = $count;
2060 $ret_arr["-3"]["description"] = __("Fresh articles");
2064 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
2065 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
2067 while ($line = db_fetch_assoc($result)) {
2069 $id = -$line["id"] - 11;
2071 $label_name = $line["description"];
2073 error_reporting (0);
2075 $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_user_entries,ttrss_entries,ttrss_feeds
2076 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
2077 ttrss_feeds.hidden = false AND
2078 ttrss_user_entries.feed_id = ttrss_feeds.id AND
2079 ttrss_user_entries.ref_id = ttrss_entries.id AND
2080 ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
2082 $count = db_fetch_result($tmp_result, 0, "count");
2084 if (!$smart_mode ||
$old_counters[$id] != $count) {
2085 $old_counters[$id] = $count;
2086 $lctrs_modified = true;
2088 print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>";
2090 $ret_arr[$id]["counter"] = $count;
2091 $ret_arr[$id]["description"] = $label_name;
2095 error_reporting (DEFAULT_ERROR_LEVEL
);
2098 if ($smart_mode && $lctrs_modified) {
2099 $_SESSION["lctr_last_value"] = $old_counters;
2105 /* function getFeedCounter($link, $id) {
2107 $result = db_query($link, "SELECT
2108 count(id) as count,last_error
2109 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
2110 WHERE feed_id = '$id' AND unread = true
2111 AND ttrss_user_entries.feed_id = ttrss_feeds.id
2112 AND ttrss_user_entries.ref_id = ttrss_entries.id");
2114 $count = db_fetch_result($result, 0, "count");
2115 $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error"));
2117 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>";
2120 function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
2123 if (!$_SESSION["fctr_last_value"]) {
2124 $_SESSION["fctr_last_value"] = array();
2128 $old_counters = $_SESSION["fctr_last_value"];
2130 /* $result = db_query($link, "SELECT id,last_error,parent_feed,
2131 SUBSTRING(last_updated,1,19) AS last_updated,
2133 FROM ttrss_entries,ttrss_user_entries
2134 WHERE feed_id = ttrss_feeds.id AND
2135 ttrss_user_entries.ref_id = ttrss_entries.id
2136 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
2137 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . "
2138 AND parent_feed IS NULL"); */
2140 $result = db_query($link, "SELECT ttrss_feeds.id,
2141 SUBSTRING(ttrss_feeds.last_updated,1,19) AS last_updated,
2143 COUNT(ttrss_entries.id) AS count
2145 LEFT JOIN ttrss_user_entries ON (ttrss_user_entries.feed_id = ttrss_feeds.id
2146 AND ttrss_user_entries.owner_uid = ttrss_feeds.owner_uid
2147 AND ttrss_user_entries.unread = true)
2148 LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id)
2149 WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]."
2150 AND parent_feed IS NULL
2151 GROUP BY ttrss_feeds.id, ttrss_feeds.title, ttrss_feeds.last_updated, last_error");
2153 $fctrs_modified = false;
2155 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
2157 while ($line = db_fetch_assoc($result)) {
2160 $count = $line["count"];
2161 $last_error = htmlspecialchars($line["last_error"]);
2163 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
2164 $last_updated = smart_date_time(strtotime($line["last_updated"]));
2166 $last_updated = date($short_date, strtotime($line["last_updated"]));
2169 $has_img = is_file(ICONS_DIR
. "/$id.ico");
2171 $tmp_result = db_query($link,
2172 "SELECT id,COUNT(unread) AS unread
2173 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
2174 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
2175 WHERE parent_feed = '$id' AND unread = true GROUP BY ttrss_feeds.id");
2177 if (db_num_rows($tmp_result) > 0) {
2178 while ($l = db_fetch_assoc($tmp_result)) {
2179 $count +
= $l["unread"];
2183 if (!$smart_mode ||
$old_counters[$id] != $count) {
2184 $old_counters[$id] = $count;
2185 $fctrs_modified = true;
2188 $error_part = "error=\"$last_error\"";
2194 $has_img_part = "hi=\"$has_img\"";
2199 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part updated=\"$last_updated\"/>";
2203 if ($smart_mode && $fctrs_modified) {
2204 $_SESSION["fctr_last_value"] = $old_counters;
2208 function get_script_dt_add() {
2209 if (strpos(VERSION
, ".99") === false) {
2216 function get_pgsql_version($link) {
2217 $result = db_query($link, "SELECT version() AS version");
2218 $version = split(" ", db_fetch_result($result, 0, "version"));
2222 function print_error_xml($code, $add_msg = "") {
2225 $error_msg = $ERRORS[$code];
2228 $error_msg = "$error_msg; $add_msg";
2231 print "<rpc-reply>";
2232 print "<error error-code=\"$code\" error-msg=\"$error_msg\"/>";
2233 print "</rpc-reply>";
2236 function subscribe_to_feed($link, $feed_link, $cat_id = 0,
2237 $auth_login = '', $auth_pass = '') {
2239 # check for feed:http://url
2240 $feed_link = trim(preg_replace("/^feed:/", "", $feed_link));
2242 # check for feed://URL
2243 if (strpos($feed_link, "//") === 0) {
2244 $feed_link = "http:$feed_link";
2247 if ($feed_link == "") return;
2249 if ($cat_id == "0" ||
!$cat_id) {
2250 $cat_qpart = "NULL";
2252 $cat_qpart = "'$cat_id'";
2255 $result = db_query($link,
2256 "SELECT id FROM ttrss_feeds
2257 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
2259 if (db_num_rows($result) == 0) {
2261 $result = db_query($link,
2262 "INSERT INTO ttrss_feeds
2263 (owner_uid,feed_url,title,cat_id, auth_login,auth_pass)
2264 VALUES ('".$_SESSION["uid"]."', '$feed_link',
2265 '[Unknown]', $cat_qpart, '$auth_login', '$auth_pass')");
2267 $result = db_query($link,
2268 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
2269 AND owner_uid = " . $_SESSION["uid"]);
2271 $feed_id = db_fetch_result($result, 0, "id");
2274 update_rss_feed($link, $feed_link, $feed_id, true);
2283 function print_feed_select($link, $id, $default_id = "",
2284 $attributes = "", $include_all_feeds = true) {
2286 print "<select id=\"$id\" name=\"$id\" $attributes>";
2287 if ($include_all_feeds) {
2288 print "<option value=\"0\">".__('All feeds')."</option>";
2291 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2292 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2294 if (db_num_rows($result) > 0 && $include_all_feeds) {
2295 print "<option disabled>--------</option>";
2298 while ($line = db_fetch_assoc($result)) {
2299 if ($line["id"] == $default_id) {
2300 $is_selected = "selected";
2304 printf("<option $is_selected value='%d'>%s</option>",
2305 $line["id"], htmlspecialchars($line["title"]));
2311 function print_feed_cat_select($link, $id, $default_id = "",
2312 $attributes = "", $include_all_cats = true) {
2314 print "<select id=\"$id\" name=\"$id\" $attributes>";
2316 if ($include_all_cats) {
2317 print "<option value=\"0\">".__('Uncategorized')."</option>";
2320 $result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
2321 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2323 if (db_num_rows($result) > 0 && $include_all_cats) {
2324 print "<option disabled>--------</option>";
2327 while ($line = db_fetch_assoc($result)) {
2328 if ($line["id"] == $default_id) {
2329 $is_selected = "selected";
2333 printf("<option $is_selected value='%d'>%s</option>",
2334 $line["id"], htmlspecialchars($line["title"]));
2340 function checkbox_to_sql_bool($val) {
2341 return ($val == "on") ?
"true" : "false";
2344 function getFeedCatTitle($link, $id) {
2346 return __("Special");
2347 } else if ($id < -10) {
2348 return __("Labels");
2349 } else if ($id > 0) {
2350 $result = db_query($link, "SELECT ttrss_feed_categories.title
2351 FROM ttrss_feeds, ttrss_feed_categories WHERE ttrss_feeds.id = '$id' AND
2352 cat_id = ttrss_feed_categories.id");
2353 if (db_num_rows($result) == 1) {
2354 return db_fetch_result($result, 0, "title");
2356 return __("Uncategorized");
2359 return "getFeedCatTitle($id) failed";
2364 function getFeedTitle($link, $id) {
2366 return __("Starred articles");
2367 } else if ($id == -2) {
2368 return __("Published articles");
2369 } else if ($id == -3) {
2370 return __("Fresh articles");
2371 } else if ($id < -10) {
2372 $label_id = -10 - $id;
2373 $result = db_query($link, "SELECT description FROM ttrss_labels WHERE id = '$label_id'");
2374 if (db_num_rows($result) == 1) {
2375 return db_fetch_result($result, 0, "description");
2377 return "Unknown label ($label_id)";
2380 } else if ($id > 0) {
2381 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$id'");
2382 if (db_num_rows($result) == 1) {
2383 return db_fetch_result($result, 0, "title");
2385 return "Unknown feed ($id)";
2388 return "getFeedTitle($id) failed";
2393 function get_session_cookie_name() {
2394 return ((!defined('TTRSS_SESSION_NAME')) ?
"ttrss_sid" : TTRSS_SESSION_NAME
);
2397 function print_init_params($link) {
2398 print "<init-params>";
2399 if ($_SESSION["stored-params"]) {
2400 foreach (array_keys($_SESSION["stored-params"]) as $key) {
2402 $value = htmlspecialchars($_SESSION["stored-params"][$key]);
2403 print "<param key=\"$key\" value=\"$value\"/>";
2408 print "<param key=\"daemon_enabled\" value=\"" . ENABLE_UPDATE_DAEMON
. "\"/>";
2409 print "<param key=\"feeds_frame_refresh\" value=\"" . FEEDS_FRAME_REFRESH
. "\"/>";
2410 print "<param key=\"daemon_refresh_only\" value=\"" . DAEMON_REFRESH_ONLY
. "\"/>";
2412 print "<param key=\"on_catchup_show_next_feed\" value=\"" .
2413 get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED") . "\"/>";
2415 print "<param key=\"hide_read_feeds\" value=\"" .
2416 (int) get_pref($link, "HIDE_READ_FEEDS") . "\"/>";
2418 print "<param key=\"feeds_sort_by_unread\" value=\"" .
2419 (int) get_pref($link, "FEEDS_SORT_BY_UNREAD") . "\"/>";
2421 print "<param key=\"confirm_feed_catchup\" value=\"" .
2422 (int) get_pref($link, "CONFIRM_FEED_CATCHUP") . "\"/>";
2424 print "<param key=\"cdm_auto_catchup\" value=\"" .
2425 (int) get_pref($link, "CDM_AUTO_CATCHUP") . "\"/>";
2427 print "<param key=\"icons_url\" value=\"" . ICONS_URL
. "\"/>";
2429 print "<param key=\"cookie_lifetime\" value=\"" . SESSION_COOKIE_LIFETIME
. "\"/>";
2431 print "<param key=\"default_view_mode\" value=\"" .
2432 get_pref($link, "_DEFAULT_VIEW_MODE") . "\"/>";
2434 print "<param key=\"default_view_limit\" value=\"" .
2435 (int) get_pref($link, "_DEFAULT_VIEW_LIMIT") . "\"/>";
2437 print "<param key=\"prefs_active_tab\" value=\"" .
2438 get_pref($link, "_PREFS_ACTIVE_TAB") . "\"/>";
2440 print "<param key=\"infobox_disable_overlay\" value=\"" .
2441 get_pref($link, "_INFOBOX_DISABLE_OVERLAY") . "\"/>";
2443 print "<param key=\"icons_location\" value=\"" .
2446 print "</init-params>";
2449 function print_runtime_info($link) {
2450 print "<runtime-info>";
2451 if (ENABLE_UPDATE_DAEMON
) {
2452 print "<param key=\"daemon_is_running\" value=\"".
2453 sprintf("%d", file_is_locked("update_daemon.lock")) . "\"/>";
2455 if ($_SESSION["daemon_stamp_check"] +
600 < time()) {
2457 $stamp = (int)read_stampfile("update_daemon.stamp");
2460 if ($stamp +
86400*3 < time()) {
2461 print "<param key=\"daemon_stamp_ok\" value=\"0\"/>";
2463 print "<param key=\"daemon_stamp_ok\" value=\"1\"/>";
2466 $stamp_fmt = date("Y.m.d, G:i", $stamp);
2468 print "<param key=\"daemon_stamp\" value=\"$stamp_fmt\"/>";
2471 $_SESSION["daemon_stamp_check"] = time();
2475 if (CHECK_FOR_NEW_VERSION
&& $_SESSION["access_level"] >= 10) {
2477 if ($_SESSION["last_version_check"] +
7200 < time()) {
2478 $new_version_details = check_for_update($link);
2480 print "<param key=\"new_version_available\" value=\"".
2481 sprintf("%d", $new_version_details != ""). "\"/>";
2483 $_SESSION["last_version_check"] = time();
2487 print "</runtime-info>";
2490 function getSearchSql($search, $match_on) {
2492 $search_query_part = "";
2494 $keywords = split(" ", $search);
2495 $query_keywords = array();
2497 if ($match_on == "both") {
2499 foreach ($keywords as $k) {
2500 array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%')
2501 OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
2504 $search_query_part = implode("AND", $query_keywords) . " AND ";
2506 } else if ($match_on == "title") {
2508 foreach ($keywords as $k) {
2509 array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))");
2512 $search_query_part = implode("AND", $query_keywords) . " AND ";
2514 } else if ($match_on == "content") {
2516 foreach ($keywords as $k) {
2517 array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
2521 $search_query_part = implode("AND", $query_keywords);
2523 return $search_query_part;
2526 function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0) {
2528 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
2532 $search_query_part = getSearchSql($search, $match_on);
2533 $search_query_part .= " AND ";
2536 $search_query_part = "";
2539 $view_query_part = "";
2541 if ($view_mode == "adaptive") {
2543 $view_query_part = " ";
2544 } else if ($feed != -1) {
2545 $unread = getFeedUnread($link, $feed, $cat_view);
2547 $view_query_part = " unread = true AND ";
2552 if ($view_mode == "marked") {
2553 $view_query_part = " marked = true AND ";
2556 if ($view_mode == "unread") {
2557 $view_query_part = " unread = true AND ";
2561 $limit_query_part = "LIMIT " . $limit;
2564 $vfeed_query_part = "";
2566 // override query strategy and enable feed display when searching globally
2567 if ($search && $search_mode == "all_feeds") {
2568 $query_strategy_part = "ttrss_entries.id > 0";
2569 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2570 } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
2571 $query_strategy_part = "ttrss_entries.id > 0";
2572 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
2573 id = feed_id) as feed_title,";
2574 } else if ($feed >= 0 && $search && $search_mode == "this_cat") {
2576 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2578 $tmp_result = false;
2581 $tmp_result = db_query($link, "SELECT id
2582 FROM ttrss_feeds WHERE cat_id = '$feed'");
2584 $tmp_result = db_query($link, "SELECT id
2585 FROM ttrss_feeds WHERE cat_id = (SELECT cat_id FROM ttrss_feeds
2586 WHERE id = '$feed') AND id != '$feed'");
2589 $cat_siblings = array();
2591 if (db_num_rows($tmp_result) > 0) {
2592 while ($p = db_fetch_assoc($tmp_result)) {
2593 array_push($cat_siblings, "feed_id = " . $p["id"]);
2596 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
2597 $feed, implode(" OR ", $cat_siblings));
2600 $query_strategy_part = "ttrss_entries.id > 0";
2603 } else if ($feed >= 0) {
2608 $query_strategy_part = "cat_id = '$feed'";
2610 $query_strategy_part = "cat_id IS NULL";
2613 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2616 $tmp_result = db_query($link, "SELECT id
2617 FROM ttrss_feeds WHERE parent_feed = '$feed'
2618 ORDER BY cat_id,title");
2620 $parent_ids = array();
2622 if (db_num_rows($tmp_result) > 0) {
2623 while ($p = db_fetch_assoc($tmp_result)) {
2624 array_push($parent_ids, "feed_id = " . $p["id"]);
2627 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
2628 $feed, implode(" OR ", $parent_ids));
2630 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2632 $query_strategy_part = "feed_id = '$feed'";
2635 } else if ($feed == -1) { // starred virtual feed
2636 $query_strategy_part = "marked = true";
2637 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2638 } else if ($feed == -2) { // published virtual feed
2639 $query_strategy_part = "published = true";
2640 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2641 } else if ($feed == -3) { // fresh virtual feed
2642 $query_strategy_part = "unread = true";
2644 $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE");
2646 if (DB_TYPE
== "pgsql") {
2647 $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
2649 $query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
2652 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2653 } else if ($feed <= -10) { // labels
2654 $label_id = -$feed - 11;
2656 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
2657 WHERE id = '$label_id'");
2659 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
2661 if (!$query_strategy_part) {
2665 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2667 $query_strategy_part = "id > 0"; // dumb
2670 if (get_pref($link, 'REVERSE_HEADLINES')) {
2671 $order_by = "updated";
2673 $order_by = "updated DESC";
2676 if ($override_order) {
2677 $order_by = $override_order;
2682 if ($search && $search_mode == "all_feeds") {
2683 $feed_title = __("Search results")." ($search)";
2684 } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
2685 $feed_title = __("Search results")." ($search, $feed)";
2686 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
2687 $feed_title = $feed;
2688 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
2693 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
2694 WHERE id = '$feed' AND owner_uid = $owner_uid");
2695 $feed_title = db_fetch_result($result, 0, "title");
2697 $feed_title = __("Uncategorized");
2701 $feed_title = __("Searched for")." $search ($feed_title)";
2706 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
2707 WHERE id = '$feed' AND owner_uid = $owner_uid");
2709 $feed_title = db_fetch_result($result, 0, "title");
2710 $feed_site_url = db_fetch_result($result, 0, "site_url");
2711 $last_error = db_fetch_result($result, 0, "last_error");
2714 $feed_title = __("Searched for") . " $search ($feed_title)";
2718 } else if ($feed == -1) {
2719 $feed_title = __("Starred articles");
2720 } else if ($feed == -2) {
2721 $feed_title = __("Published articles");
2722 } else if ($feed == -3) {
2723 $feed_title = __("Fresh articles");
2724 } else if ($feed < -10) {
2725 $label_id = -$feed - 11;
2726 $result = db_query($link, "SELECT description FROM ttrss_labels
2727 WHERE id = '$label_id'");
2728 $feed_title = db_fetch_result($result, 0, "description");
2731 $feed_title = __("Searched for") . " $search ($feed_title)";
2737 if ($feed < -10) error_reporting (0);
2739 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
2742 $feed_kind = "Feeds";
2744 $feed_kind = "Labels";
2747 $content_query_part = "content as content_preview,";
2749 if ($limit_query_part) {
2750 $offset_query_part = "OFFSET $offset";
2755 ttrss_entries.id,ttrss_entries.title,
2757 unread,feed_id,marked,published,link,last_read,
2758 SUBSTRING(last_read,1,19) as last_read_noms,
2761 SUBSTRING(updated,1,19) as updated_noms,
2764 ttrss_entries,ttrss_user_entries,ttrss_feeds
2766 ttrss_feeds.hidden = false AND
2767 ttrss_user_entries.feed_id = ttrss_feeds.id AND
2768 ttrss_user_entries.ref_id = ttrss_entries.id AND
2769 ttrss_user_entries.owner_uid = '$owner_uid' AND
2772 $query_strategy_part ORDER BY $order_by
2773 $limit_query_part $offset_query_part";
2775 $result = db_query($link, $query);
2777 if ($_GET["debug"]) print $query;
2782 $feed_kind = "Tags";
2784 $result = db_query($link, "SELECT
2786 ttrss_entries.id as id,title,
2789 marked,link,last_read,
2790 SUBSTRING(last_read,1,19) as last_read_noms,
2793 SUBSTRING(updated,1,19) as updated_noms
2795 ttrss_entries,ttrss_user_entries,ttrss_tags
2797 ref_id = ttrss_entries.id AND
2798 ttrss_user_entries.owner_uid = '$owner_uid' AND
2799 post_int_id = int_id AND tag_name = '$feed' AND
2802 $query_strategy_part ORDER BY $order_by
2803 $limit_query_part");
2806 return array($result, $feed_title, $feed_site_url, $last_error);
2810 function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat,
2811 $search, $search_mode, $match_on) {
2813 $qfh_ret = queryFeedHeadlines($link, $feed,
2814 30, false, $is_cat, $search, $search_mode, $match_on, "updated DESC", 0,
2817 $result = $qfh_ret[0];
2818 $feed_title = htmlspecialchars($qfh_ret[1]);
2819 $feed_site_url = $qfh_ret[2];
2820 $last_error = $qfh_ret[3];
2822 // if (!$feed_site_url) $feed_site_url = "http://localhost/";
2824 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>
2825 <?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\"?>
2826 <rss version=\"2.0\">
2828 <title>$feed_title</title>
2829 <link>$feed_site_url</link>
2830 <description>Feed generated by Tiny Tiny RSS</description>";
2832 while ($line = db_fetch_assoc($result)) {
2834 print "<guid>" . htmlspecialchars($line["guid"]) . "</guid>";
2835 print "<link>" . htmlspecialchars($line["link"]) . "</link>";
2837 $tags = get_article_tags($link, $line["id"], $owner_uid);
2839 foreach ($tags as $tag) {
2840 print "<category>" . htmlspecialchars($tag) . "</category>";
2843 $rfc822_date = date('r', strtotime($line["updated"]));
2845 print "<pubDate>$rfc822_date</pubDate>";
2848 htmlspecialchars($line["title"]) . "</title>";
2850 print "<description><![CDATA[" .
2851 $line["content_preview"] . "]]></description>";
2856 print "</channel></rss>";
2860 function getCategoryTitle($link, $cat_id) {
2862 if ($cat_id == -1) {
2863 return __("Special");
2864 } else if ($cat_id == -2) {
2865 return __("Labels");
2868 $result = db_query($link, "SELECT title FROM ttrss_feed_categories WHERE
2871 if (db_num_rows($result) == 1) {
2872 return db_fetch_result($result, 0, "title");
2874 return "Uncategorized";
2879 // http://ru2.php.net/strip-tags
2881 function strip_tags_long($textstring, $allowed){
2882 while($textstring != strip_tags($textstring, $allowed))
2884 while (strlen($textstring) != 0)
2886 if (strlen($textstring) > 1024) {
2889 $otherlen = strlen($textstring);
2891 $temptext = strip_tags(substr($textstring,0,$otherlen), $allowed);
2892 $safetext .= $temptext;
2893 $textstring = substr_replace($textstring,'',0,$otherlen);
2895 $textstring = $safetext;
2901 function sanitize_rss($link, $str, $force_strip_tags = false) {
2904 if (get_pref($link, "STRIP_UNSAFE_TAGS") ||
$force_strip_tags) {
2906 global $tw_paranoya_setup;
2908 $res = $tw_parser->strip_tags($res, $tw_paranoya_setup);
2910 // $res = preg_replace("/\r\n|\n|\r/", "", $res);
2911 // $res = strip_tags_long($res, "<p><a><i><em><b><strong><blockquote><br><img><div><span>");
2917 function send_headlines_digests($link, $limit = 100) {
2919 if (!DIGEST_ENABLE
) return false;
2921 $user_limit = DIGEST_EMAIL_LIMIT
;
2924 print "Sending digests, batch of max $user_limit users, days = $days, headline limit = $limit\n\n";
2926 if (DB_TYPE
== "pgsql") {
2927 $interval_query = "last_digest_sent < NOW() - INTERVAL '$days days'";
2928 } else if (DB_TYPE
== "mysql") {
2929 $interval_query = "last_digest_sent < DATE_SUB(NOW(), INTERVAL $days DAY)";
2932 $result = db_query($link, "SELECT id,email FROM ttrss_users
2933 WHERE email != '' AND (last_digest_sent IS NULL OR $interval_query)");
2935 while ($line = db_fetch_assoc($result)) {
2936 if (get_pref($link, 'DIGEST_ENABLE', $line['id'], false)) {
2937 print "Sending digest for UID:" . $line['id'] . " - " . $line["email"] . " ... ";
2939 $tuple = prepare_headlines_digest($link, $line["id"], $days, $limit);
2940 $digest = $tuple[0];
2941 $headlines_count = $tuple[1];
2943 if ($headlines_count > 0) {
2944 $rc = mail($line["login"] . " <" . $line["email"] . ">",
2945 "[tt-rss] New headlines for last 24 hours", $digest,
2946 "From: " . MAIL_FROM
. "\n".
2947 "Content-Type: text/plain; charset=\"utf-8\"\n".
2948 "Content-Transfer-Encoding: 8bit\n");
2950 db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW()
2951 WHERE id = " . $line["id"]);
2953 print "No headlines\n";
2958 // $digest = prepare_headlines_digest($link, $user_id, $days, $limit);
2962 function prepare_headlines_digest($link, $user_id, $days = 1, $limit = 100) {
2963 $tmp = __("New headlines for last 24 hours, as of ") . date("Y/m/d H:m") . "\n";
2964 $tmp .= "=======================================================\n\n";
2966 if (DB_TYPE
== "pgsql") {
2967 $interval_query = "ttrss_entries.date_entered > NOW() - INTERVAL '$days days'";
2968 } else if (DB_TYPE
== "mysql") {
2969 $interval_query = "ttrss_entries.date_entered > DATE_SUB(NOW(), INTERVAL $days DAY)";
2972 $result = db_query($link, "SELECT ttrss_entries.title,
2973 ttrss_feeds.title AS feed_title,
2976 SUBSTRING(last_updated,1,19) AS last_updated
2978 ttrss_user_entries,ttrss_entries,ttrss_feeds
2980 ref_id = ttrss_entries.id AND feed_id = ttrss_feeds.id
2981 AND include_in_digest = true
2983 AND ttrss_user_entries.owner_uid = $user_id
2984 AND unread = true ORDER BY ttrss_feeds.title, date_entered DESC
2987 $cur_feed_title = "";
2989 $headlines_count = db_num_rows($result);
2991 while ($line = db_fetch_assoc($result)) {
2992 $updated = smart_date_time(strtotime($line["last_updated"]));
2993 $feed_title = $line["feed_title"];
2995 if ($cur_feed_title != $feed_title) {
2996 $cur_feed_title = $feed_title;
2998 $tmp .= "$feed_title\n\n";
3001 $tmp .= " * " . trim($line["title"]) . " - $updated\n";
3002 $tmp .= " " . trim($line["link"]) . "\n";
3007 $tmp .= __("You have been sent this email because you have enabled daily digests in Tiny Tiny RSS at ") .
3008 DIGEST_HOSTNAME
. "\n".
3009 __("To unsubscribe, visit your configuration options or contact instance owner.\n");
3012 return array($tmp, $headlines_count);
3015 function check_for_update($link, $brief_fmt = true) {
3016 $releases_feed = "http://tt-rss.spb.ru/releases.rss";
3018 if (!CHECK_FOR_NEW_VERSION ||
$_SESSION["access_level"] < 10) {
3023 $rss = fetch_rss($releases_feed);
3024 error_reporting (DEFAULT_ERROR_LEVEL
);
3028 $items = $rss->items
;
3030 if (!$items ||
!is_array($items)) $items = $rss->entries
;
3031 if (!$items ||
!is_array($items)) $items = $rss;
3033 if (!is_array($items) ||
count($items) == 0) {
3037 $latest_item = $items[0];
3039 $latest_version = trim(preg_replace("/(Milestone)|(completed)/", "", $latest_item["title"]));
3041 $release_url = sanitize_rss($link, $latest_item["link"]);
3042 $content = sanitize_rss($link, $latest_item["description"]);
3044 if (version_compare(VERSION
, $latest_version) == -1) {
3046 return format_notice("<a href=\"javascript:showBlockElement('milestoneDetails')\">
3047 New version of Tiny-Tiny RSS ($latest_version) is available (click for details)</a>
3048 <div id=\"milestoneDetails\">$content</div>");
3050 return "New version of Tiny-Tiny RSS ($latest_version) is available:
3051 <div class='milestoneDetails'>$content</div>
3052 Visit <a target=\"_new\" href=\"http://tt-rss.spb.ru/\">official site</a> for
3053 download and update information.";
3060 function markArticlesById($link, $ids, $cmode) {
3064 foreach ($ids as $id) {
3065 array_push($tmp_ids, "ref_id = '$id'");
3068 $ids_qpart = join(" OR ", $tmp_ids);
3071 db_query($link, "UPDATE ttrss_user_entries SET
3072 marked = false,last_read = NOW()
3073 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3074 } else if ($cmode == 1) {
3075 db_query($link, "UPDATE ttrss_user_entries SET
3077 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3079 db_query($link, "UPDATE ttrss_user_entries SET
3080 marked = NOT marked,last_read = NOW()
3081 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3085 function publishArticlesById($link, $ids, $cmode) {
3089 foreach ($ids as $id) {
3090 array_push($tmp_ids, "ref_id = '$id'");
3093 $ids_qpart = join(" OR ", $tmp_ids);
3096 db_query($link, "UPDATE ttrss_user_entries SET
3097 published = false,last_read = NOW()
3098 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3099 } else if ($cmode == 1) {
3100 db_query($link, "UPDATE ttrss_user_entries SET
3102 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3104 db_query($link, "UPDATE ttrss_user_entries SET
3105 published = NOT published,last_read = NOW()
3106 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3110 function catchupArticlesById($link, $ids, $cmode) {
3114 foreach ($ids as $id) {
3115 array_push($tmp_ids, "ref_id = '$id'");
3118 $ids_qpart = join(" OR ", $tmp_ids);
3121 db_query($link, "UPDATE ttrss_user_entries SET
3122 unread = false,last_read = NOW()
3123 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3124 } else if ($cmode == 1) {
3125 db_query($link, "UPDATE ttrss_user_entries SET
3127 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3129 db_query($link, "UPDATE ttrss_user_entries SET
3130 unread = NOT unread,last_read = NOW()
3131 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3135 function catchupArticleById($link, $id, $cmode) {
3138 db_query($link, "UPDATE ttrss_user_entries SET
3139 unread = false,last_read = NOW()
3140 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
3141 } else if ($cmode == 1) {
3142 db_query($link, "UPDATE ttrss_user_entries SET
3144 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
3146 db_query($link, "UPDATE ttrss_user_entries SET
3147 unread = NOT unread,last_read = NOW()
3148 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
3152 function make_guid_from_title($title) {
3153 return preg_replace("/[ \"\',.:;]/", "-",
3154 mb_strtolower(strip_tags($title), 'utf-8'));
3157 function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
3158 $bottom = false, $rtl_content = false, $feed_id = 0,
3159 $is_cat = false, $search = false, $match_on = false,
3160 $search_mode = false, $offset = 0, $limit = 0) {
3162 $user_page_offset = $offset +
1;
3165 $class = "headlinesSubToolbar";
3166 $tid = "headlineActionsTop";
3168 $class = "headlinesSubToolbar";
3169 $tid = "headlineActionsBottom";
3172 print "<table class=\"$class\" id=\"$tid\"
3173 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
3181 $page_prev_link = "javascript:viewFeedGoPage(-1)";
3182 $page_next_link = "javascript:viewFeedGoPage(1)";
3183 $page_first_link = "javascript:viewFeedGoPage(0)";
3185 $catchup_page_link = "javascript:catchupPage()";
3186 $catchup_feed_link = "javascript:catchupCurrentFeed()";
3187 $catchup_sel_link = "javascript:catchupSelection()";
3189 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
3191 $sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)";
3192 $sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)";
3193 $sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)";
3195 $tog_unread_link = "javascript:selectionToggleUnread()";
3196 $tog_marked_link = "javascript:selectionToggleMarked()";
3197 $tog_published_link = "javascript:selectionTogglePublished()";
3201 $sel_all_link = "javascript:cdmSelectArticles('all')";
3202 $sel_unread_link = "javascript:cdmSelectArticles('unread')";
3203 $sel_none_link = "javascript:cdmSelectArticles('none')";
3205 $tog_unread_link = "javascript:selectionToggleUnread(true)";
3206 $tog_marked_link = "javascript:selectionToggleMarked(true)";
3207 $tog_published_link = "javascript:selectionTogglePublished(true)";
3211 if (strpos($_SESSION["client.userAgent"], "MSIE") === false) {
3213 print "<td class=\"headlineActions$rtl_cpart\">
3214 <ul class=\"headlineDropdownMenu\">
3217 <a href=\"$sel_all_link\">".__('All')."</a>,
3218 <a href=\"$sel_unread_link\">".__('Unread')."</a>,
3219 <a href=\"$sel_none_link\">".__('None')."</a></li>
3220 <li class=\"vsep\"> </li>
3221 <li class=\"top\">".__('Toggle')."<ul>
3222 <li onclick=\"$tog_unread_link\">".__('Unread')."</li>
3223 <li onclick=\"$tog_marked_link\">".__('Starred')."</li>
3224 <li onclick=\"$tog_published_link\">".__('Published')."</li>
3226 <li class=\"vsep\"> </li>
3227 <li class=\"top\"><a href=\"$catchup_page_link\">".__('Mark as read')."</a><ul>
3228 <li onclick=\"$catchup_sel_link\">".__('Selection')."</li>
3229 <!-- <li onclick=\"$catchup_page_link\">".__('This page')."</li> -->
3230 <li><span class=\"insensitive\">--------</span></li>
3231 <li onclick=\"catchupRelativeToArticle(0)\">".__("Above active article")."</li>
3232 <li onclick=\"catchupRelativeToArticle(1)\">".__("Below active article")."</li>
3233 <li><span class=\"insensitive\">--------</span></li>
3234 <li onclick=\"$catchup_feed_link\">".__('Entire feed')."</li></ul></li>
3237 $enable_pagination = get_pref($link, "_PREFS_ENABLE_PAGINATION");
3239 if ($limit != 0 && !$search && $enable_pagination) {
3241 <li class=\"vsep\"> </li>
3242 <li class=\"top\"><a href=\"$page_next_link\">".__('Next page')."</a><ul>
3243 <li onclick=\"$page_prev_link\">".__('Previous page')."</li>
3244 <li onclick=\"$page_first_link\">".__('First page')."</li></ul></li>
3248 if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS
) {
3250 <li class=\"vsep\"> </li>
3252 <a href=\"javascript:labelFromSearch('$search', '$search_mode',
3253 '$match_on', '$feed_id', '$is_cat');\">
3254 ".__('Convert to label')."</a></td>";
3260 // old style subtoolbar:
3262 print "<td class=\"headlineActions$rtl_cpart\">".
3264 <a href=\"$sel_all_link\">".__('All')."</a>,
3265 <a href=\"$sel_unread_link\">".__('Unread')."</a>,
3266 <a href=\"$sel_none_link\">".__('None')."</a>
3268 __('Toggle:')." <a href=\"$tog_unread_link\">".__('Unread')."</a>,
3269 <a href=\"$tog_marked_link\">".__('Starred')."</a>
3271 __('Mark as read:')."
3272 <a href=\"#\" onclick=\"$catchup_page_link\">".__('Page')."</a>,
3273 <a href=\"#\" onclick=\"$catchup_feed_link\">".__('Feed')."</a>";
3275 if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS
) {
3278 <a href=\"javascript:labelFromSearch('$search', '$search_mode',
3279 '$match_on', '$feed_id', '$is_cat');\">
3280 ".__('Convert to label')."</a>";
3287 /* if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
3288 print "<td class=\"headlineActions$rtl_cpart\">
3289 <a href=\"javascript:labelFromSearch('$search', '$search_mode',
3290 '$match_on', '$feed_id', '$is_cat');\">
3291 ".__('Convert to Label')."</a></td>";
3294 print "<td class=\"headlineTitle$rtl_cpart\">";
3296 if ($feed_site_url) {
3298 $target = "target=\"_new\"";
3300 print "<a $target href=\"$feed_site_url\">".
3301 truncate_string($feed_title,30)."</a>";
3307 $search_q = "&q=$search&m=$match_on&smode=$search_mode";
3310 if ($user_page_offset > 1) {
3311 print " [$user_page_offset] ";
3317 href=\"backend.php?op=rss&id=$feed_id&is_cat=$is_cat$search_q\">
3318 <img class=\"noborder\"
3319 alt=\"".__('Generated feed')."\" src=\"images/feed-icon-12x12.png\">
3324 print "</tr></table>";
3328 function printCategoryHeader($link, $cat_id, $hidden = false, $can_browse = true) {
3330 $tmp_category = getCategoryTitle($link, $cat_id);
3331 $cat_unread = getCategoryUnread($link, $cat_id);
3334 $holder_style = "display:none;";
3341 $catctr_class = ($cat_unread > 0) ?
"catCtrHasUnread" : "catCtrNoUnread";
3343 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
3344 <a id=\"FCATN-$cat_id\" href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>";
3347 print "<a href=\"#\" onclick=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">";
3349 print "<span id=\"FCAP-$cat_id\">";
3352 print " <span id=\"FCATCTR-$cat_id\" title=\"Click to browse category\"
3353 class=\"$catctr_class\">($cat_unread)</span> $ellipsis";
3363 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\" style='$holder_style'>";
3366 function outputFeedList($link, $tags = false) {
3368 print "<ul class=\"feedList\" id=\"feedList\">";
3370 $owner_uid = $_SESSION["uid"];
3374 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3376 if ($_COOKIE["ttrss_vf_vclps"] == 1) {
3379 $cat_hidden = false;
3382 # print "<li class=\"feedCat\">".__('Special')."</li>";
3383 # print "<li id=\"feedCatHolder\" class=\"feedCatHolder\"><ul class=\"feedCatList\">";
3384 # print "<li class=\"feedCat\">".
3385 # "<a id=\"FCATN--1\" href=\"javascript:toggleCollapseCat(-1)\">".
3386 # __('Special')."</a> <span id='FCAP--1'>$ellipsis</span></li>";
3388 # print "<li id=\"feedCatHolder\" class=\"feedCatHolder\">
3389 # <ul class=\"feedCatList\" id='FCATLIST--1' style='$holder_style'>";
3391 # $cat_unread = getCategoryUnread($link, -1);
3392 # $tmp_category = __("Special");
3393 # $catctr_class = ($cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread";
3395 printCategoryHeader($link, -1, $cat_hidden, false);
3398 $num_starred = getFeedUnread($link, -1);
3399 $num_published = getFeedUnread($link, -2);
3400 $num_fresh = getFeedUnread($link, -3);
3404 if ($num_fresh > 0) $class .= "Unread";
3406 printFeedEntry(-3, $class, __("Fresh articles"), $num_fresh,
3407 "images/fresh.png", $link);
3411 if ($num_starred > 0) $class .= "Unread";
3413 printFeedEntry(-1, $class, __("Starred articles"), $num_starred,
3414 "images/mark_set.png", $link);
3418 if ($num_published > 0) $class .= "Unread";
3420 printFeedEntry(-2, $class, __("Published articles"), $num_published,
3421 "images/pub_set.png", $link);
3423 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3429 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
3431 $result = db_query($link, "SELECT id,sql_exp,description FROM
3432 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
3434 if (db_num_rows($result) > 0) {
3435 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3437 if ($_COOKIE["ttrss_vf_lclps"] == 1) {
3440 $cat_hidden = false;
3443 printCategoryHeader($link, -2, $cat_hidden, false);
3445 # print "<li class=\"feedCat\">".
3446 # "<a id=\"FCATN--2\" href=\"javascript:toggleCollapseCat(-2)\">".
3447 # __('Labels')."</a> <span id='FCAP--2'>$ellipsis</span></li>";
3449 # print "<li id=\"feedCatHolder\" class=\"feedCatHolder\"><ul class=\"feedCatList\" id='FCATLIST--2' style='$holder_style'>";
3451 print "<li><hr></li>";
3455 while ($line = db_fetch_assoc($result)) {
3457 error_reporting (0);
3459 $label_id = -$line['id'] - 11;
3460 $count = getFeedUnread($link, $label_id);
3468 error_reporting (DEFAULT_ERROR_LEVEL
);
3470 printFeedEntry($label_id,
3471 $class, $line["description"],
3472 $count, "images/label.png", $link);
3476 if (db_num_rows($result) > 0) {
3477 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3484 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
3485 print "<li><hr></li>";
3488 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3489 if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
3490 $order_by_qpart = "category,unread DESC,title";
3492 $order_by_qpart = "category,title";
3495 if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
3496 $order_by_qpart = "unread DESC,title";
3498 $order_by_qpart = "title";
3502 $result = db_query($link, "SELECT ttrss_feeds.*,
3503 SUBSTRING(last_updated,1,19) AS last_updated_noms,
3504 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
3505 WHERE feed_id = ttrss_feeds.id AND unread = true
3506 AND ttrss_user_entries.ref_id = ttrss_entries.id
3507 AND owner_uid = '$owner_uid') as unread,
3509 ttrss_feed_categories.title AS category,
3510 ttrss_feed_categories.collapsed
3511 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
3512 ON (ttrss_feed_categories.id = cat_id)
3514 ttrss_feeds.hidden = false AND
3515 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
3516 ORDER BY $order_by_qpart");
3518 $actid = $_GET["actid"];
3528 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3530 while ($line = db_fetch_assoc($result)) {
3532 $feed = trim($line["title"]);
3534 if (!$feed) $feed = "[Untitled]";
3536 $feed_id = $line["id"];
3538 $subop = $_GET["subop"];
3540 $unread = $line["unread"];
3542 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3543 $last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
3545 $last_updated = date($short_date, strtotime($line["last_updated_noms"]));
3548 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
3551 $rtl_tag = "dir=\"RTL\"";
3556 $tmp_result = db_query($link,
3557 "SELECT id,COUNT(unread) AS unread
3558 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
3559 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
3560 WHERE parent_feed = '$feed_id' AND unread = true
3561 GROUP BY ttrss_feeds.id");
3563 if (db_num_rows($tmp_result) > 0) {
3564 while ($l = db_fetch_assoc($tmp_result)) {
3565 $unread +
= $l["unread"];
3569 $cat_id = $line["cat_id"];
3571 $tmp_category = $line["category"];
3573 if (!$tmp_category) {
3574 $tmp_category = __("Uncategorized");
3577 // $class = ($lnum % 2) ? "even" : "odd";
3579 if ($line["last_error"]) {
3585 if ($unread > 0) $class .= "Unread";
3587 if ($actid == $feed_id) {
3588 $class .= "Selected";
3591 $total_unread +
= $unread;
3593 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
3599 $category = $tmp_category;
3601 $collapsed = $line["collapsed"];
3603 // workaround for NULL category
3604 if ($category == __("Uncategorized")) {
3605 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
3610 if ($collapsed == "t" ||
$collapsed == "1") {
3611 $holder_class = "feedCatHolder";
3612 $holder_style = "display:none;";
3615 $holder_class = "feedCatHolder";
3620 $cat_id = sprintf("%d", $cat_id);
3622 $cat_unread = getCategoryUnread($link, $cat_id);
3624 $catctr_class = ($cat_unread > 0) ?
"catCtrHasUnread" : "catCtrNoUnread";
3626 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
3627 <a id=\"FCATN-$cat_id\" href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
3628 <a href=\"#\" onclick=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
3629 <span id=\"FCATCTR-$cat_id\" title=\"Click to browse category\"
3630 class=\"$catctr_class\">($cat_unread)</span> $ellipsis
3633 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\" style='$holder_style'>";
3636 printFeedEntry($feed_id, $class, $feed, $unread,
3637 ICONS_DIR
."/$feed_id.ico", $link, $rtl_content,
3638 $last_updated, $line["last_error"]);
3643 if (db_num_rows($result) == 0) {
3644 print "<li>".__('No feeds to display.')."</li>";
3651 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
3652 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
3653 post_int_id = ttrss_user_entries.int_id AND
3654 unread = true AND ref_id = ttrss_entries.id
3655 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
3657 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
3658 ORDER BY tag_name"); */
3660 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3661 print "<li class=\"feedCat\">".__('Tags')."</li>";
3662 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
3665 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
3666 FROM ttrss_user_entries WHERE int_id = post_int_id
3667 AND unread = true)) AS count FROM ttrss_tags
3668 WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name
3669 ORDER BY count DESC LIMIT 50");
3673 while ($line = db_fetch_assoc($result)) {
3674 $tags[$line["tag_name"]] +
= $line["count"];
3677 foreach (array_keys($tags) as $tag) {
3679 $unread = $tags[$tag];
3687 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
3691 if (db_num_rows($result) == 0) {
3692 print "<li>No tags to display.</li>";
3695 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3705 function get_article_tags($link, $id, $owner_uid = 0) {
3707 $a_id = db_escape_string($id);
3709 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
3711 $tmp_result = db_query($link, "SELECT DISTINCT tag_name,
3712 owner_uid as owner FROM
3713 ttrss_tags WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE
3714 ref_id = '$a_id' AND owner_uid = '$owner_uid' LIMIT 1) ORDER BY tag_name");
3718 while ($tmp_line = db_fetch_assoc($tmp_result)) {
3719 array_push($tags, $tmp_line["tag_name"]);
3725 function trim_value(&$value) {
3726 $value = trim($value);
3729 function trim_array($array) {
3731 array_walk($tmp, 'trim_value');
3735 function tag_is_valid($tag) {
3736 if ($tag == '') return false;
3737 if (preg_match("/^[0-9]*$/", $tag)) return false;
3739 $tag = iconv("utf-8", "utf-8", $tag);
3740 if (!$tag) return false;
3745 function render_login_form($link, $mobile = false) {
3747 require_once "login_form.php";
3749 require_once "mobile/login_form.php";
3753 // from http://developer.apple.com/internet/safari/faq.html
3754 function no_cache_incantation() {
3755 header("Expires: Mon, 22 Dec 1980 00:00:00 GMT"); // Happy birthday to me :)
3756 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
3757 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1
3758 header("Cache-Control: post-check=0, pre-check=0", false);
3759 header("Pragma: no-cache"); // HTTP/1.0
3762 function format_warning($msg, $id = "") {
3763 return "<div class=\"warning\" id=\"$id\">
3764 <img src=\"images/sign_excl.png\">$msg</div>";
3767 function format_notice($msg) {
3768 return "<div class=\"notice\">
3769 <img src=\"images/sign_info.png\">$msg</div>";
3772 function format_error($msg) {
3773 return "<div class=\"error\">
3774 <img src=\"images/sign_excl.png\">$msg</div>";
3777 function print_notice($msg) {
3778 return print format_notice($msg);
3781 function print_warning($msg) {
3782 return print format_warning($msg);
3785 function print_error($msg) {
3786 return print format_error($msg);
3790 function T_sprintf() {
3791 $args = func_get_args();
3792 return vsprintf(__(array_shift($args)), $args);
3795 function outputArticleXML($link, $id, $feed_id, $mark_as_read = true) {
3797 /* we can figure out feed_id from article id anyway, why do we
3798 * pass feed_id here? */
3800 $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries
3801 WHERE ref_id = '$id'");
3803 $feed_id = db_fetch_result($result, 0, "feed_id");
3805 print "<article id='$id'><![CDATA[";
3807 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
3808 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
3810 if (db_num_rows($result) == 1) {
3811 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
3813 $rtl_content = false;
3817 $rtl_tag = "dir=\"RTL\"";
3824 if ($mark_as_read) {
3825 $result = db_query($link, "UPDATE ttrss_user_entries
3826 SET unread = false,last_read = NOW()
3827 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
3830 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
3831 SUBSTRING(updated,1,16) as updated,
3832 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
3835 FROM ttrss_entries,ttrss_user_entries
3836 WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
3842 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
3843 $link_target = "target=\"_new\"";
3846 $line = db_fetch_assoc($result);
3848 if ($line["icon_url"]) {
3849 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
3851 $feed_icon = " ";
3854 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
3855 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
3857 $entry_comments = "";
3860 $num_comments = $line["num_comments"];
3861 $entry_comments = "";
3863 if ($num_comments > 0) {
3864 if ($line["comments"]) {
3865 $comments_url = $line["comments"];
3867 $comments_url = $line["link"];
3869 $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>";
3871 if ($line["comments"] && $line["link"] != $line["comments"]) {
3872 $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>";
3876 print "<div class=\"postReply\">";
3878 print "<div class=\"postHeader\">";
3880 $entry_author = $line["author"];
3882 if ($entry_author) {
3883 $entry_author = __(" - by ") . $entry_author;
3886 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3887 strtotime($line["updated"]));
3889 print "<div class=\"postDate$rtl_class\">$parsed_updated</div>";
3891 if ($line["link"]) {
3892 print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" .
3893 $line["title"] . "</a><span class='author'>$entry_author</span></div>";
3895 print "<div clear='both'>" . $line["title"] . "$entry_author</div>";
3898 /* $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
3899 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
3900 ORDER BY tag_name"); */
3902 $tags = get_article_tags($link, $id);
3909 foreach ($tags as $tag) {
3911 $tag_escaped = str_replace("'", "\\'", $tag);
3913 $tag_str = "<a href=\"javascript:viewfeed('$tag_escaped')\">$tag</a>, ";
3915 if ($num_tags == 6) {
3918 } else if ($num_tags < 6) {
3919 $tags_str .= $tag_str;
3921 $f_tags_str .= $tag_str;
3924 $tags_str = preg_replace("/, $/", "", $tags_str);
3925 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
3927 $all_tags_div = "<span class='cdmAllTagsCtr'>...<div class='cdmAllTags'>All Tags: $f_tags_str</div></span>";
3928 $tags_str = preg_replace("/\.\.\.$/", "$all_tags_div", $tags_str);
3930 if (!$entry_comments) $entry_comments = " "; # placeholder
3932 if (!$tags_str) $tags_str = '<span class="tagList">'.__('no tags').'</span>';
3934 print "<div style='float : right'>
3935 <img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'>
3937 <a title=\"Edit tags for this article\"
3938 href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a></div>
3939 <div clear='both'>$entry_comments</div>";
3943 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
3944 print "<div class=\"postContent\">";
3946 #print "<div id=\"allEntryTags\">".__('Tags:')." $f_tags_str</div>";
3948 $line["content"] = sanitize_rss($link, $line["content"]);
3950 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
3951 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
3954 print $line["content"] . "</div>";
3960 print "]]></article>";
3964 function outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view,
3965 $next_unread_feed, $offset) {
3967 $timing_info = getmicrotime();
3969 $topmost_article_ids = array();
3975 if ($subop == "undefined") $subop = "";
3977 if ($subop == "CatchupSelected") {
3978 $ids = split(",", db_escape_string($_GET["ids"]));
3979 $cmode = sprintf("%d", $_GET["cmode"]);
3981 catchupArticlesById($link, $ids, $cmode);
3984 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
3985 update_generic_feed($link, $feed, $cat_view);
3988 if ($subop == "MarkAllRead") {
3989 catchup_feed($link, $feed, $cat_view);
3991 if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
3992 if ($next_unread_feed) {
3993 $feed = $next_unread_feed;
3999 $result = db_query($link,
4000 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
4002 if (db_num_rows($result) == 0) {
4003 print "<div align='center'>".__('Feed not found.')."</div>";
4008 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
4010 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
4011 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
4013 if (db_num_rows($result) == 1) {
4014 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
4016 $rtl_content = false;
4020 $rtl_tag = "dir=\"RTL\"";
4026 $rtl_content = false;
4029 $script_dt_add = get_script_dt_add();
4031 /// START /////////////////////////////////////////////////////////////////////////////////
4033 $search = db_escape_string($_GET["query"]);
4034 $search_mode = db_escape_string($_GET["search_mode"]);
4035 $match_on = db_escape_string($_GET["match_on"]);
4041 $real_offset = $offset * $limit;
4043 if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
4045 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
4046 $search, $search_mode, $match_on, false, $real_offset);
4048 if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
4050 $result = $qfh_ret[0];
4051 $feed_title = $qfh_ret[1];
4052 $feed_site_url = $qfh_ret[2];
4053 $last_error = $qfh_ret[3];
4056 $feed_site_url = article_publish_url($link);
4059 /// STOP //////////////////////////////////////////////////////////////////////////////////
4062 print "<div id=\"headlinesContainer\" $rtl_tag>";
4065 print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
4069 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
4070 $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode,
4073 print "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">";
4076 if (db_num_rows($result) > 0) {
4078 # print "\{$offset}";
4080 if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) {
4081 print "<table class=\"headlinesList\" id=\"headlinesList\"
4082 cellspacing=\"0\">";
4087 error_reporting (DEFAULT_ERROR_LEVEL
);
4091 while ($line = db_fetch_assoc($result)) {
4093 $class = ($lnum %
2) ?
"even" : "odd";
4096 $feed_id = $line["feed_id"];
4098 if (count($topmost_article_ids) < 5) {
4099 array_push($topmost_article_ids, $id);
4102 if ($line["last_read"] == "" &&
4103 ($line["unread"] != "t" && $line["unread"] != "1")) {
4105 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
4108 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
4112 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
4120 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
4121 $marked_pic = "<img id=\"FMPIC-$id\" src=\"images/mark_set.png\"
4123 alt=\"Reset mark\" onclick='javascript:tMark($id)'>";
4125 $marked_pic = "<img id=\"FMPIC-$id\" src=\"images/mark_unset.png\"
4127 alt=\"Set mark\" onclick='javascript:tMark($id)'>";
4130 if ($line["published"] == "t" ||
$line["published"] == "1") {
4131 $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_set.png\"
4133 alt=\"Unpublish\" onclick='javascript:tPub($id)'>";
4135 $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_unset.png\"
4137 alt=\"Publish\" onclick='javascript:tPub($id)'>";
4140 # $content_link = "<a target=\"_new\" href=\"".$line["link"]."\">" .
4141 # $line["title"] . "</a>";
4143 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
4144 $line["title"] . "</a>";
4146 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
4147 # $line["title"] . "</a>";
4149 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
4150 $updated_fmt = smart_date_time(strtotime($line["updated_noms"]));
4152 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
4153 $updated_fmt = date($short_date, strtotime($line["updated_noms"]));
4156 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
4157 $content_preview = truncate_string(strip_tags($line["content_preview"]),
4161 $entry_author = $line["author"];
4163 if ($entry_author) {
4164 $entry_author = " - by $entry_author";
4167 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
4169 print "<tr class='$class' id='RROW-$id'>";
4171 print "<td class='hlUpdPic'>$update_pic</td>";
4173 print "<td class='hlSelectRow'>
4174 <input type=\"checkbox\" onclick=\"tSR(this)\"
4178 print "<td class='hlMarkedPic'>$marked_pic</td>";
4179 print "<td class='hlMarkedPic'>$published_pic</td>";
4181 if ($line["feed_title"]) {
4182 print "<td class='hlContent'>$content_link</td>";
4183 print "<td class='hlFeed'>
4184 <a href=\"javascript:viewfeed($feed_id, '', false)\">".
4185 truncate_string($line["feed_title"],30)."</a> </td>";
4187 print "<td class='hlContent' valign='middle'>";
4189 print "<a href=\"javascript:view($id,$feed_id);\">" .
4192 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
4193 if ($content_preview) {
4194 print "<span class=\"contentPreview\"> - $content_preview</span>";
4202 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
4209 $add_class = "Unread";
4214 print "<div class=\"cdmArticle$add_class\"
4215 id=\"RROW-$id\" onmouseover='cdmMouseIn(this)'
4216 onmouseout='cdmMouseOut(this)'>";
4218 print "<div class=\"cdmHeader\">";
4220 print "<div class=\"articleUpdated\">$updated_fmt</div>";
4222 print "<a class=\"title\"
4223 onclick=\"javascript:toggleUnread($id, 0)\"
4224 target=\"_new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
4226 print $entry_author;
4228 if ($line["feed_title"]) {
4229 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
4234 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
4235 $line["content_preview"] = preg_replace("/href=/i",
4236 "target=\"_new\" href=", $line["content_preview"]);
4239 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">";
4241 print "<div class=\"cdmFooter\"><span class='s0'>";
4243 /* print "<div class=\"markedPic\">Star it: $marked_pic</div>"; */
4245 print __("Select:").
4246 " <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
4247 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">";
4249 print "</span><span class='s1'>$marked_pic</span> ";
4250 print "<span class='s1'>$published_pic</span> ";
4252 $tags = get_article_tags($link, $id);
4255 $full_tags_str = "";
4258 foreach ($tags as $tag) {
4260 $full_tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
4261 if ($num_tags < 5) {
4262 $tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
4263 } else if ($num_tags == 5) {
4268 $tags_str = preg_replace("/, $/", "", $tags_str);
4269 $full_tags_str = preg_replace("/, $/", "", $full_tags_str);
4271 $all_tags_div = "<span class='cdmAllTagsCtr'>...<div class='cdmAllTags'>All Tags: $full_tags_str</div></span>";
4273 $tags_str = preg_replace("/\.\.\.$/", "$all_tags_div", $tags_str);
4276 if ($tags_str == "") $tags_str = "no tags";
4278 // print "<img src='images/tag.png' class='markedPic'>";
4280 print "<span class='s1'>
4281 <img class='tagsPic' src='images/tag.png' alt='Tags'
4282 title='Tags'> $tags_str <a title=\"Edit tags for this article\"
4283 href=\"javascript:editArticleTags($id, $feed_id, true)\">(+)</a>";
4287 print "<span class='s2'>Toggle: <a class=\"cdmToggleLink\"
4288 href=\"javascript:toggleUnread($id)\">
4299 if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) {
4303 // print_headline_subtoolbar($link,
4304 // "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
4308 if (!$offset) print "<div class='whiteBox'>".__('No articles found.')."</div>";
4316 return $topmost_article_ids;
4319 // from here: http://www.roscripts.com/Create_tag_cloud-71.html
4321 function printTagCloud($link) {
4323 /* get first ref_id to count from */
4329 if (DB_TYPE == "pgsql") {
4330 $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries
4331 WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]."
4332 AND date_entered > NOW() - INTERVAL '30 days'";
4334 $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries
4335 WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]."
4336 AND date_entered > DATE_SUB(NOW(), INTERVAL 30 DAY)";
4339 $result = db_query($link, $query);
4340 $first_id = db_fetch_result($result, 0, "id"); */
4342 //AND post_int_id >= '$first_id'
4343 $query = "SELECT tag_name, COUNT(post_int_id) AS count
4344 FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]."
4345 GROUP BY tag_name ORDER BY count DESC LIMIT 50";
4347 $result = db_query($link, $query);
4351 while ($line = db_fetch_assoc($result)) {
4352 $tags[$line["tag_name"]] = $line["count"];
4357 $max_size = 32; // max font size in pixels
4358 $min_size = 11; // min font size in pixels
4360 // largest and smallest array values
4361 $max_qty = max(array_values($tags));
4362 $min_qty = min(array_values($tags));
4364 // find the range of values
4365 $spread = $max_qty - $min_qty;
4366 if ($spread == 0) { // we don't want to divide by zero
4370 // set the font-size increment
4371 $step = ($max_size - $min_size) / ($spread);
4373 // loop through the tag array
4374 foreach ($tags as $key => $value) {
4375 // calculate font-size
4376 // find the $value in excess of $min_qty
4377 // multiply by the font-size increment ($size)
4378 // and add the $min_size set above
4379 $size = round($min_size +
(($value - $min_qty) * $step));
4381 $key_escaped = str_replace("'", "\\'", $key);
4383 echo "<a href=\"javascript:viewfeed('$key_escaped') \" style=\"font-size: " .
4384 $size . "px\" title=\"$value articles tagged with " .
4385 $key . '">' . $key . '</a> ';
4389 function print_checkpoint($n, $s) {
4390 $ts = getmicrotime();
4391 echo sprintf("<!-- CP[$n] %.4f seconds -->", $ts - $s);
4395 function sanitize_tag($tag) {
4398 $tag = mb_strtolower($tag, 'utf-8');
4400 $tag = preg_replace('/[\"\+\>\<]/', "", $tag);
4402 // $tag = str_replace('"', "", $tag);
4403 // $tag = str_replace("+", " ", $tag);
4404 $tag = str_replace("technorati tag: ", "", $tag);
4409 function generate_publish_key() {
4410 return sha1(uniqid(rand(), true));
4413 function article_publish_url($link) {
4415 $url_path = 'http://' . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH
);
4417 $url_path .= "?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY");