diff --git a/application/controllers/amp.php b/application/controllers/amp.php index e24c449a..76929d6d 100644 --- a/application/controllers/amp.php +++ b/application/controllers/amp.php @@ -1,11 +1,12 @@ permission->is_admin(); //$this->output->enable_profiler(TRUE); @@ -13,14 +14,16 @@ class Amp extends CI_Controller { $this->load->model('InfoMetas_model'); } - public function index() { + public function index() + { $data = array(); $this->load->view('bootstrap3/header', $data); $this->load->view('amp_editor'); $this->load->view('bootstrap3/footer'); } - public function edit($ic_id) { + public function edit($ic_id) + { $data = array(); $data['information'] = $this->Information_model->detail_by_ic_id($ic_id); if ($data['information'] == FALSE) { @@ -31,7 +34,25 @@ class Amp extends CI_Controller { $this->load->view('bootstrap3/footer'); } - public function edit_save() { + 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' => '找不到这个页面')); + } + //获取网页当前源码,然后发送到信息平台 + $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; + } + echo json_encode(array('result' => 'no', 'data' => '不知道哪里错了,看代码')); + } + + public function edit_save() + { $data = array(); $ic_id = $this->input->post('ic_id'); $textarea_htmlcode = $this->input->post('textarea_htmlcode'); diff --git a/application/third_party/htmlcompressor/controllers/index.php b/application/third_party/htmlcompressor/controllers/index.php index 31545ad3..45a7f716 100644 --- a/application/third_party/htmlcompressor/controllers/index.php +++ b/application/third_party/htmlcompressor/controllers/index.php @@ -136,11 +136,13 @@ class Index extends CI_Controller $html_object = str_replace('', $lastload_js . '', $html_object); } - $amp = ''; + //只返回AMP代码 if (!empty($create_amp)) { - $amp = $this->create_amp($html_object, 'ah',$websitehost); + $amp = $this->create_amp($html_object, 'ah', $websitehost); + echo json_encode(array('result' => 'ok', 'data' => array('amp' => $amp))); + return; } - echo json_encode(array('result' => 'ok', 'data' => array('html_object' => $html_object, 'js_content' => $js_content, 'amp' => $amp))); + echo json_encode(array('result' => 'ok', 'data' => array('html_object' => $html_object, 'js_content' => $js_content))); } @@ -174,12 +176,12 @@ class Index extends CI_Controller 要求: 图片文件必须带有域名,否则的获取尺寸会出错,如 https://data.asiahighlights.com/pic/abc.jpg */ //$htmlsource 移动端版本的HTML对象 $cache_path AMP文件保存路径 - function create_amp($htmlsource, $site_code,$websitehost) + function create_amp($htmlsource, $site_code, $websitehost) { $html_object = str_get_html($htmlsource); //读取站点的AMP模板 - $amp_template = $this->load->view('amp-template/' . $site_code,null, true); + $amp_template = $this->load->view('amp-template/' . $site_code, null, true); //生成移动版本,删除多余元素 @@ -229,19 +231,19 @@ class Index extends CI_Controller //格式化图片URL foreach ($html_object->find('img') as $image) { - if(!empty($image->src)){ - $img_src_host = parse_url($image->src,PHP_URL_HOST); - if(empty($img_src_host)){ - $img_src_host=$websitehost; + if (!empty($image->src)) { + $img_src_host = parse_url($image->src, PHP_URL_HOST); + if (empty($img_src_host)) { + $img_src_host = $websitehost; } - $image->src= $this->format_url($image->src,$img_src_host); + $image->src = $this->format_url($image->src, $img_src_host); } if (!empty($image->originalsrc)) { - $img_src_host = parse_url($image->src,PHP_URL_HOST); - if(empty($img_src_host)){ - $img_src_host=$websitehost; + $img_src_host = parse_url($image->src, PHP_URL_HOST); + if (empty($img_src_host)) { + $img_src_host = $websitehost; } - $image->originalsrc = $this->format_url($image->originalsrc,$img_src_host); + $image->originalsrc = $this->format_url($image->originalsrc, $img_src_host); } } diff --git a/application/third_party/htmlcompressor/views/amp-template/ah.php b/application/third_party/htmlcompressor/views/amp-template/ah.php index b6405764..cda6647e 100644 --- a/application/third_party/htmlcompressor/views/amp-template/ah.php +++ b/application/third_party/htmlcompressor/views/amp-template/ah.php @@ -17,7 +17,7 @@
-
+

- +
- +
- - + +
- 看看 + 看看 +
+
+
-