diff --git a/application/config/config.php b/application/config/config.php index 144c754e..eb0ef45a 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -727,6 +727,7 @@ $config['cache']['ru']['cache_path'] = 'C:\VHD\Dropbox\wwwcache\chinahighlights. $config['cache']['it']['cache_path'] = 'C:\VHD\Dropbox\wwwcache\viaggio-in-cina.it'; $config['cache']['ch']['cache_path'] = 'D:\wwwcache\chinahighlights.com'; $config['cache']['ah']['cache_path'] = 'D:\wwwcache\asiahighlights.com'; +$config['cache']['gh']['cache_path'] = 'D:\wwwcache\globalhighlights.com'; $config['cache']['chinatravel']['cache_path'] = 'D:\wwwcache\mobile-first\chinatravel.com'; //静态文件更新接口 diff --git a/application/controllers/information.php b/application/controllers/information.php index d75ea6fd..c8185c5b 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -26,7 +26,7 @@ class Information extends CI_Controller $this->load->model('Feedback_model'); $this->load->library('Amplib'); //加载AMP处理类 $this->load->library('html_optimize_lib'); //加载HTML优化类 - + } public function index() @@ -410,17 +410,24 @@ class Information extends CI_Controller } else if (strcasecmp($site_code, "ch") == 0 && !empty($auto_update_cache)) { //读取模板生成PC和移动优先文件 $information_new = $this->Information_model->Detail($this->input->post('is_id')); - $this->make_www_cache('mobile', $information_new); - $this->make_www_cache('pc', $information_new); + //$this->benchmark->mark('000'); + $recommand_information = $this->recommand_information($information); + //$this->benchmark->mark('111'); + $this->make_www_cache('mobile', $information_new, $recommand_information); + $this->make_www_cache('pc', $information_new, $recommand_information); + //echo ' |000~111: '.$this->benchmark->elapsed_time('000', '111'); } else if (strcasecmp($site_code, "ah") == 0 && !empty($auto_update_cache)) { //读取模板生成PC和移动优先文件 + $recommand_information = $this->recommand_information($information); $information_new = $this->Information_model->Detail($this->input->post('is_id')); - $this->make_www_cache_ah('mobile', $information_new); - $this->make_www_cache_ah('pc', $information_new); + $this->make_www_cache_ah('mobile', $information_new, $recommand_information); + $this->make_www_cache_ah('pc', $information_new, $recommand_information); } else if (strcasecmp($site_code, "gh") == 0 && !empty($auto_update_cache)) { + $recommand_information = $this->recommand_information($information); $information_new = $this->Information_model->Detail($this->input->post('is_id')); - $this->make_www_cache_gh($information_new); - }else if (strcasecmp($site_code, "chinatravel") == 0 && !empty($auto_update_cache)) { + $this->make_www_cache_gh('mobile', $information_new, $recommand_information); + $this->make_www_cache_gh('pc', $information_new, $recommand_information); + } else if (strcasecmp($site_code, "chinatravel") == 0 && !empty($auto_update_cache)) { //chinatravel读取模板生成PC和移动优先文件 $information_new = $this->Information_model->Detail($this->input->post('is_id')); $this->make_www_cache_ct($information_new); @@ -504,16 +511,17 @@ class Information extends CI_Controller return false; } if ($this->html_file_helper('find', $information->ic_url)) { + $recommand_information = $this->recommand_information($information); //用于批量更新,CH和chinatravel分开 ,20210317 zp if ($this->config->item('site_code') == 'ch') { - $this->make_www_cache('pc', $information); - $this->make_www_cache('mobile', $information); + $this->make_www_cache('pc', $information,$recommand_information); + $this->make_www_cache('mobile', $information,$recommand_information); } else if ($this->config->item('site_code') == 'ah') { - $this->make_www_cache_ah('pc', $information); - $this->make_www_cache_ah('mobile', $information); + $this->make_www_cache_ah('pc', $information,$recommand_information); + $this->make_www_cache_ah('mobile', $information,$recommand_information); } else if ($this->config->item('site_code') == 'chinatravel') { $this->make_www_cache_ct($information); - // $this->make_www_cache_ct('mobile', $information); + // $this->make_www_cache_ct('mobile', $information); } echo json_encode(array('name' => 'yes', 'data' => '更新成功!')); @@ -565,7 +573,7 @@ class Information extends CI_Controller } //生成静态文件 $device='mobile' or 'pc' - function make_www_cache($device, $information) + function make_www_cache($device, $information, $recommand_information) { $data = array(); switch ($device) { @@ -591,7 +599,6 @@ class Information extends CI_Controller break; default: } - $breadcrumb_data = $this->Information_model->get_path_exclude_self($information->is_id, $information->is_path); $breadcrumb_structured_data_content = $this->load->view( @@ -603,7 +610,6 @@ class Information extends CI_Controller $breadcrumb_structured_data_content, $template); - //替换模板中的标签 $template = str_replace('', $information->ic_seo_title, $template); $template = str_replace('', $information->ic_seo_description, $template); @@ -630,6 +636,7 @@ class Information extends CI_Controller } } + //火车票搜索框添加 -- zp if ($information->is_parent_id == "278008234") { //本地测试的火车父类ID为:278035939 。网前为:278008234 @@ -637,7 +644,6 @@ class Information extends CI_Controller $template = str_replace('', $template_TrainSearch, $template); } - //非产品页面 $meta_product_code = get_meta($information->ic_id, 'meta_product_code'); if (empty($meta_product_code)) { @@ -672,30 +678,28 @@ class Information extends CI_Controller $information->ic_content = str_replace('', $breadcrumb_content, $information->ic_content); } - - //---day tours--- 20210922 zp //本地 278035929 //网前 278008224 if ($information->is_parent_id == "278008224") { - if (!empty($meta_product_code)){ + if (!empty($meta_product_code)) { //准备需要的数据 $dataTrippest = []; - $dataTrippest["ic_title"] = $information->ic_title; + $dataTrippest["ic_title"] = $information->ic_title; //附加选项 $t_Type = get_meta($information->ic_id, 'meta_trippest_type'); - if (isset($t_Type)){ + if (isset($t_Type)) { $dataTrippest["t_Type"] = $t_Type; - }else{ + } else { $dataTrippest["t_Type"] = "general"; } $t_package = get_meta($information->ic_id, 'meta_trippest_package'); - $dataTrippest["t_package"] = explode("|",$t_package); + $dataTrippest["t_package"] = explode("|", $t_package); $t_excludedate = get_meta($information->ic_id, 'meta_trippest_excludedate'); $dataTrippest["t_excludedate"] = $t_excludedate; - $t_includedate = get_meta($information->ic_id, 'meta_trippest_includedate'); + $t_includedate = get_meta($information->ic_id, 'meta_trippest_includedate'); $dataTrippest["t_includedate"] = $t_includedate; $t_excludemonth = get_meta($information->ic_id, 'meta_trippest_excludemonth'); $dataTrippest["t_excludemonth"] = $t_excludemonth; @@ -710,7 +714,7 @@ class Information extends CI_Controller // 132004 桂林目的地 // 132005 成都目的地 $PAG_SourceType = $dataTrippest['PagDetail']->PAG_SourceType; - switch ($PAG_SourceType){ + switch ($PAG_SourceType) { case '132001': $dataTrippest['PAG_SourceType'] = "beijing"; break; @@ -722,41 +726,40 @@ class Information extends CI_Controller break; case '132004': $dataTrippest['PAG_SourceType'] = "guilin"; - break; + break; case '132005': $dataTrippest['PAG_SourceType'] = "chengdu"; - break; + break; case '132006': - $dataTrippest['PAG_SourceType'] = "zhangjiajie"; - break; + $dataTrippest['PAG_SourceType'] = "zhangjiajie"; + break; case '132007': - $dataTrippest['PAG_SourceType'] = "huangshan"; - break; + $dataTrippest['PAG_SourceType'] = "huangshan"; + break; default: $dataTrippest['PAG_SourceType'] = ""; break; } - + //每周发团 $PAG_Scheme = $dataTrippest['PagDetail']->PAG_Scheme; $dataTrippest['PAG_Scheme'] = $PAG_Scheme; //接送 - if ($dataTrippest["t_Type"]=="transfer" || 1==1) - { + if ($dataTrippest["t_Type"] == "transfer" || 1 == 1) { $PagList = $this->trippest_model->GetTransfer($dataTrippest['PagDetail']->PAG_SN); $dataTrippest["PagList"] = $PagList; } - //价格 + //价格 // $price = $this->trippest_model->get_price("BJALC-1",2); - $price = $this->trippest_model->get_price($dataTrippest['PagDetail']->PAG_Code,2); + $price = $this->trippest_model->get_price($dataTrippest['PagDetail']->PAG_Code, 2); $showPrice = ""; - if (!empty($price)){ + if (!empty($price)) { $PKP_AdultNetPrice = $price->PKP_AdultNetPrice; $PKP_AdultSpecialPrice = $price->PKP_AdultSpecialPrice; - if ($PKP_AdultSpecialPrice>0){ + if ($PKP_AdultSpecialPrice > 0) { $showPrice = $PKP_AdultSpecialPrice; - }else{ + } else { $showPrice = $PKP_AdultNetPrice; } } @@ -774,9 +777,8 @@ class Information extends CI_Controller //---day tours end ---- - //信息推荐 - $template_recommand = $this->recommand_information($information); + $template_recommand = $recommand_information; //$this->recommand_information($information); 从外面传进来,pc和移动只需要查一次,减少数据库负担 $template = str_replace('', $this->load->view($template_path . '-next', array('recommands' => $template_recommand), TRUE), $template); // //广告,改叫tips,防止被插件屏蔽 if (!empty($template_recommand['Tips Right TOP'])) { @@ -785,8 +787,6 @@ class Information extends CI_Controller if (!empty($template_recommand['Tips Right'])) { $template = str_replace('', "
" . $template_recommand['Tips Right']->it_content . "
", $template); } - - //文中的信息推荐 if (strpos($information->ic_content, '') !== false) { $information->ic_content = str_replace('', $this->load->view($template_path . '-recommends-article', array('recommands' => $template_recommand), TRUE), $information->ic_content); @@ -796,6 +796,17 @@ class Information extends CI_Controller $information->ic_content = str_replace('', $this->load->view($template_path . '-recommends-tour', array('recommands' => $template_recommand), TRUE), $information->ic_content); } + //替换内容中广告 + $temp_array = array(); + preg_match_all('^^', $information->ic_content, $temp_array); + if (!empty($temp_array[1])) { + foreach ($temp_array[1] as $key => $item) { + $tips_detail = $this->recommends_and_tips_model->tips_detail($item); + if ($tips_detail) { + $information->ic_content = str_replace($temp_array[0][$key], $tips_detail->it_content, $information->ic_content); + } + } + } //顶部全屏大图 if ($device == 'mobile') { //移动端读取移动大图 @@ -806,7 +817,7 @@ class Information extends CI_Controller // 火车票首页搜索框 --zp $template_TrainSearch = ""; - if ($information->ic_url =="/china-trains/hometest.htm" || $information->ic_url=="/china-trains/"){ + if ($information->ic_url == "/china-trains/hometest.htm" || $information->ic_url == "/china-trains/") { $template_TrainSearch = $this->load->view($template_path . '-train-index', null, TRUE); } @@ -816,7 +827,7 @@ class Information extends CI_Controller if (!empty($meta_addon_picture_url)) { $template = str_replace('', '
' . $information->ic_title . '
', $template); } else { - $template = str_replace('', '
' . $information->ic_title . ''.$template_TrainSearch.'
', $template); + $template = str_replace('', '
' . $information->ic_title . '' . $template_TrainSearch . '
', $template); } } //顶部视频 @@ -825,15 +836,21 @@ class Information extends CI_Controller if (!empty($meta_news_video) && !empty($meta_video_picture)) { $template = str_replace('', '
', $template); } - //主样式表,内联模式 - $main_css_string = compress_css(GET_HTTP('https://proxy-data.chinahighlights.com/css/mobile-first.css')); + + if (is_file('D:/wwwroot/origin-data.chinahighlights.com/css/mobile-first.css')) {//主样式表,内联模式,优先读取本地,没有在从网络读取,为了加速 + $main_css_string = compress_css(file_get_contents('D:/wwwroot/origin-data.chinahighlights.com/css/mobile-first.css')); + } else { + $main_css_string = compress_css(GET_HTTP('https://proxy-data.chinahighlights.com/css/mobile-first.css')); + } $template = str_replace('', '', $template); //额外样式 $meta_addon_css = get_meta($information->ic_id, 'meta_addon_css'); if (!empty($meta_addon_css)) { - //引用方式 $template = str_replace('', '', $template); - //内联方式 - $meta_addon_css_string = compress_css(GET_HTTP($meta_addon_css)); + if ($meta_addon_css == 'https://proxy-data.chinahighlights.com/css/tour-detail-former.css' && is_file('D:/wwwroot/origin-data.chinahighlights.com/css/tour-detail-former.css')) { + $meta_addon_css_string = compress_css(file_get_contents('D:/wwwroot/origin-data.chinahighlights.com/css/tour-detail-former.css')); + } else { + $meta_addon_css_string = compress_css(GET_HTTP($meta_addon_css)); + } $template = str_replace('', '', $template); } //额外js @@ -854,17 +871,21 @@ class Information extends CI_Controller $template = str_replace('', '', $template); //} //社媒分享图片 - $full_ic_photo=''; + $full_ic_photo = ''; if (!empty($information->ic_photo)) { $full_ic_photo = $this->config->item('site_image_url') . $information->ic_photo; - }else{ - $full_ic_photo = get_meta($information->ic_id, 'meta_addon_picture_mobile'); - } - if(!empty($full_ic_photo)){ + } else { + $full_ic_photo = get_meta($information->ic_id, 'meta_addon_picture_mobile'); + } + if (!empty($full_ic_photo)) { $template = str_replace('', '', $template); } //设置图片尺寸 - $template = $this->html_optimize_lib->set_image_size($template); + if (is_dir('D:/wwwroot/origin-images.chinahighlights.com') && is_dir('D:/wwwroot/origin-www.chinahighlights.com')) { + $template = $this->html_optimize_lib->set_image_size_local($template, 'D:/wwwroot/origin-www.chinahighlights.com', 'D:/wwwroot/origin-images.chinahighlights.com'); + } else { + $template = $this->html_optimize_lib->set_image_size($template); + } // /travelguide/chinese-zodiac/monthly-fortune-for-dog.htm $html_path = $this->config->item('cache')[$this->config->item('site_code')]['cache_path'] . $information->ic_url; $html_path = str_replace("\\", "/", $html_path); @@ -877,48 +898,220 @@ class Information extends CI_Controller } - function make_www_cache_gh($information){ - return false; + function make_www_cache_gh($device, $information, $recommand_information) + { $data = array(); - $data['information'] = $information; - //获取移动优先的模板,如果有的话 - $template_path = 'mobile_first/' . $this->config->item('site_code'); - $template_mobile = $this->load->view($template_path, '', TRUE); - $template_pc = $this->load->view($template_path . '-pc', '', TRUE); + switch ($device) { + case 'mobile': + //获取移动优先的模板,如果有的话 + $template_path = 'mobile_first/' . $this->config->item('site_code'); + if (is_file(APPPATH . 'views/' . $template_path . EXT)) { + $template = $this->load->view($template_path, '', TRUE); + $html_path_ext = '-mobile.htm'; + } else { + return false; + } + break; + case 'pc': + //获取PC的模板,如果有的话 + $template_path = 'mobile_first/' . $this->config->item('site_code'); + if (is_file(APPPATH . 'views/' . $template_path . '-pc' . EXT)) { + $template = $this->load->view($template_path . '-pc', '', TRUE); + $html_path_ext = '-pc.htm'; + } else { + return false; + } + break; + default: + } + $breadcrumb_data = $this->Information_model->get_path_exclude_self($information->is_id, $information->is_path); + + $breadcrumb_structured_data_content = $this->load->view( + $template_path . '-structured-data-breadcrumb', + array('breadcrumb_data' => $breadcrumb_data, 'information' => $information), + true); + $template = str_replace( + '', + $breadcrumb_structured_data_content, + $template); //替换模板中的标签 - $template_mobile = str_replace('', $information->ic_seo_title, $template_mobile); - $template_pc = str_replace('', $information->ic_seo_title, $template_pc); - $template_mobile = str_replace('', $information->ic_seo_description, $template_mobile); - $template_pc = str_replace('', $information->ic_seo_description, $template_pc); - $template_mobile = str_replace('', $information->ic_seo_keywords, $template_mobile); - $template_pc = str_replace('', $information->ic_seo_keywords, $template_pc); - $template_mobile = str_replace('', $this->config->item('site_url') . $information->ic_url, $template_mobile); - $template_pc = str_replace('', $this->config->item('site_url') . $information->ic_url, $template_pc); + $template = str_replace('', $information->ic_seo_title, $template); + $template = str_replace('', $information->ic_seo_description, $template); + $template = str_replace('', $information->ic_seo_keywords, $template); + $template = str_replace('', $this->config->item('site_url') . $information->ic_url, $template); + // 动态加载反馈标签 + // HTLM:
+ // 解析结果:, Shanghai + $feedback_array = []; + preg_match_all('^^', $information->ic_content, $feedback_array); + if (!empty($feedback_array)) { + foreach ($feedback_array[0] as $index => $tag_name) { + $city_name = $feedback_array[1][$index]; + $feedback_data = $this->Feedback_model->get_feedback_by_city($city_name); + $feedback_content = $this->load->view( + $template_path . '-feedback', + array('feedback_data' => $feedback_data), + true); + $information->ic_content = str_replace( + $tag_name, + $feedback_content, + $information->ic_content); + } + } - //顶部视频 - $data['meta_news_video'] = get_meta($information->ic_id, 'meta_news_video'); - $data['meta_video_picture'] = get_meta($information->ic_id, 'meta_video_picture'); - if (empty($data['meta_news_video']) && empty($data['meta_video_picture'])) { - //没有顶部视频时候才读取全屏大图 - //顶部全屏大图 - if ($device == 'mobile') { //移动端读取移动大图 - $data['meta_addon_picture'] = get_meta($information->ic_id, 'meta_addon_picture_mobile'); + + //非产品页面 + $meta_product_code = get_meta($information->ic_id, 'meta_product_code'); + if (empty($meta_product_code)) { + + $ads_by_google = !empty(get_meta($information->ic_id, 'meta_google_ad_article')); + //H1模板替换 + $data_H1 = array(); + $data_H1['infocategory'] = $this->Information_model->get_detail_by_path($information->is_path, 1); //信息所属分类,获取信息顶级节点内容 + $author = $this->Operator_model->get_author_nikename($information->ic_author); + $data_H1['author'] = $author; //获取作者信息 + $data_H1['ic_title'] = $information->ic_title; + $data_H1['ic_photo'] = $information->ic_photo; + $data_H1['breadcrumb_data'] = $breadcrumb_data; + $data_H1['ads_by_google'] = $ads_by_google; + $template_H1 = $this->load->view($template_path . '-h1', $data_H1, TRUE); + $template = str_replace('', $template_H1, $template); + +// $addthis_widget = $this->load->view($template_path . '-add-this', false, true); +// $template = str_replace('', $addthis_widget, $template); + +// $article_structured_data_content = $this->load->view( +// $template_path . '-structured-data-article', +// array('information' => $information, 'author' => $author), +// true); +// $template = str_replace('', $article_structured_data_content, $template); + } else { +// $template = str_replace('', '', $template); +// $inquiry_form_template = $this->load->view($template_path . '-inquiry-form', array('meta_product_code' => $meta_product_code), true); +// $information->ic_content = str_replace('', $inquiry_form_template, $information->ic_content); +// +// $breadcrumb_content = $this->load->view($template_path . '-breadcrumb', array('breadcrumb_data' => $breadcrumb_data), true); +// $information->ic_content = str_replace('', $breadcrumb_content, $information->ic_content); + } + + //信息推荐 + $template_recommand = $recommand_information; //$this->recommand_information($information); 从外面传进来,pc和移动只需要查一次,减少数据库负担 + // $template = str_replace('', $this->load->view($template_path . '-next', array('recommands' => $template_recommand), TRUE), $template); +// //广告,改叫tips,防止被插件屏蔽 + if (!empty($template_recommand['Tips Right TOP'])) { + // $template = str_replace('', "
", $template); + } + if (!empty($template_recommand['Tips Right'])) { + // $template = str_replace('', "
" . $template_recommand['Tips Right']->it_content . "
", $template); + } + //文中的信息推荐 + if (strpos($information->ic_content, '') !== false) { + // $information->ic_content = str_replace('', $this->load->view($template_path . '-recommends-article', array('recommands' => $template_recommand), TRUE), $information->ic_content); + } + //文中的线路推荐 + if (strpos($information->ic_content, '') !== false) { + // $information->ic_content = str_replace('', $this->load->view($template_path . '-recommends-tour', array('recommands' => $template_recommand), TRUE), $information->ic_content); + } + + //替换内容中广告 + $temp_array = array(); + preg_match_all('^^', $information->ic_content, $temp_array); + if (!empty($temp_array[1])) { + foreach ($temp_array[1] as $key => $item) { + $tips_detail = $this->recommends_and_tips_model->tips_detail($item); + if ($tips_detail) { + $information->ic_content = str_replace($temp_array[0][$key], $tips_detail->it_content, $information->ic_content); + } + } + } + + //顶部全屏大图 + if ($device == 'mobile') { //移动端读取移动大图 + $meta_addon_picture = get_meta($information->ic_id, 'meta_addon_picture_mobile'); + } else { + $meta_addon_picture = get_meta($information->ic_id, 'meta_addon_picture'); + } + + + $meta_addon_picture_url = get_meta($information->ic_id, 'meta_addon_picture_url'); + if (!empty($meta_addon_picture)) { + if (!empty($meta_addon_picture_url)) { + // $template = str_replace('', '
' . $information->ic_title . '
', $template); } else { - $data['meta_addon_picture'] = get_meta($information->ic_id, 'meta_addon_picture'); + // $template = str_replace('', '
' . $information->ic_title . '' . $template_TrainSearch . '
', $template); } - $data['meta_addon_picture_url'] = get_meta($information->ic_id, 'meta_addon_picture_url'); } + //顶部视频 +// $meta_news_video = get_meta($information->ic_id, 'meta_news_video'); +// $meta_video_picture = get_meta($information->ic_id, 'meta_video_picture'); +// if (!empty($meta_news_video) && !empty($meta_video_picture)) { +// $template = str_replace('', '
', $template); +// } + + if (is_file('D:/wwwroot/origin-www.globalhighlights.com/css/gh-global.css')) {//主样式表,内联模式,优先读取本地,没有在从网络读取,为了加速 + $main_css_string = compress_css(file_get_contents('D:/wwwroot/origin-www.globalhighlights.com/css/gh-global.css')); + } else { + $main_css_string = compress_css(GET_HTTP('https://origin-www.globalhighlights.com/css/gh-global.css')); + } + $template = str_replace('', '', $template); + //额外样式 + $meta_addon_css = get_meta($information->ic_id, 'meta_addon_css'); + if (!empty($meta_addon_css)) { + // if ($meta_addon_css == 'https://proxy-data.chinahighlights.com/css/tour-detail-former.css' && is_file('D:/wwwroot/origin-data.chinahighlights.com/css/tour-detail-former.css')) { + //$meta_addon_css_string = compress_css(file_get_contents('D:/wwwroot/origin-data.chinahighlights.com/css/tour-detail-former.css')); + // } else { + $meta_addon_css_string = compress_css(GET_HTTP($meta_addon_css)); + // } + $template = str_replace('', '', $template); + } + //额外js + $meta_addon_js = get_meta($information->ic_id, 'meta_addon_js'); + if (!empty($meta_addon_js)) { + $template = str_replace('', '', $template); + } + //设置内容图片缓加载 + $lazy_content = $this->html_optimize_lib->set_lazy_loader($information->ic_content, 'https://data.chinahighlights.com/grey.gif'); + $template = str_replace('', $lazy_content, $template); - $data['author'] = $this->Operator_model->get_author_nikename($information->ic_author); //获取作者信息 - $template_H1 = $this->load->view($template_path . '-h1', $data, TRUE); - $template_mobile = str_replace('', $template_H1, $template_mobile); - $template_pc = str_replace('', $template_H1, $template_pc); + //替换内容中各种标签 + //$tag_why_us = $this->load->view($template_path . '-why-us', false, true); + // $template = str_replace('', $tag_why_us, $template); + //Google广告代码 + //if (!empty(get_meta($information->ic_id, 'meta_google_ad_content'))) { + //$template = str_replace('', '', $template); + //} + //社媒分享图片 + $full_ic_photo = ''; + if (!empty($information->ic_photo)) { + $full_ic_photo = $this->config->item('site_image_url') . $information->ic_photo; + } else { + $full_ic_photo = get_meta($information->ic_id, 'meta_addon_picture_mobile'); + } + if (!empty($full_ic_photo)) { + $template = str_replace('', '', $template); + } + //设置图片尺寸 + if (is_dir('D:/wwwroot/origin-images.chinahighlights.com') && is_dir('D:/wwwroot/origin-www.globalhighlights.com')) { + $template = $this->html_optimize_lib->set_image_size_local($template, 'D:/wwwroot/origin-www.globalhighlights.com', 'D:/wwwroot/origin-images.chinahighlights.com'); + } else { + $template = $this->html_optimize_lib->set_image_size($template); + } + // /travelguide/chinese-zodiac/monthly-fortune-for-dog.htm + $html_path = $this->config->item('cache')[$this->config->item('site_code')]['cache_path'] . $information->ic_url; + $html_path = str_replace("\\", "/", $html_path); + if (substr($html_path, -1, 1) == '/') { + $html_path = $html_path . 'index.htm'; + } + $html_path .= $html_path_ext; + create_folder_by_path(dirname($html_path)); + file_put_contents($html_path, $template, LOCK_EX); } - function make_www_cache_ah($device, $information) + + function make_www_cache_ah($device, $information, $recommand_information) { $data = array(); @@ -978,7 +1171,7 @@ class Information extends CI_Controller //推荐信息或者产品 //信息推荐 - $template_recommand = $this->recommand_information($information); + $template_recommand = $recommand_information;// $this->recommand_information($information); $template = str_replace('', $this->load->view($template_path . '-next', array('recommands' => $template_recommand), TRUE), $template); //广告,改叫tips,防止被插件屏蔽 if (!empty($template_recommand['Tips Right'])) { @@ -993,6 +1186,18 @@ class Information extends CI_Controller $information->ic_content = str_replace('', $this->load->view($template_path . '-recommends-tour', array('recommands' => $template_recommand), TRUE), $information->ic_content); } + //替换内容中广告 + $temp_array = array(); + preg_match_all('^^', $information->ic_content, $temp_array); + if (!empty($temp_array[1])) { + foreach ($temp_array[1] as $key => $item) { + $tips_detail = $this->recommends_and_tips_model->tips_detail($item); + if ($tips_detail) { + $information->ic_content = str_replace($temp_array[0][$key], $tips_detail->it_content, $information->ic_content); + } + } + } + //非产品页面 if (empty(get_meta($information->ic_id, 'meta_product_code'))) { $addthis_widget = $this->load->view($template_path . '-add-this', false, true); @@ -1002,7 +1207,11 @@ class Information extends CI_Controller } //主样式表,内联模式 - $main_css_string = compress_css(GET_HTTP('https://proxy-data.asiahighlights.com/css/mobile-first.css')); + if (is_file('D:/wwwroot/origin-www.asiahighlights.com/css/mobile-first.css')) {//主样式表,内联模式,优先读取本地,没有在从网络读取,为了加速 + $main_css_string = compress_css(file_get_contents('D:/wwwroot/origin-www.asiahighlights.com/css/mobile-first.css')); + } else { + $main_css_string = compress_css(GET_HTTP('https://proxy-data.asiahighlights.com/css/mobile-first.css')); + } $template = str_replace('', '', $template); //额外样式 $meta_addon_css = get_meta($information->ic_id, 'meta_addon_css'); @@ -1020,36 +1229,29 @@ class Information extends CI_Controller $lazy_content = $this->html_optimize_lib->set_lazy_loader($information->ic_content, 'https://data.asiahighlights.com/grey.gif'); $template = str_replace('', $lazy_content, $template); - //替换内容中广告 - $temp_array = array(); - preg_match_all('^^', $template, $temp_array); - if (!empty($temp_array[1])) { - foreach ($temp_array[1] as $key => $item) { - $tips_detail = $this->recommends_and_tips_model->tips_detail($item); - if ($tips_detail) { - $template = str_replace($temp_array[0][$key], $tips_detail->it_content, $template); - } - } - } //Google广告代码 //if (!empty(get_meta($information->ic_id, 'meta_google_ad_content'))) { $template = str_replace('', '', $template); //} //社媒分享图片 - - $full_ic_photo=''; + + $full_ic_photo = ''; if (!empty($information->ic_photo)) { $full_ic_photo = $this->config->item('site_image_url') . $information->ic_photo; - }else{ - $full_ic_photo = get_meta($information->ic_id, 'meta_addon_picture_mobile'); - } - if(!empty($full_ic_photo)){ + } else { + $full_ic_photo = get_meta($information->ic_id, 'meta_addon_picture_mobile'); + } + if (!empty($full_ic_photo)) { $template = str_replace('', '', $template); } - + //设置图片尺寸 - $template = $this->html_optimize_lib->set_image_size($template); + if (is_dir('D:/wwwroot/origin-images.chinahighlights.com') && is_dir('D:/wwwroot/origin-www.asiahighlights.com')) { + $template = $this->html_optimize_lib->set_image_size_local($template, 'D:/wwwroot/origin-www.asiahighlights.com', 'D:/wwwroot/origin-images.chinahighlights.com'); + } else { + $template = $this->html_optimize_lib->set_image_size($template); + } // /travelguide/chinese-zodiac/monthly-fortune-for-dog.htm $html_path = $this->config->item('cache')[$this->config->item('site_code')]['cache_path'] . $information->ic_url; $html_path = str_replace("\\", "/", $html_path); @@ -1081,9 +1283,21 @@ class Information extends CI_Controller $data["KEYWORDS"] = $information->ic_seo_keywords; $data["CANONICAL"] = $this->config->item('site_url') . $information->ic_url; + + //面包屑 + $crumb = ""; + $crumb_data = $this->Information_model->get_path_exclude_ct($information->is_id, $information->is_path); + if (count($crumb_data)>0){ //至少有一个父类面包屑才显示 + $crumb = "
Home"; + foreach ($crumb_data as $index => $item) { + $crumb .= ''.$item['ic_url_title'].''; + } + $crumb .="
"; + } + $data["crumb"] = $crumb; /* 详细内容 */ $ic_content = $information->ic_content; - // /**替换详细内容里面的价格 + // /**替换详细内容里面的价格 /* 直接使用fetch来动态获取价格,这样不用替换标签,直接录标签 // * // 一日游价格标签, "" 或者 逗号后面是人数 // * //精华线路标签"" @@ -1099,8 +1313,9 @@ class Information extends CI_Controller // return '';; // },$ic_content); - - + /** 替换H1加面包屑 */ + $ic_content = preg_replace('/

(.*)<\/h1>/i',$crumb."\r\n".'

$1

',$ic_content,1); + //图片加延迟 $ic_content = $this->html_optimize_lib->set_lazy_loader($ic_content, 'https://data.chinatravel.com/images/mobile-first/grey.gif'); @@ -1133,7 +1348,7 @@ class Information extends CI_Controller //主样式表,内联模式 //$apiweb="http://202.103.68.104"; //本地测试 - $apiweb = "https://data.chinatravel.com"; + $apiweb = "https://data.chinatravel.com"; $cssUrl = $apiweb . "/css/newcss3/base.css?v=" . time(); $main_css_string = compress_css(GET_HTTP($cssUrl)); $data["MAINCSS"] = ''; @@ -1151,11 +1366,11 @@ class Information extends CI_Controller //社媒分享图片 $data["OGIMAGE"] = ""; if (!empty($information->ic_photo)) { - if (strpos($information->ic_photo,"chinatravel.com")!=false){ + if (strpos($information->ic_photo, "chinatravel.com") != false) { $full_ic_photo = $information->ic_photo; - }else{ + } else { $full_ic_photo = $this->config->item('site_image_url') . $information->ic_photo; - } + } $data["OGIMAGE"] = ''; } @@ -1189,7 +1404,7 @@ class Information extends CI_Controller if (!empty($meta_addon_js)) { $addonJs .= ''; } - //价格js + //价格js if ($meta_ct_page_price == "yes") { $addonJs .= ''; } @@ -1273,8 +1488,8 @@ class Information extends CI_Controller #endregion #region 移动端和PC端差别处理区域 - $arrDevice = array("mobile","pc"); - foreach($arrDevice as $device){ + $arrDevice = array("mobile", "pc"); + foreach ($arrDevice as $device) { //顶部全屏大图 $data["TOPBANNER"] = ""; $ImgText = ""; //图文字 @@ -1282,29 +1497,29 @@ class Information extends CI_Controller $meta_addon_picture_text = get_meta($information->ic_id, 'meta_addon_picture_text'); if ($device == 'mobile') { //移动端读取移动大图 $meta_addon_picture = get_meta($information->ic_id, 'meta_addon_picture_mobile'); - $bannerImg = '' . $information->ic_title . ''; + $bannerImg = '' . $information->ic_title . ''; if (!empty($meta_addon_picture_url) && !empty($meta_addon_picture_text)) { $ImgText = ''; - } else if(!empty($meta_addon_picture_text)){ + } else if (!empty($meta_addon_picture_text)) { $ImgText = ''; } } else { $meta_addon_picture = get_meta($information->ic_id, 'meta_addon_picture'); $bannerImg = '' . $information->ic_title . ''; - if (!empty($meta_addon_picture_url) && !empty($meta_addon_picture_text) ) { + if (!empty($meta_addon_picture_url) && !empty($meta_addon_picture_text)) { $ImgText = ''; - } else if(!empty($meta_addon_picture_text)) { + } else if (!empty($meta_addon_picture_text)) { $ImgText = ''; } } // 搜索框 $template_TrainSearch = ""; - if ($information->ic_url =="/china-trains/hometest" || $information->ic_url=="/china-trains"){ + if ($information->ic_url == "/china-trains/hometest" || $information->ic_url == "/china-trains") { //火车票首页 $template_TrainSearch = $this->load->view($template_path . '-train-index', null, TRUE); $ImgText = ""; - }else if ($information->ic_url =="/china-flights"){ + } else if ($information->ic_url == "/china-flights") { //机票首页 $template_TrainSearch = $this->load->view($template_path . '-flight-index', null, TRUE); $ImgText = ""; @@ -1319,7 +1534,7 @@ class Information extends CI_Controller } - //两种设备分别调用两种模板 ,静态化 + //两种设备分别调用两种模板 ,静态化 switch ($device) { case 'mobile': //获取移动优先的模板,如果有的话 @@ -1354,8 +1569,8 @@ class Information extends CI_Controller $html_path .= $html_path_ext; create_folder_by_path(dirname($html_path)); file_put_contents($html_path, $template, LOCK_EX); - - } + + } #endregion } @@ -1393,7 +1608,7 @@ class Information extends CI_Controller $data = $this->Information_model->random(1, $root_information->is_path, $exclude_ids); break; case 'rule_this_node_random'://指定节点下随机 - $ir_pointer = $this->Information_model->Detail($recommand->ir_pointer_is_id); + $ir_pointer = $this->Information_model->Detail($recommand->ir_pointer_is_id, 'is_path'); if (!empty($ir_pointer)) { $data = $this->Information_model->random(1, $ir_pointer->is_path, $exclude_ids); } @@ -1423,7 +1638,7 @@ class Information extends CI_Controller $data->mobile_photo = get_meta($data->ic_id, 'meta_addon_picture_mobile'); if (empty($data->mobile_photo)) { if (!empty($data->ic_photo)) { - $data->mobile_photo = $this->config->item('site_image_url').$data->ic_photo; + $data->mobile_photo = $this->config->item('site_image_url') . $data->ic_photo; } else { $data->mobile_photo = 'https://data.chinahighlights.com/image/travelguide/article/recommended-info-bottom-cover.jpg'; } @@ -1442,7 +1657,6 @@ class Information extends CI_Controller $root_recommands = $this->recommends_and_tips_model->recommends_list($root_detail->is_id);//节点下所有的推荐规则 $exclude_ids = array($information->is_id);//需要排除的is_id,防止通过页面显示相同内容,默认排除本身,每个推荐内容都需要排除已经推荐过的 - foreach ($root_recommands as $item) { $result = $this->recommand_information_rule($information, $root_detail, $item, $exclude_ids); if (!empty($result)) { diff --git a/application/libraries/html_optimize_lib.php b/application/libraries/html_optimize_lib.php index 1480aa62..d241bd6e 100644 --- a/application/libraries/html_optimize_lib.php +++ b/application/libraries/html_optimize_lib.php @@ -31,7 +31,7 @@ class html_optimize_lib /**有些图片不需要延迟加载,比如头部第一张图,延迟加载会影响CLS的评分,所以图片加loader="nolazy"属性就可以不用替换为延迟加载代码。 */ $loader = $image->loader; - if (!empty($loader) && $loader=="nolazy"){ + if (!empty($loader) && $loader == "nolazy") { continue; } /** 无需延迟加载结束 20210527 zp */ @@ -99,8 +99,41 @@ class html_optimize_lib } return $html_object->save(); - } + //获取图片尺寸的本地版本,图片存在相同服务器上,速度比较快 + //$dataPath data文件夹本地路径 + //$imagesPath images文件夹本地路径 + public function set_image_size_local($html, $dataPath, $imagesPath) + { + $html_object = str_get_html($html); + + foreach ($html_object->find('img') as $image) { + $img_src = $image->src; + if (!empty($image->originalsrc)) { + $img_src = $image->originalsrc; + } + //图片已经设置了尺寸的不再修改 + if (empty($image->width) && (strpos($img_src, '//data.') !== false || strpos($img_src, '//images.') !== false)) {//以data或者images开头的域名才能获取尺寸 + $img_src_urls = parse_url(trim($img_src)); + $request_size[$img_src_urls['host']][] = $img_src_urls['path']; + $file_path = ''; + if (strpos($img_src, '//data.') !== false) { + $file_path = $dataPath . $img_src_urls['path']; + } + if (strpos($img_src, '//images.') !== false) { + $file_path = $imagesPath . $img_src_urls['path']; + } + if (is_file($file_path)) { + $properties = getimagesize($file_path);//获取图片属性 + if (!empty($properties[0]) && !empty($properties[1])) { + $image->width = $properties[0]; + $image->height = $properties[1]; + } + } + } + } + return $html_object->save(); + } } diff --git a/application/models/information_model.php b/application/models/information_model.php index aea0bc56..a25db8a9 100644 --- a/application/models/information_model.php +++ b/application/models/information_model.php @@ -117,7 +117,7 @@ class Information_model extends CI_Model { $exclude_ids_string=implode(',',$exclude_ids); $this->search .= " AND ic_status=1 AND is_id NOT in ($exclude_ids_string,0)"; $this->orderBy = " ORDER BY NewID() "; - return $this->GetList(); + return $this->GetList('ic_id, is_id, ic_url,ic_url_title,ic_title,is_path,is_level,ic_status,ic.ic_photo'); } //根据url搜索信息 @@ -237,7 +237,7 @@ class Information_model extends CI_Model { } - function Detail($ic_url_is_id) { + function Detail($ic_url_is_id,$filed='') { if (empty($ic_url_is_id)) { return false; } @@ -303,7 +303,8 @@ class Information_model extends CI_Model { $sql.=" $filed "; } //添加查询AMP发布状态 - $sql.=",isnull((select top 1 CONVERT(varchar, im_value) from infoMetas where im_ic_id=ic_id and im_key='AMP_STATUS'),0) as amp_status "; + //$sql.=",isnull((select top 1 CONVERT(varchar, im_value) from infoMetas where im_ic_id=ic_id and im_key='AMP_STATUS'),0) as amp_status "; + $sql.=",0 as amp_status "; $sql.="FROM infoStructures is1 \n" . " INNER JOIN infoContents ic ON ic.ic_id = is1.is_ic_id \n" . " AND ic.ic_sitecode = is1.is_sitecode \n" @@ -550,5 +551,68 @@ class Information_model extends CI_Model { return $this->GetList(); } + /** + * CT 获取当前页面的面包屑,不包括当前节点,去除链接为空及不发布的节点 + */ + function get_path_exclude_ct($is_id, $path) { + $site_code = $this->config->item('site_code'); + $path_query = $this->HT->query("select + ic_id, is_id, ic_url,ic_url_title,ic_title,is_path,is_level,ic_status + from infoStructures a inner join infoContents b on a.is_ic_id=b.ic_id + where is_id in ($path 0) and is_id <> ? and is_siteCode = ? order by is_level asc", array($is_id, $site_code)); + $path_result = $path_query->result(); + $path_list = []; + + $group_map = [ + 278013869 => [ + 'ic_url' => '/tour', + 'ic_url_title' => 'China Tours' + ], + 278014282 => [ + 'ic_url' => '/citytour', + 'ic_url_title' => 'China City Tours' + ], + 278013862 => [ + 'ic_url' => '/daytrip', + 'ic_url_title' => 'China Day Trip' + ], + 278014609 => [ + 'ic_url' => '/china-trains', + 'ic_url_title' => 'China Trains' + ], + 278014608 => [ + 'ic_url' => '/china-flights', + 'ic_url_title' => 'China Flights' + ] + ]; + + foreach ($path_result as $path_row) { + + if (array_key_exists($path_row->is_id, $group_map)) { + $top_group = $group_map[$path_row->is_id]; + $path_array = [ + 'ic_id' => $path_row->ic_id, + 'is_id' => $path_row->is_id, + 'ic_title' => $path_row->ic_title, + 'ic_url' => $top_group['ic_url'], + 'ic_url_title' => $top_group['ic_url_title'] + ]; + $path_list[] = $path_array; + } + else if ($path_row->ic_status === 1) { + $path_array = [ + 'ic_id' => $path_row->ic_id, + 'is_id' => $path_row->is_id, + 'ic_title' => $path_row->ic_title, + 'ic_url' => $path_row->ic_url, + 'ic_url_title' => $path_row->ic_url_title + ]; + $path_list[] = $path_array; + + } + } + + return $path_list; + } } diff --git a/application/views/bootstrap3/information_edit.php b/application/views/bootstrap3/information_edit.php index 050bf014..53bc8d4e 100644 --- a/application/views/bootstrap3/information_edit.php +++ b/application/views/bootstrap3/information_edit.php @@ -2312,7 +2312,7 @@ 忽略URL重复
- config->item('site_code'), array('ch', 'cht', 'gm', 'ah', 'ct','chinatravel'))) { ?> + config->item('site_code'), array('ch', 'cht', 'gm', 'ah', 'gh', 'ct','chinatravel'))) { ?>