diff --git a/application/controllers/amp.php b/application/controllers/amp.php
index d830960d..55dd1aef 100644
--- a/application/controllers/amp.php
+++ b/application/controllers/amp.php
@@ -11,6 +11,7 @@ class Amp extends CI_Controller {
//$this->output->enable_profiler(TRUE);
$this->load->model('Information_model');
$this->load->model('InfoMetas_model');
+ $this->load->library('Amplib');
}
public function index() {
@@ -20,101 +21,15 @@ class Amp extends CI_Controller {
}
public function edit($ic_id) {
- $data = array();
- $data['information'] = $this->Information_model->detail_by_ic_id($ic_id);
- if ($data['information'] == FALSE) {
- show_404();
- }
- $this->load->view('bootstrap3/header', $data);
- $this->load->view('amp_editor');
- $this->load->view('bootstrap3/footer');
+ $this->amplib->edit($ic_id);
}
public function auto_create($ic_id) {
- $data = array();
- $data['information'] = $this->Information_model->detail_by_ic_id($ic_id);
- if ($data['information'] == FALSE) {
- echo json_encode(array('result' => 'no', 'data' => '找不到这个页面'));
- }
-
- //144.76.185.44:8029
- //根据站点不同,配置不同参数
- $site_code = strtolower($this->config->item('site_code'));
- switch ($site_code) {
- case 'ah':
- //websitehost是表示资源下载的域名,在网页代码中有/css/xxx.css之类的路径,程序需要添加域名组成完整URL去下载文件,一般是data域名或者www域名
- $websitehost = 'https://data.asiahighlights.com';
- $html_source_url = 'https://www.asiahighlights.com/index.php/information/detail/?no_cache=true&static_html_url=' . $data['information']->ic_url;
- break;
- case 'cht':
- $websitehost = 'https://data.chinahighlights.com';
- $html_source_url = 'http://192.155.224.195:2222' . $data['information']->ic_url;
- break;
- case 'gm':
- $websitehost = 'https://data.chinarundreisen.com';
- $html_source_url = 'http://144.76.185.44:8029' . $data['information']->ic_url;
- break;
- case 'ct':
- $websitehost = 'https://data.chinatravel.com';
- $html_source_url = 'http://158.85.210.78:2222' . $data['information']->ic_url;
- break;
- default:
- $websitehost = $this->config->item('site_url');
- $html_source_url = $this->config->item('site_url') . $data['information']->ic_url;
- }
-
- //获取网页当前源码,然后发送到信息平台
- $html_source = GET_HTTP($html_source_url);
- if (!empty($html_source)) {
- $post_data = array('websitehost' => $websitehost, 'template_name' => $site_code, 'create_amp' => 'true', 'htmlsource' => $html_source);
- echo GET_HTTP(site_url('/apps/htmlcompressor/index/optimize'), $post_data, 'POST');
- return;
- }
- echo json_encode(array('result' => 'no', 'data' => '不知道哪里错了,看代码'));
+ echo $this->amplib->auto_create($ic_id);
}
public function edit_save() {
- $data = array();
- $ic_id = $this->input->post('ic_id');
- $textarea_htmlcode = $this->input->post('textarea_htmlcode');
- $amp_status = $this->input->post('amp_status');
- $data['information'] = $this->Information_model->detail_by_ic_id($ic_id);
-
- if ($data['information'] == FALSE) {
- show_404();
- }
-
- //CH的页面没有canonical内容,在这里帮补上
- $textarea_htmlcode = str_replace('', $this->config->item('site_url') . $data['information']->ic_url, $textarea_htmlcode);
-
- //AMP格式验证
- //把AMP网页内容到purifycss处理,内置了AMP-Validator
- $purifycss_server = 'http://184.172.113.216:33033/';
- if ($this->config->item('site_code' == 'gm')) {//德语站点使用自己的css处理服务器
- $purifycss_server = 'http://158.177.67.52:33033/';
- }
- $validator_result = GET_HTTP($purifycss_server, 'amp_source=' . urlencode($textarea_htmlcode), 'POST');
- $validator_result = json_decode($validator_result);
- if ($validator_result->status == 'FAIL') {
- echo json_encode(array('name' => 'no', 'value' => $validator_result->errors));
- return;
- }
- $amp = $this->InfoMetas_model->get($ic_id, 'AMP');
- if ($amp === false) {
- $this->InfoMetas_model->add($ic_id, 'AMP', $textarea_htmlcode);
- } else {
- $this->InfoMetas_model->update($ic_id, 'AMP', $textarea_htmlcode);
- }
-
- $amp_status_value = $this->InfoMetas_model->get($ic_id, 'AMP_STATUS');
- if ($amp_status_value === false) {
- $this->InfoMetas_model->add($ic_id, 'AMP_STATUS', $amp_status);
- } else {
- $this->InfoMetas_model->update($ic_id, 'AMP_STATUS', $amp_status);
- }
-
- $data[] = array('name' => 'ok', 'value' => $this->lang->line('form_info_success'));
- echo json_encode($data);
+ echo $this->amplib->edit_save();
}
}
diff --git a/application/controllers/information.php b/application/controllers/information.php
index 80cc0f5b..4e3fd961 100644
--- a/application/controllers/information.php
+++ b/application/controllers/information.php
@@ -18,13 +18,8 @@ class Information extends CI_Controller {
$this->load->model('Logs_model');
$this->load->model('InfoMetas_model');
$this->load->model('Infoauthors_model');
- $this->load->model('InfoKeywordsanalytics_model', 'analytics_model');
$this->load->model('InfoSMS_model');
-
- if (is_series_site()) {
- //$this->load->model('InfoTags_model');
- }
-
+ $this->load->library('Amplib'); //加载AMP处理类
$this->load->library('Accesscheck');
$this->accesscheck->check_access();
}
@@ -196,10 +191,10 @@ class Information extends CI_Controller {
if (in_array($this->config->item('site_code'), array('cht'))) {
$this->config->set_item('templates', $this->config->item('templates_cht'));
}
- if (in_array($this->config->item('site_code'), array('gm'))) {
+ if (in_array($this->config->item('site_code'), array('gm'))) {
$this->config->set_item('templates', $this->config->item('templates_gm'));
}
-
+
//信息区域类型
switch ($data['rootInformation']->ic_ht_area_type) {
@@ -280,12 +275,9 @@ class Information extends CI_Controller {
//$this->InfoTags_model->ic_id = $data['information']->ic_id;
//$data['my_tags'] = $this->InfoTags_model->list_tag();
//差集
- foreach ($data['all_tags'] as &$it)
- {
- foreach ($data['my_tags'] as $it2)
- {
- if ($it->it_id == $it2->icit_it_id)
- {
+ foreach ($data['all_tags'] as &$it) {
+ foreach ($data['my_tags'] as $it2) {
+ if ($it->it_id == $it2->icit_it_id) {
$it = null;
break;
}
@@ -396,26 +388,31 @@ class Information extends CI_Controller {
} else {
$this->InfoContents_model->Update($information->is_ic_id, $this->input->post('ic_url'), $this->input->post('ic_url_title'), $this->input->post('ic_type'), $this->input->post('ic_title'), $this->input->post('ic_content'), $this->input->post('ic_summary'), $this->input->post('ic_seo_title'), $this->input->post('ic_seo_description'), $this->input->post('ic_seo_keywords'), $this->input->post('ic_show_bread_crumbs'), $this->input->post('ic_status'), $this->input->post('ic_template'), $this->input->post('ic_photo'), $this->input->post('ic_photo_width'), $this->input->post('ic_photo_height'), $this->input->post('ic_recommend_tours'), $this->input->post('ic_recommend_packages'), $this->input->post('ic_ht_area_id'), $this->input->post('ic_ht_area_type'), $this->input->post('ic_ht_product_id'), $this->input->post('ic_ht_product_type'), $this->input->post('ic_author'));
- //收录查询,只在发布上线并且url不为空的时候检查
- $embody_url = $this->input->post('ic_url');
- $embody_url = trim($embody_url);
- if ($this->input->post('ic_status') == 1 && $embody_url != '') {
- $embody = $this->InfoMetas_model->get($information->is_ic_id, 'meta_embody');
- if (empty($embody)) {
- $times = date('Y-m-d H:i:s');
- $this->InfoMetas_model->add($information->is_ic_id, 'meta_embody', $times);
+ //AMP更新和生成 beign
+ $auto_update_amp = $this->input->get_post('auto_update_amp');
+ if (!empty($auto_update_amp) && $auto_update_amp == 'true' && $this->input->post('ic_status') == 1) {
+ $amp_result=$this->amplib->auto_create($information->ic_id);
+ if (!empty($amp_result)) {
+ $amp_result = json_decode($amp_result);
+ if($amp_result->result=='ok'){
+ $amp_save_result= $this->amplib->edit_save($information->ic_id,$amp_result->data->amp,'1');
+ if(!empty($amp_save_result)){
+ $amp_save_result = json_decode($amp_save_result);
+ if($amp_save_result->name=='no'){
+ echo json_encode(array('name' => 'no', 'value' => 'AMP转换语法错误,请重新进入AMP编辑器检查'));
+ return;
+ }
+ }
+ }
}
}
-
+ //AMP更新和生成 end
//为新闻添加默认发布时间
- //if($information->ic_ht_area_type=='s' || $information->ic_type=='c_article')
- //{
$meta_news_createdate = get_meta($information->ic_id, 'meta_news_createdate');
if (empty($meta_news_createdate)) {
add_meta($information->ic_id, 'meta_news_createdate', date('m/d/Y', time()));
}
- //}
- // if (is_series_site()) {
+
//如果URL有修改也删除静态文件
if ($this->input->post('ic_url') != $information->ic_url) {
$this->update_cache($information->ic_url, true);
@@ -426,11 +423,11 @@ class Information extends CI_Controller {
$this->update_cache($this->input->post('ic_url'), true);
}
-
//德语站FAQ版块需要删除原来的文件才能更新静态
$site_code = $this->config->item('site_code');
$ic_url = $this->input->post('ic_url');
$auto_update_cache = $this->input->get_post('auto_update_cache_checkbox');
+
if (strcasecmp($site_code, "gm") == 0 && !empty($auto_update_cache)) {
$update_info_log = $this->update_cache($ic_url, true);
} else if (strcasecmp($site_code, "cht") == 0 && !empty($auto_update_cache)) {
@@ -535,8 +532,8 @@ class Information extends CI_Controller {
if ($delete_only) {
$url = "http://144.76.185.44:8029/gm.php/information/delete_cache_23Xd913mddkgssODII?static_html_url=" . urlencode($url);
} else {
- //先删除再生成,部分页面没有在信息平台中
- GET_HTTP("http://144.76.185.44:8029/gm.php/information/delete_cache_23Xd913mddkgssODII?static_html_url=" . urlencode($url));
+ //先删除再生成,部分页面没有在信息平台中
+ GET_HTTP("http://144.76.185.44:8029/gm.php/information/delete_cache_23Xd913mddkgssODII?static_html_url=" . urlencode($url));
$url = "http://144.76.185.44:8029" . $url;
}
break;
@@ -553,7 +550,7 @@ class Information extends CI_Controller {
$information = $this->Information_model->Detail($url);
$tmp = $url;
//判断是否是更新信息
- // 产品页面不能生成静态页面,比如/beijing/hotel/只是为了在导航显示一个链接,如果生成了静态页面,网前只会显示一个空白页面了
+ // 产品页面不能生成静态页面,比如/beijing/hotel/只是为了在导航显示一个链接,如果生成了静态页面,网前只会显示一个空白页面了
if (!empty($information->ic_content)) {
$url = $this->config->item('site_url') . '/index.php/information/detail/?static_html_url=' . $url;
} else {
@@ -579,10 +576,6 @@ class Information extends CI_Controller {
break;
}
- //关闭错误提示,防止file_get_contents请求特殊字符的时候会报错或者404、500,特殊字符需要用urlencode编码第一个/后面的url
- //error_reporting(NULL);
- //ini_set('display_errors', 'Off');
-
$content = GET_HTTP($url);
if ($content === false) {
$data[] = array('name' => 'no', 'value' => sprintf($this->lang->line('update_cache_failed'), $url));
@@ -593,9 +586,9 @@ class Information extends CI_Controller {
if ($this->input->post('updatecdn') == 1) {
$notice = $this->update_cdn();
if ($notice == 200) {
- $msg.=$this->lang->line('update_cdn_success');
+ $msg .= $this->lang->line('update_cdn_success');
} else {
- $msg.=$this->lang->line('update_cdn_failed') . '
' . $notice;
+ $msg .= $this->lang->line('update_cdn_failed') . '
' . $notice;
}
}
$data[] = array('name' => 'ok', 'value' => $msg, 'url' => $url);
@@ -672,40 +665,6 @@ class Information extends CI_Controller {
$this->load->view('bootstrap/footer');
}
- //增加新景点到景点概述下
- //先找到当前城市的景点概述根节点,然后新增加
- //$lsi_sn 翰特景点id
- function add_landscape($area_id, $lsi_sn) {
- //获取景点概述节点
- $root_landscape = $this->Information_model->get_type_detail('c_attraction', 'c', $area_id);
-
- if ($root_landscape == FALSE) {
- $data[] = array('name' => 'no', 'value' => $this->lang->line('root_landscape_notfound'));
- echo json_encode($data);
- return false;
- }
-
- //获取景点详细内容
- $Landscape = $this->Landscape_model->get_detail($lsi_sn);
- if ($root_landscape == FALSE) {
- $data[] = array('name' => 'no', 'value' => $this->lang->line('landscape_notfound'));
- echo json_encode($data);
- return false;
- }
-
-
- //添加空内容
- $this->InfoContents_model->Add($Landscape->LSI2_Name, $Landscape->LSI2_Name, '', $Landscape->LSI2_Name, $Landscape->LSI2_ShortIntro, '', '', '', '', 0, 0, '', '', 0, 0, '', '', $area_id, 'c', $lsi_sn, 't', '');
- if ($this->InfoStructures_model->Add($root_landscape->is_id, $this->InfoContents_model->insert_id)) {
- $data[] = array('name' => 'ok', 'value' => site_url('information/edit/' . $this->InfoStructures_model->insert_id));
- } else {
- $data[] = array('name' => 'no', 'value' => $this->lang->line('form_info_error'));
- }
- echo json_encode($data);
- $this->Logs_model->add($this->InfoStructures_model->insert_id);
- return true;
- }
-
//保存自定义配置
function save_meta() {
$im_ic_id = $this->input->post('im_ic_id');
diff --git a/application/libraries/Amplib.php b/application/libraries/Amplib.php
new file mode 100644
index 00000000..5630d27b
--- /dev/null
+++ b/application/libraries/Amplib.php
@@ -0,0 +1,122 @@
+CI = & get_instance();
+ $this->CI->load->model('Information_model');
+ $this->CI->load->model('InfoMetas_model');
+ }
+
+ public function edit($ic_id) {
+ $data = array();
+ $data['information'] = $this->CI->Information_model->detail_by_ic_id($ic_id);
+ if ($data['information'] == FALSE) {
+ show_404();
+ }
+ $this->CI->load->view('bootstrap3/header', $data);
+ $this->CI->load->view('amp_editor');
+ $this->CI->load->view('bootstrap3/footer');
+ }
+
+ public function auto_create($ic_id) {
+ $data = array();
+ $data['information'] = $this->CI->Information_model->detail_by_ic_id($ic_id);
+ if ($data['information'] == FALSE) {
+ return json_encode(array('result' => 'no', 'data' => '找不到这个页面'));
+ }
+
+ //144.76.185.44:8029
+ //根据站点不同,配置不同参数
+ $site_code = strtolower($this->CI->config->item('site_code'));
+ switch ($site_code) {
+ case 'ah':
+ //websitehost是表示资源下载的域名,在网页代码中有/css/xxx.css之类的路径,程序需要添加域名组成完整URL去下载文件,一般是data域名或者www域名
+ $websitehost = 'https://data.asiahighlights.com';
+ $html_source_url = 'https://www.asiahighlights.com/index.php/information/detail/?no_cache=true&static_html_url=' . $data['information']->ic_url;
+ break;
+ case 'cht':
+ $websitehost = 'https://data.chinahighlights.com';
+ $html_source_url = 'http://192.155.224.195:2222' . $data['information']->ic_url;
+ break;
+ case 'gm':
+ $websitehost = 'https://data.chinarundreisen.com';
+ $html_source_url = 'http://144.76.185.44:8029' . $data['information']->ic_url;
+ break;
+ case 'ct':
+ $websitehost = 'https://data.chinatravel.com';
+ $html_source_url = 'http://158.85.210.78:2222' . $data['information']->ic_url;
+ break;
+ default:
+ $websitehost = $this->CI->config->item('site_url');
+ $html_source_url = $this->CI->config->item('site_url') . $data['information']->ic_url;
+ }
+
+ //获取网页当前源码,然后发送到信息平台
+ $html_source = GET_HTTP($html_source_url);
+ if (!empty($html_source)) {
+ $post_data = array('websitehost' => $websitehost, 'template_name' => $site_code, 'create_amp' => 'true', 'htmlsource' => $html_source);
+ return GET_HTTP(site_url('/apps/htmlcompressor/index/optimize'), $post_data, 'POST');
+ }
+ return json_encode(array('result' => 'no', 'data' => '不知道哪里错了,看代码'));
+ }
+
+ public function edit_save($ic_id = false, $textarea_htmlcode = false, $amp_status = false) {
+ $data = array();
+ if ($ic_id === false) {
+ $ic_id = $this->CI->input->post('ic_id');
+ }
+ if ($textarea_htmlcode === false) {
+ $textarea_htmlcode = $this->CI->input->post('textarea_htmlcode');
+ }
+ if ($amp_status === false) {
+ $amp_status = $this->CI->input->post('amp_status');
+ }
+ $data['information'] = $this->CI->Information_model->detail_by_ic_id($ic_id);
+
+ if ($data['information'] == FALSE) {
+ show_404();
+ }
+
+ //CH的页面没有canonical内容,在这里帮补上
+ $textarea_htmlcode = str_replace('', $this->CI->config->item('site_url') . $data['information']->ic_url, $textarea_htmlcode);
+
+ //AMP格式验证
+ if ($amp_status !== '0') {//只有发布的时候才需要验证
+ //把AMP网页内容到purifycss处理,内置了AMP-Validator
+ $purifycss_server = 'http://184.172.113.216:33033/';
+ if ($this->CI->config->item('site_code' == 'gm')) {//德语站点使用自己的css处理服务器
+ $purifycss_server = 'http://158.177.67.52:33033/';
+ }
+ $validator_result = GET_HTTP($purifycss_server, 'amp_source=' . urlencode($textarea_htmlcode), 'POST');
+ $validator_result = json_decode($validator_result);
+ if ($validator_result->status == 'FAIL') {
+ return json_encode(array('name' => 'no', 'value' => $validator_result->errors));
+ }
+ }
+ $amp = $this->CI->InfoMetas_model->get($ic_id, 'AMP');
+ if ($amp === false) {
+ $this->CI->InfoMetas_model->add($ic_id, 'AMP', $textarea_htmlcode);
+ } else {
+ $this->CI->InfoMetas_model->update($ic_id, 'AMP', $textarea_htmlcode);
+ }
+
+ $amp_status_value = $this->CI->InfoMetas_model->get($ic_id, 'AMP_STATUS');
+ if ($amp_status_value === false) {
+ $this->CI->InfoMetas_model->add($ic_id, 'AMP_STATUS', $amp_status);
+ } else {
+ $this->CI->InfoMetas_model->update($ic_id, 'AMP_STATUS', $amp_status);
+ }
+
+ return json_encode(array('name' => 'ok', 'value' => $this->CI->lang->line('form_info_success')));
+ }
+
+}
diff --git a/application/models/information_model.php b/application/models/information_model.php
index 0b0ebade..aa164191 100644
--- a/application/models/information_model.php
+++ b/application/models/information_model.php
@@ -169,7 +169,7 @@ 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' and CONVERT(varchar, im_value) = '1'),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.="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"
diff --git a/application/views/amp_editor.php b/application/views/amp_editor.php
index 108b2a30..ade80f75 100644
--- a/application/views/amp_editor.php
+++ b/application/views/amp_editor.php
@@ -34,6 +34,8 @@
CSS压缩
|
CSS格式化
+ |
+ 调试