📄 install.func.php
字号:
$next = $step + 1;
$discuz_license = str_replace(' ', ' ', $lang['license']);
echo <<<EOT
</div>
<div class="main" style="margin-top:-123px;">
<div class="licenseblock">$discuz_license</div>
<div class="btnbox marginbot">
<form method="post" action="$self">
<input type="hidden" name="action" value="uc">
<input type="hidden" name="step" value="$next">
$uchidden
<input type="submit" name="submit" value="{$lang['agreement_yes']}" style="padding: 2px">
<input type="button" name="exit" value="{$lang['agreement_no']}" style="padding: 2px" onclick="javascript: window.close(); return false;">
</form>
</div>
EOT;
show_footer();
}
function check_env() {
global $lang, $attachdir;
$errors = array('quit' => false);
$quit = false;
if(!function_exists('mysql_connect')) {
$errors[] = 'mysql_unsupport';
$quit = true;
}
if(PHP_VERSION < '4.3') {
$errors[] = 'php_version_430';
$quit = true;
}
if(!file_exists(DISCUZ_ROOT.'./config.inc.php')) {
$errors[] = 'config_nonexistence';
$quit = true;
} elseif(!is_writeable(DISCUZ_ROOT.'./config.inc.php')) {
$errors[] = 'config_unwriteable';
$quit = true;
}
$checkdirarray = array(
'attach' => $attachdir,
'forumdata' => './forumdata',
'cache' => './forumdata/cache',
'ftemplates' => './forumdata/templates',
'threadcache' => './forumdata/threadcaches',
'log' => './forumdata/logs',
'uccache' => './uc_client/data/cache'
);
foreach($checkdirarray as $key => $dir) {
if(!dir_writeable(DISCUZ_ROOT.$dir)) {
$langkey = $key.'_unwriteable';
$errors[] = $key.'_unwriteable';
if(!in_array($key, array('ftemplate'))) {
$quit = TRUE;
}
}
}
$errors['quit'] = $quit;
return $errors;
}
function show_error($type, $errors = '', $quit = false) {
global $lang, $step;
$title = lang($type);
$comment = lang($type.'_comment', false);
$errormsg = '';
if($errors) {
if(!empty($errors)) {
foreach ((array)$errors as $k => $v) {
if(is_numeric($k)) {
$comment .= "<li><em class=\"red\">".lang($v)."</em></li>";
}
}
}
}
if($step > 0) {
echo "<div class=\"desc\"><b>$title</b><ul>$comment</ul>";
} else {
echo "</div><div class=\"main\" style=\"margin-top: -123px;\"><b>$title</b><ul style=\"line-height: 200%; margin-left: 30px;\">$comment</ul>";
}
if($quit) {
echo '<br /><span class="red">'.$lang['error_quit_msg'].'</span><br /><br /><br /><br /><br /><br />';
}
echo '</div>';
$quit && show_footer();
}
function show_tips($tip, $title = '', $comment = '', $style = 1) {
global $lang;
$title = empty($title) ? lang($tip) : $title;
$comment = empty($comment) ? lang($tip.'_comment', FALSE) : $comment;
if($style) {
echo "<div class=\"desc\"><b>$title</b>";
} else {
echo "</div><div class=\"main\" style=\"margin-top: -123px;\">$title<div class=\"desc1 marginbot\"><ul>";
}
$comment && print('<br>'.$comment);
echo "</div>";
}
function show_setting($setname, $varname = '', $value = '', $type = 'text|password|checkbox', $error = '') {
global $self;
if($setname == 'start') {
echo "<form method=\"post\" action=\"$self\">\n<table class=\"tb2\">\n";
return;
} elseif($setname == 'end') {
echo "\n</table>\n</form>\n";
return;
} elseif($setname == 'hidden') {
echo "<input type=\"hidden\" name=\"$varname\" value=\"$value\">\n";
return;
}
echo "\n".'<tr><th class="tbopt'.($error ? ' red' : '').'"> '.lang($setname)."</th>\n<td>";
if($type == 'text' || $type == 'password') {
$value = htmlspecialchars($value);
echo "<input type=\"$type\" name=\"$varname\" value=\"$value\" size=\"35\" class=\"txt\">";
} elseif($type == 'submit') {
$value = empty($value) ? 'next_step' : $value;
echo "<input type=\"submit\" name=\"$varname\" value=\"".lang($value)."\" class=\"btn\">\n";
} elseif($type == 'checkbox') {
if(!is_array($varname) && !is_array($value)) {
echo'<input type="checkbox" name="'.$varname.'" value="'.$value."\" style=\"border: 0\">\n";
}
} else {
echo $value;
}
echo "</td>\n<td> ";
if($error) {
$comment = '<span class="red">'.(is_string($error) ? lang($error) : lang($setname.'_error')).'</span>';
} else {
$comment = lang($setname.'_comment', false);
}
echo "$comment</td>\n</tr>\n";
return true;
}
function show_step($step) {
$laststep = 4;
$title = lang('step_'.$step);
$comment = lang('step_'.$step.'_comment');
$stepclass = array();
for($i = 1; $i <= $laststep; $i++) {
$stepclass[$i] = $i == $step ? 'current' : ($i < $step ? '' : 'unactivated');
}
$stepclass[$laststep] .= ' last';
echo <<<EOT
<div class="setup step{$step}">
<h2>$title</h2>
<p>$comment</p>
</div>
<div class="stepstat">
<ul>
<li class="$stepclass[1]">1</li>
<li class="$stepclass[2]">2</li>
<li class="$stepclass[3]">3</li>
<li class="$stepclass[4]">4</li>
</ul>
<div class="stepstatbg stepstat1"></div>
</div>
</div>
<div class="main">
EOT;
}
function lang($lang_key, $force = true) {
return isset($GLOBALS['lang'][$lang_key]) ? $GLOBALS['lang'][$lang_key] : ($force ? $lang_key : '');
}
function check_adminuser($username, $password, $email) {
@include DISCUZ_ROOT.'./config.inc.php';
include DISCUZ_ROOT.'./uc_client/client.php';
$error = '';
$uid = uc_user_register($username, $password, $email);
/*
-1 : 用户名不合法
-2 : 包含不允许注册的词语
-3 : 用户名已经存在
-4 : email 格式有误
-5 : email 不允许注册
-6 : 该 email 已经被注册
>1 : 表示成功,数值为 UID
*/
if($uid == -1 || $uid == -2) {
$error = 'admin_username_invalid';
} elseif($uid == -4 || $uid == -5 || $uid == -6) {
$error = 'admin_email_invalid';
} elseif($uid == -3) {
$ucresult = uc_user_login($username, $password);
list($tmp['uid'], $tmp['username'], $tmp['password'], $tmp['email']) = uc_addslashes($ucresult);
$ucresult = $tmp;
if($ucresult['uid'] <= 0) {
$error = 'admin_exist_password_error';
} else {
$uid = $ucresult['uid'];
$email = $ucresult['email'];
$password = $ucresult['password'];
}
}
if(!$error && $uid > 0) {
$password = md5($password);
uc_user_addprotected($username, '');
} else {
$uid = 0;
$error = empty($error) ? 'error_unknow_type' : $error;
}
return array('uid' => $uid, 'username' => $username, 'password' => $password, 'email' => $email, 'error' => $error);
}
function save_uc_config($config, $file) {
$success = false;
list($appauthkey, $appid, $ucdbhost, $ucdbname, $ucdbuser, $ucdbpw, $ucdbcharset, $uctablepre, $uccharset, $ucapi, $ucip) = explode('|', $config);
if($content = file_get_contents($file)) {
$content = trim($content);
$content = substr($content, -2) == '?>' ? substr($content, 0, -2) : $content;
$link = mysql_connect($ucdbhost, $ucdbuser, $ucdbpw, 1);
$uc_connnect = $link && mysql_select_db($ucdbname, $link) ? 'mysql' : '';
$content = insertconfig($content, "/define\('UC_CONNECT',\s*'.*?'\);/i", "define('UC_CONNECT', '$uc_connnect');");
$content = insertconfig($content, "/define\('UC_DBHOST',\s*'.*?'\);/i", "define('UC_DBHOST', '$ucdbhost');");
$content = insertconfig($content, "/define\('UC_DBUSER',\s*'.*?'\);/i", "define('UC_DBUSER', '$ucdbuser');");
$content = insertconfig($content, "/define\('UC_DBPW',\s*'.*?'\);/i", "define('UC_DBPW', '$ucdbpw');");
$content = insertconfig($content, "/define\('UC_DBNAME',\s*'.*?'\);/i", "define('UC_DBNAME', '$ucdbname');");
$content = insertconfig($content, "/define\('UC_DBCHARSET',\s*'.*?'\);/i", "define('UC_DBCHARSET', '$ucdbcharset');");
$content = insertconfig($content, "/define\('UC_DBTABLEPRE',\s*'.*?'\);/i", "define('UC_DBTABLEPRE', '`$ucdbname`.$uctablepre');");
$content = insertconfig($content, "/define\('UC_DBCONNECT',\s*'.*?'\);/i", "define('UC_DBCONNECT', '0');");
$content = insertconfig($content, "/define\('UC_KEY',\s*'.*?'\);/i", "define('UC_KEY', '$appauthkey');");
$content = insertconfig($content, "/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '$ucapi');");
$content = insertconfig($content, "/define\('UC_CHARSET',\s*'.*?'\);/i", "define('UC_CHARSET', '$uccharset');");
$content = insertconfig($content, "/define\('UC_IP',\s*'.*?'\);/i", "define('UC_IP', '$ucip');");
$content = insertconfig($content, "/define\('UC_APPID',\s*'?.*?'?\);/i", "define('UC_APPID', '$appid');");
$content = insertconfig($content, "/define\('UC_PPP',\s*'?.*?'?\);/i", "define('UC_PPP', '20');");
if(@file_put_contents($file, $content)) {
$success = true;
}
}
return $success;
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -