improve installation

This commit is contained in:
joyqi
2021-08-16 18:34:25 +08:00
parent 21a57903a9
commit bac7340c2a
8 changed files with 467 additions and 318 deletions

View File

@@ -18,7 +18,6 @@ $header = Typecho_Plugin::factory('admin/header.php')->header($header);
<html class="no-js">
<head>
<meta charset="<?php $options->charset(); ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title><?php _e('%s - %s - Powered by Typecho', $menu->title, $options->title); ?></title>

View File

@@ -44,7 +44,246 @@ else:
endif;
ob_start();
define('__TYPECHO_INSTALL__', true);
/**
* 获取系统语言
*
* @return string
*/
function install_get_lang(): string {
if (isset($_SERVER['TYPECHO_LANG'])) {
return $_SERVER['TYPECHO_LANG'];
} else {
$lang = 'zh_CN';
$request = Typecho_Request::getInstance();
if ($request->is('lang')) {
$lang = $request->get('lang');
Typecho_Cookie::set('lang', $lang);
}
return Typecho_Cookie::get('lang', $lang);
}
}
/**
* 获取站点地址
*
* @return string
*/
function install_get_site_url(): string {
if (isset($_SERVER['TYPECHO_SITE_URL'])) {
return $_SERVER['TYPECHO_SITE_URL'];
} else {
$request = Typecho_Request::getInstance();
return $request->get('userUrl', $request->getRequestRoot());
}
}
/**
* 获取默认参数
*
* @return array
*/
function install_get_default_options(): array {
return [
'theme' => 'default',
'theme:default' => 'a:2:{s:7:"logoUrl";N;s:12:"sidebarBlock";a:5:{i:0;s:15:"ShowRecentPosts";i:1;s:18:"ShowRecentComments";i:2;s:12:"ShowCategory";i:3;s:11:"ShowArchive";i:4;s:9:"ShowOther";}}',
'timezone' => '28800',
'lang' => install_get_lang(),
'charset' => _('UTF-8'),
'contentType' => 'text/html',
'gzip' => 0,
'generator' => 'Typecho ' . Typecho_Common::VERSION,
'title' => 'Hello World',
'description' => 'Your description here.',
'keywords' => 'typecho,php,blog',
'rewrite' => 0,
'frontPage' => 'recent',
'frontArchive' => 0,
'commentsRequireMail' => 1,
'commentsWhitelist' => 0,
'commentsRequireURL' => 0,
'commentsRequireModeration' => 0,
'plugins' => 'a:0:{}',
'commentDateFormat' => 'F jS, Y \a\t h:i a',
'siteUrl' => install_get_site_url(),
'defaultCategory' => 1,
'allowRegister' => 0,
'defaultAllowComment' => 1,
'defaultAllowPing' => 1,
'defaultAllowFeed' => 1,
'pageSize' => 5,
'postsListSize' => 10,
'commentsListSize' => 10,
'commentsHTMLTagAllowed' => null,
'postDateFormat' => 'Y-m-d',
'feedFullText' => 1,
'editorSize' => 350,
'autoSave' => 0,
'markdown' => 1,
'xmlrpcMarkdown' => 0,
'commentsMaxNestingLevels' => 5,
'commentsPostTimeout' => 24 * 3600 * 30,
'commentsUrlNofollow' => 1,
'commentsShowUrl' => 1,
'commentsMarkdown' => 0,
'commentsPageBreak' => 0,
'commentsThreaded' => 1,
'commentsPageSize' => 20,
'commentsPageDisplay' => 'last',
'commentsOrder' => 'ASC',
'commentsCheckReferer' => 1,
'commentsAutoClose' => 0,
'commentsPostIntervalEnable' => 1,
'commentsPostInterval' => 60,
'commentsShowCommentOnly' => 0,
'commentsAvatar' => 1,
'commentsAvatarRating' => 'G',
'commentsAntiSpam' => 1,
'routingTable' => 'a:25:{s:5:"index";a:3:{s:3:"url";s:1:"/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:7:"archive";a:3:{s:3:"url";s:6:"/blog/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:2:"do";a:3:{s:3:"url";s:22:"/action/[action:alpha]";s:6:"widget";s:9:"Widget_Do";s:6:"action";s:6:"action";}s:4:"post";a:3:{s:3:"url";s:24:"/archives/[cid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:10:"attachment";a:3:{s:3:"url";s:26:"/attachment/[cid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:8:"category";a:3:{s:3:"url";s:17:"/category/[slug]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:3:"tag";a:3:{s:3:"url";s:12:"/tag/[slug]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:6:"author";a:3:{s:3:"url";s:22:"/author/[uid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:6:"search";a:3:{s:3:"url";s:19:"/search/[keywords]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:10:"index_page";a:3:{s:3:"url";s:21:"/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"archive_page";a:3:{s:3:"url";s:26:"/blog/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:13:"category_page";a:3:{s:3:"url";s:32:"/category/[slug]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:8:"tag_page";a:3:{s:3:"url";s:27:"/tag/[slug]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"author_page";a:3:{s:3:"url";s:37:"/author/[uid:digital]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"search_page";a:3:{s:3:"url";s:34:"/search/[keywords]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"archive_year";a:3:{s:3:"url";s:18:"/[year:digital:4]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:13:"archive_month";a:3:{s:3:"url";s:36:"/[year:digital:4]/[month:digital:2]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"archive_day";a:3:{s:3:"url";s:52:"/[year:digital:4]/[month:digital:2]/[day:digital:2]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:17:"archive_year_page";a:3:{s:3:"url";s:38:"/[year:digital:4]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:18:"archive_month_page";a:3:{s:3:"url";s:56:"/[year:digital:4]/[month:digital:2]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:16:"archive_day_page";a:3:{s:3:"url";s:72:"/[year:digital:4]/[month:digital:2]/[day:digital:2]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"comment_page";a:3:{s:3:"url";s:53:"[permalink:string]/comment-page-[commentPage:digital]";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:4:"feed";a:3:{s:3:"url";s:20:"/feed[feed:string:0]";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:4:"feed";}s:8:"feedback";a:3:{s:3:"url";s:31:"[permalink:string]/[type:alpha]";s:6:"widget";s:15:"Widget_Feedback";s:6:"action";s:6:"action";}s:4:"page";a:3:{s:3:"url";s:12:"/[slug].html";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}}',
'actionTable' => 'a:0:{}',
'panelTable' => 'a:0:{}',
'attachmentTypes' => '@image@',
'secret' => Typecho_Common::randString(32, true),
'installed' => 0,
'allowXmlRpc' => 2
];
}
/**
* 获取所有可用数据库驱动
*
* @return array
*/
function install_get_db_drivers(): array {
$drivers = [];
if (Typecho_Db_Adapter_Mysqli::isAvailable()) {
$drivers['Mysqli'] = _t('Mysql 原生函数适配器');
}
if (Typecho_Db_Adapter_SQLite::isAvailable()) {
$drivers['SQLite'] = _t('SQLite 原生函数适配器 (SQLite 2.x)');
}
if (Typecho_Db_Adapter_Pgsql::isAvailable()) {
$drivers['Pgsql'] = _t('Pgsql 原生函数适配器');
}
if (Typecho_Db_Adapter_Pdo_Mysql::isAvailable()) {
$drivers['Pdo_Mysql'] = _t('Pdo 驱动 Mysql 适配器');
}
if (Typecho_Db_Adapter_Pdo_SQLite::isAvailable()) {
$drivers['Pdo_SQLite'] = _t('Pdo 驱动 SQLite 适配器 (SQLite 3.x)');
}
if (Typecho_Db_Adapter_Pdo_Pgsql::isAvailable()) {
$drivers['Pdo_Pgsql'] = _t('Pdo 驱动 PostgreSql 适配器');
}
return $drivers;
}
function install_ajax_support() {
?>
<script>
let form = document.querySelector('form'), errorBox = document.createElement('div');
form.insertBefore(errorBox, form.firstChild);
errorBox.classList.add('error', 'hidden');
function showError(error) {
let str = '<?php _t('安装程序捕捉到以下错误: " %s ". 程序被终止, 请检查您的配置信息.', '%') ?>';
errorBox.innerHTML = str.replace('%', error);
errorBox.classList.remove('hidden');
}
form.addEventListener('submit', function (e) {
e.preventDefault();
errorBox.classList.add('hidden');
fetch(this.getAttribute('action'), {
method: 'POST',
body: new FormData(this)
}).then(function (response) {
return response.json();
}).then(function (data) {
if (data.success) {
location.href = '?step=' + data.message;
} else {
showError(data.message);
}
}).catch(function (error) {
showError(error.message);
});
}, true);
</script>
<?php
}
function install_step_1() {
$langs = Widget_Options_General::getLangs();
$lang = install_get_lang();
?>
<form method="get" action="?step=2">
<h1><?php _e('欢迎使用 Typecho'); ?></h1>
<h2><?php _e('安装说明'); ?></h2>
<p><strong><?php _e('本安装程序将自动检测服务器环境是否符合最低配置需求. 如果不符合, 将在上方出现提示信息, 请按照提示信息检查您的主机配置. 如果服务器环境符合要求, 将在下方出现 "开始下一步" 的按钮, 点击此按钮即可一步完成安装.'); ?></strong></p>
<h2><?php _e('许可及协议'); ?></h2>
<p><?php _e('Typecho 基于 <a href="http://www.gnu.org/copyleft/gpl.html">GPL</a> 协议发布, 我们允许用户在 GPL 协议许可的范围内使用, 拷贝, 修改和分发此程序.'); ?>
<?php _e('在GPL许可的范围内, 您可以自由地将其用于商业以及非商业用途.'); ?></p>
<p><?php _e('Typecho 软件由其社区提供支持, 核心开发团队负责维护程序日常开发工作以及新特性的制定.'); ?>
<?php _e('如果您遇到使用上的问题, 程序中的 BUG, 以及期许的新功能, 欢迎您在社区中交流或者直接向我们贡献代码.'); ?>
<?php _e('对于贡献突出者, 他的名字将出现在贡献者名单中.'); ?></p>
<p class="submit">
<button type="submit"><?php _e('我准备好了, 开始下一步 &raquo;'); ?></button>
<?php if (count($langs) > 1): ?>
<select style="float: right" onchange="location.href='?lang=' + this.value">
<?php foreach ($langs as $key => $val): ?>
<option value="<?php echo $key; ?>"<?php if ($lang == $key): ?> selected<?php endif; ?>><?php echo $val; ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
</p>
</form>
<?php
}
function install_step_2() {
$drivers = install_get_db_drivers();
$adapter = _r('driver', key($drivers));
$parts = explode('_', $adapter);
$type = $adapter == 'Mysqli' ? 'Mysql' : array_pop($parts);
?>
<ul class="typecho-option">
<li>
<label for="dbAdapter" class="typecho-label"><?php _e('数据库适配器'); ?></label>
<select name="dbAdapter" id="dbAdapter" onchange="location.href='?step=2&driver=' + this.value">
<?php foreach ($drivers as $driver => $name): ?>
<option value="<?php echo $driver; ?>"<?php if($driver == $adapter): ?> selected="selected"<?php endif; ?>><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
<p class="description"><?php _e('请根据您的数据库类型选择合适的适配器'); ?></p>
</li>
<?php require_once './install/' . $type . '.php'; ?>
<li>
<label class="typecho-label" for="dbPrefix"><?php _e('数据库前缀'); ?></label>
<input type="text" class="text" name="dbPrefix" id="dbPrefix" value="<?php _v('dbPrefix', 'typecho_'); ?>" />
<p class="description"><?php _e('默认前缀是 "typecho_"'); ?></p>
</li>
</ul>
<?php
install_ajax_support();
}
$options = Typecho_Widget::widget('Widget_Options', install_get_default_options());
Typecho_Widget::widget('Widget_Init');
// 挡掉可能的跨站请求
if (!empty($_GET) || !empty($_POST)) {
@@ -66,12 +305,12 @@ if (!empty($_GET) || !empty($_POST)) {
* 获取传递参数
*
* @param string $name 参数名称
* @param string $default 默认值
* @return string
* @param string|null $default 默认值
*
* @return mixed
*/
function _r($name, $default = NULL) {
return isset($_REQUEST[$name]) ?
(is_array($_REQUEST[$name]) ? $default : $_REQUEST[$name]) : $default;
function _r(string $name, string $default = NULL) {
return Typecho_Request::getInstance()->get($name, $default);
}
/**
@@ -96,9 +335,8 @@ function _rFrom() {
*
* @param string $name 参数名称
* @param string $default 默认值
* @return string
*/
function _v($name, $default = '') {
function _v(string $name, string $default = '') {
echo _r($name, $default);
}
@@ -145,12 +383,12 @@ function _u() {
$options = new stdClass();
$options->generator = 'Typecho ' . Typecho_Common::VERSION;
list($soft, $currentVersion) = explode(' ', $options->generator);
[$soft, $currentVersion] = explode(' ', $options->generator);
$options->software = $soft;
$options->version = $currentVersion;
list($prefixVersion, $suffixVersion) = explode('/', $currentVersion);
[$prefixVersion, $suffixVersion] = explode('/', $currentVersion);
/** 获取语言 */
$lang = _r('lang', Typecho_Cookie::get('__typecho_lang'));
@@ -167,10 +405,11 @@ if ('zh_CN' != $lang) {
Typecho_Cookie::set('__typecho_lang', $lang);
?><!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head lang="zh-CN">
<html>
<head>
<meta charset="<?php _e('UTF-8'); ?>" />
<title><?php _e('Typecho 安装程序'); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title><?php _e('Typecho 安装程序'); ?></title>
<link rel="stylesheet" type="text/css" href="admin/css/normalize.css" />
<link rel="stylesheet" type="text/css" href="admin/css/grid.css" />
<link rel="stylesheet" type="text/css" href="admin/css/style.css" />
@@ -221,10 +460,6 @@ Typecho_Cookie::set('__typecho_lang', $lang);
<?php endif;?>
</div>
<div class="p message notice">
<a target="_blank" href="http://spreadsheets.google.com/viewform?key=pd1Gl4Ur_pbniqgebs5JRIg&hl=en">参与用户调查, 帮助我们完善产品</a>
</div>
<div class="session">
<p><?php _e('您可以将下面两个链接保存到您的收藏夹'); ?>:</p>
<ul>

View File

@@ -1,165 +1,43 @@
<?php if(!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php
$engine = '';
<li>
<label class="typecho-label" for="dbHost"><?php _e('数据库地址'); ?></label>
<input type="text" class="text" name="dbHost" id="dbHost" value="<?php _v('dbHost', 'localhost'); ?>"/>
<p class="description"><?php _e('您可能会使用 "%s"', 'localhost'); ?></p>
</li>
<li>
<label class="typecho-label" for="dbPort"><?php _e('数据库端口'); ?></label>
<input type="text" class="text" name="dbPort" id="dbPort" value="<?php _v('dbPort', '3306'); ?>"/>
<p class="description"><?php _e('如果您不知道此选项的意义, 请保留默认设置'); ?></p>
</li>
<li>
<label class="typecho-label" for="dbUser"><?php _e('数据库用户名'); ?></label>
<input type="text" class="text" name="dbUser" id="dbUser" value="<?php _v('dbUser', 'root'); ?>" />
<p class="description"><?php _e('您可能会使用 "%s"', 'root'); ?></p>
</li>
<li>
<label class="typecho-label" for="dbPassword"><?php _e('数据库密码'); ?></label>
<input type="password" class="text" name="dbPassword" id="dbPassword" value="<?php _v('dbPassword'); ?>" />
</li>
<li>
<label class="typecho-label" for="dbDatabase"><?php _e('数据库名'); ?></label>
<input type="text" class="text" name="dbDatabase" id="dbDatabase" value="<?php _v('dbDatabase', 'typecho'); ?>" />
<p class="description"><?php _e('请您指定数据库名称'); ?></p>
</li>
if (defined('SAE_MYSQL_DB') && SAE_MYSQL_DB != "app_") {
$engine = 'SAE';
} else if (!!getenv('HTTP_BAE_ENV_ADDR_SQL_IP')) {
$engine = 'BAE';
} else if (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
$engine = 'GAE';
}
?>
<li>
<label class="typecho-label" for="dbCharset"><?php _e('数据库编码'); ?></label>
<select name="dbCharset" id="dbCharset">
<option value="utf8mb4"<?php if (_r('dbCharset') == 'utf8mb4'): ?> selected<?php endif; ?>>utf8mb4</option>
<option value="utf8"<?php if (_r('dbCharset') == 'utf8'): ?> selected<?php endif; ?>>utf8</option>
</select>
<p class="description"><?php _e('选择 utf8mb4 编码至少需要 MySQL 5.5.3 版本'); ?></p>
</li>
<?php if (!empty($engine)): ?>
<h3 class="warning"><?php _e('系统将为您自动匹配 %s 环境的安装选项', $engine); ?></h3>
<?php endif; ?>
<?php if ('SAE' == $engine): ?>
<!-- SAE -->
<input type="hidden" name="config" value="array (
'host' => SAE_MYSQL_HOST_M,
'user' => SAE_MYSQL_USER,
'password' => SAE_MYSQL_PASS,
'charset' => '{charset}',
'port' => SAE_MYSQL_PORT,
'database' => SAE_MYSQL_DB
)" />
<input type="hidden" name="dbHost" value="<?php echo SAE_MYSQL_HOST_M; ?>" />
<input type="hidden" name="dbPort" value="<?php echo SAE_MYSQL_PORT; ?>" />
<input type="hidden" name="dbUser" value="<?php echo SAE_MYSQL_USER; ?>" />
<input type="hidden" name="dbPassword" value="<?php echo SAE_MYSQL_PASS; ?>" />
<input type="hidden" name="dbDatabase" value="<?php echo SAE_MYSQL_DB; ?>" />
<?php elseif ('BAE' == $engine):
$baeDbUser = "getenv('HTTP_BAE_ENV_AK')";
$baeDbPassword = "getenv('HTTP_BAE_ENV_SK')";
?>
<!-- BAE -->
<?php if (!getenv('HTTP_BAE_ENV_AK')): $baeDbUser = "'{user}'"; ?>
<li>
<label class="typecho-label" for="dbUser"><?php _e('应用API Key'); ?></label>
<input type="text" class="text" name="dbUser" id="dbUser" value="<?php _v('dbUser'); ?>" />
</li>
<?php else: ?>
<input type="hidden" name="dbUser" value="<?php echo getenv('HTTP_BAE_ENV_AK'); ?>" />
<?php endif; ?>
<?php if (!getenv('HTTP_BAE_ENV_SK')): $baeDbPassword = "'{password}'"; ?>
<li>
<label class="typecho-label" for="dbPassword"><?php _e('应用Secret Key'); ?></label>
<input type="text" class="text" name="dbPassword" id="dbPassword" value="<?php _v('dbPassword'); ?>" />
</li>
<?php else: ?>
<input type="hidden" name="dbPassword" value="<?php echo getenv('HTTP_BAE_ENV_SK'); ?>" />
<?php endif; ?>
<li>
<label class="typecho-label" for="dbDatabase"><?php _e('数据库名'); ?></label>
<input type="text" class="text" id="dbDatabase" name="dbDatabase" value="<?php _v('dbDatabase'); ?>" />
<p class="description"><?php _e('可以在MySQL服务的管理页面看到您创建的数据库名称'); ?></p>
</li>
<input type="hidden" name="config" value="array (
'host' => getenv('HTTP_BAE_ENV_ADDR_SQL_IP'),
'user' => <?php echo $baeDbUser; ?>,
'password' => <?php echo $baeDbPassword; ?>,
'charset' => '{charset}',
'port' => getenv('HTTP_BAE_ENV_ADDR_SQL_PORT'),
'database' => '{database}'
)" />
<input type="hidden" name="dbHost" value="<?php echo getenv('HTTP_BAE_ENV_ADDR_SQL_IP'); ?>" />
<input type="hidden" name="dbPort" value="<?php echo getenv('HTTP_BAE_ENV_ADDR_SQL_PORT'); ?>" />
<?php elseif ('GAE' == $engine): ?>
<!-- GAE -->
<h3 class="warning"><?php _e('系统将为您自动匹配 %s 环境的安装选项', 'GAE'); ?></h3>
<?php if (0 === strpos($adapter, 'Pdo_')): ?>
<li>
<label class="typecho-label" for="dbHost"><?php _e('数据库实例名'); ?></label>
<input type="text" class="text" name="dbHost" id="dbHost" value="<?php _v('dbHost'); ?>"/>
<p class="description"><?php _e('请填入您在Cloud SQL面板中创建的数据库实例名称, 示例: %s', '<em class="warning">/cloudsql/typecho-gae:typecho</em>'); ?></p>
</li>
<?php else: ?>
<li>
<label class="typecho-label" for="dbHost"><?php _e('数据库实例名'); ?></label>
<input type="text" class="text" name="dbHost" id="dbHost" value="<?php _v('dbHost'); ?>"/>
<p class="description"><?php _e('请填入您在Cloud SQL面板中创建的数据库实例名称, 示例: %s', '<em class="warning">:/cloudsql/typecho-gae:typecho</em>'); ?></p>
</li>
<?php endif; ?>
<li>
<label class="typecho-label" for="dbUser"><?php _e('数据库用户名'); ?></label>
<input type="text" class="text" name="dbUser" id="dbUser" value="<?php _v('dbUser'); ?>" />
</li>
<li>
<label class="typecho-label" for="dbPassword"><?php _e('数据库密码'); ?></label>
<input type="password" class="text" name="dbPassword" id="dbPassword" value="<?php _v('dbPassword'); ?>" />
</li>
<li>
<label class="typecho-label" for="dbDatabase"><?php _e('数据库名'); ?></label>
<input type="text" class="text" name="dbDatabase" id="dbDatabase" value="<?php _v('dbDatabase', 'typecho'); ?>" />
<p class="description"><?php _e('请填入您在Cloud SQL的实例中创建的数据库名称'); ?></p>
</li>
<?php if (0 === strpos($adapter, 'Pdo_')): ?>
<input type="hidden" name="dbDsn" value="mysql:dbname={database};unix_socket={host};charset={charset}" />
<input type="hidden" name="config" value="array (
'dsn' => '{dsn}',
'user' => '{user}',
'password' => '{password}'
)" />
<?php else: ?>
<input type="hidden" name="config" value="array (
'host' => '{host}',
'database' => '{database}',
'user' => '{user}',
'password' => '{password}'
)" />
<?php endif; ?>
<?php else: ?>
<li>
<label class="typecho-label" for="dbHost"><?php _e('数据库地址'); ?></label>
<input type="text" class="text" name="dbHost" id="dbHost" value="<?php _v('dbHost', 'localhost'); ?>"/>
<p class="description"><?php _e('您可能会使用 "%s"', 'localhost'); ?></p>
</li>
<li>
<label class="typecho-label" for="dbPort"><?php _e('数据库端口'); ?></label>
<input type="text" class="text" name="dbPort" id="dbPort" value="<?php _v('dbPort', '3306'); ?>"/>
<p class="description"><?php _e('如果您不知道此选项的意义, 请保留默认设置'); ?></p>
</li>
<li>
<label class="typecho-label" for="dbUser"><?php _e('数据库用户名'); ?></label>
<input type="text" class="text" name="dbUser" id="dbUser" value="<?php _v('dbUser', 'root'); ?>" />
<p class="description"><?php _e('您可能会使用 "%s"', 'root'); ?></p>
</li>
<li>
<label class="typecho-label" for="dbPassword"><?php _e('数据库密码'); ?></label>
<input type="password" class="text" name="dbPassword" id="dbPassword" value="<?php _v('dbPassword'); ?>" />
</li>
<li>
<label class="typecho-label" for="dbDatabase"><?php _e('数据库名'); ?></label>
<input type="text" class="text" name="dbDatabase" id="dbDatabase" value="<?php _v('dbDatabase', 'typecho'); ?>" />
<p class="description"><?php _e('请您指定数据库名称'); ?></p>
</li>
<?php endif; ?>
<input type="hidden" name="dbCharset" value="<?php _e('utf8'); ?>" />
<li>
<label class="typecho-label" for="dbCharset"><?php _e('数据库编码'); ?></label>
<select name="dbCharset" id="dbCharset">
<option value="utf8mb4"<?php if (_r('dbCharset') == 'utf8mb4'): ?> selected<?php endif; ?>>utf8mb4</option>
<option value="utf8"<?php if (_r('dbCharset') == 'utf8'): ?> selected<?php endif; ?>>utf8</option>
</select>
<p class="description"><?php _e('选择 utf8mb4 编码至少需要 MySQL 5.5.3 版本'); ?></p>
</li>
<li>
<label class="typecho-label" for="dbEngine"><?php _e('数据库引擎'); ?></label>
<select name="dbEngine" id="dbEngine">
<option value="InnoDB"<?php if (_r('dbEngine') == 'InnoDB'): ?> selected<?php endif; ?>>InnoDB</option>
<option value="MyISAM"<?php if (_r('dbEngine') == 'MyISAM'): ?> selected<?php endif; ?>>MyISAM</option>
</select>
</li>
<li>
<label class="typecho-label" for="dbEngine"><?php _e('数据库引擎'); ?></label>
<select name="dbEngine" id="dbEngine">
<option value="InnoDB"<?php if (_r('dbEngine') == 'InnoDB'): ?> selected<?php endif; ?>>InnoDB</option>
<option value="MyISAM"<?php if (_r('dbEngine') == 'MyISAM'): ?> selected<?php endif; ?>>MyISAM</option>
</select>
</li>

View File

@@ -1,26 +1,26 @@
<?php if(!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<li>
<label class="typecho-label" for="dbHost"><?php _e('数据库地址'); ?></label>
<input type="text" class="text" name="dbHost" id="dbHost" value="<?php _v('dbHost', 'localhost'); ?>"/>
<p class="description"><?php _e('您可能会使用 "%s"', 'localhost'); ?></p>
<label class="typecho-label" for="dbHost"><?php _e('数据库地址'); ?></label>
<input type="text" class="text" name="dbHost" id="dbHost" value="<?php _v('dbHost', 'localhost'); ?>"/>
<p class="description"><?php _e('您可能会使用 "%s"', 'localhost'); ?></p>
</li>
<li>
<label class="typecho-label" for="dbPort"><?php _e('数据库端口'); ?></label>
<input type="text" class="text" name="dbPort" id="dbPort" value="<?php _v('dbPort', '5432'); ?>"/>
<p class="description"><?php _e('如果您不知道此选项的意义, 请保留默认设置'); ?></p>
<label class="typecho-label" for="dbPort"><?php _e('数据库端口'); ?></label>
<input type="text" class="text" name="dbPort" id="dbPort" value="<?php _v('dbPort', '5432'); ?>"/>
<p class="description"><?php _e('如果您不知道此选项的意义, 请保留默认设置'); ?></p>
</li>
<li>
<label class="typecho-label" for="dbUser"><?php _e('数据库用户名'); ?></label>
<input type="text" class="text" name="dbUser" id="dbUser" value="<?php _v('dbUser', 'postgres'); ?>" />
<p class="description"><?php _e('您可能会使用 "%s"', 'postgres'); ?></p>
<label class="typecho-label" for="dbUser"><?php _e('数据库用户名'); ?></label>
<input type="text" class="text" name="dbUser" id="dbUser" value="<?php _v('dbUser', 'postgres'); ?>" />
<p class="description"><?php _e('您可能会使用 "%s"', 'postgres'); ?></p>
</li>
<li>
<label class="typecho-label" for="dbPassword"><?php _e('数据库密码'); ?></label>
<input type="password" class="text" name="dbPassword" id="dbPassword" value="<?php _v('dbPassword'); ?>" />
<label class="typecho-label" for="dbPassword"><?php _e('数据库密码'); ?></label>
<input type="password" class="text" name="dbPassword" id="dbPassword" value="<?php _v('dbPassword'); ?>" />
</li>
<li>
<label class="typecho-label" for="dbDatabase"><?php _e('数据库名'); ?></label>
<input type="text" class="text" name="dbDatabase" id="dbDatabase" value="<?php _v('dbDatabase', 'typecho'); ?>" />
<p class="description"><?php _e('请您指定数据库名称'); ?></p>
<label class="typecho-label" for="dbDatabase"><?php _e('数据库名'); ?></label>
<input type="text" class="text" name="dbDatabase" id="dbDatabase" value="<?php _v('dbDatabase', 'typecho'); ?>" />
<p class="description"><?php _e('请您指定数据库名称'); ?></p>
</li>
<input type="hidden" name="dbCharset" value="<?php _e('utf8'); ?>" />

View File

@@ -1,7 +1,7 @@
<?php if(!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $defaultDir = dirname($_SERVER['SCRIPT_FILENAME']) . '/usr/' . uniqid() . '.db'; ?>
<?php $defaultDir = __TYPECHO_ROOT_DIR__ . '/usr/' . uniqid() . '.db'; ?>
<li>
<label class="typecho-label" for="dbFile"><?php _e('数据库文件路径'); ?></label>
<input type="text" class="text" name="dbFile" id="dbFile" value="<?php _v('dbFile', $defaultDir); ?>"/>
<p class="description"><?php _e('"%s" 是我们为您自动生成的地址', $defaultDir); ?></p>
<label class="typecho-label" for="dbFile"><?php _e('数据库文件路径'); ?></label>
<input type="text" class="text" name="dbFile" id="dbFile" value="<?php _v('dbFile', $defaultDir); ?>"/>
<p class="description"><?php _e('"%s" 是我们为您自动生成的地址', $defaultDir); ?></p>
</li>

View File

@@ -22,7 +22,7 @@ class Typecho_Request
* @access private
* @var array
*/
private $_params = array();
private $_params = [];
/**
* 路径信息
@@ -30,7 +30,7 @@ class Typecho_Request
* @access private
* @var string
*/
private $_pathInfo = NULL;
private $_pathInfo = null;
/**
* 服务端参数
@@ -38,31 +38,31 @@ class Typecho_Request
* @access private
* @var array
*/
private $_server = array();
private $_server = [];
/**
* _requestUri
*
* _requestUri
*
* @var string
* @access private
*/
private $_requestUri = NULL;
private $_requestUri = null;
/**
* _requestRoot
*
* _requestRoot
*
* @var mixed
* @access private
*/
private $_requestRoot = NULL;
private $_requestRoot = null;
/**
* 获取baseurl
*
*
* @var string
* @access private
*/
private $_baseUrl = NULL;
private $_baseUrl = null;
/**
* 客户端ip地址
@@ -70,7 +70,7 @@ class Typecho_Request
* @access private
* @var string
*/
private $_ip = NULL;
private $_ip = null;
/**
* 客户端字符串
@@ -78,7 +78,7 @@ class Typecho_Request
* @access private
* @var string
*/
private $_agent = NULL;
private $_agent = null;
/**
* 来源页
@@ -86,7 +86,7 @@ class Typecho_Request
* @access private
* @var string
*/
private $_referer = NULL;
private $_referer = null;
/**
* 单例句柄
@@ -94,7 +94,7 @@ class Typecho_Request
* @access private
* @var Typecho_Request
*/
private static $_instance = NULL;
private static $_instance = null;
/**
* 全部的http数据
@@ -103,13 +103,13 @@ class Typecho_Request
*/
private static $_httpParams = false;
/**
* 域名前缀
*
* @var string
*/
private static $_urlPrefix = NULL;
private $_urlPrefix = null;
/**
* 当前过滤器
@@ -117,7 +117,7 @@ class Typecho_Request
* @access private
* @var array
*/
private $_filter = array();
private $_filter = [];
/**
* 支持的过滤器列表
@@ -125,14 +125,14 @@ class Typecho_Request
* @access private
* @var string
*/
private static $_supportFilters = array(
'int' => 'intval',
'integer' => 'intval',
'search' => array('Typecho_Common', 'filterSearchQuery'),
'xss' => array('Typecho_Common', 'removeXSS'),
'url' => array('Typecho_Common', 'safeUrl'),
'slug' => array('Typecho_Common', 'slugName')
);
private static $_supportFilters = [
'int' => 'intval',
'integer' => 'intval',
'search' => ['Typecho_Common', 'filterSearchQuery'],
'xss' => ['Typecho_Common', 'removeXSS'],
'url' => ['Typecho_Common', 'safeUrl'],
'slug' => ['Typecho_Common', 'slugName']
];
/**
* 获取单例句柄
@@ -142,7 +142,7 @@ class Typecho_Request
*/
public static function getInstance()
{
if (NULL === self::$_instance) {
if (null === self::$_instance) {
self::$_instance = new Typecho_Request();
}
@@ -153,7 +153,9 @@ class Typecho_Request
* 应用过滤器
*
* @access private
*
* @param mixed $value
*
* @return mixed
*/
private function _applyFilter($value)
@@ -161,10 +163,10 @@ class Typecho_Request
if ($this->_filter) {
foreach ($this->_filter as $filter) {
$value = is_array($value) ? array_map($filter, $value) :
call_user_func($filter, $value);
call_user_func($filter, $value);
}
$this->_filter = array();
$this->_filter = [];
}
return $value;
@@ -174,13 +176,14 @@ class Typecho_Request
* 检查ip地址是否合法
*
* @param string $ip ip地址
*
* @return boolean
*/
private function _checkIp($ip)
{
if (__TYPECHO_FILTER_SUPPORTED__) {
return false !== (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)
|| filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
|| filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
}
return preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)
@@ -191,12 +194,13 @@ class Typecho_Request
* 检查ua是否合法
*
* @param string $agent ua字符串
*
* @return boolean
*/
private function _checkAgent($agent)
{
return preg_match("/^[_a-z0-9- ,:;=#@\.\(\)\/\+\*\?]+$/i", $agent);
}
}
/**
* 初始化变量
@@ -205,28 +209,28 @@ class Typecho_Request
{
if (false === self::$_httpParams) {
self::$_httpParams = array_filter(array_merge($_POST, $_GET),
array('Typecho_Common', 'checkStrEncoding'));
['Typecho_Common', 'checkStrEncoding']);
}
}
/**
* 获取url前缀
*
* 获取url前缀
*
* @access public
* @return string
*/
public static function getUrlPrefix()
public function getUrlPrefix()
{
if (empty(self::$_urlPrefix)) {
if (empty($this->_urlPrefix)) {
if (defined('__TYPECHO_URL_PREFIX__')) {
self::$_urlPrefix = __TYPECHO_URL_PREFIX__;
$this->_urlPrefix = __TYPECHO_URL_PREFIX__;
} else if (!defined('__TYPECHO_CLI__')) {
self::$_urlPrefix = (self::isSecure() ? 'https' : 'http') . '://'
$this->_urlPrefix = ($this->isSecure() ? 'https' : 'http') . '://'
. (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']);
}
}
return self::$_urlPrefix;
return $this->_urlPrefix;
}
/**
@@ -235,7 +239,7 @@ class Typecho_Request
* @access public
* @return boolean
*/
public static function isSecure()
public function isSecure()
{
return (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && !strcasecmp('https', $_SERVER['HTTP_X_FORWARDED_PROTO']))
|| (!empty($_SERVER['HTTP_X_FORWARDED_PORT']) && 443 == $_SERVER['HTTP_X_FORWARDED_PORT'])
@@ -256,7 +260,7 @@ class Typecho_Request
foreach ($filters as $filter) {
$this->_filter[] = is_string($filter) && isset(self::$_supportFilters[$filter])
? self::$_supportFilters[$filter] : $filter;
? self::$_supportFilters[$filter] : $filter;
}
return $this;
@@ -266,7 +270,9 @@ class Typecho_Request
* 获取实际传递参数(magic)
*
* @access public
*
* @param string $key 指定参数
*
* @return mixed
*/
public function __get($key)
@@ -278,24 +284,28 @@ class Typecho_Request
* 判断参数是否存在
*
* @access public
*
* @param string $key 指定参数
*
* @return boolean
*/
public function __isset($key)
{
return isset(self::$_httpParams[$key])
|| isset($this->_params[$key]);
|| isset($this->_params[$key]);
}
/**
* 获取实际传递参数
*
* @access public
*
* @param string $key 指定参数
* @param mixed $default 默认参数 (default: NULL)
*
* @return mixed
*/
public function get($key, $default = NULL)
public function get($key, $default = null)
{
switch (true) {
case isset($this->_params[$key]):
@@ -317,15 +327,16 @@ class Typecho_Request
* 获取一个数组
*
* @param $key
*
* @return array
*/
public function getArray($key)
{
$result = isset($this->_params[$key]) ? $this->_params[$key] :
(isset(self::$_httpParams[$key]) ? self::$_httpParams[$key] : array());
(isset(self::$_httpParams[$key]) ? self::$_httpParams[$key] : []);
$result = is_array($result) ? $result
: (strlen($result) > 0 ? array($result) : array());
: (strlen($result) > 0 ? [$result] : []);
return $this->_applyFilter($result);
}
@@ -333,12 +344,14 @@ class Typecho_Request
* 从参数列表指定的值中获取http传递参数
*
* @access public
*
* @param mixed $params 指定的参数
*
* @return array
*/
public function from($params)
{
$result = array();
$result = [];
$args = is_array($params) ? $params : func_get_args();
foreach ($args as $arg) {
@@ -352,8 +365,10 @@ class Typecho_Request
* 设置http传递参数
*
* @access public
*
* @param string $name 指定的参数
* @param mixed $value 参数值
*
* @return void
*/
public function setParam($name, $value)
@@ -367,7 +382,9 @@ class Typecho_Request
* 设置多个参数
*
* @access public
*
* @param mixed $params 参数列表
*
* @return void
*/
public function setParams($params)
@@ -379,20 +396,20 @@ class Typecho_Request
}
$this->_params = array_merge($this->_params,
array_filter($params, array('Typecho_Common', 'checkStrEncoding')));
array_filter($params, ['Typecho_Common', 'checkStrEncoding']));
}
/**
* getRequestRoot
*
* getRequestRoot
*
* @access public
* @return string
*/
public function getRequestRoot()
{
if (NULL === $this->_requestRoot) {
$root = rtrim(self::getUrlPrefix() . $this->getBaseUrl(), '/') . '/';
if (null === $this->_requestRoot) {
$root = rtrim($this->getUrlPrefix() . $this->getBaseUrl(), '/') . '/';
$pos = strrpos($root, '.php/');
if ($pos) {
$root = dirname(substr($root, 0, $pos));
@@ -406,18 +423,18 @@ class Typecho_Request
/**
* 获取当前请求url
*
*
* @access public
* @return string
*/
public function getRequestUrl()
{
return self::getUrlPrefix() . $this->getRequestUri();
return $this->getUrlPrefix() . $this->getRequestUri();
}
/**
* 获取请求地址
*
*
* @access public
* @return string
*/
@@ -438,16 +455,16 @@ class Typecho_Request
&& $_SERVER['IIS_WasUrlRewritten'] == '1'
&& isset($_SERVER['UNENCODED_URL'])
&& $_SERVER['UNENCODED_URL'] != ''
) {
) {
$requestUri = $_SERVER['UNENCODED_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
$parts = @parse_url($requestUri);
$parts = @parse_url($requestUri);
if (isset($_SERVER['HTTP_HOST']) && strstr($requestUri, $_SERVER['HTTP_HOST'])) {
if (false !== $parts) {
$requestUri = (empty($parts['path']) ? '' : $parts['path'])
. ((empty($parts['query'])) ? '' : '?' . $parts['query']);
$requestUri = (empty($parts['path']) ? '' : $parts['path'])
. ((empty($parts['query'])) ? '' : '?' . $parts['query']);
}
} elseif (!empty($_SERVER['QUERY_STRING']) && empty($parts['query'])) {
// fix query missing
@@ -464,14 +481,14 @@ class Typecho_Request
}
/**
* getBaseUrl
*
* getBaseUrl
*
* @access public
* @return string
*/
public function getBaseUrl()
{
if (NULL !== $this->_baseUrl) {
if (null !== $this->_baseUrl) {
return $this->_baseUrl;
}
@@ -487,22 +504,22 @@ class Typecho_Request
} else {
// Backtrack up the script_filename to find the portion matching
// php_self
$path = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';
$file = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : '';
$segs = explode('/', trim($file, '/'));
$segs = array_reverse($segs);
$index = 0;
$last = count($segs);
$path = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';
$file = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : '';
$segs = explode('/', trim($file, '/'));
$segs = array_reverse($segs);
$index = 0;
$last = count($segs);
$baseUrl = '';
do {
$seg = $segs[$index];
$seg = $segs[$index];
$baseUrl = '/' . $seg . $baseUrl;
++$index;
} while (($last > $index) && (false !== ($pos = strpos($path, $baseUrl))) && (0 != $pos));
}
// Does the baseUrl have anything in common with the request_uri?
$finalBaseUrl = NULL;
$finalBaseUrl = null;
$requestUri = $this->getRequestUri();
if (0 === strpos($requestUri, $baseUrl)) {
@@ -515,25 +532,26 @@ class Typecho_Request
// no match whatsoever; set it blank
$finalBaseUrl = '';
} else if ((strlen($requestUri) >= strlen($baseUrl))
&& ((false !== ($pos = strpos($requestUri, $baseUrl))) && ($pos !== 0)))
{
&& ((false !== ($pos = strpos($requestUri, $baseUrl))) && ($pos !== 0))) {
// If using mod_rewrite or ISAPI_Rewrite strip the script filename
// out of baseUrl. $pos !== 0 makes sure it is not matching a value
// from PATH_INFO or QUERY_STRING
$baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
}
return ($this->_baseUrl = (NULL === $finalBaseUrl) ? rtrim($baseUrl, '/') : $finalBaseUrl);
return ($this->_baseUrl = (null === $finalBaseUrl) ? rtrim($baseUrl, '/') : $finalBaseUrl);
}
/**
* 根据当前uri构造指定参数的uri
*
* @access public
*
* @param mixed $parameter 指定的参数
*
* @return string
*/
public function makeUriByRequest($parameter = NULL)
public function makeUriByRequest($parameter = null)
{
/** 初始化地址 */
$requestUri = $this->getRequestUrl();
@@ -563,19 +581,21 @@ class Typecho_Request
* 获取当前pathinfo
*
* @access public
*
* @param string $inputEncoding 输入编码
* @param string $outputEncoding 输出编码
*
* @return string
*/
public function getPathInfo($inputEncoding = NULL, $outputEncoding = NULL)
public function getPathInfo($inputEncoding = null, $outputEncoding = null)
{
/** 缓存信息 */
if (NULL !== $this->_pathInfo) {
if (null !== $this->_pathInfo) {
return $this->_pathInfo;
}
//参考Zend Framework对pahtinfo的处理, 更好的兼容性
$pathInfo = NULL;
$pathInfo = null;
//处理requestUri
$requestUri = $this->getRequestUri();
@@ -586,12 +606,11 @@ class Typecho_Request
$requestUri = substr($requestUri, 0, $pos);
}
if ((NULL !== $finalBaseUrl)
&& (false === ($pathInfo = substr($requestUri, strlen($finalBaseUrl)))))
{
if ((null !== $finalBaseUrl)
&& (false === ($pathInfo = substr($requestUri, strlen($finalBaseUrl))))) {
// If substr() returns false then PATH_INFO is set to an empty string
$pathInfo = '/';
} elseif (NULL === $finalBaseUrl) {
} elseif (null === $finalBaseUrl) {
$pathInfo = $requestUri;
}
@@ -599,8 +618,8 @@ class Typecho_Request
//针对iis的utf8编码做强制转换
//参考http://docs.moodle.org/ja/%E5%A4%9A%E8%A8%80%E8%AA%9E%E5%AF%BE%E5%BF%9C%EF%BC%9A%E3%82%B5%E3%83%BC%E3%83%90%E3%81%AE%E8%A8%AD%E5%AE%9A
if (!empty($inputEncoding) && !empty($outputEncoding) &&
(stripos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false
|| stripos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false)) {
(stripos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false
|| stripos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false)) {
if (function_exists('mb_convert_encoding')) {
$pathInfo = mb_convert_encoding($pathInfo, $outputEncoding, $inputEncoding);
} else if (function_exists('iconv')) {
@@ -619,13 +638,15 @@ class Typecho_Request
* 设置服务端参数
*
* @access public
*
* @param string $name 参数名称
* @param mixed $value 参数值
*
* @return void
*/
public function setServer($name, $value = NULL)
public function setServer($name, $value = null)
{
if (NULL == $value) {
if (null == $value) {
if (isset($_SERVER[$name])) {
$value = $_SERVER[$name];
} else if (isset($_ENV[$name])) {
@@ -640,7 +661,9 @@ class Typecho_Request
* 获取环境变量
*
* @access public
*
* @param string $name 获取环境变量名
*
* @return string
*/
public function getServer($name)
@@ -656,21 +679,22 @@ class Typecho_Request
* 设置ip地址
*
* @access public
*
* @param string $ip
*/
public function setIp($ip = NULL)
public function setIp($ip = null)
{
if (!empty($ip)) {
$this->_ip = $ip;
} else {
switch (true) {
case defined('__TYPECHO_IP_SOURCE__') && NULL !== $this->getServer(__TYPECHO_IP_SOURCE__):
case defined('__TYPECHO_IP_SOURCE__') && null !== $this->getServer(__TYPECHO_IP_SOURCE__):
list($this->_ip) = array_map('trim', explode(',', $this->getServer(__TYPECHO_IP_SOURCE__)));
break;
case NULL !== $this->getServer('REMOTE_ADDR'):
case null !== $this->getServer('REMOTE_ADDR'):
$this->_ip = $this->getServer('REMOTE_ADDR');
break;
case NULL !== $this->getServer('HTTP_CLIENT_IP'):
case null !== $this->getServer('HTTP_CLIENT_IP'):
$this->_ip = $this->getServer('HTTP_CLIENT_IP');
break;
default:
@@ -691,7 +715,7 @@ class Typecho_Request
*/
public function getIp()
{
if (NULL === $this->_ip) {
if (null === $this->_ip) {
$this->setIp();
}
@@ -702,12 +726,14 @@ class Typecho_Request
* 设置客户端
*
* @access public
*
* @param string $agent 客户端字符串
*
* @return void
*/
public function setAgent($agent = NULL)
public function setAgent($agent = null)
{
$agent = (NULL === $agent) ? $this->getServer('HTTP_USER_AGENT') : $agent;
$agent = (null === $agent) ? $this->getServer('HTTP_USER_AGENT') : $agent;
$this->_agent = self::_checkAgent($agent) ? $agent : '';
}
@@ -719,7 +745,7 @@ class Typecho_Request
*/
public function getAgent()
{
if (NULL === $this->_agent) {
if (null === $this->_agent) {
$this->setAgent();
}
@@ -730,12 +756,14 @@ class Typecho_Request
* 设置来源页
*
* @access public
*
* @param string $referer 客户端字符串
*
* @return void
*/
public function setReferer($referer = NULL)
public function setReferer($referer = null)
{
$this->_referer = (NULL === $referer) ? $this->getServer('HTTP_REFERER') : $referer;
$this->_referer = (null === $referer) ? $this->getServer('HTTP_REFERER') : $referer;
}
/**
@@ -746,7 +774,7 @@ class Typecho_Request
*/
public function getReferer()
{
if (NULL === $this->_referer) {
if (null === $this->_referer) {
$this->setReferer();
}
@@ -784,7 +812,7 @@ class Typecho_Request
public function isPut()
{
return 'PUT' == $this->getServer('REQUEST_METHOD');
}
}
/**
* 判断是否为ajax
@@ -809,8 +837,8 @@ class Typecho_Request
}
/**
* isMobile
*
* isMobile
*
* @static
* @access public
* @return boolean
@@ -818,14 +846,16 @@ class Typecho_Request
public function isMobile()
{
$userAgent = $this->getAgent();
return preg_match('/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$userAgent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($userAgent,0,4));
return preg_match('/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $userAgent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr($userAgent, 0, 4));
}
/**
* 判断输入是否满足要求
*
* @access public
*
* @param mixed $query 条件
*
* @return boolean
*/
public function is($query)

View File

@@ -27,7 +27,7 @@ class Widget_Init extends Typecho_Widget
$options = $this->widget('Widget_Options');
/** 检查安装状态 */
if (!$options->installed) {
if (!defined('__TYPECHO_INSTALL__') && !$options->installed) {
$options->update(array('value' => 1), Typecho_Db::get()->sql()->where('name = ?', 'installed'));
}
@@ -74,7 +74,7 @@ class Widget_Init extends Typecho_Widget
Typecho_Date::setTimezoneOffset($options->timezone);
/** 开始会话, 减小负载只针对后台打开session支持 */
if ($this->widget('Widget_User')->hasLogin()) {
if (!defined('__TYPECHO_INSTALL__') && $this->widget('Widget_User')->hasLogin()) {
@session_start();
}

View File

@@ -52,12 +52,17 @@ class Widget_Options extends Typecho_Widget
* @param mixed $response response对象
* @param mixed $params 参数列表
*/
public function __construct($request, $response, $params = NULL)
public function __construct($request, $response, $params = null)
{
parent::__construct($request, $response, $params);
parent::__construct($request, $response, null);
/** 初始化数据库 */
$this->db = Typecho_Db::get();
if (!empty($params)) {
// 使用参数初始化而不使用数据库
$this->row = $params;
} else {
/** 初始化数据库 */
$this->db = Typecho_Db::get();
}
}
/**
@@ -335,7 +340,7 @@ class Widget_Options extends Typecho_Widget
{
$attachmentTypesResult = array();
if (NULL != $this->attachmentTypes) {
if (null != $this->attachmentTypes) {
$attachmentTypes = str_replace(
array('@image@', '@media@', '@doc@'),
array('gif,jpg,jpeg,png,tiff,bmp', 'mp3,mp4,mov,wmv,wma,rmvb,rm,avi,flv,ogg,oga,ogv',
@@ -355,12 +360,14 @@ class Widget_Options extends Typecho_Widget
*/
public function execute()
{
$this->db->fetchAll($this->db->select()->from('table.options')
->where('user = 0'), array($this, 'push'));
if (!empty($this->db)) {
$this->db->fetchAll($this->db->select()->from('table.options')
->where('user = 0'), array($this, 'push'));
}
/** 支持皮肤变量重载 */
if (!empty($this->row['theme:' . $this->row['theme']])) {
$themeOptions = NULL;
$themeOptions = null;
/** 解析变量 */
if ($themeOptions = unserialize($this->row['theme:' . $this->row['theme']])) {
@@ -387,7 +394,7 @@ class Widget_Options extends Typecho_Widget
}
$this->originalSiteUrl = $this->siteUrl;
$this->siteUrl = Typecho_Common::url(NULL, $this->siteUrl);
$this->siteUrl = Typecho_Common::url(null, $this->siteUrl);
$this->plugins = unserialize($this->plugins);
/** 动态判断皮肤目录 */
@@ -400,7 +407,7 @@ class Widget_Options extends Typecho_Widget
/** 自动初始化路由表 */
$this->routingTable = unserialize($this->routingTable);
if (!isset($this->routingTable[0])) {
if (!empty($this->db) && !isset($this->routingTable[0])) {
/** 解析路由并缓存 */
$parser = new Typecho_Router_Parser($this->routingTable);
$parsedRoutingTable = $parser->parse();
@@ -431,7 +438,7 @@ class Widget_Options extends Typecho_Widget
* @param string $path 子路径
* @return void
*/
public function siteUrl($path = NULL)
public function siteUrl($path = null)
{
echo Typecho_Common::url($path, $this->siteUrl);
}
@@ -443,7 +450,7 @@ class Widget_Options extends Typecho_Widget
* @param string $path 子路径
* @return void
*/
public function index($path = NULL)
public function index($path = null)
{
echo Typecho_Common::url($path, $this->index);
}
@@ -456,7 +463,7 @@ class Widget_Options extends Typecho_Widget
* @param string $theme 模版名称
* @return string
*/
public function themeUrl($path = NULL, $theme = NULL)
public function themeUrl($path = null, $theme = null)
{
if (empty($theme)) {
echo Typecho_Common::url($path, $this->themeUrl);
@@ -475,7 +482,7 @@ class Widget_Options extends Typecho_Widget
* @param string $path 子路径
* @return void
*/
public function pluginUrl($path = NULL)
public function pluginUrl($path = null)
{
echo Typecho_Common::url($path, $this->pluginUrl);
}
@@ -498,7 +505,7 @@ class Widget_Options extends Typecho_Widget
* @param $plugin
* @return string
*/
public function pluginDir($plugin = NULL)
public function pluginDir($plugin = null)
{
return __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__;
}
@@ -510,7 +517,7 @@ class Widget_Options extends Typecho_Widget
* @param string $path 子路径
* @return void
*/
public function adminUrl($path = NULL)
public function adminUrl($path = null)
{
echo Typecho_Common::url($path, $this->adminUrl);
}
@@ -522,7 +529,7 @@ class Widget_Options extends Typecho_Widget
* @param string $file
* @return void|string
*/
public function adminStaticUrl($type, $file = NULL)
public function adminStaticUrl($type, $file = null)
{
$url = Typecho_Common::url($type, $this->adminUrl);