From 594d91c265a9644559c82d2488b0ee02be3dfc41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Thu, 21 Jun 2018 10:07:36 +0800 Subject: [PATCH] =?UTF-8?q?amp=E8=87=AA=E5=8A=A8=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=90=84=E7=AB=99=E9=80=9A=E7=94=A8=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/amp.php | 27 ++++++++++++++++--- .../htmlcompressor/controllers/index.php | 3 ++- .../htmlcompressor/views/welcome.php | 12 ++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/application/controllers/amp.php b/application/controllers/amp.php index 76929d6d..de54b267 100644 --- a/application/controllers/amp.php +++ b/application/controllers/amp.php @@ -42,11 +42,30 @@ class Amp extends CI_Controller echo json_encode(array('result' => 'no', 'data' => '找不到这个页面')); } //获取网页当前源码,然后发送到信息平台 - $html_source = GET_HTTP($this->config->item('site_url').'/index.php/information/detail/?no_cache=true&static_html_url='. $data['information']->ic_url); + $html_source = GET_HTTP($this->config->item('site_url') . '/index.php/information/detail/?no_cache=true&static_html_url=' . $data['information']->ic_url); if (!empty($html_source)) { - $post_data = array('websitehost' => 'https://data.asiahighlights.com', 'create_amp' => 'true', 'htmlsource' => $html_source); - echo GET_HTTP(site_url('/apps/htmlcompressor/index/optimize'), $post_data, 'POST'); - return; + //websitehost是表示资源下载的域名,在网页代码中有/css/xxx.css之类的路径,程序需要添加域名组成完整URL去下载文件,一般是data域名或者www域名 + $site_code = strtolower($this->config->item('site_code')); + switch ($site_code) { + case 'ah': + $websitehost = 'https://data.asiahighlights.com'; + break; + case 'cht': + $websitehost = 'https://data.chinahighlights.com'; + break; + case 'gm': + $websitehost = 'https://data.chinarundreisen.com'; + break; + case 'ct': + $websitehost = 'https://data.chinatravel.com'; + break; + default: + $websitehost = $this->config->item('site_url'); + } + + $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' => '不知道哪里错了,看代码')); } diff --git a/application/third_party/htmlcompressor/controllers/index.php b/application/third_party/htmlcompressor/controllers/index.php index 45a7f716..688e98b2 100644 --- a/application/third_party/htmlcompressor/controllers/index.php +++ b/application/third_party/htmlcompressor/controllers/index.php @@ -20,6 +20,7 @@ class Index extends CI_Controller { $htmlsource = $this->input->post('htmlsource'); $websitehost = $this->input->post('websitehost'); + $template_name = $this->input->post('template_name'); $create_amp = $this->input->post('create_amp'); if (empty($htmlsource) || empty($websitehost)) { $this->output->set_status_header(500); @@ -138,7 +139,7 @@ class Index extends CI_Controller //只返回AMP代码 if (!empty($create_amp)) { - $amp = $this->create_amp($html_object, 'ah', $websitehost); + $amp = $this->create_amp($html_object, $template_name, $websitehost); echo json_encode(array('result' => 'ok', 'data' => array('amp' => $amp))); return; } diff --git a/application/third_party/htmlcompressor/views/welcome.php b/application/third_party/htmlcompressor/views/welcome.php index 21f40ffe..3a49b12e 100644 --- a/application/third_party/htmlcompressor/views/welcome.php +++ b/application/third_party/htmlcompressor/views/welcome.php @@ -14,8 +14,18 @@

页面样式精简



+ +

-

+ + +