예제 #1
0
파일: dispath.php 프로젝트: yaoboqin/fis3
 static function get()
 {
     $args = array();
     $uiPath = dirname(__FILE__) . "/";
     $pageRoot = "";
     //appache与lighttpd的获取url的方式不一样
     $url = parse_url($_SERVER['SCRIPT_URL'] ? $_SERVER['SCRIPT_URL'] : $_SERVER['REQUEST_URI']);
     //潜规则1.lighttpd会把查询参数带上,所以需要去掉2.注意这里的是.html也能访问,因为历史原因使用.html统计
     $url = preg_replace('/\\.html$/', "", $url["path"]);
     $ip = $_SERVER['SERVER_ADDR'] ? $_SERVER['SERVER_ADDR'] : "0.0.0.0";
     //为controller设置属性isTestEnv,以便别是否是测试环境
     $isTestEnv = true;
     //通过UA匹配iphone和android手机适配移动版或mobile参数等于true,当pc参数为true时均进入pc版
     //注意:暂时无法区分android pad
     $isMobile = $_GET['pc'] != true && ($_GET['mobile'] == true || preg_match('/iphone|android/i', $_SERVER['HTTP_USER_AGENT']));
     //手机访问域名还是浏览器访问,缺省是web类型
     $hostType = $isMobile ? "m" : "web";
     $pageFound = false;
     //手机版的前缀,默认是m
     $mobileHostPrefix = "m";
     $host = $_SERVER['HTTP_HOST'];
     //ip转换为host
     $pathseg = explode('/', trim($url, '/'));
     $dataDir = "";
     //过滤空串
     $pathseg = array_filter($pathseg);
     $count = count($pathseg);
     //检测ui目录下面是否有对应国家的ui根目录(先url,后host)
     //只检测host,else(url)在迁移到www.hao123.com的时候或者测试环境中使用
     if (($dir = explode('.', $host)) && !$isTestEnv) {
         //潜规则:线上的test域名test.tw.hao123.com实际上是tw.hao123.com
         if ($dir[0] === "test") {
             $dir = array_slice($dir, 1);
         }
         //手机类型的域名
         if ($dir[0] === $mobileHostPrefix) {
             $isMobile = true;
             $hostType = $dir[0];
             $pageRoot = $dataDir = $hostType . "/" . $dir[1] . "/";
             $country = $dir[1];
             //有ui的根目录的情况
             $pageFound = is_dir($uiPath . $pageRoot);
             //web
         } else {
             $pageRoot = $dataDir = $hostType . "/" . $dir[0] . "/";
             $country = $dir[0];
             $pageFound = is_dir($uiPath . $pageRoot);
         }
         $dataRoot = $dataDir;
         //为了方便迁移到www.hao123.com,并且方便在测试环境中才使用url映射host,目前暂时只支持测试环境
     } else {
         if (!empty($pathseg[0])) {
             //手机类型的域名
             if ($pathseg[0] === $mobileHostPrefix) {
                 $isMobile = true;
                 $hostType = $pathseg[0];
                 if (!empty($pathseg[1])) {
                     $country = $pathseg[1];
                     $pageRoot = $dataDir = $pathseg[0] . "/" . $pathseg[1] . "/";
                     $pageFound = is_dir($uiPath . $pageRoot);
                     $pathseg = array_slice($pathseg, 2);
                     $count = count($pathseg);
                 }
                 //web
             } else {
                 $reffer = $_SERVER['HTTP_REFERER'];
                 if (strlen($pathseg[0]) > 2) {
                     $reffer = parse_url($reffer);
                     $reffer_path = explode("/", $reffer['path']);
                     $pathseg[0] = $reffer_path[1];
                 }
                 $pageRoot = $dataDir = $hostType . "/" . $pathseg[0] . "/";
                 $country = $pathseg[0];
                 //$dataDir = $hostType."/".$dataDir;
                 $pathseg = array_slice($pathseg, 1);
                 $count = count($pathseg);
                 $pageFound = is_dir($uiPath . $pageRoot);
             }
             $dataRoot = $dataDir;
         }
     }
     $dataDir = rtrim($dataDir . implode("/", $pathseg), "/") . "/";
     //如果是首页,放到目录/index中
     $dataDir = $count > 0 ? $dataDir : $dataDir . "index/";
     //为controller设置属性isTestEnv,以便别是否是测试环境
     //记录对应的data.json所在的Template路径,默认与ui对应
     self::$dataDir = rtrim($dataDir, "/") . "/";
     self::$dataPrivate = "";
     //测试环境使用url,线上环境使用host
     self::$country = $country;
     self::$host = $host;
     self::$dataRoot = rtrim($dataRoot, "/") . "/";
     self::getCms();
     return self::$cmsData;
 }