Discuz!源代碼分析系列:./include/global.func.php(5)

轉自www.discuz.net 做者:郭鑫 /** * 更新版主工做統計的 * @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']);         } }
相關文章
相關標籤/搜索