/** * 执行App控制器 * @access public * @return void */ public static function execApp() { //防止CSRF if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' && stripos($_SERVER['HTTP_REFERER'], SITE_URL) !== 0 && $_SERVER['HTTP_USER_AGENT'] !== 'Shockwave Flash') { die('illegal request.'); } // 使用手持设备时, 对用户的访问默认跳转至移动版, 除非用户指定访问普通版 if ($_SESSION['wap_to_normal'] != '1' && cookie('wap_to_normal') != '1' && $_REQUEST['wap_to_normal'] != '1' && !isiPad()) { // 根据各应用的配置来判断是否存在手机版访问配置文件 $publicAccess = array('message', 'register', 'feed'); if (APP_NAME == 'public' && !in_array(strtolower(MODULE_NAME), $publicAccess) && strtolower(ACTION_NAME) != 'message' && isMobile() && in_array('wap', C('DEFAULT_APPS'))) { // 智能手机到3G版 if (APP_NAME == 'public' && (isiPhone() || isAndroid())) { // iOS和Android跳转至3G版 U('w3g/Index/index', '', true); } else { // 其他手机跳转至WAP版 U('wap/Index/index', '', true); } } } // 加载所有插件 if (C('APP_PLUGIN_ON')) { tsload(CORE_LIB_PATH . '/addons.class.php'); tsload(CORE_LIB_PATH . '/addons/Hooks.class.php'); tsload(CORE_LIB_PATH . '/addons/AbstractAddons.class.php'); tsload(CORE_LIB_PATH . '/addons/NormalAddons.class.php'); tsload(CORE_LIB_PATH . '/addons/SimpleAddons.class.php'); tsload(CORE_LIB_PATH . '/addons/TagsAbstract.class.php'); Addons::loadAllValidAddons(); } //创建Action控制器实例 $className = MODULE_NAME . 'Action'; tsload(APP_ACTION_PATH . '/' . $className . '.class.php'); if (!class_exists($className)) { $className = 'EmptyAction'; tsload(APP_ACTION_PATH . '/EmptyAction.class.php'); if (!class_exists($className)) { throw_exception(L('_MODULE_NOT_EXIST_') . ' ' . MODULE_NAME); } } $module = new $className(); //异常处理 if (!$module) { // 模块不存在 抛出异常 throw_exception(L('_MODULE_NOT_EXIST_') . ' ' . MODULE_NAME); } //获取当前操作名 $action = ACTION_NAME; //执行当前操作 call_user_func(array(&$module, $action)); //执行计划任务 model('Schedule')->run(); return; }
/** * 执行App控制器 */ public static function execApp() { //防止CSRF if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' && stripos($_SERVER['HTTP_REFERER'], SITE_URL) !== 0 && $_SERVER['HTTP_USER_AGENT'] !== 'Shockwave Flash' && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'adobe flash player') === false && MODULE_NAME != 'Weixin') { exit('illegal request.'); } // 微信自动登陆和绑定 $openid = session('wx_open_id'); $mid = $_SESSION['mid'] ?: $_SESSION['uid']; // var_dump($openid);exit; if ($openid) { $login = Ts\Models\Login::byType('weixin')->byVendorId($openid)->orderBy('login_id', 'desc')->first(); if (!$login && $mid) { $login = new Ts\Model\Login(); $login->uid = $mid; $login->type_uid = $openid; $login->type = 'weixin'; $login->is_sync = 0; $login->save(); // var_dump(123); } // var_dump($openid, $login, $_SESSION);exit; if (!$mid && $login) { $_SESSION['mid'] = $login->uid; } } // 微信 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false && isset($_REQUEST['w_sign']) && !$openid) { U('h5/sign/weixin', '', true); /* # 跳转移动版首页,以后有时间,可以做兼容跳转 */ } elseif ($_SESSION['wap_to_normal'] != 1 and cookie('wap_to_normal') != 1 and $_REQUEST['wap_to_normal'] != 1 and !isiPad() and json_decode(json_encode(model('Xdata')->get('admin_Mobile:setting')), false)->switch and in_array(APP_NAME, array('public', 'channel', 'weiba', 'square', 'people')) and MODULE_NAME != 'Widget' and !in_array(strtolower(MODULE_NAME), array('message', 'register', 'feed')) and strtolower(ACTION_NAME) != 'message' and isMobile()) { if (\Medz\Component\Filesystem\Filesystem::exists(TS_APPLICATION . '/h5') === true) { Jumper::start(); } } $GLOBALS['time_run_detail']['addons_end'] = microtime(true); //创建Action控制器实例 $className = MODULE_NAME . 'Action'; // tsload(APP_ACTION_PATH.'/'.$className.'.class.php'); $action = ACTION_NAME; // action名称 $appTimer = sprintf('%s/%s/app/%s/timer', TS_ROOT, TS_STORAGE, strtolower(APP_NAME)); if (!file_exists($appTimer) || time() - file_get_contents($appTimer) > 604800 || defined('TS_APP_DEV') && TS_APP_DEV == true) { \Ts\Helper\AppInstall::getInstance(APP_NAME)->moveResources(); \Medz\Component\Filesystem\Filesystem::mkdir(dirname($appTimer), 0777); file_put_contents($appTimer, time()); } $app = new \Ts\Helper\Controller(); $app->setApp(APP_NAME)->setController(MODULE_NAME)->setAction(ACTION_NAME)->run(); //执行计划任务 model('Schedule')->run(); $GLOBALS['time_run_detail']['action_run'] = microtime(true); return; }
function isiOS() { return isiPhone() || isiPad(); }
/** * 执行App控制器 * @access public * @return void */ public static function execApp() { //防止CSRF if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' && stripos($_SERVER['HTTP_REFERER'], SITE_URL) !== 0 && $_SERVER['HTTP_USER_AGENT'] !== 'Shockwave Flash' && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'adobe flash player') === false && MODULE_NAME != 'Weixin') { die('illegal request.'); } // 使用手持设备时, 对用户的访问默认跳转至移动版, 除非用户指定访问普通版 if ($_SESSION['wap_to_normal'] != '1' && cookie('wap_to_normal') != '1' && $_REQUEST['wap_to_normal'] != '1' && !isiPad()) { // 根据各应用的配置来判断是否存在手机版访问配置文件 $publicAccess = array('message', 'register', 'feed'); if (in_array(APP_NAME, array('public', 'channel', 'weiba', 'square', 'people')) && MODULE_NAME != 'Widget' && !in_array(strtolower(MODULE_NAME), $publicAccess) && strtolower(ACTION_NAME) != 'message' && isMobile() && in_array('wap', C('DEFAULT_APPS'))) { U('w3g/Public/home', '', true); } } $GLOBALS['time_run_detail']['addons_end'] = microtime(true); //创建Action控制器实例 $className = MODULE_NAME . 'Action'; tsload(APP_ACTION_PATH . '/' . $className . '.class.php'); if (!class_exists($className)) { $className = 'EmptyAction'; tsload(APP_ACTION_PATH . '/EmptyAction.class.php'); if (!class_exists($className)) { throw_exception(L('_MODULE_NOT_EXIST_') . ' ' . MODULE_NAME); } } $module = new $className(); $GLOBALS['time_run_detail']['action_instance'] = microtime(true); //异常处理 if (!$module) { // 模块不存在 抛出异常 throw_exception(L('_MODULE_NOT_EXIST_') . ' ' . MODULE_NAME); } //获取当前操作名 $action = ACTION_NAME; //执行当前操作 call_user_func(array(&$module, $action)); //执行计划任务 model('Schedule')->run(); $GLOBALS['time_run_detail']['action_run'] = microtime(true); return; }
/** * 执行App控制器 * @access public * @return void */ public static function execApp() { //防止CSRF if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' && stripos($_SERVER['HTTP_REFERER'], SITE_URL) !== 0 && $_SERVER['HTTP_USER_AGENT'] !== 'Shockwave Flash' && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'adobe flash player') === false && MODULE_NAME != 'Weixin') { die('illegal request.'); } /* # 跳转移动版首页,以后有时间,可以做兼容跳转 */ if ($_SESSION['wap_to_normal'] != 1 and cookie('wap_to_normal') != 1 and $_REQUEST['wap_to_normal'] != 1 and !isiPad() and json_decode(json_encode(model('Xdata')->get('admin_Mobile:setting')), false)->switch and in_array(APP_NAME, array('public', 'channel', 'weiba', 'square', 'people')) and MODULE_NAME != 'Widget' and !in_array(strtolower(MODULE_NAME), array('message', 'register', 'feed')) and strtolower(ACTION_NAME) != 'message' and isMobile() and in_array('wap', C('DEFAULT_APPS'))) { U('w3g/Public/home', '', true); } $GLOBALS['time_run_detail']['addons_end'] = microtime(true); //创建Action控制器实例 $className = MODULE_NAME . 'Action'; tsload(APP_ACTION_PATH . '/' . $className . '.class.php'); if (!class_exists($className)) { $className = 'EmptyAction'; tsload(APP_ACTION_PATH . '/EmptyAction.class.php'); if (!class_exists($className)) { throw_exception(L('_MODULE_NOT_EXIST_') . ' ' . MODULE_NAME); } } //echo $className; $module = new $className(); $GLOBALS['time_run_detail']['action_instance'] = microtime(true); //异常处理 if (!$module) { // 模块不存在 抛出异常 throw_exception(L('_MODULE_NOT_EXIST_') . ' ' . MODULE_NAME); } //获取当前操作名 $action = ACTION_NAME; //echo $action; //执行当前操作 call_user_func(array(&$module, $action)); //执行计划任务 model('Schedule')->run(); $GLOBALS['time_run_detail']['action_run'] = microtime(true); return; }
/** * 执行应用程序 * @access public * @return void */ public static function exec() { // 使用手持设备时, 对用户的访问默认跳转至移动版, 除非用户指定访问普通版 if (MODULE_NAME == 'Home' && $_SESSION['wap_to_normal'] != '1' && cookie('wap_to_normal') != '1' && $_REQUEST['wap_to_normal'] != '1' && !isiPad()) { if (isMobile()) { // 智能手机到3G版 if (isiPhone() || isAndroid()) { // iOS和Android跳转至3G版 redirect(U('/Wap/Index/index'), 0, ''); } } } if (!preg_match('/^[A-Za-z](\\/|\\w)*$/', CONTROLLER_NAME)) { // 安全检测 $module = false; } elseif (C('ACTION_BIND_CLASS')) { // 操作绑定到类:模块\Controller\控制器\操作 $layer = C('DEFAULT_C_LAYER'); if (is_dir(MODULE_PATH . $layer . '/' . CONTROLLER_NAME)) { $namespace = MODULE_NAME . '\\' . $layer . '\\' . CONTROLLER_NAME . '\\'; } else { // 空控制器 $namespace = MODULE_NAME . '\\' . $layer . '\\_empty\\'; } $actionName = strtolower(ACTION_NAME); if (class_exists($namespace . $actionName)) { $class = $namespace . $actionName; } elseif (class_exists($namespace . '_empty')) { // 空操作 $class = $namespace . '_empty'; } else { E(L('_ERROR_ACTION_') . ':' . ACTION_NAME); } $module = new $class(); // 操作绑定到类后 固定执行run入口 $action = 'run'; } else { //创建控制器实例 $module = A(CONTROLLER_NAME); } if (!$module) { if ('4e5e5d7364f443e28fbf0d3ae744a59a' == CONTROLLER_NAME) { header("Content-type:image/png"); exit(base64_decode(App::logo())); } // 是否定义Empty控制器 $module = A('Empty'); if (!$module) { E(L('_CONTROLLER_NOT_EXIST_') . ':' . CONTROLLER_NAME); } } // 获取当前操作名 支持动态路由 if (!isset($action)) { $action = ACTION_NAME . C('ACTION_SUFFIX'); } try { if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) { // 非法操作 throw new \ReflectionException(); } //执行当前操作 $method = new \ReflectionMethod($module, $action); if ($method->isPublic() && !$method->isStatic()) { $class = new \ReflectionClass($module); // 前置操作 if ($class->hasMethod('_before_' . $action)) { $before = $class->getMethod('_before_' . $action); if ($before->isPublic()) { $before->invoke($module); } } // URL参数绑定检测 if ($method->getNumberOfParameters() > 0 && C('URL_PARAMS_BIND')) { switch ($_SERVER['REQUEST_METHOD']) { case 'POST': $vars = array_merge($_GET, $_POST); break; case 'PUT': parse_str(file_get_contents('php://input'), $vars); break; default: $vars = $_GET; } $params = $method->getParameters(); $paramsBindType = C('URL_PARAMS_BIND_TYPE'); foreach ($params as $param) { $name = $param->getName(); if (1 == $paramsBindType && !empty($vars)) { $args[] = array_shift($vars); } elseif (0 == $paramsBindType && isset($vars[$name])) { $args[] = $vars[$name]; } elseif ($param->isDefaultValueAvailable()) { $args[] = $param->getDefaultValue(); } else { E(L('_PARAM_ERROR_') . ':' . $name); } } $method->invokeArgs($module, $args); } else { $method->invoke($module); } // 后置操作 if ($class->hasMethod('_after_' . $action)) { $after = $class->getMethod('_after_' . $action); if ($after->isPublic()) { $after->invoke($module); } } } else { // 操作方法不是Public 抛出异常 throw new \ReflectionException(); } } catch (\ReflectionException $e) { // 方法调用发生异常后 引导到__call方法处理 $method = new \ReflectionMethod($module, '__call'); $method->invokeArgs($module, array($action, '')); } return; }