PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/#/#.php

https://bitbucket.org/nemo_xiaolan/muyou
PHP | 139 lines | 72 code | 23 blank | 44 comment | 13 complexity | a659047f77e1b5e534254b31fc185023 MD5 | raw file
  1. <?php
  2. /**
  3. * @author Nemo <nemo.xiaolan@gmail.com>
  4. */
  5. !defined("IN_APP") && exit();
  6. #header('P3P: CP="CAO PSA OUR"');
  7. header("Content-Type:text/html;charset=utf-8");
  8. unset($GLOBALS);
  9. /**
  10. * 开启输出缓冲
  11. */
  12. require "lib/func.ob.php";
  13. //ob_start("ob_gzip");
  14. ob_start();
  15. /**
  16. * 全局约定配置
  17. */
  18. $C = require "#@.php";
  19. require "lib/func.utils.php";
  20. require "lib/func.common.php";
  21. /**
  22. * 模板配置开始 初始化模板引擎
  23. */
  24. import("vendor/smarty/Smarty.class");
  25. $tpl = new Smarty();
  26. foreach($C['tpl'] as $k=> $cnf) {
  27. $tpl->$k = $cnf;
  28. }
  29. unset($k);
  30. unset($cnf);
  31. /**
  32. * 载入smarty插件
  33. */
  34. load_smarty_tag();
  35. /**
  36. * 初始化插件
  37. */
  38. import("lib/class.pluggable");
  39. Pluggable::init();
  40. /**
  41. * 注册结束时的函数
  42. */
  43. import("lib/func.when_shutdown");
  44. /**
  45. * 泛解析二级域名
  46. */
  47. if(!isset($C['base']['runmode']) or $C['base']['runmode'] != 'devel') {
  48. $sd = array_shift(explode(".", $_SERVER["HTTP_HOST"]));
  49. if(!in_array($sd, $C["denied_domain_list"]) and $_SERVER["HTTP_HOST"] !== $C["base"]["host"]) {
  50. $_SERVER["REQUEST_URI"] = $_SERVER["REQUEST_URI"] == "/" ? "" : $_SERVER["REQUEST_URI"];
  51. $_SERVER["REQUEST_URI"] = sprintf("/view/%s%s", $sd, $_SERVER["REQUEST_URI"]);
  52. }
  53. unset($sd);
  54. unset($uri);
  55. }
  56. /**
  57. * URI解析/分发
  58. */
  59. import("lib/class.dispatcher");
  60. Dispatcher::$type = $C["base"]["url_type"];
  61. $action = Dispatcher::work();
  62. $action["group"] = $action["group"] ? $action["group"] : "home";
  63. $action["name"] = $action["name"] ? $action["name"] : "index";
  64. $action_file = PROJECT_DIR.DS."actions".DS.$action["group"].DS.$action["name"].".php";
  65. if(!is_file($action_file)) {
  66. $action["not_found"] = $action["name"];
  67. $action["source_name"] = $action["name"];
  68. $action["name"] = "index";
  69. $action_file = PROJECT_DIR.DS."actions".DS.$action["group"].DS.$action["name"].".php";
  70. if(!is_file($action_file)) {
  71. /**
  72. * 首先判断是否存在模板文件, 存在则直接显示
  73. */
  74. if($action["params"]) {
  75. $the_param = "/".implode("/", $action["params"]);
  76. }
  77. $is_tpl = sprintf("%s/%s%s.tpl", $action["group"], $action["source_name"], $the_param);
  78. if($tpl->templateExists($is_tpl)) {
  79. $include_tpl = true;
  80. } else {
  81. r("error/404");
  82. }
  83. }
  84. }
  85. $C["action"] = $action;
  86. /**
  87. * 引入常用包
  88. */
  89. import("lib/database/pdo");
  90. import("lib/class.model");
  91. import("actions/account/class.user");
  92. import("actions/blog/func.blog");
  93. import("actions/account/func.account");
  94. /**
  95. * session
  96. */
  97. import("lib/class.session");
  98. /**
  99. * swf upload
  100. */
  101. if($_GET["UPLOAD_HASH"]) {
  102. session_id($_GET["UPLOAD_HASH"]);
  103. }
  104. session_start();
  105. /**
  106. * 实例化用户信息
  107. */
  108. $user = new User();
  109. $tpl->assign("user", $user);
  110. $tpl->assign("C", $C);
  111. if($include_tpl) {
  112. $tpl->display($is_tpl);
  113. exit;
  114. } else {
  115. require $action_file;
  116. }