这个是第二部分。
第一部分:http://www.discuz.net/viewthread.php?tid=612193
第二部分:http://www.discuz.net/viewthread.php?tid=612195
第三部分:http://www.discuz.net/viewthread.php?tid=612197
申明下版权:
1.这里面的每个中文字都是我打的,code部分是引用的,当然我也加了一点注释在里面了。
2.如果要转载的话请注明- 转自[url]www.discuz.net[/url] 作者:郭鑫
复制代码
3.由于我个人的能力有限,写这篇文章没有参考一点资料,甚至连本地环境也没有搭建(遇到了白屏问题),所以难免会有错误的地方,大家发现了的话请跟帖或者联系我吧,我会尽快更正。
- /**
- * 输出用的,这个时候可以做一点事情,比如说:把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
- (
- "/]+s*)href=(["|']?)([^"'s]+)/ies",
- "/()/is"
- );
- $replacearray = array
- (
- "transsid('3','
- "1n"
- );
- } else {
- $searcharray = array
- (
- //"//",
- "/]*)>/e",
- "/]*)>/e",
- "/]*)>/e",
- "/]*)>/e"
- );
- $replacearray = array
- (
- //"",
- "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 返回一个链接,如:
- */
- function rewrite_thread($tid, $page = 0, $prevpage = 0, $extra = '') {
- return '';
- }
- function rewrite_forum($fid, $page = 0, $extra = '') {
- return '';
- }
- function rewrite_profile($uid, $username, $extra = '') {
- return '';
- }
- function rewrite_space($uid, $username, $extra = '') {
- return '';
- }
复制代码
- /**
- * 访问时段检查
- * @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("rn", 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("rn", ', ', $_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)");
- }
- }
复制代码
[ 本帖最后由 郭鑫 于 2007-5-4 01:24 编辑 ] |