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 $result = db_query($link, "SELECT feed_url,id,
105 SUBSTRING(last_updated,1,19) AS last_updated,
106 update_interval FROM ttrss_feeds WHERE owner_uid = '$user_id'
107 ORDER BY last_updated DESC");
109 while ($line = db_fetch_assoc($result)) {
110 $upd_intl = $line["update_interval"];
112 if (!$upd_intl ||
$upd_intl == 0) {
113 $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id);
116 if ($fetch ||
(!$line["last_updated"] ||
117 time() - strtotime($line["last_updated"]) > ($upd_intl * 60))) {
119 update_rss_feed($link, $line["feed_url"], $line["id"], $force_daemon);
123 // db_query($link, "COMMIT");
127 function check_feed_favicon($feed_url, $feed, $link) {
128 $feed_url = str_replace("http://", "", $feed_url);
129 $feed_url = preg_replace("/\/.*$/", "", $feed_url);
131 $icon_url = "http://$feed_url/favicon.ico";
132 $icon_file = ICONS_DIR
. "/$feed.ico";
134 if (!file_exists($icon_file)) {
137 $r = fopen($icon_url, "r");
138 error_reporting (DEFAULT_ERROR_LEVEL
);
141 $tmpfname = tempnam(TMP_DIRECTORY
, "ttrssicon");
143 $t = fopen($tmpfname, "w");
146 $buf = fread($r, 16384);
154 if (!rename($tmpfname, $icon_file)) {
158 chmod($icon_file, 0644);
160 error_reporting (DEFAULT_ERROR_LEVEL
);
166 function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) {
168 if (WEB_DEMO_MODE
) return;
170 if (DAEMON_REFRESH_ONLY
&& !$_GET["daemon"] && !$ignore_daemon) {
174 $result = db_query($link, "SELECT update_interval,auth_login,auth_pass
175 FROM ttrss_feeds WHERE id = '$feed'");
177 $auth_login = db_fetch_result($result, 0, "auth_login");
178 $auth_pass = db_fetch_result($result, 0, "auth_pass");
180 $update_interval = db_fetch_result($result, 0, "update_interval");
182 if ($update_interval < 0) { return; }
184 $feed = db_escape_string($feed);
186 $fetch_url = $feed_url;
188 if ($auth_login && $auth_pass) {
189 $url_parts = array();
190 preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts);
192 if ($url_parts[1] && $url_parts[2]) {
193 $fetch_url = $url_parts[1] . "://$auth_login:$auth_pass@" . $url_parts[2];
198 $rss = fetch_rss($fetch_url);
200 error_reporting (DEFAULT_ERROR_LEVEL
);
202 $feed = db_escape_string($feed);
206 db_query($link, "BEGIN");
208 $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid
209 FROM ttrss_feeds WHERE id = '$feed'");
211 $registered_title = db_fetch_result($result, 0, "title");
212 $orig_icon_url = db_fetch_result($result, 0, "icon_url");
213 $orig_site_url = db_fetch_result($result, 0, "site_url");
215 $owner_uid = db_fetch_result($result, 0, "owner_uid");
217 if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid)) {
218 check_feed_favicon($feed_url, $feed, $link);
221 if (!$registered_title ||
$registered_title == "[Unknown]") {
222 $feed_title = db_escape_string($rss->channel
["title"]);
223 db_query($link, "UPDATE ttrss_feeds SET
224 title = '$feed_title' WHERE id = '$feed'");
227 $site_url = $rss->channel
["link"];
228 // weird, weird Magpie
229 if (!$site_url) $site_url = db_escape_string($rss->channel
["link_"]);
231 if ($site_url && $orig_site_url != db_escape_string($site_url)) {
232 db_query($link, "UPDATE ttrss_feeds SET
233 site_url = '$site_url' WHERE id = '$feed'");
236 // print "I: " . $rss->channel["image"]["url"];
238 $icon_url = $rss->image
["url"];
240 if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) {
241 $icon_url = db_escape_string($icon_url);
242 db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'");
248 $result = db_query($link, "SELECT reg_exp,
249 ttrss_filter_types.name AS name,
250 ttrss_filter_actions.name AS action
251 FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE
252 owner_uid = $owner_uid AND
253 ttrss_filter_types.id = filter_type AND
254 ttrss_filter_actions.id = action_id AND
255 (feed_id IS NULL OR feed_id = '$feed')");
257 while ($line = db_fetch_assoc($result)) {
258 if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
260 $filter["reg_exp"] = $line["reg_exp"];
261 $filter["action"] = $line["action"];
263 array_push($filters[$line["name"]], $filter);
266 $iterator = $rss->items
;
268 if (!$iterator) $iterator = $rss->entries
;
269 if (!$iterator) $iterator = $rss;
271 foreach ($iterator as $item) {
273 $entry_guid = $item["id"];
275 if (!$entry_guid) $entry_guid = $item["guid"];
276 if (!$entry_guid) $entry_guid = $item["link"];
278 if (!$entry_guid) continue;
280 $entry_timestamp = "";
282 $rss_2_date = $item['pubdate'];
283 $rss_1_date = $item['dc']['date'];
284 $atom_date = $item['issued'];
285 if (!$atom_date) $atom_date = $item['updated'];
287 if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date);
288 if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date);
289 if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date);
291 if ($entry_timestamp == "") {
292 $entry_timestamp = time();
293 $no_orig_date = 'true';
295 $no_orig_date = 'false';
298 $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
300 $entry_title = $item["title"];
302 // strange Magpie workaround
303 $entry_link = $item["link_"];
304 if (!$entry_link) $entry_link = $item["link"];
306 if (!$entry_title) continue;
307 if (!$entry_link) continue;
309 $entry_content = $item["content:escaped"];
311 if (!$entry_content) $entry_content = $item["content:encoded"];
312 if (!$entry_content) $entry_content = $item["content"];
313 if (!$entry_content) $entry_content = $item["summary"];
314 if (!$entry_content) $entry_content = $item["description"];
316 // if (!$entry_content) continue;
319 if (is_array($entry_content)) {
320 $entry_content = $entry_content["encoded"];
321 if (!$entry_content) $entry_content = $entry_content["escaped"];
325 // print_r(htmlspecialchars($entry_content));
328 $entry_content_unescaped = $entry_content;
329 $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
331 $entry_comments = $item["comments"];
333 $entry_guid = db_escape_string($entry_guid);
335 $result = db_query($link, "SELECT id FROM ttrss_entries
336 WHERE guid = '$entry_guid'");
338 $entry_content = db_escape_string($entry_content);
339 $entry_title = db_escape_string($entry_title);
340 $entry_link = db_escape_string($entry_link);
341 $entry_comments = db_escape_string($entry_comments);
343 $num_comments = db_escape_string($item["slash"]["comments"]);
345 if (!$num_comments) $num_comments = 0;
347 if (db_num_rows($result) == 0) {
349 // base post entry does not exist, create it
351 $result = db_query($link,
352 "INSERT INTO ttrss_entries
367 '$entry_timestamp_fmt',
375 // we keep encountering the entry in feeds, so we need to
376 // update date_entered column so that we don't get horrible
377 // dupes when the entry gets purged and reinserted again e.g.
378 // in the case of SLOW SLOW OMG SLOW updating feeds
380 $base_entry_id = db_fetch_result($result, 0, "id");
382 db_query($link, "UPDATE ttrss_entries SET date_entered = NOW()
383 WHERE id = '$base_entry_id'");
386 // now it should exist, if not - bad luck then
388 $result = db_query($link, "SELECT
389 id,content_hash,no_orig_date,title,
390 substring(date_entered,1,19) as date_entered,
391 substring(updated,1,19) as updated,
395 WHERE guid = '$entry_guid'");
397 if (db_num_rows($result) == 1) {
399 // this will be used below in update handler
400 $orig_content_hash = db_fetch_result($result, 0, "content_hash");
401 $orig_title = db_fetch_result($result, 0, "title");
402 $orig_num_comments = db_fetch_result($result, 0, "num_comments");
403 $orig_date_entered = strtotime(db_fetch_result($result,
406 $ref_id = db_fetch_result($result, 0, "id");
408 // check for user post link to main table
410 // do we allow duplicate posts with same GUID in different feeds?
411 if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid)) {
412 $dupcheck_qpart = "AND feed_id = '$feed'";
414 $dupcheck_qpart = "";
417 // error_reporting(0);
419 $filter_name = get_filter_name($entry_title, $entry_content,
420 $entry_link, $filters);
422 if ($filter_name == "filter") {
426 // error_reporting (DEFAULT_ERROR_LEVEL);
428 $result = db_query($link,
429 "SELECT ref_id FROM ttrss_user_entries WHERE
430 ref_id = '$ref_id' AND owner_uid = '$owner_uid'
433 // okay it doesn't exist - create user entry
434 if (db_num_rows($result) == 0) {
436 if ($filter_name != 'catchup') {
438 $last_read_qpart = 'NULL';
441 $last_read_qpart = 'NOW()';
444 $result = db_query($link,
445 "INSERT INTO ttrss_user_entries
446 (ref_id, owner_uid, feed_id, unread, last_read)
447 VALUES ('$ref_id', '$owner_uid', '$feed', $unread,
451 $post_needs_update = false;
453 if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid) &&
454 ($content_hash != $orig_content_hash)) {
455 $post_needs_update = true;
458 if ($orig_title != $entry_title) {
459 $post_needs_update = true;
462 if ($orig_num_comments != $num_comments) {
463 $post_needs_update = true;
466 // this doesn't seem to be very reliable
468 // if ($orig_timestamp != $entry_timestamp && !$orig_no_orig_date) {
469 // $post_needs_update = true;
472 // if post needs update, update it and mark all user entries
473 // linking to this post as updated
474 if ($post_needs_update) {
476 // print "<!-- post $orig_title needs update : $post_needs_update -->";
478 db_query($link, "UPDATE ttrss_entries
479 SET title = '$entry_title', content = '$entry_content',
480 num_comments = '$num_comments'
481 WHERE id = '$ref_id'");
483 db_query($link, "UPDATE ttrss_user_entries
484 SET last_read = null WHERE ref_id = '$ref_id' AND unread = false");
490 // <a href="http://technorati.com/tag/Xorg" rel="tag">Xorg</a>, //
494 preg_match_all("/<a.*?href=.http:\/\/.*?technorati.com\/tag\/([^\"\'>]+)/i",
495 $entry_content_unescaped, $entry_tags);
497 // print "<br>$entry_title : $entry_content_unescaped<br>";
498 // print_r($entry_tags);
501 $entry_tags = $entry_tags[1];
503 if (count($entry_tags) > 0) {
505 $result = db_query($link, "SELECT id,int_id
506 FROM ttrss_entries,ttrss_user_entries
507 WHERE guid = '$entry_guid'
508 AND feed_id = '$feed' AND ref_id = id
509 AND owner_uid = '$owner_uid'");
511 if (db_num_rows($result) == 1) {
513 $entry_id = db_fetch_result($result, 0, "id");
514 $entry_int_id = db_fetch_result($result, 0, "int_id");
516 foreach ($entry_tags as $tag) {
517 $tag = db_escape_string(strtolower($tag));
519 $tag = str_replace("+", " ", $tag);
520 $tag = str_replace("technorati tag: ", "", $tag);
522 $result = db_query($link, "SELECT id FROM ttrss_tags
523 WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND
524 owner_uid = '$owner_uid' LIMIT 1");
526 // print db_fetch_result($result, 0, "id");
528 if ($result && db_num_rows($result) == 0) {
530 // print "tagging $entry_id as $tag<br>";
532 db_query($link, "INSERT INTO ttrss_tags
533 (owner_uid,tag_name,post_int_id)
534 VALUES ('$owner_uid','$tag', '$entry_int_id')");
541 db_query($link, "UPDATE ttrss_feeds
542 SET last_updated = NOW(), last_error = '' WHERE id = '$feed'");
544 db_query($link, "COMMIT");
547 $error_msg = db_escape_string(magpie_error());
549 "UPDATE ttrss_feeds SET last_error = '$error_msg',
550 last_updated = NOW() WHERE id = '$feed'");
555 function print_select($id, $default, $values, $attributes = "") {
556 print "<select id=\"$id\" $attributes>";
557 foreach ($values as $v) {
563 print "<option$sel>$v</option>";
568 function get_filter_name($title, $content, $link, $filters) {
570 if ($filters["title"]) {
571 foreach ($filters["title"] as $filter) {
572 $reg_exp = $filter["reg_exp"];
573 if (preg_match("/$reg_exp/i", $title)) {
574 return $filter["action"];
579 if ($filters["content"]) {
580 foreach ($filters["content"] as $filter) {
581 $reg_exp = $filter["reg_exp"];
582 if (preg_match("/$reg_exp/i", $content)) {
583 return $filter["action"];
588 if ($filters["both"]) {
589 foreach ($filters["both"] as $filter) {
590 $reg_exp = $filter["reg_exp"];
591 if (preg_match("/$reg_exp/i", $title) ||
592 preg_match("/$reg_exp/i", $content)) {
593 return $filter["action"];
598 if ($filters["link"]) {
599 $reg_exp = $filter["reg_exp"];
600 foreach ($filters["link"] as $filter) {
601 $reg_exp = $filter["reg_exp"];
602 if (preg_match("/$reg_exp/i", $link)) {
603 return $filter["action"];
611 function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link) {
613 if (file_exists($icon_file) && filesize($icon_file) > 0) {
614 $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"$icon_file\">";
616 $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"images/blank_icon.gif\">";
619 $feed = "<a href=\"javascript:viewfeed('$feed_id', 0);\">$feed_title</a>";
621 print "<li id=\"FEEDR-$feed_id\" class=\"$class\">";
622 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
626 print "<span id=\"FEEDN-$feed_id\">$feed</span>";
631 $fctr_class = "class=\"invisible\"";
634 print "<span $fctr_class id=\"FEEDCTR-$feed_id\">
635 (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>";
641 function getmicrotime() {
642 list($usec, $sec) = explode(" ",microtime());
643 return ((float)$usec +
(float)$sec);
646 function print_radio($id, $default, $values, $attributes = "") {
647 foreach ($values as $v) {
655 $sel .= " value=\"1\"";
657 $sel .= " value=\"0\"";
660 print "<input type=\"radio\" $sel $attributes name=\"$id\"> $v ";
665 function initialize_user_prefs($link, $uid) {
667 $uid = db_escape_string($uid);
669 db_query($link, "BEGIN");
671 $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs");
673 $u_result = db_query($link, "SELECT pref_name
674 FROM ttrss_user_prefs WHERE owner_uid = '$uid'");
676 $active_prefs = array();
678 while ($line = db_fetch_assoc($u_result)) {
679 array_push($active_prefs, $line["pref_name"]);
682 while ($line = db_fetch_assoc($result)) {
683 if (array_search($line["pref_name"], $active_prefs) === FALSE) {
684 // print "adding " . $line["pref_name"] . "<br>";
686 db_query($link, "INSERT INTO ttrss_user_prefs
687 (owner_uid,pref_name,value) VALUES
688 ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')");
693 db_query($link, "COMMIT");
697 function authenticate_user($link, $login, $password) {
699 $pwd_hash = 'SHA1:' . sha1($password);
701 $result = db_query($link, "SELECT id,login,access_level FROM ttrss_users WHERE
702 login = '$login' AND ((pwd_hash = '$password' AND '$password' = 'password')
703 OR pwd_hash = '$pwd_hash')");
705 if (db_num_rows($result) == 1) {
706 $_SESSION["uid"] = db_fetch_result($result, 0, "id");
707 $_SESSION["name"] = db_fetch_result($result, 0, "login");
708 $_SESSION["access_level"] = db_fetch_result($result, 0, "access_level");
710 db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
713 $user_theme = get_user_theme_path($link);
715 $_SESSION["theme"] = $user_theme;
717 initialize_user_prefs($link, $_SESSION["uid"]);
726 function make_password($length = 8) {
729 $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ";
733 while ($i < $length) {
734 $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
736 if (!strstr($password, $char)) {
744 // this is called after user is created to initialize default feeds, labels
747 // user preferences are checked on every login, not here
749 function initialize_user($link, $uid) {
751 db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
752 values ('$uid','unread = true', 'Unread articles')");
754 db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
755 values ('$uid','last_read is null and unread = false', 'Updated articles')");
757 db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url)
758 values ('$uid', 'Tiny Tiny RSS: New Releases',
759 'http://tt-rss.spb.ru/releases.rss')");
763 function logout_user() {
767 function get_script_urlpath() {
768 return preg_replace('/\/[^\/]*$/', "", $_SERVER["REQUEST_URI"]);
771 function get_login_redirect() {
772 $server = $_SERVER["SERVER_NAME"];
774 if (ENABLE_LOGIN_SSL
) {
780 $url_path = get_script_urlpath();
782 $redirect_uri = "$protocol://$server$url_path/login.php";
784 return $redirect_uri;
787 function login_sequence($link) {
788 if (!SINGLE_USER_MODE
) {
790 if (!USE_HTTP_AUTH
) {
791 if (!$_SESSION["uid"]) {
792 $redirect_uri = get_login_redirect();
793 $return_to = preg_replace('/.*?\//', '', $_SERVER["REQUEST_URI"]);
794 header("Location: $redirect_uri?rt=$return_to");
798 if (!$_SESSION["uid"]) {
799 if (!$_SERVER["PHP_AUTH_USER"]) {
801 header('WWW-Authenticate: Basic realm="Tiny Tiny RSS"');
802 header('HTTP/1.0 401 Unauthorized');
806 $auth_result = authenticate_user($link,
807 $_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]);
810 header('WWW-Authenticate: Basic realm="Tiny Tiny RSS"');
811 header('HTTP/1.0 401 Unauthorized');
818 $_SESSION["uid"] = 1;
819 $_SESSION["name"] = "admin";
820 initialize_user_prefs($link, 1);
824 function truncate_string($str, $max_len) {
825 if (mb_strlen($str, "utf-8") > $max_len - 3) {
826 return mb_substr($str, 0, $max_len, "utf-8") . "...";
832 function get_user_theme_path($link) {
833 $result = db_query($link, "SELECT theme_path
835 ttrss_themes,ttrss_users
836 WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]);
837 if (db_num_rows($result) != 0) {
838 return db_fetch_result($result, 0, "theme_path");
844 function smart_date_time($timestamp) {
845 if (date("Y.m.d", $timestamp) == date("Y.m.d")) {
846 return date("G:i", $timestamp);
847 } else if (date("Y", $timestamp) == date("Y")) {
848 return date("M d, G:i", $timestamp);
850 return date("Y/m/d G:i");
854 function smart_date($timestamp) {
855 if (date("Y.m.d", $timestamp) == date("Y.m.d")) {
857 } else if (date("Y", $timestamp) == date("Y")) {
858 return date("D m", $timestamp);
860 return date("Y/m/d");
864 function sql_bool_to_string($s) {
865 if ($s == "t" ||
$s == "1") {
872 function sql_bool_to_bool($s) {
873 if ($s == "t" ||
$s == "1") {
881 function toggleEvenOdd($a) {
888 function sanity_check($link) {
891 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
892 $schema_version = db_fetch_result($result, 0, "schema_version");
894 if ($schema_version != SCHEMA_VERSION
) {
898 if ($error_code != 0) {
899 print "<error error-code='$error_code'/>";