Browse Source

安装脚本支持选择语言(中文or English)

star7th 8 years ago
parent
commit
ff8c96ba0c
6 changed files with 307 additions and 131 deletions
  1. 46 73
      install/ajax.php
  2. 75 0
      install/common.php
  3. 111 0
      install/database.php
  4. 7 58
      install/index.php
  5. 34 0
      install/lang.en.php
  6. 34 0
      install/lang.zh.php

+ 46 - 73
install/ajax.php

@@ -5,36 +5,40 @@
 ini_set("display_errors", "Off");
 error_reporting(E_ALL | E_STRICT);
 header("Content-type: text/html; charset=utf-8"); 
-
+include("common.php");
 if($f = file_get_contents("./install.lock")){
-	ajax_out("本程序已经安装过!如果要解除安装锁定,则可删除/install目录下的install.lock文件后再重新访问本页面",10099);
+	ajax_out(L("lock"),10099);
 }
 
 if(!new_is_writeable("./")){
-	ajax_out("请赋予 /install 目录以可写权限!",10098);
+	ajax_out(L("not_writable_install"),10098);
 }
 
 if(!new_is_writeable("../Public/Uploads")){
-	ajax_out("请赋予 /Public/Uploads/ 目录以可写权限!",10098);
+	ajax_out(L("not_writable_upload"),10098);
 }
 
 if(!new_is_writeable("../Application/Runtime")){
-	ajax_out("请赋予 /Application/Runtime 目录以可写权限!",10095);
+	ajax_out(L("not_writable_runtime"),10095);
 }
 
 if(!new_is_writeable("../Application/Common/Conf/config.php")){
-	ajax_out("请赋予 /Application/Common/Conf/config.php 文件以可写权限!",10094);
+	ajax_out(L("not_writable_config"),10094);
+}
+
+if(!new_is_writeable("../Application/Home/Conf/config.php")){
+	ajax_out(L("not_writable_home_config"),10098);
 }
 
 
 $db_type = $_POST["db_type"] ?  $_POST["db_type"] :"sqlite";
 if ($db_type == "sqlite") {
 	if(!new_is_writeable("../Sqlite")){
-		ajax_out("请赋予 /Sqlite 目录以可写权限!",10097);
+		ajax_out(L("not_writable_sqlite"),10097);
 	}
 
 	if(!new_is_writeable("../Sqlite/showdoc.db.php")){
-		ajax_out("请赋予 /Sqlite/showdoc.db.php 以可写权限!",10096);
+		ajax_out(L("not_writable_sqlite_db"),10096);
 	}
     user_sqlite();
 }
@@ -43,6 +47,7 @@ elseif ($db_type == "mysql") {
 }
 function user_sqlite(){
         clear_runtime();//清除缓存
+        write_home_config();
         $config = 
 <<<EOD
 <?php
@@ -66,6 +71,7 @@ return array(
     'URL_ROUTER_ON'   => true, 
     'URL_ROUTE_RULES'=>array(
         ':id\d'               => 'Home/Item/Show?item_id=:1',
+		':domain\s$'               => 'Home/Item/Show?item_domain=:1',//item的个性域名
         'uid/:id\d'               => 'Home/Item/showByUid?uid=:1',
     ),
     'URL_CASE_INSENSITIVE'=>true,
@@ -74,10 +80,10 @@ return array(
 EOD;
         $ret = file_put_contents("../Application/Common/Conf/config.php", $config);
         if ($ret) {
-        	file_put_contents("./install.lock","http://doc.star7th.com/");
-            ajax_out("安装成功!建议删除/install目录,以免安装脚本被再次执行。");
+        	file_put_contents("./install.lock","http://www.showdoc.cc/");
+            ajax_out(L("install_success"));
         }else{
-            ajax_out("安装失败,配置文件写入错误!",10001);
+            ajax_out(L("install_config_not_writable"),10001);
         }
 }
 
@@ -94,23 +100,25 @@ function user_mysql(){
 
         $con = mysqli_connect($db_host,$db_user,$db_password,$db_name,$db_port);
         if (!$con ) {
-           ajax_out("数据库链接错误,请检查配置信息是否填写正确",10002);
+           ajax_out(L("db_wrong"),10002);
            exit();
         }
         mysqli_query($con, "SET NAMES UTF8");
         $row = mysqli_fetch_array(mysqli_query($con, " SELECT COUNT(*) FROM user "));
         
         if ($row) {
-           ajax_out("检测到该数据库已经存在数据。请清理后再重试",10003);
+           ajax_out(L("db_has_data"),10003);
            exit();
         }
         
         //开始导入mysql数据库 
         $ret = import_mysql($con);
         if (!$ret) {
-           ajax_out("创建数据库表失败!",10004);
+           ajax_out(L("create_table_fail"),10004);
            exit();
-        }       
+        }
+
+        write_home_config();
 
         $config = "<?php ";
         $config .= "
@@ -134,6 +142,7 @@ return array(
     'URL_ROUTER_ON'   => true, 
     'URL_ROUTE_RULES'=>array(
         ':id\d'               => 'Home/Item/Show?item_id=:1',
+		':domain\s$'               => 'Home/Item/Show?item_domain=:1',//item的个性域名
         'uid/:id\d'               => 'Home/Item/showByUid?uid=:1',
     ),
     'URL_CASE_INSENSITIVE'=>true,
@@ -143,44 +152,13 @@ return array(
 
 
         if ($ret) {
-        	file_put_contents("./install.lock","http://doc.star7th.com/");
-            ajax_out("安装成功!建议删除/install目录,以免安装脚本被再次执行。");
+        	file_put_contents("./install.lock","http://www.showdoc.cc/");
+            ajax_out(L("install_success"));
         }else{
-            ajax_out("安装失败,配置文件写入错误!",10001);
+            ajax_out(L("install_config_not_writable"),10001);
         }
 }
 
-
-function ajax_out($message,$error_code = 0){
-        echo json_encode(array("error_code"=>$error_code,"message"=>$message));
-        exit();
-}
-
-function clear_runtime($path = "../Application/Runtime"){  
-    //给定的目录不是一个文件夹  
-    if(!is_dir($path)){  
-        return null;  
-    }  
-  
-    $fh = opendir($path);  
-    while(($row = readdir($fh)) !== false){  
-        //过滤掉虚拟目录  
-        if($row == '.' || $row == '..'|| $row == 'index.html'){  
-            continue;  
-        }  
-  
-        if(!is_dir($path.'/'.$row)){
-            unlink($path.'/'.$row);  
-        }  
-        clear_runtime($path.'/'.$row);  
-          
-    }  
-    //关闭目录句柄,否则出Permission denied  
-    closedir($fh);    
-    return true;  
-} 
-
-
 function import_mysql($con){
 
 	//创建目录表
@@ -206,6 +184,7 @@ function import_mysql($con){
 	`uid` int(10) NOT NULL DEFAULT '0',
 	`username` varchar(50) NOT NULL DEFAULT '',
 	`password` varchar(50) NOT NULL DEFAULT '',
+	`item_domain` varchar(50) NOT NULL DEFAULT '',
 	`addtime` int(11) NOT NULL DEFAULT '0',
 	`last_update_time` int(11) NOT NULL DEFAULT '0' COMMENT '最后更新时间',
 	PRIMARY KEY (`item_id`),
@@ -287,30 +266,24 @@ function import_mysql($con){
 
 }
 
-/**
- * 判断 文件/目录 是否可写(取代系统自带的 is_writeable 函数)
- *
- * @param string $file 文件/目录
- * @return boolean
- */
-function new_is_writeable($file) {
-	if (is_dir($file)){
-		$dir = $file;
-		if ($fp = @fopen("$dir/test.txt", 'w')) {
-			@fclose($fp);
-			@unlink("$dir/test.txt");
-			$writeable = 1;
-		} else {
-			$writeable = 0;
-		}
-	} else {
-		if ($fp = @fopen($file, 'a+')) {
-			@fclose($fp);
-			$writeable = 1;
-		} else {
-			$writeable = 0;
-		}
+function write_home_config(){
+	$lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
+	if ($lang == 'en') {
+		$DEFAULT_LANG = 'en-us';
+	}else{
+		$DEFAULT_LANG = 'zh-cn';
 	}
+        $config = "<?php ";
+        $config .= "
+return array(
+	//'配置项'=>'配置值'
+    'LANG_SWITCH_ON' => true,   // 开启语言包功能
+    'LANG_AUTO_DETECT' => false, // 自动侦测语言 开启多语言功能后有效
+    'DEFAULT_LANG' => '{$DEFAULT_LANG}', // 默认语言
+    'LANG_LIST'        => 'zh-cn,en-us', // 允许切换的语言列表 用逗号分隔
+    'VAR_LANGUAGE'     => 'l', // 默认语言切换变量
+);";
+
+	$ret = file_put_contents("../Application/Home/Conf/config.php", $config);
 
-	return $writeable;
 }

+ 75 - 0
install/common.php

@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * 判断语言
+ */
+
+function lang(){
+  $lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
+  return include("lang.".$lang.".php");
+}
+
+
+function L($field){
+  if (!isset($GLOBALS['lang'])) {
+      $GLOBALS['lang'] = lang();
+  }
+  return $GLOBALS['lang'][$field] ;
+}
+
+/**
+ * 判断 文件/目录 是否可写(取代系统自带的 is_writeable 函数)
+ *
+ * @param string $file 文件/目录
+ * @return boolean
+ */
+function new_is_writeable($file) {
+  if (is_dir($file)){
+    $dir = $file;
+    if ($fp = @fopen("$dir/test.txt", 'w')) {
+      @fclose($fp);
+      @unlink("$dir/test.txt");
+      $writeable = 1;
+    } else {
+      $writeable = 0;
+    }
+  } else {
+    if ($fp = @fopen($file, 'a+')) {
+      @fclose($fp);
+      $writeable = 1;
+    } else {
+      $writeable = 0;
+    }
+  }
+
+  return $writeable;
+}
+
+function clear_runtime($path = "../Application/Runtime"){  
+    //给定的目录不是一个文件夹  
+    if(!is_dir($path)){  
+        return null;  
+    }  
+  
+    $fh = opendir($path);  
+    while(($row = readdir($fh)) !== false){  
+        //过滤掉虚拟目录  
+        if($row == '.' || $row == '..'|| $row == 'index.html'){  
+            continue;  
+        }  
+  
+        if(!is_dir($path.'/'.$row)){
+            unlink($path.'/'.$row);  
+        }  
+        clear_runtime($path.'/'.$row);  
+          
+    }  
+    //关闭目录句柄,否则出Permission denied  
+    closedir($fh);    
+    return true;  
+} 
+
+function ajax_out($message,$error_code = 0){
+        echo json_encode(array("error_code"=>$error_code,"message"=>$message));
+        exit();
+}

+ 111 - 0
install/database.php

@@ -0,0 +1,111 @@
+<?php
+// ShowDoc安装脚本
+// install Showdoc
+// 
+// --------
+// 	如果你能在浏览器中看到本句话,则证明你没有安装好PHP运行环境。请先安装好PHP运行环境
+// --------
+include("common.php");
+$cur_lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
+
+?>
+
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title> ShowDoc</title>
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <meta name="description" content="">
+    <meta name="author" content="">
+    <link href="../Public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
+    <style type="text/css">
+    @charset "utf-8";
+	body {
+		font:14px/1.5 "Microsoft Yahei","微软雅黑",Tahoma,Arial,Helvetica,STHeiti;
+	}
+    </style>
+
+  </head>
+  <body>
+<link rel="stylesheet" href="../Public/css/login.css" />
+
+    <div class="container">
+
+      <form class="form-signin" method="post">
+        <h3 class="form-signin-heading"><?php echo L("install_title");?></h3>
+        <br>
+        <div>
+	        <select id="db_type">
+	        	<option value="sqlite"><?php echo L("use_sqlite");?></option>
+	        	<option value="mysql"><?php echo L("use_mysql");?></option>
+	        </select>
+        </div>
+        <br>
+        <div class="mysql-info" style="display:none">
+	        <input type="text" class="input-block-level"  name="db_host" id = "db_host" placeholder="<?php echo L("server_address");?>">
+	        <input type="text" class="input-block-level"  name="db_port" id = "db_port"  placeholder="<?php echo L("server_port");?>">
+	        <input type="text" class="input-block-level"  name="db_name" id = "db_name"  placeholder="<?php echo L("db_name");?>">
+	        <input type="text" class="input-block-level"  name="db_user" id = "db_user"  placeholder="<?php echo L("db_user");?>">
+	        <input type="text" class="input-block-level"  name="db_password" id = "db_password"  placeholder="<?php echo L("db_password");?>">
+        </div>
+        <div class="sqlite_tips" ><?php echo L("sqlite_tips");?></div>
+        <input type="hidden" value="<?php echo $cur_lang;?>" id="lang">
+        <br>
+        <div>
+        	 <button class="btn btn-large btn-primary " id="start" type="submit"><?php echo L("go");?>&nbsp;&nbsp;<i class="icon-circle-arrow-right"></i></button>
+          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.showdoc.cc/help?page_id=16118" target="_blank"><?php echo L("FAQ");?></a>
+        </div>
+      </form>
+
+    </div> <!-- /container -->
+
+    
+	<script src="../Public/js/common/jquery.min.js"></script>
+    <script src="../Public/bootstrap/js/bootstrap.min.js"></script>
+  </body>
+</html> 
+
+ <script type="text/javascript">
+ $(function(){
+ 	$("#db_type").change(function(){
+ 		if ($("#db_type").val() == 'mysql') {
+      $(".mysql-info").show();
+ 			$(".sqlite_tips").hide();
+ 		};
+ 		if ($("#db_type").val() == 'sqlite') {
+      $(".mysql-info").hide();
+      $(".sqlite_tips").show();
+ 		};
+ 	});
+
+ 	$("#start").click(function(){
+ 		var db_type = $("#db_type").val();
+ 		var db_host = $("#db_host").val();
+ 		var db_port = $("#db_port").val();
+ 		var db_name = $("#db_name").val();
+    var db_user = $("#db_user").val();
+ 		var lang = $("#lang").val();
+ 		var db_password = $("#db_password").val();
+ 		$.post(
+ 			'ajax.php',
+ 			{"lang":lang,"db_type":db_type,"db_host":db_host,"db_port":db_port,"db_name":db_name,"db_user":db_user,"db_password":db_password},
+ 			function(data){
+ 				if (data.error_code === 0) {
+ 					//安装成功
+			 		//alert(data.message);
+          var text = '<div><?php echo L("install_success_help");?></div><br>';
+			 		 text += '<div><a href="../" ><?php echo L("home");?></a></div>';
+           $(".form-signin").html(text);
+ 				}else{
+ 					alert(data.message);
+ 				}
+ 			},
+ 			"json"
+
+ 			);
+
+ 		return false;
+ 	});
+ });
+</script>

+ 7 - 58
install/index.php

@@ -5,6 +5,7 @@
 // --------
 // 	如果你能在浏览器中看到本句话,则证明你没有安装好PHP运行环境。请先安装好PHP运行环境
 // --------
+include("common.php");
 
 ?>
 
@@ -30,29 +31,20 @@
 
     <div class="container">
 
-      <form class="form-signin" method="post">
-        <h3 class="form-signin-heading">安装ShowDoc</h3>
+      <form class="form-signin" method="get" action="database.php">
+        <h3 class="form-signin-heading">选择语言<br>(Choose language)</h3>
         <br>
         <div>
-	        <select id="db_type">
-	        	<option value="sqlite">使用Sqlite数据库</option>
-	        	<option value="mysql">使用Mysql数据库</option>
+	        <select id="db_type" name="lang">
+	        	<option value="zh">中文</option>
+	        	<option value="en">English</option>
 	        </select>
         </div>
         <br>
-        <div class="mysql-info" style="display:none">
-	        <input type="text" class="input-block-level"  name="db_host" id = "db_host" placeholder="服务器地址,一般为localhost">
-	        <input type="text" class="input-block-level"  name="db_port" id = "db_port"  placeholder="端口,一般为3306">
-	        <input type="text" class="input-block-level"  name="db_name" id = "db_name"  placeholder="数据库名,建议数据库名为showdoc">
-	        <input type="text" class="input-block-level"  name="db_user" id = "db_user"  placeholder="数据库用户名">
-	        <input type="text" class="input-block-level"  name="db_password" id = "db_password"  placeholder="数据库密码">
-        </div>
-
-        <div class="sqlite_tips" >PHP内置支持Sqlite数据库,你无须再配置数据库,直接点击开始即可</div>
 
         <br>
         <div>
-        	 <button class="btn btn-large btn-primary " id="start" type="submit">开始&nbsp;&nbsp;<i class="icon-circle-arrow-right"></i></button>
+        	 <button class="btn btn-large btn-primary " id="start" type="submit">ok&nbsp;&nbsp;<i class="icon-circle-arrow-right"></i></button>
         </div>
       </form>
 
@@ -63,46 +55,3 @@
     <script src="../Public/bootstrap/js/bootstrap.min.js"></script>
   </body>
 </html> 
-
- <script type="text/javascript">
- $(function(){
- 	$("#db_type").change(function(){
- 		if ($("#db_type").val() == 'mysql') {
-      $(".mysql-info").show();
- 			$(".sqlite_tips").hide();
- 		};
- 		if ($("#db_type").val() == 'sqlite') {
-      $(".mysql-info").hide();
-      $(".sqlite_tips").show();
- 		};
- 	});
-
- 	$("#start").click(function(){
- 		var db_type = $("#db_type").val();
- 		var db_host = $("#db_host").val();
- 		var db_port = $("#db_port").val();
- 		var db_name = $("#db_name").val();
- 		var db_user = $("#db_user").val();
- 		var db_password = $("#db_password").val();
- 		$.post(
- 			'ajax.php',
- 			{"db_type":db_type,"db_host":db_host,"db_port":db_port,"db_name":db_name,"db_user":db_user,"db_password":db_password},
- 			function(data){
- 				if (data.error_code === 0) {
- 					//安装成功
-			 		//alert(data.message);
-          var text = '<div>安装成功!建议删除/install目录,以免安装脚本被再次执行。若再遇到问题,可参考ShowDoc帮助文档:<a href="http://doc.star7th.com/3" target="_blank">http://doc.star7th.com/3</a></div><br>';
-			 		 text += '<div><a href="../" >进入网站首页</a></div>';
-           $(".form-signin").html(text);
- 				}else{
- 					alert(data.message);
- 				}
- 			},
- 			"json"
-
- 			);
-
- 		return false;
- 	});
- });
-</script>

+ 34 - 0
install/lang.en.php

@@ -0,0 +1,34 @@
+<?php
+return array(
+  //index.php
+  "install_title"=>'Install ShowDoc',
+  "use_sqlite"=>'Use Sqlite Database',
+  "use_mysql"=>'Use Mysql Database',
+  "server_address"=>'Server address (e.g: localhost)',
+  "server_port"=>'Port(e.g:3306)',
+  "db_name"=>'Database Name(e.g:showdoc)',
+  "db_user"=>'Database Username',
+  "db_password"=>' Database Password',
+  "sqlite_tips"=>'Sqlite has supported by PHP and you just need to click the Go buttun',
+  "go"=>'Go',
+  "install_success_help"=>'Installation success!Please delete the /install directory, avoid the script to be executed again.<br><a href="http://www.showdoc.cc/help-en" target="_blank">http://www.showdoc.cc/help-en</a>',
+  "home"=>'Website Home',
+  "FAQ"=>'FAQ',
+
+  //ajax.php
+  "lock"=>'ShowDoc has been installed!If you want to reinstall,please delete file /install/install.lock ',
+  "not_writable_install"=>' Directory /install is not writable !',
+  "not_writable_upload"=>'Directory /Public/Uploads/  is not writable !',
+  "not_writable_runtime"=>'Directory /Application/Runtime is not writable !',
+  "not_writable_config"=>'File /Application/Common/Conf/config.php is not writable !',
+  "not_writable_home_config"=>'File /Application/Home/Conf/config.php is not writable !',
+  "not_writable_sqlite"=>'Directory /Sqlite is not writable !',
+  "not_writable_sqlite_db"=>'File /Sqlite/showdoc.db.php is not writable !',
+  "install_success"=>'Installation success!Please delete the /install directory, avoid the script to be executed again',
+  "install_config_not_writable"=>'Fail to write config file ',
+  "db_wrong"=>'Database connection error',
+  "db_has_data"=>'Database tables already exists,please clear up and try again',
+  "create_table_fail"=>'Fail to create table',
+  "install_config_not_writable"=>'Fail to write config file',
+
+  );

+ 34 - 0
install/lang.zh.php

@@ -0,0 +1,34 @@
+<?php
+return array(
+  //index.php
+  "install_title"=>'安装ShowDoc',
+  "use_sqlite"=>'使用Sqlite数据库',
+  "use_mysql"=>'使用Mysql数据库',
+  "server_address"=>'服务器地址,一般为localhost',
+  "server_port"=>'端口,一般为3306',
+  "db_name"=>'数据库名,建议数据库名为showdoc',
+  "db_user"=>'数据库用户名',
+  "db_password"=>'数据库密码',
+  "sqlite_tips"=>'PHP内置支持Sqlite数据库,你无须再配置数据库,直接点击开始即可',
+  "go"=>'开始',
+  "install_success_help"=>'安装成功!建议删除/install目录,以免安装脚本被再次执行。若再遇到问题,可参考ShowDoc帮助文档:<a href="http://www.showdoc.cc/help" target="_blank">http://www.showdoc.cc/help</a>',
+  "home"=>'进入网站首页',
+  "FAQ"=>'常见问题',
+
+  //ajax.php
+  "lock"=>'本程序已经安装过!如果要解除安装锁定,则可删除/install目录下的install.lock文件后再重新访问本页面',
+  "not_writable_install"=>'请赋予 /install 目录以可写权限!',
+  "not_writable_upload"=>'请赋予 /Public/Uploads/ 目录以可写权限!',
+  "not_writable_runtime"=>'请赋予 /Application/Runtime 目录以可写权限!',
+  "not_writable_config"=>'请赋予 /Application/Common/Conf/config.php 文件以可写权限!',
+  "not_writable_home_config"=>'请赋予 /Application/Home/Conf/config.php 文件以可写权限!',
+  "not_writable_sqlite"=>'请赋予 /Sqlite 目录以可写权限!',
+  "not_writable_sqlite_db"=>'请赋予 /Sqlite/showdoc.db.php 以可写权限!',
+  "install_success"=>'安装成功!建议删除/install目录,以免安装脚本被再次执行。',
+  "install_config_not_writable"=>'安装失败,配置文件写入错误!',
+  "db_wrong"=>'数据库链接错误,请检查配置信息是否填写正确',
+  "db_has_data"=>'检测到该数据库已经存在数据。请清理后再重试',
+  "create_table_fail"=>'创建数据库表失败!',
+  "install_config_not_writable"=>'安装失败,配置文件写入错误!',
+
+  );