📄 tools.php
字号:
if(!$query){
htmlheader();
errorpage('您当前的数据库版本无法检查字符集设定,可能是由于版本过低不支持检查语句导致', '', 0, 0);
htmlfooter();
exit;
}
while($dbdetail = mysql_fetch_array($query)){
$dbtable[$dbdetail["Name"]]["Collation"] = pregcharset($dbdetail["Collation"],1); //获得每个表的编码
$dbtable[$dbdetail["Name"]]["tablename"] = $dbdetail["Name"]; //数据库所有的表名
$tablequery = mysql_query("SHOW FULL FIELDS FROM `".$dbdetail["Name"]."`");//取出每个表的结构
while($tables= mysql_fetch_array($tablequery)){
if(!empty($tables["Collation"])) {
$collcharset = pregcharset($tables["Collation"], 0);
$tableschar[$collcharset][$dbdetail["Name"]][] = $tables["Field"];
$chars[pregcharset($tables["Collation"], 0)]++;
}
}
}
}
}
htmlheader();
echo '<h4>编码检查</h4>';
echo "<div class=\"specialdiv\">操作提示:<ul>
<li>MySQL版本在4.1以上才有字符集的设定,所以数据库4.1版本以上的才能使用本功能</li>
<li>如果某些字段的字符集不一致,有可能会导致程序中出现乱码,尽量把字符集不一致的字段转换成统一字符集</li>
<li>有关MySQL编码机制可以参考 <a href='http://www.discuz.net/viewthread.php?tid=1022673' target='_blank'>点击查看</a></li>
<li>一些关于MySQL编码方面的<a href='http://www.discuz.net/viewthread.php?tid=1070306' target='_blank'>教程</a></li>
<li><font color=red>Tools工具箱只是尝试帮你修复数据库的字段编码,修复前请先备份你的数据库,以免造成不必要的损失,如果因为你没有备份数据库造成的损失与本程序无关</font></li>
<li><font color=red>不能修复latin1字符集,可以尝试使用其他方法进行转码</font></li>
</ul></div>";
if($my_version > '4.1') {
echo'<div class="tabbody">
<style>.tabbody p em { color:#09C; padding:0 10px;} .char_div { margin-top:30px; margin-bottom:30px;} .char_div h4, .notice h4 { font-weight:600; font-size:16px; margin:0; padding:0; margin-bottom:10px;}</style>
<div class="char_div"><h5>数据库('.$dbname.')的字符集统计:</h5>
<table style="width:40%; margin:0; margin-bottom:20px;"><tr><th>gbk字段</th><th>big5字段</th><th>utf8字段</th><th>latin1字段</th></tr><tr><td>'.$chars[gbk].' </td><td>'.$chars[big5].' </td><td>'.$chars[utf8].' </td><td>'.$chars[latin1].' </td></tr></table>
<div class="notice">
<h5>下列字段可能存在编码设置异常:</h5>';
?>
<script type="text/JavaScript">
function setrepaircheck(obj, form, table, char) {
eval('var rem = /^' + table + '\\|.+?\\|.+?\\|' + char + '$/;');
eval('var rechar = /latin1/;');
for(var i = 0; i < form.elements.length; i++) {
var e = form.elements[i];
if(e.type == 'checkbox' && e.name == 'repair[]') {
if(rem.exec(e.value) != null) {
if(obj.checked) {
if(rechar.exec(e.value) != null){
e.checked = false;
e.disabled = true;
}else{
e.checked = true;
}
} else {
e.checked = false;
}
}
}
}
}
</script>
<?php
foreach($chars as $char => $num) {
if ($char != $maincharset) {
if(is_array($tableschar[$char])) {
echo '<form name="form" action="" method="post">';
foreach($tableschar[$char] as $tablename => $fields) {
echo'<table style="margin-left:0; width:40%;">
<tr>
<th><input type="checkbox" id="tables[]" style="border-style:none;" name="chkall" onclick="setrepaircheck(this, this.form, \''.$tablename.'\', \''.$char.'\');" value="'.$tablename.'">全选</th>
<th width=60%><strong>'.$tablename.'</strong> <font color="red">表异常的字段</font></th>
<th>编码</th>
</tr>';
foreach($fields as $collation) {
echo'<tr><td><input type="checkbox" style="border-style:none;"';
if($char == 'latin1'){
echo ' disabled ';
}
echo 'id="fields['.$tablename.'][]"';
echo 'name=repair[] value="'.$tablename.'|'.$collation.'|'.$maincharset.'|'.$char.'">';
echo '</td><td>'.$collation.'</td><td><font color="red">'.$char.'</font></td></tr>';
}
echo '</table>';
}
}
}
}
echo '<input type="submit" value="把指定的字段编码转换为'.$maincharset.'" name="repairsubmit" onclick="javascript:if (confirm(\'Tools工具箱只是尝试帮你修复数据库字段字符集,修复前请先备份你的数据库,以免造成不必要的损失,如果因为你没有备份数据库造成的损失与本程序无关\'));else return false;"></form>';
echo'<br /><br /><br /></div> </div>';
}else {
errorpage('MySQL数据库版本在4.1以下,没有字符集设定,无需检测', '', 0, 0);
}
htmlfooter();
} elseif ($action == 'dz_doctor') {//论坛医生
htmlheader();
echo "<script language=\"javascript\">
function copytoclip(obj) {
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
if(is_ie && obj.style.display != 'none') {
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand(\"Copy\");
rng.collapse(false);
}
}
function $(id) {
return document.getElementById(id);
}
function openerror(error){
obj = document.getElementById(error);
if(obj.style.display == ''){
obj.style.display='none';
}else{
obj.style.display='';
}
}
</script>";
function create_checkfile() {
global $dir;
$fp = @fopen('./forumdata/checkfile.php',w);
$includedir = $dir != './' ? str_replace('forumdata/','./',$dir) : '../';
$content = "<?php
define('IN_DISCUZ',TRUE);
if(function_exists('ini_set')) @ini_set('display_errors',1);
if(\$_GET['file'] != 'config.inc.php') include '../include/common.inc.php';
error_reporting(E_ERROR | E_WARNING | E_PARSE);
include '$includedir'.\$_GET['file'];\n?>";
fwrite($fp, $content);
fclose($fp);
}
function http_fopen($host, $path, $port="80") {
global $target_fsockopen;
$conn_host = $target_fsockopen == 1 ? gethostbyname($host) : $host;
$conn_port = $port;
$abs_url = "http://$host:$port$path";
$query="GET $abs_url HTTP/1.0\r\n".
"HOST:$host:$port\r\n".
"User-agent:PHP/class http 0.1\r\n".
"\r\n";
$fp=fsockopen($conn_host, $conn_port);
if(!$fp){
return false;
}
fputs($fp,$query);
//得到返回的结果
$contents = "";
while (!feof($fp)) {
$contents .= fread($fp, 1024);
}
fclose($fp);
$array = split("\n\r", $contents, "2");
return trim($array[1]);
}
//论坛模式样式代码变量
$ok_style_s = '[color=RoyalBlue][b]';
$error_style_s = '[color=Red][b]';
$style_e = '[/b][/color]';
$title_style_s = '[b]';
$title_style_e = '[/b]';
$phpfile_array = array('discuzroot', 'templates', 'cache');//文件错误检查中的目录及对应名称($dir_array)
$dir_array = array('论坛根目录', '模板缓存目录(forumdata/templates)', '其它缓存目录(forumdata/cache)');
$doctor_top = count($phpfile_array) - 1;
//$doctor_step = isset($_REQUEST['doctor_step']) ? intval($_REQUEST['doctor_step']) : '';
if(@!include("./config.inc.php")) {
if(@!include("./config.php")) {
cexit("<h4>请先上传config文件以保证您的数据库能正常链接!</h4>");
}
}
if($doctor_step == $doctor_top) {
//检查Config.inc.php文件配置
$carray = $clang = $comment = array();
$doctor_config = $doctor_config_db = '';
$configfilename = file_exists('./config.inc.php') ? './config.inc.php' : './config.php';
$fp = @fopen($configfilename, 'r');
$configfile = @fread($fp, @filesize($configfilename));
@fclose($fp);
preg_match_all("/[$]([\w\[\]\']+)\s*\=\s*[\"']?(.*?)[\"']?;/is", $configfile, $cmatch);
foreach($cmatch[1] as $key => $var) {
if(!in_array($var, array('database','adminemail','admincp'))) {
$carray[$var] = $cmatch[2][$key];
}
}
$clang = array(
'dbhost' => '数据库服务器',
'dbuser' => '数据库用户名',
'dbpw' => '数据库密码',
'dbname' => '数据库名',
'pconnect' => '数据库是否持久连接',
'cookiepre' => 'cookie 前缀',
'cookiedomain' => 'cookie 作用域',
'cookiepath' => 'cookie 作用路径',
'tablepre' => '表名前缀',
'dbcharset' => 'MySQL链接字符集',
'charset' => '论坛字符集',
'headercharset' => '强制论坛页面使用默认字符集',
'tplrefresh' => '论坛风格模板自动刷新开关',
'forumfounders' => '论坛创始人uid',
'dbreport' => '是否发送错误报告给管理员',
'errorreport' => '是否屏蔽程序错误信息',
'attackevasive' => '论坛防御级别',
'admincp[\'forcesecques\']' => '管理人员是否必须设置安全提问才能进入系统设置',
'admincp[\'checkip\']' => '后台管理操作是否验证管理员的 IP',
'admincp[\'tpledit\']' => '是否允许在线编辑论坛模板',
'admincp[\'runquery\']' => '是否允许后台运行 SQL 语句',
'admincp[\'dbimport\']' => '是否允许后台恢复论坛数据',
);
$comment = array(
'pconnect' => '非持久连接',
'cookiepre' => '不检测',
'cookiepath' => '不检测',
'charset' => '不检测',
'adminemail' => '不检测',
'admincp' => '非设置项',
);
@mysql_connect($carray['dbhost'], $carray['dbuser'], $carray['dbpw']) or $mysql_errno = mysql_errno();
!$mysql_errno && @mysql_select_db($carray['dbname']) or $mysql_errno = mysql_errno();
$comment_error = "{$error_style_s}出错{$style_e}";
if ($mysql_errno == '2003') {
$comment['dbhost'] = "{$error_style_s}端口设置出错{$style_e}";
} elseif ($mysql_errno == '2005') {
$comment['dbhost'] = $comment_error;
} elseif ($mysql_errno == '1045') {
$comment['dbuser'] = $comment_error;
$comment['dbpw'] = $comment_error;
} elseif ($mysql_errno == '1049') {
$comment['dbname'] = $comment_error;
} elseif (!empty($mysql_errno)) {
$comment['dbhost'] = $comment_error;
$comment['dbuser'] = $comment_error;
$comment['dbpw'] = $comment_error;
$comment['dbname'] = $comment_error;
}
$comment['pconnect'] = '非持久链接';
$carray['pconnect'] == 1 && $comment['pconnect'] = '持久连接';
if ($carray['cookiedomain'] && substr($carray['cookiedomain'], 0, 1) != '.') {
$comment['cookiedomain'] = "{$error_style_s}请以 . 开头,不然同步登录会出错{$style_e}";
}
(!$mysql_errno && !mysql_num_rows(mysql_query('SHOW TABLES LIKE \''.$carray['tablepre'].'posts\''))) && $comment['tablepre'] = $comment_error;
if (!$comment['tablepre'] && !$mysql_errno && @mysql_get_server_info() > '4.1') {
$tableinfo = loadtable('threads');
$dzdbcharset = substr($tableinfo['subject']['Collation'], 0, strpos($tableinfo['subject']['Collation'], '_'));
if(!$carray['dbcharset'] && in_array(strtolower($carray['charset']), array('gbk', 'big5', 'utf-8'))) {
$ckdbcharset = str_replace('-', '', $carray['charset']);
} else {
$ckdbcharset = $carray['dbcharset'];
}
if ($dzdbcharset != $ckdbcharset && $ckdbcharset != '') {
$carray['dbcharset'] .= $error_style_s.'出错,您的论坛数据库字符集为 '.$dzdbcharset.' ,请将本项设置成 '.$dzdbcharset.$style_e;
}
}
if(!in_array($carray['charset'],array('gbk', 'big5', 'utf-8'))) {
$carray['charset'] .= $error_style_s." 出错,目前字符集只支持'gbk', 'big5', 'utf-8'".$style_e;
}
if ($carray['headercharset'] == 0) {
$comment['headercharset'] = $title_style_s.'未开启'.$title_style_e;
} else {
$comment['headercharset'] = $ok_style_s.'开启'.$style_e;
}
if ($carray['tplrefresh'] == 0) {
$comment['tplrefresh'] = $title_style_s.'关闭'.$title_style_e;
} else {
$comment['tplrefresh'] = $ok_style_s.'开启'.$style_e;
}
if (preg_match('/[^\d,]/i', str_replace(' ', '', $carray['forumfounders']))) {
$comment['forumfounders'] = $error_style_s.'出错:含有非法字符,该项设置只能含有数字和半角逗号 ,'.$style_e;
} elseif(!$comment['tablepre'] && !$mysql_errno) {
if ($carray['forumfounders']) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -