$val) { $string[$key] = daddslashes($val); } } else { $string = $trim ? trim(addslashes($string)) : addslashes($string); } return $string; } function cutstr($string, $length, $dot = '') { global $discuz_charset; if(strlen($string) <= $length) { return $string; } $strcut = ''; if(strtolower($discuz_charset) == 'utf8') { $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]; } } return $strcut.$dot; } function parseqqicq($qqicq, $minlen = 5, $maxlen = 12) {// qq 转换 return $qqicq ? (preg_match("/^([0-9]+)$/", $qqicq) && strlen($qqicq) >= $minlen && strlen($qqicq) <= $maxlen ? $qqicq : '') : ''; } function parsesite($site) { if($site && strtolower($site) != 'http://') { $user_site = trim(preg_match("/^https?:\/\/.+/i", $site) ? $site : ($site ? 'http://'.$site : '')); return $user_site ? cutstr(htmlspecialchars($user_site), 75) : ''; } return ''; } function parsesign($sign) { $searcharray = array( '[/color]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]', '[list=A]', '[*]', '[/list]', '[indent]', '[/indent]' ); $replacearray = array( '', '', '', '

', '', '', '', '', '', '', '', '
', '
' ); $pregfind = array( "/\[url\]\s*(www.|https?:\/\/|ftp:\/\/|gopher:\/\/|news:\/\/|telnet:\/\/|rtsp:\/\/|mms:\/\/|callto:\/\/|ed2k:\/\/){1}([^\[\"']+?)\s*\[\/url\]/ie", "/\[url=www.([^\[\"']+?)\](.+?)\[\/url\]/is", "/\[url=(https?|ftp|gopher|news|telnet|rtsp|mms|callto|ed2k){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/is", "/\[email\]\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*\[\/email\]/i", "/\[email=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\](.+?)\[\/email\]/is", "/\[color=([^\[\<]+?)\]/i", "/\[size=([^\[\<]+?)\]/i", "/\[font=([^\[\<]+?)\]/i", "/\[align=([^\[\<]+?)\]/i", "/\s*\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s*/is", "/\s*\[code\](.+?)\[\/code\]\s*/is", "/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies", "/\[img=(\d{1,3})[x|\,](\d{1,3})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies" ); $pregreplace = array( "cuturl('\\1\\2')", "\\2", "\\3", "\\1@\\2", "\\3", "", "", "", "

", "

\\1
", "
\\1
", "bbcodeurl('\\1', 'screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'Click here to open new window\\nCTRL+Mouse wheel to zoom in/out\';}\" onmouseover=\"if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'Click here to open new window\\nCTRL+Mouse wheel to zoom in/out\';}\" onclick=\"if(!this.resized) {return true;} else {window.open(\'%s\');}\" onmousewheel=\"return imgzoom(this);\" alt=\"\" />')", "bbcodeurl('\\3', '\"\"')" ); return daddslashes(str_replace($searcharray, $replacearray, preg_replace($pregfind, $pregreplace, $sign))); } function bbcodeurl($url, $tags) {//url 转换 if(!preg_match("/<.+?>/s", $url)) { if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'ftp://', 'rtsp:/', 'mms://'))) { $url = 'http://'.$url; } return str_replace(array('submit', 'logging.php'), array('', ''), sprintf($tags, $url, addslashes($url))); } else { return ' '.$url; } } function cuturl($url) { $length = 65; $urllink = "'; if(strlen($url) > $length) { $url = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3)); } $urllink .= $url.''; return $urllink; } function timetounix($time) { if($time > 100000000) { return $time; } $time = str_replace(array(' 一月 ',' 二月 ',' 三月 ',' 四月 ',' 五月 ',' 六月 ',' 七月 ',' 八月 ',' 九月 ',' 十月 ',' 十一月 ',' 十二月 ', ' 上午 '), array('-1-','-2-','-3-','-4-','-5-','-6-','-7-','-8-','-9-','-10-','-11-','-12-', ' '), $time); if(strrchr($time, '下午') !== false) { return strtotime(str_replace(' 下午 ', ' ', $time)) + 43200; } else { return strtotime($time); } } function convertcharset($msg) { global $source_charset, $discuz_charset, $db, $language; if($discuz_charset == $source_charset || ($db['source']->version() > 4.1 && $db['discuz']->version() > 4.1)){ return $msg; } elseif (function_exists(iconv)) { $source_charset = str_replace('utf8', 'utf-8', $source_charset); $discuz_charset = str_replace('utf8', 'utf-8', $discuz_charset); return iconv($source_charset, $discuz_charset, $msg); } else { showmessage($language['convert_noiconv']); } } function xconvert_encrypt($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(xconvert_key($tmp, $key)); } function xconvert_decrypt($txt, $key) { $txt = xconvert_key(base64_decode($txt), $key); $tmp = ''; for($i = 0;$i < strlen($txt); $i++) { $md5 = $txt[$i]; $tmp .= $txt[++$i] ^ $md5; } return $tmp; } function xconvert_key($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 showmessage($message, $url_forward = '', $vars = array(), $timeout = 1) { showheader(); $message = lang($message, $vars); $messageadd = ''; $timeout = intval($timeout); if($url_forward) { $messageadd .= ""; $messageadd .= ">>".lang('message_stop').""; } elseif(strpos($message, lang('return'))) { $messageadd .= "".lang('message_return').'

'; } echo << 系统提示
$message

$messageadd EOT; showfooter(); exit; } function showheader($action = '', $setting = array()) { static $isshow; if($isshow) { return true; } $class[$action] = 'class="current"'; $titleadd = !empty($setting['program']['source']) ? " ({$setting['program']['source']} --> {$setting['program']['target']})" : ''; echo << Discuz! X 系列产品升级转换

Discuz! X 系列产品升级/转换 向导 $titleadd

EOT; $isshow = true; } function getfiletype($filename = '') { $extnum = strrpos($filename, '.') + 1; $exts = strtolower(substr($filename, $extnum)); switch ($exts) { case 'jpg': return 'image/pjpeg'; break; case 'jpe': return 'image/pjpeg'; break; case 'jpeg': return 'image/pjpeg'; break; case 'pdf': return 'application/pdf'; break; case 'gif': return 'image/gif'; break; case 'bmp': return 'image/bmp'; break; case 'png': return 'image/png'; break; case 'rar': return 'x-rar-compressed'; break; case 'txt': return 'text/plain'; break; case 'swf': return 'application/x-shockwave-flash'; break; case 'zip': return 'application/zip'; break; case 'doc': return 'application/msword'; break; default: return 'application/octet-stream'; break; } } function convertucpw($password) { $salt = substr(uniqid(rand()), -6); $pass = md5(strtolower($password).$salt); return array('password'=>$pass, 'salt'=>$salt); } function getgpc($k, $type='GP') { $type = strtoupper($type); switch($type) { case 'G': $var = &$_GET; break; case 'P': $var = &$_POST; break; case 'C': $var = &$_COOKIE; break; default: if(isset($_GET[$k])) { $var = &$_GET; } else { $var = &$_POST; } break; } return isset($var[$k]) ? $var[$k] : NULL; } function show_table_header($show = true) { $s = << EOT; $s .= "\n"; return output($s, $show); } function show_table_footer($show = true) { $s = '
'."\n"; return output($s, $show); } function show_table_row($tds, $trclass = 'bg1', $show = true) { $s = ''; foreach ($tds as $td) { if(is_array($td)) { $s .= ''.$td[1].''; } else { $s .= ''.$td.''; } $s .= "\n"; } $s .= "\n"; return output($s, $show); } function output(&$s, $show) { if($show) { echo $s; } return $s; } function showfooter($halt = false) { static $isshow; if(!$isshow) { echo <<
EOT; } $isshow = true; } function submitcheck($var = 'submit', $allowget = false) { $check = getgpc($var); $ret = false; if(empty($check)) { } elseif($allowget) { $ret = true; } elseif($_REQUEST['method'] == 'post') { $ret = true; } return $ret; } function loadsetting($folder) { $folder = trim($folder); $ret = array(); if($folder != '' && !preg_match('/(\/)|(\.\.)|(\\\)/', $folder) && file_exists(DISCUZ_ROOT.'/source/'.$folder.'/setting.ini')) { $ret = @parse_ini_file(DISCUZ_ROOT.'/source/'.$folder.'/setting.ini', true); } return $ret; } function loadconfig($file = 'config.inc.php') { $_config = array(); @include DISCUZ_ROOT.'./data/'.$file; return $_config; } function showtips($tip) { $title = lang('tips'); $msg = lang($tip); echo << $title
    $msg
EOT; } function lang($name, $vars = array()) { static $language; if($language === null) { @include DISCUZ_ROOT.'./language/lang.php'; if(empty($language)) { $language = array(); } } $ret = isset($language[$name]) ? $language[$name] : $name; if(!empty($vars)) { foreach ($vars as $key => $value) { $ret = str_replace('{'.$key.'}', $value); } } return $ret; } function show_hidden_field($name, $value) { echo ''."\n"; } function show_form_header($method = 'post') { echo << EOT; } function show_form_footer($submitname = '', $submitvalue = 'submit') { if($submitname != '') { $submitvalue = lang($submitvalue); echo << EOT; } echo ''; } function show_config_input($type, $config, $error = array()) { $title = lang('config_type_'.$type); show_table_header(); show_table_row(array(array('colspan="3"', $title)), 'header title'); if($type == 'target') { show_table_row(array(array('colspan="3"', ''.lang('config_type_target_comment').'')), 'bg2'); } foreach ($config as $key => $value) { $addmsg = $error && $key == 'dbhost' ? lang($error) : ''; $tip = $key == 'pconnect' ? lang('tips_pconnect') : ''; show_table_row( array( array('width="150"', lang('config_'.$key)), array('class="bg2"', ''), array('class="bg2"', ''.$tip.''.$addmsg.'') ), 'bg1' ); } show_table_footer(); echo '
'; } function getvars($data, $type = 'VAR') { $evaluate = ''; foreach($data as $key => $val) { if(!preg_match("/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/", $key)) { continue; } if(is_array($val)) { $evaluate .= buildarray($val, 0, "\${$key}")."\r\n"; } else { $val = addcslashes($val, '\'\\'); $evaluate .= $type == 'VAR' ? "\$$key = '$val';\n" : "define('".strtoupper($key)."', '$val');\n"; } } return $evaluate; } function buildarray($array, $level = 0, $pre = '$_config') { static $ks; if($level == 0) { $ks = array(); $return = ''; } foreach ($array as $key => $val) { if($level == 0) { $newline = str_pad(' CONFIG '.strtoupper($key).' ', 50, '-', STR_PAD_BOTH); $return .= "\r\n// $newline //\r\n"; } $ks[$level] = $ks[$level - 1]."['$key']"; if(is_array($val)) { $ks[$level] = $ks[$level - 1]."['$key']"; $return .= buildarray($val, $level + 1, $pre); } else { $val = !is_array($val) && (!preg_match("/^\-?[1-9]\d*$/", $val) || strlen($val) > 12) ? '\''.addcslashes($val, '\'\\').'\'' : $val; $return .= $pre.$ks[$level - 1]."['$key']"." = $val;\r\n"; } } return $return; } function save_config_file($filename, $config, $default) { $config = setdefault($config, $default); $date = gmdate("Y-m-d H:i:s", time() + 3600 * 8); $year = date('Y'); $content = << $config)); $content .= "\r\n// ".str_pad(' THE END ', 50, '-', STR_PAD_BOTH)." //\r\n\r\n?>"; file_put_contents($filename, $content); } function setdefault($var, $default) { foreach ($default as $k => $v) { if(!isset($var[$k])) { $var[$k] = $default[$k]; } elseif(is_array($v)) { $var[$k] = setdefault($var[$k], $default[$k]); } } return $var; } function mysql_connect_test($config, $type) { global $setting; static $error_code = array('connect_error' => -1, 'table_error' => -2); static $db; $ret = true; if($db === null) { require_once(DISCUZ_ROOT.'./include/db.class.php'); $db = new db_mysql(); } $db->set_config($config); $check = $db->connect(false); if(!$check) { $ret = $error_code['connect_error']; } else { if(isset($setting['tablecheck'][$type])) { $find = $db->fetch_first("SHOW TABLES LIKE '{$config[tablepre]}{$setting['tablecheck'][$type]}'"); if(!$find) { $ret = $error_code['table_error']; } } } $db->close(); return $ret; } function tablepre(&$db) { $pre = $db->table_pre; if(strexists($pre, '.')) { $tablepre = substr($pre, strpos($pre, '.') + 1); } else { $tablepre = $pre; } return $tablepre; } function implode_field_value($array, $glue = ',', $fields = array()) { $sql = $comma = ''; foreach ($array as $k => $v) { if(empty($fields) || isset($fields[$k])) { $sql .= $comma."`$k`='$v'"; $comma = $glue; } } return $sql; } function load_process($key) { global $db_target; $table = $db_target->tablepre.CACHETABLE; $data = $db_target->fetch_first("SELECT cachevalue FROM $table WHERE cachekey='$key'"); if($data) { $data = unserialize($data['cachevalue']); } return !is_array($data) ? array() : $data; } function delete_process($key) { global $db_target; $table = $db_target->tablepre.CACHETABLE; if(empty($key) || $key == 'all') { $db_target->query("DELETE FROM $table"); } else { $db_target->query("DELETE FROM $table WHERE cachekey='$key'"); } } function save_process($key, $data) { global $db_target; $table = $db_target->tablepre.CACHETABLE; $data = serialize($data); $db_target->query("REPLACE INTO $table SET cachekey='$key', cachevalue='$data'"); } function dimplode($array) { if(!empty($array)) { return "'".implode("','", is_array($array) ? $array : array($array))."'"; } else { return ''; } } function db_table_charset($dbobject, $tablename) { $tablestruct = $dbobject->fetch_first("show create table {$dbobject->tablepre}$tablename"); preg_match("/CHARSET=(\w+)/", $tablestruct['Create Table'], $m); return $m[1]; } function db_table_fields($db, $table) { static $tables = array(); $table = str_replace($db->tablepre, '', $table); if(!isset($tables[$table])) { $tables[$table] = array(); if($db->version() > '4.1') { $query = $db->query("SHOW FULL COLUMNS FROM {$db->tablepre}$table", 'SILENT'); } else { $query = $db->query("SHOW COLUMNS FROM {$db->tablepre}$table", 'SILENT'); } while($field = @$db->fetch_array($query)) { $tables[$table][$field['Field']] = $field; } } return $tables[$table]; } function dstripslashes($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = dstripslashes($val); } } else { $string = stripslashes($string); } return $string; } function strexists($string, $find) { return !(strpos($string, $find) === FALSE); } if(!function_exists('file_put_contents')) { if(!defined('FILE_APPEND')) define('FILE_APPEND', 8); function file_put_contents($filename, $data, $flag = 0) { $return = false; if($fp = @fopen($filename, $flag != FILE_APPEND ? 'w' : 'a')) { if($flag == LOCK_EX) @flock($fp, LOCK_EX); $return = fwrite($fp, is_array($data) ? implode('', $data) : $data); fclose($fp); } return $return; } }