You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 rivejä
2.8 KiB

4 vuotta sitten
  1. <?php
  2. // --------
  3. // 如果你能在浏览器中看到本句话,则证明你没有安装好PHP运行环境。请先安装好PHP运行环境
  4. // --------
  5. ini_set("display_errors", "Off");
  6. error_reporting(E_ALL | E_STRICT);
  7. header("Content-type: text/html; charset=utf-8");
  8. include("common.php");
  9. if(file_exists('./install.lock') && $f = file_get_contents("./install.lock")){
  10. ajax_out(L("lock"),10099);
  11. }
  12. if(!new_is_writeable("./")){
  13. ajax_out(L("not_writable_install"),10098);
  14. }
  15. if(!new_is_writeable("../Public/Uploads")){
  16. ajax_out(L("not_writable_upload"),10098);
  17. }
  18. if(!new_is_writeable("../server/Application/Runtime")){
  19. ajax_out(L("not_writable_server_runtime"),10095);
  20. }
  21. if(!new_is_writeable("../server/Application/Home/Conf/config.php")){
  22. ajax_out(L("not_writable_home_config"),10098);
  23. }
  24. $db_type = $_POST["db_type"] ? $_POST["db_type"] :"sqlite";
  25. if ($db_type == "sqlite") {
  26. if(!new_is_writeable("../Sqlite")){
  27. ajax_out(L("not_writable_sqlite"),10097);
  28. }
  29. if(!new_is_writeable("../Sqlite/showdoc.db.php")){
  30. ajax_out(L("not_writable_sqlite_db"),10096);
  31. }
  32. user_sqlite();
  33. }
  34. elseif ($db_type == "mysql") {
  35. //showdoc不再支持mysql http://www.showdoc.cc/help?page_id=31990
  36. }
  37. function user_sqlite(){
  38. clear_runtime();//清除缓存
  39. write_js_lang();
  40. $ret = write_home_config();
  41. if ($ret) {
  42. file_put_contents("./install.lock","https://www.showdoc.cc/");
  43. ajax_out(L("install_success"));
  44. }else{
  45. ajax_out(L("not_writable_home_config"),10001);
  46. }
  47. }
  48. function write_home_config(){
  49. $lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
  50. if ($lang == 'en') {
  51. $DEFAULT_LANG = 'en-us';
  52. }else{
  53. $DEFAULT_LANG = 'zh-cn';
  54. }
  55. $config = "<?php ";
  56. $config .= "
  57. return array(
  58. //'配置项'=>'配置值'
  59. 'DB_TYPE' => 'Sqlite',
  60. 'DB_NAME' => './Sqlite/showdoc.db.php',
  61. 'LANG_SWITCH_ON' => true, // 开启语言包功能
  62. 'LANG_AUTO_DETECT' => false, // 自动侦测语言 开启多语言功能后有效
  63. 'DEFAULT_LANG' => '{$DEFAULT_LANG}', // 默认语言
  64. 'LANG_LIST' => 'zh-cn,en-us', // 允许切换的语言列表 用逗号分隔
  65. 'VAR_LANGUAGE' => 'l', // 默认语言切换变量
  66. );";
  67. $ret = file_put_contents("../server/Application/Home/Conf/config.php", $config);
  68. return $ret ;
  69. }
  70. function write_js_lang(){
  71. $lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
  72. if ($lang == 'en') {
  73. replace_file_content("../web/index.html","zh-cn","en") ;
  74. replace_file_content("../web_src/index.html","zh-cn","en") ;
  75. }
  76. }
  77. function replace_file_content($file , $from ,$to ){
  78. $content = file_get_contents($file);
  79. $content2 = str_replace($from,$to,$content);
  80. if ($content2) {
  81. file_put_contents($file,$content2);
  82. }
  83. }