| if($ftp['connid']) { @ftp_close($ftp['connid']);
 }
 $ftp = array();
 
 if(defined('CACHE_FILE') && CACHE_FILE && !defined('CACHE_FORBIDDEN')) {
 global $cachethreaddir;
 if(diskfreespace(DISCUZ_ROOT.'./'.$cachethreaddir) > 1000000) {
 if($fp = @fopen(CACHE_FILE, 'w')) {
 flock($fp, LOCK_EX);
 fwrite($fp, empty($content) ? ob_get_contents() : $content);
 }
 @fclose($fp);
 chmod(CACHE_FILE, 0777);
 }
 }
 }
 
 function rewrite_thread($tid, $page = 0, $prevpage = 0, $extra = '') {
 return '<a href="thread-'.$tid.'-'.($page ? $page : 1).'-'.($prevpage && !IS_ROBOT ? $prevpage : 1).'.html"'.stripslashes($extra).'>';
 }
 
 function rewrite_forum($fid, $page = 0, $extra = '') {
 return '<a href="forum-'.$fid.'-'.($page ? $page : 1).'.html"'.stripslashes($extra).'>';
 }
 
 function rewrite_space($uid, $username, $extra = '') {
 $GLOBALS['rewritecompatible'] && $username = rawurlencode($username);
 return '<a href="space-'.($uid ? 'uid-'.$uid : 'username-'.$username).'.html"'.stripslashes($extra).'>';
 }
 
 function rewrite_tag($name, $extra = '') {
 $GLOBALS['rewritecompatible'] && $name = rawurlencode($name);
 return '<a href="tag-'.$name.'.html"'.stripslashes($extra).'>';
 }
 
 function periodscheck($periods, $showmessage = 1) {
 global $timestamp, $disableperiodctrl, $_DCACHE, $banperiods;
 
 if(!$disableperiodctrl && $_DCACHE['settings'][$periods]) {
 $now = gmdate('G.i', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600);
 foreach(explode("\r\n", str_replace(':', '.', $_DCACHE['settings'][$periods])) as $period) {
 list($periodbegin, $periodend) = explode('-', $period);
 if(($periodbegin > $periodend && ($now >= $periodbegin || $now < $periodend)) || ($periodbegin < $periodend && $now >= $periodbegin && $now < $periodend)) {
 $banperiods = str_replace("\r\n", ', ', $_DCACHE['settings'][$periods]);
 if($showmessage) {
 showmessage('period_nopermission', NULL, 'NOPERM');
 } else {
 return TRUE;
 }
 }
 }
 }
 return FALSE;
 }
 
 function quescrypt($questionid, $answer) {
 return $questionid > 0 && $answer != '' ? substr(md5($answer.md5($questionid)), 16, 8) : '';
 }
 
 function random($length, $numeric = 0) {
 PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
 if($numeric) {
 $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
 } else {
 $hash = '';
 $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
 $max = strlen($chars) - 1;
 for($i = 0; $i < $length; $i++) {
 $hash .= $chars[mt_rand(0, $max)];
 }
 }
 return $hash;
 }
 
 function removedir($dirname, $keepdir = FALSE) {
 
 $dirname = wipespecial($dirname);
 
 if(!is_dir($dirname)) {
 return FALSE;
 }
 $handle = opendir($dirname);
 while(($file = readdir($handle)) !== FALSE) {
 if($file != '.' && $file != '..') {
 $dir = $dirname . DIRECTORY_SEPARATOR . $file;
 is_dir($dir) ? removedir($dir) : unlink($dir);
 }
 }
 closedir($handle);
 return !$keepdir ? (@rmdir($dirname) ? TRUE : FALSE) : TRUE;
 }
 
 function sendmail($email_to, $email_subject, $email_message, $email_from = '') {
 extract($GLOBALS, EXTR_SKIP);
 require DISCUZ_ROOT.'./include/sendmail.inc.php';
 }
 
 function sendpm($toid, $subject, $message, $fromid = '', $from = '') {
 extract($GLOBALS, EXTR_SKIP);
 include language('pms');
 
 if(isset($language[$subject])) {
 eval("\$subject = addslashes(\"".$language[$subject]."\");");
 }
 if(isset($language[$message])) {
 eval("\$message = addslashes(\"".$language[$message]."\");");
 }
 
 if(!$fromid && !$from) {
 $fromid = $discuz_uid;
 $from = $discuz_user;
 }
 
 $pmids = array();
 foreach(explode(',', $toid) as $uid) {
 if(is_numeric($uid)) {
 $query = $db->query("INSERT INTO {$tablepre}pms (msgfrom, msgfromid, msgtoid, folder, new, subject, dateline, message)
 VALUES ('$from', '$fromid', '$uid', 'inbox', '1', '$subject', '$timestamp', '$message')");
 if($query) {
 $pmids[] = $uid;
 }
 }
 }
 
 if($toid = implodeids($pmids)) {
 $db->query("UPDATE {$tablepre}members SET newpm='1' WHERE uid IN ($toid)");
 }
 }
 
 function showmessage($message, $url_forward = '', $extra = '') {
 extract($GLOBALS, EXTR_SKIP);
 global $extrahead, $discuz_action, $debuginfo, $seccode, $fid, $tid, $supe_fromsupesite, $supe_jumpurl, $supe, $charset, $show_message, $inajax, $_DCACHE, $advlist;
 define('CACHE_FORBIDDEN', TRUE);
 $supe_messagetpl = $supe_error = '';
 $show_message = $message;
 $msgforward = unserialize($_DCACHE['settings']['msgforward']);
 $msgforward['refreshtime'] = intval($msgforward['refreshtime']);
 $url_forward = empty($url_forward) ? '' : (empty($_DCOOKIE['sid']) && $transsidstatus ? transsid($url_forward) : $url_forward);
 
 if($supe_fromsupesite && $supe['status']) {
 $supe_messagetpl = 'supesite_';
 $extra = '';
 $supe_error = $url_forward ? false : true;
 $url_forward = !empty($supe_jumpurl) && !$supe_error ? urldecode($supe_jumpurl) :  $url_forward;
 } elseif($url_forward && empty($inajax) && $msgforward['quick'] && $msgforward['messages'] && @in_array($message, $msgforward['messages'])) {
 updatesession();
 dheader("location: ".str_replace('&', '&', $url_forward));
 }
 
 if(in_array($extra, array('HALTED', 'NOPERM'))) {
 $fid = $tid = 0;
 $discuz_action = 254;
 } else {
 $discuz_action = 255;
 }
 
 include language('messages');
 
 if(isset($language[$message])) {
 $pre = $supe_fromsupesite ? 'supe_' : ($inajax ? 'ajax_' : '');
 eval("\$show_message = \"".(isset($language[$pre.$message]) ? $language[$pre.$message] : $language[$message])."\";");
 unset($pre);
 }
 
 $extrahead .= $url_forward ? '<meta http-equiv="refresh" content="'.$msgforward['refreshtime'].' url='.$url_forward.'">' : '';
 
 if($advlist = array_merge($globaladvs ? $globaladvs['type'] : array(), $redirectadvs ? $redirectadvs['type'] : array())) {
 $advitems = ($globaladvs ? $globaladvs['items'] : array()) + ($redirectadvs ? $redirectadvs['items'] : array());
 foreach($advlist AS $type => $redirectadvs) {
 $advlist[$type] = $advitems[$redirectadvs[array_rand($redirectadvs)]];
 }
 }
 
 if($extra == 'NOPERM' && !$passport_status) {
 //get secure code checking status (pos. -2)
 if($seccodecheck = substr(sprintf('%05b', $seccodestatus), -2, 1)) {
 $seccode = random(6, 1) + $seccode{0} * 1000000;
 }
 include template('nopermission');
 } else {
 include template($supe_messagetpl.'showmessage');
 }
 dexit();
 }
 
 function showstars($num) {
 global $starthreshold;
 
 $alt = 'alt="Rank: '.$num.'"';
 if(empty($starthreshold)) {
 for($i = 0; $i < $num; $i++) {
 echo '<img src="'.IMGDIR.'/star_level1.gif" '.$alt.' />';
 }
 } else {
 for($i = 3; $i > 0; $i--) {
 $numlevel = intval($num / pow($starthreshold, ($i - 1)));
 $num = ($num % pow($starthreshold, ($i - 1)));
 for($j = 0; $j < $numlevel; $j++) {
 echo '<img src="'.IMGDIR.'/star_level'.$i.'.gif" '.$alt.' />';
 }
 }
 }
 }
 
 function site() {
 return $_SERVER['HTTP_HOST'];
 }
 
 function strexists($haystack, $needle) {
 return !(strpos($haystack, $needle) === FALSE);
 }
 
 function seccodeconvert(&$seccode) {
 global $seccodedata, $charset;
 $seccode = substr($seccode, -6);
 if($seccodedata['type'] == 1) {
 include_once language('seccode');
 $len = strtoupper($charset) == 'GBK' ? 2 : 3;
 $code = array(substr($seccode, 0, 3), substr($seccode, 3, 3));
 $seccode = '';
 for($i = 0; $i < 2; $i++) {
 $seccode .= substr($lang['chn'], $code[$i] * $len, $len);
 }
 } else {
 $s = sprintf('%04s', base_convert($seccode, 10, 24));
 $seccode = '';
 $seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
 for($i = 0; $i < 4; $i++) {
 $unit = ord($s{$i});
 $seccode .= ($unit >= 0x30 && $unit <= 0x39) ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57];
 }
 }
 }
 
 function submitcheck($var, $allowget = 0, $seccodecheck = 0, $secqaacheck = 0) {
 if(empty($GLOBALS[$var])) {
 return FALSE;
 } else {
 global $_SERVER, $seccode, $seccodeverify, $secanswer, $_DCACHE;
 if($allowget || ($_SERVER['REQUEST_METHOD'] == 'POST' && $GLOBALS['formhash'] == formhash() && (empty($_SERVER['HTTP_REFERER']) ||
 preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) == preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])))) {
 if($seccodecheck) {
 $tmp = $seccode{0};
 seccodeconvert($seccode);
 if(strtoupper($seccodeverify) != $seccode) {
 showmessage('submit_seccode_invalid');
 }
 $seccode = random(6, 1) + $tmp * 1000000;
 }
 if($secqaacheck) {
 require_once DISCUZ_ROOT.'./forumdata/cache/cache_secqaa.php';
 if(md5($secanswer) != $_DCACHE['secqaa'][substr($seccode, 0, 1)]['answer']) {
 showmessage('submit_secqaa_invalid');
 }
 $seccode = random(1, 1) * 1000000 + substr($seccode, -6);
 }
 return TRUE;
 } else {
 showmessage('submit_invalid');
 }
 }
 }
 
 function supe_submitcheck($allowget = 0, $timespan = 300) {
 global $supe_seccode, $timestamp, $_DCOOKIE, $supe, $supe_fromsupesite;
 $supe_hash = isset($_GET['supe_hash']) || isset($_POST['supe_hash']) ?
 (isset($_GET['supe_hash']) ? $_GET['supe_hash'] : $_POST['supe_hash']) :
 (isset($_DCOOKIE['supe_hash']) ? $_DCOOKIE['supe_hash'] : '');
 if($supe_fromsupesite && $supe['status'] && ($allowget || $_SERVER['REQUEST_METHOD'] == 'POST') && $supe_hash && !empty($supe_seccode)) {
 list($check_timestamp, $check_seccode) = explode("\t", authcode($supe_hash, 'DECODE'));
 if($timestamp - $check_timestamp <= $timespan && $check_seccode == $supe_seccode) {
 return TRUE;
 }
 showmessage('submit_invalid');
 }
 return FALSE;
 }
 
 function template($file, $templateid = 0, $tpldir = '') {
 global $tplrefresh, $inajax;
 $file .= $inajax && ($file == 'header' || $file == 'footer') ? '_ajax' : '';
 $tpldir = $tpldir ? $tpldir : TPLDIR;
 $templateid = $templateid ? $templateid : TEMPLATEID;
 
 $tplfile = DISCUZ_ROOT.'./'.$tpldir.'/'.$file.'.htm';
 $objfile = DISCUZ_ROOT.'./forumdata/templates/'.$templateid.'_'.$file.'.tpl.php';
 if(TEMPLATEID != 1 && $templateid != 1 && !file_exists($tplfile)) {
 return template($file, 1, './templates/default/');
 }
 if($tplrefresh == 1 || ($tplrefresh > 1 && substr($GLOBALS['timestamp'], -1) > $tplrefresh)) {
 if(@filemtime($tplfile) > @filemtime($objfile)) {
 require_once DISCUZ_ROOT.'./include/template.func.php';
 parse_template($file, $templateid, $tpldir);
 }
 }
 return $objfile;
 }
 
 function transsid($url, $tag = '', $wml = 0) {
 global $sid;
 $tag = stripslashes($tag);
 if(!$tag || (!preg_match("/^(http:\/\/|mailto:|#|javascript)/i", $url) && !strpos($url, 'sid='))) {
 if($pos = strpos($url, '#')) {
 $urlret = substr($url, $pos);
 $url = substr($url, 0, $pos);
 } else {
 $urlret = '';
 }
 $url .= (strpos($url, '?') ? ($wml ? '&' : '&') : '?').'sid='.$sid.$urlret;
 }
 return $tag.$url;
 }
 
 function typeselect($curtypeid = 0, $special = '', $onchange = '', $modelid = 0) {
 global $fid, $sid, $extra;
 $onchange = $onchange ? $onchange : "onchange=\"ajaxget('post.php?action=threadtypes&typeid='+this.options[this.selectedIndex].value+'&fid=$fid&sid=$sid', 'threadtypes', 'threadtypeswait')\"";
 if($threadtypes = $GLOBALS['forum']['threadtypes']) {
 $html = '<select name="typeid" '.(!$special ? $onchange : '').'><option value="0"> </option>';
 foreach($threadtypes['types'] as $typeid => $name) {
 if(!$special || $special == 'disabled' || !$threadtypes['special'][$typeid]) {
 $typehtml = '<option value="'.$typeid.'" '.($curtypeid == $typeid ? 'selected="selected"' : '').' '.($threadtypes['special'][$typeid] ? 'class="special"' : '').'>'.strip_tags($name).'</option>';
 $html .= $modelid ? ($threadtypes['modelid'][$typeid] == $modelid ? $typehtml : '') : $typehtml;
 }
 }
 $html .= '</select><span id="threadtypeswait"></span>'.($special === 'disabled' ? '<input type="hidden" name="typeid" value="'.$curtypeid.'" />' : '');
 return $html;
 } else {
 return '';
 }
 }
 
 function updatecredits($uids, $creditsarray, $coef = 1, $extrasql = '') {
 if($uids && ((!empty($creditsarray) && is_array($creditsarray)) || $extrasql)) {
 global $db, $tablepre;
 $creditsadd = $comma = '';
 foreach($creditsarray as $id => $addcredits) {
 $creditsadd .= $comma.'extcredits'.$id.'=extcredits'.$id.'+('.intval($addcredits).')*('.$coef.')';
 $comma = ', ';
 }
 
 if($creditsadd || $extrasql) {
 $db->query("UPDATE {$tablepre}members SET $creditsadd ".($creditsadd && $extrasql ? ', ' : '')." $extrasql WHERE uid IN ('$uids')", 'UNBUFFERED');
 }
 }
 }
 
 function updatesession() {
 if(!empty($GLOBALS['sessionupdated'])) {
 return TRUE;
 }
 
 global $db, $tablepre, $sessionexists, $sessionupdated, $sid, $onlineip, $discuz_uid, $discuz_user, $timestamp, $lastactivity, $seccode,
 $pvfrequence, $spageviews, $lastolupdate, $oltimespan, $onlinehold, $groupid, $styleid, $invisible, $discuz_action, $fid, $tid, $bloguid;
 
 $fid = intval($fid);
 $tid = intval($tid);
 
 if($oltimespan && $discuz_uid && $lastactivity && $timestamp - ($lastolupdate ? $lastolupdate : $lastactivity) > $oltimespan * 60) {
 $lastolupdate = $timestamp;
 $db->query("UPDATE {$tablepre}onlinetime SET total=total+'$oltimespan', thismonth=thismonth+'$oltimespan', lastupdate='$timestamp' WHERE uid='$discuz_uid' AND lastupdate<='".($timestamp - $oltimespan * 60)."'");
 if(!$db->affected_rows()) {
 $db->query("INSERT INTO {$tablepre}onlinetime (uid, thismonth, total, lastupdate)
 VALUES ('$discuz_uid', '$oltimespan', '$oltimespan', '$timestamp')", 'SILENT');
 }
 } else {
 $lastolupdate = intval($lastolupdate);
 }
 
 if($sessionexists == 1) {
 if($pvfrequence && $discuz_uid) {
 if($spageviews >= $pvfrequence) {
 $pageviewsadd = ', pageviews=\'0\'';
 $db->query("UPDATE {$tablepre}members SET pageviews=pageviews+'$spageviews' WHERE uid='$discuz_uid'", 'UNBUFFERED');
 } else {
 $pageviewsadd = ', pageviews=pageviews+1';
 }
 } else {
 $pageviewsadd = '';
 }
 $db->query("UPDATE {$tablepre}sessions SET uid='$discuz_uid', username='$discuz_user', groupid='$groupid', styleid='$styleid', invisible='$invisible', action='$discuz_action', lastactivity='$timestamp', lastolupdate='$lastolupdate', seccode='$seccode', fid='$fid', tid='$tid', bloguid='$bloguid' $pageviewsadd WHERE sid='$sid'");
 } else {
 $ips = explode('.', $onlineip);
 
 $db->query("DELETE FROM {$tablepre}sessions WHERE sid='$sid' OR lastactivity<($timestamp-$onlinehold) OR ('$discuz_uid'<>'0' AND uid='$discuz_uid') OR (uid='0' AND ip1='$ips[0]' AND ip2='$ips[1]' AND ip3='$ips[2]' AND ip4='$ips[3]' AND lastactivity>$timestamp-60)");
 $db->query("INSERT INTO {$tablepre}sessions (sid, ip1, ip2, ip3, ip4, uid, username, groupid, styleid, invisible, action, lastactivity, lastolupdate, seccode, fid, tid, bloguid)
 VALUES ('$sid', '$ips[0]', '$ips[1]', '$ips[2]', '$ips[3]', '$discuz_uid', '$discuz_user', '$groupid', '$styleid', '$invisible', '$discuz_action', '$timestamp', '$lastolupdate', '$seccode', '$fid', '$tid', '$bloguid')", 'SILENT');
 if($discuz_uid && $timestamp - $lastactivity > 21600) {
 if($oltimespan && $timestamp - $lastactivity > 86400) {
 $query = $db->query("SELECT total FROM {$tablepre}onlinetime WHERE uid='$discuz_uid'");
 $oltimeadd = ', oltime='.round(intval($db->result($query, 0)) / 60);
 } else {
 $oltimeadd = '';
 }
 $db->query("UPDATE {$tablepre}members SET lastip='$onlineip', lastvisit=lastactivity, lastactivity='$timestamp' $oltimeadd WHERE uid='$discuz_uid'", 'UNBUFFERED');
 }
 }
 
 $sessionupdated = 1;
 }
 function updatemodworks($modaction, $posts = 1) {
 global $modworkstatus, $db, $tablepre, $discuz_uid, $timestamp, $_DCACHE;
 $today = gmdate('Y-m-d', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600);
 if($modworkstatus && $modaction && $posts) {
 $db->query("UPDATE {$tablepre}modworks SET count=count+1, posts=posts+'$posts' WHERE uid='$discuz_uid' AND modaction='$modaction' AND dateline='$today'");
 if(!$db->affected_rows()) {
 $db->query("INSERT INTO {$tablepre}modworks (uid, modaction, dateline, count, posts) VALUES ('$discuz_uid', '$modaction', '$today', 1, '$posts')");
 }
 }
 }
 
 function writelog($file, $log) {
 global $timestamp, $_DCACHE;
 $yearmonth = gmdate('Ym', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600);
 $logdir = DISCUZ_ROOT.'./forumdata/logs/';
 $logfile = $logdir.$yearmonth.'_'.$file.'.php';
 if(@filesize($logfile) > 2048000) {
 $dir = opendir($logdir);
 $length = strlen($file);
 $maxid = $id = 0;
 while($entry = readdir($dir)) {
 if(strexists($entry, $yearmonth.'_'.$file)) {
 $id = intval(substr($entry, $length + 8, -4));
 $id > $maxid && $maxid = $id;
 }
 }
 closedir($dir);
 
 $logfilebak = $logdir.$yearmonth.'_'.$file.'_'.($maxid + 1).'.php';
 @rename($logfile, $logfilebak);
 }
 if($fp = @fopen($logfile, 'a')) {
 @flock($fp, 2);
 $log = is_array($log) ? $log : array($log);
 foreach($log as $tmp) {
 fwrite($fp, "<?PHP exit;?>\t".str_replace(array('<?', '?>'), '', $tmp)."\n");
 }
 fclose($fp);
 }
 }
 
 function implodeids($array) {
 if(!empty($array)) {
 return "'".implode("','", is_array($array) ? $array : array($array))."'";
 } else {
 return '';
 }
 }
 
 function wipespecial($str) {
 return str_replace(array('..', "\n", "\r"), array('', '', ''), $str);
 }
 
 function supe_dbconnect() {
 
 global $supe, $db;
 
 if(!$supe['status']) {
 return FALSE;
 } elseif(empty($supe['dbmode'])) {
 $supe['db'] = $db;
 } elseif(empty($supe['db'])) {
 $supe['db'] = new dbstuff;
 $supe['link'] = $supe['db']->connect($supe['dbhost'], $supe['dbuser'], $supe['dbpw'], $supe['dbname'], $supe['pconnect'], FALSE);
 $supe['status'] = $supe['link'] ? $supe['link'] : FALSE;
 }
 }
 
 
 function checkmd5($md5, $verified, $salt = '') {
 if(md5($md5.$salt) == $verified) {
 $result = !empty($salt) ? 1 : 2;
 } elseif(empty($salt)) {
 $result = $md5 == $verified ? 3 : ((strlen($verified) == 16 && substr($md5, 8, 16) == $verified) ? 4 : 0);
 } else {
 $result = 0;
 }
 return $result;
 }
 
 function dfopen($url, $limit = 500000, $post = '', $cookie = '', $bysocket = FALSE) {
 global $version, $boardurl;
 if(ini_get('allow_url_fopen') && !$bysocket && !$post) {
 $fp = @fopen($url, 'r');
 $s = @fread($fp, $limit);
 @fclose($fp);
 return $s;
 }
 $return = '';
 $matches = parse_url($url);
 $host = $matches['host'];
 $script = $matches['path'].'?'.$matches['query'].'#'.$matches['fragment'];
 $port = !empty($matches['port']) ? $matches['port'] : 80;
 if($post) {
 $out = "POST $script HTTP/1.1\r\n";
 $out .= "Accept: */*\r\n";
 $out .= "Referer: $boardurl\r\n";
 $out .= "Accept-Language: zh-cn\r\n";
 $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
 $out .= "Accept-Encoding: none\r\n";
 $out .= "User-Agent: Comsenz/1.0 ($version)\r\n";
 $out .= "Host: $host\r\n";
 $out .= 'Content-Length: '.strlen($post)."\r\n";
 $out .= "Connection: Close\r\n";
 $out .= "Cache-Control: no-cache\r\n";
 $out .= "Cookie: $cookie\r\n\r\n";
 $out .= $post;
 } else {
 $out = "GET $script HTTP/1.1\r\n";
 $out .= "Accept: */*\r\n";
 $out .= "Referer: $boardurl\r\n";
 $out .= "Accept-Language: zh-cn\r\n";
 $out .= "Accept-Encoding:\r\n";
 $out .= "User-Agent: Comsenz/1.0 ($version)\r\n";
 $out .= "Host: $host\r\n";
 $out .= "Connection: Close\r\n";
 $out .= "Cookie: $cookie\r\n\r\n";
 }
 $fp = fsockopen($host, $port, $errno, $errstr, 30);
 if(!$fp) {
 return "";
 } else {
 @fwrite($fp, $out);
 while(!feof($fp) && $limit > -1) {
 $limit -= 524;
 $return .= @fread($fp, 524);
 }
 @fclose($fp);
 $return = preg_replace("/\r\n\r\n/", "\n\n", $return, 1);
 $strpos = strpos($return, "\n\n");
 $strpos = $strpos !== FALSE ? $strpos + 2 : 0;
 $return = substr($return, $strpos);
 return $return;
 }
 }
 
 ?>
 |