Esempio n. 1
0
 /**
  * 构造方法
  *
  * @author Seven Du <*****@*****.**>
  **/
 protected function __construct()
 {
     if (!self::$appName) {
         throw new Exception('没有传递需要初始化的应用!', 1);
     }
     $handle = opendir(TS_APPLICATION);
     while (($file = readdir($handle)) !== false) {
         if (strtolower($file) == self::$appName) {
             self::$applicationDir = TS_APPLICATION . Ts::DS . $file;
             break;
         }
     }
     closedir($handle);
     $manageFile = self::$applicationDir . Ts::DS . 'manage.json';
     if (!self::$applicationDir) {
         throw new Exception('应用:“' . self::$appName . '”不存在!', 1);
     } elseif (!Filesystem::exists($manageFile)) {
         throw new Exception(sprintf('不存在应用配置文件:“%s”', $manageFile));
     }
     self::$appInfo = file_get_contents($manageFile);
     self::$appInfo = json_decode(self::$appInfo, true);
     if (!isset(self::$appInfo['resource'])) {
         self::$appInfo['resource'] = '_static';
     }
 }
Esempio n. 2
0
 /**
  * 执行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;
 }
Esempio n. 3
0
 /**
  * 运行控制器
  */
 public static function run()
 {
     // 设定错误和异常处理
     set_error_handler(array('App', 'appError'));
     set_exception_handler(array('App', 'appException'));
     // Session初始化
     if (!session_id()) {
         session_start();
     }
     // 模版检查
     $GLOBALS['time_run_detail']['init_end'] = microtime(true);
     //检查服务器是否开启了zlib拓展
     if (C('GZIP_OPEN') && extension_loaded('zlib') && function_exists('ob_gzhandler')) {
         ob_end_clean();
         ob_start('ob_gzhandler');
     }
     $GLOBALS['time_run_detail']['obstart'] = microtime(true);
     $pharApiFile = sprintf('%s/api/ts-api.phar', TS_ROOT);
     if (constant('API_VERSION') && API_VERSION == 'sociax' && !\Medz\Component\Filesystem\Filesystem::exists(sprintf('%s/api/sociax', TS_ROOT))) {
         $class_file = sprintf('phar://%s/%sApi.class.php', $pharApiFile, MODULE_NAME);
     } elseif (constant('API_VERSION')) {
         $class_file = SITE_PATH . '/api/' . API_VERSION . '/' . MODULE_NAME . 'Api.class.php';
     } else {
         $class_file = SITE_PATH . '/api/thinksns/' . MODULE_NAME . 'Api.class.php';
     }
     if (!file_exists($class_file)) {
         $message['msg'] = '接口不存在';
         $message['status'] = 404;
         API::error($message);
     }
     //执行当前操作
     include $class_file;
     $className = MODULE_NAME . 'Api';
     $module = new $className();
     $action = ACTION_NAME;
     $data = call_user_func(array(&$module, $action));
     //格式化输出
     if ($_REQUEST['format'] == 'php') {
         //输出php格式
         echo var_export($data);
     } elseif ($_REQUEST['format'] == 'test') {
         //测试输出
         dump($data);
     } else {
         header('Content-Type:application/json');
         echo json_encode($data);
     }
     //输出buffer中的内容,即压缩后的css文件
     if (C('GZIP_OPEN') && extension_loaded('zlib') && function_exists('ob_gzhandler')) {
         ob_end_flush();
     }
     $GLOBALS['time_run_detail']['obflush'] = microtime(true);
     if (C('LOG_RECORD')) {
         Log::save();
     }
     return;
 }
Esempio n. 4
0
 public function testExists()
 {
     $this->assertEquals(true, Filesystem::exists(static::$file));
 }