Merge branch 'AMP编辑器'

hotfix/远程访问多媒体中心
尹诚诚 8 years ago
commit 179e1172be

@ -0,0 +1,62 @@
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Amp extends CI_Controller {
function __construct() {
parent::__construct();
$this->permission->is_admin();
//$this->output->enable_profiler(TRUE);
$this->load->model('Information_model');
$this->load->model('InfoMetas_model');
}
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) {
$data = array();
$data['information'] = $this->Information_model->detail_by_ic_id($ic_id);
if ($data['information'] == FALSE) {
show_404();
}
$this->load->view('bootstrap3/header', $data);
$this->load->view('amp_editor');
$this->load->view('bootstrap3/footer');
}
public function edit_save() {
$data = array();
$ic_id = $this->input->post('ic_id');
$textarea_htmlcode = $this->input->post('textarea_htmlcode');
$amp_status = $this->input->post('amp_status');
$data['information'] = $this->Information_model->detail_by_ic_id($ic_id);
if ($data['information'] == FALSE) {
show_404();
}
$amp = $this->InfoMetas_model->get($ic_id, 'AMP');
if ($amp === false) {
$this->InfoMetas_model->add($ic_id, 'AMP', $textarea_htmlcode);
} else {
$this->InfoMetas_model->update($ic_id, 'AMP', $textarea_htmlcode);
}
$amp_status_value = $this->InfoMetas_model->get($ic_id, 'AMP_STATUS');
if ($amp_status_value === false) {
$this->InfoMetas_model->add($ic_id, 'AMP_STATUS', $amp_status);
} else {
$this->InfoMetas_model->update($ic_id, 'AMP_STATUS', $amp_status);
}
$data[] = array('name' => 'ok', 'value' => $this->lang->line('form_info_success'));
echo json_encode($data);
}
}

@ -0,0 +1,85 @@
<style>
.preview_box {
float: left;
width:375px;
height:600px;
margin-top:8px;
}
.code_editor {
overflow: hidden;
height:600px;
margin-top:8px;
}
</style>
<div class="container-fluid">
<div class="row">
<div class="preview_box" id="iframe_box" ></div>
<div class="code_editor" id="editor"></div>
</div>
<hr/>
<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;"><?php echo get_meta($information->ic_id, 'AMP'); ?></textarea>
<input type="hidden" name="ic_id" value="<?php echo $information->ic_id; ?>" />
<div class="row">
<div class="col-sm-13" ><a href="https://validator.ampproject.org/" target="_blank">AMP代码验证</a></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>
</select>
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-primary" onclick="submit_amp_editor();">保存</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/>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/eclipse");
editor.session.setMode("ace/mode/html");
editor.setOptions({
autoScrollEditorIntoView: true,
wrap: true
});
editor.getSession().on('change', function (e) {
update_preview();
});
editor.session.setValue($('#textarea_htmlcode').html($('#textarea_htmlcode').html()).text());
function update_preview() {
//考虑做成异步操作,降低页面卡顿
var iframe = document.createElement('iframe');
iframe.setAttribute('frameBorder', '0');
iframe.setAttribute('id', 'previewIframe');
iframe.setAttribute('height', '100%');
iframe.setAttribute('width', '100%');
iframe.setAttribute('name', 'AMP Playground Output');
$('#iframe_box').html('');
$('#iframe_box').append(iframe);
var doc = iframe.contentDocument || iframe.document;
doc.open();
doc.write(editor.getValue());
doc.close();
}
function submit_amp_editor() {
$('#textarea_htmlcode').text(editor.getValue()).html();
submitForm('form_amp_code');
}
</script>

@ -541,6 +541,13 @@
<?php } ?> <?php } ?>
</label> </label>
</div> </div>
<div class="col-xs-17 text-right">
<?php if(get_meta($information->ic_id, 'AMP_STATUS') === '1'){ ?>
<label title="AMP页面编辑"><a href="<?php echo site_url('amp/edit/'.$information->ic_id); ?>" target="_blank"><i class="glyphicon glyphicon-flash"></i></a></label>
<?php }else{ ?>
<label title="创建AMP页面"><a href="<?php echo site_url('amp/edit/'.$information->ic_id); ?>" target="_blank"><i class="glyphicon glyphicon-plus"></i></a></label>
<?php } ?>
</div>
<div class="col-xs-24"> <div class="col-xs-24">
<input class="form-control" type="text" id="ic_title" style="<?php if ($embody == 1) echo 'border-color:green;'; ?>" name="ic_title" value="<?php echo $information->ic_title; ?>" > <input class="form-control" type="text" id="ic_title" style="<?php if ($embody == 1) echo 'border-color:green;'; ?>" name="ic_title" value="<?php echo $information->ic_title; ?>" >
</div> </div>

Loading…
Cancel
Save