From 8ced108d40f4005498b865bcd1ed88c3104e9053 Mon Sep 17 00:00:00 2001 From: ycc Date: Wed, 30 Dec 2020 10:48:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=9B=BF=E6=8D=A2=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=BA=8C=E5=90=88=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/information.php | 112 ++++++------------------ 1 file changed, 29 insertions(+), 83 deletions(-) diff --git a/application/controllers/information.php b/application/controllers/information.php index df957357..73961815 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -490,8 +490,8 @@ class Information extends CI_Controller $update_info_log = $this->update_cache($ic_url, true); } else if (strcasecmp($site_code, "ch") == 0 && !empty($auto_update_cache)) { //读取模板生成PC和移动优先文件 - $this->make_mobile_html($information); - $this->make_pc_html($information); + $this->make_www_cache('mobile',$information); + $this->make_www_cache('pc',$information); } 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)) { @@ -603,99 +603,45 @@ class Information extends CI_Controller return false; } - //生成静态文件 $template='mobile' or 'pc' - function make_www_cache($template,$information){ + //生成静态文件 $device='mobile' or 'pc' + function make_www_cache($device, $information) + { $data = array(); - switch ($template){ + switch ($device) { case 'mobile': //获取移动优先的模板,如果有的话 - $mobile_first_template_path = 'mobile_first/' . $this->config->item('site_code'); - if (is_file(APPPATH . 'views/' . $mobile_first_template_path . EXT)) { - $mobile_template = $this->load->view($mobile_first_template_path, '', TRUE); + $template_path = 'mobile_first/' . $this->config->item('site_code'); + if (is_file(APPPATH . 'views/' . $template_path . EXT)) { + $template = $this->load->view($template_path, '', TRUE); + $html_path_ext = '-mobile.htm'; } else { return false; } break; case 'pc': + //获取PC的模板,如果有的话 + $template_path = 'mobile_first/' . $this->config->item('site_code'); + if (is_file(APPPATH . 'views/' . $template_path . '-pc' . EXT)) { + $template = $this->load->view($template_path . '-pc', '', TRUE); + $html_path_ext = '-pc.htm'; + } else { + return false; + } break; default: } - } - - function make_mobile_html($information) - { - $data = array(); - //获取移动优先的模板,如果有的话 - $mobile_first_template_path = 'mobile_first/' . $this->config->item('site_code'); - if (is_file(APPPATH . 'views/' . $mobile_first_template_path . EXT)) { - $mobile_template = $this->load->view($mobile_first_template_path, '', TRUE); - } else { - return false; - } - $mobile_template = str_replace('', $this->input->post('ic_seo_title'), $mobile_template); - $mobile_template = str_replace('', $this->input->post('ic_seo_description'), $mobile_template); - $mobile_template = str_replace('', $this->input->post('ic_seo_keywords'), $mobile_template); - $mobile_template = str_replace('', $this->input->post('site_url') . $this->input->post('ic_url'), $mobile_template); - //非产品页面 - if (empty(get_meta($information->ic_id, 'meta_product_code'))) { - //H1标题样式 - $mobile_template_H1 = $this->call_mobile_template_H1($mobile_first_template_path, $this->input->post('is_path'), $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); - //信息推荐 - $template_NEXT = $this->call_mobile_template_NEXT($mobile_first_template_path, $this->input->post('is_id')); - $mobile_template = str_replace('', $template_NEXT, $mobile_template); - $mobile_template = str_replace('', '', $mobile_template); - } - //额外样式 - $meta_addon_css = get_meta($information->ic_id, 'meta_addon_css'); - if (!empty($meta_addon_css)) { - $mobile_template = str_replace('', '', $mobile_template); - } - $mobile_template = str_replace('', $this->input->post('ic_content'), $mobile_template); - //Google广告代码 - if (!empty(get_meta($information->ic_id, 'meta_google_ad_content'))) { - $mobile_template = str_replace('', '', $mobile_template); - } - if (!empty(get_meta($information->ic_id, 'meta_google_ad_article'))) { - $mobile_template = str_replace('', '', $mobile_template); - } - //社媒分享图片 - if (!empty($information->ic_photo)) { - $full_ic_photo = $this->config->item('site_image_url') . $information->ic_photo; - $mobile_template = str_replace('', '', $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); - if (substr($mobile_html, -1, 1) == '/') { - $mobile_html = $mobile_html . 'index.htm'; - } - $mobile_html .= '-mobile.htm'; - create_folder_by_path(dirname($mobile_html)); - file_put_contents($mobile_html, $mobile_template, LOCK_EX); - } - - function make_pc_html($information) - { - $data = array(); - //获取PC的模板,如果有的话 - $template_path = 'mobile_first/' . $this->config->item('site_code'); - if (is_file(APPPATH . 'views/' . $template_path . '-pc' . EXT)) { - $template = $this->load->view($template_path . '-pc', '', TRUE); - } else { - return false; - } - $template = str_replace('', $this->input->post('ic_seo_title'), $template); - $template = str_replace('', $this->input->post('ic_seo_description'), $template); - $template = str_replace('', $this->input->post('ic_seo_keywords'), $template); - $template = str_replace('', $this->input->post('site_url') . $this->input->post('ic_url'), $template); + //替换模板中的标签 + $template = str_replace('', $information->ic_seo_title, $template); + $template = str_replace('', $information->ic_seo_description, $template); + $template = str_replace('', $information->ic_seo_keywords, $template); + $template = str_replace('', $this->config->item('site_url') . $information->ic_url, $template); //非产品页面 if (empty(get_meta($information->ic_id, 'meta_product_code'))) { - $template_H1 = $this->call_mobile_template_H1($template_path, $this->input->post('is_path'), $this->input->post('ic_author'), $this->input->post('ic_title'), $this->input->post('ic_photo'));//H1模板替换 + $template_H1 = $this->call_mobile_template_H1($template_path, $information->is_path, $information->ic_author, $information->ic_title, $information->ic_photo);//H1模板替换 $template = str_replace('', $template_H1, $template); //信息推荐 - $template_NEXT = $this->call_mobile_template_NEXT($template_path, $this->input->post('is_id')); + $template_NEXT = $this->call_mobile_template_NEXT($template_path, $information->is_id); $template = str_replace('', $template_NEXT, $template); $template = str_replace('', '', $template); } @@ -704,7 +650,7 @@ class Information extends CI_Controller if (!empty($meta_addon_css)) { $template = str_replace('', '', $template); } - $template = str_replace('', $this->input->post('ic_content'), $template); + $template = str_replace('', $information->ic_content, $template); //Google广告代码 if (!empty(get_meta($information->ic_id, 'meta_google_ad_content'))) { $template = str_replace('', '', $template); @@ -718,12 +664,12 @@ class Information extends CI_Controller $template = str_replace('', '', $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 = $this->config->item('cache')[$this->config->item('site_code')]['cache_path'] . $information->ic_url; $html_path = str_replace("\\", "/", $html_path); if (substr($html_path, -1, 1) == '/') { $html_path = $html_path . 'index.htm'; } - $html_path .= '-pc.htm'; + $html_path.=$html_path_ext; create_folder_by_path(dirname($html_path)); file_put_contents($html_path, $template, LOCK_EX); } @@ -786,7 +732,7 @@ class Information extends CI_Controller ); $data['info_topthings'] = $this->Information_model->Detail($random_array[rand(0, count($random_array) - 1)]); if (!empty($data['info_topthings'])) { - $data['info_topthings_root'] =$this->Information_model->get_detail_by_path($data['info_topthings']->is_path, 1); + $data['info_topthings_root'] = $this->Information_model->get_detail_by_path($data['info_topthings']->is_path, 1); $data['info_topthings']->ic_photo = $this->set_photo_content($data['info_topthings']->ic_photo, $data['info_topthings']->ic_content); } //文化板块的页面,随机挑选一篇