From 6329909c52fd30f111e7dae7cbcb53ce07ccd09c Mon Sep 17 00:00:00 2001 From: ycc Date: Wed, 23 Dec 2020 14:16:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=8E=A8=E8=8D=90=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/information.php | 77 ++++++++++++++++--- application/helpers/info_helper.php | 7 ++ application/models/information_model.php | 13 ++++ .../views/bootstrap3/information_edit.php | 2 +- application/views/mobile_first/ch-next.php | 49 ++++++++++++ application/views/mobile_first/ch.php | 5 +- 6 files changed, 140 insertions(+), 13 deletions(-) create mode 100644 application/views/mobile_first/ch-next.php diff --git a/application/controllers/information.php b/application/controllers/information.php index 6cd2ad05..58225795 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -574,7 +574,8 @@ class Information extends CI_Controller $mobile_template_H1=$this->call_mobile_template_H1($mobile_first_template_path,$this->input->post('is_parent_id'),$this->input->post('ic_author'),$this->input->post('ic_title'),$this->input->post('ic_photo'));//H1模板替换 $mobile_template=str_replace('', $mobile_template_H1, $mobile_template); $mobile_template=str_replace('', $this->input->post('ic_content'), $mobile_template); - + $template_NEXT=$this->call_mobile_template_NEXT($mobile_first_template_path,$this->input->post('is_id')); + $mobile_template=str_replace('', $template_NEXT, $mobile_template); // /travelguide/chinese-zodiac/monthly-fortune-for-dog.htm $mobile_html=$this->config->item('cache')[$this->config->item('site_code')]['cache_path'].$this->input->post('ic_url'); $mobile_html=str_replace("\\", "/", $mobile_html); @@ -603,7 +604,8 @@ class Information extends CI_Controller $template_H1=$this->call_mobile_template_H1($template_path,$this->input->post('is_parent_id'),$this->input->post('ic_author'),$this->input->post('ic_title'),$this->input->post('ic_photo'));//H1模板替换 $template=str_replace('', $template_H1, $template); $template=str_replace('', $this->input->post('ic_content'), $template); - + $template_NEXT=$this->call_mobile_template_NEXT($template_path,$this->input->post('is_id')); + $template=str_replace('', $template_NEXT, $template); // /travelguide/chinese-zodiac/monthly-fortune-for-dog.htm $html_path=$this->config->item('cache')[$this->config->item('site_code')]['cache_path'].$this->input->post('ic_url'); $html_path=str_replace("\\", "/", $html_path); @@ -623,19 +625,72 @@ class Information extends CI_Controller return $this->load->view($mobile_first_template_path.'-h1', $data, TRUE); } - function call_mobile_template_NEXT($template_path,$is_parent_id,$ic_author,$ic_title,$ic_photo){ + function call_mobile_template_NEXT($template_path,$is_id){ + $data['detail']=$this->Information_model->Detail($is_id);//信息所属分类,获取信息顶级节点内容 + $data['root_detail']=$this->Information_model->get_detail_by_path($data['detail']->is_path,1);//信息所属分类,获取信息顶级节点内容 //how to plan - + $data['info_howtoplan']=$this->Information_model->search_by_words($data['root_detail']->is_path,array('how','plan')); + if(empty($data['info_howtoplan'])){//找不到对应信息则显示备用 + $data['info_howtoplan']=$this->Information_model->Detail('/travelguide/plan-first-trip.htm'); + } + if(!empty($data['info_howtoplan'])){ + if(empty($data['info_howtoplan']->ic_photo)){ + $images=get_image_url_by_source($data['info_howtoplan']->ic_content); + if(!empty($images)){ + $data['info_howtoplan']->ic_photo=$images[1][0]; + } + }else{ + $data['info_howtoplan']->ic_photo=$this->config->item('site_image_url').$data['info_howtoplan']->ic_photo; + } + } //best time to visit - + $data['info_besttime']=$this->Information_model->search_by_words($data['root_detail']->is_path,array('best','time')); + if(empty($data['info_besttime'])){ + $data['info_besttime']=$this->Information_model->Detail('/weather/china-best-times.htm'); + } + if(!empty($data['info_besttime'])){ + if(empty($data['info_besttime']->ic_photo)){ + $images=get_image_url_by_source($data['info_besttime']->ic_content); + if(!empty($images)){ + $data['info_besttime']->ic_photo=$images[1][0]; + } + }else{ + $data['info_besttime']->ic_photo=$this->config->item('site_image_url').$data['info_besttime']->ic_photo; + } + } //top things to do - + $data['info_topthings']=$this->Information_model->search_by_words($data['root_detail']->is_path,array('top','things')); + if(empty($data['info_topthings'])){ + $data['info_topthings']=$this->Information_model->Detail('/travelguide/article-top-china-tourist-destination.htm'); + } + if(!empty($data['info_topthings'])){ + if(empty($data['info_topthings']->ic_photo)){ + $images=get_image_url_by_source($data['info_topthings']->ic_content); + if(!empty($images)){ + $data['info_topthings']->ic_photo=$images[1][0]; + } + }else{ + $data['info_topthings']->ic_photo=$this->config->item('site_image_url').$data['info_topthings']->ic_photo; + } + } //hotel , where to stay - - $data['infocategory']=$this->Information_model->Detail($is_parent_id);//信息所属分类,获取信息父级节点url title - $data['author']=$this->Operator_model->get_author_nikename($ic_author);//获取作者信息 - $data['ic_title']=$ic_title; - $data['ic_photo']=$ic_photo; + $data['info_hotel']=$this->Information_model->search_by_words($data['root_detail']->is_path,array('hotel')); + if(empty($data['info_hotel'])){ + $data['info_hotel']=$this->Information_model->search_by_words($data['root_detail']->is_path,array('where','stay')); + } + if(empty($data['info_hotel'])){ + $data['info_hotel']=$this->Information_model->Detail('/travelguide/most-beautiful-places.htm'); + } + if(!empty($data['info_hotel'])){ + if(empty($data['info_hotel']->ic_photo)){ + $images=get_image_url_by_source($data['info_hotel']->ic_content); + if(!empty($images)){ + $data['info_hotel']->ic_photo=$images[1][0]; + } + }else{ + $data['info_hotel']->ic_photo=$this->config->item('site_image_url').$data['info_hotel']->ic_photo; + } + } return $this->load->view($template_path.'-next', $data, TRUE); } diff --git a/application/helpers/info_helper.php b/application/helpers/info_helper.php index 06cb3f44..9d0d2f15 100644 --- a/application/helpers/info_helper.php +++ b/application/helpers/info_helper.php @@ -325,4 +325,11 @@ function get_content_by_url($url) { } curl_close($curl); //关闭CURL会话 return $tmpInfo; //返回数据 + } + + //获取内容中图片地址 + function get_image_url_by_source($source){ + $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.jpeg|\.png|\.jpg]))[\'|\"].*?[\/]?>/"; + preg_match_all($pattern, $source, $match); + return $match; } \ No newline at end of file diff --git a/application/models/information_model.php b/application/models/information_model.php index 84e6aea9..2150894f 100644 --- a/application/models/information_model.php +++ b/application/models/information_model.php @@ -64,6 +64,19 @@ class Information_model extends CI_Model { return $this->GetList(); } + //根据关键词来搜索内容 + function search_by_words($is_path,array $words){ + $this->init(); + $this->topNum = 1; + $sql_keyword=' AND ( 1=1 '; + foreach ($words as $item) { + $sql_keyword .=" AND ic_url like '%". $this->HT->escape_like_str($item) ."%' "; + } + $sql_keyword.=' ) '; + $this->search =" AND is1.is_path LIKE '$is_path%' ". $sql_keyword; + return $this->GetList(); + } + //根据url搜索信息 function search_url($url) { $this->init(); diff --git a/application/views/bootstrap3/information_edit.php b/application/views/bootstrap3/information_edit.php index 66cb29a9..c39741dc 100644 --- a/application/views/bootstrap3/information_edit.php +++ b/application/views/bootstrap3/information_edit.php @@ -139,7 +139,7 @@ //移动到任意节点下 function move_by_is_id(is_id) { - is_parent_id = prompt("请输入移动到的节点ID:", ""); + is_parent_id = prompt("请输入移动到的节点ID(is_id):", ""); if (is_parent_id != null) { if (confirm('请确认是否要移动到:' + is_parent_id)) { var urlReQuery = ""; diff --git a/application/views/mobile_first/ch-next.php b/application/views/mobile_first/ch-next.php new file mode 100644 index 00000000..eae29dfc --- /dev/null +++ b/application/views/mobile_first/ch-next.php @@ -0,0 +1,49 @@ +
+
+

Related Articles

+
+ +
+ <?php echo $info_howtoplan->ic_title; ?> + ic_url_title; ?> + ic_url_title; ?> +
+ + + +
+ <?php echo $info_besttime->ic_title; ?> + ic_url_title; ?> + ic_url_title; ?> +
+ + + +
+ <?php echo $info_topthings->ic_title; ?> + ic_url_title; ?> + ic_url_title; ?> +
+ + + +
+ <?php echo $info_hotel->ic_title; ?> + ic_url_title; ?> + ic_url_title; ?> +
+ + +
\ No newline at end of file diff --git a/application/views/mobile_first/ch.php b/application/views/mobile_first/ch.php index 97d50d16..7f1d7cdb 100644 --- a/application/views/mobile_first/ch.php +++ b/application/views/mobile_first/ch.php @@ -175,7 +175,10 @@ -
+
+ + +