PageRenderTime 50ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/install.php

https://github.com/alishtory/typecho
PHP | 628 lines | 494 code | 65 blank | 69 comment | 100 complexity | 2a22b73f6321fec8de426b3d7defd5c0 MD5 | raw file
  1. <?php
  2. /**
  3. * Typecho Blog Platform
  4. *
  5. * @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
  6. * @license GNU General Public License 2.0
  7. * @version $Id$
  8. */
  9. /** 定义根目录 */
  10. define('__TYPECHO_ROOT_DIR__', dirname(__FILE__));
  11. /** 定义插件目录(相对路径) */
  12. define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins');
  13. /** 定义模板目录(相对路径) */
  14. define('__TYPECHO_THEME_DIR__', '/usr/themes');
  15. /** 后台路径(相对路径) */
  16. define('__TYPECHO_ADMIN_DIR__', '/admin/');
  17. /** 设置包含路径 */
  18. @set_include_path(get_include_path() . PATH_SEPARATOR .
  19. __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR .
  20. __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__);
  21. /** 载入API支持 */
  22. require_once 'Typecho/Common.php';
  23. /** 载入Response支持 */
  24. require_once 'Typecho/Response.php';
  25. /** 载入配置支持 */
  26. require_once 'Typecho/Config.php';
  27. /** 载入异常支持 */
  28. require_once 'Typecho/Exception.php';
  29. /** 载入插件支持 */
  30. require_once 'Typecho/Plugin.php';
  31. /** 载入国际化支持 */
  32. require_once 'Typecho/I18n.php';
  33. /** 载入数据库支持 */
  34. require_once 'Typecho/Db.php';
  35. /** 载入路由器支持 */
  36. require_once 'Typecho/Router.php';
  37. /** 程序初始化 */
  38. Typecho_Common::init();
  39. ob_start();
  40. session_start();
  41. //判断是否已经安装
  42. if (!isset($_GET['finish']) && file_exists(__TYPECHO_ROOT_DIR__ . '/config.inc.php') && empty($_SESSION['typecho'])) {
  43. exit;
  44. }
  45. // 挡掉可能的跨站请求
  46. if (!empty($_GET) || !empty($_POST)) {
  47. if (empty($_SERVER['HTTP_REFERER'])) {
  48. exit;
  49. }
  50. $parts = parse_url($_SERVER['HTTP_REFERER']);
  51. if (empty($parts['host']) || $_SERVER['HTTP_HOST'] != $parts['host']) {
  52. exit;
  53. }
  54. }
  55. /**
  56. * 获取传递参数
  57. *
  58. * @param string $name 参数名称
  59. * @param string $default 默认值
  60. * @return string
  61. */
  62. function _r($name, $default = NULL) {
  63. return isset($_REQUEST[$name]) ?
  64. (is_array($_REQUEST[$name]) ? $default : $_REQUEST[$name]) : $default;
  65. }
  66. /**
  67. * 获取多个传递参数
  68. *
  69. * @return array
  70. */
  71. function _rFrom() {
  72. $result = array();
  73. $params = func_get_args();
  74. foreach ($params as $param) {
  75. $result[$param] = isset($_REQUEST[$param]) ?
  76. (is_array($_REQUEST[$param]) ? NULL : $_REQUEST[$param]) : NULL;
  77. }
  78. return $result;
  79. }
  80. /**
  81. * 输出传递参数
  82. *
  83. * @param string $name 参数名称
  84. * @param string $default 默认值
  85. * @return string
  86. */
  87. function _v($name, $default = '') {
  88. echo _r($name, $default);
  89. }
  90. /**
  91. * 判断是否兼容某个环境(perform)
  92. *
  93. * @param string $adapter 适配器
  94. * @return boolean
  95. */
  96. function _p($adapter) {
  97. switch ($adapter) {
  98. case 'Mysql':
  99. return Typecho_Db_Adapter_Mysql::isAvailable();
  100. case 'Pdo_Mysql':
  101. return Typecho_Db_Adapter_Pdo_Mysql::isAvailable();
  102. case 'SQLite':
  103. return Typecho_Db_Adapter_SQLite::isAvailable();
  104. case 'Pdo_SQLite':
  105. return Typecho_Db_Adapter_Pdo_SQLite::isAvailable();
  106. case 'Pgsql':
  107. return Typecho_Db_Adapter_Pgsql::isAvailable();
  108. case 'Pdo_Pgsql':
  109. return Typecho_Db_Adapter_Pdo_Pgsql::isAvailable();
  110. default:
  111. return false;
  112. }
  113. }
  114. /**
  115. * 获取url地址
  116. *
  117. * @return string
  118. */
  119. function _u() {
  120. $url = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
  121. if (isset($_SERVER["QUERY_STRING"])) {
  122. $url = str_replace("?" . $_SERVER["QUERY_STRING"], "", $url);
  123. }
  124. return dirname($url);
  125. }
  126. $options = new stdClass();
  127. $options->generator = 'Typecho ' . Typecho_Common::VERSION;
  128. list($soft, $currentVersion) = explode(' ', $options->generator);
  129. $options->software = $soft;
  130. $options->version = $currentVersion;
  131. list($prefixVersion, $suffixVersion) = explode('/', $currentVersion);
  132. ?><!DOCTYPE HTML>
  133. <html xmlns="http://www.w3.org/1999/xhtml">
  134. <head lang="zh-CN">
  135. <meta charset="<?php _e('UTF-8'); ?>" />
  136. <title><?php _e('Typecho 安装程序'); ?></title>
  137. <link rel="stylesheet" type="text/css" href="admin/css/normalize.css" />
  138. <link rel="stylesheet" type="text/css" href="admin/css/grid.css" />
  139. <link rel="stylesheet" type="text/css" href="admin/css/style.css" />
  140. </head>
  141. <body>
  142. <div class="typecho-install-patch">
  143. <h1>Typecho</h1>
  144. <ol class="path">
  145. <li<?php if (!isset($_GET['finish']) && !isset($_GET['config'])) : ?> class="current"<?php endif; ?>><span>1</span><?php _e('欢迎使用'); ?></li>
  146. <li<?php if (isset($_GET['config'])) : ?> class="current"<?php endif; ?>><span>2</span><?php _e('初始化配置'); ?></li>
  147. <li<?php if (isset($_GET['start'])) : ?> class="current"<?php endif; ?>><span>3</span><?php _e('开始安装'); ?></li>
  148. <li<?php if (isset($_GET['finish'])) : ?> class="current"<?php endif; ?>><span>4</span><?php _e('安装成功'); ?></li>
  149. </ol>
  150. </div>
  151. <div class="container">
  152. <div class="row">
  153. <div class="col-mb-12 col-tb-8 col-tb-offset-2">
  154. <div class="column-14 start-06 typecho-install">
  155. <?php if (isset($_GET['finish'])) : ?>
  156. <?php if (!@file_exists(__TYPECHO_ROOT_DIR__ . '/config.inc.php')) : ?>
  157. <h1 class="typecho-install-title"><?php _e('安装失败!'); ?></h1>
  158. <div class="typecho-install-body">
  159. <form method="post" action="?config" name="config">
  160. <p class="message error"><?php _e('您没有上传 config.inc.php 文件,请您重新安装!'); ?> <button class="btn primary" type="submit"><?php _e('重新安装 &raquo;'); ?></button></p>
  161. </form>
  162. </div>
  163. <?php elseif (!Typecho_Cookie::get('__typecho_config')): ?>
  164. <h1 class="typecho-install-title"><?php _e('没有安装!'); ?></h1>
  165. <div class="typecho-install-body">
  166. <form method="post" action="?config" name="config">
  167. <p class="message error"><?php _e('您没有执行安装步骤,请您重新安装!'); ?> <button class="btn primary" type="submit"><?php _e('重新安装 &raquo;'); ?></button></p>
  168. </form>
  169. </div>
  170. <?php else : ?>
  171. <?php
  172. $config = unserialize(base64_decode(Typecho_Cookie::get('__typecho_config')));
  173. Typecho_Cookie::delete('__typecho_config');
  174. $db = new Typecho_Db($config['adapter'], $config['prefix']);
  175. $db->addServer($config, Typecho_Db::READ | Typecho_Db::WRITE);
  176. Typecho_Db::set($db);
  177. ?>
  178. <h1 class="typecho-install-title"><?php _e('安装成功!'); ?></h1>
  179. <div class="typecho-install-body">
  180. <div class="message success">
  181. <?php if(isset($_GET['use_old']) ) : ?>
  182. <?php _e('您选择了使用原有的数据, 您的用户名和密码和原来的一致'); ?>
  183. <?php else : ?>
  184. <?php if (isset($_REQUEST['user']) && isset($_REQUEST['password'])): ?>
  185. <?php _e('您的用户名是'); ?>: <strong class="mono"><?php echo htmlspecialchars(_r('user')); ?></strong><br>
  186. <?php _e('您的密码是'); ?>: <strong class="mono"><?php echo htmlspecialchars(_r('password')); ?></strong>
  187. <?php endif;?>
  188. <?php endif;?>
  189. </div>
  190. <div class="p message notice">
  191. <a target="_blank" href="http://spreadsheets.google.com/viewform?key=pd1Gl4Ur_pbniqgebs5JRIg&hl=en">参与用户调查, 帮助我们完善产品</a>
  192. </div>
  193. <div class="session">
  194. <p><?php _e('您可以将下面两个链接保存到您的收藏夹'); ?>:</p>
  195. <ul>
  196. <?php
  197. if (isset($_REQUEST['user']) && isset($_REQUEST['password'])) {
  198. $loginUrl = _u() . '/index.php/action/login?name=' . urlencode(_r('user')) . '&password='
  199. . urlencode(_r('password')) . '&referer=' . _u() . '/admin/index.php';
  200. $loginUrl = Typecho_Widget::widget('Widget_Security')->getTokenUrl($loginUrl);
  201. } else {
  202. $loginUrl = _u() . '/admin/index.php';
  203. }
  204. ?>
  205. <li><a href="<?php echo $loginUrl; ?>"><?php _e('点击这里访问您的控制面板'); ?></a></li>
  206. <li><a href="<?php echo _u(); ?>/index.php"><?php _e('点击这里查看您的 Blog'); ?></a></li>
  207. </ul>
  208. </div>
  209. <p><?php _e('希望您能尽情享用 Typecho 带来的乐趣!'); ?></p>
  210. </div>
  211. <?php endif;?>
  212. <?php elseif (isset($_GET['start'])): ?>
  213. <?php if (!@file_exists(__TYPECHO_ROOT_DIR__ . '/config.inc.php')) : ?>
  214. <h1 class="typecho-install-title"><?php _e('安装失败!'); ?></h1>
  215. <div class="typecho-install-body">
  216. <form method="post" action="?config" name="config">
  217. <p class="message error"><?php _e('您没有上传 config.inc.php 文件,请您重新安装!'); ?> <button class="btn primary" type="submit"><?php _e('重新安装 &raquo;'); ?></button></p>
  218. </form>
  219. </div>
  220. <?php else : ?>
  221. <?php
  222. $config = unserialize(base64_decode(Typecho_Cookie::get('__typecho_config')));
  223. $type = explode('_', $config['adapter']);
  224. $type = array_pop($type);
  225. try {
  226. $installDb = new Typecho_Db($config['adapter'], $config['prefix']);
  227. $installDb->addServer($config, Typecho_Db::READ | Typecho_Db::WRITE);
  228. /** 初始化数据库结构 */
  229. $scripts = file_get_contents ('./install/' . $type . '.sql');
  230. $scripts = str_replace('typecho_', $config['prefix'], $scripts);
  231. if (isset($config['charset'])) {
  232. $scripts = str_replace('%charset%', $config['charset'], $scripts);
  233. }
  234. $scripts = explode(';', $scripts);
  235. foreach ($scripts as $script) {
  236. $script = trim($script);
  237. if ($script) {
  238. $installDb->query($script, Typecho_Db::WRITE);
  239. }
  240. }
  241. /** 全局变量 */
  242. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'theme', 'user' => 0, 'value' => 'default')));
  243. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'theme:default', 'user' => 0, 'value' => '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";}}')));
  244. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'timezone', 'user' => 0, 'value' => _t('28800'))));
  245. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'charset', 'user' => 0, 'value' => 'UTF-8')));
  246. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'contentType', 'user' => 0, 'value' => 'text/html')));
  247. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'gzip', 'user' => 0, 'value' => 0)));
  248. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'generator', 'user' => 0, 'value' => $options->generator)));
  249. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'title', 'user' => 0, 'value' => 'Hello World')));
  250. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'description', 'user' => 0, 'value' => 'Just So So ...')));
  251. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'keywords', 'user' => 0, 'value' => 'typecho,php,blog')));
  252. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'rewrite', 'user' => 0, 'value' => 0)));
  253. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'frontPage', 'user' => 0, 'value' => 'recent')));
  254. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'frontArchive', 'user' => 0, 'value' => 0)));
  255. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsRequireMail', 'user' => 0, 'value' => 1)));
  256. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsWhitelist', 'user' => 0, 'value' => 0)));
  257. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsRequireURL', 'user' => 0, 'value' => 0)));
  258. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsRequireModeration', 'user' => 0, 'value' => 0)));
  259. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'plugins', 'user' => 0, 'value' => 'a:0:{}')));
  260. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentDateFormat', 'user' => 0, 'value' => 'F jS, Y \a\t h:i a')));
  261. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'siteUrl', 'user' => 0, 'value' => $config['siteUrl'])));
  262. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'defaultCategory', 'user' => 0, 'value' => 1)));
  263. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'allowRegister', 'user' => 0, 'value' => 0)));
  264. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'defaultAllowComment', 'user' => 0, 'value' => 1)));
  265. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'defaultAllowPing', 'user' => 0, 'value' => 1)));
  266. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'defaultAllowFeed', 'user' => 0, 'value' => 1)));
  267. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'pageSize', 'user' => 0, 'value' => 5)));
  268. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'postsListSize', 'user' => 0, 'value' => 10)));
  269. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsListSize', 'user' => 0, 'value' => 10)));
  270. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsHTMLTagAllowed', 'user' => 0, 'value' => NULL)));
  271. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'postDateFormat', 'user' => 0, 'value' => 'Y-m-d')));
  272. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'feedFullText', 'user' => 0, 'value' => 1)));
  273. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'editorSize', 'user' => 0, 'value' => 350)));
  274. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'autoSave', 'user' => 0, 'value' => 0)));
  275. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'markdown', 'user' => 0, 'value' => 1)));
  276. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsMaxNestingLevels', 'user' => 0, 'value' => 5)));
  277. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsPostTimeout', 'user' => 0, 'value' => 24 * 3600 * 30)));
  278. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsUrlNofollow', 'user' => 0, 'value' => 1)));
  279. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsShowUrl', 'user' => 0, 'value' => 1)));
  280. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsMarkdown', 'user' => 0, 'value' => 0)));
  281. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsPageBreak', 'user' => 0, 'value' => 0)));
  282. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsThreaded', 'user' => 0, 'value' => 1)));
  283. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsPageSize', 'user' => 0, 'value' => 20)));
  284. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsPageDisplay', 'user' => 0, 'value' => 'last')));
  285. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsOrder', 'user' => 0, 'value' => 'ASC')));
  286. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsCheckReferer', 'user' => 0, 'value' => 1)));
  287. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsAutoClose', 'user' => 0, 'value' => 0)));
  288. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsPostIntervalEnable', 'user' => 0, 'value' => 1)));
  289. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsPostInterval', 'user' => 0, 'value' => 60)));
  290. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsShowCommentOnly', 'user' => 0, 'value' => 0)));
  291. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsAvatar', 'user' => 0, 'value' => 1)));
  292. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsAvatarRating', 'user' => 0, 'value' => 'G')));
  293. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'routingTable', 'user' => 0, 'value' => '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";}}')));
  294. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'actionTable', 'user' => 0, 'value' => 'a:0:{}')));
  295. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'panelTable', 'user' => 0, 'value' => 'a:0:{}')));
  296. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'attachmentTypes', 'user' => 0, 'value' => '@image@')));
  297. $installDb->query($installDb->insert('table.options')->rows(array('name' => 'secret', 'user' => 0, 'value' => Typecho_Common::randString(32, true))));
  298. /** 初始分类 */
  299. $installDb->query($installDb->insert('table.metas')->rows(array('name' => _t('默认分类'), 'slug' => 'default', 'type' => 'category', 'description' => _t('只是一个默认分类'),
  300. 'count' => 1, 'order' => 1)));
  301. /** 初始关系 */
  302. $installDb->query($installDb->insert('table.relationships')->rows(array('cid' => 1, 'mid' => 1)));
  303. /** 初始内容 */
  304. $installDb->query($installDb->insert('table.contents')->rows(array('title' => _t('欢迎使用 Typecho'), 'slug' => 'start', 'created' => Typecho_Date::gmtTime(), 'modified' => Typecho_Date::gmtTime(),
  305. 'text' => '<!--markdown-->' . _t('如果您看到这篇文章,表示您的 blog 已经安装成功.'), 'authorId' => 1, 'type' => 'post', 'status' => 'publish', 'commentsNum' => 1, 'allowComment' => 1,
  306. 'allowPing' => 1, 'allowFeed' => 1, 'parent' => 0)));
  307. $installDb->query($installDb->insert('table.contents')->rows(array('title' => _t('关于'), 'slug' => 'start-page', 'created' => Typecho_Date::gmtTime(), 'modified' => Typecho_Date::gmtTime(),
  308. 'text' => '<!--markdown-->' . _t('本页面由 Typecho 创建, 这只是个测试页面.'), 'authorId' => 1, 'order' => 0, 'type' => 'page', 'status' => 'publish', 'commentsNum' => 0, 'allowComment' => 1,
  309. 'allowPing' => 1, 'allowFeed' => 1, 'parent' => 0)));
  310. /** 初始评论 */
  311. $installDb->query($installDb->insert('table.comments')->rows(array('cid' => 1, 'created' => Typecho_Date::gmtTime(), 'author' => 'Typecho', 'ownerId' => 1, 'url' => 'http://typecho.org',
  312. 'ip' => '127.0.0.1', 'agent' => $options->generator, 'text' => '欢迎加入 Typecho 大家族', 'type' => 'comment', 'status' => 'approved', 'parent' => 0)));
  313. /** 初始用户 */
  314. $password = empty($config['userPassword']) ? substr(uniqid(), 7) : $config['userPassword'];
  315. $hasher = new PasswordHash(8, true);
  316. $installDb->query($installDb->insert('table.users')->rows(array('name' => $config['userName'], 'password' => $hasher->HashPassword($password), 'mail' => $config['userMail'],
  317. 'url' => 'http://www.typecho.org', 'screenName' => $config['userName'], 'group' => 'administrator', 'created' => Typecho_Date::gmtTime())));
  318. unset($_SESSION['typecho']);
  319. header('Location: ./install.php?finish&user=' . urlencode($config['userName'])
  320. . '&password=' . urlencode($password));
  321. } catch (Typecho_Db_Exception $e) {
  322. $success = false;
  323. $code = $e->getCode();
  324. ?>
  325. <h1 class="typecho-install-title"><?php _e('安装失败!'); ?></h1>
  326. <div class="typecho-install-body">
  327. <form method="post" action="?start" name="check">
  328. <?php
  329. if(('Mysql' == $type && (1050 == $code || '42S01' == $code)) ||
  330. ('SQLite' == $type && ('HY000' == $code || 1 == $code)) ||
  331. ('Pgsql' == $type && '42P07' == $code)) {
  332. if(_r('delete')) {
  333. //删除原有数据
  334. $dbPrefix = $config['prefix'];
  335. $tableArray = array($dbPrefix . 'comments', $dbPrefix . 'contents', $dbPrefix . 'fields', $dbPrefix . 'metas', $dbPrefix . 'options', $dbPrefix . 'relationships', $dbPrefix . 'users',);
  336. foreach($tableArray as $table) {
  337. if($type == 'Mysql') {
  338. $installDb->query("DROP TABLE IF EXISTS `{$table}`");
  339. } elseif($type == 'Pgsql') {
  340. $installDb->query("DROP TABLE {$table}");
  341. } elseif($type == 'SQLite') {
  342. $installDb->query("DROP TABLE {$table}");
  343. }
  344. }
  345. echo '<p class="message success">' . _t('已经删除完原有数据') . '<br /><br /><button class="btn primary" type="submit" class="primary">'
  346. . _t('继续安装 &raquo;') . '</button></p>';
  347. } elseif (_r('goahead')) {
  348. //使用原有数据
  349. //但是要更新用户网站
  350. $installDb->query($installDb->update('table.options')->rows(array('value' => $config['siteUrl']))->where('name = ?', 'siteUrl'));
  351. unset($_SESSION['typecho']);
  352. header('Location: ./install.php?finish&use_old');
  353. exit;
  354. } else {
  355. echo '<p class="message error">' . _t('安装程序检查到原有数据表已经存在.')
  356. . '<br /><br />' . '<button type="submit" name="delete" value="1" class="btn btn-warn">' . _t('删除原有数据') . '</button> '
  357. . _t('或者') . ' <button type="submit" name="goahead" value="1" class="btn primary">' . _t('使用原有数据') . '</button></p>';
  358. }
  359. } else {
  360. echo '<p class="message error">' . _t('安装程序捕捉到以下错误: "%s". 程序被终止, 请检查您的配置信息.',$e->getMessage()) . '</p>';
  361. }
  362. ?>
  363. </form>
  364. </div>
  365. <?php
  366. }
  367. ?>
  368. <?php endif;?>
  369. <?php elseif (isset($_GET['config'])): ?>
  370. <?php
  371. $adapters = array('Mysql', 'Pdo_Mysql', 'SQLite', 'Pdo_SQLite', 'Pgsql', 'Pdo_Pgsql');
  372. foreach ($adapters as $firstAdapter) {
  373. if (_p($firstAdapter)) {
  374. break;
  375. }
  376. }
  377. $adapter = _r('dbAdapter', $firstAdapter);
  378. $type = explode('_', $adapter);
  379. $type = array_pop($type);
  380. ?>
  381. <form method="post" action="?config" name="config">
  382. <h1 class="typecho-install-title"><?php _e('确认您的配置'); ?></h1>
  383. <div class="typecho-install-body">
  384. <h2><?php _e('数据库配置'); ?></h2>
  385. <?php
  386. if ('config' == _r('action')) {
  387. $success = true;
  388. if (_r('created') && !file_exists('./config.inc.php')) {
  389. echo '<p class="message error">' . _t('没有检测到您手动创建的配置文件, 请检查后再次创建') . '</p>';
  390. $success = false;
  391. } else {
  392. if (NULL == _r('userUrl')) {
  393. $success = false;
  394. echo '<p class="message error">' . _t('请填写您的网站地址') . '</p>';
  395. } else if (NULL == _r('userName')) {
  396. $success = false;
  397. echo '<p class="message error">' . _t('请填写您的用户名') . '</p>';
  398. } else if (NULL == _r('userMail')) {
  399. $success = false;
  400. echo '<p class="message error">' . _t('请填写您的邮箱地址') . '</p>';
  401. } else if (32 < strlen(_r('userName'))) {
  402. $success = false;
  403. echo '<p class="message error">' . _t('用户名长度超过限制, 请不要超过 32 个字符') . '</p>';
  404. } else if (200 < strlen(_r('userMail'))) {
  405. $success = false;
  406. echo '<p class="message error">' . _t('邮箱长度超过限制, 请不要超过 200 个字符') . '</p>';
  407. }
  408. }
  409. $_dbConfig = _rFrom('dbHost', 'dbUser', 'dbPassword', 'dbCharset', 'dbPort', 'dbDatabase', 'dbFile', 'dbDsn');
  410. $_dbConfig = array_filter($_dbConfig);
  411. $dbConfig = array();
  412. foreach ($_dbConfig as $key => $val) {
  413. $dbConfig[strtolower (substr($key, 2))] = $val;
  414. }
  415. // 在特殊服务器上的特殊安装过程处理
  416. if (_r('config')) {
  417. $replace = array_keys($dbConfig);
  418. foreach ($replace as &$key) {
  419. $key = '{' . $key . '}';
  420. }
  421. if (!empty($_dbConfig['dbDsn'])) {
  422. $dbConfig['dsn'] = str_replace($replace, array_values($dbConfig), $dbConfig['dsn']);
  423. }
  424. $config = str_replace($replace, array_values($dbConfig), _r('config'));
  425. }
  426. if (!isset($config) && $success && !_r('created')) {
  427. $installDb = new Typecho_Db($adapter, _r('dbPrefix'));
  428. $installDb->addServer($dbConfig, Typecho_Db::READ | Typecho_Db::WRITE);
  429. /** 检测数据库配置 */
  430. try {
  431. $installDb->query('SELECT 1=1');
  432. } catch (Typecho_Db_Adapter_Exception $e) {
  433. $success = false;
  434. echo '<p class="message error">'
  435. . _t('对不起,无法连接数据库,请先检查数据库配置再继续进行安装') . '</p>';
  436. } catch (Typecho_Db_Exception $e) {
  437. $success = false;
  438. echo '<p class="message error">'
  439. . _t('安装程序捕捉到以下错误: " %s ". 程序被终止, 请检查您的配置信息.',$e->getMessage()) . '</p>';
  440. }
  441. }
  442. if($success) {
  443. Typecho_Cookie::set('__typecho_config', base64_encode(serialize(array_merge(array(
  444. 'prefix' => _r('dbPrefix'),
  445. 'userName' => _r('userName'),
  446. 'userPassword' => _r('userPassword'),
  447. 'userMail' => _r('userMail'),
  448. 'adapter' => $adapter,
  449. 'siteUrl' => _r('userUrl')
  450. ), $dbConfig))));
  451. if (_r('created')) {
  452. header('Location: ./install.php?start');
  453. exit;
  454. }
  455. /** 初始化配置文件 */
  456. $lines = array_slice(file(__FILE__), 0, 52);
  457. $lines[] = "
  458. /** 定义数据库参数 */
  459. \$db = new Typecho_Db('{$adapter}', '" . _r('dbPrefix') . "');
  460. \$db->addServer(" . (!isset($config) ? var_export($dbConfig, true) : $config) . ", Typecho_Db::READ | Typecho_Db::WRITE);
  461. Typecho_Db::set(\$db);
  462. ";
  463. $contents = implode('', $lines);
  464. if (!Typecho_Common::isAppEngine()) {
  465. @file_put_contents('./config.inc.php', $contents);
  466. }
  467. // 创建一个用于标识的临时文件
  468. $_SESSION['typecho'] = 1;
  469. if (!file_exists('./config.inc.php')) {
  470. ?>
  471. <div class="message notice"><p><?php _e('安装程序无法自动创建 <strong>config.inc.php</strong> 文件'); ?><br />
  472. <?php _e('您可以在网站根目录下手动创建 <strong>config.inc.php</strong> 文件, 并复制如下代码至其中'); ?></p>
  473. <p><textarea rows="5" onmouseover="this.select();" class="w-100 mono" readonly><?php echo htmlspecialchars($contents); ?></textarea></p>
  474. <p><button name="created" value="1" type="submit" class="btn primary">创建完毕, 继续安装 &raquo;</button></p></div>
  475. <?php
  476. } else {
  477. header('Location: ./install.php?start');
  478. exit;
  479. }
  480. }
  481. // 安装不成功删除配置文件
  482. if($success != true && file_exists(__TYPECHO_ROOT_DIR__ . '/config.inc.php')) {
  483. unlink(__TYPECHO_ROOT_DIR__ . '/config.inc.php');
  484. }
  485. }
  486. ?>
  487. <ul class="typecho-option">
  488. <li>
  489. <label for="dbAdapter" class="typecho-label"><?php _e('数据库适配器'); ?></label>
  490. <select name="dbAdapter" id="dbAdapter">
  491. <?php if (_p('Mysql')): ?><option value="Mysql"<?php if('Mysql' == $adapter): ?> selected=true<?php endif; ?>><?php _e('Mysql 原生函数适配器') ?></option><?php endif; ?>
  492. <?php if (_p('SQLite')): ?><option value="SQLite"<?php if('SQLite' == $adapter): ?> selected=true<?php endif; ?>><?php _e('SQLite 原生函数适配器 (SQLite 2.x)') ?></option><?php endif; ?>
  493. <?php if (_p('Pgsql')): ?><option value="Pgsql"<?php if('Pgsql' == $adapter): ?> selected=true<?php endif; ?>><?php _e('Pgsql 原生函数适配器') ?></option><?php endif; ?>
  494. <?php if (_p('Pdo_Mysql')): ?><option value="Pdo_Mysql"<?php if('Pdo_Mysql' == $adapter): ?> selected=true<?php endif; ?>><?php _e('Pdo 驱动 Mysql 适配器') ?></option><?php endif; ?>
  495. <?php if (_p('Pdo_SQLite')): ?><option value="Pdo_SQLite"<?php if('Pdo_SQLite' == $adapter): ?> selected=true<?php endif; ?>><?php _e('Pdo 驱动 SQLite 适配器 (SQLite 3.x)') ?></option><?php endif; ?>
  496. <?php if (_p('Pdo_Pgsql')): ?><option value="Pdo_Pgsql"<?php if('Pdo_Pgsql' == $adapter): ?> selected=true<?php endif; ?>><?php _e('Pdo 驱动 PostgreSql 适配器') ?></option><?php endif; ?>
  497. </select>
  498. <p class="description"><?php _e('请根据您的数据库类型选择合适的适配器'); ?></p>
  499. </li>
  500. <?php require_once './install/' . $type . '.php'; ?>
  501. <li>
  502. <label class="typecho-label" for="dbPrefix"><?php _e('数据库前缀'); ?></label>
  503. <input type="text" class="text" name="dbPrefix" id="dbPrefix" value="<?php _v('dbPrefix', 'typecho_'); ?>" />
  504. <p class="description"><?php _e('默认前缀是 "typecho_"'); ?></p>
  505. </li>
  506. </ul>
  507. <script>
  508. var _select = document.config.dbAdapter;
  509. _select.onchange = function() {
  510. setTimeout("window.location.href = 'install.php?config&dbAdapter=" + this.value + "'; ",0);
  511. }
  512. </script>
  513. <h2><?php _e('创建您的管理员帐号'); ?></h2>
  514. <ul class="typecho-option">
  515. <li>
  516. <label class="typecho-label" for="userUrl"><?php _e('网站地址'); ?></label>
  517. <input type="text" name="userUrl" id="userUrl" class="text" value="<?php _v('userUrl', _u()); ?>" />
  518. <p class="description"><?php _e('这是程序自动匹配的网站路径, 如果不正确请修改它'); ?></p>
  519. </li>
  520. <li>
  521. <label class="typecho-label" for="userName"><?php _e('用户名'); ?></label>
  522. <input type="text" name="userName" id="userName" class="text" value="<?php _v('userName', 'admin'); ?>" />
  523. <p class="description"><?php _e('请填写您的用户名'); ?></p>
  524. </li>
  525. <li>
  526. <label class="typecho-label" for="userPassword"><?php _e('登录密码'); ?></label>
  527. <input type="password" name="userPassword" id="userPassword" class="text" value="<?php _v('userPassword'); ?>" />
  528. <p class="description"><?php _e('请填写您的登录密码, 如果留空系统将为您随机生成一个'); ?></p>
  529. </li>
  530. <li>
  531. <label class="typecho-label" for="userMail"><?php _e('邮件地址'); ?></label>
  532. <input type="text" name="userMail" id="userMail" class="text" value="<?php _v('userMail', 'webmaster@yourdomain.com'); ?>" />
  533. <p class="description"><?php _e('请填写一个您的常用邮箱'); ?></p>
  534. </li>
  535. </ul>
  536. </div>
  537. <input type="hidden" name="action" value="config" />
  538. <p class="submit"><button type="submit" class="btn primary"><?php _e('确认, 开始安装 &raquo;'); ?></button></p>
  539. </form>
  540. <?php else: ?>
  541. <form method="post" action="?config">
  542. <h1 class="typecho-install-title"><?php _e('欢迎使用 Typecho'); ?></h1>
  543. <div class="typecho-install-body">
  544. <h2><?php _e('安装说明'); ?></h2>
  545. <p><strong><?php _e('本安装程序将自动检测服务器环境是否符合最低配置需求. 如果不符合, 将在上方出现提示信息, 请按照提示信息检查您的主机配置. 如果服务器环境符合要求, 将在下方出现 "开始下一步" 的按钮, 点击此按钮即可一步完成安装.'); ?></strong></p>
  546. <h2><?php _e('许可及协议'); ?></h2>
  547. <p><?php _e('Typecho 基于 <a href="http://www.gnu.org/copyleft/gpl.html">GPL</a> 协议发布, 我们允许用户在 GPL 协议许可的范围内使用, 拷贝, 修改和分发此程序.'); ?>
  548. <?php _e('在GPL许可的范围内,您可以自由地将其用于商业以及非商业用途.'); ?></p>
  549. <p><?php _e('Typecho 软件由其社区提供支持, 核心开发团队负责维护程序日常开发工作以及新特性的制定.'); ?>
  550. <?php _e('如果您遇到使用上的问题, 程序中的 BUG, 以及期许的新功能, 欢迎您在社区中交流或者直接向我们贡献代码.'); ?>
  551. <?php _e('对于贡献突出者, 他的名字将出现在贡献者名单中.'); ?></p>
  552. </div>
  553. <p class="submit"><button type="submit" class="btn primary"><?php _e('我准备好了, 开始下一步 &raquo;'); ?></button></p>
  554. </form>
  555. <?php endif; ?>
  556. </div>
  557. </div>
  558. </div>
  559. </div>
  560. <?php
  561. include 'admin/copyright.php';
  562. include 'admin/footer.php';
  563. ?>