diff --git a/application/controllers/information.php b/application/controllers/information.php index f908bb92..b6c8eb62 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -334,6 +334,10 @@ class Information extends CI_Controller } else { $data['mobile_first_template'] = '没有找到移动模板'; } + //查找是否有静态文件 + if ($this->html_file_helper('find', $data['information']->ic_url)) { + $data['has_html_file'] = true; + } $this->load->view('bootstrap3/header', $data); $this->load->view('bootstrap3/information_edit'); @@ -557,6 +561,46 @@ class Information extends CI_Controller return true; } + //静态文件操作 + public function html_file_helper($active = 'find', $ic_url=false) + { + if(empty($ic_url)){ + $ic_url=$this->input->get_post('ic_url'); + } + if(empty($ic_url)){ + return false; + } + $html_file = $this->config->item('cache')[$this->config->item('site_code')]['cache_path'] . $ic_url; + $html_file = str_replace("\\", "/", $html_file); + if (substr($html_file, -1, 1) == '/') { + $html_file = $html_file . 'index.htm'; + } + $html_file_mobile = $html_file . '-mobile.htm'; + $html_file_pc = $html_file . '-pc.htm'; + + switch ($active) { + case 'find': //寻找静态文件 + if (is_file($html_file_mobile) || is_file($html_file_pc)) { + return true; + } else { + return false; + } + break; + case 'delete': + if (is_file($html_file_mobile)) { + unlink($html_file_mobile); + } + if (is_file($html_file_pc)) { + unlink($html_file_pc); + } + echo '删除静态文件成功! ' . $ic_url; + break; + default: + return false; + } + return false; + } + function make_mobile_html($information) { $data = array(); @@ -574,16 +618,16 @@ class Information extends CI_Controller $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); //额外样式 - $meta_addon_css=get_meta($information->ic_id, 'meta_addon_css'); - if(!empty($meta_addon_css)){ - $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'))){ + 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'))) { + if (!empty(get_meta($information->ic_id, 'meta_google_ad_article'))) { $mobile_template = str_replace('', '', $mobile_template); } //信息推荐 @@ -623,16 +667,16 @@ class Information extends CI_Controller $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 = str_replace('', $template_H1, $template); //额外样式 - $meta_addon_css=get_meta($information->ic_id, 'meta_addon_css'); - if(!empty($meta_addon_css)){ - $template = str_replace('', '', $template); + $meta_addon_css = get_meta($information->ic_id, 'meta_addon_css'); + if (!empty($meta_addon_css)) { + $template = str_replace('', '', $template); } $template = str_replace('', $this->input->post('ic_content'), $template); //Google广告代码 - if(!empty(get_meta($information->ic_id, 'meta_google_ad_content'))){ + if (!empty(get_meta($information->ic_id, 'meta_google_ad_content'))) { $template = str_replace('', '', $template); } - if(!empty(get_meta($information->ic_id, 'meta_google_ad_article'))) { + if (!empty(get_meta($information->ic_id, 'meta_google_ad_article'))) { $template = str_replace('', '', $template); } //信息推荐 diff --git a/application/helpers/info_helper.php b/application/helpers/info_helper.php index 9d0d2f15..e1043955 100644 --- a/application/helpers/info_helper.php +++ b/application/helpers/info_helper.php @@ -3,20 +3,22 @@ //获取项目类型名称 function get_project_typename($type) { - $CI = & get_instance(); - $type_list=$CI->config->item('project_types'); + $CI = &get_instance(); + $type_list = $CI->config->item('project_types'); return $type_list[$type]; } -function GetAreaName($HT_areaType, $HT_areaID) { - $CI = & get_instance(); +function GetAreaName($HT_areaType, $HT_areaID) +{ + $CI = &get_instance(); $CI->load->model('Area_model'); return $CI->Area_model->get_area_name($HT_areaType, $HT_areaID); } //查找作者名称,根据参数类型判断查作者表还是翰特表 -function get_author_name($author_code_id) { - $CI = & get_instance(); +function get_author_name($author_code_id) +{ + $CI = &get_instance(); if (is_numeric($author_code_id)) { $CI->load->model('Infoauthors_model'); $user = $CI->Infoauthors_model->detail_by_id($author_code_id); @@ -34,7 +36,8 @@ function get_author_name($author_code_id) { } //根据站点id获取站点名称 -function get_sitecode($site_id, $site_array) { +function get_sitecode($site_id, $site_array) +{ foreach ($site_array as $item) { if ($item['site_id'] == $site_id) { return $item['site_code']; @@ -47,7 +50,8 @@ function get_sitecode($site_id, $site_array) { * 递归创建文件夹 */ -function create_folder_by_path($dir, $mode = 0777) { +function create_folder_by_path($dir, $mode = 0777) +{ if (!is_dir($dir)) { return @mkdir($dir, $mode, true); } @@ -57,8 +61,9 @@ function create_folder_by_path($dir, $mode = 0777) { /** * 获取iis rewrite之前的原始url */ -function get_origin_url() { - $CI = & get_instance(); +function get_origin_url() +{ + $CI = &get_instance(); if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { $origin_url = str_replace($CI->config->item('index_page'), '/', $_SERVER['HTTP_X_REWRITE_URL']); } else { @@ -68,8 +73,9 @@ function get_origin_url() { } //是否是系列站 -function is_series_site() { - $CI = & get_instance(); +function is_series_site() +{ + $CI = &get_instance(); $sitecode = $CI->config->item('site_code'); if ($sitecode == 'vc' || $sitecode == 'ru' || $sitecode == 'jp' || $sitecode == 'vac' || $sitecode == 'it') { return true; @@ -80,8 +86,9 @@ function is_series_site() { //是否是子站点 -function is_sub_site() { - $CI = & get_instance(); +function is_sub_site() +{ + $CI = &get_instance(); $sitecode = $CI->config->item('site_code'); if ($sitecode == 'yz' || $sitecode == 'tbt' || $sitecode == 'mbj' || $sitecode == 'sht' || $sitecode == 'gl') { return true; @@ -90,150 +97,154 @@ function is_sub_site() { } } -function add_meta($im_ic_id, $im_key, $im_value) { - $CI = & get_instance(); +function add_meta($im_ic_id, $im_key, $im_value) +{ + $CI = &get_instance(); $CI->load->model('InfoMetas_model'); return $CI->InfoMetas_model->add($im_ic_id, $im_key, $im_value); } -function get_meta($im_ic_id, $im_key) { - $CI = & get_instance(); +function get_meta($im_ic_id, $im_key) +{ + $CI = &get_instance(); $CI->load->model('InfoMetas_model'); return $CI->InfoMetas_model->get($im_ic_id, $im_key); } -function update_meta($im_ic_id, $im_key, $im_value) { - $CI = & get_instance(); +function update_meta($im_ic_id, $im_key, $im_value) +{ + $CI = &get_instance(); $CI->load->model('InfoMetas_model'); return $CI->InfoMetas_model->update($im_ic_id, $im_key, $im_value); } -function delete_meta($im_ic_id, $im_key) { - $CI = & get_instance(); +function delete_meta($im_ic_id, $im_key) +{ + $CI = &get_instance(); $CI->load->model('InfoMetas_model'); return $CI->InfoMetas_model->delete($im_ic_id, $im_key); } //检查是否有短消息 -function have_unread_sms($m_object_type,$m_object_id) +function have_unread_sms($m_object_type, $m_object_id) { - $CI = & get_instance(); - $CI->load->model('InfoSMS_model'); - $sms_list=$CI->InfoSMS_model->unread_sms($m_object_type,$m_object_id); - $admin_info=$CI->session->userdata('session_admin'); - if(empty($sms_list)) - { - return false; - } - else - { - $sender=get_author_name($sms_list[0]->m_sender); - if($admin_info['OPI_Name']==$sender){ - return false; - }else{ - return true; - } - } + $CI = &get_instance(); + $CI->load->model('InfoSMS_model'); + $sms_list = $CI->InfoSMS_model->unread_sms($m_object_type, $m_object_id); + $admin_info = $CI->session->userdata('session_admin'); + if (empty($sms_list)) { + return false; + } else { + $sender = get_author_name($sms_list[0]->m_sender); + if ($admin_info['OPI_Name'] == $sender) { + return false; + } else { + return true; + } + } } //截取字符串 -function get_text_short($str, $length = 40, $ext = '',$only_content=false) { - $str = strip_tags($str); - $str = htmlspecialchars_decode($str); - $strlenth = 0; - $out = ''; - $output = ''; - $is_length = false; - preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/", $str, $match); - foreach($match[0] as $v){ - preg_match("/[\xe0-\xef][\x80-\xbf]{2}/",$v, $matchs); - if(!empty($matchs[0])){ - $strlenth += 1; - }elseif(is_numeric($v)){ - $strlenth += 0.5; // 字符字节长度比例 汉字为1 - }else{ - $strlenth += 0.5; // 字符字节长度比例 汉字为1 - } - if ($strlenth > $length) { - $output .= $ext; - $is_length=true; - break; - } - $output .= $v; +function get_text_short($str, $length = 40, $ext = '', $only_content = false) +{ + $str = strip_tags($str); + $str = htmlspecialchars_decode($str); + $strlenth = 0; + $out = ''; + $output = ''; + $is_length = false; + preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/", $str, $match); + foreach ($match[0] as $v) { + preg_match("/[\xe0-\xef][\x80-\xbf]{2}/", $v, $matchs); + if (!empty($matchs[0])) { + $strlenth += 1; + } elseif (is_numeric($v)) { + $strlenth += 0.5; // 字符字节长度比例 汉字为1 + } else { + $strlenth += 0.5; // 字符字节长度比例 汉字为1 } - $data['content']=$output; - $data['length']=$is_length; - if ($only_content) { - return $data['content']; + if ($strlenth > $length) { + $output .= $ext; + $is_length = true; + break; } - return $data; + $output .= $v; } + $data['content'] = $output; + $data['length'] = $is_length; + if ($only_content) { + return $data['content']; + } + return $data; +} //平台头部展示所有未读消息数量 -function get_all_unread_sms($type='author',$author=false) +function get_all_unread_sms($type = 'author', $author = false) { - $CI = & get_instance(); + $CI = &get_instance(); $CI->load->model('InfoSMS_model'); - if(!$author){ - $admin_info=$CI->session->userdata('session_admin'); - $author=$admin_info['OPI_Code']; + if (!$author) { + $admin_info = $CI->session->userdata('session_admin'); + $author = $admin_info['OPI_Code']; } - - if ($type=='info') { - $unread_sms=$CI->InfoSMS_model->info_unread_sms($author,'info'); - }else{ - $unread_sms=$CI->InfoSMS_model->all_unread_sms($author,'task'); + + if ($type == 'info') { + $unread_sms = $CI->InfoSMS_model->info_unread_sms($author, 'info'); + } else { + $unread_sms = $CI->InfoSMS_model->all_unread_sms($author, 'task'); } return $unread_sms; } //获取不同任务状态的任务数量 -function get_task_count_by_status(){ - $CI = & get_instance(); +function get_task_count_by_status() +{ + $CI = &get_instance(); $CI->load->model('Infotasks_model'); - $task_count_by_status=$CI->Infotasks_model->get_task_count_by_status(); + $task_count_by_status = $CI->Infotasks_model->get_task_count_by_status(); return $task_count_by_status; } //获取作者头像 -function get_author_photo($author_code_id=false) +function get_author_photo($author_code_id = false) { - $CI = & get_instance(); - $root_url='';//'http://data.chtcdn.com'; - $avatar=$root_url.'/css/images/avatar.jpg'; - if($author_code_id && is_numeric($author_code_id)) - { - $CI->load->model('Infoauthors_model'); - $user=$CI->Infoauthors_model->detail_by_id($author_code_id); - if(isset($user->a_photo) && $user->a_photo!='') - { - $avatar = $root_url.'/author/document/profile_photo/'.$user->a_photo; - } - } - return $avatar; + $CI = &get_instance(); + $root_url = '';//'http://data.chtcdn.com'; + $avatar = $root_url . '/css/images/avatar.jpg'; + if ($author_code_id && is_numeric($author_code_id)) { + $CI->load->model('Infoauthors_model'); + $user = $CI->Infoauthors_model->detail_by_id($author_code_id); + if (isset($user->a_photo) && $user->a_photo != '') { + $avatar = $root_url . '/author/document/profile_photo/' . $user->a_photo; + } + } + return $avatar; } //补全图片路径 -function get_photo_url($photo){ - $root_url='';//'http://data.chtcdn.com'; - if ($photo=='') { - $avatar = $root_url.'/css/images/uploadPic.jpg'; - }else{ - $avatar = $root_url.'/author/document/profile_photo/'.$photo; +function get_photo_url($photo) +{ + $root_url = '';//'http://data.chtcdn.com'; + if ($photo == '') { + $avatar = $root_url . '/css/images/uploadPic.jpg'; + } else { + $avatar = $root_url . '/author/document/profile_photo/' . $photo; } return $avatar; } //获取待审核作者数量 -function un_active_count(){ - $CI = & get_instance(); +function un_active_count() +{ + $CI = &get_instance(); $CI->load->model('Infoauthors_model'); - $num=$CI->Infoauthors_model->un_active_count(); + $num = $CI->Infoauthors_model->un_active_count(); return $num; } //分页函数 -function show_page($page){ +function show_page($page) +{ $pageSize = $page['pageSize']; $total = $page['total']; $url = $page['url']; @@ -242,94 +253,106 @@ function show_page($page){ $startPage = ($currentPage - 1) * $pageSize; $befor = $after = 0; - $nowview=ceil(($currentPage+1)/10); - $befor = $nowview==1?($nowview-1)*10+1:($nowview-1)*10; - if($pageNumber>=$nowview*10){ - $after = $nowview*10; - }else{ + $nowview = ceil(($currentPage + 1) / 10); + $befor = $nowview == 1 ? ($nowview - 1) * 10 + 1 : ($nowview - 1) * 10; + if ($pageNumber >= $nowview * 10) { + $after = $nowview * 10; + } else { $after = $pageNumber; } - $html=''; - if($nowview>1) $befor--; - if ($pageSize <= $total) { - for ($i = $befor; $i <= $after; $i++) { - if ($i == $currentPage) { + $html = ''; + if ($nowview > 1) $befor--; + if ($pageSize <= $total) { + for ($i = $befor; $i <= $after; $i++) { + if ($i == $currentPage) { $html .= "