master
LMR 4 months ago
parent 4e9c9ed1de
commit f6b40ac1f3

@ -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;

@ -85,11 +85,11 @@
//file = encodeURI(file);
current.find('.msg_wait').css('color', 'red').html('更新中');
$.ajax({
url: '<?php echo($cache_api); ?>',
url: '<?php echo ($cache_api); ?>',
dataType: 'json',
type: 'POST',
data: {
'<?php echo($post_para); ?>': file
'<?php echo ($post_para); ?>': 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 / <?php echo(count($file)); ?>)) + '% ').show();
$('#count_num').html('已更新' + num + '个页面 进度' + (Math.ceil(num * 100 / <?php echo (count($file)); ?>)) + '% ').show();
num_zero++;
}
});
@ -124,7 +124,7 @@
<li class="active dropdown mr10">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
站点:
<?php echo($this->config->item('site_code')); ?>
<?php echo ($this->config->item('site_code')); ?>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
@ -168,16 +168,16 @@
</ul>
</li>
<span class="mt12 label label-success">缓存目录
<?php echo(count($path)); ?>
<?php echo (count($path)); ?>
</span>
<span class="mt12 label label-info">含文件
<?php echo(count($file)); ?>
<?php echo (count($file)); ?>
</span>
<span class="mt12 label label-important none" id="count_num">已更新0个页面 进度0%</span>
<form class="form-search" id="path_search" action="#" method="post">
<input type="text" placeholder="输入路径删选,例如:/tours/。" value="<?php if (isset($_POST['p'])) {
echo($_POST['p']);
}?>" class="input-medium search-query" name="p" />
echo ($_POST['p']);
} ?>" class="input-medium search-query" name="p" />
<button type="submit" class="btn">筛选</button>
</form>
<a id="update" class="btn mr10 btn-info">更新</a>
@ -195,36 +195,36 @@
</thead>
<tbody class="data_group">
<?php $c = 0; ?>
<?php foreach ($file as $key => $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++;
?>
<?php foreach ($file as $key => $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++;
?>
<tr class="data">
<td>
<?php echo($c); ?>
<?php echo ($c); ?>
</td>
<?php if (strlen($_it) > 100) {?>
<td class="file" title="<?php echo($_it); ?>">
<?php echo(substr($_it, 0, 40)); ?>..........
<?php echo(substr($_it, -35)); ?>
<?php if (strlen($_it) > 100) { ?>
<td class="file" title="<?php echo ($_it); ?>">
<?php echo (substr($_it, 0, 40)); ?>..........
<?php echo (substr($_it, -35)); ?>
</td>
<?php } else {?>
<td class="file" title="<?php echo($_it); ?>">
<?php echo($_it); ?>
<?php } else { ?>
<td class="file" title="<?php echo ($_it); ?>">
<?php echo ($_it); ?>
</td>
<?php }?>
<?php } ?>
<td>
<?php echo(isset($file_time[$it]) ? $file_time[$it] : 'bad file'); ?>
<?php echo (isset($file_time[$it]) ? $file_time[$it] : 'bad file'); ?>
</td>
<td class="msg_wait">无操作</td>
</tr>
<?php }?>
<?php } ?>
</tbody>
</table>
</div>

Loading…
Cancel
Save