App.class.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. // +--------------------------------------------------------------------------
  3. // | Senthot [ DEVELOPED BY ME ]
  4. // +--------------------------------------------------------------------------
  5. // | Copyright (c) 2005-2013 http://www.senthot.com All rights reserved.
  6. // | License ( http://www.apache.org/licenses/LICENSE-2.0 )
  7. // | Author: ms134n ( [email protected] )
  8. // +--------------------------------------------------------------------------
  9. /**
  10. * Senthot Application class Execution of the application process management
  11. * You can redefine schema extensions However, the interface must have a Run method
  12. * @category Sen
  13. * @package Sen
  14. * @subpackage Core
  15. * @author ms134n <[email protected]>
  16. */
  17. class App {
  18. /**
  19. * Application initialization
  20. * @access public
  21. * @return void
  22. */
  23. static public function init() {
  24. // Set the system time zone
  25. date_default_timezone_set(C('DEFAULT_TIMEZONE'));
  26. // Public load dynamic project files and configuration
  27. load_ext_file();
  28. // URL dispatcher
  29. Dispatcher::dispatch();
  30. // System constants defined for the current request
  31. define('NOW_TIME', $_SERVER['REQUEST_TIME']);
  32. define('REQUEST_METHOD',$_SERVER['REQUEST_METHOD']);
  33. define('IS_GET', REQUEST_METHOD =='GET' ? true : false);
  34. define('IS_POST', REQUEST_METHOD =='POST' ? true : false);
  35. define('IS_PUT', REQUEST_METHOD =='PUT' ? true : false);
  36. define('IS_DELETE', REQUEST_METHOD =='DELETE' ? true : false);
  37. define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') || !empty($_POST[C('VAR_AJAX_SUBMIT')]) || !empty($_GET[C('VAR_AJAX_SUBMIT')])) ? true : false);
  38. // URL dispatcher end tag
  39. tag('url_dispatch');
  40. // Page Compression Output Support
  41. if(C('OUTPUT_ENCODE')){
  42. $zlib = ini_get('zlib.output_compression');
  43. if(empty($zlib)) ob_start('ob_gzhandler');
  44. }
  45. // Security filtering system variables
  46. if(C('VAR_FILTERS')) {
  47. $filters = explode(',',C('VAR_FILTERS'));
  48. foreach($filters as $filter){
  49. // Global Parameters filter
  50. array_walk_recursive($_POST,$filter);
  51. array_walk_recursive($_GET,$filter);
  52. }
  53. }
  54. /* Get the name of the template topic */
  55. $templateSet = C('DEFAULT_THEME');
  56. if(C('TMPL_DETECT_THEME')) {// Automatically detects the template theme
  57. $t = C('VAR_TEMPLATE');
  58. if (isset($_GET[$t])){
  59. $templateSet = $_GET[$t];
  60. }elseif(cookie('sen_template')){
  61. $templateSet = cookie('sen_template');
  62. }
  63. if(!in_array($templateSet,explode(',',C('THEME_LIST')))){
  64. $templateSet = C('DEFAULT_THEME');
  65. }
  66. cookie('sen_template',$templateSet,864000);
  67. }
  68. /* Template Related Category constants */
  69. define('THEME_NAME', $templateSet); // Current template theme name
  70. $group = defined('GROUP_NAME')?GROUP_NAME.'/':'';
  71. if(1==C('APP_GROUP_MODE')){ // Independent Packet Mode
  72. define('THEME_PATH', BASE_LIB_PATH.basename(TMPL_PATH).'/'.(THEME_NAME?THEME_NAME.'/':''));
  73. define('APP_TMPL_PATH',__ROOT__.'/'.APP_NAME.(APP_NAME?'/':'').C('APP_GROUP_PATH').'/'.$group.basename(TMPL_PATH).'/'.(THEME_NAME?THEME_NAME.'/':''));
  74. }else{
  75. define('THEME_PATH', TMPL_PATH.$group.(THEME_NAME?THEME_NAME.'/':''));
  76. define('APP_TMPL_PATH',__ROOT__.'/'.APP_NAME.(APP_NAME?'/':'').basename(TMPL_PATH).'/'.$group.(THEME_NAME?THEME_NAME.'/':''));
  77. }
  78. C('CACHE_PATH',CACHE_PATH.$group);
  79. //Dynamic Configuration TMPL_EXCEPTION_FILE, to absolute address
  80. C('TMPL_EXCEPTION_FILE',realpath(C('TMPL_EXCEPTION_FILE')));
  81. return ;
  82. }
  83. /**
  84. * Execution of the application
  85. * @access public
  86. * @return void
  87. */
  88. static public function exec() {
  89. if(!preg_match('/^[A-Za-z](\w)*$/',MODULE_NAME)){ // Safety testing
  90. $module = false;
  91. }else{
  92. //Creating Action controller instance
  93. $group = defined('GROUP_NAME') && C('APP_GROUP_MODE')==0 ? GROUP_NAME.'/' : '';
  94. $module = A($group.MODULE_NAME);
  95. }
  96. if(!$module) {
  97. if('4e5e5d7364f443e28fbf0d3ae744a59a' == MODULE_NAME) {
  98. header("Content-type:image/png");
  99. exit(base64_decode(App::logo()));
  100. }
  101. if(function_exists('__hack_module')) {
  102. // hack Define the expansion module Back Action object
  103. $module = __hack_module();
  104. if(!is_object($module)) {
  105. // No longer continue Direct return
  106. return ;
  107. }
  108. }else{
  109. // Whether the definition of Empty module
  110. $module = A($group.'Empty');
  111. if(!$module){
  112. _404(L('_MODULE_NOT_EXIST_').':'.MODULE_NAME);
  113. }
  114. }
  115. }
  116. // Get the current operation name Support dynamic routing
  117. $action = C('ACTION_NAME')?C('ACTION_NAME'):ACTION_NAME;
  118. C('TEMPLATE_NAME',THEME_PATH.MODULE_NAME.C('TMPL_FILE_DEPR').$action.C('TMPL_TEMPLATE_SUFFIX'));
  119. $action .= C('ACTION_SUFFIX');
  120. try{
  121. if(!preg_match('/^[A-Za-z](\w)*$/',$action)){
  122. // Illegal Operation
  123. throw new ReflectionException();
  124. }
  125. //Perform the current operation
  126. $method = new ReflectionMethod($module, $action);
  127. if($method->isPublic()) {
  128. $class = new ReflectionClass($module);
  129. // Pre-operation
  130. if($class->hasMethod('_before_'.$action)) {
  131. $before = $class->getMethod('_before_'.$action);
  132. if($before->isPublic()) {
  133. $before->invoke($module);
  134. }
  135. }
  136. // URL parameter binding detection
  137. if(C('URL_PARAMS_BIND') && $method->getNumberOfParameters()>0){
  138. switch($_SERVER['REQUEST_METHOD']) {
  139. case 'POST':
  140. $vars = $_POST;
  141. break;
  142. case 'PUT':
  143. parse_str(file_get_contents('php://input'), $vars);
  144. break;
  145. default:
  146. $vars = $_GET;
  147. }
  148. $params = $method->getParameters();
  149. foreach ($params as $param){
  150. $name = $param->getName();
  151. if(isset($vars[$name])) {
  152. $args[] = $vars[$name];
  153. }elseif($param->isDefaultValueAvailable()){
  154. $args[] = $param->getDefaultValue();
  155. }else{
  156. throw_exception(L('_PARAM_ERROR_').':'.$name);
  157. }
  158. }
  159. $method->invokeArgs($module,$args);
  160. }else{
  161. $method->invoke($module);
  162. }
  163. // Rear Operation
  164. if($class->hasMethod('_after_'.$action)) {
  165. $after = $class->getMethod('_after_'.$action);
  166. if($after->isPublic()) {
  167. $after->invoke($module);
  168. }
  169. }
  170. }else{
  171. // Method of operation is not Public throw an exception
  172. throw new ReflectionException();
  173. }
  174. } catch (ReflectionException $e) {
  175. // Method call after an exception occurs Directed to __call approach
  176. $method = new ReflectionMethod($module,'__call');
  177. $method->invokeArgs($module,array($action,''));
  178. }
  179. return ;
  180. }
  181. /**
  182. * Run Applications Import files using the shortcut method
  183. * @access public
  184. * @return void
  185. */
  186. static public function run() {
  187. // Project Initialization tab
  188. tag('app_init');
  189. App::init();
  190. // Project start tag
  191. tag('app_begin');
  192. // Session Initialization
  193. session(C('SESSION_OPTIONS'));
  194. // Record application initialization time
  195. G('initTime');
  196. App::exec();
  197. // Tag end of the project
  198. tag('app_end');
  199. // Save the log records
  200. if(C('LOG_RECORD')) Log::save();
  201. return ;
  202. }
  203. static public function logo(){
  204. return 'iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAANlBMVEUAZsz////G099Zn8HE0d7y9/zz+P33+v0ie7wjfLwkfLzu8fNeocNtqsn1+f1xrcp2r8yvzel/Y2NuAAAA20lEQVR4Xt2RSw4DIQxDx8x/+r//ZStNo5rIQgnLllUW7xFjhh86pZMHSicPTJ08UHr4baCR4Xdbk+dtmJI8x5LlaaR5por6sYE7cjyQ2PGl7nAGgvxqlKj/wBDeDEi7zfcC1hO8oTwNG8WQPI/KgLZL/uCVTCVdaX5vzGrovwI3b8wns7v/u3jjWRnGv8jrDtRdyf1inPzVv3izSQzq48dYXf6mwa6EF8O1u7o8oTG28rfaXVyf8Y7F5Y8N4UOD+WND+dhgnpwR8dou+8zuYP6kQT6fquuQ/8PzBqPwA96+q0kmAAAAAElFTkSuQmCC';
  205. }
  206. }