123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <?php
-
- namespace app\common;
-
- use core\basic\Controller;
- use core\basic\Config;
- use app\home\model\ParserModel;
-
- class HomeController extends Controller
- {
-
- public function __construct()
- {
- $this->model = new ParserModel();
-
-
- cache_config();
-
-
- define("CMSNAME", $this->config("cmsname") ?: 'PbootCMS');
-
-
- if (! ! $close_site = Config::get('close_site')) {
- $close_site_note = Config::get('close_site_note');
- error($close_site_note ?: '本站维护中,请稍后再访问,带来不便,敬请谅解!');
- }
-
-
- if (! is_https() && ! ! $tohttps = Config::get('to_https')) {
-
- header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], true,301);
- }
-
-
- if (! ($this->config('wap_domain') && is_mobile()) && (! ! $main_domain = Config::get('main_domain')) && (! ! $to_main_domain = Config::get('to_main_domain'))) {
- if (! preg_match('{^' . $main_domain . '$}i', get_http_host(true))) {
- if (is_https()) {
- header("Location: https://" . $main_domain . ':' . $_SERVER['SERVER_PORT'], true, 301);
- } else {
- header("Location: http://" . $main_domain . ':' . $_SERVER['SERVER_PORT'], true, 301);
- }
- exit();
- }
- }
-
-
- $user_ip = get_user_ip();
- if (filter_var($user_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
-
- $ip_deny = Config::get('ip_deny', true);
- foreach ($ip_deny as $key => $value) {
- if (network_match($user_ip, $value)) {
- error('本站启用了黑名单功能,您的IP(' . $user_ip . ')不允许访问!');
- }
- }
-
- $ip_allow = Config::get('ip_allow', true);
- foreach ($ip_allow as $key => $value) {
- if (network_match($user_ip, $value)) {
- $allow = true;
- }
- }
-
-
- if ($ip_allow && ! isset($allow)) {
- error('本站启用了白名单功能,您的IP(' . $user_ip . ')不在允许范围!');
- }
- }
-
-
- $lgs = Config::get('lgs');
- if (count($lgs) > 1) {
- $domain = get_http_host();
- foreach ($lgs as $value) {
- if ($value['domain'] == $domain) {
- cookie('lg', $value['acode']);
- break;
- }
- }
- }
-
-
- $citys = Config::get('citys');
- $domain = get_http_host();
- $wildcard = $this->config('wildcard');
-
- if( $wildcard ){
- $main_domain = $this->config('main_domain');
- if( $main_domain=='' ){
- error('请到后台全局配置->参数配置->基本配置中填入「网站主域名」');
- }
- $domain_first = explode('.', $domain)[0];
- define('PATH', P);
- define('ISURL', TRUE);
- if( $domain == $main_domain ){
-
- cookie('city',$this->config('firstcity'));
- }else{
- cookie('city',$domain_first);
-
- $apo = explode('.', $domain);
- if(!empty($apo[2])){
-
- $isHf = $this->model->getCityDomain($domain_first);
- if((int)$isHf > 0){
- }else{
-
-
- $target_url = "https://www.".$apo[1].'.'.$apo[2];
-
- header("HTTP/1.1 301 Moved Permanently");
- header("Location: $target_url");
- exit;
- }
- }
- }
-
-
-
-
-
- $cityid = $this->model->getCityId($domain_first);
- if(empty($cityid)){
- $cityid = 0;
- $temp_cityId = 381;
- }else{
- $temp_cityId = $cityid;
- }
-
- cookie('city_id',$cityid);
-
- $this->assign('cityId',$cityid);
- $this->assign('temp_cityId',$temp_cityId);
-
-
-
-
-
-
- $citylogo = $this->model->getCityLogo($domain_first);
- if(empty($citylogo)){
- $citylogo = $this->model->getSiteLogo();
- }
- $this->assign('citylogo',$citylogo);
-
- }else{
- $cur_city = array_filter($citys, function($t) use ($domain) { return $t['isurl'] == $domain; });
- if( !empty($cur_city) ){
- define('PATH', P);
- define('ISURL', TRUE);
- cookie('city',key($cur_city));
- }else{
- if( !empty(P) ){
-
- if( strpos(P,'/')===false && strpos(P,'.html')!==false ){
- $tmp = explode('.', P);
- if ( array_key_exists($tmp[0],$citys) ){
- define('PATH', '');
- cookie('city',$tmp[0]);
- }else{
- define('PATH', P);
-
- cookie('city',$this->config('firstcity'));
- }
- }elseif( strpos(P,'/')!==false ){
- $tmp = explode('/', P);
- if ( array_key_exists($tmp[0],$citys) ){
- $tmp_p = substr(P,strpos(P,'/')+1);
- define('PATH', $tmp_p);
- cookie('city',$tmp[0]);
- }else{
- define('PATH', P);
-
- cookie('city',$this->config('firstcity'));
- }
- }
- }else{
- define('PATH', P);
-
- cookie('city',$this->config('firstcity'));
- }
- }
- }
-
-
-
-
- $black_lg = ['pboot','system'];
- if (!isset($_COOKIE['lg']) || in_array($_COOKIE['lg'],$black_lg)) {
- cookie('lg', get_default_lg());
- }
-
-
- if ($this->config('open_wap')) {
- if ($this->config('wap_domain') && $this->config('wap_domain') == get_http_host()) {
- $this->setTheme(get_theme() . '/wap');
- } elseif (is_mobile() && $this->config('wap_domain') && $this->config('wap_domain') != get_http_host()) {
- if (is_https()) {
- $pre = 'https://';
- } else {
- $pre = 'http://';
- }
- header('Location:' . $pre . $this->config('wap_domain') . URL, true, 302);
- exit();
- } elseif (is_mobile()) {
- $this->setTheme(get_theme() . '/wap');
- } else {
- $this->setTheme(get_theme());
- }
- } else {
- $this->setTheme(get_theme());
- }
- }
- }
|