CT的静态化程序优化速度

hotfix/paypal-note
赵鹏 4 years ago
parent 3e7c44285a
commit 77b338ce73

@ -423,8 +423,8 @@ class Information extends CI_Controller
}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('mobile', $information_new);
$this->make_www_cache_ct('pc', $information_new);
$this->make_www_cache_ct($information_new);
// $this->make_www_cache_ct('pc', $information_new);
} else if (strcasecmp($site_code, "cht") == 0 && !empty($auto_update_cache)) {
$update_info_log = $this->update_cache($ic_url);
} else if (strcasecmp($site_code, "ah") == 0 && !empty($auto_update_cache)) {
@ -512,8 +512,8 @@ class Information extends CI_Controller
$this->make_www_cache_ah('pc', $information);
$this->make_www_cache_ah('mobile', $information);
} else if ($this->config->item('site_code') == 'chinatravel') {
$this->make_www_cache_ct('pc', $information);
$this->make_www_cache_ct('mobile', $information);
$this->make_www_cache_ct($information);
// $this->make_www_cache_ct('mobile', $information);
}
echo json_encode(array('name' => 'yes', 'data' => '更新成功!'));
@ -1065,9 +1065,11 @@ class Information extends CI_Controller
* @return:
* @Date Changed:
*/
function make_www_cache_ct($device, $information)
function make_www_cache_ct($information)
{
$data = array();
#region 公用数据
//$apiurl = "http://202.103.68.104:61/info.php"; //本地测试
$apiurl = "https://ct.mycht.cn/info.php"; //网前
@ -1095,7 +1097,7 @@ class Information extends CI_Controller
// return '<span class="js_getTourPrice" data="'.$matchItem.'"></span>';;
// },$ic_content);
//$ic_content = '<div class="container-details details-content">'.$ic_content.'</div>'; //兼容拷贝过来的内容样式
//图片加延迟
$ic_content = $this->html_optimize_lib->set_lazy_loader($ic_content, 'https://data.chinatravel.com/images/mobile-first/grey.gif');
@ -1117,48 +1119,6 @@ class Information extends CI_Controller
$data["ISPRODUCT"] = "yes";
}
//顶部全屏大图
$data["TOPBANNER"] = "";
$ImgText = ""; //图文字
$meta_addon_picture_url = get_meta($information->ic_id, 'meta_addon_picture_url');
$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 = '<img class="img-responsive" alt="' . $information->ic_title . '" src="' . $meta_addon_picture . '" width="750" height="500">';
if (!empty($meta_addon_picture_url) && !empty($meta_addon_picture_text)) {
$ImgText = '<div class="carousel-caption"><p class="ads-title"><a href="' . $meta_addon_picture_url . '">' . $meta_addon_picture_text . '</a></p></div>';
} else if(!empty($meta_addon_picture_text)){
$ImgText = '<div class="carousel-caption"><p class="ads-title">' . $meta_addon_picture_text . '</p></div>';
}
} else {
$meta_addon_picture = get_meta($information->ic_id, 'meta_addon_picture');
$bannerImg = '<img class="img-responsive" alt="' . $information->ic_title . '" src="' . $meta_addon_picture . '" width="1920" height="600">';
if (!empty($meta_addon_picture_url) && !empty($meta_addon_picture_text) ) {
$ImgText = '<div class="carousel-caption"><p class="ads-title"><a href="' . $meta_addon_picture_url . '">' . $meta_addon_picture_text . '</a></p></div>';
} else if(!empty($meta_addon_picture_text)) {
$ImgText = '<div class="carousel-caption"><p class="ads-title">' . $meta_addon_picture_text . '</p></div>';
}
}
// 搜索框
$template_TrainSearch = "";
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"){
//机票首页
$template_TrainSearch = $this->load->view($template_path . '-flight-index', null, TRUE);
$ImgText = "";
}
if (!empty($meta_addon_picture)) {
if (!empty($meta_addon_picture_url)) {
$data["TOPBANNER"] = '<div class="banner"><a href="' . $meta_addon_picture_url . '">' . $bannerImg . ' </a>' . $ImgText . $template_TrainSearch . '</div>';
} else {
$data["TOPBANNER"] = '<div class="banner">' . $bannerImg . $ImgText . $template_TrainSearch . '</div>';
}
}
//顶部视频
$data["TOPVIDEO"] = "";
@ -1172,11 +1132,7 @@ class Information extends CI_Controller
//主样式表,内联模式
//$apiweb="http://202.103.68.104"; //本地测试
$apiweb = "https://data.chinatravel.com";
if ($device == "mobile") {
$cssUrl = $apiweb . "/css/newcss3/base.css?v=" . time();
} else {
$cssUrl = $apiweb . "/css/newcss3/base.css?v=" . time();
}
$cssUrl = $apiweb . "/css/newcss3/base.css?v=" . time();
$main_css_string = compress_css(GET_HTTP($cssUrl));
$data["MAINCSS"] = '<style type="text/css">' . $main_css_string . '</style>';
@ -1312,46 +1268,93 @@ class Information extends CI_Controller
$data["ADDONJS"] = $addonJs;
$data["passParam"] = $passParam;
#region 移动端和PC端差别处理区域
#endregion
//两种模板
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, $data, TRUE);
$html_path_ext = '-mobile.htm';
} else {
return false;
#region 移动端和PC端差别处理区域
$arrDevice = array("mobile","pc");
foreach($arrDevice as $device){
//顶部全屏大图
$data["TOPBANNER"] = "";
$ImgText = ""; //图文字
$meta_addon_picture_url = get_meta($information->ic_id, 'meta_addon_picture_url');
$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 = '<img class="img-responsive" alt="' . $information->ic_title . '" src="' . $meta_addon_picture . '" width="750" height="500">';
if (!empty($meta_addon_picture_url) && !empty($meta_addon_picture_text)) {
$ImgText = '<div class="carousel-caption"><p class="ads-title"><a href="' . $meta_addon_picture_url . '">' . $meta_addon_picture_text . '</a></p></div>';
} else if(!empty($meta_addon_picture_text)){
$ImgText = '<div class="carousel-caption"><p class="ads-title">' . $meta_addon_picture_text . '</p></div>';
}
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', $data, TRUE);
$html_path_ext = '-pc.htm';
} else {
$meta_addon_picture = get_meta($information->ic_id, 'meta_addon_picture');
$bannerImg = '<img class="img-responsive" alt="' . $information->ic_title . '" src="' . $meta_addon_picture . '" width="1920" height="600">';
if (!empty($meta_addon_picture_url) && !empty($meta_addon_picture_text) ) {
$ImgText = '<div class="carousel-caption"><p class="ads-title"><a href="' . $meta_addon_picture_url . '">' . $meta_addon_picture_text . '</a></p></div>';
} else if(!empty($meta_addon_picture_text)) {
$ImgText = '<div class="carousel-caption"><p class="ads-title">' . $meta_addon_picture_text . '</p></div>';
}
}
// 搜索框
$template_TrainSearch = "";
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"){
//机票首页
$template_TrainSearch = $this->load->view($template_path . '-flight-index', null, TRUE);
$ImgText = "";
}
if (!empty($meta_addon_picture)) {
if (!empty($meta_addon_picture_url)) {
$data["TOPBANNER"] = '<div class="banner"><a href="' . $meta_addon_picture_url . '">' . $bannerImg . ' </a>' . $ImgText . $template_TrainSearch . '</div>';
} else {
return false;
$data["TOPBANNER"] = '<div class="banner">' . $bannerImg . $ImgText . $template_TrainSearch . '</div>';
}
break;
default:
}
}
//生成静态文件
$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);
//两种设备分别调用两种模板 ,静态化
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, $data, 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', $data, TRUE);
$html_path_ext = '-pc.htm';
} else {
return false;
}
break;
default:
}
//生成静态文件
$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);
}
#endregion
}

@ -22,7 +22,7 @@
<input name="flightfrom" id="flightfrom" type="text" class="inputBox form-control" autocomplete="off" placeholder="From City or airport">
<input id="flightfromcode" name="flightfromcode" type="hidden" value="" />
</div>
<a href="javascript:;" class="exchange js_FlightsChange" id="js_FlightsChange"><img class="cityArrow" src="/images/icon/reverseCity.png"></a>
<a href="javascript:;" class="exchange js_FlightsChange" id="js_FlightsChange"><img class="cityArrow" src="https://data.chinatravel.com/images/icon/reverseCity.png" width="34px" height="34px"></a>
<div class="flex-col-2">
<input name="flighto" id="flighto" type="text" class="inputBox form-control" autocomplete="off" placeholder="To City or airport">
<input name="flightocode" id="flightocode" type="hidden" value="" />

Loading…
Cancel
Save