Discuz学习笔记(一)

include/common.inc.php

//变量化所有的全局变量

foreach(array('_COOKIE', '_POST', '_GET') as $_request) {
 foreach($$_request as $_key => $_value) {
  $_key{0} != '_' && $$_key = daddslashes($_value);
 }
}

 

include/global.func.php

//转义字符

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;
}

//用法

if (!MAGIC_QUOTES_GPC && $_FILES) {
 $_FILES = daddslashes($_FILES);
}

 

include/cpanel.share.php

//切分数组参数 $skip 为跳过的item

function implodearray($array, $skip = array()) {
 $return = '';
 if(is_array($array) && !empty($array)) {
  foreach ($array as $key => $value) {
   if(empty($skip) || !in_array($key, $skip)) {
    if(is_array($value)) {
     $return .= "$key={".implodearray($value, $skip)."}; ";
    } else {
     $return .= "$key=$value; ";
    }
   }
  }
 }
 return $return;
}

 

//用法

$extralog = implodearray(array('GET' => $_GET, 'POST' => $_POST), array('formhash', 'submit', 'addsubmit', 'admin_password', 'sid', 'action'));

 

//写日志方法

参数 $cplog 文件名 | $str 日志内容

writelog('cplog', implode("\t", clearlogstring(array($timestamp,$discuz_userss,$adminid,$onlineip,$action,$extralog))));

你可能感兴趣的:(discuz)