优化批量更新

hotfix/paypal-note
尹诚诚 4 years ago
parent 058781c896
commit 4291e685cd

@ -509,13 +509,14 @@ 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);
@ -895,48 +896,219 @@ class Information extends CI_Controller
}
function make_www_cache_gh($information)
function make_www_cache_gh($device, $information, $recommand_information)
{
return false;
$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(
'<!--@STRUCTURED-DATA-BREADCRUMB-BLOCK@-->',
$breadcrumb_structured_data_content,
$template);
//替换模板中的标签
$template_mobile = str_replace('<!--@TITLE@-->', $information->ic_seo_title, $template_mobile);
$template_pc = str_replace('<!--@TITLE@-->', $information->ic_seo_title, $template_pc);
$template_mobile = str_replace('<!--@DESCRIPTION@-->', $information->ic_seo_description, $template_mobile);
$template_pc = str_replace('<!--@DESCRIPTION@-->', $information->ic_seo_description, $template_pc);
$template_mobile = str_replace('<!--@KEYWORDS@-->', $information->ic_seo_keywords, $template_mobile);
$template_pc = str_replace('<!--@KEYWORDS@-->', $information->ic_seo_keywords, $template_pc);
$template_mobile = str_replace('<!--@CANONICAL@-->', $this->config->item('site_url') . $information->ic_url, $template_mobile);
$template_pc = str_replace('<!--@CANONICAL@-->', $this->config->item('site_url') . $information->ic_url, $template_pc);
$template = str_replace('<!--@TITLE@-->', $information->ic_seo_title, $template);
$template = str_replace('<!--@DESCRIPTION@-->', $information->ic_seo_description, $template);
$template = str_replace('<!--@KEYWORDS@-->', $information->ic_seo_keywords, $template);
$template = str_replace('<!--@CANONICAL@-->', $this->config->item('site_url') . $information->ic_url, $template);
// 动态加载反馈标签
// HTLM: <div><!--@FEEDBACK_Shanghai@--></div>
// 解析结果:<!--@FEEDBACK_Shanghai@-->, Shanghai
$feedback_array = [];
preg_match_all('^<!--@FEEDBACK_(.*)@-->^', $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);
}
}
//非产品页面
$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('<!--@HEAD_1@-->', $template_H1, $template);
$addthis_widget = $this->load->view($template_path . '-add-this', false, true);
$template = str_replace('<!--@ADDTHIS-WIDGET@-->', $addthis_widget, $template);
$article_structured_data_content = $this->load->view(
$template_path . '-structured-data-article',
array('information' => $information, 'author' => $author),
true);
$template = str_replace('<!--@STRUCTURED-DATA-ARTICLE-BLOCK@-->', $article_structured_data_content, $template);
} else {
$template = str_replace('<!--@PRODUCT-JS@-->', '<script src="https://data.chinahighlights.com/js/flatpickr.js"></script>', $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@-->', $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-BLOCK@-->', $breadcrumb_content, $information->ic_content);
}
//信息推荐
$template_recommand = $recommand_information; //$this->recommand_information($information); 从外面传进来pc和移动只需要查一次减少数据库负担
$template = str_replace('<!--@ARTICLENEXT@-->', $this->load->view($template_path . '-next', array('recommands' => $template_recommand), TRUE), $template);
// //广告改叫tips防止被插件屏蔽
if (!empty($template_recommand['Tips Right TOP'])) {
$template = str_replace('<!--@TIPS-RIGHT-TOP@-->', "<div class='right_brand_info'><aside>" . $template_recommand['Tips Right TOP']->it_content . "</aside></div>", $template);
}
if (!empty($template_recommand['Tips Right'])) {
$template = str_replace('<!--@TIPS-RIGHT@-->', "<div class='right_tour'>" . $template_recommand['Tips Right']->it_content . "</div>", $template);
}
//文中的信息推荐
if (strpos($information->ic_content, '<!--@Content-Recommends-Article@-->') !== false) {
$information->ic_content = str_replace('<!--@Content-Recommends-Article@-->', $this->load->view($template_path . '-recommends-article', array('recommands' => $template_recommand), TRUE), $information->ic_content);
}
//文中的线路推荐
if (strpos($information->ic_content, '<!--@Content-Recommends-Tour@-->') !== false) {
$information->ic_content = str_replace('<!--@Content-Recommends-Tour@-->', $this->load->view($template_path . '-recommends-tour', array('recommands' => $template_recommand), TRUE), $information->ic_content);
}
//替换内容中广告
$temp_array = array();
preg_match_all('^<!--@TIPS-[A-Z]+-([0-9]+)@-->^', $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('<!--@TOP-BANNER@-->', '<div class="detailtopbanner"><a href="' . $meta_addon_picture_url . '"> <img class="img-responsive" alt="' . $information->ic_title . '" src="' . $meta_addon_picture . '"></a></div>', $template);
} else {
$template = str_replace('<!--@TOP-BANNER@-->', '<div class="detailtopbanner"><img class="img-responsive" alt="' . $information->ic_title . '" src="' . $meta_addon_picture . '">' . $template_TrainSearch . '</div>', $template);
}
}
//顶部视频
$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_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('<!--@TOP-VIDEO@-->', '<div class="detailtopbanner"><video autoplay="" controls="controls" id="bgvid" poster="' . $meta_video_picture . '" src="' . $meta_news_video . '" style="position: inherit;"> </video></div>', $template);
}
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('<!--@MAIN-CSS@-->', '<style type="text/css">' . $main_css_string . '</style>', $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 {
$data['meta_addon_picture'] = get_meta($information->ic_id, 'meta_addon_picture');
$meta_addon_css_string = compress_css(GET_HTTP($meta_addon_css));
}
$data['meta_addon_picture_url'] = get_meta($information->ic_id, 'meta_addon_picture_url');
$template = str_replace('<!--@ADDON-CSS@-->', '<style type="text/css">' . $meta_addon_css_string . '</style>', $template);
}
//额外js
$meta_addon_js = get_meta($information->ic_id, 'meta_addon_js');
if (!empty($meta_addon_js)) {
$template = str_replace('<!--@ADDON-JS@-->', '<script src="' . $meta_addon_js . '"></script>', $template);
}
//设置内容图片缓加载
$lazy_content = $this->html_optimize_lib->set_lazy_loader($information->ic_content, 'https://data.chinahighlights.com/grey.gif');
$template = str_replace('<!--@CUSTOM-CONENT@-->', $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('<!--@HEAD_1@-->', $template_H1, $template_mobile);
$template_pc = str_replace('<!--@HEAD_1@-->', $template_H1, $template_pc);
//替换内容中各种标签
$tag_why_us = $this->load->view($template_path . '-why-us', false, true);
$template = str_replace('<!--@TAG-WHY-US@-->', $tag_why_us, $template);
//Google广告代码
//if (!empty(get_meta($information->ic_id, 'meta_google_ad_content'))) {
$template = str_replace('<!--@Match-Content-GOOGLE@-->', '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-4231674166786366" data-ad-slot="1447610161" data-matched-content-rows-num="2,2" data-matched-content-columns-num="1,3" data-matched-content-ui-type="image_stacked,image_stacked"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>', $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('<!--@OG:IMAGE@-->', '<meta property="og:image" content="' . $full_ic_photo . '"><meta property="og:image:secure_url" content="' . $full_ic_photo . '"><meta property="og:image:width" content="800"><meta property="og:image:height" content="450">', $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);
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, $recommand_information)
{

Loading…
Cancel
Save