123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513 |
- <?php
-
- namespace app\home\controller;
-
- use core\basic\Controller;
- use app\home\model\ParserModel;
- use core\basic\Config;
- use core\basic\Url;
-
- class IndexController extends Controller
- {
-
- protected $parser;
-
- protected $model;
-
- protected $htmldir;
-
- public function __construct()
- {
- $this->parser = new ParserController();
- $this->model = new ParserModel();
- $this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
-
-
-
- }
-
-
- public function _empty()
- {
-
- $url_rule_type = $this->config('url_rule_type') ?: 3;
-
- if (PATH) {
- if ($url_rule_type == 2 && stripos(URL, $_SERVER['SCRIPT_NAME']) !== false) {
-
- _301();
- }
- $path = PATH;
- } elseif ($url_rule_type == 3 && isset($_SERVER["QUERY_STRING"]) && $qs = $_SERVER["QUERY_STRING"]) {
- parse_str($qs, $output);
- unset($output['page']);
- if ($output && ! current($output)) {
- $path = key($output);
- } elseif (get('tag')) {
- $tag = new TagController();
- $tag->index();
- } elseif (get('keyword')) {
- $search = new SearchController();
- $search->index();
- }
- }
-
-
- $url_rule_suffix = substr($this->config('url_rule_suffix'), 1);
-
- $suffix = false;
- $slash = false;
- if (preg_match('/(.*)(_|\.)' . $url_rule_suffix . '$/', $path, $matchs)) {
- $path = $matchs[1];
- $suffix = true;
- } elseif (preg_match('/^[\w\-\/]+\/$/', $path)) {
- $slash = true;
- $path = trim($path, '/');
- }
-
-
-
-
-
- if((int)$path > 0){
- $suffix = true;
- }
-
- $path = escape_string($path);
- $path_arr = $path ? explode('/', $path) : array();
-
-
- if (isset($path_arr) && count($path_arr) > 0 && ( in_array('tag',$path_arr) || preg_match('/^[\w\-\/]+$/', $path)) ) {
-
-
- switch (strtolower($path_arr[0])) {
- case 'search':
- case 'keyword':
- $search = new SearchController();
- $search->index();
- break;
- case 'message':
- $msg = new MessageController();
- $msg->index();
- break;
- case 'form':
- $_GET['fcode'] = $path_arr[1];
- $form = new FormController();
- $form->index();
- break;
- case 'sitemap':
- case 'sitemap_xml':
- $sitemap = new SitemapController();
- $sitemap->index();
- break;
- case 'sitemap_txt':
- $sitemap = new SitemapController();
- $sitemap->linkTxt();
- break;
- case 'tag':
- $tag = new TagController();
- $tag->index();
- break;
- case 'member':
- $member = new MemberController();
- $member->{$path_arr[1]}();
- break;
- case 'comment':
- $comment = new CommentController();
- $comment->{$path_arr[1]}();
- break;
- case 'spider':
- $spider = new SpiderController();
- $spider->index();
- break;
- default:
-
- $url_break_char = $this->config('url_break_char') ?: '_';
- $url_rule_content_path = $this->config('url_rule_content_path') ? true : false;
- $err = '';
- $iscontent = false;
-
-
- if (! $suffix && ! ! $sort = $this->model->getSort($path)) {
-
- } elseif (preg_match('/^([a-zA-Z0-9\-\/]+)' . $url_break_char . '([0-9]+)$/i', $path, $matchs) && ! ! $sort = $this->model->getSort($matchs[1])) {
-
- define('CMS_PAGE_CUSTOM', true);
- $_GET['page'] = $matchs[2];
- } else {
-
- if ($url_rule_content_path && ! ! $data = $this->model->getContent($path)) {
-
- $iscontent = true;
- } elseif (! $url_rule_content_path) {
-
-
- $part1 = dirname($path);
- $part2 = basename($path);
- while ($part1 != '.') {
- if ((! ! $sort = $this->model->getSort($part1)) && ! ! $data = $this->model->getContent($part2)) {
-
- $iscontent = true;
- $scode = $sort->scode;
- break;
- } elseif (preg_match('/^([a-zA-Z0-9\-\/]+)' . $url_break_char . '([0-9]+)$/i', $part1, $matchs) && ! ! $model = $this->model->checkModelUrlname($matchs[1])) {
-
- $data = $this->model->getContent($part2);
- $iscontent = true;
- $scode = $matchs[2];
-
- if (! ! $data->urlname && $matchs[1] != $data->urlname) {
- $err = true;
- }
- break;
- } else {
- $part2 = basename($part1) . '/' . $part2;
- $part1 = dirname($part1);
- }
- }
-
-
- if ($scode != $data->scode) {
- $err = true;
- }
-
-
- if (! ! $data->filename && $part2 != $data->filename) {
- $err = true;
- }
- }
-
-
- if (! $iscontent) {
-
- preg_match('/^([a-zA-Z0-9\-\/]+)(' . $url_break_char . '([0-9]+))?' . $url_break_char . '([0-9]+)$/i', $path, $matchs);
- if ($matchs[2] && $model = $this->model->checkModelUrlname($matchs[1])) {
-
- define('CMS_PAGE_CUSTOM', false);
- $sort = $this->model->getSort($matchs[3]);
- $_GET['page'] = $matchs[4];
- } elseif (! ! $model = $this->model->checkModelUrlname($matchs[1])) {
-
- $sort = $this->model->getSort($matchs[4]);
- }
-
-
- if ($sort->filename != '') {
- $err = true;
- }
-
-
- if (! ! $sort->urlname && $matchs[1] != $sort->urlname) {
- $err = true;
- }
- }
- }
-
- if ($iscontent) {
-
- define('CMS_PAGE', false);
-
- if (! ! $data && $suffix && ! $err) {
- $this->getContentPage($data);
- } else {
-
-
- _301();
- }
- } else {
- define('CMS_PAGE', true);
- if (! ! $sort && ! $suffix && ! $err) {
- if ($sort->type == 1) {
- $this->getAboutPage($sort);
- } else {
- $this->getListPage($sort);
- }
- } else {
-
- _301();
- }
- }
- }
- } else {
-
-
- if(SITE_DIR == ''){
-
- $this->urlJump($url_rule_type,false);
- } else {
-
- $this->urlJump($url_rule_type,true);
- }
- }
-
-
- }
-
-
- private function getIndexPage()
- {
-
- $cur_city = cookie('city');
-
-
-
-
-
- $domain_url = get_http_url();
- $ap = explode('.',$domain_url);
- if($ap[1] == 'cn' || $ap[1] == 'com'){
- $aps = $ap[0];
- $aps = str_replace('https://', '', $aps);
- $aps = str_replace('http://', '', $aps);
- }else{
- $aps = $ap[1];
- }
-
-
- if($cur_city == $aps){
-
- $content = parent::parser($this->htmldir . 'city.html');
- }else{
-
- $content = parent::parser($this->htmldir . 'index.html');
- }
-
- $content = $this->parser->parserBefore($content);
-
- if( !! $cur_city ){
- $citys = Config::get('citys');
- $city = $citys[$cur_city];
- $content = str_replace('{pboot:pagetitle}', $city['seo_title']?:($this->config('index_title') ?: '{pboot:sitetitle}-{pboot:sitesubtitle}'), $content);
- $content = str_replace('{pboot:pagekeywords}', $city['seo_keywords']?:'{pboot:sitekeywords}', $content);
- $content = str_replace('{pboot:pagedescription}', $city['seo_description']?:'{pboot:sitedescription}', $content);
- }else{
- $content = str_replace('{pboot:pagetitle}', $this->config('index_title') ?: '{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
- }
-
-
- $content = $this->parser->parserPositionLabel($content, - 1, '首页', SITE_INDEX_DIR . '/');
- $content = $this->parser->parserSpecialPageSortLabel($content, 0, '', SITE_INDEX_DIR . '/');
- $content = $this->parser->parserAfter($content);
- $this->cache($content, true);
- }
-
-
- private function getListPage($sort)
- {
-
- if ($sort->acode != get_lg() && Config::get('lgautosw') !== '0') {
- cookie('lg', $sort->acode);
- }
- if ($sort->listtpl) {
- $this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote);
- $content = parent::parser($this->htmldir . $sort->listtpl);
- $content = $this->parser->parserBefore($content);
- $pagetitle = $sort->title ? "{sort:title}" : "{sort:name}";
- $content = str_replace('{pboot:pagetitle}', $this->config('list_title') ?: ($pagetitle . '-{pboot:sitetitle}-{pboot:sitesubtitle}'), $content);
- $content = str_replace('{pboot:pagekeywords}', '{sort:keywords}', $content);
- $content = str_replace('{pboot:pagedescription}', '{sort:description}', $content);
- $content = $this->parser->parserPositionLabel($content, $sort->scode);
- $content = $this->parser->parserSortLabel($content, $sort);
- $content = $this->parser->parserListLabel($content, $sort->scode);
- $content = $this->parser->parserAfter($content);
- } else {
- error('请到后台设置分类栏目列表页模板!');
- }
- $this->cache($content, true);
- }
-
-
- private function getContentPage($data)
- {
-
-
- if ($data->acode != get_lg() && Config::get('lgautosw') !== '0') {
- cookie('lg', $data->acode);
- }
-
-
- if (! ! $sort = $this->model->getSort($data->scode)) {
- if ($sort->contenttpl) {
- $this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote);
- $this->checkPageLevel($data->gcode, $data->gtype, $data->gnote);
- $content = parent::parser($this->htmldir . $sort->contenttpl);
- $content = $this->parser->parserBefore($content);
- $content = str_replace('{pboot:pagetitle}', $this->config('content_title') ?: '{content:title}-{sort:name}-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
- $content = str_replace('{pboot:pagekeywords}', '{content:keywords}', $content);
- $content = str_replace('{pboot:pagedescription}', '{content:description}', $content);
- $content = $this->parser->parserPositionLabel($content, $sort->scode);
- $content = $this->parser->parserSortLabel($content, $sort);
- $content = $this->parser->parserCurrentContentLabel($content, $sort, $data);
- $content = $this->parser->parserCommentLabel($content);
- $content = $this->parser->parserAfter($content);
- } else {
- error('请到后台设置分类栏目内容页模板!');
- }
- } else {
-
- _301();
- }
- $this->cache($content, true);
- }
-
-
- private function getAboutPage($sort)
- {
-
- if ($sort->acode != get_lg() && Config::get('lgautosw') !== '0') {
- cookie('lg', $sort->acode);
- }
-
-
- if (! $data = $this->model->getAbout($sort->scode)) {
-
- _301();
- }
-
- if ($sort->contenttpl) {
- $this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote);
- $content = parent::parser($this->htmldir . $sort->contenttpl);
- $content = $this->parser->parserBefore($content);
- $pagetitle = $sort->title ? "{sort:title}" : "{content:title}";
- $content = str_replace('{pboot:pagetitle}', $this->config('about_title') ?: ($pagetitle . '-{pboot:sitetitle}-{pboot:sitesubtitle}'), $content);
- $content = str_replace('{pboot:pagekeywords}', '{content:keywords}', $content);
- $content = str_replace('{pboot:pagedescription}', '{content:description}', $content);
- $content = $this->parser->parserPositionLabel($content, $sort->scode);
- $content = $this->parser->parserSortLabel($content, $sort);
- $content = $this->parser->parserCurrentContentLabel($content, $sort, $data);
- $content = $this->parser->parserCommentLabel($content);
- $content = $this->parser->parserAfter($content);
- } else {
- error('请到后台设置分类栏目内容页模板!');
- }
-
- $this->cache($content, true);
- }
-
-
- private function checkPageLevel($gcode, $gtype, $gnote)
- {
- if ($gcode) {
- $deny = false;
- $gtype = $gtype ?: 4;
- switch ($gtype) {
- case 1:
- if ($gcode <= session('pboot_gcode')) {
- $deny = true;
- }
- break;
- case 2:
- if ($gcode < session('pboot_gcode')) {
- $deny = true;
- }
- break;
- case 3:
- if ($gcode != session('pboot_gcode')) {
- $deny = true;
- }
- break;
- case 4:
- if ($gcode > session('pboot_gcode')) {
- $deny = true;
- }
- break;
- case 5:
- if ($gcode >= session('pboot_gcode')) {
- $deny = true;
- }
- break;
- }
- if ($deny) {
- $gnote = $gnote ?: '您的权限不足,无法浏览本页面!';
- if (session('pboot_uid')) {
- error($gnote);
- } else {
- if ($this->config('login_no_wait')) {
- location(Url::home('member/login', null, "backurl=" . urlencode(get_current_url())));
- } else {
- error($gnote, Url::home('member/login', null, "backurl=" . urlencode(get_current_url())));
- }
- }
- }
- }
- }
-
-
-
-
- private function urlJump($type, $isSecSiteDir){
- $http = is_https() ? 'https://' : 'http://';
- $matches1 = '';
- switch ($type){
-
- case 1:
- $preg1 = '';
- if($isSecSiteDir === true){
- if($_SERVER['REQUEST_URI'] == SITE_DIR . '/index.php'){
- $preg1 = '/^\/.*?\/index.php/';
- } elseif($_SERVER['REQUEST_URI'] == '/index.php'){
- $preg1 = '/^\/index.php/';
- }
- } else {
- $preg1 = '/^\/index.php/';
- }
- preg_match($preg1,$_SERVER['REQUEST_URI'],$matches1);
- break;
-
- case 2:
- $preg2 = '';
- if($isSecSiteDir === true){
- if($_SERVER['REQUEST_URI'] == SITE_DIR . '/'){
- $preg2 = '/^\/.*/';
- } elseif($_SERVER['REQUEST_URI'] == '/'){
- $preg2 = '/^\/$/';
- }
- } else {
- $preg2 = '/^\/.*/';
- }
- preg_match($preg2,$_SERVER['REQUEST_URI'],$matches1);
- break;
-
- case 3:
- $preg3 = '';
- if($isSecSiteDir === true){
- if(strpos($_SERVER['REQUEST_URI'], SITE_DIR) === 0){
- $preg3 = '/(^\/.*?\/index.php)|(^\/.*)/';
- } elseif(strpos($_SERVER['REQUEST_URI'], '/') === 0){
- $preg3 = '/(^\/index.php)|(^\/)/';
- }
- } else {
- $preg3 = '/(^\/index.php)|(^\/)/';
- }
- preg_match($preg3,$_SERVER['REQUEST_URI'],$matches1);
- break;
- }
- if($matches1[0]){
- if($_SERVER['REQUEST_URI'] == $matches1[0]){
- $this->getIndexPage();
- } else {
-
- if($this->config('url_index_404') == 1){
-
- _301();
- }
- header("Location: " . $http . $_SERVER['HTTP_HOST'] . $matches1[0], true, 301);
- }
- } else {
- if( file_exists(ROOT_PATH . '/data/city.lock') ){
- $this->getIndexPage();
- }else{
-
- _301();
- }
- }
- }
- }
|