4 define('DEFAULT_ERROR_LEVEL', E_ALL
);
6 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE
);
9 require_once 'config.php';
10 require_once 'db-prefs.php';
11 require_once 'compat.php';
13 require_once 'magpierss/rss_utils.inc';
15 define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
17 function purge_feed($link, $feed_id, $purge_interval) {
19 if (DB_TYPE
== "pgsql") {
20 db_query($link, "DELETE FROM ttrss_user_entries WHERE
21 marked = false AND feed_id = '$feed_id' AND
22 (SELECT date_entered FROM ttrss_entries WHERE
23 id = ref_id) < NOW() - INTERVAL '$purge_interval days'");
25 db_query($link, "DELETE FROM ttrss_user_entries WHERE
26 marked = false AND feed_id = '$feed_id' AND
27 (SELECT date_entered FROM ttrss_entries WHERE
28 id = ref_id) < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)");
32 function global_purge_old_posts($link, $do_output = false) {
34 $result = db_query($link,
35 "SELECT id,purge_interval,owner_uid FROM ttrss_feeds");
37 while ($line = db_fetch_assoc($result)) {
39 $feed_id = $line["id"];
40 $purge_interval = $line["purge_interval"];
41 $owner_uid = $line["owner_uid"];
43 if ($purge_interval == 0) {
45 $tmp_result = db_query($link,
46 "SELECT value FROM ttrss_user_prefs WHERE
47 pref_name = 'PURGE_OLD_DAYS' AND owner_uid = '$owner_uid'");
49 if (db_num_rows($tmp_result) != 0) {
50 $purge_interval = db_fetch_result($tmp_result, 0, "value");
55 print "<feed id='$feed_id' p_intl='$purge_interval'/>";
58 if ($purge_interval > 0) {
59 purge_feed($link, $feed_id, $purge_interval);
63 // purge orphaned posts in main content table
64 db_query($link, "DELETE FROM ttrss_entries WHERE
65 (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
69 function purge_old_posts($link) {
71 $user_id = $_SESSION["uid"];
73 $result = db_query($link, "SELECT id,purge_interval FROM ttrss_feeds
74 WHERE owner_uid = '$user_id'");
76 while ($line = db_fetch_assoc($result)) {
78 $feed_id = $line["id"];
79 $purge_interval = $line["purge_interval"];
81 if ($purge_interval == 0) $purge_interval = get_pref($link, 'PURGE_OLD_DAYS');
83 if ($purge_interval > 0) {
84 purge_feed($link, $feed_id, $purge_interval);
88 // purge orphaned posts in main content table
89 db_query($link, "DELETE FROM ttrss_entries WHERE
90 (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
93 function update_all_feeds($link, $fetch, $user_id = false, $force_daemon = false) {
95 if (WEB_DEMO_MODE
) return;
98 $user_id = $_SESSION["uid"];
99 purge_old_posts($link);
102 // db_query($link, "BEGIN");
104 if (MAX_UPDATE_TIME
> 0) {
105 if (DB_TYPE
== "mysql") {
108 $q_order = "RANDOM()";
111 $q_order = "last_updated DESC";
114 $result = db_query($link, "SELECT feed_url,id,
115 SUBSTRING(last_updated,1,19) AS last_updated,
116 update_interval FROM ttrss_feeds WHERE owner_uid = '$user_id'
121 while ($line = db_fetch_assoc($result)) {
122 $upd_intl = $line["update_interval"];
124 if (!$upd_intl ||
$upd_intl == 0) {
125 $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id);
129 // Updates for this feed are disabled
133 if ($fetch ||
(!$line["last_updated"] ||
134 time() - strtotime($line["last_updated"]) > ($upd_intl * 60))) {
136 // print "<!-- feed: ".$line["feed_url"]." -->";
138 update_rss_feed($link, $line["feed_url"], $line["id"], $force_daemon);
140 $upd_elapsed = time() - $upd_start;
142 if (MAX_UPDATE_TIME
> 0 && $upd_elapsed > MAX_UPDATE_TIME
) {
148 // db_query($link, "COMMIT");
152 function check_feed_favicon($feed_url, $feed, $link) {
153 $feed_url = str_replace("http://", "", $feed_url);
154 $feed_url = preg_replace("/\/.*$/", "", $feed_url);
156 $icon_url = "http://$feed_url/favicon.ico";
157 $icon_file = ICONS_DIR
. "/$feed.ico";
159 if (!file_exists($icon_file)) {
162 $r = fopen($icon_url, "r");
163 error_reporting (DEFAULT_ERROR_LEVEL
);
166 $tmpfname = tempnam(TMP_DIRECTORY
, "ttrssicon");
168 $t = fopen($tmpfname, "w");
171 $buf = fread($r, 16384);
179 if (!rename($tmpfname, $icon_file)) {
183 chmod($icon_file, 0644);
185 error_reporting (DEFAULT_ERROR_LEVEL
);
191 function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) {
193 if (WEB_DEMO_MODE
) return;
195 if (DAEMON_REFRESH_ONLY
&& !$_GET["daemon"] && !$ignore_daemon) {
199 $result = db_query($link, "SELECT update_interval,auth_login,auth_pass
200 FROM ttrss_feeds WHERE id = '$feed'");
202 $auth_login = db_fetch_result($result, 0, "auth_login");
203 $auth_pass = db_fetch_result($result, 0, "auth_pass");
205 $update_interval = db_fetch_result($result, 0, "update_interval");
207 if ($update_interval < 0) { return; }
209 $feed = db_escape_string($feed);
211 $fetch_url = $feed_url;
213 if ($auth_login && $auth_pass) {
214 $url_parts = array();
215 preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts);
217 if ($url_parts[1] && $url_parts[2]) {
218 $fetch_url = $url_parts[1] . "://$auth_login:$auth_pass@" . $url_parts[2];
223 $rss = fetch_rss($fetch_url);
225 error_reporting (DEFAULT_ERROR_LEVEL
);
227 $feed = db_escape_string($feed);
231 db_query($link, "BEGIN");
233 $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid
234 FROM ttrss_feeds WHERE id = '$feed'");
236 $registered_title = db_fetch_result($result, 0, "title");
237 $orig_icon_url = db_fetch_result($result, 0, "icon_url");
238 $orig_site_url = db_fetch_result($result, 0, "site_url");
240 $owner_uid = db_fetch_result($result, 0, "owner_uid");
242 if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid)) {
243 check_feed_favicon($feed_url, $feed, $link);
246 if (!$registered_title ||
$registered_title == "[Unknown]") {
247 $feed_title = db_escape_string($rss->channel
["title"]);
248 db_query($link, "UPDATE ttrss_feeds SET
249 title = '$feed_title' WHERE id = '$feed'");
252 $site_url = $rss->channel
["link"];
253 // weird, weird Magpie
254 if (!$site_url) $site_url = db_escape_string($rss->channel
["link_"]);
256 if ($site_url && $orig_site_url != db_escape_string($site_url)) {
257 db_query($link, "UPDATE ttrss_feeds SET
258 site_url = '$site_url' WHERE id = '$feed'");
261 // print "I: " . $rss->channel["image"]["url"];
263 $icon_url = $rss->image
["url"];
265 if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) {
266 $icon_url = db_escape_string($icon_url);
267 db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'");
273 $result = db_query($link, "SELECT reg_exp,
274 ttrss_filter_types.name AS name,
275 ttrss_filter_actions.name AS action
276 FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE
277 owner_uid = $owner_uid AND
278 ttrss_filter_types.id = filter_type AND
279 ttrss_filter_actions.id = action_id AND
280 (feed_id IS NULL OR feed_id = '$feed')");
282 while ($line = db_fetch_assoc($result)) {
283 if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
285 $filter["reg_exp"] = $line["reg_exp"];
286 $filter["action"] = $line["action"];
288 array_push($filters[$line["name"]], $filter);
291 $iterator = $rss->items
;
293 if (!$iterator) $iterator = $rss->entries
;
294 if (!$iterator) $iterator = $rss;
296 foreach ($iterator as $item) {
298 $entry_guid = $item["id"];
300 if (!$entry_guid) $entry_guid = $item["guid"];
301 if (!$entry_guid) $entry_guid = $item["link"];
303 if (!$entry_guid) continue;
305 $entry_timestamp = "";
307 $rss_2_date = $item['pubdate'];
308 $rss_1_date = $item['dc']['date'];
309 $atom_date = $item['issued'];
310 if (!$atom_date) $atom_date = $item['updated'];
312 if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date);
313 if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date);
314 if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date);
316 if ($entry_timestamp == "") {
317 $entry_timestamp = time();
318 $no_orig_date = 'true';
320 $no_orig_date = 'false';
323 $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
325 $entry_title = $item["title"];
327 // strange Magpie workaround
328 $entry_link = $item["link_"];
329 if (!$entry_link) $entry_link = $item["link"];
331 if (!$entry_title) continue;
332 if (!$entry_link) continue;
334 $entry_content = $item["content:escaped"];
336 if (!$entry_content) $entry_content = $item["content:encoded"];
337 if (!$entry_content) $entry_content = $item["content"];
338 if (!$entry_content) $entry_content = $item["summary"];
339 if (!$entry_content) $entry_content = $item["description"];
341 // if (!$entry_content) continue;
344 if (is_array($entry_content)) {
345 $entry_content = $entry_content["encoded"];
346 if (!$entry_content) $entry_content = $entry_content["escaped"];
350 // print_r(htmlspecialchars($entry_content));
353 $entry_content_unescaped = $entry_content;
354 $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
356 $entry_comments = $item["comments"];
358 $entry_guid = db_escape_string($entry_guid);
360 $result = db_query($link, "SELECT id FROM ttrss_entries
361 WHERE guid = '$entry_guid'");
363 $entry_content = db_escape_string($entry_content);
364 $entry_title = db_escape_string($entry_title);
365 $entry_link = db_escape_string($entry_link);
366 $entry_comments = db_escape_string($entry_comments);
368 $num_comments = db_escape_string($item["slash"]["comments"]);
370 if (!$num_comments) $num_comments = 0;
372 if (db_num_rows($result) == 0) {
374 // base post entry does not exist, create it
376 $result = db_query($link,
377 "INSERT INTO ttrss_entries
392 '$entry_timestamp_fmt',
400 // we keep encountering the entry in feeds, so we need to
401 // update date_entered column so that we don't get horrible
402 // dupes when the entry gets purged and reinserted again e.g.
403 // in the case of SLOW SLOW OMG SLOW updating feeds
405 $base_entry_id = db_fetch_result($result, 0, "id");
407 db_query($link, "UPDATE ttrss_entries SET date_entered = NOW()
408 WHERE id = '$base_entry_id'");
411 // now it should exist, if not - bad luck then
413 $result = db_query($link, "SELECT
414 id,content_hash,no_orig_date,title,
415 substring(date_entered,1,19) as date_entered,
416 substring(updated,1,19) as updated,
420 WHERE guid = '$entry_guid'");
422 if (db_num_rows($result) == 1) {
424 // this will be used below in update handler
425 $orig_content_hash = db_fetch_result($result, 0, "content_hash");
426 $orig_title = db_fetch_result($result, 0, "title");
427 $orig_num_comments = db_fetch_result($result, 0, "num_comments");
428 $orig_date_entered = strtotime(db_fetch_result($result,
431 $ref_id = db_fetch_result($result, 0, "id");
433 // check for user post link to main table
435 // do we allow duplicate posts with same GUID in different feeds?
436 if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid)) {
437 $dupcheck_qpart = "AND feed_id = '$feed'";
439 $dupcheck_qpart = "";
442 // error_reporting(0);
444 $filter_name = get_filter_name($entry_title, $entry_content,
445 $entry_link, $filters);
447 if ($filter_name == "filter") {
451 // error_reporting (DEFAULT_ERROR_LEVEL);
453 $result = db_query($link,
454 "SELECT ref_id FROM ttrss_user_entries WHERE
455 ref_id = '$ref_id' AND owner_uid = '$owner_uid'
458 // okay it doesn't exist - create user entry
459 if (db_num_rows($result) == 0) {
461 if ($filter_name != 'catchup') {
463 $last_read_qpart = 'NULL';
466 $last_read_qpart = 'NOW()';
469 $result = db_query($link,
470 "INSERT INTO ttrss_user_entries
471 (ref_id, owner_uid, feed_id, unread, last_read)
472 VALUES ('$ref_id', '$owner_uid', '$feed', $unread,
476 $post_needs_update = false;
478 if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid) &&
479 ($content_hash != $orig_content_hash)) {
480 $post_needs_update = true;
483 if ($orig_title != $entry_title) {
484 $post_needs_update = true;
487 if ($orig_num_comments != $num_comments) {
488 $post_needs_update = true;
491 // this doesn't seem to be very reliable
493 // if ($orig_timestamp != $entry_timestamp && !$orig_no_orig_date) {
494 // $post_needs_update = true;
497 // if post needs update, update it and mark all user entries
498 // linking to this post as updated
499 if ($post_needs_update) {
501 // print "<!-- post $orig_title needs update : $post_needs_update -->";
503 db_query($link, "UPDATE ttrss_entries
504 SET title = '$entry_title', content = '$entry_content',
505 num_comments = '$num_comments'
506 WHERE id = '$ref_id'");
508 db_query($link, "UPDATE ttrss_user_entries
509 SET last_read = null WHERE ref_id = '$ref_id' AND unread = false");
515 // <a href="http://technorati.com/tag/Xorg" rel="tag">Xorg</a>, //
519 preg_match_all("/<a.*?href=.http:\/\/.*?technorati.com\/tag\/([^\"\'>]+)/i",
520 $entry_content_unescaped, $entry_tags);
522 // print "<br>$entry_title : $entry_content_unescaped<br>";
523 // print_r($entry_tags);
526 $entry_tags = $entry_tags[1];
528 if (count($entry_tags) > 0) {
530 $result = db_query($link, "SELECT id,int_id
531 FROM ttrss_entries,ttrss_user_entries
532 WHERE guid = '$entry_guid'
533 AND feed_id = '$feed' AND ref_id = id
534 AND owner_uid = '$owner_uid'");
536 if (db_num_rows($result) == 1) {
538 $entry_id = db_fetch_result($result, 0, "id");
539 $entry_int_id = db_fetch_result($result, 0, "int_id");
541 foreach ($entry_tags as $tag) {
542 $tag = db_escape_string(strtolower($tag));
544 $tag = str_replace("+", " ", $tag);
545 $tag = str_replace("technorati tag: ", "", $tag);
547 $result = db_query($link, "SELECT id FROM ttrss_tags
548 WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND
549 owner_uid = '$owner_uid' LIMIT 1");
551 // print db_fetch_result($result, 0, "id");
553 if ($result && db_num_rows($result) == 0) {
555 // print "tagging $entry_id as $tag<br>";
557 db_query($link, "INSERT INTO ttrss_tags
558 (owner_uid,tag_name,post_int_id)
559 VALUES ('$owner_uid','$tag', '$entry_int_id')");
566 db_query($link, "UPDATE ttrss_feeds
567 SET last_updated = NOW(), last_error = '' WHERE id = '$feed'");
569 db_query($link, "COMMIT");
572 $error_msg = db_escape_string(magpie_error());
574 "UPDATE ttrss_feeds SET last_error = '$error_msg',
575 last_updated = NOW() WHERE id = '$feed'");
580 function print_select($id, $default, $values, $attributes = "") {
581 print "<select id=\"$id\" $attributes>";
582 foreach ($values as $v) {
588 print "<option$sel>$v</option>";
593 function get_filter_name($title, $content, $link, $filters) {
595 if ($filters["title"]) {
596 foreach ($filters["title"] as $filter) {
597 $reg_exp = $filter["reg_exp"];
598 if (preg_match("/$reg_exp/i", $title)) {
599 return $filter["action"];
604 if ($filters["content"]) {
605 foreach ($filters["content"] as $filter) {
606 $reg_exp = $filter["reg_exp"];
607 if (preg_match("/$reg_exp/i", $content)) {
608 return $filter["action"];
613 if ($filters["both"]) {
614 foreach ($filters["both"] as $filter) {
615 $reg_exp = $filter["reg_exp"];
616 if (preg_match("/$reg_exp/i", $title) ||
617 preg_match("/$reg_exp/i", $content)) {
618 return $filter["action"];
623 if ($filters["link"]) {
624 $reg_exp = $filter["reg_exp"];
625 foreach ($filters["link"] as $filter) {
626 $reg_exp = $filter["reg_exp"];
627 if (preg_match("/$reg_exp/i", $link)) {
628 return $filter["action"];
636 function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link) {
638 if (file_exists($icon_file) && filesize($icon_file) > 0) {
639 $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"$icon_file\">";
641 $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"images/blank_icon.gif\">";
644 $feed = "<a href=\"javascript:viewfeed('$feed_id', 0);\">$feed_title</a>";
646 print "<li id=\"FEEDR-$feed_id\" class=\"$class\">";
647 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
651 print "<span id=\"FEEDN-$feed_id\">$feed</span>";
656 $fctr_class = "class=\"invisible\"";
659 print "<span $fctr_class id=\"FEEDCTR-$feed_id\">
660 (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>";
666 function getmicrotime() {
667 list($usec, $sec) = explode(" ",microtime());
668 return ((float)$usec +
(float)$sec);
671 function print_radio($id, $default, $values, $attributes = "") {
672 foreach ($values as $v) {
680 $sel .= " value=\"1\"";
682 $sel .= " value=\"0\"";
685 print "<input type=\"radio\" $sel $attributes name=\"$id\"> $v ";
690 function initialize_user_prefs($link, $uid) {
692 $uid = db_escape_string($uid);
694 db_query($link, "BEGIN");
696 $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs");
698 $u_result = db_query($link, "SELECT pref_name
699 FROM ttrss_user_prefs WHERE owner_uid = '$uid'");
701 $active_prefs = array();
703 while ($line = db_fetch_assoc($u_result)) {
704 array_push($active_prefs, $line["pref_name"]);
707 while ($line = db_fetch_assoc($result)) {
708 if (array_search($line["pref_name"], $active_prefs) === FALSE) {
709 // print "adding " . $line["pref_name"] . "<br>";
711 db_query($link, "INSERT INTO ttrss_user_prefs
712 (owner_uid,pref_name,value) VALUES
713 ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')");
718 db_query($link, "COMMIT");
722 function authenticate_user($link, $login, $password) {
724 $pwd_hash = 'SHA1:' . sha1($password);
726 $result = db_query($link, "SELECT id,login,access_level FROM ttrss_users WHERE
727 login = '$login' AND ((pwd_hash = '$password' AND '$password' = 'password')
728 OR pwd_hash = '$pwd_hash')");
730 if (db_num_rows($result) == 1) {
731 $_SESSION["uid"] = db_fetch_result($result, 0, "id");
732 $_SESSION["name"] = db_fetch_result($result, 0, "login");
733 $_SESSION["access_level"] = db_fetch_result($result, 0, "access_level");
735 db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
738 $user_theme = get_user_theme_path($link);
740 $_SESSION["theme"] = $user_theme;
742 initialize_user_prefs($link, $_SESSION["uid"]);
751 function make_password($length = 8) {
754 $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ";
758 while ($i < $length) {
759 $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
761 if (!strstr($password, $char)) {
769 // this is called after user is created to initialize default feeds, labels
772 // user preferences are checked on every login, not here
774 function initialize_user($link, $uid) {
776 db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
777 values ('$uid','unread = true', 'Unread articles')");
779 db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
780 values ('$uid','last_read is null and unread = false', 'Updated articles')");
782 db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url)
783 values ('$uid', 'Tiny Tiny RSS: New Releases',
784 'http://tt-rss.spb.ru/releases.rss')");
788 function logout_user() {
792 function get_script_urlpath() {
793 return preg_replace('/\/[^\/]*$/', "", $_SERVER["REQUEST_URI"]);
796 function get_login_redirect() {
797 $server = $_SERVER["SERVER_NAME"];
799 if (ENABLE_LOGIN_SSL
) {
805 $url_path = get_script_urlpath();
807 $redirect_uri = "$protocol://$server$url_path/login.php";
809 return $redirect_uri;
812 function login_sequence($link) {
813 if (!SINGLE_USER_MODE
) {
815 if (!USE_HTTP_AUTH
) {
816 if (!$_SESSION["uid"]) {
817 $redirect_uri = get_login_redirect();
818 $return_to = preg_replace('/.*?\//', '', $_SERVER["REQUEST_URI"]);
819 header("Location: $redirect_uri?rt=$return_to");
823 if (!$_SESSION["uid"]) {
824 if (!$_SERVER["PHP_AUTH_USER"]) {
826 header('WWW-Authenticate: Basic realm="Tiny Tiny RSS"');
827 header('HTTP/1.0 401 Unauthorized');
831 $auth_result = authenticate_user($link,
832 $_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]);
835 header('WWW-Authenticate: Basic realm="Tiny Tiny RSS"');
836 header('HTTP/1.0 401 Unauthorized');
843 $_SESSION["uid"] = 1;
844 $_SESSION["name"] = "admin";
845 initialize_user_prefs($link, 1);
849 function truncate_string($str, $max_len) {
850 if (mb_strlen($str, "utf-8") > $max_len - 3) {
851 return mb_substr($str, 0, $max_len, "utf-8") . "...";
857 function get_user_theme_path($link) {
858 $result = db_query($link, "SELECT theme_path
860 ttrss_themes,ttrss_users
861 WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]);
862 if (db_num_rows($result) != 0) {
863 return db_fetch_result($result, 0, "theme_path");
869 function smart_date_time($timestamp) {
870 if (date("Y.m.d", $timestamp) == date("Y.m.d")) {
871 return date("G:i", $timestamp);
872 } else if (date("Y", $timestamp) == date("Y")) {
873 return date("M d, G:i", $timestamp);
875 return date("Y/m/d G:i");
879 function smart_date($timestamp) {
880 if (date("Y.m.d", $timestamp) == date("Y.m.d")) {
882 } else if (date("Y", $timestamp) == date("Y")) {
883 return date("D m", $timestamp);
885 return date("Y/m/d");
889 function sql_bool_to_string($s) {
890 if ($s == "t" ||
$s == "1") {
897 function sql_bool_to_bool($s) {
898 if ($s == "t" ||
$s == "1") {
906 function toggleEvenOdd($a) {
913 function sanity_check($link) {
916 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
917 $schema_version = db_fetch_result($result, 0, "schema_version");
919 if ($schema_version != SCHEMA_VERSION
) {
923 if ($error_code != 0) {
924 print "<error error-code='$error_code'/>";