diff --git a/application/controllers/cache.php b/application/controllers/cache.php index 6be82b4e..cf2d1b57 100644 --- a/application/controllers/cache.php +++ b/application/controllers/cache.php @@ -1,9 +1,10 @@ input->get('site_code')) { + if (!$this->input->get('site_code')) { $this->permission->is_admin(); } $this->load->model('Area_model'); @@ -38,19 +40,20 @@ class Cache extends CI_Controller { * @param String $site_code * */ - public function update() { + public function update() + { header('Content-Type: text/html; charset=utf-8'); $returnType = $this->input->get('type'); //设置缓存文件文件夹 - $cache_config = $this->config->item('cache'); + $cache_config = $this->config->item('cache'); $current_cache_config = $cache_config[$this->site_code]; - $this->dir = $current_cache_config['cache_path']; + $this->dir = $current_cache_config['cache_path']; - //设置当前站点 + //设置当前站点 $this->current_domain = $current_cache_config['site_url']; //$this->config->item('site_url'); - //echo $this->config->item('site_url'); - //设置缓存更新接口及POST参数 + //echo $this->config->item('site_url'); + //设置缓存更新接口及POST参数 $this->cache_api = $current_cache_config['cache_api']; $this->post_para = $current_cache_config['cache_api_para']; //遍历缓存文件夹 @@ -63,8 +66,8 @@ class Cache extends CI_Controller { $this->filter($this->file, $this->path); //整理需要传递到视图的数据 - $data['file'] = $this->file; - $data['path'] = $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; @@ -73,7 +76,7 @@ class Cache extends CI_Controller { //print_r($cache_config[$this->site_code]); //echo('json'); //print_r($data['file']); - echo(json_encode($data['file'])); + echo (json_encode($data['file'])); } else { //视图 $this->load->view('cache/update', $data); @@ -88,12 +91,13 @@ class Cache extends CI_Controller { * @param String $site_code * */ - public function sitemap() { + public function sitemap() + { header("Content-type:text/xml"); //设置缓存文件文件夹 - $cache_config = $this->config->item('cache'); + $cache_config = $this->config->item('cache'); $current_cache_config = $cache_config[$this->site_code]; - $this->dir = $current_cache_config['cache_path']; + $this->dir = $current_cache_config['cache_path']; //设置当前站点 $this->current_domain = $this->config->item('site_url'); @@ -106,8 +110,8 @@ class Cache extends CI_Controller { $this->filter($this->file, $this->path); //整理需要传递到视图的数据 - $data['file'] = $this->file; - $data['path'] = $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; @@ -116,20 +120,20 @@ class Cache extends CI_Controller { sort($data['file']); //生成sitemap - $dom = new DomDocument('1.0', 'utf-8'); + $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'); + $url = $dom->createElement('url'); + $loc = $dom->createElement('loc'); $text = $dom->createTextNode($f); $loc->appendchild($text); $url->appendchild($loc); $urlset->appendchild($url); } - echo($dom->saveXML()); + echo ($dom->saveXML()); } /** @@ -143,7 +147,8 @@ class Cache extends CI_Controller { * @param Array $file_time - 存放文件更新日期的数组引用 * */ - private function tree($dir, &$file, &$path, &$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) && (strpos($dir, '/amp/') === false) && (strpos($dir, '/js/') === false) && (strpos($dir, 'stfolder') === false)) { @@ -151,18 +156,18 @@ class Cache extends CI_Controller { $this->tree("$dir/$f", $file, $path, $file_time); } else { if ($f != '.' && $f != '..' && (strpos($f, 'stfolder') === false) && (strpos($f, '/cn/') === false) && (strpos($f, '/amp/') === false) && (strpos($f, '.pdf') === false) && (strpos($f, '.mobile.htm') === false) && (strpos($f, '.txt') === false) && (strpos($f, '/js/') === false) && (strpos($f, '.amp') === false) && (strpos($f, 'stignore') === false)) { - $file_temp = str_replace('/index.htm###', '', $f . '###'); - $file_temp = str_replace('###', '', $file_temp); - $path_temp = str_replace($this->dir, '', $dir); - $url_temp = $this->current_domain . $path_temp . '/' . $file_temp; - $url_temp = str_replace('/index.htm', '/', $url_temp); + $file_temp = str_replace('/index.htm###', '', $f . '###'); + $file_temp = str_replace('###', '', $file_temp); + $path_temp = str_replace($this->dir, '', $dir); + $url_temp = $this->current_domain . $path_temp . '/' . $file_temp; + $url_temp = str_replace('/index.htm', '/', $url_temp); $file_time[$url_temp] = date("F d Y H:i:s", filemtime("$dir/$f")); // $encode = mb_detect_encoding($url_temp); // $_url_temp = mb_convert_encoding($url_temp, 'UTF8', $encode); // $_url_temp = mb_convert_encoding($url_temp, 'UTF-8//IGNORE', $encode) . '?encoding=' . $encode; $_url_temp = $url_temp; - $file[] = $_url_temp; + $file[] = $_url_temp; } } } @@ -180,8 +185,9 @@ class Cache extends CI_Controller { * 可选参数:POST参数 - $_POST['p'] * */ - private function filter(&$file, &$path) { - if (isset($_POST['p']) && ! empty($_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; diff --git a/application/views/cache/update.php b/application/views/cache/update.php index db78210f..ade5e85c 100644 --- a/application/views/cache/update.php +++ b/application/views/cache/update.php @@ -85,11 +85,11 @@ //file = encodeURI(file); current.find('.msg_wait').css('color', 'red').html('更新中'); $.ajax({ - url: '', + url: '', dataType: 'json', type: 'POST', data: { - '': file + '': file }, success: function (data) { star = star + step; @@ -110,7 +110,7 @@ var num_zero = 1; function count_num(num) { - $('#count_num').html('已更新' + num + '个页面 进度' + (Math.ceil(num * 100 / )) + '% ').show(); + $('#count_num').html('已更新' + num + '个页面 进度' + (Math.ceil(num * 100 / )) + '% ').show(); num_zero++; } }); @@ -124,7 +124,7 @@ 缓存目录 - 个 + 含文件 - 个 + 已更新0个页面 进度0% 更新 @@ -195,36 +195,36 @@ - $it) { - // $encode = mb_detect_encoding($it, array('ASCII', 'GBK', 'ISO-8859-1', 'UTF-8')); - // $_it = mb_convert_encoding($it, 'UTF8', $encode); - $_it = preg_replace('/#(.*)$/i', '', $it); - if (strlen($it) != strlen($_it)) { - continue; - } - - $c++; - ?> + $it) { + // $encode = mb_detect_encoding($it, array('ASCII', 'GBK', 'ISO-8859-1', 'UTF-8')); + // $_it = mb_convert_encoding($it, 'UTF8', $encode); + $_it = preg_replace('/#(.*)$/i', '', $it); + if (strlen($it) != strlen($_it)) { + continue; + } + + $c++; + ?> - + - 100) {?> - - .......... - + 100) { ?> + + .......... + - - - + + + - + - + 无操作 - +