diff --git a/application/controllers/amp.php b/application/controllers/amp.php index 2895f5fa..652e5f48 100644 --- a/application/controllers/amp.php +++ b/application/controllers/amp.php @@ -1,12 +1,11 @@ permission->is_admin(); //$this->output->enable_profiler(TRUE); @@ -14,16 +13,14 @@ 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) { @@ -34,8 +31,7 @@ class Amp extends CI_Controller $this->load->view('bootstrap3/footer'); } - public function auto_create($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) { @@ -43,7 +39,6 @@ class Amp extends CI_Controller } //144.76.185.44:8029 - //根据站点不同,配置不同参数 $site_code = strtolower($this->config->item('site_code')); switch ($site_code) { @@ -79,8 +74,7 @@ class Amp extends CI_Controller echo json_encode(array('result' => 'no', 'data' => '不知道哪里错了,看代码')); } - public function edit_save() - { + public function edit_save() { $data = array(); $ic_id = $this->input->post('ic_id'); $textarea_htmlcode = $this->input->post('textarea_htmlcode'); @@ -92,8 +86,20 @@ class Amp extends CI_Controller } //CH的页面没有canonical内容,在这里帮补上 - $textarea_htmlcode=str_replace('',$this->config->item('site_url'). $data['information']->ic_url, $textarea_htmlcode); + $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); diff --git a/application/views/amp_editor.php b/application/views/amp_editor.php index 6fc138c9..1f6d2db4 100644 --- a/application/views/amp_editor.php +++ b/application/views/amp_editor.php @@ -18,7 +18,9 @@
+