AH版自动转换AMP功能上线

hotfix/远程访问多媒体中心
尹诚诚 7 years ago
parent 93022f655d
commit c2773f842b

@ -1,11 +1,12 @@
<?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();
$this->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');

@ -136,11 +136,13 @@ class Index extends CI_Controller
$html_object = str_replace('</body>', $lastload_js . '</body>', $html_object);
}
$amp = '';
//只返回AMP代码
if (!empty($create_amp)) {
$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)));
}

File diff suppressed because one or more lines are too long

@ -5,6 +5,7 @@
height: 600px;
margin-top: 8px;
}
.code_editor {
overflow: hidden;
height: 600px;
@ -23,25 +24,41 @@
<input type="hidden" name="ic_id" value="<?php echo $information->ic_id; ?>"/>
<div class="row">
<div class="col-sm-13" >
<div class="col-sm-10">
<a href="http://ampvalidator.mycht.cn/" target="_blank">AMP代码验证</a>
|
<a href="https://uncss-online.com/" target="_blank">CSS精简</a>
|
<a href="http://tool.oschina.net/jscompress" target="_blank">CSS压缩</a>
|
<a href="http://tool.oschina.net/codeformat/css" target="_blank">CSS格式化</a>
</div>
<div class="col-sm-3">
<button type="button" class="btn btn-info" onclick="auto_create_amp(this);">
自动转换
</button>
</div>
<div class="col-sm-3">
<select name="amp_status" id="amp_status" class="form-control">
<option value="0" <?php echo get_meta($information->ic_id, 'AMP_STATUS') === '0' ? 'selected' : FALSE; ?> >不发布</option>
<option value="1" <?php echo get_meta($information->ic_id, 'AMP_STATUS') === '1' ? 'selected' : FALSE; ?> >发布</option>
<option value="0" <?php echo get_meta($information->ic_id, 'AMP_STATUS') === '0' ? 'selected' : FALSE; ?> >
不发布
</option>
<option value="1" <?php echo get_meta($information->ic_id, 'AMP_STATUS') === '1' ? 'selected' : FALSE; ?> >
发布
</option>
</select>
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-primary" onclick="submit_amp_editor();">保存</button>
<a href="http://192.155.224.195:8080/guide-use.php/amp_loader/test/?info_url=<?php echo $information->ic_url ?>" target="_blank">看看</a>
<a href="http://192.155.224.195:8080/guide-use.php/amp_loader/test/?info_url=<?php echo $information->ic_url ?>"
target="_blank">看看</a>
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-default"
onclick="meta('delete', '<?php echo $information->ic_id; ?>', 'AMP', ''); meta('delete', '<?php echo $information->ic_id; ?>', 'AMP_STATUS', '');">
删除
</button>
</div>
<div class="col-sm-4"> <button type="button" class="btn btn-default" onclick="meta('delete', '<?php echo $information->ic_id; ?>', 'AMP', ''); meta('delete', '<?php echo $information->ic_id; ?>', 'AMP_STATUS', '');">删除</button> </div>
</div>
</form>
<hr/>
@ -88,6 +105,19 @@
$('#textarea_htmlcode').text(editor.getValue()).html();
submitForm('form_amp_code');
}
function auto_create_amp(obj) {
$(obj).text('转换中...');
$(obj).enable(false);
$.getJSON("<?php echo site_url('amp/auto_create/' . $information->ic_id) ?>", function (result) {
$.each(result, function (i, field) {
if (i == 'data') {
editor.setValue(field.amp);
}
});
});
}
</script>

Loading…
Cancel
Save