$value) { addS($array[$key]); } } elseif (is_string($array)) { $array = addslashes($array); } } function stripS(&$array) { if (is_array($array)) { foreach ($array as $key => $value) { stripS($array[$key]); } } elseif (is_string($array)) { $array = stripslashes($array); } } function reS(&$array) { if (is_array($array)) { foreach ($array as $key => $value) { reS($array[$key]); } } elseif (is_string($array)) { $array = addslashes(stripslashes($array)); } } function gdate($time = '', $format = '') { global $pb_timezone,$pb_timeformat,$pb_dateformat; !$time && $time = time(); if (!$format) { //24 OR 12 time format $hour = $pb_timeformat ? 'H:i' : 'h:i A'; $format = $pb_dateformat . ' ' . $hour; } return gmdate($format, ($time + $pb_timezone * 3600)); } function loadPluginLang($mark, $cp = FALSE) { global $pb_lang; $plugin_message = ''; $filename = $mark; if ($cp) $filename .= '_cp'; $langPath = PBDIGG_ROOT.'plugins/'.$mark.'/languages/'.$pb_lang.'/'.$filename.'.lang.php'; if (!file_exists($langPath)) { $langPath = PBDIGG_ROOT.'plugins/'.$mark.'/languages/zh/'.$filename.'.lang.php'; if (!file_exists($langPath)) { exit('Load Language File Failed!'); } } require $langPath; return $plugin_message; } function &loadLang($type) { global $pb_lang; static $lang = array(); if (isset($lang[$type])) return $lang[$type]; $langPath = PBDIGG_ROOT.'languages/'.$pb_lang.'/'.$type.'.lang.php'; if (!file_exists($langPath)) { $langPath = PBDIGG_ROOT.'languages/zh/'.$type.'.lang.php'; if (!file_exists($langPath)) { exit('Load Language File Failed!'); } } require $langPath; $lang[$type] = ${$type.'_message'}; return $lang[$type]; } function getSingleLang($type, $key) { $lang = &loadLang($type); $SingleLang = isset($lang[$key]) ? $lang[$key] : ''; unset($lang); return $SingleLang; } function gCookie($var) { global $pb_ckpre; $ckpre = $pb_ckpre ? substr(md5($pb_ckpre), 8, 6).'_' : ''; return isset($_COOKIE[$ckpre.$var]) ? $_COOKIE[$ckpre.$var] : ''; } /** * 设置COOKIE信息 * * @param $name cookie名称 * @param $value cookie值 * @param $expire 过期时间:-1:删除,0:即时,1:永久 * @return Boolean 设置cookie是否成功 */ function sCookie($name, $value, $expire = 0, $httponly = true) { global $pb_ckpath, $pb_ckdomain, $pb_ckpre, $timestamp; switch ($expire) { case 0: $expire = 0; break; case 1: $expire = $timestamp + 31536000; break; case -1: $expire = $timestamp - 31536000; break; default: $expire += $timestamp; break; } !$pb_ckpath && $pb_ckpath = '/'; $secure = ($_SERVER['SERVER_PORT'] == '443') ? 1 : 0; $ckpre = $pb_ckpre ? substr(md5($pb_ckpre), 8, 6).'_' : ''; if (PHP_VERSION >= '5.2.0') { return setcookie($ckpre.$name, $value, $expire, $pb_ckpath, $pb_ckdomain, $secure, ($httponly ? 1 : 0)); } else { return setcookie($ckpre.$name, $value, $expire, $pb_ckpath, $pb_ckdomain, $secure); } } /** * 清除cookies */ function clearcookie() { sCookie('pb_sid', '', -1); sCookie('pb_auth', '', -1); sCookie('pb_lastvisit', '', -1); sCookie('pb_tdigged', '', -1); sCookie('pb_tburied', '', -1); sCookie('pb_rdigged', '', -1); sCookie('pb_rburied', '', -1); } function getIP() { $isagent = TRUE; if (isset ($_SERVER['HTTP_X_FORWARDED_FOR'])) { $currentIP = $_SERVER['HTTP_X_FORWARDED_FOR']; } elseif (isset ($_SERVER['HTTP_CLIENT_IP'])) { $currentIP = $_SERVER['HTTP_CLIENT_IP']; } else { $currentIP = $_SERVER['REMOTE_ADDR']; $isagent = FALSE; } return array((preg_match('~[\d\.]{7,15}~', $currentIP, $match) ? $match[0] : 'unknow'), $isagent); } function redirect($msg, $url, $time = 2) { showMsg($msg, $url, $time * 1000, 1); } /* function showMsg($msg, $url = '', $time = 0, $redirect = 0) { @extract($GLOBALS, EXTR_SKIP); define('MSG', TRUE); ob_end_clean(); obStart(); if (defined('IN_ADMIN')) { $admin_msg = loadLang('admin') + loadLang('common'); if (defined('IN_PLUGIN')) $admin_msg += loadPluginLang(IN_PLUGIN, TRUE); if (defined('IN_MODULE')) $admin_msg += loadLang(IN_MODULE); isset($admin_msg[$msg]) && eval("\$msg = \"".addcslashes($admin_msg[$msg], '"')."\";"); } else { isset($common_message[$msg]) && eval("\$msg = \"".addcslashes($common_message[$msg], '"')."\";"); $pb_seotitle = strip_tags($msg); } if (PB_PAGE == 'ajax') return $msg; require_once pt_fetch('msg'); PBOutPut(); } */ function showMsg($msg, $url = '', $time = 0, $redirect = 0) { @extract($GLOBALS, EXTR_SKIP); define('MSG', TRUE); if (defined('IN_ADMIN')) { $admin_msg = loadLang('admin') + loadLang('common'); if (defined('IN_PLUGIN')) $admin_msg += loadPluginLang(IN_PLUGIN, TRUE); if (defined('IN_MODULE')) $admin_msg += loadLang(IN_MODULE); isset($admin_msg[$msg]) && eval("\$msg = \"".addcslashes($admin_msg[$msg], '"')."\";"); } else { isset($common_message[$msg]) && eval("\$msg = \"".addcslashes($common_message[$msg], '"')."\";"); $pb_seotitle = strip_tags($msg); } echo('[err]'.$msg.'[/err]'); exit; } function PEncode($txt, $key) { srand((double)microtime() * 1000000); $encrypt_key = md5(rand(0, 32000)); $ctr = 0; $tmp = ''; for($i = 0;$i < strlen($txt); $i++) { $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]); } return base64_encode(PKey($tmp, $key)); } function PDecode($txt, $key) { $txt = PKey(base64_decode($txt), $key); $tmp = ''; for ($i = 0;$i < strlen($txt); $i++) { $md5 = $txt[$i]; $tmp .= $txt[++$i] ^ $md5; } return $tmp; } function PKey($txt, $encrypt_key) { $encrypt_key = md5($encrypt_key); $ctr = 0; $tmp = ''; for($i = 0; $i < strlen($txt); $i++) { $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; $tmp .= $txt[$i] ^ $encrypt_key[$ctr++]; } return $tmp; } function spendTime() { global $loadTime; $mtime = explode(' ', microtime()); return number_format(($mtime[1] + $mtime[0] - $loadTime), 6); } function writeSafeContent($filename, $content, $mod) { PWriteFile($filename, "", $mod); } function PWriteFile($filename, $content, $mode = 'ab', $chmod = 1) { strpos($filename, '..') !== FALSE && exit('Access Denied!'); $fp = @fopen($filename, $mode); if ($fp) { flock($fp, LOCK_EX); fwrite($fp, $content); fclose($fp); $chmod && @chmod($filename, 0666); return TRUE; } return FALSE; } function PReadFile($filename, $mode = 'rb') { strpos($filename, '..') !== FALSE && exit('Access Denied!'); if ($fp = @ fopen($filename, $mode)) { flock($fp, LOCK_SH); $filedata = @ fread($fp, filesize($filename)); fclose($fp); } return $filedata; } function PCopy($source, $dest) { return @copy($source, $dest) || PWriteFile($dest, PReadFile($source), 'wb'); } function PMove($source, $dest) { if (@copy($source, $dest) || PWriteFile($dest, PReadFile($source), 'wb')) { PDel($source); return true; } } function PDel($var) { return strpos($var, '..') === FALSE && is_file($var) && @unlink($var) ? TRUE : FALSE; } function PDelDir($var) { return strpos($var, '..') === FALSE && is_dir($var) && @rmdir($var) ? TRUE : FALSE; } function emptyDir($dir) { $newdir = ''; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== FALSE) { if ($file != '..' && $file != '.') { $newdir = $dir.'/'.$file; if (is_dir($newdir)) { emptyDir($newdir, FALSE); } else { @unlink($dir.'/'.$file); } } } closedir($dh); } @rmdir($dir); } } function PListFile($var, $type = array()) { if (is_dir($var)) { $rs = @opendir($var); while (($file = readdir($rs)) !== FALSE) { if ($file != '..' && $file != '.') { if ($type && in_array(Fext($file), $type)) $rt[] = $file; } } return $rt; } return FALSE; } function Pmkdir($var, $basedir, $force = FALSE) { if (strpos($var, '..') !== FALSE || strpos($basedir, '..') !== FALSE) { exit('Access Denied!'); } if (!is_dir($basedir.$var)) { $var = preg_replace('/\/{2,}/', '/', str_replace('\\', '/', $var)); $basedir = preg_replace('/\/{2,}/', '/', str_replace('\\', '/', $basedir)); $temp = explode('/',$var); $dirnum = count($temp); $cur_dir = $basedir.'/'; for($i = 0; $i < $dirnum; $i++) { $cur_dir .= $temp[$i].'/'; if (!is_dir($cur_dir)) { if (!mkdir($cur_dir, 0777) && $force) { showMsg('attachment_mkdir_failed'); } } } } return TRUE; } function random($length, $isNum = FALSE) { $random = ''; $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $num = '0123456789'; if ($isNum) { $sequece = 'num'; } else { $sequece = 'str'; } $max = strlen($$sequece) - 1; for ($i = 0; $i < $length; $i++) { $random .= ${$sequece}{mt_rand(0, $max)}; } return $random; } function getUserHash($uid) { return substr(md5(intval($uid).$GLOBALS['pb_sitehash'].ipFragment($GLOBALS['_PBENV']['PB_IP'])), 8, 8); } function HConvert($var) { if (is_array($var)) { foreach ($var as $key => $value) { $var[$key] = HConvert($value); } } else { do { $clean = $var; $var = preg_replace('~&(?!(#[0-9]+|[a-z]+);)~is', '&', $var); $var = preg_replace(array('~%0[0-8]~','~%1[124-9]~','~%2[0-9]~','~%3[0-1]~','~[\x00-\x08\x0b\x0c\x0e-\x1f]~'), '', $var); } while ($clean != $var); $var = str_replace(array('"', '\'', '<', '>', "\t", "\r"), array('"', ''', '<', '>', '  ', ''), $var); } return $var; } /** * HTML危险代码过滤 * * @param String $string 过滤字符 */ function safeConvert(&$string) { require_once PBDIGG_ROOT.'include/safehtml.class.php'; $safehtml = & new HTML_Safe(); $string = $safehtml->parse($string); } /** * 字符截取函数 * * @param String $text 内容 * @param Integer $limit 截取长度 * @param String $add 更多标记 */ function PBSubstr($text, $limit, $add = '…') { global $db_charset; $strlen = strlen($text); $db_charset = strtolower($db_charset); if($strlen <= $limit) return $text; // $text = str_replace(array(' ', '"', '''), array(' ', '"', "'"), $text); $rtext = ''; if ($db_charset == 'utf-8') { $n = $tn = $noc = 0; while ($n < $strlen) { $t = ord($text{$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 >= $limit) break; } if($noc > $limit) $n -= $tn; $rtext = substr($text, 0, $n); } else { $addlen = strlen($add); $limit -= $addlen - 1; for ($i = 0; $i < $limit; $i++) { $rtext .= ord($text[$i]) > 127 ? $text[$i] . $text[++$i] : $text[$i]; } } // $rtext = str_replace(array('"', "'"), array('"', '''), $rtext); return $rtext.$add; } /** * Convert character encoding * * @param String $from_encoding 原始编码 * @param String $to_encoding 目标编码 * @param String $str 编码字符串 */ function convert_encoding($from_encoding, $to_encoding, $str) { if(empty($str) || (strtolower($from_encoding) == strtolower($to_encoding))) return $str; // $from_encoding = str_replace('gbk', 'gb2312', $from_encoding); // $to_encoding = str_replace('gbk', 'gb2312', $to_encoding); if(function_exists('mb_convert_encoding')) { return mb_convert_encoding($str, $to_encoding, $from_encoding); } elseif (function_exists('iconv')) { return iconv($from_encoding, $to_encoding.'//IGNORE', $str); } else { global $CHS; if (!is_object($CHS)) { require_once PBDIGG_ROOT.'include/Chinese.class.php'; $CHS = new Chinese($from_encoding, $to_encoding); } return $CHS->Convert($str); } } function ipControl($ip) { global $pb_ipallow, $pb_ipdeny; $ipExist = FALSE; if ($pb_ipallow) { $allowip = explode("\n", unserialize($pb_ipallow)); foreach ($allowip as $value) { if (preg_match("~^{$value}[\d\.]*~i", $ip)) { $ipExist = TRUE; break; } } if (!$ipExist) { showMsg('ip_limit'); } } if ($pb_ipdeny) { $ipdeny = explode("\n", unserialize($pb_ipdeny)); foreach ($ipdeny as $value) { preg_match("~^{$value}[\d\.]*~i", $ip) && showMsg('ip_limit'); } } } function parCate($cate, &$parCate, $cid = 0) { if (!$cate[$cid]['cup']) return; foreach ($cate as $key => $value) { if ($value['cid'] == $cate[$cid]['cup']) { $parCate[] = $value['cid']; parCate($cate, $parCate, $value['cid']); } } } function subCate($cate, &$subCate, $cid = 0) { foreach ($cate as $key => $value) { if ($value['cup'] == $cid) { $subCate[] = $value['cid']; subCate($cate, $subCate, $value['cid']); } } } function str_parcate($cate, &$str_parcate, $startID = 0) { if (!$cate[$startID]['cup']) return; foreach ($cate as $key => $value) { if ($value['cid'] == $cate[$startID]['cup']) { $str_parcate .= $value['cid'].','; str_parcate($cate, $str_parcate, $value['cid']); } } } function str_subcate($cate, &$str_subcate, $startID = 0) { foreach ($cate as $key => $value) { if ($value['cup'] == $startID) { $str_subcate .= $value['cid'].','; str_subcate($cate, $str_subcate, $value['cid']); } } } function cateOption($cate, &$option, $startID = 0, $index = 0, $level = 0) { foreach ($cate as $key => $value) { if ($value['cup'] == $startID) { $option .= '