发新话题
打印

Discuz!源代码分析-global.func.php

Discuz!源代码分析-global.func.php

./include/global.func.php
复制内容到剪贴板
代码:
if(!defined('IN_DISCUZ')) {
        exit('Access Denied');
}
//防非法引用的
复制内容到剪贴板
代码:
/**
* 这一个部分是生成discuz authcode的,用的是base64加密,分别能加密和解密。通过传入$operation = 'ENCODE'|'DECODE'来实现。
* @para string $string 要加/解密的string
* @para string $operation 方法(个人觉得用boolean比较好)
* @para string $key 用来加密的key
*
* @return string
*/

function authcode($string, $operation, $key = '') {

        $key = md5($key ? $key : $GLOBALS['discuz_auth_key']);
        $key_length = strlen($key);

        $string = $operation == 'DECODE' ? base64_decode($string) : substr(md5($string.$key), 0, 8).$string;
        $string_length = strlen($string);

        $rndkey = $box = array();
        $result = '';

        for($i = 0; $i <= 255; $i++) {
                $rndkey[$i] = ord($key[$i % $key_length]);
                $box[$i] = $i;
        }

        for($j = $i = 0; $i < 256; $i++) {
                $j = ($j + $box[$i] + $rndkey[$i]) % 256;
                $tmp = $box[$i];
                $box[$i] = $box[$j];
                $box[$j] = $tmp;
        }

        for($a = $j = $i = 0; $i < $string_length; $i++) {
                $a = ($a + 1) % 256;
                $j = ($j + $box[$a]) % 256;
                $tmp = $box[$a];
                $box[$a] = $box[$j];
                $box[$j] = $tmp;
                $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
        }

        if($operation == 'DECODE') {
                if(substr($result, 0, 8) == substr(md5(substr($result, 8).$key), 0, 8)) {
                        return substr($result, 8);
                } else {
                        return '';
                }
        } else {
                return str_replace('=', '', base64_encode($result));
        }

}
复制内容到剪贴板
代码:
/**
* 这个是用来清除所有的cookie的
*/

function clearcookies() {
        global $discuz_uid, $discuz_user, $discuz_pw, $discuz_secques, $adminid, $credits;
        dsetcookie('sid', '', -86400 * 365);
        dsetcookie('auth', '', -86400 * 365);
        dsetcookie('visitedfid', '', -86400 * 365);
        dsetcookie('onlinedetail', '', -86400 * 365, 0);

        $discuz_uid = $adminid = $credits = 0;
        $discuz_user = $discuz_pw = $discuz_secques = '';
}
复制内容到剪贴板
代码:
/**
* 用来检查积分的最低要求的
* @para array $creditsarray 传入积分数组
* @para int $coef 单位
*/

function checklowerlimit($creditsarray, $coef = 1) {
        if(is_array($creditsarray)) {
                global $extcredits, $id;
                foreach($creditsarray as $id => $addcredits) {
                        if($addcredits * $coef < 0 && $GLOBALS['extcredits'.$id] - $addcredits < $extcredits[$id]['lowerlimit']) {
                                showmessage('credits_policy_lowerlimit');
                        }
                }
        }
}
复制内容到剪贴板
代码:
/**
* 用来完美分词的,也就是把一段中文字只取前面一段,再加一个…
* @para string $string 用来分词的串
* @para int $length 保留的长度
* @para string $dot 最后加点什么
*
* @return string
*/

function cutstr($string, $length, $dot = ' ...') {
        global $charset;

        if(strlen($string) <= $length) {
                return $string;
        }

        $string = str_replace(array('&', '"', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string);

        $strcut = '';
        if(strtolower($charset) == 'utf-8') {

                $n = $tn = $noc = 0;
                while($n < strlen($string)) {

                        $t = ord($string[$n]);
                        if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
                                $tn = 1; $n++; $noc++;
                        } elseif(194 <= $t && $t <= 223) {
                                $tn = 2; $n += 2; $noc += 2;
                        } elseif(224 <= $t && $t < 239) {
                                $tn = 3; $n += 3; $noc += 2;
                        } elseif(240 <= $t && $t <= 247) {
                                $tn = 4; $n += 4; $noc += 2;
                        } elseif(248 <= $t && $t <= 251) {
                                $tn = 5; $n += 5; $noc += 2;
                        } elseif($t == 252 || $t == 253) {
                                $tn = 6; $n += 6; $noc += 2;
                        } else {
                                $n++;
                        }

                        if($noc >= $length) {
                                break;
                        }

                }
                if($noc > $length) {
                        $n -= $tn;
                }

                $strcut = substr($string, 0, $n);

        } else {
                for($i = 0; $i < $length - strlen($dot) - 1; $i++) {
                        $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
                }
        }

        $strcut = str_replace(array('&', '"', '<', '>'), array('&', '"', '&lt;', '&gt;'), $strcut);

        return $strcut.$dot;
}
复制内容到剪贴板
代码:
/**
* 用来过滤字串的,之所以要这样一个函数是考虑到是不是打开了magic_quotes_gpc.
* @para string $string 要过滤的字串
* @para int $force 强制过滤
*
* @return string
*/

function daddslashes($string, $force = 0) {
        !defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
        if(!MAGIC_QUOTES_GPC || $force) {
                if(is_array($string)) {
                        foreach($string as $key => $val) {
                                $string[$key] = daddslashes($val, $force);
                        }
                } else {
                        $string = addslashes($string);
                }
        }
        return $string;
}
复制内容到剪贴板
代码:
/**
* 检查一个日期是否合法
* @para string $ymd 日期字串
* @para string $sep 分隔符
*
* @return boolean
*/

function datecheck($ymd, $sep='-') {
        if(!empty($ymd)) {
                list($year, $month, $day) = explode($sep, $ymd);
                return checkdate($month, $day, $year);
        } else {
                return FALSE;
        }
}
复制内容到剪贴板
代码:
/**
* 用来计算程序运行时间的,论坛底部的debug info
*
* @return boolean
*/
function debuginfo() {
        if($GLOBALS['debug']) {
                global $db, $discuz_starttime, $debuginfo;
                $mtime = explode(' ', microtime());
                $debuginfo = array('time' => number_format(($mtime[1] + $mtime[0] - $discuz_starttime), 6), 'queries' => $db->querynum);
                return TRUE;
        } else {
                return FALSE;
        }
}
复制内容到剪贴板
代码:
/**
* 强制退出
* @para string $message
*
*/
function dexit($message = '') {
        echo $message;
        output();
        exit();
}
复制内容到剪贴板
代码:
/**        
* 过滤HTML代码的
* @para string $string
*
* @return string
*/
function dhtmlspecialchars($string) {
        if(is_array($string)) {
                foreach($string as $key => $val) {
                        $string[$key] = dhtmlspecialchars($val);
                }
        } else {
                $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1',
                str_replace(array('&', '"', '<', '>'), array('&', '"', '&lt;', '&gt;'), $string));
        }
        return $string;
}
复制内容到剪贴板
代码:
/**
* 用来设置header的
* @para string $string
* @para boolean $replace
* @para int $http_reponse_code
*
*/

function dheader($string, $replace = true, $http_response_code = 0) {
        $string = str_replace(array("\r", "\n"), array('', ''), $string);
        header($string, $replace, $http_response_code); //直接设置header
        if(preg_match('/^\s*location:/is', $string)) { //如果不符合location开头的话就exit了
                exit();
        }
}
复制内容到剪贴板
代码:
/**
* 判断是不是文件上传了
* @return boolean
*/

function disuploadedfile($file) {
        return function_exists('is_uploaded_file') && (is_uploaded_file($file) || is_uploaded_file(str_replace('\\\\', '\\', $file)));
}
复制内容到剪贴板
代码:
/**
* 用来得到上一个页面的地址,也就是来路。
* @para string $default 这个参数是直接设置一个refer,不用判断得到
*
* @return string
*/

function dreferer($default = '') {
        global $referer, $indexname;

        $default = empty($default) ? $indexname : '';
        if(empty($referer) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])) {
                $referer = preg_replace("/([\?&])((sid\=[a-z0-9]{6})(&|$))/i", '\\1', $GLOBALS['_SERVER']['HTTP_REFERER']);
                $referer = substr($referer, -1) == '?' ? substr($referer, 0, -1) : $referer;
        } else {
                $referer = dhtmlspecialchars($referer);
        }

        if(!preg_match("/(\.php|[a-z]+(\-\d+)+\.html)/", $referer) || strpos($referer, 'logging.php')) {
                $referer = $default;
        }
        return $referer;
}
复制内容到剪贴板
代码:
/**
* 设置cookie用的,我觉得这个和clearcookies放到一起比较好,不过好像这个是按字母排的…
* @para string $var cookie名
* @para string $value cookie值
* @para int $life 生存时间
* @para int $prefix cookie前缀
*
*/

function dsetcookie($var, $value, $life = 0, $prefix = 1) {
        global $cookiepre, $cookiedomain, $cookiepath, $timestamp, $_SERVER;
        //echo $prefix."--".$var."--".$value."--".$life."--".$cookiepath;
        
        setcookie(($prefix ? $cookiepre : '').$var, $value,
                $life ? $timestamp + $life : 0, $cookiepath,
                $cookiedomain, $_SERVER['SERVER_PORT'] == 443 ? 1 : 0);
}
复制内容到剪贴板
代码:
/**
* 删除论坛的附件用的
* @para string $filename 附件名
* @para int $havethumb 是否有缩略图
* @para int $remote 是否为远程附件
*
*/

function dunlink($filename, $havethumb = 0, $remote = 0) {
        global $authkey, $ftp, $attachdir;
        if($remote) {
                require_once DISCUZ_ROOT.'./include/ftp.func.php';
                if(!$ftp['connid']) {
                        if(!($ftp['connid'] = dftp_connect($ftp['host'], $ftp['username'], authcode($ftp['password'], 'DECODE', md5($authkey)), $ftp['attachdir'], $ftp['port'], $ftp['ssl']))) {
                                return;
                        }
                }
                dftp_delete($ftp['connid'], $filename);
                $havethumb && dftp_delete($ftp['connid'], $filename.'.thumb.jpg');
        } else {
                @unlink($attachdir.'/'.$filename);
                $havethumb && @unlink($attachdir.'/'.$filename.'.thumb.jpg');
        }
}
复制内容到剪贴板
代码:
/**
* 生成email连接用的,比如把[email]nicollelord@yahoo.com[/email]换成:<a href="mailto:nicollelord@yahoo.com">nicollelord@yahoo.com</a>这样的形式
* @para string $email
* @para int $tolink
*/

function emailconv($email, $tolink = 1) {
        $email = str_replace(array('@', '.'), array('&#64;', '&#46;'), $email);
        return $tolink ? '<a href="mailto: '.$email.'">'.$email.'</a>': $email;
}
复制内容到剪贴板
代码:
/**
* 记录错误日志用的
* @para string $type 错误类型
* @para string $message 错误内容
* @para int $halt 发生错误后是不是就马上停止论坛的运行
*
*/

function errorlog($type, $message, $halt = 1) {
        global $timestamp, $discuz_userss, $onlineip, $_SERVER;
        $user = empty($discuz_userss) ? '' : $discuz_userss.'<br>';
        $user .= $onlineip.'|'.$_SERVER['REMOTE_ADDR'];
        writelog('errorlog', dhtmlspecialchars("$timestamp\t$type\t$user\t".str_replace(array("\r", "\n"), array(' ', ' '), trim($message))));
        if($halt) {
                dexit();
        }
}
复制内容到剪贴板
代码:
/**
* 判断访问者是不是robot
*
* @return boolean
*/

function getrobot() {
        if(!defined('IS_ROBOT')) {
                $kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
                $kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';
                if(preg_match("/($kw_browsers)/", $_SERVER['HTTP_USER_AGENT'])) {
                        define('IS_ROBOT', FALSE);
                } elseif(preg_match("/($kw_spiders)/", $_SERVER['HTTP_USER_AGENT'])) {
                        define('IS_ROBOT', TRUE);
                } else {
                        define('IS_ROBOT', FALSE);
                }
        }
        return IS_ROBOT;
}
复制内容到剪贴板
代码:
/**
* 得到一个文件的扩展名
* @para string $filename
*
* @return string
*/

function fileext($filename) {
        return trim(substr(strrchr($filename, '.'), 1, 10));
}
复制内容到剪贴板
代码:
/**
* 用当前时间,会员名,uid,密码,authkey生成一个form hash(哈希)
*
* @return string
*/

function formhash() {
        global $discuz_user, $discuz_uid, $discuz_pw, $timestamp, $discuz_auth_key;
        return substr(md5(substr($timestamp, 0, -7).$discuz_user.$discuz_uid.$discuz_pw.$discuz_auth_key), 8, 8);
}
复制内容到剪贴板
代码:
/**
* 生成论坛访问权限的字串,以|隔开
* @para string $permstr 访问权限字串
*
* @return string
*/

function forumperm($permstr) {
        global $groupid, $extgroupids;

        $groupidarray = array($groupid);
        foreach(explode("\t", $extgroupids) as $extgroupid) {
                if($extgroupid = intval(trim($extgroupid))) {
                        $groupidarray[] = $extgroupid;
                }
        }
        return preg_match("/(^|\t)(".implode('|', $groupidarray).")(\t|$)/", $permstr);
}
复制内容到剪贴板
代码:
/**
* 得到用户组,同步groupid和member['groupid'],当会员积分和当前积分不一致更新members表。
* @para int $uid 会员的uid
* @para array $group 会员所属的用户组
* @para array $member
*
* @return string
*/

function getgroupid($uid, $group, &$member) {
        global $creditsformula, $db, $tablepre;

        if(!empty($creditsformula)) {
                $updatearray = array();
                eval("\$credits = round($creditsformula);");

                if($credits != $member['credits']) {
                        $updatearray[] = "credits='$credits'";
                }
                if($group['type'] == 'member' && !($member['credits'] >= $group['creditshigher'] && $member['credits'] < $group['creditslower'])) {
                        $query = $db->query("SELECT groupid FROM {$tablepre}usergroups WHERE type='member' AND $member[credits]>=creditshigher AND $member[credits]<creditslower LIMIT 1");
                        if($db->num_rows($query)) {
                                $member['groupid'] = $db->result($query, 0);
                                $updatearray[] = "groupid='$member[groupid]'";
                        }
                }

                if($updatearray) {
                        $db->query("UPDATE {$tablepre}members SET ".implode(', ', $updatearray)." WHERE uid='$uid'");
                }
        }

        return $member['groupid'];
}
复制内容到剪贴板
代码:
/**
* 这个的作用主要是把序列化后存在于数据库中的会员组到期信息取出来
* @para string $terms
* @para int $expiry
*/

function groupexpiry($terms) {
        $terms = is_array($terms) ? $terms : unserialize($terms);
        $groupexpiry = isset($terms['main']['time']) ? intval($terms['main']['time']) : 0;
        if(is_array($terms['ext'])) {
                foreach($terms['ext'] as $expiry) {
                        if((!$groupexpiry && $expiry) || $expiry < $groupexpiry) {
                                $groupexpiry = $expiry;
                        }
                }
        }
        return $groupexpiry;
}
复制内容到剪贴板
代码:
/**
* 看看一个ip是不是在允许访问的范围内
* @para string $ip
* @para array $accesslist
*
* @return boolean
*/

function ipaccess($ip, $accesslist) {
        return preg_match("/^(".str_replace(array("\r\n", ' '), array('|', ''), preg_quote($accesslist, '/')).")/", $ip);
}
复制内容到剪贴板
代码:
/**
* 判断ip是不是被ban了
* @para string $onlineip
*
* @return boolean
*/

function ipbanned($onlineip) {
        global $ipaccess, $timestamp, $cachelost;

        if($ipaccess && !ipaccess($onlineip, $ipaccess)) {
                return TRUE;
        }

        $cachelost .= (@include DISCUZ_ROOT.'./forumdata/cache/cache_ipbanned.php') ? '' : ' ipbanned';
        if(empty($_DCACHE['ipbanned'])) {
                return FALSE;
        } else {
                if($_DCACHE['ipbanned']['expiration'] < $timestamp) {
                        @unlink(DISCUZ_ROOT.'./forumdata/cache/cache_ipbanned.php');
                }
                return preg_match("/^(".$_DCACHE['ipbanned']['regexp'].")$/", $onlineip);
        }
}
复制内容到剪贴板
代码:
/**
* 检查一个email的合法性
* @para string $email
*
* @return boolean
*/

function isemail($email) {
        return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
}
复制内容到剪贴板
代码:
/**
* Discuz语言解析用到的东西,即按照需要装入语言包这个数组
* @para string $file 语言文件(如:templates, email, actions等)
* @para int $templateid 用的是哪套模板中的,若没有的话用TEMPLATEID这个常数取代
* @para string $tpldir 模板所在的目录
*
* @return array or false
*/

function language($file, $templateid = 0, $tpldir = '') {
        $tpldir = $tpldir ? $tpldir : TPLDIR;
        $templateid = $templateid ? $templateid : TEMPLATEID;

        $languagepack = DISCUZ_ROOT.'./'.$tpldir.'/'.$file.'.lang.php';
        if(file_exists($languagepack)) {
                return $languagepack;
        } elseif($templateid != 1 && $tpldir != './templates/default') {
                return language($file, 1, './templates/default');
        } else {
                return FALSE;
        }
}
复制内容到剪贴板
代码:
/**
* 超经典的分页函数来了
* @para int $num 记录总数
* @para int $perpage 每页的记录数
* @para int $curpage 当前页
* @para string $mpurl 这个是用来保留query string中的参数的,打个比方:forumdisplay.php?fid=2,这个就是mpurl了,处理后会变成forumdisplay.php?fid=2&page=xx
* @para int $maxpages 最大的页数
* @para int $page 总页数
* @para int $simple 好像simple如果比一大的话就只有第一页,上一页,下一页,最后页
* @para string $onclick 点击触发的事件,AJAX用的。
*
* @return string
*/

function multi($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $simple = 0, $onclick = '') {
        $multipage = '';
        $mpurl .= strpos($mpurl, '?') ? '&' : '?';
        $onclick = $onclick ? ' onclick="'.$onclick.'(event)"' : '';
        if($num > $perpage) {
                $offset = 2;

                $realpages = @ceil($num / $perpage);
                $pages = $maxpages && $maxpages < $realpages ? $maxpages : $realpages;

                if($page > $pages) {
                        $from = 1;
                        $to = $pages;
                } else {
                        $from = $curpage - $offset;
                        $to = $from + $page - 1;
                        if($from < 1) {
                                $to = $curpage + 1 - $from;
                                $from = 1;
                                if($to - $from < $page) {
                                        $to = $page;
                                }
                        } elseif($to > $pages) {
                                $from = $pages - $page + 1;
                                $to = $pages;
                        }
                }

                $multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.$mpurl.'page=1" class="p_redirect"'.$onclick.'>|&#8249;</a>' : '').
                        ($curpage > 1 && !$simple ? '<a href="'.$mpurl.'page='.($curpage - 1).'" class="p_redirect">&#8249;&#8249;</a>' : '');
                for($i = $from; $i <= $to; $i++) {
                        $multipage .= $i == $curpage ? '<a class="p_curpage">'.$i.'</a>' :
                                '<a href="'.$mpurl.'page='.$i.'" class="p_num"'.$onclick.'>'.$i.'</a>';
                }

                $multipage .= ($curpage < $pages && !$simple ? '<a href="'.$mpurl.'page='.($curpage + 1).'" class="p_redirect"'.$onclick.'>&#8250;&#8250;</a>' : '').
                        ($to < $pages ? '<a href="'.$mpurl.'page='.$pages.'" class="p_redirect"'.$onclick.'>&#8250;|</a>' : '').
                        ($curpage == $maxpages ? '<a class="p_redirect" href="misc.php?action=maxpages&pages='.$maxpages.'">&#8250;?</a>' : '').
                        (!$simple && $pages > $page ? '<a class="p_pages" style="padding: 0px"><input class="p_input" type="text" name="custompage" onKeyDown="if(event.keyCode==13) {window.location=\''.$mpurl.'page=\'+this.value; return false;}"></a>' : '');

                $multipage = $multipage ? '<div class="p_bar">'.(!$simple ? '<a class="p_total">&nbsp;'.$num.'&nbsp;</a><a class="p_pages">&nbsp;'.$curpage.'/'.$realpages.'&nbsp;</a>' : '').$multipage.'</div>' : '';
        }
        return $multipage;
}
空间出租:P4 3.0+1G+RIAD 1 160G+PHP+IIS+MYSQL+MDaemon

QQ:126682182
Email:hhyisw@163.com
Home:http://www.stksky.com

TOP

复制内容到剪贴板
代码:
/**
* 输出用的,这个时候可以做一点事情,比如说:把sid用正则写到form里面,rewrite规则启用后把论坛里面的forumdisplay.php?fid=1&page=2用正则换成forum-1-2.html。
* 并把ftp连接关掉,写入cache
*/

function output() {
        global $sid, $transsidstatus, $rewritestatus, $ftp;

        if(($transsidstatus = empty($GLOBALS['_DCOOKIE']['sid']) && $transsidstatus) || in_array($rewritestatus, array(2, 3))) {
                if($transsidstatus) {
                        $searcharray = array
                                (
                                "/\<a(\s*[^\>]+\s*)href\=([\"|\']?)([^\"\'\s]+)/ies",
                                "/(\<form.+?\>)/is"
                                );
                        $replacearray = array
                                (
                                "transsid('\\3','<a\\1href=\\2')",
                                "\\1\n<input type=\"hidden\" name=\"sid\" value=\"$sid\">"
                                );
                } else {
                        $searcharray = array
                                (
                                //"/\<a href\=\"index\.php\"\>/",
                                "/\<a href\=\"forumdisplay\.php\?fid\=(\d+)(&page\=(\d+))?\"([^\>]*)\>/e",
                                "/\<a href\=\"viewthread\.php\?tid\=(\d+)(&extra\=page\%3D(\d+))?(&page\=(\d+))?\"([^\>]*)\>/e",
                                "/\<a href\=\"viewpro\.php\?(uid\=(\d+)|username\=([^&]+?))\"([^\>]*)\>/e",
                                "/\<a href\=\"space\.php\?(uid\=(\d+)|username\=([^&]+?))\"([^\>]*)\>/e"
                                );
                        $replacearray = array
                                (
                                //"<a href=\"index.html\">",
                                "rewrite_forum('\\1', '\\3', '\\4')",
                                "rewrite_thread('\\1', '\\5', '\\3', '\\6')",
                                "rewrite_profile('\\2', '\\3', '\\4')",
                                "rewrite_space('\\2', '\\3', '\\4')"
                                );
                }

                $content = preg_replace($searcharray, $replacearray, ob_get_contents());
                ob_end_clean();
                $GLOBALS['gzipcompress'] ? ob_start('ob_gzhandler') : ob_start();

                echo $content;
        }
        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) {
                        $fp = fopen(CACHE_FILE, 'w');
                        if($fp) {
                                flock($fp, LOCK_EX);
                                fwrite($fp, empty($content) ? ob_get_contents() : $content);
                        }
                        @fclose($fp);
                }
        }
}
复制内容到剪贴板
代码:
/**这一段都是rewrite规则,和上一个函数相映成趣~
* @para int $tid 帖子的id
* @para int $page 页数
* @para int $prevpage 上一页
* @para string $extra 附加的东东
*
* @return string 返回一个链接,如: <a href = "thread-1-1.html">
*/

function rewrite_thread($tid, $page = 0, $prevpage = 0, $extra = '') {
        return '<a href="thread-'.$tid.'-'.($page ? $page : 1).'-'.($prevpage ? $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_profile($uid, $username, $extra = '') {
        return '<a href="profile-'.($uid ? 'uid-'.$uid : 'username-'.$username).'.html"'.stripslashes($extra).'>';
}

function rewrite_space($uid, $username, $extra = '') {
        return '<a href="space-'.($uid ? 'uid-'.$uid : 'username-'.$username).'.html"'.stripslashes($extra).'>';
}
复制内容到剪贴板
代码:
/**
* 访问时段检查
* @para string $periods 允许访问的时段
* @para string showmessage 如果不允许访问的时段会员访问了的话出现的自定义提示
*
* @return TRUE or no return
*/

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)) || ($oeriodbegin < $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;
}
复制内容到剪贴板
代码:
/**
* 加密安全提问的,MD5加密
* @para int $qestionid
* @para string $anser
*
* @return string 返回加密后的字串
*/

function quescrypt($questionid, $answer) {
        return $questionid > 0 && $answer != '' ? substr(md5($answer.md5($questionid)), 16, 8) : '';
}
复制内容到剪贴板
代码:
/**
* 生成随机数(这里返回$hash名字有点点不合适,hash是包含key和value的,这里没有这样的意思)
* @para int $length 要生成的长度
* @para int $numeric 传入一个非零的数表示要生成的全是数字
*
* @return string 返回生成的字串
*/

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;
}
复制内容到剪贴板
代码:
/**
* 删除目录和文件用的
* @para string $dirname 要删除的目录名
* @para boolean $keepdir 是否在删除文件后保留目录,也就是只清空目录
*
* @return boolean
*/

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;
}
复制内容到剪贴板
代码:
/**
* 发信件用的,用到了include目录下的sendmail.inc.php
* @para string $email_to
* @para string $email_subject
* @para string $email_message
* @para string $email_from

*/

function sendmail($email_to, $email_subject, $email_message, $email_from = '') {
        extract($GLOBALS, EXTR_SKIP);
        require DISCUZ_ROOT.'./include/sendmail.inc.php';
}
复制内容到剪贴板
代码:
/**
* 发送PM的函数
* @para int $toid 对方id
* @para string $subject PM主题
* @para int $fromid 发送方id
* @para string $from 发送方用户名

*/

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)");
        }
}
复制内容到剪贴板
代码:
/**
* 大家熟悉的showmesage终于出现~!包含了ajax效果了
* @para string $message 显示在跳转页面的信息,比如:您已成功登陆……
* @para string $url_forword 下一个url,过三秒会自动跳转过去
* @para string $extra 这个用来控制一些特殊的显示,比如:HALTED, NOPERM,这样可以控制一些特殊场合,Discuz想得真是太全面了~!
*/

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, $_DCACHE;
        $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($_GET['inajax']) && $msgforward['quick'] && $msgforward['messages'] && @in_array($message, $msgforward['messages'])) {
                updatesession();
                dheader("location: ".str_replace('&amp;', '&', $url_forward));
        }

        if(in_array($extra, array('HALTED', 'NOPERM'))) {
                $fid = $tid = 0;
                $discuz_action = 254;
        } else {
                $discuz_action = 255;
        }

        include language('messages'); //把message这个语言包加了进来

        if(isset($language[$message])) {
                $supe_pre = $supe_fromsupesite ? 'supe_' : '';
                eval("\$show_message = \"".($language[$supe_pre.$message] ? $language[$supe_pre.$message] : $language[$message])."\";");
                unset($supe_pre);
        }

        ajaxtemplate('showmessage_ajax');

        $extrahead .= $url_forward ? '<meta http-equiv="refresh" content="'.$msgforward['refreshtime'].' url='.$url_forward.'">' : '';

        if($advlist = $advlist['redirect']) {
                foreach($advlist AS $type => $redirectadvs) {
                        $advlist[$type] = $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();
}
复制内容到剪贴板
代码:
/**
* 用来计算星星月亮太阳显示的
* @para $num 等级数
*
*/

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.' />';
                        }
                }
        }
}
复制内容到剪贴板
代码:
/**
* 得到站点
*
* @return string 如: [url]http://discuz.net[/url]
*/

function site() {
        return $_SERVER['HTTP_HOST'];
}
复制内容到剪贴板
代码:
/**
* 这个看成函数重载也无妨,功能就是查找$haystack是不是在$needle中存在
* @para string $haystack
* @para string $needle
*
* @return boolean
*/

function strexists($haystack, $needle) {
        return !(strpos($haystack, $needle) === FALSE);
}
复制内容到剪贴板
代码:
/**
* 验证码转换,具体功能用处还没研究
* @para string $seccode 验证码
*
*/

function seccodeconvert(&$seccode) {
        $seccode = substr($seccode, -6);
        $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];
        }
}
复制内容到剪贴板
代码:
/**
* 提交后的检查,主要是检查验证码,安全提问和来路是不是正常。
* @para string $var 存放在全局变量中的下标
* @para int $allowget 是不是允许get提交
* @para int $seccodecheck 验证码检查
* @para int $secqaacheck 安全提问检查
*
* @return boolean
*/

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');
                }
        }
}
复制内容到剪贴板
代码:
/**
* 另一个提交检查,检查super site的提交的
* @para int $allowget 是不是允许get提交
* @para int $timespan 时间跨度
*
* @return boolean
*/
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;
}
复制内容到剪贴板
代码:
/**
* 另外一个重大函数来了,那就是模板解析,绝对Discuz核心
* @para string $file 模板文件(如:discuz, forumdata, viewthread等)
* @para int $templateid 用的是哪套模板中的,若没有的话用TEMPLATEID这个常数取代
* @para string $tpldir 模板所在的目录
*
* @return string 解析好的模板文件,通过include template('xxx')这样引用到文件,framework的MVC也是这样一个模式的
*/
function template($file, $templateid = 0, $tpldir = '') {
        global $tplrefresh;

        $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;
}
复制内容到剪贴板
代码:
/**
* 得到url中的sid
* @para string $url
* @para string tag
* @para int $wml
*
* @return string
*/
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 ? '&amp;' : '&') : '?').'sid='.$sid.$urlret;
        }
        return $tag.$url;
}
复制内容到剪贴板
代码:
/**
* 生成主题分类下拉列表
* @para int $curtypeid 当前选择的id
*
* @return string
*/
function typeselect($curtypeid = 0) {
        if($threadtypes = $GLOBALS['forum']['threadtypes']) {
                $html = '<select name="typeid"><option value="0">&nbsp;</option>';
                foreach($threadtypes['types'] as $typeid => $name) {
                        $html .= '<option value="'.$typeid.'" '.($curtypeid == $typeid ? 'selected' : '').'>'.strip_tags($name).'</option>';
                }
                $html .= '</select>';
                return $html;
        } else {
                return '';
        }
}
复制内容到剪贴板
代码:
/**
* 更新积分用到的函数
* @para string $uids 要更新的uid
* @para array $creditsarray 要更新的积分
* @para int $coef 单位
* @para string $extrasql 附加的sql语句
*
*/
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');
                }
        }
}
复制内容到剪贴板
代码:
/**
* 把session更新一下,更新了如下的表:onlinetime, members, sessions
*/
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;
}
空间出租:P4 3.0+1G+RIAD 1 160G+PHP+IIS+MYSQL+MDaemon

QQ:126682182
Email:hhyisw@163.com
Home:http://www.stksky.com

TOP

复制内容到剪贴板
代码:
/**
* 更新版主工作统计的
* @para string $modaction 进行的何种操作(高亮,关闭,提升…)
* @para int $posts 一次进行了的个数
*
*/
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')");
                }
        }
}
复制内容到剪贴板
代码:
/**
* 写入系统日志
* @para string $file 写入的日志文件
* @para string $log 要写入的内容提要
*
*/
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);
        }
}
复制内容到剪贴板
代码:
/**
* 看成函数的重载,即把implode这个函数重载成在两边加上'(单引号)的函数
* @para array $array
*
* @return string
*/
function implodeids($array) {
        if(!empty($array)) {
                return "'".implode("','", is_array($array) ? $array : array($array))."'";
        } else {
                return '';
        }
}
复制内容到剪贴板
代码:
/**
* 把这三个函数放一起,因为它们三个是一起实现的,即传说中的ajax…
* 这里说一下ajax的实现方式,一种方法是用XMLHttpRequest异步提交给服务器,服务器返回一个带有数据结点的xml文件
* javascript或者php等解析这个xml文档,从而得到数据;另外一种是这个xml文件中含一个CDATA,把已经用HTML格式化好的
* 内容返回过来直接用,显然第二种好用,Discuz用的就是这样一个方式。其他用iframe等等就不在这里介绍了,那个一般
* 在提交数据检查、异步文件上传的时候用。
*/
//ajaxshowheader生成一个xml头和一个<root>根以及一个CDATA
function ajaxshowheader() {
        global $charset;
        @header("Expires: -1");
        @header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
        @header("Pragma: no-cache");
        header("Content-type: application/xml");
        echo "<?xml version=\"1.0\" encoding=\"$charset\"?>\n<root><![CDATA[";
}

//闭合CDATA和root
function ajaxshowfooter() {
        echo ']]></root>';
}

//ajaxtemplate组合了ajaxshowheader + 模板 + ajaxshowfooter,使之完整。
function ajaxtemplate($tplname) {
        if(!empty($_GET['inajax'])) {
                extract($GLOBALS);
                updatesession();
                ajaxshowheader();
                include template($tplname);
                ajaxshowfooter();
                die();
        }
}
复制内容到剪贴板
代码:
/**
* 过滤.., \n, \r 用的
* @para string $str 要过滤的string
*
* @return string
*/
function wipespecial($str) {
        return str_replace(array('..', "\n", "\r"), array('', '', ''), $str);
}
复制内容到剪贴板
代码:
/**
* supser site 数据库连接
* 通过$super['db']来用,而Discuz本身的是$db
*/
function supe_dbconnect() {
        global $supe, $db;
        if(empty($supe['dbmode'])) {
                $supe['db'] = $db;
        } elseif(empty($supe['db'])) {
                $supe['db'] = new dbstuff;
                $supe['db']->connect($supe['dbhost'], $supe['dbuser'], $supe['dbpw'], $supe['dbname'], $supe['pconnect']);
        }
}
空间出租:P4 3.0+1G+RIAD 1 160G+PHP+IIS+MYSQL+MDaemon

QQ:126682182
Email:hhyisw@163.com
Home:http://www.stksky.com

TOP

发新话题