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);
$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);
}
}

File diff suppressed because one or more lines are too long

@ -1,54 +1,71 @@
<style>
.preview_box {
float: left;
width:375px;
height:600px;
margin-top:8px;
width: 375px;
height: 600px;
margin-top: 8px;
}
.code_editor {
overflow: hidden;
height:600px;
margin-top:8px;
height: 600px;
margin-top: 8px;
}
</style>
<div class="container-fluid">
<div class="row">
<div class="preview_box" id="iframe_box" ></div>
<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;"></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; ?>"/>
<div class="row">
<div class="col-sm-13" >
<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>
</div>
<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">
<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>
<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>
</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/>
</div>
<script type="text/x-template" id="amp_html">
<?php echo htmlentities(get_meta($information->ic_id, 'AMP')); ?>
<?php echo htmlentities(get_meta($information->ic_id, 'AMP')); ?>
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
@ -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