ajax.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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("../Application/Runtime")){
  19. ajax_out(L("not_writable_runtime"),10095);
  20. }
  21. if(!new_is_writeable("../server/Application/Runtime")){
  22. ajax_out(L("not_writable_server_runtime"),10095);
  23. }
  24. if(!new_is_writeable("../Application/Common/Conf/config.php")){
  25. ajax_out(L("not_writable_config"),10094);
  26. }
  27. if(!new_is_writeable("../Application/Home/Conf/config.php")){
  28. ajax_out(L("not_writable_home_config"),10098);
  29. }
  30. $db_type = $_POST["db_type"] ? $_POST["db_type"] :"sqlite";
  31. if ($db_type == "sqlite") {
  32. if(!new_is_writeable("../Sqlite")){
  33. ajax_out(L("not_writable_sqlite"),10097);
  34. }
  35. if(!new_is_writeable("../Sqlite/showdoc.db.php")){
  36. ajax_out(L("not_writable_sqlite_db"),10096);
  37. }
  38. user_sqlite();
  39. }
  40. elseif ($db_type == "mysql") {
  41. //showdoc不再支持mysql http://www.showdoc.cc/help?page_id=31990
  42. }
  43. function user_sqlite(){
  44. clear_runtime();//清除缓存
  45. write_home_config();
  46. write_js_lang();
  47. $config =
  48. <<<EOD
  49. <?php
  50. return array(
  51. //'配置项'=>'配置值'
  52. //使用sqlite数据库
  53. 'DB_TYPE' => 'Sqlite',
  54. 'DB_NAME' => 'Sqlite/showdoc.db.php',
  55. //showdoc不再支持mysql http://www.showdoc.cc/help?page_id=31990
  56. 'DB_HOST' => 'localhost',
  57. 'DB_USER' => 'showdoc',
  58. 'DB_PWD' => 'showdoc123456',
  59. 'DB_PORT' => 3306, // 端口
  60. 'DB_PREFIX' => '', // 数据库表前缀
  61. 'DB_CHARSET'=> 'utf8', // 字符集
  62. 'DB_DEBUG' => TRUE, // 数据库调试模式 开启后可以记录SQL日志
  63. 'URL_HTML_SUFFIX' => '',//url伪静态后缀
  64. 'URL_MODEL' => 3 ,//URL兼容模式
  65. 'URL_ROUTER_ON' => true,
  66. 'URL_ROUTE_RULES'=>array(
  67. ':id\d' => 'Home/Item/show?item_id=:1',
  68. ':domain\s$' => 'Home/Item/show?item_domain=:1',//item的个性域名
  69. 'uid/:id\d' => 'Home/Item/showByUid?uid=:1',
  70. 'page/:id\d' => 'Home/Page/single?page_id=:1',
  71. ),
  72. 'URL_CASE_INSENSITIVE'=>true,
  73. 'SHOW_ERROR_MSG' => true, // 显示错误信息,这样在部署模式下也能显示错误
  74. 'STATS_CODE' =>'', //可选,统计代码
  75. 'TMPL_CACHE_ON' => false,//禁止模板编译缓存
  76. 'HTML_CACHE_ON' => false,//禁止静态缓存
  77. //上传文件到七牛的配置
  78. 'UPLOAD_SITEIMG_QINIU' => array(
  79. 'maxSize' => 5 * 1024 * 1024,//文件大小
  80. 'rootPath' => './',
  81. 'saveName' => array ('uniqid', ''),
  82. 'driver' => 'Qiniu',
  83. 'driverConfig' => array (
  84. 'secrectKey' => '',
  85. 'accessKey' => '',
  86. 'domain' => '',
  87. 'bucket' => '',
  88. )
  89. ),
  90. );
  91. EOD;
  92. $ret = file_put_contents("../Application/Common/Conf/config.php", $config);
  93. if ($ret) {
  94. file_put_contents("./install.lock","https://www.showdoc.cc/");
  95. ajax_out(L("install_success"));
  96. }else{
  97. ajax_out(L("install_config_not_writable"),10001);
  98. }
  99. }
  100. function write_home_config(){
  101. $lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
  102. if ($lang == 'en') {
  103. $DEFAULT_LANG = 'en-us';
  104. }else{
  105. $DEFAULT_LANG = 'zh-cn';
  106. }
  107. $config = "<?php ";
  108. $config .= "
  109. return array(
  110. //'配置项'=>'配置值'
  111. 'LANG_SWITCH_ON' => true, // 开启语言包功能
  112. 'LANG_AUTO_DETECT' => false, // 自动侦测语言 开启多语言功能后有效
  113. 'DEFAULT_LANG' => '{$DEFAULT_LANG}', // 默认语言
  114. 'LANG_LIST' => 'zh-cn,en-us', // 允许切换的语言列表 用逗号分隔
  115. 'VAR_LANGUAGE' => 'l', // 默认语言切换变量
  116. );";
  117. $ret = file_put_contents("../Application/Home/Conf/config.php", $config);
  118. }
  119. function write_js_lang(){
  120. $lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
  121. if ($lang == 'en') {
  122. replace_file_content("../web/index.html","zh-cn","en") ;
  123. replace_file_content("../web_src/index.html","zh-cn","en") ;
  124. }
  125. }
  126. function replace_file_content($file , $from ,$to ){
  127. $content = file_get_contents($file);
  128. $content2 = str_replace($from,$to,$content);
  129. if ($content2) {
  130. file_put_contents($file,$content2);
  131. }
  132. }