ajax.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. $config =
  47. <<<EOD
  48. <?php
  49. return array(
  50. //'配置项'=>'配置值'
  51. //使用sqlite数据库
  52. 'DB_TYPE' => 'Sqlite',
  53. 'DB_NAME' => 'Sqlite/showdoc.db.php',
  54. //showdoc不再支持mysql http://www.showdoc.cc/help?page_id=31990
  55. 'DB_HOST' => 'localhost',
  56. 'DB_USER' => 'showdoc',
  57. 'DB_PWD' => 'showdoc123456',
  58. 'DB_PORT' => 3306, // 端口
  59. 'DB_PREFIX' => '', // 数据库表前缀
  60. 'DB_CHARSET'=> 'utf8', // 字符集
  61. 'DB_DEBUG' => TRUE, // 数据库调试模式 开启后可以记录SQL日志
  62. 'URL_HTML_SUFFIX' => '',//url伪静态后缀
  63. 'URL_MODEL' => 3 ,//URL兼容模式
  64. 'URL_ROUTER_ON' => true,
  65. 'URL_ROUTE_RULES'=>array(
  66. ':id\d' => 'Home/Item/show?item_id=:1',
  67. ':domain\s$' => 'Home/Item/show?item_domain=:1',//item的个性域名
  68. 'uid/:id\d' => 'Home/Item/showByUid?uid=:1',
  69. 'page/:id\d' => 'Home/Page/single?page_id=:1',
  70. ),
  71. 'URL_CASE_INSENSITIVE'=>true,
  72. 'SHOW_ERROR_MSG' => true, // 显示错误信息,这样在部署模式下也能显示错误
  73. 'STATS_CODE' =>'', //可选,统计代码
  74. 'TMPL_CACHE_ON' => false,//禁止模板编译缓存
  75. 'HTML_CACHE_ON' => false,//禁止静态缓存
  76. //上传文件到七牛的配置
  77. 'UPLOAD_SITEIMG_QINIU' => array(
  78. 'maxSize' => 5 * 1024 * 1024,//文件大小
  79. 'rootPath' => './',
  80. 'saveName' => array ('uniqid', ''),
  81. 'driver' => 'Qiniu',
  82. 'driverConfig' => array (
  83. 'secrectKey' => '',
  84. 'accessKey' => '',
  85. 'domain' => '',
  86. 'bucket' => '',
  87. )
  88. ),
  89. );
  90. EOD;
  91. $ret = file_put_contents("../Application/Common/Conf/config.php", $config);
  92. if ($ret) {
  93. file_put_contents("./install.lock","https://www.showdoc.cc/");
  94. ajax_out(L("install_success"));
  95. }else{
  96. ajax_out(L("install_config_not_writable"),10001);
  97. }
  98. }
  99. function write_home_config(){
  100. $lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
  101. if ($lang == 'en') {
  102. $DEFAULT_LANG = 'en-us';
  103. }else{
  104. $DEFAULT_LANG = 'zh-cn';
  105. }
  106. $config = "<?php ";
  107. $config .= "
  108. return array(
  109. //'配置项'=>'配置值'
  110. 'LANG_SWITCH_ON' => true, // 开启语言包功能
  111. 'LANG_AUTO_DETECT' => false, // 自动侦测语言 开启多语言功能后有效
  112. 'DEFAULT_LANG' => '{$DEFAULT_LANG}', // 默认语言
  113. 'LANG_LIST' => 'zh-cn,en-us', // 允许切换的语言列表 用逗号分隔
  114. 'VAR_LANGUAGE' => 'l', // 默认语言切换变量
  115. );";
  116. $ret = file_put_contents("../Application/Home/Conf/config.php", $config);
  117. }