diff --git a/application/controllers/information.php b/application/controllers/information.php index 73acae9e..92d48090 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -423,7 +423,7 @@ class Information extends CI_Controller } else if (strcasecmp($site_code, "cht") == 0 && !empty($auto_update_cache)) { $update_info_log = $this->update_cache($ic_url); } else if (strcasecmp($site_code, "ah") == 0 && !empty($auto_update_cache)) { - $update_info_log = $this->update_cache($ic_url); + //$update_info_log = $this->update_cache($ic_url); } else if (strcasecmp($site_code, "cht") != 0 && strcasecmp($site_code, "gm") != 0 && strcasecmp($site_code, "ah") != 0) { //非cht站点并且非GM并且非AH $update_info_log = $this->update_cache($ic_url); } else if (strcasecmp($site_code, "ct") == 0 && !empty($auto_update_cache)) { @@ -649,7 +649,10 @@ class Information extends CI_Controller if (!empty($meta_addon_js)) { $template = str_replace('', '', $template); } - $template = str_replace('', $information->ic_content, $template); + //设置内容图片缓加载 + $lazy_content=$this->html_optimize_lib->set_lazy_loader($information->ic_content,'https://data.chinahighlights.com/grey.gif'); + $template = str_replace('', $lazy_content, $template); + //Google广告代码 //if (!empty(get_meta($information->ic_id, 'meta_google_ad_content'))) { $template = str_replace('', '', $template); @@ -755,7 +758,22 @@ class Information extends CI_Controller if (!empty($meta_addon_js)) { $template = str_replace('', '', $template); } - $template = str_replace('', $information->ic_content, $template); + //设置内容图片缓加载 + $lazy_content=$this->html_optimize_lib->set_lazy_loader($information->ic_content,'https://data.asiahighlights.com/grey.gif'); + $template = str_replace('', $lazy_content, $template); + + //替换内容中广告 + $temp_array=array(); + preg_match_all('^^', $template, $temp_array); + if(!empty($temp_array[1])){ + foreach ($temp_array[1] as $key=>$item){ + $tips_detail= $this->recommends_and_tips_model->tips_detail($item); + if($tips_detail){ + $template = str_replace($temp_array[0][$key], $tips_detail->it_content, $template); + } + } + } + //Google广告代码 //if (!empty(get_meta($information->ic_id, 'meta_google_ad_content'))) { $template = str_replace('', '', $template); diff --git a/application/libraries/html_optimize_lib.php b/application/libraries/html_optimize_lib.php index 4f8b51a3..7c92ec4f 100644 --- a/application/libraries/html_optimize_lib.php +++ b/application/libraries/html_optimize_lib.php @@ -20,8 +20,26 @@ class html_optimize_lib $this->CI->load->library('simple_html_dom_lib'); } +//开启了延迟加载 + public function set_lazy_loader($html, $grey_pic) + { + + $html_object = str_get_html($html); + + foreach ($html_object->find('img') as $image) { + $img_src = $image->src; + if (!empty($image->originalsrc)) { + $img_src = $image->originalsrc; + } + $image->src = $grey_pic; + $image->loader = 'lazy'; + $image->originalsrc = $img_src; + } + + return $html_object->save(); + } - //获取图片尺寸 + //获取图片尺寸,$lazy_loader是否开启延迟加载 public function set_image_size($html) { $html_object = str_get_html($html); @@ -34,9 +52,9 @@ class html_optimize_lib $img_src = $image->originalsrc; } //图片已经设置了尺寸的不再修改 - if (empty($image->width) && (strpos($img_src, '//data.') !== false || strpos($img_src, '//images.') !== false)) {//以data或者images开头的域名才能获取尺寸 + if (empty($image->width) && (strpos($img_src, '//data.') !== false || strpos($img_src, '//images.') !== false)) {//以data或者images开头的域名才能获取尺寸 $img_src_urls = parse_url(trim($img_src)); - $request_size[$img_src_urls['host']][] =$img_src_urls['path']; + $request_size[$img_src_urls['host']][] = $img_src_urls['path']; } } @@ -48,7 +66,7 @@ class html_optimize_lib if (!empty($size_data)) { $size_data = json_decode($size_data); foreach ($size_data as $size_item) { - $size_item->photo = "https://".$host . $size_item->photo;//这个作为索引,找到对应url的尺寸 + $size_item->photo = "https://" . $host . $size_item->photo;//这个作为索引,找到对应url的尺寸 $image_sizes[$size_item->photo] = $size_item; } } @@ -62,12 +80,12 @@ class html_optimize_lib $img_src = $image->originalsrc; } //图片已经设置了尺寸的不再修改 - if (empty($image->width) && (strpos($img_src, '//data.') !== false || strpos($img_src, '//images.') !== false)) {//以data或者images开头的域名才能获取尺寸 + if (empty($image->width) && (strpos($img_src, '//data.') !== false || strpos($img_src, '//images.') !== false)) {//以data或者images开头的域名才能获取尺寸 $img_src_urls = parse_url(trim($img_src)); - $img_index="https://".$img_src_urls['host'] . $img_src_urls['path']; - if(!empty($image_sizes[$img_index])){ - $image->width=$image_sizes[$img_index]->width; - $image->height=$image_sizes[$img_index]->height; + $img_index = "https://" . $img_src_urls['host'] . $img_src_urls['path']; + if (!empty($image_sizes[$img_index])) { + $image->width = $image_sizes[$img_index]->width; + $image->height = $image_sizes[$img_index]->height; } } diff --git a/application/models/recommends_and_tips_model.php b/application/models/recommends_and_tips_model.php index fd35e0b5..fd0e4a10 100644 --- a/application/models/recommends_and_tips_model.php +++ b/application/models/recommends_and_tips_model.php @@ -40,6 +40,7 @@ class recommends_and_tips_model extends CI_Model it.it_id ,it.it_title ,it.it_expires + ,it.it_code ,it.it_content ,it.it_sitecode ,it.it_datetime diff --git a/application/third_party/recommend/controllers/tips.php b/application/third_party/recommend/controllers/tips.php index 9fb699fd..dccf2cd0 100644 --- a/application/third_party/recommend/controllers/tips.php +++ b/application/third_party/recommend/controllers/tips.php @@ -27,6 +27,7 @@ class Tips extends CI_Controller $infoTip->it_title = '新广告'; $infoTip->it_expires = time(); $infoTip->it_content = ''; + $infoTip->it_code = ''; $infoTip->it_datetime = time(); $infoTip->it_sitecode = $this->config->item('site_code'); $infoTip->it_id = $this->infoTips_model->add('infoTips', $infoTip); @@ -75,6 +76,7 @@ class Tips extends CI_Controller $infoTip = new StdClass; $infoTip->it_title = $this->input->post('it_title'); $infoTip->it_expires = strtotime($this->input->post('it_expires')); + $infoTip->it_code = $this->input->post('it_code'); $infoTip->it_content = $this->input->post('it_content'); $infoTip->it_datetime = time(); $infoTip->it_id = $this->infoTips_model->update('infoTips', $infoTip, 'it_id=' . $it_id); diff --git a/application/third_party/recommend/models/infoTips_model.php b/application/third_party/recommend/models/infoTips_model.php index 67b7e637..4745e170 100644 --- a/application/third_party/recommend/models/infoTips_model.php +++ b/application/third_party/recommend/models/infoTips_model.php @@ -32,6 +32,7 @@ class infoTips_model extends CI_Model it.it_id ,it.it_title ,it.it_expires + ,it.it_code ,it.it_content ,it.it_sitecode ,it.it_datetime diff --git a/application/third_party/recommend/views/tips_info.php b/application/third_party/recommend/views/tips_info.php index 3f6419f5..f0f9b053 100644 --- a/application/third_party/recommend/views/tips_info.php +++ b/application/third_party/recommend/views/tips_info.php @@ -15,7 +15,9 @@ $(function () { $("#it_expires").datepicker({ - showButtonPanel: true + showButtonPanel: true, + changeMonth:true, + changeYear:true }); }) @@ -33,13 +35,20 @@