📄 install.func.php
字号:
<?php
/*
[Discuz!] (C)2001-2007 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id$
*/
if(!function_exists('file_put_contents')) {
function file_put_contents($filename, $s) {
$fp = @fopen($filename, 'w');
@fwrite($fp, $s);
@fclose($fp);
return TRUE;
}
}
function createtable($sql, $dbcharset) {
$type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
$type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).
(mysql_get_server_info() > '4.1' ? " ENGINE=$type DEFAULT CHARSET=$dbcharset" : " TYPE=$type");
}
function dir_writeable($dir) {
if(!is_dir($dir)) {
@mkdir($dir, 0777);
}
if(is_dir($dir)) {
if($fp = @fopen("$dir/test.txt", 'w')) {
@fclose($fp);
@unlink("$dir/test.txt");
$writeable = 1;
} else {
$writeable = 0;
}
}
return $writeable;
}
function dir_clear($dir) {
global $lang;
showjsmessage($lang['clear_dir'].' '.$dir);
$directory = dir($dir);
while($entry = $directory->read()) {
$filename = $dir.'/'.$entry;
if(is_file($filename)) {
@unlink($filename);
}
}
$directory->close();
@touch($dir.'/index.htm');
}
function show_header() {
define('SHOW_HEADER', TRUE);
global $charset, $step;
$version = DISCUZ_VERSION;
$release = DISCUZ_RELEASE;
$install_lang = lang(INSTALL_LANG);
$title = lang('title_install');
echo <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=$charset" />
<title>$title</title>
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
<script type="text/javascript">
function $(id) {
return document.getElementById(id);
}
function showmessage(message) {
$('notice').value += message + "\\r\\n";
}
</script>
<meta content="Comsenz Inc." name="Copyright" />
</head>
<div class="container">
<div class="header">
<h1>$title</h1>
<span>V$version $install_lang $release</span>
EOT;
$step > 0 && show_step($step);
}
function show_footer($quit = true) {
echo <<<EOT
<div class="footer">©2001 - 2008 <a href="http://www.comsenz.com/">Comsenz</a> Inc.</div>
</div>
</div>
</body>
</html>
EOT;
$quit && exit();
}
function loginit($logfile) {
global $lang;
showjsmessage($lang['init_log'].' '.$logfile);
if($fp = @fopen('./forumdata/logs/'.$logfile.'.php', 'w')) {
fwrite($fp, '<'.'?PHP exit(); ?'.">\n");
fclose($fp);
}
}
function showjsmessage($message) {
echo '<script type="text/javascript">showmessage(\''.addslashes($message).' \');</script>'."\r\n";
flush();
ob_flush();
}
function random($length) {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
function redirect($url) {
echo "<script>".
"function redirect() {window.location.replace('$url');}\n".
"setTimeout('redirect();', 0);\n".
"</script>";
exit();
}
function runquery($sql) {
global $lang, $dbcharset, $tablepre, $db;
$sql = str_replace("\r", "\n", str_replace(' cdb_', ' '.$tablepre, $sql));
$ret = array();
$num = 0;
foreach(explode(";\n", trim($sql)) as $query) {
$queries = explode("\n", trim($query));
foreach($queries as $query) {
$ret[$num] .= $query[0] == '#' || $query[0].$query[1] == '--' ? '' : $query;
}
$num++;
}
unset($sql);
foreach($ret as $query) {
$query = trim($query);
if($query) {
if(substr($query, 0, 12) == 'CREATE TABLE') {
$name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
showjsmessage($lang['create_table'].' '.$name.' ... '.$lang['succeed']);
$db->query(createtable($query, $dbcharset));
} else {
$db->query($query);
}
}
}
}
function charcovert($string) {
if(!get_magic_quotes_gpc()) {
$string = str_replace('\'', '\\\'', $string);
} else {
$string = str_replace('\"', '"', $string);
}
return $string;
}
function insertconfig($s, $find, $replace) {
if(preg_match($find, $s)) {
$s = preg_replace($find, $replace, $s);
} else {
// 插入到最后一行
$s .= "\r\n".$replace;
}
return $s;
}
function getgpc($k, $var='GP') {
$var = strtoupper($var);
switch($var) {
case 'GP' : isset($_POST[$k]) ? $var = &$_POST : $var = &$_GET; break;
case 'G': $var = &$_GET; break;
case 'P': $var = &$_POST; break;
case 'C': $var = &$_COOKIE; break;
case 'R': $var = &$_REQUEST; break;
}
return isset($var[$k]) ? $var[$k] : '';
}
function var_to_hidden($k, $v) {
return "<input type=\"hidden\" name=\"$k\" value=\"$v\" />\n";
}
function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
$return = '';
$matches = parse_url($url);
$host = $matches['host'];
$path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
$port = !empty($matches['port']) ? $matches['port'] : 80;
if($post) {
$out = "POST $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
//$out .= "Referer: $boardurl\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= 'Content-Length: '.strlen($post)."\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cache-Control: no-cache\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
$out .= $post;
} else {
$out = "GET $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
//$out .= "Referer: $boardurl\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
}
$fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
if(!$fp) {
return '';
} else {
stream_set_blocking($fp, $block);
stream_set_timeout($fp, $timeout);
@fwrite($fp, $out);
$status = stream_get_meta_data($fp);
if(!$status['timed_out']) {
while (!feof($fp)) {
if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
break;
}
}
$stop = false;
while(!feof($fp) && !$stop) {
$data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
$return .= $data;
if($limit) {
$limit -= strlen($data);
$stop = $limit <= 0;
}
}
}
@fclose($fp);
return $return;
}
}
function show_license() {
global $lang, $self, $uchidden, $step;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -