ajax.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. 'LANG_SWITCH_ON' => true, // 开启语言包功能
  60. 'LANG_AUTO_DETECT' => false, // 自动侦测语言 开启多语言功能后有效
  61. 'DEFAULT_LANG' => '{$DEFAULT_LANG}', // 默认语言
  62. 'LANG_LIST' => 'zh-cn,en-us', // 允许切换的语言列表 用逗号分隔
  63. 'VAR_LANGUAGE' => 'l', // 默认语言切换变量
  64. );";
  65. $ret = file_put_contents("../server/Application/Home/Conf/config.php", $config);
  66. return $ret ;
  67. }
  68. function write_js_lang(){
  69. $lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
  70. if ($lang == 'en') {
  71. replace_file_content("../web/index.html","zh-cn","en") ;
  72. replace_file_content("../web_src/index.html","zh-cn","en") ;
  73. }
  74. }
  75. function replace_file_content($file , $from ,$to ){
  76. $content = file_get_contents($file);
  77. $content2 = str_replace($from,$to,$content);
  78. if ($content2) {
  79. file_put_contents($file,$content2);
  80. }
  81. }