From 1d3c5cb2def0f39687da275bb846dc911348e53a Mon Sep 17 00:00:00 2001 From: "lmr@hainatravel.com" <59361885@qq.com> Date: Wed, 12 Jul 2017 15:30:54 +0800 Subject: [PATCH] merge origin --- application/controllers/tools.php | 194 +++++++++++++++++++++++ application/models/information_model.php | 24 +++ 2 files changed, 218 insertions(+) create mode 100644 application/controllers/tools.php diff --git a/application/controllers/tools.php b/application/controllers/tools.php new file mode 100644 index 00000000..85b2c4eb --- /dev/null +++ b/application/controllers/tools.php @@ -0,0 +1,194 @@ +permission->is_admin(); + $this->load->model('Area_model'); + $this->load->model('InfoStructures_model'); + $this->load->model('Information_model'); + $this->site_code = $this->config->item('site_code'); + } + + /** + * + * 公有函数:扫描已有缓存文件并更新。 + * + * 必要参数: + * @param String $site_code + * + */ + public function update() + { + //设置缓存文件文件夹 + $cache_config = $this->config->item('cache'); + $current_cache_config = $cache_config[$this->site_code]; + $this->dir = $current_cache_config['cache_path']; + + //设置当前站点 + $this->current_domain = $this->config->item('site_url'); + //echo $this->config->item('site_url'); + //设置缓存更新接口及POST参数 + $this->cache_api = $current_cache_config['cache_api']; + $this->post_para = $current_cache_config['cache_api_para']; + //遍历缓存文件夹 + $this->tree($this->dir, $this->file, $this->path, $this->file_time); + //按目录筛选结果 + $this->filter($this->file, $this->path); + + //整理需要传递到视图的数据 + $data['file'] = $this->file; + $data['path'] = $this->path; + $data['file_time'] = $this->file_time; + $data['cache_api'] = $this->cache_api; + $data['post_para'] = $this->post_para; + + //视图 + $this->load->view('cache/update', $data); + } + + /** + * + * 公有函数:扫描已有缓存文件并更新。 + * + * 必要参数: + * @param String $site_code + * + */ + public function sitemap() + { + header("Content-type:text/xml"); + //设置缓存文件文件夹 + $cache_config = $this->config->item('cache'); + $current_cache_config = $cache_config[$this->site_code]; + $this->dir = $current_cache_config['cache_path']; + + //设置当前站点 + $this->current_domain = $this->config->item('site_url'); + //设置缓存更新接口及POST参数 + $this->cache_api = $current_cache_config['cache_api']; + $this->post_para = $current_cache_config['cache_api_para']; + //遍历缓存文件夹 + $this->tree($this->dir, $this->file, $this->path, $this->file_time); + //按目录筛选结果 + $this->filter($this->file, $this->path); + + //整理需要传递到视图的数据 + $data['file'] = $this->file; + $data['path'] = $this->path; + $data['file_time'] = $this->file_time; + $data['cache_api'] = $this->cache_api; + $data['post_para'] = $this->post_para; + + //排序file数组 + sort ($data['file']); + + //生成sitemap + $dom = new DomDocument('1.0', 'utf-8'); + $urlset = $dom->createElement('urlset'); + $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); + $dom->appendchild($urlset); + foreach ($data['file'] as $f) + { + $url = $dom->createElement('url'); + $loc = $dom->createElement('loc'); + $text = $dom->createTextNode($f); + $loc->appendchild($text); + $url->appendchild($loc); + $urlset->appendchild($url); + } + + echo($dom->saveXML()); + + } + + + /** + * + * 私有函数:递归遍历缓存文件夹,将目录存放到$path,文件存放到$file。 + * + * 必要参数: + * @param String $dir - 需要遍历的目录 + * @param Array $file - 存放文件结果的数组引用 + * @param Array $path - 存放路径结果的数组引用 + * @param Array $file_time - 存放文件更新日期的数组引用 + * + */ + private function tree($dir, &$file, &$path, &$file_time) + { + $mydir = dir($dir); + while($f = $mydir->read()) + { + if(is_dir("$dir/$f") && $f!="." && $f!=".." && (strpos($dir, '/cn/')==false)) + { + $path[] = "$dir/$f"; + $this->tree("$dir/$f", $file, $path, $file_time); + } + else + { + if ($f!='.' && $f!='..' && (strpos($dir, '/cn/')==false) && (strpos($f, '.pdf')===false)) + { + $file_temp = str_ireplace('index.htm###', '', $f.'###'); + $file_temp = str_ireplace('###', '', $file_temp); + $path_temp = str_ireplace($this->dir, '', $dir); + $url_temp = $this->current_domain.$path_temp.'/'.$file_temp; + $file_time[$url_temp] = date("F d Y H:i:s", filemtime("$dir/$f")); + $file[] = $url_temp; + } + } + } + $mydir->close(); + } + + + /** + * + * 私有函数:筛选目录和文件。 + * + * 必要参数: + * @param Array $file - 存放文件结果的数组引用 + * @param Array $path - 存放路径结果的数组引用 + * + * 可选参数:POST参数 - $_POST['p'] + * + */ + private function filter(&$file, &$path) + { + if (isset($_POST['p']) && !empty($_POST['p'])) + { + //删选文件 + foreach ($file as &$f) + { + (stripos($f, $_POST['p'])!==false) or $f = false; + } + $file = array_filter($file); + //删选目录 + foreach ($path as &$p) + { + (stripos($p, $_POST['p'])!==false) or $p = false; + } + $path = array_filter($path); + } + } + +} +//end of Cache diff --git a/application/models/information_model.php b/application/models/information_model.php index b850059f..e1ff03ab 100644 --- a/application/models/information_model.php +++ b/application/models/information_model.php @@ -328,4 +328,28 @@ class Information_model extends CI_Model { return $this->GetList(); } + //获取3年未更新的信息 + function get_oldest_info() { + //年份条件 + $yeardiff = $this->input->get_post('yeardiff'); + if (!$yeardiff) $yeardiff = 3; + //sql + $sql = "SELECT + ic_id, + ic_url, + ic_sitecode, + ic_title, + ic_url_title, + ic_datetime, + ic_type, + ic_author, + ic_status=1, + ic_view + FROM infoContents + WHERE datediff(YEAR,DATEPART(yyyy, ic_datetime),DATEPART(YYYY, getdate())) > ? + AND ic_sitecode = ? "; + $query = $this->HT->query($sql, array($yeardiff, $this->config->item('site_code'))); + return $query->result(); + } + }