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() {
12 $tr = array("en_US" => "English",
15 "zh_CN" => "Chinese");
20 if (ENABLE_TRANSLATIONS
== true) {
21 require_once "accept-to-gettext.php";
22 require_once "gettext/gettext.inc";
24 function startup_gettext() {
26 # Get locale from Accept-Language header
27 $lang = al2gt(array("en_US", "ru_RU", "zh_CN", "fr_FR"), "text/html");
29 if (defined('_TRANSLATION_OVERRIDE_DEFAULT')) {
30 $lang = _TRANSLATION_OVERRIDE_DEFAULT
;
34 _setlocale(LC_MESSAGES
, $lang);
35 _bindtextdomain("messages", "locale");
36 _textdomain("messages");
37 _bind_textdomain_codeset("messages", "UTF-8");
47 function startup_gettext() {
53 require_once 'db-prefs.php';
54 require_once 'compat.php';
55 require_once 'errors.php';
56 require_once 'version.php';
58 define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION
. ')');
59 define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
61 require_once "magpierss/rss_fetch.inc";
62 require_once 'magpierss/rss_utils.inc';
64 include_once "tw/tw-config.php";
65 include_once "tw/tw.php";
66 include_once TW_SETUP
. "paranoya.php";
68 $tw_parser = new twParser();
70 function _debug($msg) {
71 $ts = strftime("%H:%M:%S", time());
75 function purge_feed($link, $feed_id, $purge_interval, $debug = false) {
79 if (DB_TYPE
== "pgsql") {
80 /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE
81 marked = false AND feed_id = '$feed_id' AND
82 (SELECT date_entered FROM ttrss_entries WHERE
83 id = ref_id) < NOW() - INTERVAL '$purge_interval days'"); */
85 $pg_version = get_pgsql_version($link);
87 if (preg_match("/^7\./", $pg_version) ||
preg_match("/^8\.0/", $pg_version)) {
89 $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE
90 ttrss_entries.id = ref_id AND
92 feed_id = '$feed_id' AND
93 ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'");
97 $result = db_query($link, "DELETE FROM ttrss_user_entries
99 WHERE ttrss_entries.id = ref_id AND
101 feed_id = '$feed_id' AND
102 ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'");
105 $rows = pg_affected_rows($result);
109 /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE
110 marked = false AND feed_id = '$feed_id' AND
111 (SELECT date_entered FROM ttrss_entries WHERE
112 id = ref_id) < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); */
114 $result = db_query($link, "DELETE FROM ttrss_user_entries
115 USING ttrss_user_entries, ttrss_entries
116 WHERE ttrss_entries.id = ref_id AND
118 feed_id = '$feed_id' AND
119 ttrss_entries.date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)");
121 $rows = mysql_affected_rows($link);
126 _debug("Purged feed $feed_id ($purge_interval): deleted $rows articles");
130 function global_purge_old_posts($link, $do_output = false, $limit = false) {
132 $random_qpart = sql_random_function();
135 $limit_qpart = "LIMIT $limit";
140 $result = db_query($link,
141 "SELECT id,purge_interval,owner_uid FROM ttrss_feeds
142 ORDER BY $random_qpart $limit_qpart");
144 while ($line = db_fetch_assoc($result)) {
146 $feed_id = $line["id"];
147 $purge_interval = $line["purge_interval"];
148 $owner_uid = $line["owner_uid"];
150 if ($purge_interval == 0) {
152 $tmp_result = db_query($link,
153 "SELECT value FROM ttrss_user_prefs WHERE
154 pref_name = 'PURGE_OLD_DAYS' AND owner_uid = '$owner_uid'");
156 if (db_num_rows($tmp_result) != 0) {
157 $purge_interval = db_fetch_result($tmp_result, 0, "value");
162 // print "Feed $feed_id: purge interval = $purge_interval\n";
165 if ($purge_interval > 0) {
166 purge_feed($link, $feed_id, $purge_interval, $do_output);
170 // purge orphaned posts in main content table
171 db_query($link, "DELETE FROM ttrss_entries WHERE
172 (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
176 function purge_old_posts($link) {
178 $user_id = $_SESSION["uid"];
180 $result = db_query($link, "SELECT id,purge_interval FROM ttrss_feeds
181 WHERE owner_uid = '$user_id'");
183 while ($line = db_fetch_assoc($result)) {
185 $feed_id = $line["id"];
186 $purge_interval = $line["purge_interval"];
188 if ($purge_interval == 0) $purge_interval = get_pref($link, 'PURGE_OLD_DAYS');
190 if ($purge_interval > 0) {
191 purge_feed($link, $feed_id, $purge_interval);
195 // purge orphaned posts in main content table
196 db_query($link, "DELETE FROM ttrss_entries WHERE
197 (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
200 function update_all_feeds($link, $fetch, $user_id = false, $force_daemon = false) {
202 if (WEB_DEMO_MODE
) return;
205 $user_id = $_SESSION["uid"];
206 purge_old_posts($link);
209 // db_query($link, "BEGIN");
211 if (MAX_UPDATE_TIME
> 0) {
212 if (DB_TYPE
== "mysql") {
215 $q_order = "RANDOM()";
218 $q_order = "last_updated DESC";
221 $result = db_query($link, "SELECT feed_url,id,
222 SUBSTRING(last_updated,1,19) AS last_updated,
223 update_interval FROM ttrss_feeds WHERE owner_uid = '$user_id'
228 while ($line = db_fetch_assoc($result)) {
229 $upd_intl = $line["update_interval"];
231 if (!$upd_intl ||
$upd_intl == 0) {
232 $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id, false);
236 // Updates for this feed are disabled
240 if ($fetch ||
(!$line["last_updated"] ||
241 time() - strtotime($line["last_updated"]) > ($upd_intl * 60))) {
243 // print "<!-- feed: ".$line["feed_url"]." -->";
245 update_rss_feed($link, $line["feed_url"], $line["id"], $force_daemon);
247 $upd_elapsed = time() - $upd_start;
249 if (MAX_UPDATE_TIME
> 0 && $upd_elapsed > MAX_UPDATE_TIME
) {
255 // db_query($link, "COMMIT");
259 function fetch_file_contents($url) {
260 if (USE_CURL_FOR_ICONS
) {
261 $tmpfile = tempnam(TMP_DIRECTORY
, "ttrss-tmp");
263 $ch = curl_init($url);
264 $fp = fopen($tmpfile, "w");
267 curl_setopt($ch, CURLOPT_FILE
, $fp);
268 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT
, 15);
269 curl_setopt($ch, CURLOPT_TIMEOUT
, 45);
275 $contents = file_get_contents($tmpfile);
281 return file_get_contents($url);
286 // adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/)
287 // http://dev.wp-plugins.org/file/favatars/trunk/favatars.php
289 function get_favicon_url($url) {
291 if ($html = @fetch_file_contents
($url)) {
293 if ( preg_match('/<link[^>]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $html, $matches)) {
294 // Attempt to grab a favicon link from their webpage url
295 $linkUrl = html_entity_decode($matches[1]);
297 if (substr($linkUrl, 0, 1) == '/') {
298 $urlParts = parse_url($url);
299 $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].$linkUrl;
300 } else if (substr($linkUrl, 0, 7) == 'http://') {
301 $faviconURL = $linkUrl;
302 } else if (substr($url, -1, 1) == '/') {
303 $faviconURL = $url.$linkUrl;
305 $faviconURL = $url.'/'.$linkUrl;
309 // If unsuccessful, attempt to "guess" the favicon location
310 $urlParts = parse_url($url);
311 $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].'/favicon.ico';
315 // Run a test to see if what we have attempted to get actually exists.
316 if(USE_CURL_FOR_ICONS ||
url_validate($faviconURL)) {
323 function url_validate($link) {
325 $url_parts = @parse_url
($link);
327 if ( empty( $url_parts["host"] ) )
330 if ( !empty( $url_parts["path"] ) ) {
331 $documentpath = $url_parts["path"];
336 if ( !empty( $url_parts["query"] ) )
337 $documentpath .= "?" . $url_parts["query"];
339 $host = $url_parts["host"];
340 $port = $url_parts["port"];
345 $socket = @fsockopen
( $host, $port, $errno, $errstr, 30 );
350 fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
352 $http_response = fgets( $socket, 22 );
354 $responses = "/(200 OK)|(30[0-9] Moved)/";
355 if ( preg_match($responses, $http_response) ) {
364 function check_feed_favicon($site_url, $feed, $link) {
365 $favicon_url = get_favicon_url($site_url);
367 # print "FAVICON [$site_url]: $favicon_url\n";
371 $icon_file = ICONS_DIR
. "/$feed.ico";
373 if ($favicon_url && !file_exists($icon_file)) {
374 $contents = fetch_file_contents($favicon_url);
376 $fp = fopen($icon_file, "w");
379 fwrite($fp, $contents);
381 chmod($icon_file, 0644);
385 error_reporting(DEFAULT_ERROR_LEVEL
);
389 function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) {
391 if (DAEMON_REFRESH_ONLY
&& !$_GET["daemon"] && !$ignore_daemon) {
395 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
396 _debug("update_rss_feed: start");
399 $result = db_query($link, "SELECT update_interval,auth_login,auth_pass
400 FROM ttrss_feeds WHERE id = '$feed'");
402 $auth_login = db_fetch_result($result, 0, "auth_login");
403 $auth_pass = db_fetch_result($result, 0, "auth_pass");
405 $update_interval = db_fetch_result($result, 0, "update_interval");
407 if ($update_interval < 0) { return; }
409 $feed = db_escape_string($feed);
411 $fetch_url = $feed_url;
413 if ($auth_login && $auth_pass) {
414 $url_parts = array();
415 preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts);
417 if ($url_parts[1] && $url_parts[2]) {
418 $fetch_url = $url_parts[1] . "://$auth_login:$auth_pass@" . $url_parts[2];
423 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
424 _debug("update_rss_feed: fetching...");
427 if (!defined('DAEMON_EXTENDED_DEBUG')) {
431 $rss = fetch_rss($fetch_url);
433 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
434 _debug("update_rss_feed: fetch done, parsing...");
436 error_reporting (DEFAULT_ERROR_LEVEL
);
439 $feed = db_escape_string($feed);
443 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
444 _debug("update_rss_feed: processing feed data...");
447 // db_query($link, "BEGIN");
449 $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid
450 FROM ttrss_feeds WHERE id = '$feed'");
452 $registered_title = db_fetch_result($result, 0, "title");
453 $orig_icon_url = db_fetch_result($result, 0, "icon_url");
454 $orig_site_url = db_fetch_result($result, 0, "site_url");
456 $owner_uid = db_fetch_result($result, 0, "owner_uid");
458 if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid, false)) {
459 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
460 _debug("update_rss_feed: checking favicon...");
462 check_feed_favicon($rss->channel
["link"], $feed, $link);
465 if (!$registered_title ||
$registered_title == "[Unknown]") {
467 $feed_title = db_escape_string($rss->channel
["title"]);
469 if (defined('DAEMON_EXTENDED_DEBUG') ||
$_GET['xdebug']) {
470 _debug("update_rss_feed: registering title: $feed_title");
473 db_query($link, "UPDATE ttrss_feeds SET
474 title = '$feed_title' WHERE id = '$feed'");
477 $site_url = $rss->channel
["link"];
478 // weird, weird Magpie
479 if (!$site_url) $site_url = db_escape_string($rss->channel
["link_"]);
481 if ($site_url && $orig_site_url != db_escape_string($site_url)) {
482 db_query($link, "UPDATE ttrss_feeds SET
483 site_url = '$site_url' WHERE id = '$feed'");
486 // print "I: " . $rss->channel["image"]["url"];
488 $icon_url = $rss->image
["url"];
490 if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) {
491 $icon_url = db_escape_string($icon_url);
492 db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'");
495 if (defined('DAEMON_EXTENDED_DEBUG' ||
$_GET['xdebug'])) {
496 _debug("update_rss_feed: loading filters...");
501 $result = db_query($link, "SELECT reg_exp,
502 ttrss_filter_types.name AS name,
503 ttrss_filter_actions.name AS action,
506 FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE
508 owner_uid = $owner_uid AND
509 ttrss_filter_types.id = filter_type AND
510 ttrss_filter_actions.id = action_id AND
511 (feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp");
513 while ($line = db_fetch_assoc($result)) {
514 if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
516 $filter["reg_exp"] = $line["reg_exp"];
517 $filter["action"] = $line["action"];
518 $filter["action_param"] = $line["action_param"];
519 $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
521 array_push($filters[$line["name"]], $filter);
524 $iterator = $rss->items
;
526 if (!$iterator ||
!is_array($iterator)) $iterator = $rss->entries
;
527 if (!$iterator ||
!is_array($iterator)) $iterator = $rss;
529 if (!is_array($iterator)) {
530 /* db_query($link, "UPDATE ttrss_feeds
531 SET last_error = 'Parse error: can\'t find any articles.'
532 WHERE id = '$feed'"); */
534 // clear any errors and mark feed as updated if fetched okay
535 // even if it's blank
537 if (defined('DAEMON_EXTENDED_DEBUG')) {
538 _debug("update_rss_feed: entry iterator is not an array, no articles?");
541 db_query($link, "UPDATE ttrss_feeds
542 SET last_updated = NOW(), last_error = '' WHERE id = '$feed'");
544 return; // no articles
547 if (defined('DAEMON_EXTENDED_DEBUG')) {
548 _debug("update_rss_feed: processing articles...");
551 foreach ($iterator as $item) {
553 $entry_guid = $item["id"];
555 if (!$entry_guid) $entry_guid = $item["guid"];
556 if (!$entry_guid) $entry_guid = $item["link"];
557 if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]);
559 if (defined('DAEMON_EXTENDED_DEBUG')) {
560 _debug("update_rss_feed: guid $entry_guid");
563 if (!$entry_guid) continue;
565 $entry_timestamp = "";
567 $rss_2_date = $item['pubdate'];
568 $rss_1_date = $item['dc']['date'];
569 $atom_date = $item['issued'];
570 if (!$atom_date) $atom_date = $item['updated'];
572 if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date);
573 if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date);
574 if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date);
576 if ($entry_timestamp == "" ||
$entry_timestamp == -1 ||
!$entry_timestamp) {
577 $entry_timestamp = time();
578 $no_orig_date = 'true';
580 $no_orig_date = 'false';
583 $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
585 $entry_title = trim(strip_tags($item["title"]));
587 // strange Magpie workaround
588 $entry_link = $item["link_"];
589 if (!$entry_link) $entry_link = $item["link"];
591 if (!$entry_title) continue;
592 # if (!$entry_link) continue;
594 $entry_link = strip_tags($entry_link);
596 $entry_content = $item["content:escaped"];
598 if (!$entry_content) $entry_content = $item["content:encoded"];
599 if (!$entry_content) $entry_content = $item["content"];
600 if (!$entry_content) $entry_content = $item["atom_content"];
601 if (!$entry_content) $entry_content = $item["summary"];
602 if (!$entry_content) $entry_content = $item["description"];
604 // if (!$entry_content) continue;
607 if (is_array($entry_content)) {
608 $entry_content = $entry_content["encoded"];
609 if (!$entry_content) $entry_content = $entry_content["escaped"];
613 // print_r(htmlspecialchars($entry_content));
616 $entry_content_unescaped = $entry_content;
618 $entry_comments = strip_tags($item["comments"]);
620 $entry_author = db_escape_string(strip_tags($item['dc']['creator']));
622 if ($item['author']) {
624 if (is_array($item['author'])) {
626 if (!$entry_author) {
627 $entry_author = db_escape_string(strip_tags($item['author']['name']));
630 if (!$entry_author) {
631 $entry_author = db_escape_string(strip_tags($item['author']['email']));
635 if (!$entry_author) {
636 $entry_author = db_escape_string(strip_tags($item['author']));
640 if (preg_match('/^[\t\n\r ]*$/', $entry_author)) $entry_author = '';
642 $entry_guid = db_escape_string(strip_tags($entry_guid));
644 $result = db_query($link, "SELECT id FROM ttrss_entries
645 WHERE guid = '$entry_guid'");
647 $entry_content = db_escape_string($entry_content);
649 $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
651 $entry_title = db_escape_string($entry_title);
652 $entry_link = db_escape_string($entry_link);
653 $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250);
654 $entry_author = mb_substr($entry_author, 0, 250);
656 $num_comments = db_escape_string($item["slash"]["comments"]);
658 if (!$num_comments) $num_comments = 0;
660 // parse <category> entries into tags
662 $t_ctr = $item['category#'];
664 $additional_tags = false;
667 $additional_tags = false;
668 } else if ($t_ctr == 1) {
669 $additional_tags = array($item['category']);
671 $additional_tags = array();
672 for ($i = 0; $i <= $t_ctr; $i++
) {
673 if ($item["category#$i"]) {
674 array_push($additional_tags, $item["category#$i"]);
679 // parse <dc:subject> elements
681 $t_ctr = $item['dc']['subject#'];
684 $additional_tags = array($item['dc']['subject']);
685 } else if ($t_ctr > 1) {
686 $additional_tags = array();
687 for ($i = 0; $i <= $t_ctr; $i++
) {
688 if ($item['dc']["subject#$i"]) {
689 array_push($additional_tags, $item['dc']["subject#$i"]);
696 // $entry_content = sanitize_rss($entry_content);
698 if (defined('DAEMON_EXTENDED_DEBUG')) {
699 _debug("update_rss_feed: done collecting data [TITLE:$entry_title]");
702 db_query($link, "BEGIN");
704 if (db_num_rows($result) == 0) {
706 if (defined('DAEMON_EXTENDED_DEBUG')) {
707 _debug("update_rss_feed: base guid not found");
710 // base post entry does not exist, create it
712 $result = db_query($link,
713 "INSERT INTO ttrss_entries
729 '$entry_timestamp_fmt',
738 // we keep encountering the entry in feeds, so we need to
739 // update date_entered column so that we don't get horrible
740 // dupes when the entry gets purged and reinserted again e.g.
741 // in the case of SLOW SLOW OMG SLOW updating feeds
743 $base_entry_id = db_fetch_result($result, 0, "id");
745 db_query($link, "UPDATE ttrss_entries SET date_entered = NOW()
746 WHERE id = '$base_entry_id'");
749 // now it should exist, if not - bad luck then
751 $result = db_query($link, "SELECT
752 id,content_hash,no_orig_date,title,
753 substring(date_entered,1,19) as date_entered,
754 substring(updated,1,19) as updated,
758 WHERE guid = '$entry_guid'");
760 if (db_num_rows($result) == 1) {
762 if (defined('DAEMON_EXTENDED_DEBUG')) {
763 _debug("update_rss_feed: base guid found, checking for user record");
766 // this will be used below in update handler
767 $orig_content_hash = db_fetch_result($result, 0, "content_hash");
768 $orig_title = db_fetch_result($result, 0, "title");
769 $orig_num_comments = db_fetch_result($result, 0, "num_comments");
770 $orig_date_entered = strtotime(db_fetch_result($result,
773 $ref_id = db_fetch_result($result, 0, "id");
775 // check for user post link to main table
777 // do we allow duplicate posts with same GUID in different feeds?
778 if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
779 $dupcheck_qpart = "AND feed_id = '$feed'";
781 $dupcheck_qpart = "";
784 // error_reporting(0);
786 $article_filters = get_article_filters($filters, $entry_title,
787 $entry_content, $entry_link);
789 if (defined('DAEMON_EXTENDED_DEBUG')) {
790 _debug("update_rss_feed: article filters: ");
791 if (count($article_filters) != 0) {
792 print_r($article_filters);
796 if (find_article_filter($article_filters, "filter")) {
800 // error_reporting (DEFAULT_ERROR_LEVEL);
802 $result = db_query($link,
803 "SELECT ref_id FROM ttrss_user_entries WHERE
804 ref_id = '$ref_id' AND owner_uid = '$owner_uid'
807 // okay it doesn't exist - create user entry
808 if (db_num_rows($result) == 0) {
810 if (defined('DAEMON_EXTENDED_DEBUG')) {
811 _debug("update_rss_feed: user record not found, creating...");
814 if (!find_article_filter($article_filters, 'catchup')) {
816 $last_read_qpart = 'NULL';
819 $last_read_qpart = 'NOW()';
822 if (find_article_filter($article_filters, 'mark')) {
828 if (find_article_filter($article_filters, 'publish')) {
831 $published = 'false';
834 $result = db_query($link,
835 "INSERT INTO ttrss_user_entries
836 (ref_id, owner_uid, feed_id, unread, last_read, marked, published)
837 VALUES ('$ref_id', '$owner_uid', '$feed', $unread,
838 $last_read_qpart, $marked, $published)");
841 $post_needs_update = false;
843 if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid, false) &&
844 ($content_hash != $orig_content_hash)) {
845 // print "<!-- [$entry_title] $content_hash vs $orig_content_hash -->";
846 $post_needs_update = true;
849 if (db_escape_string($orig_title) != $entry_title) {
850 $post_needs_update = true;
853 if ($orig_num_comments != $num_comments) {
854 $post_needs_update = true;
857 // this doesn't seem to be very reliable
859 // if ($orig_timestamp != $entry_timestamp && !$orig_no_orig_date) {
860 // $post_needs_update = true;
863 // if post needs update, update it and mark all user entries
864 // linking to this post as updated
865 if ($post_needs_update) {
867 if (defined('DAEMON_EXTENDED_DEBUG')) {
868 _debug("update_rss_feed: post $entry_guid needs update...");
871 // print "<!-- post $orig_title needs update : $post_needs_update -->";
873 db_query($link, "UPDATE ttrss_entries
874 SET title = '$entry_title', content = '$entry_content',
875 content_hash = '$content_hash',
876 num_comments = '$num_comments'
877 WHERE id = '$ref_id'");
879 if (get_pref($link, "MARK_UNREAD_ON_UPDATE", $owner_uid, false)) {
880 db_query($link, "UPDATE ttrss_user_entries
881 SET last_read = null, unread = true WHERE ref_id = '$ref_id'");
883 db_query($link, "UPDATE ttrss_user_entries
884 SET last_read = null WHERE ref_id = '$ref_id' AND unread = false");
890 db_query($link, "COMMIT");
892 if (defined('DAEMON_EXTENDED_DEBUG')) {
893 _debug("update_rss_feed: looking for tags...");
897 // <a href="..." rel="tag">Xorg</a>, //
901 preg_match_all("/<a.*?rel=['\"]tag['\"].*?>([^<]+)<\/a>/i",
902 $entry_content_unescaped, $entry_tags);
904 /* print "<p><br/>$entry_title : $entry_content_unescaped<br>";
905 print_r($entry_tags);
906 print "<br/></p>"; */
908 $entry_tags = $entry_tags[1];
910 # check for manual tags
912 $tag_filter = find_article_filter($article_filters, "tag");
916 $manual_tags = trim_array(split(",", $tag_filter[1]));
918 foreach ($manual_tags as $tag) {
919 if (tag_is_valid($tag)) {
920 array_push($entry_tags, $tag);
925 $boring_tags = trim_array(split(",", mb_strtolower(get_pref($link,
926 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8')));
928 if ($additional_tags && is_array($additional_tags)) {
929 foreach ($additional_tags as $tag) {
930 if (tag_is_valid($tag) &&
931 array_search($tag, $boring_tags) === FALSE) {
932 array_push($entry_tags, $tag);
937 // print "<p>TAGS: "; print_r($entry_tags); print "</p>";
939 if (count($entry_tags) > 0) {
941 db_query($link, "BEGIN");
943 $result = db_query($link, "SELECT id,int_id
944 FROM ttrss_entries,ttrss_user_entries
945 WHERE guid = '$entry_guid'
946 AND feed_id = '$feed' AND ref_id = id
947 AND owner_uid = '$owner_uid'");
949 if (db_num_rows($result) == 1) {
951 $entry_id = db_fetch_result($result, 0, "id");
952 $entry_int_id = db_fetch_result($result, 0, "int_id");
954 foreach ($entry_tags as $tag) {
956 $tag = sanitize_tag($tag);
957 $tag = db_escape_string($tag);
959 if (!tag_is_valid($tag)) continue;
961 $result = db_query($link, "SELECT id FROM ttrss_tags
962 WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND
963 owner_uid = '$owner_uid' LIMIT 1");
965 // print db_fetch_result($result, 0, "id");
967 if ($result && db_num_rows($result) == 0) {
969 db_query($link, "INSERT INTO ttrss_tags
970 (owner_uid,tag_name,post_int_id)
971 VALUES ('$owner_uid','$tag', '$entry_int_id')");
975 db_query($link, "COMMIT");
979 db_query($link, "UPDATE ttrss_feeds
980 SET last_updated = NOW(), last_error = '' WHERE id = '$feed'");
982 // db_query($link, "COMMIT");
985 $error_msg = db_escape_string(magpie_error());
987 "UPDATE ttrss_feeds SET last_error = '$error_msg',
988 last_updated = NOW() WHERE id = '$feed'");
991 if (defined('DAEMON_EXTENDED_DEBUG')) {
992 _debug("update_rss_feed: done");
997 function print_select($id, $default, $values, $attributes = "") {
998 print "<select name=\"$id\" id=\"$id\" $attributes>";
999 foreach ($values as $v) {
1005 print "<option$sel>$v</option>";
1010 function print_select_hash($id, $default, $values, $attributes = "") {
1011 print "<select name=\"$id\" id='$id' $attributes>";
1012 foreach (array_keys($values) as $v) {
1018 print "<option $sel value=\"$v\">".$values[$v]."</option>";
1024 function get_article_filters($filters, $title, $content, $link) {
1027 if ($filters["title"]) {
1028 foreach ($filters["title"] as $filter) {
1029 $reg_exp = $filter["reg_exp"];
1030 $inverse = $filter["inverse"];
1031 if ((!$inverse && preg_match("/$reg_exp/i", $title)) ||
1032 ($inverse && !preg_match("/$reg_exp/i", $title))) {
1034 array_push($matches, array($filter["action"], $filter["action_param"]));
1039 if ($filters["content"]) {
1040 foreach ($filters["content"] as $filter) {
1041 $reg_exp = $filter["reg_exp"];
1042 $inverse = $filter["inverse"];
1044 if ((!$inverse && preg_match("/$reg_exp/i", $content)) ||
1045 ($inverse && !preg_match("/$reg_exp/i", $content))) {
1047 array_push($matches, array($filter["action"], $filter["action_param"]));
1052 if ($filters["both"]) {
1053 foreach ($filters["both"] as $filter) {
1054 $reg_exp = $filter["reg_exp"];
1055 $inverse = $filter["inverse"];
1058 if (!preg_match("/$reg_exp/i", $title) ||
!preg_match("/$reg_exp/i", $content)) {
1059 array_push($matches, array($filter["action"], $filter["action_param"]));
1062 if (preg_match("/$reg_exp/i", $title) ||
preg_match("/$reg_exp/i", $content)) {
1063 array_push($matches, array($filter["action"], $filter["action_param"]));
1069 if ($filters["link"]) {
1070 $reg_exp = $filter["reg_exp"];
1071 foreach ($filters["link"] as $filter) {
1072 $reg_exp = $filter["reg_exp"];
1073 $inverse = $filter["inverse"];
1075 if ((!$inverse && preg_match("/$reg_exp/i", $link)) ||
1076 ($inverse && !preg_match("/$reg_exp/i", $link))) {
1078 array_push($matches, array($filter["action"], $filter["action_param"]));
1086 function find_article_filter($filters, $filter_name) {
1087 foreach ($filters as $f) {
1088 if ($f[0] == $filter_name) {
1095 function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
1096 $rtl_content = false, $last_updated = false, $last_error = false) {
1098 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1099 $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"$icon_file\">";
1101 $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"images/blank_icon.gif\">";
1105 $rtl_tag = "dir=\"rtl\"";
1107 $rtl_tag = "dir=\"ltr\"";
1110 $error_notify_msg = "";
1113 $link_title = "Error: $last_error ($last_updated)";
1114 $error_notify_msg = "(Error)";
1115 } else if ($last_updated) {
1116 $link_title = "Updated: $last_updated";
1119 $feed = "<a title=\"$link_title\" id=\"FEEDL-$feed_id\"
1120 href=\"javascript:viewfeed('$feed_id', '', false, '', false, 0);\">$feed_title</a>";
1122 print "<li id=\"FEEDR-$feed_id\" class=\"$class\">";
1123 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1127 print "<span $rtl_tag id=\"FEEDN-$feed_id\">$feed</span>";
1132 $fctr_class = "class=\"invisible\"";
1135 print " <span $rtl_tag $fctr_class id=\"FEEDCTR-$feed_id\">
1136 (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>";
1138 if (get_pref($link, "EXTENDED_FEEDLIST")) {
1139 print "<div class=\"feedExtInfo\">
1140 <span id=\"FLUPD-$feed_id\">$last_updated $error_notify_msg</span></div>";
1147 function getmicrotime() {
1148 list($usec, $sec) = explode(" ",microtime());
1149 return ((float)$usec +
(float)$sec);
1152 function print_radio($id, $default, $values, $attributes = "") {
1153 foreach ($values as $v) {
1161 $sel .= " value=\"1\"";
1163 $sel .= " value=\"0\"";
1166 print "<input class=\"noborder\"
1167 type=\"radio\" $sel $attributes name=\"$id\"> $v ";
1172 function initialize_user_prefs($link, $uid) {
1174 $uid = db_escape_string($uid);
1176 db_query($link, "BEGIN");
1178 $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs");
1180 $u_result = db_query($link, "SELECT pref_name
1181 FROM ttrss_user_prefs WHERE owner_uid = '$uid'");
1183 $active_prefs = array();
1185 while ($line = db_fetch_assoc($u_result)) {
1186 array_push($active_prefs, $line["pref_name"]);
1189 while ($line = db_fetch_assoc($result)) {
1190 if (array_search($line["pref_name"], $active_prefs) === FALSE) {
1191 // print "adding " . $line["pref_name"] . "<br>";
1193 db_query($link, "INSERT INTO ttrss_user_prefs
1194 (owner_uid,pref_name,value) VALUES
1195 ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')");
1200 db_query($link, "COMMIT");
1204 function lookup_user_id($link, $user) {
1206 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1209 if (db_num_rows($result) == 1) {
1210 return db_fetch_result($result, 0, "id");
1216 function http_authenticate_user($link) {
1218 error_log("http_authenticate_user: ".$_SERVER["PHP_AUTH_USER"]."\n", 3, '/tmp/tt-rss.log');
1220 if (!$_SERVER["PHP_AUTH_USER"]) {
1222 header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"');
1223 header('HTTP/1.0 401 Unauthorized');
1227 $auth_result = authenticate_user($link,
1228 $_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]);
1230 if (!$auth_result) {
1231 header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"');
1232 header('HTTP/1.0 401 Unauthorized');
1240 function authenticate_user($link, $login, $password, $force_auth = false) {
1242 if (!SINGLE_USER_MODE
) {
1244 $pwd_hash = 'SHA1:' . sha1($password);
1246 if ($force_auth && defined('_DEBUG_USER_SWITCH')) {
1247 $query = "SELECT id,login,access_level
1248 FROM ttrss_users WHERE
1251 $query = "SELECT id,login,access_level
1252 FROM ttrss_users WHERE
1253 login = '$login' AND pwd_hash = '$pwd_hash'";
1256 $result = db_query($link, $query);
1258 if (db_num_rows($result) == 1) {
1259 $_SESSION["uid"] = db_fetch_result($result, 0, "id");
1260 $_SESSION["name"] = db_fetch_result($result, 0, "login");
1261 $_SESSION["access_level"] = db_fetch_result($result, 0, "access_level");
1263 db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
1266 $user_theme = get_user_theme_path($link);
1268 $_SESSION["theme"] = $user_theme;
1269 $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
1271 initialize_user_prefs($link, $_SESSION["uid"]);
1280 $_SESSION["uid"] = 1;
1281 $_SESSION["name"] = "admin";
1283 $user_theme = get_user_theme_path($link);
1285 $_SESSION["theme"] = $user_theme;
1286 $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
1288 initialize_user_prefs($link, $_SESSION["uid"]);
1294 function make_password($length = 8) {
1297 $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ";
1301 while ($i < $length) {
1302 $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
1304 if (!strstr($password, $char)) {
1312 // this is called after user is created to initialize default feeds, labels
1315 // user preferences are checked on every login, not here
1317 function initialize_user($link, $uid) {
1319 db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
1320 values ('$uid','unread = true', 'Unread articles')");
1322 db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
1323 values ('$uid','last_read is null and unread = false', 'Updated articles')");
1325 db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url)
1326 values ('$uid', 'Tiny Tiny RSS: New Releases',
1327 'http://tt-rss.spb.ru/releases.rss')");
1329 db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url)
1330 values ('$uid', 'Tiny Tiny RSS: Forum',
1331 'http://tt-rss.spb.ru/forum/rss.php')");
1334 function logout_user() {
1336 if (isset($_COOKIE[session_name()])) {
1337 setcookie(session_name(), '', time()-42000, '/');
1341 function get_script_urlpath() {
1342 return preg_replace('/\/[^\/]*$/', "", $_SERVER["REQUEST_URI"]);
1345 function validate_session($link) {
1346 if (SESSION_CHECK_ADDRESS
&& $_SESSION["uid"]) {
1347 if ($_SESSION["ip_address"]) {
1348 if ($_SESSION["ip_address"] != $_SERVER["REMOTE_ADDR"]) {
1349 $_SESSION["login_error_msg"] = "Session failed to validate (incorrect IP)";
1355 /* if ($_SESSION["cookie_lifetime"] && $_SESSION["uid"]) {
1357 //print_r($_SESSION);
1359 if (time() > $_SESSION["cookie_lifetime"]) {
1367 function login_sequence($link, $mobile = false) {
1368 if (!SINGLE_USER_MODE
) {
1370 if (defined('_DEBUG_USER_SWITCH') && $_SESSION["uid"]) {
1371 $swu = db_escape_string($_REQUEST["swu"]);
1373 $_SESSION["prefs_cache"] = false;
1374 return authenticate_user($link, $swu, null, true);
1378 $login_action = $_POST["login_action"];
1380 # try to authenticate user if called from login form
1381 if ($login_action == "do_login") {
1382 $login = $_POST["login"];
1383 $password = $_POST["password"];
1384 $remember_me = $_POST["remember_me"];
1386 if (authenticate_user($link, $login, $password)) {
1387 $_POST["password"] = "";
1389 $_SESSION["language"] = $_POST["language"];
1391 header("Location: " . $_SERVER["REQUEST_URI"]);
1396 $_SESSION["login_error_msg"] = "Incorrect username or password";
1400 // print session_id();
1401 // print_r($_SESSION);
1403 if (!$_SESSION["uid"] ||
!validate_session($link)) {
1404 render_login_form($link, $mobile);
1407 /* bump login timestamp */
1408 db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
1413 return authenticate_user($link, "admin", null);
1417 function truncate_string($str, $max_len) {
1418 if (mb_strlen($str, "utf-8") > $max_len - 3) {
1419 return mb_substr($str, 0, $max_len, "utf-8") . "...";
1425 function get_user_theme_path($link) {
1426 $result = db_query($link, "SELECT theme_path
1428 ttrss_themes,ttrss_users
1429 WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]);
1430 if (db_num_rows($result) != 0) {
1431 return db_fetch_result($result, 0, "theme_path");
1437 function smart_date_time($timestamp) {
1438 if (date("Y.m.d", $timestamp) == date("Y.m.d")) {
1439 return date("G:i", $timestamp);
1440 } else if (date("Y", $timestamp) == date("Y")) {
1441 return date("M d, G:i", $timestamp);
1443 return date("Y/m/d, G:i", $timestamp);
1447 function smart_date($timestamp) {
1448 if (date("Y.m.d", $timestamp) == date("Y.m.d")) {
1450 } else if (date("Y", $timestamp) == date("Y")) {
1451 return date("D m", $timestamp);
1453 return date("Y/m/d", $timestamp);
1457 function sql_bool_to_string($s) {
1458 if ($s == "t" ||
$s == "1") {
1465 function sql_bool_to_bool($s) {
1466 if ($s == "t" ||
$s == "1") {
1474 function toggleEvenOdd($a) {
1481 function sanity_check($link) {
1486 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
1487 $schema_version = db_fetch_result($result, 0, "schema_version");
1489 if ($schema_version != SCHEMA_VERSION
) {
1493 if (DB_TYPE
== "mysql") {
1494 $result = db_query($link, "SELECT true", false);
1495 if (db_num_rows($result) != 1) {
1500 error_reporting (DEFAULT_ERROR_LEVEL
);
1502 if ($error_code != 0) {
1503 print_error_xml($error_code);
1510 function file_is_locked($filename) {
1512 $fp = fopen($filename, "r");
1513 error_reporting(DEFAULT_ERROR_LEVEL
);
1515 if (flock($fp, LOCK_EX | LOCK_NB
)) {
1516 flock($fp, LOCK_UN
);
1526 function make_lockfile($filename) {
1527 $fp = fopen($filename, "w");
1529 if (flock($fp, LOCK_EX | LOCK_NB
)) {
1536 function make_stampfile($filename) {
1537 $fp = fopen($filename, "w");
1539 if (flock($fp, LOCK_EX | LOCK_NB
)) {
1540 fwrite($fp, time() . "\n");
1541 flock($fp, LOCK_UN
);
1549 function read_stampfile($filename) {
1552 $fp = fopen($filename, "r");
1553 error_reporting (DEFAULT_ERROR_LEVEL
);
1555 if (flock($fp, LOCK_EX
)) {
1556 $stamp = fgets($fp);
1557 flock($fp, LOCK_UN
);
1565 function sql_random_function() {
1566 if (DB_TYPE
== "mysql") {
1573 function catchup_feed($link, $feed, $cat_view) {
1575 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
1580 $cat_qpart = "cat_id = '$feed'";
1582 $cat_qpart = "cat_id IS NULL";
1585 $tmp_result = db_query($link, "SELECT id
1586 FROM ttrss_feeds WHERE $cat_qpart AND owner_uid = " .
1589 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1591 $tmp_feed = $tmp_line["id"];
1593 db_query($link, "UPDATE ttrss_user_entries
1594 SET unread = false,last_read = NOW()
1595 WHERE feed_id = '$tmp_feed' AND owner_uid = " . $_SESSION["uid"]);
1598 } else if ($feed > 0) {
1600 $tmp_result = db_query($link, "SELECT id
1601 FROM ttrss_feeds WHERE parent_feed = '$feed'
1602 ORDER BY cat_id,title");
1604 $parent_ids = array();
1606 if (db_num_rows($tmp_result) > 0) {
1607 while ($p = db_fetch_assoc($tmp_result)) {
1608 array_push($parent_ids, "feed_id = " . $p["id"]);
1611 $children_qpart = implode(" OR ", $parent_ids);
1613 db_query($link, "UPDATE ttrss_user_entries
1614 SET unread = false,last_read = NOW()
1615 WHERE (feed_id = '$feed' OR $children_qpart)
1616 AND owner_uid = " . $_SESSION["uid"]);
1619 db_query($link, "UPDATE ttrss_user_entries
1620 SET unread = false,last_read = NOW()
1621 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1624 } else if ($feed < 0 && $feed > -10) { // special, like starred
1627 db_query($link, "UPDATE ttrss_user_entries
1628 SET unread = false,last_read = NOW()
1629 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
1633 db_query($link, "UPDATE ttrss_user_entries
1634 SET unread = false,last_read = NOW()
1635 WHERE published = true AND owner_uid = ".$_SESSION["uid"]);
1638 } else if ($feed < -10) { // label
1640 // TODO make this more efficient
1642 $label_id = -$feed - 11;
1644 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1645 WHERE id = '$label_id'");
1648 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
1650 db_query($link, "BEGIN");
1652 $tmp2_result = db_query($link,
1656 ttrss_user_entries,ttrss_entries,ttrss_feeds
1658 ref_id = ttrss_entries.id AND
1659 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1661 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
1663 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
1664 db_query($link, "UPDATE
1667 unread = false, last_read = NOW()
1669 int_id = " . $tmp_line["int_id"]);
1672 db_query($link, "COMMIT");
1674 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
1675 SET unread = false,last_read = NOW()
1678 AND owner_uid = ".$_SESSION["uid"]); */
1682 db_query($link, "BEGIN");
1684 $tag_name = db_escape_string($feed);
1686 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
1687 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
1689 while ($line = db_fetch_assoc($result)) {
1690 db_query($link, "UPDATE ttrss_user_entries SET
1691 unread = false, last_read = NOW()
1692 WHERE int_id = " . $line["post_int_id"]);
1694 db_query($link, "COMMIT");
1698 function update_generic_feed($link, $feed, $cat_view) {
1702 $cat_qpart = "cat_id = '$feed'";
1704 $cat_qpart = "cat_id IS NULL";
1707 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
1708 WHERE $cat_qpart AND owner_uid = " . $_SESSION["uid"]);
1710 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1711 $feed_url = $tmp_line["feed_url"];
1712 update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON
);
1716 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
1717 WHERE id = '$feed'");
1718 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
1719 update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON
);
1723 function getAllCounters($link, $omode = "flc") {
1724 /* getLabelCounters($link);
1725 getFeedCounters($link);
1726 getTagCounters($link);
1727 getGlobalCounters($link);
1728 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1729 getCategoryCounters($link);
1732 if (!$omode) $omode = "flc";
1734 getGlobalCounters($link);
1736 if (strchr($omode, "l")) getLabelCounters($link);
1737 if (strchr($omode, "f")) getFeedCounters($link);
1738 if (strchr($omode, "t")) getTagCounters($link);
1739 if (strchr($omode, "c")) {
1740 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1741 getCategoryCounters($link);
1746 function getCategoryCounters($link) {
1747 $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id)
1748 FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id
1749 AND unread = true)) AS unread FROM ttrss_feeds
1751 hidden = false AND owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
1753 while ($line = db_fetch_assoc($result)) {
1754 $line["cat_id"] = sprintf("%d", $line["cat_id"]);
1755 print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"".
1756 $line["unread"]."\"/>";
1760 function getCategoryUnread($link, $cat) {
1763 $cat_query = "cat_id = '$cat'";
1765 $cat_query = "cat_id IS NULL";
1768 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query
1770 AND owner_uid = " . $_SESSION["uid"]);
1772 $cat_feeds = array();
1773 while ($line = db_fetch_assoc($result)) {
1774 array_push($cat_feeds, "feed_id = " . $line["id"]);
1777 if (count($cat_feeds) == 0) return 0;
1779 $match_part = implode(" OR ", $cat_feeds);
1781 $result = db_query($link, "SELECT COUNT(int_id) AS unread
1782 FROM ttrss_user_entries
1783 WHERE unread = true AND ($match_part) AND owner_uid = " . $_SESSION["uid"]);
1787 # this needs to be rewritten
1788 while ($line = db_fetch_assoc($result)) {
1789 $unread +
= $line["unread"];
1796 function getFeedUnread($link, $feed, $is_cat = false) {
1797 $n_feed = sprintf("%d", $feed);
1800 return getCategoryUnread($link, $n_feed);
1801 } else if ($n_feed == -1) {
1802 $match_part = "marked = true";
1803 } else if ($n_feed == -2) {
1804 $match_part = "published = true";
1805 } else if ($n_feed > 0) {
1807 $result = db_query($link, "SELECT id FROM ttrss_feeds
1808 WHERE parent_feed = '$n_feed'
1810 AND owner_uid = " . $_SESSION["uid"]);
1812 if (db_num_rows($result) > 0) {
1814 $linked_feeds = array();
1815 while ($line = db_fetch_assoc($result)) {
1816 array_push($linked_feeds, "feed_id = " . $line["id"]);
1819 array_push($linked_feeds, "feed_id = $n_feed");
1821 $match_part = implode(" OR ", $linked_feeds);
1823 $result = db_query($link, "SELECT COUNT(int_id) AS unread
1824 FROM ttrss_user_entries
1825 WHERE unread = true AND ($match_part)
1826 AND owner_uid = " . $_SESSION["uid"]);
1830 # this needs to be rewritten
1831 while ($line = db_fetch_assoc($result)) {
1832 $unread +
= $line["unread"];
1838 $match_part = "feed_id = '$n_feed'";
1840 } else if ($feed < -10) {
1842 $label_id = -$feed - 11;
1844 $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE
1845 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
1847 $match_part = db_fetch_result($result, 0, "sql_exp");
1852 $result = db_query($link, "SELECT count(int_id) AS unread
1853 FROM ttrss_user_entries,ttrss_feeds,ttrss_entries WHERE
1854 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1855 ttrss_user_entries.ref_id = ttrss_entries.id AND
1856 ttrss_feeds.hidden = false AND
1857 unread = true AND ($match_part) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
1861 $result = db_query($link, "SELECT COUNT(post_int_id) AS unread
1862 FROM ttrss_tags,ttrss_user_entries
1863 WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND
1864 ttrss_tags.owner_uid = " . $_SESSION["uid"]);
1867 $unread = db_fetch_result($result, 0, "unread");
1872 /* FIXME this needs reworking */
1874 function getGlobalUnread($link, $user_id = false) {
1877 $user_id = $_SESSION["uid"];
1880 $result = db_query($link, "SELECT count(ttrss_entries.id) as c_id FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
1881 WHERE unread = true AND
1882 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1883 ttrss_user_entries.ref_id = ttrss_entries.id AND
1885 ttrss_user_entries.owner_uid = '$user_id'");
1886 $c_id = db_fetch_result($result, 0, "c_id");
1890 function getGlobalCounters($link, $global_unread = -1) {
1891 if ($global_unread == -1) {
1892 $global_unread = getGlobalUnread($link);
1894 print "<counter type=\"global\" id='global-unread'
1895 counter='$global_unread'/>";
1897 $result = db_query($link, "SELECT COUNT(id) AS fn FROM
1898 ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
1900 $subscribed_feeds = db_fetch_result($result, 0, "fn");
1902 print "<counter type=\"global\" id='subscribed-feeds'
1903 counter='$subscribed_feeds'/>";
1907 function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
1910 if (!$_SESSION["tctr_last_value"]) {
1911 $_SESSION["tctr_last_value"] = array();
1915 $old_counters = $_SESSION["tctr_last_value"];
1917 $tctrs_modified = false;
1919 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
1920 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
1921 ttrss_user_entries.ref_id = ttrss_entries.id AND
1922 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
1923 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
1925 select tag_name,0 as count FROM ttrss_tags
1926 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
1928 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
1929 FROM ttrss_user_entries WHERE int_id = post_int_id
1930 AND unread = true)) AS count FROM ttrss_tags
1931 WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name
1932 ORDER BY count DESC LIMIT 55");
1936 while ($line = db_fetch_assoc($result)) {
1937 $tags[$line["tag_name"]] +
= $line["count"];
1940 foreach (array_keys($tags) as $tag) {
1941 $unread = $tags[$tag];
1943 $tag = htmlspecialchars($tag);
1945 if (!$smart_mode ||
$old_counters[$tag] != $unread) {
1946 $old_counters[$tag] = $unread;
1947 $tctrs_modified = true;
1948 print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>";
1953 if ($smart_mode && $tctrs_modified) {
1954 $_SESSION["tctr_last_value"] = $old_counters;
1959 function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS
, $ret_mode = false) {
1962 if (!$_SESSION["lctr_last_value"]) {
1963 $_SESSION["lctr_last_value"] = array();
1969 $old_counters = $_SESSION["lctr_last_value"];
1970 $lctrs_modified = false;
1972 $result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
1973 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
1974 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1975 hidden = false AND unread = true AND ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
1977 $count = db_fetch_result($result, 0, "count");
1980 print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>";
1982 $ret_arr["-1"]["counter"] = $count;
1983 $ret_arr["-1"]["description"] = "Starred";
1986 $result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
1987 WHERE published = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
1988 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1989 hidden = false AND unread = true AND ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
1991 $count = db_fetch_result($result, 0, "count");
1994 print "<counter type=\"label\" id=\"-2\" counter=\"$count\"/>";
1996 $ret_arr["-2"]["counter"] = $count;
1997 $ret_arr["-2"]["description"] = "Published";
2001 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
2002 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
2004 while ($line = db_fetch_assoc($result)) {
2006 $id = -$line["id"] - 11;
2008 $label_name = $line["description"];
2010 error_reporting (0);
2012 $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_user_entries,ttrss_entries,ttrss_feeds
2013 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
2014 ttrss_feeds.hidden = false AND
2015 ttrss_user_entries.feed_id = ttrss_feeds.id AND
2016 ttrss_user_entries.ref_id = ttrss_entries.id AND
2017 ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
2019 $count = db_fetch_result($tmp_result, 0, "count");
2021 if (!$smart_mode ||
$old_counters[$id] != $count) {
2022 $old_counters[$id] = $count;
2023 $lctrs_modified = true;
2025 print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>";
2027 $ret_arr[$id]["counter"] = $count;
2028 $ret_arr[$id]["description"] = $label_name;
2032 error_reporting (DEFAULT_ERROR_LEVEL
);
2035 if ($smart_mode && $lctrs_modified) {
2036 $_SESSION["lctr_last_value"] = $old_counters;
2042 /* function getFeedCounter($link, $id) {
2044 $result = db_query($link, "SELECT
2045 count(id) as count,last_error
2046 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
2047 WHERE feed_id = '$id' AND unread = true
2048 AND ttrss_user_entries.feed_id = ttrss_feeds.id
2049 AND ttrss_user_entries.ref_id = ttrss_entries.id");
2051 $count = db_fetch_result($result, 0, "count");
2052 $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error"));
2054 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>";
2057 function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
2060 if (!$_SESSION["fctr_last_value"]) {
2061 $_SESSION["fctr_last_value"] = array();
2065 $old_counters = $_SESSION["fctr_last_value"];
2067 /* $result = db_query($link, "SELECT id,last_error,parent_feed,
2068 SUBSTRING(last_updated,1,19) AS last_updated,
2070 FROM ttrss_entries,ttrss_user_entries
2071 WHERE feed_id = ttrss_feeds.id AND
2072 ttrss_user_entries.ref_id = ttrss_entries.id
2073 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
2074 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . "
2075 AND parent_feed IS NULL"); */
2077 $result = db_query($link, "SELECT ttrss_feeds.id,
2078 SUBSTRING(ttrss_feeds.last_updated,1,19) AS last_updated,
2080 COUNT(ttrss_entries.id) AS count
2082 LEFT JOIN ttrss_user_entries ON (ttrss_user_entries.feed_id = ttrss_feeds.id
2083 AND ttrss_user_entries.owner_uid = ttrss_feeds.owner_uid
2084 AND ttrss_user_entries.unread = true)
2085 LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id)
2086 WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]."
2087 AND parent_feed IS NULL
2088 GROUP BY ttrss_feeds.id, ttrss_feeds.title, ttrss_feeds.last_updated, last_error");
2090 $fctrs_modified = false;
2092 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
2094 while ($line = db_fetch_assoc($result)) {
2097 $count = $line["count"];
2098 $last_error = htmlspecialchars($line["last_error"]);
2100 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
2101 $last_updated = smart_date_time(strtotime($line["last_updated"]));
2103 $last_updated = date($short_date, strtotime($line["last_updated"]));
2106 $has_img = is_file(ICONS_DIR
. "/$id.ico");
2108 $tmp_result = db_query($link,
2109 "SELECT id,COUNT(unread) AS unread
2110 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
2111 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
2112 WHERE parent_feed = '$id' AND unread = true GROUP BY ttrss_feeds.id");
2114 if (db_num_rows($tmp_result) > 0) {
2115 while ($l = db_fetch_assoc($tmp_result)) {
2116 $count +
= $l["unread"];
2120 if (!$smart_mode ||
$old_counters[$id] != $count) {
2121 $old_counters[$id] = $count;
2122 $fctrs_modified = true;
2125 $error_part = "error=\"$last_error\"";
2131 $has_img_part = "hi=\"$has_img\"";
2136 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part updated=\"$last_updated\"/>";
2140 if ($smart_mode && $fctrs_modified) {
2141 $_SESSION["fctr_last_value"] = $old_counters;
2145 function get_script_dt_add() {
2146 if (strpos(VERSION
, ".99") === false) {
2153 function get_pgsql_version($link) {
2154 $result = db_query($link, "SELECT version() AS version");
2155 $version = split(" ", db_fetch_result($result, 0, "version"));
2159 function print_error_xml($code, $add_msg = "") {
2162 $error_msg = $ERRORS[$code];
2165 $error_msg = "$error_msg; $add_msg";
2168 print "<rpc-reply>";
2169 print "<error error-code=\"$code\" error-msg=\"$error_msg\"/>";
2170 print "</rpc-reply>";
2173 function subscribe_to_feed($link, $feed_link, $cat_id = 0,
2174 $auth_login = '', $auth_pass = '') {
2176 # check for feed:http://url
2177 $feed_link = trim(preg_replace("/^feed:/", "", $feed_link));
2179 # check for feed://URL
2180 if (strpos($feed_link, "//") === 0) {
2181 $feed_link = "http:$feed_link";
2184 if ($feed_link == "") return;
2186 if ($cat_id == "0" ||
!$cat_id) {
2187 $cat_qpart = "NULL";
2189 $cat_qpart = "'$cat_id'";
2192 $result = db_query($link,
2193 "SELECT id FROM ttrss_feeds
2194 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
2196 if (db_num_rows($result) == 0) {
2198 $result = db_query($link,
2199 "INSERT INTO ttrss_feeds
2200 (owner_uid,feed_url,title,cat_id, auth_login,auth_pass)
2201 VALUES ('".$_SESSION["uid"]."', '$feed_link',
2202 '[Unknown]', $cat_qpart, '$auth_login', '$auth_pass')");
2204 $result = db_query($link,
2205 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
2206 AND owner_uid = " . $_SESSION["uid"]);
2208 $feed_id = db_fetch_result($result, 0, "id");
2211 update_rss_feed($link, $feed_link, $feed_id, true);
2220 function print_feed_select($link, $id, $default_id = "",
2221 $attributes = "", $include_all_feeds = true) {
2223 print "<select id=\"$id\" name=\"$id\" $attributes>";
2224 if ($include_all_feeds) {
2225 print "<option value=\"0\">".__('All feeds')."</option>";
2228 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2229 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2231 if (db_num_rows($result) > 0 && $include_all_feeds) {
2232 print "<option disabled>--------</option>";
2235 while ($line = db_fetch_assoc($result)) {
2236 if ($line["id"] == $default_id) {
2237 $is_selected = "selected";
2241 printf("<option $is_selected value='%d'>%s</option>",
2242 $line["id"], htmlspecialchars($line["title"]));
2248 function print_feed_cat_select($link, $id, $default_id = "",
2249 $attributes = "", $include_all_cats = true) {
2251 print "<select id=\"$id\" name=\"$id\" $attributes>";
2253 if ($include_all_cats) {
2254 print "<option value=\"0\">".__('Uncategorized')."</option>";
2257 $result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
2258 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2260 if (db_num_rows($result) > 0 && $include_all_cats) {
2261 print "<option disabled>--------</option>";
2264 while ($line = db_fetch_assoc($result)) {
2265 if ($line["id"] == $default_id) {
2266 $is_selected = "selected";
2270 printf("<option $is_selected value='%d'>%s</option>",
2271 $line["id"], htmlspecialchars($line["title"]));
2277 function checkbox_to_sql_bool($val) {
2278 return ($val == "on") ?
"true" : "false";
2281 function getFeedCatTitle($link, $id) {
2283 return __("Special");
2284 } else if ($id < -10) {
2285 return __("Labels");
2286 } else if ($id > 0) {
2287 $result = db_query($link, "SELECT ttrss_feed_categories.title
2288 FROM ttrss_feeds, ttrss_feed_categories WHERE ttrss_feeds.id = '$id' AND
2289 cat_id = ttrss_feed_categories.id");
2290 if (db_num_rows($result) == 1) {
2291 return db_fetch_result($result, 0, "title");
2293 return __("Uncategorized");
2296 return "getFeedCatTitle($id) failed";
2301 function getFeedTitle($link, $id) {
2303 return __("Starred articles");
2304 } else if ($id == -2) {
2305 return __("Published articles");
2306 } else if ($id < -10) {
2307 $label_id = -10 - $id;
2308 $result = db_query($link, "SELECT description FROM ttrss_labels WHERE id = '$label_id'");
2309 if (db_num_rows($result) == 1) {
2310 return db_fetch_result($result, 0, "description");
2312 return "Unknown label ($label_id)";
2315 } else if ($id > 0) {
2316 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$id'");
2317 if (db_num_rows($result) == 1) {
2318 return db_fetch_result($result, 0, "title");
2320 return "Unknown feed ($id)";
2323 return "getFeedTitle($id) failed";
2328 function get_session_cookie_name() {
2329 return ((!defined('TTRSS_SESSION_NAME')) ?
"ttrss_sid" : TTRSS_SESSION_NAME
);
2332 function print_init_params($link) {
2333 print "<init-params>";
2334 if ($_SESSION["stored-params"]) {
2335 foreach (array_keys($_SESSION["stored-params"]) as $key) {
2337 $value = htmlspecialchars($_SESSION["stored-params"][$key]);
2338 print "<param key=\"$key\" value=\"$value\"/>";
2343 print "<param key=\"daemon_enabled\" value=\"" . ENABLE_UPDATE_DAEMON
. "\"/>";
2344 print "<param key=\"feeds_frame_refresh\" value=\"" . FEEDS_FRAME_REFRESH
. "\"/>";
2345 print "<param key=\"daemon_refresh_only\" value=\"" . DAEMON_REFRESH_ONLY
. "\"/>";
2347 print "<param key=\"on_catchup_show_next_feed\" value=\"" .
2348 get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED") . "\"/>";
2350 print "<param key=\"hide_read_feeds\" value=\"" .
2351 (int) get_pref($link, "HIDE_READ_FEEDS") . "\"/>";
2353 print "<param key=\"feeds_sort_by_unread\" value=\"" .
2354 (int) get_pref($link, "FEEDS_SORT_BY_UNREAD") . "\"/>";
2356 print "<param key=\"confirm_feed_catchup\" value=\"" .
2357 (int) get_pref($link, "CONFIRM_FEED_CATCHUP") . "\"/>";
2359 print "<param key=\"cdm_auto_catchup\" value=\"" .
2360 (int) get_pref($link, "CDM_AUTO_CATCHUP") . "\"/>";
2362 print "<param key=\"icons_url\" value=\"" . ICONS_URL
. "\"/>";
2364 print "<param key=\"cookie_lifetime\" value=\"" . SESSION_COOKIE_LIFETIME
. "\"/>";
2366 print "<param key=\"default_view_mode\" value=\"" .
2367 get_pref($link, "_DEFAULT_VIEW_MODE") . "\"/>";
2369 print "<param key=\"default_view_limit\" value=\"" .
2370 (int) get_pref($link, "_DEFAULT_VIEW_LIMIT") . "\"/>";
2372 print "<param key=\"prefs_active_tab\" value=\"" .
2373 get_pref($link, "_PREFS_ACTIVE_TAB") . "\"/>";
2375 print "<param key=\"infobox_disable_overlay\" value=\"" .
2376 get_pref($link, "_INFOBOX_DISABLE_OVERLAY") . "\"/>";
2378 print "</init-params>";
2381 function print_runtime_info($link) {
2382 print "<runtime-info>";
2383 if (ENABLE_UPDATE_DAEMON
) {
2384 print "<param key=\"daemon_is_running\" value=\"".
2385 sprintf("%d", file_is_locked("update_daemon.lock")) . "\"/>";
2387 if ($_SESSION["daemon_stamp_check"] +
600 < time()) {
2389 $stamp = (int)read_stampfile("update_daemon.stamp");
2392 if ($stamp +
86400*3 < time()) {
2393 print "<param key=\"daemon_stamp_ok\" value=\"0\"/>";
2395 print "<param key=\"daemon_stamp_ok\" value=\"1\"/>";
2398 $stamp_fmt = date("Y.m.d, G:i", $stamp);
2400 print "<param key=\"daemon_stamp\" value=\"$stamp_fmt\"/>";
2403 $_SESSION["daemon_stamp_check"] = time();
2407 if (CHECK_FOR_NEW_VERSION
&& $_SESSION["access_level"] >= 10) {
2409 if ($_SESSION["last_version_check"] +
600 < time()) {
2410 $new_version_details = check_for_update($link);
2412 print "<param key=\"new_version_available\" value=\"".
2413 sprintf("%d", $new_version_details != ""). "\"/>";
2415 $_SESSION["last_version_check"] = time();
2419 print "</runtime-info>";
2422 function getSearchSql($search, $match_on) {
2424 $search_query_part = "";
2426 $keywords = split(" ", $search);
2427 $query_keywords = array();
2429 if ($match_on == "both") {
2431 foreach ($keywords as $k) {
2432 array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%')
2433 OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
2436 $search_query_part = implode("AND", $query_keywords) . " AND ";
2438 } else if ($match_on == "title") {
2440 foreach ($keywords as $k) {
2441 array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))");
2444 $search_query_part = implode("AND", $query_keywords) . " AND ";
2446 } else if ($match_on == "content") {
2448 foreach ($keywords as $k) {
2449 array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
2453 $search_query_part = implode("AND", $query_keywords);
2455 return $search_query_part;
2458 function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0) {
2460 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
2464 $search_query_part = getSearchSql($search, $match_on);
2465 $search_query_part .= " AND ";
2468 $search_query_part = "";
2471 $view_query_part = "";
2473 if ($view_mode == "adaptive") {
2475 $view_query_part = " ";
2476 } else if ($feed != -1) {
2477 $unread = getFeedUnread($link, $feed, $cat_view);
2479 $view_query_part = " unread = true AND ";
2484 if ($view_mode == "marked") {
2485 $view_query_part = " marked = true AND ";
2488 if ($view_mode == "unread") {
2489 $view_query_part = " unread = true AND ";
2493 $limit_query_part = "LIMIT " . $limit;
2496 $vfeed_query_part = "";
2498 // override query strategy and enable feed display when searching globally
2499 if ($search && $search_mode == "all_feeds") {
2500 $query_strategy_part = "ttrss_entries.id > 0";
2501 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2502 } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
2503 $query_strategy_part = "ttrss_entries.id > 0";
2504 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
2505 id = feed_id) as feed_title,";
2506 } else if ($feed >= 0 && $search && $search_mode == "this_cat") {
2508 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2510 $tmp_result = false;
2513 $tmp_result = db_query($link, "SELECT id
2514 FROM ttrss_feeds WHERE cat_id = '$feed'");
2516 $tmp_result = db_query($link, "SELECT id
2517 FROM ttrss_feeds WHERE cat_id = (SELECT cat_id FROM ttrss_feeds
2518 WHERE id = '$feed') AND id != '$feed'");
2521 $cat_siblings = array();
2523 if (db_num_rows($tmp_result) > 0) {
2524 while ($p = db_fetch_assoc($tmp_result)) {
2525 array_push($cat_siblings, "feed_id = " . $p["id"]);
2528 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
2529 $feed, implode(" OR ", $cat_siblings));
2532 $query_strategy_part = "ttrss_entries.id > 0";
2535 } else if ($feed >= 0) {
2540 $query_strategy_part = "cat_id = '$feed'";
2542 $query_strategy_part = "cat_id IS NULL";
2545 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2548 $tmp_result = db_query($link, "SELECT id
2549 FROM ttrss_feeds WHERE parent_feed = '$feed'
2550 ORDER BY cat_id,title");
2552 $parent_ids = array();
2554 if (db_num_rows($tmp_result) > 0) {
2555 while ($p = db_fetch_assoc($tmp_result)) {
2556 array_push($parent_ids, "feed_id = " . $p["id"]);
2559 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
2560 $feed, implode(" OR ", $parent_ids));
2562 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2564 $query_strategy_part = "feed_id = '$feed'";
2567 } else if ($feed == -1) { // starred virtual feed
2568 $query_strategy_part = "marked = true";
2569 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2570 } else if ($feed == -2) { // published virtual feed
2571 $query_strategy_part = "published = true";
2572 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2573 } else if ($feed <= -10) { // labels
2574 $label_id = -$feed - 11;
2576 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
2577 WHERE id = '$label_id'");
2579 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
2581 if (!$query_strategy_part) {
2585 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
2587 $query_strategy_part = "id > 0"; // dumb
2590 if (get_pref($link, 'REVERSE_HEADLINES')) {
2591 $order_by = "updated";
2593 $order_by = "updated DESC";
2596 if ($override_order) {
2597 $order_by = $override_order;
2602 if ($search && $search_mode == "all_feeds") {
2603 $feed_title = __("Search results")." ($search)";
2604 } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
2605 $feed_title = __("Search results")." ($search, $feed)";
2606 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
2607 $feed_title = $feed;
2608 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
2613 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
2614 WHERE id = '$feed' AND owner_uid = $owner_uid");
2615 $feed_title = db_fetch_result($result, 0, "title");
2617 $feed_title = __("Uncategorized");
2621 $feed_title = __("Searched for")." $search ($feed_title)";
2626 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
2627 WHERE id = '$feed' AND owner_uid = $owner_uid");
2629 $feed_title = db_fetch_result($result, 0, "title");
2630 $feed_site_url = db_fetch_result($result, 0, "site_url");
2631 $last_error = db_fetch_result($result, 0, "last_error");
2634 $feed_title = __("Searched for") . " $search ($feed_title)";
2638 } else if ($feed == -1) {
2639 $feed_title = __("Starred articles");
2640 } else if ($feed == -2) {
2641 $feed_title = __("Published articles");
2642 } else if ($feed < -10) {
2643 $label_id = -$feed - 11;
2644 $result = db_query($link, "SELECT description FROM ttrss_labels
2645 WHERE id = '$label_id'");
2646 $feed_title = db_fetch_result($result, 0, "description");
2649 $feed_title = __("Searched for") . " $search ($feed_title)";
2655 if ($feed < -10) error_reporting (0);
2657 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
2660 $feed_kind = "Feeds";
2662 $feed_kind = "Labels";
2665 $content_query_part = "content as content_preview,";
2667 if ($limit_query_part) {
2668 $offset_query_part = "OFFSET $offset";
2673 ttrss_entries.id,ttrss_entries.title,
2675 unread,feed_id,marked,published,link,last_read,
2676 SUBSTRING(last_read,1,19) as last_read_noms,
2679 SUBSTRING(updated,1,19) as updated_noms,
2682 ttrss_entries,ttrss_user_entries,ttrss_feeds
2684 ttrss_feeds.hidden = false AND
2685 ttrss_user_entries.feed_id = ttrss_feeds.id AND
2686 ttrss_user_entries.ref_id = ttrss_entries.id AND
2687 ttrss_user_entries.owner_uid = '$owner_uid' AND
2690 $query_strategy_part ORDER BY $order_by
2691 $limit_query_part $offset_query_part";
2693 $result = db_query($link, $query);
2695 if ($_GET["debug"]) print $query;
2700 $feed_kind = "Tags";
2702 $result = db_query($link, "SELECT
2704 ttrss_entries.id as id,title,
2707 marked,link,last_read,
2708 SUBSTRING(last_read,1,19) as last_read_noms,
2711 SUBSTRING(updated,1,19) as updated_noms
2713 ttrss_entries,ttrss_user_entries,ttrss_tags
2715 ref_id = ttrss_entries.id AND
2716 ttrss_user_entries.owner_uid = '$owner_uid' AND
2717 post_int_id = int_id AND tag_name = '$feed' AND
2720 $query_strategy_part ORDER BY $order_by
2721 $limit_query_part");
2724 return array($result, $feed_title, $feed_site_url, $last_error);
2728 function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat,
2729 $search, $search_mode, $match_on) {
2731 $qfh_ret = queryFeedHeadlines($link, $feed,
2732 30, false, $is_cat, $search, $search_mode, $match_on, "updated DESC", 0,
2735 $result = $qfh_ret[0];
2736 $feed_title = htmlspecialchars($qfh_ret[1]);
2737 $feed_site_url = $qfh_ret[2];
2738 $last_error = $qfh_ret[3];
2740 // if (!$feed_site_url) $feed_site_url = "http://localhost/";
2742 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>
2743 <?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\"?>
2744 <rss version=\"2.0\">
2746 <title>$feed_title</title>
2747 <link>$feed_site_url</link>
2748 <description>Feed generated by Tiny Tiny RSS</description>";
2750 while ($line = db_fetch_assoc($result)) {
2752 print "<guid>" . htmlspecialchars($line["guid"]) . "</guid>";
2753 print "<link>" . htmlspecialchars($line["link"]) . "</link>";
2755 $tags = get_article_tags($link, $line["id"], $owner_uid);
2757 foreach ($tags as $tag) {
2758 print "<category>" . htmlspecialchars($tag) . "</category>";
2761 $rfc822_date = date('r', strtotime($line["updated"]));
2763 print "<pubDate>$rfc822_date</pubDate>";
2766 htmlspecialchars($line["title"]) . "</title>";
2768 print "<description><![CDATA[" .
2769 $line["content_preview"] . "]]></description>";
2774 print "</channel></rss>";
2778 function getCategoryTitle($link, $cat_id) {
2780 $result = db_query($link, "SELECT title FROM ttrss_feed_categories WHERE
2783 if (db_num_rows($result) == 1) {
2784 return db_fetch_result($result, 0, "title");
2786 return "Uncategorized";
2790 // http://ru2.php.net/strip-tags
2792 function strip_tags_long($textstring, $allowed){
2793 while($textstring != strip_tags($textstring, $allowed))
2795 while (strlen($textstring) != 0)
2797 if (strlen($textstring) > 1024) {
2800 $otherlen = strlen($textstring);
2802 $temptext = strip_tags(substr($textstring,0,$otherlen), $allowed);
2803 $safetext .= $temptext;
2804 $textstring = substr_replace($textstring,'',0,$otherlen);
2806 $textstring = $safetext;
2812 function sanitize_rss($link, $str, $force_strip_tags = false) {
2815 if (get_pref($link, "STRIP_UNSAFE_TAGS") ||
$force_strip_tags) {
2817 global $tw_paranoya_setup;
2819 $res = $tw_parser->strip_tags($res, $tw_paranoya_setup);
2821 // $res = preg_replace("/\r\n|\n|\r/", "", $res);
2822 // $res = strip_tags_long($res, "<p><a><i><em><b><strong><blockquote><br><img><div><span>");
2828 function send_headlines_digests($link, $limit = 100) {
2830 if (!DIGEST_ENABLE
) return false;
2832 $user_limit = DIGEST_EMAIL_LIMIT
;
2835 print "Sending digests, batch of max $user_limit users, days = $days, headline limit = $limit\n\n";
2837 if (DB_TYPE
== "pgsql") {
2838 $interval_query = "last_digest_sent < NOW() - INTERVAL '$days days'";
2839 } else if (DB_TYPE
== "mysql") {
2840 $interval_query = "last_digest_sent < DATE_SUB(NOW(), INTERVAL $days DAY)";
2843 $result = db_query($link, "SELECT id,email FROM ttrss_users
2844 WHERE email != '' AND (last_digest_sent IS NULL OR $interval_query)");
2846 while ($line = db_fetch_assoc($result)) {
2847 if (get_pref($link, 'DIGEST_ENABLE', $line['id'], false)) {
2848 print "Sending digest for UID:" . $line['id'] . " - " . $line["email"] . " ... ";
2850 $tuple = prepare_headlines_digest($link, $line["id"], $days, $limit);
2851 $digest = $tuple[0];
2852 $headlines_count = $tuple[1];
2854 if ($headlines_count > 0) {
2855 $rc = mail($line["login"] . " <" . $line["email"] . ">",
2856 "[tt-rss] New headlines for last 24 hours", $digest,
2857 "From: " . MAIL_FROM
. "\n".
2858 "Content-Type: text/plain; charset=\"utf-8\"\n".
2859 "Content-Transfer-Encoding: 8bit\n");
2861 db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW()
2862 WHERE id = " . $line["id"]);
2864 print "No headlines\n";
2869 // $digest = prepare_headlines_digest($link, $user_id, $days, $limit);
2873 function prepare_headlines_digest($link, $user_id, $days = 1, $limit = 100) {
2874 $tmp = __("New headlines for last 24 hours, as of ") . date("Y/m/d H:m") . "\n";
2875 $tmp .= "=======================================================\n\n";
2877 if (DB_TYPE
== "pgsql") {
2878 $interval_query = "ttrss_entries.date_entered > NOW() - INTERVAL '$days days'";
2879 } else if (DB_TYPE
== "mysql") {
2880 $interval_query = "ttrss_entries.date_entered > DATE_SUB(NOW(), INTERVAL $days DAY)";
2883 $result = db_query($link, "SELECT ttrss_entries.title,
2884 ttrss_feeds.title AS feed_title,
2887 SUBSTRING(last_updated,1,19) AS last_updated
2889 ttrss_user_entries,ttrss_entries,ttrss_feeds
2891 ref_id = ttrss_entries.id AND feed_id = ttrss_feeds.id
2892 AND include_in_digest = true
2894 AND ttrss_user_entries.owner_uid = $user_id
2895 AND unread = true ORDER BY ttrss_feeds.title, date_entered DESC
2898 $cur_feed_title = "";
2900 $headlines_count = db_num_rows($result);
2902 while ($line = db_fetch_assoc($result)) {
2903 $updated = smart_date_time(strtotime($line["last_updated"]));
2904 $feed_title = $line["feed_title"];
2906 if ($cur_feed_title != $feed_title) {
2907 $cur_feed_title = $feed_title;
2909 $tmp .= "$feed_title\n\n";
2912 $tmp .= " * " . trim($line["title"]) . " - $updated\n";
2913 $tmp .= " " . trim($line["link"]) . "\n";
2918 $tmp .= __("You have been sent this email because you have enabled daily digests in Tiny Tiny RSS at ") .
2919 DIGEST_HOSTNAME
. "\n".
2920 __("To unsubscribe, visit your configuration options or contact instance owner.\n");
2923 return array($tmp, $headlines_count);
2926 function check_for_update($link, $brief_fmt = true) {
2927 $releases_feed = "http://tt-rss.spb.ru/releases.rss";
2929 if (!CHECK_FOR_NEW_VERSION ||
$_SESSION["access_level"] < 10) {
2934 $rss = fetch_rss($releases_feed);
2935 error_reporting (DEFAULT_ERROR_LEVEL
);
2939 $items = $rss->items
;
2941 if (!$items ||
!is_array($items)) $items = $rss->entries
;
2942 if (!$items ||
!is_array($items)) $items = $rss;
2944 if (!is_array($items) ||
count($items) == 0) {
2948 $latest_item = $items[0];
2950 $latest_version = trim(preg_replace("/(Milestone)|(completed)/", "", $latest_item["title"]));
2952 $release_url = sanitize_rss($link, $latest_item["link"]);
2953 $content = sanitize_rss($link, $latest_item["description"]);
2955 if (version_compare(VERSION
, $latest_version) == -1) {
2957 return format_notice("<a href=\"javascript:showBlockElement('milestoneDetails')\">
2958 New version of Tiny-Tiny RSS ($latest_version) is available (click for details)</a>
2959 <div id=\"milestoneDetails\">$content</div>");
2961 return "New version of Tiny-Tiny RSS ($latest_version) is available:
2962 <div class='milestoneDetails'>$content</div>
2963 Visit <a target=\"_new\" href=\"http://tt-rss.spb.ru/\">official site</a> for
2964 download and update information.";
2971 function markArticlesById($link, $ids, $cmode) {
2975 foreach ($ids as $id) {
2976 array_push($tmp_ids, "ref_id = '$id'");
2979 $ids_qpart = join(" OR ", $tmp_ids);
2982 db_query($link, "UPDATE ttrss_user_entries SET
2983 marked = false,last_read = NOW()
2984 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
2985 } else if ($cmode == 1) {
2986 db_query($link, "UPDATE ttrss_user_entries SET
2988 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
2990 db_query($link, "UPDATE ttrss_user_entries SET
2991 marked = NOT marked,last_read = NOW()
2992 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
2996 function publishArticlesById($link, $ids, $cmode) {
3000 foreach ($ids as $id) {
3001 array_push($tmp_ids, "ref_id = '$id'");
3004 $ids_qpart = join(" OR ", $tmp_ids);
3007 db_query($link, "UPDATE ttrss_user_entries SET
3008 published = false,last_read = NOW()
3009 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3010 } else if ($cmode == 1) {
3011 db_query($link, "UPDATE ttrss_user_entries SET
3013 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3015 db_query($link, "UPDATE ttrss_user_entries SET
3016 published = NOT published,last_read = NOW()
3017 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3021 function catchupArticlesById($link, $ids, $cmode) {
3025 foreach ($ids as $id) {
3026 array_push($tmp_ids, "ref_id = '$id'");
3029 $ids_qpart = join(" OR ", $tmp_ids);
3032 db_query($link, "UPDATE ttrss_user_entries SET
3033 unread = false,last_read = NOW()
3034 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3035 } else if ($cmode == 1) {
3036 db_query($link, "UPDATE ttrss_user_entries SET
3038 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3040 db_query($link, "UPDATE ttrss_user_entries SET
3041 unread = NOT unread,last_read = NOW()
3042 WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
3046 function catchupArticleById($link, $id, $cmode) {
3049 db_query($link, "UPDATE ttrss_user_entries SET
3050 unread = false,last_read = NOW()
3051 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
3052 } else if ($cmode == 1) {
3053 db_query($link, "UPDATE ttrss_user_entries SET
3055 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
3057 db_query($link, "UPDATE ttrss_user_entries SET
3058 unread = NOT unread,last_read = NOW()
3059 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
3063 function make_guid_from_title($title) {
3064 return preg_replace("/[ \"\',.:;]/", "-",
3065 mb_strtolower(strip_tags($title), 'utf-8'));
3068 function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
3069 $bottom = false, $rtl_content = false, $feed_id = 0,
3070 $is_cat = false, $search = false, $match_on = false,
3071 $search_mode = false, $offset = 0, $limit = 0) {
3073 $user_page_offset = $offset +
1;
3076 $class = "headlinesSubToolbar";
3077 $tid = "headlineActionsTop";
3079 $class = "headlinesSubToolbar";
3080 $tid = "headlineActionsBottom";
3083 print "<table class=\"$class\" id=\"$tid\"
3084 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
3092 $page_prev_link = "javascript:viewFeedGoPage(-1)";
3093 $page_next_link = "javascript:viewFeedGoPage(1)";
3094 $page_first_link = "javascript:viewFeedGoPage(0)";
3096 $catchup_page_link = "javascript:catchupPage()";
3097 $catchup_feed_link = "javascript:catchupCurrentFeed()";
3099 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
3101 $sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)";
3102 $sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)";
3103 $sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)";
3105 $tog_unread_link = "javascript:selectionToggleUnread()";
3106 $tog_marked_link = "javascript:selectionToggleMarked()";
3107 $tog_published_link = "javascript:selectionTogglePublished()";
3111 $sel_all_link = "javascript:cdmSelectArticles('all')";
3112 $sel_unread_link = "javascript:cdmSelectArticles('unread')";
3113 $sel_none_link = "javascript:cdmSelectArticles('none')";
3115 $tog_unread_link = "javascript:selectionToggleUnread(true)";
3116 $tog_marked_link = "javascript:selectionToggleMarked(true)";
3117 $tog_published_link = "javascript:selectionTogglePublished(true)";
3121 if (strpos($_SESSION["client.userAgent"], "MSIE") === false) {
3123 print "<td class=\"headlineActions$rtl_cpart\">
3124 <ul class=\"headlineDropdownMenu\">
3127 <a href=\"$sel_all_link\">".__('All')."</a>,
3128 <a href=\"$sel_unread_link\">".__('Unread')."</a>,
3129 <a href=\"$sel_none_link\">".__('None')."</a></li>
3130 <li class=\"vsep\"> </li>
3131 <li class=\"top\">".__('Toggle')."<ul>
3132 <li onclick=\"$tog_unread_link\">".__('Unread')."</li>
3133 <li onclick=\"$tog_marked_link\">".__('Starred')."</li>
3134 <li onclick=\"$tog_published_link\">".__('Published')."</li>
3136 <li class=\"vsep\"> </li>
3137 <li class=\"top\"><a href=\"$catchup_page_link\">".__('Mark as read')."</a><ul>
3138 <li onclick=\"$catchup_page_link\">".__('This page')."</li>
3139 <li onclick=\"$catchup_feed_link\">".__('Entire feed')."</li></ul></li>
3142 $enable_pagination = get_pref($link, "_PREFS_ENABLE_PAGINATION");
3144 if ($limit != 0 && !$search && $enable_pagination) {
3146 <li class=\"vsep\"> </li>
3147 <li class=\"top\"><a href=\"$page_next_link\">".__('Next page')."</a><ul>
3148 <li onclick=\"$page_prev_link\">".__('Previous page')."</li>
3149 <li onclick=\"$page_first_link\">".__('First page')."</li></ul></li>
3153 if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS
) {
3155 <li class=\"vsep\"> </li>
3157 <a href=\"javascript:labelFromSearch('$search', '$search_mode',
3158 '$match_on', '$feed_id', '$is_cat');\">
3159 ".__('Convert to label')."</a></td>";
3165 // old style subtoolbar:
3167 print "<td class=\"headlineActions$rtl_cpart\">".
3169 <a href=\"$sel_all_link\">".__('All')."</a>,
3170 <a href=\"$sel_unread_link\">".__('Unread')."</a>,
3171 <a href=\"$sel_none_link\">".__('None')."</a>
3173 __('Toggle:')." <a href=\"$tog_unread_link\">".__('Unread')."</a>,
3174 <a href=\"$tog_marked_link\">".__('Starred')."</a>
3176 __('Mark as read:')."
3177 <a href=\"#\" onclick=\"$catchup_page_link\">".__('Page')."</a>,
3178 <a href=\"#\" onclick=\"$catchup_feed_link\">".__('Feed')."</a>";
3180 if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS
) {
3183 <a href=\"javascript:labelFromSearch('$search', '$search_mode',
3184 '$match_on', '$feed_id', '$is_cat');\">
3185 ".__('Convert to label')."</a>";
3192 /* if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
3193 print "<td class=\"headlineActions$rtl_cpart\">
3194 <a href=\"javascript:labelFromSearch('$search', '$search_mode',
3195 '$match_on', '$feed_id', '$is_cat');\">
3196 ".__('Convert to Label')."</a></td>";
3199 print "<td class=\"headlineTitle$rtl_cpart\">";
3201 if ($feed_site_url) {
3203 $target = "target=\"_new\"";
3205 print "<a $target href=\"$feed_site_url\">$feed_title</a>";
3211 $search_q = "&q=$search&m=$match_on&smode=$search_mode";
3214 if ($user_page_offset > 1) {
3215 print " [$user_page_offset] ";
3221 href=\"backend.php?op=rss&id=$feed_id&is_cat=$is_cat$search_q\">
3222 <img class=\"noborder\"
3223 alt=\"".__('Generated feed')."\" src=\"images/feed-icon-12x12.png\">
3228 print "</tr></table>";
3232 function outputFeedList($link, $tags = false) {
3234 print "<ul class=\"feedList\" id=\"feedList\">";
3236 $owner_uid = $_SESSION["uid"];
3240 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3241 print "<li class=\"feedCat\">".__('Special')."</li>";
3242 print "<li id=\"feedCatHolder\" class=\"feedCatHolder\"><ul class=\"feedCatList\">";
3245 $num_starred = getFeedUnread($link, -1);
3246 $num_published = getFeedUnread($link, -2);
3250 if ($num_starred > 0) $class .= "Unread";
3252 printFeedEntry(-1, $class, __("Starred articles"), $num_starred,
3253 "images/mark_set.png", $link);
3257 if ($num_published > 0) $class .= "Unread";
3259 printFeedEntry(-2, $class, __("Published articles"), $num_published,
3260 "images/pub_set.png", $link);
3262 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3268 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
3270 $result = db_query($link, "SELECT id,sql_exp,description FROM
3271 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
3273 if (db_num_rows($result) > 0) {
3274 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3275 print "<li class=\"feedCat\">".__('Labels')."</li>";
3276 print "<li id=\"feedCatHolder\" class=\"feedCatHolder\"><ul class=\"feedCatList\">";
3278 print "<li><hr></li>";
3282 while ($line = db_fetch_assoc($result)) {
3284 error_reporting (0);
3286 $label_id = -$line['id'] - 11;
3287 $count = getFeedUnread($link, $label_id);
3295 error_reporting (DEFAULT_ERROR_LEVEL
);
3297 printFeedEntry($label_id,
3298 $class, $line["description"],
3299 $count, "images/label.png", $link);
3303 if (db_num_rows($result) > 0) {
3304 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3311 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
3312 print "<li><hr></li>";
3315 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3316 if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
3317 $order_by_qpart = "category,unread DESC,title";
3319 $order_by_qpart = "category,title";
3322 if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
3323 $order_by_qpart = "unread DESC,title";
3325 $order_by_qpart = "title";
3329 $result = db_query($link, "SELECT ttrss_feeds.*,
3330 SUBSTRING(last_updated,1,19) AS last_updated_noms,
3331 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
3332 WHERE feed_id = ttrss_feeds.id AND unread = true
3333 AND ttrss_user_entries.ref_id = ttrss_entries.id
3334 AND owner_uid = '$owner_uid') as unread,
3336 ttrss_feed_categories.title AS category,
3337 ttrss_feed_categories.collapsed
3338 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
3339 ON (ttrss_feed_categories.id = cat_id)
3341 ttrss_feeds.hidden = false AND
3342 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
3343 ORDER BY $order_by_qpart");
3345 $actid = $_GET["actid"];
3355 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3357 while ($line = db_fetch_assoc($result)) {
3359 $feed = trim($line["title"]);
3361 if (!$feed) $feed = "[Untitled]";
3363 $feed_id = $line["id"];
3365 $subop = $_GET["subop"];
3367 $unread = $line["unread"];
3369 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3370 $last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
3372 $last_updated = date($short_date, strtotime($line["last_updated_noms"]));
3375 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
3378 $rtl_tag = "dir=\"RTL\"";
3383 $tmp_result = db_query($link,
3384 "SELECT id,COUNT(unread) AS unread
3385 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
3386 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
3387 WHERE parent_feed = '$feed_id' AND unread = true
3388 GROUP BY ttrss_feeds.id");
3390 if (db_num_rows($tmp_result) > 0) {
3391 while ($l = db_fetch_assoc($tmp_result)) {
3392 $unread +
= $l["unread"];
3396 $cat_id = $line["cat_id"];
3398 $tmp_category = $line["category"];
3400 if (!$tmp_category) {
3401 $tmp_category = __("Uncategorized");
3404 // $class = ($lnum % 2) ? "even" : "odd";
3406 if ($line["last_error"]) {
3412 if ($unread > 0) $class .= "Unread";
3414 if ($actid == $feed_id) {
3415 $class .= "Selected";
3418 $total_unread +
= $unread;
3420 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
3426 $category = $tmp_category;
3428 $collapsed = $line["collapsed"];
3430 // workaround for NULL category
3431 if ($category == __("Uncategorized")) {
3432 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
3437 if ($collapsed == "t" ||
$collapsed == "1") {
3438 $holder_class = "feedCatHolder";
3439 $holder_style = "display:none;";
3442 $holder_class = "feedCatHolder";
3447 $cat_id = sprintf("%d", $cat_id);
3449 $cat_unread = getCategoryUnread($link, $cat_id);
3451 $catctr_class = ($cat_unread > 0) ?
"catCtrHasUnread" : "catCtrNoUnread";
3453 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
3454 <a id=\"FCATN-$cat_id\" href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
3455 <a href=\"#\" onclick=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
3456 <span id=\"FCATCTR-$cat_id\" title=\"Click to browse category\"
3457 class=\"$catctr_class\">($cat_unread)</span> $ellipsis
3460 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
3461 // -> keyboard navigation, etc.
3462 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\" style='$holder_style'>";
3465 printFeedEntry($feed_id, $class, $feed, $unread,
3466 ICONS_DIR
."/$feed_id.ico", $link, $rtl_content,
3467 $last_updated, $line["last_error"]);
3472 if (db_num_rows($result) == 0) {
3473 print "<li>".__('No feeds to display.')."</li>";
3480 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
3481 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
3482 post_int_id = ttrss_user_entries.int_id AND
3483 unread = true AND ref_id = ttrss_entries.id
3484 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
3486 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
3487 ORDER BY tag_name"); */
3489 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3490 print "<li class=\"feedCat\">".__('Tags')."</li>";
3491 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
3494 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
3495 FROM ttrss_user_entries WHERE int_id = post_int_id
3496 AND unread = true)) AS count FROM ttrss_tags
3497 WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name
3498 ORDER BY count DESC LIMIT 50");
3502 while ($line = db_fetch_assoc($result)) {
3503 $tags[$line["tag_name"]] +
= $line["count"];
3506 foreach (array_keys($tags) as $tag) {
3508 $unread = $tags[$tag];
3516 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
3520 if (db_num_rows($result) == 0) {
3521 print "<li>No tags to display.</li>";
3524 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3534 function get_article_tags($link, $id, $owner_uid = 0) {
3536 $a_id = db_escape_string($id);
3538 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
3540 $tmp_result = db_query($link, "SELECT DISTINCT tag_name,
3541 owner_uid as owner FROM
3542 ttrss_tags WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE
3543 ref_id = '$a_id' AND owner_uid = '$owner_uid' LIMIT 1) ORDER BY tag_name");
3547 while ($tmp_line = db_fetch_assoc($tmp_result)) {
3548 array_push($tags, $tmp_line["tag_name"]);
3554 function trim_value(&$value) {
3555 $value = trim($value);
3558 function trim_array($array) {
3560 array_walk($tmp, 'trim_value');
3564 function tag_is_valid($tag) {
3565 if ($tag == '') return false;
3566 if (preg_match("/^[0-9]*$/", $tag)) return false;
3568 $tag = iconv("utf-8", "utf-8", $tag);
3569 if (!$tag) return false;
3574 function render_login_form($link, $mobile = false) {
3576 require_once "login_form.php";
3578 require_once "mobile/login_form.php";
3582 // from http://developer.apple.com/internet/safari/faq.html
3583 function no_cache_incantation() {
3584 header("Expires: Mon, 22 Dec 1980 00:00:00 GMT"); // Happy birthday to me :)
3585 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
3586 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1
3587 header("Cache-Control: post-check=0, pre-check=0", false);
3588 header("Pragma: no-cache"); // HTTP/1.0
3591 function format_warning($msg, $id = "") {
3592 return "<div class=\"warning\" id=\"$id\">
3593 <img src=\"images/sign_excl.png\">$msg</div>";
3596 function format_notice($msg) {
3597 return "<div class=\"notice\">
3598 <img src=\"images/sign_info.png\">$msg</div>";
3601 function format_error($msg) {
3602 return "<div class=\"error\">
3603 <img src=\"images/sign_excl.png\">$msg</div>";
3606 function print_notice($msg) {
3607 return print format_notice($msg);
3610 function print_warning($msg) {
3611 return print format_warning($msg);
3614 function print_error($msg) {
3615 return print format_error($msg);
3619 function T_sprintf() {
3620 $args = func_get_args();
3621 return vsprintf(__(array_shift($args)), $args);
3624 function outputArticleXML($link, $id, $feed_id, $mark_as_read = true) {
3626 /* we can figure out feed_id from article id anyway, why do we
3627 * pass feed_id here? */
3629 $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries
3630 WHERE ref_id = '$id'");
3632 $feed_id = db_fetch_result($result, 0, "feed_id");
3634 print "<article id='$id'><![CDATA[";
3636 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
3637 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
3639 if (db_num_rows($result) == 1) {
3640 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
3642 $rtl_content = false;
3646 $rtl_tag = "dir=\"RTL\"";
3653 if ($mark_as_read) {
3654 $result = db_query($link, "UPDATE ttrss_user_entries
3655 SET unread = false,last_read = NOW()
3656 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
3659 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
3660 SUBSTRING(updated,1,16) as updated,
3661 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
3664 FROM ttrss_entries,ttrss_user_entries
3665 WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
3671 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
3672 $link_target = "target=\"_new\"";
3675 $line = db_fetch_assoc($result);
3677 if ($line["icon_url"]) {
3678 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
3680 $feed_icon = " ";
3683 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
3684 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
3686 $entry_comments = "";
3689 $num_comments = $line["num_comments"];
3690 $entry_comments = "";
3692 if ($num_comments > 0) {
3693 if ($line["comments"]) {
3694 $comments_url = $line["comments"];
3696 $comments_url = $line["link"];
3698 $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>";
3700 if ($line["comments"] && $line["link"] != $line["comments"]) {
3701 $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>";
3705 print "<div class=\"postReply\">";
3707 print "<div class=\"postHeader\">";
3709 $entry_author = $line["author"];
3711 if ($entry_author) {
3712 $entry_author = __(" - by ") . $entry_author;
3715 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3716 strtotime($line["updated"]));
3718 print "<div class=\"postDate$rtl_class\">$parsed_updated</div>";
3720 if ($line["link"]) {
3721 print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" .
3722 $line["title"] . "</a>$entry_author</div>";
3724 print "<div clear='both'>" . $line["title"] . "$entry_author</div>";
3727 /* $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
3728 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
3729 ORDER BY tag_name"); */
3731 $tags = get_article_tags($link, $id);
3738 foreach ($tags as $tag) {
3740 $tag_escaped = str_replace("'", "\\'", $tag);
3742 $tag_str = "<a href=\"javascript:viewfeed('$tag_escaped')\">$tag</a>, ";
3744 if ($num_tags == 6) {
3747 } else if ($num_tags < 6) {
3748 $tags_str .= $tag_str;
3750 $f_tags_str .= $tag_str;
3753 $tags_str = preg_replace("/, $/", "", $tags_str);
3754 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
3756 $all_tags_div = "<span class='cdmAllTagsCtr'>...<div class='cdmAllTags'>All Tags: $f_tags_str</div></span>";
3757 $tags_str = preg_replace("/\.\.\.$/", "$all_tags_div", $tags_str);
3759 if (!$entry_comments) $entry_comments = " "; # placeholder
3761 if (!$tags_str) $tags_str = '<span class="tagList">'.__('no tags').'</span>';
3763 print "<div style='float : right'>$tags_str
3764 <a title=\"Edit tags for this article\"
3765 href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a></div>
3766 <div clear='both'>$entry_comments</div>";
3770 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
3771 print "<div class=\"postContent\">";
3773 #print "<div id=\"allEntryTags\">".__('Tags:')." $f_tags_str</div>";
3775 $line["content"] = sanitize_rss($link, $line["content"]);
3777 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
3778 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
3781 print $line["content"] . "</div>";
3787 print "]]></article>";
3791 function outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view,
3792 $next_unread_feed, $offset) {
3794 $timing_info = getmicrotime();
3796 $topmost_article_ids = array();
3802 if ($subop == "undefined") $subop = "";
3804 if ($subop == "CatchupSelected") {
3805 $ids = split(",", db_escape_string($_GET["ids"]));
3806 $cmode = sprintf("%d", $_GET["cmode"]);
3808 catchupArticlesById($link, $ids, $cmode);
3811 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
3812 update_generic_feed($link, $feed, $cat_view);
3815 if ($subop == "MarkAllRead") {
3816 catchup_feed($link, $feed, $cat_view);
3818 if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
3819 if ($next_unread_feed) {
3820 $feed = $next_unread_feed;
3826 $result = db_query($link,
3827 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
3829 if (db_num_rows($result) == 0) {
3830 print "<div align='center'>".__('Feed not found.')."</div>";
3835 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
3837 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
3838 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
3840 if (db_num_rows($result) == 1) {
3841 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
3843 $rtl_content = false;
3847 $rtl_tag = "dir=\"RTL\"";
3853 $rtl_content = false;
3856 $script_dt_add = get_script_dt_add();
3858 /// START /////////////////////////////////////////////////////////////////////////////////
3860 $search = db_escape_string($_GET["query"]);
3861 $search_mode = db_escape_string($_GET["search_mode"]);
3862 $match_on = db_escape_string($_GET["match_on"]);
3868 $real_offset = $offset * $limit;
3870 if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
3872 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
3873 $search, $search_mode, $match_on, false, $real_offset);
3875 if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
3877 $result = $qfh_ret[0];
3878 $feed_title = $qfh_ret[1];
3879 $feed_site_url = $qfh_ret[2];
3880 $last_error = $qfh_ret[3];
3883 $feed_site_url = article_publish_url($link);
3886 /// STOP //////////////////////////////////////////////////////////////////////////////////
3889 print "<div id=\"headlinesContainer\" $rtl_tag>";
3892 print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
3896 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
3897 $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode,
3900 print "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">";
3903 if (db_num_rows($result) > 0) {
3905 # print "\{$offset}";
3907 if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) {
3908 print "<table class=\"headlinesList\" id=\"headlinesList\"
3909 cellspacing=\"0\">";
3914 error_reporting (DEFAULT_ERROR_LEVEL
);
3918 while ($line = db_fetch_assoc($result)) {
3920 $class = ($lnum %
2) ?
"even" : "odd";
3923 $feed_id = $line["feed_id"];
3925 if (count($topmost_article_ids) < 5) {
3926 array_push($topmost_article_ids, $id);
3929 if ($line["last_read"] == "" &&
3930 ($line["unread"] != "t" && $line["unread"] != "1")) {
3932 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
3935 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
3939 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
3947 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
3948 $marked_pic = "<img id=\"FMPIC-$id\" src=\"images/mark_set.png\"
3950 alt=\"Reset mark\" onclick='javascript:tMark($id)'>";
3952 $marked_pic = "<img id=\"FMPIC-$id\" src=\"images/mark_unset.png\"
3954 alt=\"Set mark\" onclick='javascript:tMark($id)'>";
3957 if ($line["published"] == "t" ||
$line["published"] == "1") {
3958 $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_set.png\"
3960 alt=\"Unpublish\" onclick='javascript:tPub($id)'>";
3962 $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_unset.png\"
3964 alt=\"Publish\" onclick='javascript:tPub($id)'>";
3967 # $content_link = "<a target=\"_new\" href=\"".$line["link"]."\">" .
3968 # $line["title"] . "</a>";
3970 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
3971 $line["title"] . "</a>";
3973 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
3974 # $line["title"] . "</a>";
3976 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3977 $updated_fmt = smart_date_time(strtotime($line["updated_noms"]));
3979 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3980 $updated_fmt = date($short_date, strtotime($line["updated_noms"]));
3983 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
3984 $content_preview = truncate_string(strip_tags($line["content_preview"]),
3988 $entry_author = $line["author"];
3990 if ($entry_author) {
3991 $entry_author = " - by $entry_author";
3994 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
3996 print "<tr class='$class' id='RROW-$id'>";
3998 print "<td class='hlUpdPic'>$update_pic</td>";
4000 print "<td class='hlSelectRow'>
4001 <input type=\"checkbox\" onclick=\"tSR(this)\"
4005 print "<td class='hlMarkedPic'>$marked_pic</td>";
4006 print "<td class='hlMarkedPic'>$published_pic</td>";
4008 if ($line["feed_title"]) {
4009 print "<td class='hlContent'>$content_link</td>";
4010 print "<td class='hlFeed'>
4011 <a href=\"javascript:viewfeed($feed_id, '', false)\">".
4012 $line["feed_title"]."</a> </td>";
4014 print "<td class='hlContent' valign='middle'>";
4016 print "<a href=\"javascript:view($id,$feed_id);\">" .
4019 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
4020 if ($content_preview) {
4021 print "<span class=\"contentPreview\"> - $content_preview</span>";
4029 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
4036 $add_class = "Unread";
4041 print "<div class=\"cdmArticle$add_class\"
4042 id=\"RROW-$id\" onmouseover='cdmMouseIn(this)'
4043 onmouseout='cdmMouseOut(this)'>";
4045 print "<div class=\"cdmHeader\">";
4047 print "<div class=\"articleUpdated\">$updated_fmt</div>";
4049 print "<a class=\"title\"
4050 onclick=\"javascript:toggleUnread($id, 0)\"
4051 target=\"_new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
4053 print $entry_author;
4055 if ($line["feed_title"]) {
4056 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
4061 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
4062 $line["content_preview"] = preg_replace("/href=/i",
4063 "target=\"_new\" href=", $line["content_preview"]);
4066 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">";
4068 print "<div class=\"cdmFooter\"><span class='s0'>";
4070 /* print "<div class=\"markedPic\">Star it: $marked_pic</div>"; */
4072 print __("Select:").
4073 " <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
4074 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">";
4076 print "</span><span class='s1'>$marked_pic</span> ";
4077 print "<span class='s1'>$published_pic</span> ";
4079 $tags = get_article_tags($link, $id);
4082 $full_tags_str = "";
4085 foreach ($tags as $tag) {
4087 $full_tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
4088 if ($num_tags < 5) {
4089 $tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
4090 } else if ($num_tags == 5) {
4095 $tags_str = preg_replace("/, $/", "", $tags_str);
4096 $full_tags_str = preg_replace("/, $/", "", $full_tags_str);
4098 $all_tags_div = "<span class='cdmAllTagsCtr'>...<div class='cdmAllTags'>All Tags: $full_tags_str</div></span>";
4100 $tags_str = preg_replace("/\.\.\.$/", "$all_tags_div", $tags_str);
4103 if ($tags_str == "") $tags_str = "no tags";
4105 // print "<img src='images/tag.png' class='markedPic'>";
4107 print "<span class='s1'>Tags: $tags_str <a title=\"Edit tags for this article\"
4108 href=\"javascript:editArticleTags($id, $feed_id, true)\">(+)</a>";
4112 print "<span class='s2'>Toggle: <a class=\"cdmToggleLink\"
4113 href=\"javascript:toggleUnread($id)\">
4124 if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) {
4128 // print_headline_subtoolbar($link,
4129 // "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
4133 if (!$offset) print "<div class='whiteBox'>".__('No articles found.')."</div>";
4141 return $topmost_article_ids;
4144 // from here: http://www.roscripts.com/Create_tag_cloud-71.html
4146 function printTagCloud($link) {
4148 /* get first ref_id to count from */
4154 if (DB_TYPE == "pgsql") {
4155 $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries
4156 WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]."
4157 AND date_entered > NOW() - INTERVAL '30 days'";
4159 $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries
4160 WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]."
4161 AND date_entered > DATE_SUB(NOW(), INTERVAL 30 DAY)";
4164 $result = db_query($link, $query);
4165 $first_id = db_fetch_result($result, 0, "id"); */
4167 //AND post_int_id >= '$first_id'
4168 $query = "SELECT tag_name, COUNT(post_int_id) AS count
4169 FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]."
4170 GROUP BY tag_name ORDER BY count DESC LIMIT 50";
4172 $result = db_query($link, $query);
4176 while ($line = db_fetch_assoc($result)) {
4177 $tags[$line["tag_name"]] = $line["count"];
4182 $max_size = 32; // max font size in pixels
4183 $min_size = 11; // min font size in pixels
4185 // largest and smallest array values
4186 $max_qty = max(array_values($tags));
4187 $min_qty = min(array_values($tags));
4189 // find the range of values
4190 $spread = $max_qty - $min_qty;
4191 if ($spread == 0) { // we don't want to divide by zero
4195 // set the font-size increment
4196 $step = ($max_size - $min_size) / ($spread);
4198 // loop through the tag array
4199 foreach ($tags as $key => $value) {
4200 // calculate font-size
4201 // find the $value in excess of $min_qty
4202 // multiply by the font-size increment ($size)
4203 // and add the $min_size set above
4204 $size = round($min_size +
(($value - $min_qty) * $step));
4206 $key_escaped = str_replace("'", "\\'", $key);
4208 echo "<a href=\"javascript:viewfeed('$key_escaped') \" style=\"font-size: " .
4209 $size . "px\" title=\"$value articles tagged with " .
4210 $key . '">' . $key . '</a> ';
4214 function print_checkpoint($n, $s) {
4215 $ts = getmicrotime();
4216 echo sprintf("<!-- CP[$n] %.4f seconds -->", $ts - $s);
4220 function sanitize_tag($tag) {
4223 $tag = mb_strtolower($tag, 'utf-8');
4225 $tag = preg_replace('/[\"\+\>\<]/', "", $tag);
4227 // $tag = str_replace('"', "", $tag);
4228 // $tag = str_replace("+", " ", $tag);
4229 $tag = str_replace("technorati tag: ", "", $tag);
4234 function generate_publish_key() {
4235 return sha1(uniqid(rand(), true));
4238 function article_publish_url($link) {
4240 $url_path = 'http://' . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH
);
4242 $url_path .= "?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY");