添加CT的静态文件生成代码

ct-mobile-first
赵鹏 4 years ago
parent 4ff6f2edaa
commit 3379d71b35

@ -725,6 +725,7 @@ $config['cache']['vac']['cache_path'] = 'C:\VHD\Dropbox\wwwcache\viaje-a-china.c
$config['cache']['ru']['cache_path'] = 'C:\VHD\Dropbox\wwwcache\chinahighlights.ru';
$config['cache']['it']['cache_path'] = 'C:\VHD\Dropbox\wwwcache\viaggio-in-cina.it';
$config['cache']['ch']['cache_path'] = 'D:\wwwcache\chinahighlights.com';
$config['cache']['chinatravel']['cache_path'] = 'D:\wwwcache\chinatravel.com';
//静态文件更新接口
$config['cache']['jp']['cache_api'] = '/info.php/information/update_cache/';

@ -328,22 +328,25 @@ class Information extends CI_Controller
}
//获取移动优先的模板,如果有的话
$mobile_first_template_path = 'mobile_first/' . $this->config->item('site_code');
if (is_file(APPPATH . 'views/' . $mobile_first_template_path . EXT)) {
$mobile_template_H1 = $this->call_mobile_template_H1($mobile_first_template_path, $data['information']->is_path, $data['information']->ic_author, $data['information']->ic_title, $data['information']->ic_photo);//H1模板替换
$data['mobile_first_template'] = $this->load->view($mobile_first_template_path, '', TRUE);
if (empty(get_meta($data['information']->ic_id, 'meta_product_code'))) {
$data['mobile_first_template'] = str_replace('<!--@HEAD_1@-->', $mobile_template_H1, $data['mobile_first_template']);
}
//主样式表,内联模式
$main_css_string=compress_css(GET_HTTP('https://proxy-data.chinahighlights.com/css/mobile-first.css'));
$data['mobile_first_template'] = str_replace('<!--@MAIN-CSS@-->', '<style type="text/css">' . $main_css_string . '</style>', $data['mobile_first_template']);
//查找是否有静态文件
if ($this->html_file_helper('find', $data['information']->ic_url)) {
$data['has_html_file'] = true;
//增加判断站点,每个站点需要读取的模板不一样。 20210311 zp
if ($this->config->item('site_code')=="ch"){
$mobile_first_template_path = 'mobile_first/' . $this->config->item('site_code');
if (is_file(APPPATH . 'views/' . $mobile_first_template_path . EXT)) {
$mobile_template_H1 = $this->call_mobile_template_H1($mobile_first_template_path, $data['information']->is_path, $data['information']->ic_author, $data['information']->ic_title, $data['information']->ic_photo);//H1模板替换
$data['mobile_first_template'] = $this->load->view($mobile_first_template_path, '', TRUE);
if (empty(get_meta($data['information']->ic_id, 'meta_product_code'))) {
$data['mobile_first_template'] = str_replace('<!--@HEAD_1@-->', $mobile_template_H1, $data['mobile_first_template']);
}
//主样式表,内联模式
$main_css_string=compress_css(GET_HTTP('https://proxy-data.chinahighlights.com/css/mobile-first.css'));
$data['mobile_first_template'] = str_replace('<!--@MAIN-CSS@-->', '<style type="text/css">' . $main_css_string . '</style>', $data['mobile_first_template']);
//查找是否有静态文件
if ($this->html_file_helper('find', $data['information']->ic_url)) {
$data['has_html_file'] = true;
}
} else {
$data['mobile_first_template'] = '没有找到移动模板';
}
} else {
$data['mobile_first_template'] = '没有找到移动模板';
}
@ -499,6 +502,12 @@ class Information extends CI_Controller
$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);
}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);
} 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)) {
@ -737,6 +746,112 @@ class Information extends CI_Controller
file_put_contents($html_path, $template, LOCK_EX);
}
/**
* @description: CT用的生成静态文件方法.有些内容的替换CT这边不一样需要单独处理 zp
* @param {type} $device='mobile' or 'pc'
* @return:
* @Date Changed:
*/
function make_www_cache_ct($device,$information){
$data = array();
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:
}
//替换模板中的标签
$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);
//非产品页面
if (empty(get_meta($information->ic_id, 'meta_product_code'))) {
} else {
$template = str_replace('<!--@PRODUCT-JS@-->', '<script src="https://data.chinahighlights.com/js/flatpickr.js"></script>', $template);
}
//顶部全屏大图
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 . '"></div>', $template);
}
}
//顶部视频
$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);
}
//主样式表,内联模式
$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)) {
//引用方式 $template = str_replace('<!--@ADDON-CSS@-->', '<link href="' . $meta_addon_css . '" rel="stylesheet">', $template);
//内联方式
$meta_addon_css_string=compress_css(GET_HTTP($meta_addon_css));
$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);
}
$template = str_replace('<!--@CUSTOM-CONENT@-->', $information->ic_content, $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"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>', $template);
}
if (!empty(get_meta($information->ic_id, 'meta_google_ad_article'))) {
$in_article_google=$this->load->view($template_path.'-google-ad', false,true);
$template = str_replace('<!--@IN-ARTICLE-GOOGLE@-->', $in_article_google, $template);
}
//社媒分享图片
if (!empty($information->ic_photo)) {
$full_ic_photo = $this->config->item('site_image_url') . $information->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);
}
//设置图片尺寸
$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 call_mobile_template_H1($mobile_first_template_path, $is_path, $ic_author, $ic_title, $ic_photo)
{
$data['infocategory'] = $this->Information_model->get_detail_by_path($is_path, 1);//信息所属分类,获取信息顶级节点内容

@ -569,7 +569,7 @@
<ul id="treeDemo" name="treeDemo" class="ztree" style="height:1035px;overflow-x:auto;"></ul>
<ul class="nav nav-list">
<li class="nav-header">
<?php if($this->config->item('site_code')!=='ch'){ ?>
<?php if(!in_array($this->config->item('site_code'),array('ch','chinatravel'))){ ?>
<a href="<?php echo site_url('welcome/create_infomation_urls/' . $information->is_id); ?>"
target="_blank" class="col-sm-5" title="批量更新静态化页面"><i
class="text-muted glyphicon glyphicon-retweet"></i></a>
@ -2075,7 +2075,7 @@
</div>
</div>
<?php if ($this->config->item('site_code') == 'ch') { ?>
<?php if (in_array($this->config->item('site_code'),array('ch','chinatravel'))) { ?>
<script>
function show_ad_mate(mate_name, value) {
if ($('#' + mate_name).prop("checked")) {
@ -2111,7 +2111,7 @@
</div>
<?php } ?>
<?php if ($this->config->item('site_code') !== 'ch') { ?>
<?php if (!in_array($this->config->item('site_code'),array('ch','chinatravel'))) { ?>
<label>信息类型</label>
<select name="ic_type" id="ic_type" class="form-control" onselect="">
<?php
@ -2193,7 +2193,7 @@
<input type="checkbox" name="ignore_url_check" id="ignore_url_check"/>忽略URL重复
</label>
<div class="clearfix"></div>
<?php if (in_array($this->config->item('site_code'), array('ch', 'cht', 'gm', 'ah', 'ct'))) { ?>
<?php if (in_array($this->config->item('site_code'), array('ch', 'cht', 'gm', 'ah', 'ct','chinatravel'))) { ?>
<label class="checkbox col-xs-24" style="font-weight: normal;margin-top:0;padding-left: 21px;">
<input type="checkbox" name="auto_update_cache_checkbox" id="auto_update_cache_checkbox"
onclick="get_update_cache_url();" value="<?php echo $information->ic_url; ?>"/>静态更新

Loading…
Cancel
Save