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