easyiit_auto_cache_html.php
6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
/*
Plugin Name: 全静态插件
Plugin URI: #
Description: 全静态插件 Globalso.com
Version: 6.0
Author: #
date:2019-09-04
Author URI:#
*/
/*ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)');
require_once(ABSPATH . 'wp-admin/includes/file.php');
if ( ! defined( 'EACH_PLUGIN_DIR' ) )
define( 'EACH_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) );
if ( ! defined( 'EACH_PLUGIN_URL' ) )
define( 'EACH_PLUGIN_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
$script_uri = rtrim( "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"] ,"/");
$home_path = get_home_path();
$page_posts = get_option('posts_per_page');
$home_url_length = strlen ( get_option ( 'home' ) . "/" );
$cache_update=array();
if (get_option ( 'permalink_structure' ) == "")
define ( 'eac_nonpermanent', true );
else
define ( 'eac_nonpermanent', false );
require_once EACH_PLUGIN_DIR . '/inc/easyiit_auto_cache_html.class.php';
require_once EACH_PLUGIN_DIR . '/inc/functions.php';
add_action('admin_menu', 'cache_html_create');
function cache_html_create() {
add_menu_page('生成全站静态', '生成全站静态', 7, 'cache_html_create');
add_submenu_page('cache_html_create', '批量生成全站静态', '批量生成全站静态', 7, 'cache_html_create', array('easyiit_auto_cache_html','html_create_form_init'));
}
add_action('get_home_url',array('easyiit_auto_cache_html','cache_home_url'));
add_action('get_cat_url',array('easyiit_auto_cache_html','cache_cat_url'));
add_action('get_posts_url',array('easyiit_auto_cache_html','cache_posts_url'));
add_action('get_pages_url',array('easyiit_auto_cache_html','cache_pages_url'));
add_action('get_tags_url',array('easyiit_auto_cache_html','cache_tags_url'));
add_action('edit_post', array('easyiit_auto_cache_html','edit_post_static_html'), 10 );
add_action('delete_post', array('easyiit_auto_cache_html','delete_post_static_html'), 10 );
add_action('save_post', array('easyiit_auto_cache_html','save_post_static_html_home'), 10 );
$auto_cache = get_option('eac_auto_cache');
if($auto_cache==1){
add_action('save_post', array('easyiit_auto_cache_html','save_post_static_html'), 10 );
}
function easyiit_make_cache_html(){
global $wp;
$file = 'cache_flie_url.php';
$cache_type = $_GET['cache_type'];
if(file_exists(EACH_PLUGIN_DIR."/cache/".$file)){
include EACH_PLUGIN_DIR."/cache/".$file;
$eac_all_refresh_cache = $cache_html[$cache_type];
}else{
easyiit_auto_cache_html::update_cache();
if(file_exists(EACH_PLUGIN_DIR."/cache/".$file)){
include EACH_PLUGIN_DIR."/cache/".$file;
$eac_all_refresh_cache = $cache_html[$cache_type];
}else{
exit();
}
}
$total = count($eac_all_refresh_cache);
$k=1;
$t = date("Y-m-d H:i:s");
if(!$_GET['total']&&!$_GET['num']){
$ret['total'] = $total;
$ret['num'] = 0;
$ret['next_num'] = $ret['num']+1;
$ret['file'] = $file = "获取数据中...";
}else{
$ret['total'] = $total;
$ret['num'] = $_GET['num'];
if($_GET['total']==$_GET['num']){
$ret['next_num'] = -1;
}else{
$ret['next_num'] = $_GET['num']+1;
}
$ret['file'] = $file = $eac_all_refresh_cache[$ret['num']]['file'];
$url = $eac_all_refresh_cache[$ret['num']]['url'];
$ret['url'] = $url;
if(file_exists(ABSPATH.$file)){
del_dir_and_file(ABSPATH.$file);
}
ob_start();
echo get_static_content($url);
$data = ob_get_contents();
if($data){
$data = $data."<!--Globalso.com - Static Page Time: $t-->";
}
ob_clean();
$dir = ABSPATH.dirname($file);
if(!is_dir($dir)) {
mkdir($dir, 0777,1);
}
if($data){
$strlen = file_put_contents(ABSPATH.$file, $data);
}
@chmod($file,0777);
}
echo json_encode($ret);
exit();
}
add_action( 'wp_ajax_easyiit_make_cache_html', 'easyiit_make_cache_html' );
function easyiit_unset_cache_html(){
global $wp;
$cache_type = $_GET['cache_type'];
if(file_exists(EACH_PLUGIN_DIR."/cache/cache_flie_url.php")&&file_exists(EACH_PLUGIN_DIR."/cache/cache_dir.php")){
include EACH_PLUGIN_DIR."/cache/cache_flie_url.php";
$eac_all_refresh_cache = $cache_html[$cache_type];
include EACH_PLUGIN_DIR."/cache/cache_dir.php";
$eac_all_refresh_dir_cache = $cache_dir[$cache_type];
}else{
easyiit_auto_cache_html::update_cache();
include EACH_PLUGIN_DIR."/cache/cache_flie_url.php";
$eac_all_refresh_cache = $cache_html[$cache_type];
include EACH_PLUGIN_DIR."/cache/cache_dir.php";
$eac_all_refresh_dir_cache = $cache_dir[$cache_type];
}
if($cache_type=='index'||$cache_type=='post'){
$eac_all_refresh_arr = $eac_all_refresh_cache;
}else{
$eac_all_refresh_arr = $eac_all_refresh_dir_cache;
}
if(!is_array($eac_all_refresh_arr)){
return;
}
$k=1;
$eac_all_refresh = array();
foreach($eac_all_refresh_arr as $val){
$eac_all_refresh[$k]=$val['file'];
$k++;
}
$total = count($eac_all_refresh);
if(!$_GET['total']&&!$_GET['num']){
$ret['total'] = $total;
$ret['num'] = $ret['next_num'] = 1;
$ret['file'] = $file = "获取数据中...";
}else{
$ret['total'] = $total;
$num = $ret['num'] = $_GET['num'];
if($_GET['total']==$_GET['num']){
$ret['next_num'] = -1;
}else{
$ret['next_num'] = $_GET['num']+1;
}
if($num==-1||!$num){
$ret['file'] = "跳转下一分类";
echo json_encode($ret);
exit();
}
$file = ABSPATH.$eac_all_refresh[$num];
if(del_dir_and_file($file, true)){
$t_res ='-删除成功';
$ret['file'] = $file.$t_res;
}else{
$t_res ='-删除失败';
$ret['file'] = $file.$t_res;
}
}
echo json_encode($ret);
exit();
}
add_action( 'wp_ajax_easyiit_unset_cache_html', 'easyiit_unset_cache_html' );
//更新链接接口 并更新首页
add_action( 'wp_ajax_nopriv_easyiit_update_cache', 'easyiit_update_cache' );
add_action( 'wp_ajax_easyiit_update_cache', 'easyiit_update_cache' );
function easyiit_update_cache(){
global $post, $cache_update, $page_posts, $home_url_length;
easyiit_auto_cache_html::update_cache();
$cur_time = time();
if(file_exists(__DIR__.'/cache/cache_flie_url.php')){
$utime = filemtime(__DIR__.'/cache/cache_flie_url.php');
if(abs($utime-$cur_time) < 60){
easyiit_auto_cache_html::make_html('index.html',get_option ( 'home' ) . "/index.php");
echo 200;exit;
}else{
echo 1;exit;
}
}else{
echo 2;exit;
}
}*/
function ppm_fixe_trailingslash($url, $type){
if ('single' === $type){
return $url;
}
return trailingslashit($url);
}
add_filter('user_trailingslashit', 'ppm_fixe_trailingslash', 10, 2);
?>