添加AMP语法检测功能

hotfix/远程访问多媒体中心
尹诚诚 7 years ago
parent c1ee3e1e60
commit e6fb20bc14

@ -1,12 +1,11 @@
<?php <?php
if (!defined('BASEPATH')) exit('No direct script access allowed'); if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Amp extends CI_Controller class Amp extends CI_Controller {
{
function __construct() function __construct() {
{
parent::__construct(); parent::__construct();
$this->permission->is_admin(); $this->permission->is_admin();
//$this->output->enable_profiler(TRUE); //$this->output->enable_profiler(TRUE);
@ -14,16 +13,14 @@ class Amp extends CI_Controller
$this->load->model('InfoMetas_model'); $this->load->model('InfoMetas_model');
} }
public function index() public function index() {
{
$data = array(); $data = array();
$this->load->view('bootstrap3/header', $data); $this->load->view('bootstrap3/header', $data);
$this->load->view('amp_editor'); $this->load->view('amp_editor');
$this->load->view('bootstrap3/footer'); $this->load->view('bootstrap3/footer');
} }
public function edit($ic_id) public function edit($ic_id) {
{
$data = array(); $data = array();
$data['information'] = $this->Information_model->detail_by_ic_id($ic_id); $data['information'] = $this->Information_model->detail_by_ic_id($ic_id);
if ($data['information'] == FALSE) { if ($data['information'] == FALSE) {
@ -34,8 +31,7 @@ class Amp extends CI_Controller
$this->load->view('bootstrap3/footer'); $this->load->view('bootstrap3/footer');
} }
public function auto_create($ic_id) public function auto_create($ic_id) {
{
$data = array(); $data = array();
$data['information'] = $this->Information_model->detail_by_ic_id($ic_id); $data['information'] = $this->Information_model->detail_by_ic_id($ic_id);
if ($data['information'] == FALSE) { if ($data['information'] == FALSE) {
@ -43,7 +39,6 @@ class Amp extends CI_Controller
} }
//144.76.185.44:8029 //144.76.185.44:8029
//根据站点不同,配置不同参数 //根据站点不同,配置不同参数
$site_code = strtolower($this->config->item('site_code')); $site_code = strtolower($this->config->item('site_code'));
switch ($site_code) { switch ($site_code) {
@ -79,8 +74,7 @@ class Amp extends CI_Controller
echo json_encode(array('result' => 'no', 'data' => '不知道哪里错了,看代码')); echo json_encode(array('result' => 'no', 'data' => '不知道哪里错了,看代码'));
} }
public function edit_save() public function edit_save() {
{
$data = array(); $data = array();
$ic_id = $this->input->post('ic_id'); $ic_id = $this->input->post('ic_id');
$textarea_htmlcode = $this->input->post('textarea_htmlcode'); $textarea_htmlcode = $this->input->post('textarea_htmlcode');
@ -94,6 +88,18 @@ class Amp extends CI_Controller
//CH的页面没有canonical内容在这里帮补上 //CH的页面没有canonical内容在这里帮补上
$textarea_htmlcode = str_replace('<!--@CANONICAL@-->', $this->config->item('site_url') . $data['information']->ic_url, $textarea_htmlcode); $textarea_htmlcode = str_replace('<!--@CANONICAL@-->', $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'); $amp = $this->InfoMetas_model->get($ic_id, 'AMP');
if ($amp === false) { if ($amp === false) {
$this->InfoMetas_model->add($ic_id, 'AMP', $textarea_htmlcode); $this->InfoMetas_model->add($ic_id, 'AMP', $textarea_htmlcode);

@ -18,7 +18,9 @@
<div class="preview_box" id="iframe_box"></div> <div class="preview_box" id="iframe_box"></div>
<div class="code_editor" id="editor"></div> <div class="code_editor" id="editor"></div>
</div> </div>
<hr/> <hr/>
<form name="form_amp_code" id="form_amp_code" method="post" action="<?php echo site_url('amp/edit_save') ?>"> <form name="form_amp_code" id="form_amp_code" method="post" action="<?php echo site_url('amp/edit_save') ?>">
<textarea id="textarea_htmlcode" name="textarea_htmlcode" style="display: none;"></textarea> <textarea id="textarea_htmlcode" name="textarea_htmlcode" style="display: none;"></textarea>
<input type="hidden" name="ic_id" value="<?php echo $information->ic_id; ?>"/> <input type="hidden" name="ic_id" value="<?php echo $information->ic_id; ?>"/>
@ -65,6 +67,9 @@
</div> </div>
</div> </div>
</form> </form>
<div id="amp_error">
</div>
<hr/> <hr/>
</div> </div>
@ -106,8 +111,28 @@
} }
function submit_amp_editor() { function submit_amp_editor() {
$('#amp_error').html('');
$('#textarea_htmlcode').text(editor.getValue()).html(); $('#textarea_htmlcode').text(editor.getValue()).html();
submitForm('form_amp_code'); $("#form_amp_code").ajaxSubmit({
success: function (responseText, statusText, xhr, form) {
if (responseText.name === 'no') {
error_msg='<h3>AMP validation FAIL</h3>';
$.each(responseText.value, function (index, element) {
error_msg=error_msg+'<p>line '+element.line+' col '+element.col+' :'+element.message+'</p>';
});
$.modaldialog.error('AMP语法错误请看下方错误详情');
$('#amp_error').html(error_msg);
} else {
$.modaldialog.success(responseText.value);
}
},
error: function (responseText, statusText, xhr, form) {
$.modaldialog.error("Action unsuccessful. Try again later.");
},
dataType: "json",
timeout: 30000
});
return false
} }
function auto_create_amp(obj) { function auto_create_amp(obj) {

@ -42,7 +42,7 @@
<li><a href="<?php echo site_url('sendmail') ?>" >订单邮件管理</a> </li> <li><a href="<?php echo site_url('sendmail') ?>" >订单邮件管理</a> </li>
<li><a href="http://share.chtcdn.com/info.php/infoshare/" target="_blank" >信息分享平台</a> </li> <li><a href="http://share.chtcdn.com/info.php/infoshare/" target="_blank" >信息分享平台</a> </li>
<li><a href="<?php echo site_url('welcome/create_all_urls') ?>" target="_blank" >全站静态化更新</a> </li> <li><a href="<?php echo site_url('welcome/create_all_urls') ?>" target="_blank" >全站静态化更新</a> </li>
<li><a href="<?php echo site_url('welcome/create_all_urls/amp') ?>" target="_blank" >全站AMP更新</a> </li> <!--<li><a href="<?php echo site_url('welcome/create_all_urls/amp') ?>" target="_blank" >全站AMP更新</a> </li>-->
<li class="divider"></li> <li class="divider"></li>

Loading…
Cancel
Save