|
|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
<?php
|
|
|
|
|
if (! defined('BASEPATH')) {
|
|
|
|
|
if (!defined('BASEPATH')) {
|
|
|
|
|
exit('No direct script access allowed');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Cache extends CI_Controller {
|
|
|
|
|
class Cache extends CI_Controller
|
|
|
|
|
{
|
|
|
|
|
//缓存文件绝对路径
|
|
|
|
|
private $dir = '';
|
|
|
|
|
//存放缓存文件的数组
|
|
|
|
|
@ -19,9 +20,10 @@ class Cache extends CI_Controller {
|
|
|
|
|
//文件更新日期
|
|
|
|
|
private $file_time = [];
|
|
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
|
function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
if (! $this->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;
|
|
|
|
|
|