Version Description
Download this release
Release Info
Developer | rtcamp |
Plugin | Nginx Helper |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- admin/admin.php +318 -0
- admin/assets/logo.png +0 -0
- admin/assets/nginx-icon-32x32.png +0 -0
- admin/assets/nginx.js +8 -0
- admin/assets/rtp-social-icons-32-32.png +0 -0
- admin/assets/style.css +51 -0
- admin/install.php +113 -0
- compatibility.php +36 -0
- nginx.php +336 -0
- purger.php +708 -0
- readme.txt +28 -0
admin/admin.php
ADDED
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace rtCamp\WP\Nginx{
|
3 |
+
class Admin{
|
4 |
+
|
5 |
+
function __construct() {
|
6 |
+
if(is_multisite()){
|
7 |
+
add_action('network_admin_menu', array (&$this, 'add_network_menu'));
|
8 |
+
}else{
|
9 |
+
add_action('admin_menu', array (&$this, 'add_menu') );
|
10 |
+
}
|
11 |
+
add_action('admin_print_scripts', array(&$this, 'load_scripts') );
|
12 |
+
add_action('admin_print_styles', array(&$this, 'load_styles') );
|
13 |
+
}
|
14 |
+
|
15 |
+
function add_menu() {
|
16 |
+
add_submenu_page( 'options-general.php', 'Nginx', __( 'Nginx', 'rt_wp_nginx_helper' ), 'install_plugins', 'nginx', array (&$this, 'show_menu') );
|
17 |
+
//add_submenu_page($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function)
|
18 |
+
}
|
19 |
+
|
20 |
+
function add_network_menu() {
|
21 |
+
add_submenu_page( 'settings.php', 'Nginx', __( 'Nginx', 'rt_wp_nginx_helper' ), 'install_plugins', 'nginx', array (&$this, 'show_menu'));
|
22 |
+
}
|
23 |
+
|
24 |
+
// load the script for the defined page and load only this code
|
25 |
+
function show_menu() {
|
26 |
+
|
27 |
+
global $rt_wp_nginx_helper;
|
28 |
+
|
29 |
+
$required_page = $_GET['page'];
|
30 |
+
switch ($required_page) {
|
31 |
+
|
32 |
+
default :
|
33 |
+
|
34 |
+
$update = 0;
|
35 |
+
$error_time = false;
|
36 |
+
$error_log_filesize = false;
|
37 |
+
$rt_wp_nginx_helper->options['enable_purge'] = (isset($_POST['enable_purge']) and ($_POST['enable_purge'] == 1) ) ? 1 : 0;
|
38 |
+
$rt_wp_nginx_helper->options['enable_map'] = (isset($_POST['enable_map']) and ($_POST['enable_map'] == 1) ) ? 1 : 0;
|
39 |
+
$rt_wp_nginx_helper->options['enable_log'] = (isset($_POST['enable_log']) and ($_POST['enable_log'] == 1) ) ? 1 : 0;
|
40 |
+
|
41 |
+
if ( isset($_POST['is_submit']) && ($_POST['is_submit'] == 1) ) {
|
42 |
+
if(!(!is_network_admin() && is_multisite())) {
|
43 |
+
if($rt_wp_nginx_helper->options['enable_log'] ){
|
44 |
+
if ( isset($_POST['log_level']) && !empty($_POST['log_level']) && $_POST['log_level']!='' ){
|
45 |
+
$rt_wp_nginx_helper->options['log_level'] = $_POST['log_level'];
|
46 |
+
}else{
|
47 |
+
$rt_wp_nginx_helper->options['log_level']='INFO';
|
48 |
+
}
|
49 |
+
if ( isset($_POST['log_filesize']) && !empty($_POST['log_filesize']) && $_POST['log_filesize']!='' ){
|
50 |
+
if ( (!is_numeric($_POST['log_filesize'])) || (empty($_POST['log_filesize'])) ) {
|
51 |
+
$error_log_filesize = "Log file size must be a number";
|
52 |
+
} else {
|
53 |
+
$rt_wp_nginx_helper->options['log_filesize'] = $_POST['log_filesize'];
|
54 |
+
}
|
55 |
+
}else{
|
56 |
+
$rt_wp_nginx_helper->options['log_filesize'] = 5;
|
57 |
+
}
|
58 |
+
}
|
59 |
+
if($rt_wp_nginx_helper->options['enable_map']){
|
60 |
+
$rt_wp_nginx_helper->update_map();
|
61 |
+
}
|
62 |
+
|
63 |
+
}
|
64 |
+
if($rt_wp_nginx_helper->options['enable_purge'] ){
|
65 |
+
|
66 |
+
$rt_wp_nginx_helper->options['purge_homepage_on_edit'] = (isset($_POST['purge_homepage_on_edit']) and ($_POST['purge_homepage_on_edit'] == 1) ) ? 1 : 0;
|
67 |
+
$rt_wp_nginx_helper->options['purge_homepage_on_del'] = (isset($_POST['purge_homepage_on_del']) and ($_POST['purge_homepage_on_del'] == 1) ) ? 1 : 0;
|
68 |
+
|
69 |
+
$rt_wp_nginx_helper->options['purge_archive_on_edit'] = (isset($_POST['purge_archive_on_edit']) and ($_POST['purge_archive_on_edit'] == 1) ) ? 1 : 0;
|
70 |
+
$rt_wp_nginx_helper->options['purge_archive_on_del'] = (isset($_POST['purge_archive_on_del']) and ($_POST['purge_archive_on_del'] == 1) ) ? 1 : 0;
|
71 |
+
|
72 |
+
$rt_wp_nginx_helper->options['purge_archive_on_new_comment'] = (isset($_POST['purge_archive_on_new_comment']) and ($_POST['purge_archive_on_new_comment'] == 1) ) ? 1 : 0;
|
73 |
+
$rt_wp_nginx_helper->options['purge_archive_on_deleted_comment'] = (isset($_POST['purge_archive_on_deleted_comment']) and ($_POST['purge_archive_on_deleted_comment'] == 1) ) ? 1 : 0;
|
74 |
+
|
75 |
+
$rt_wp_nginx_helper->options['purge_page_on_mod'] = (isset($_POST['purge_page_on_mod']) and ($_POST['purge_page_on_mod'] == 1) ) ? 1 : 0;
|
76 |
+
$rt_wp_nginx_helper->options['purge_page_on_new_comment'] = (isset($_POST['purge_page_on_new_comment']) and ($_POST['purge_page_on_new_comment'] == 1) ) ? 1 : 0;
|
77 |
+
$rt_wp_nginx_helper->options['purge_page_on_deleted_comment'] = (isset($_POST['purge_page_on_deleted_comment']) and ($_POST['purge_page_on_deleted_comment'] == 1) ) ? 1 : 0;
|
78 |
+
|
79 |
+
}
|
80 |
+
update_option( "rt_wp_nginx_helper_options", $rt_wp_nginx_helper->options );
|
81 |
+
|
82 |
+
|
83 |
+
$update = 1;
|
84 |
+
}
|
85 |
+
$rt_wp_nginx_helper->options = get_option("rt_wp_nginx_helper_options");
|
86 |
+
|
87 |
+
|
88 |
+
?>
|
89 |
+
|
90 |
+
<div class="wrap">
|
91 |
+
|
92 |
+
<div class="icon32" id="icon-options-nginx"><br /></div>
|
93 |
+
<h2>Nginx Settings</h2>
|
94 |
+
<div id="content_block" class="align_left">
|
95 |
+
<form id="post_form" method="post" action="#" name="smart_http_expire_form">
|
96 |
+
<?php if(!(!is_network_admin() && is_multisite())){ ?>
|
97 |
+
|
98 |
+
<input type="hidden" name="is_submit" value="1" />
|
99 |
+
|
100 |
+
<h3>Plugin Options</h3>
|
101 |
+
|
102 |
+
<table class="form-table">
|
103 |
+
<tr valign="top">
|
104 |
+
<td>
|
105 |
+
<label for="enable_purge"><input type="checkbox" value="1" id="enable_purge" name="enable_purge"<?php checked( $rt_wp_nginx_helper->options['enable_purge'], 1 ); ?>>Enable Cache Purge (requires external settings for nginx).</label><br />
|
106 |
+
<?php if(is_network_admin()){ ?>
|
107 |
+
<label for="enable_map"><input type="checkbox" value="1" id="enable_map" name="enable_map"<?php checked( $rt_wp_nginx_helper->options['enable_map'], 1 ); ?>>Enable Nginx Map.</label><br />
|
108 |
+
<?php } ?>
|
109 |
+
<label for="enable_log"><input type="checkbox" value="1" id="enable_log" name="enable_log"<?php checked( $rt_wp_nginx_helper->options['enable_log'], 1 ); ?>>Enable Logging</label><br />
|
110 |
+
</td>
|
111 |
+
</tr>
|
112 |
+
</table>
|
113 |
+
|
114 |
+
<?php
|
115 |
+
if($rt_wp_nginx_helper->options['enable_purge']!=false){
|
116 |
+
?>
|
117 |
+
<h3>Purging Options</h3>
|
118 |
+
|
119 |
+
<table class="form-table rtnginx-table">
|
120 |
+
<tr valign="top">
|
121 |
+
<th scope="row"><h4>Purge Homepage:</h4></th>
|
122 |
+
<td>
|
123 |
+
<fieldset>
|
124 |
+
<legend class="screen-reader-text"><span> when a post/page/custom post is modified or added.</span></legend>
|
125 |
+
<label for="purge_homepage_on_edit"><input type="checkbox" value="1" id="purge_homepage_on_edit" name="purge_homepage_on_edit"<?php checked( $rt_wp_nginx_helper->options['purge_homepage_on_edit'], 1 ); ?>> when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.</label><br />
|
126 |
+
</fieldset>
|
127 |
+
<fieldset>
|
128 |
+
<legend class="screen-reader-text"><span> when an existing post/page/custom post is modified.</span></legend>
|
129 |
+
<label for="purge_homepage_on_del"><input type="checkbox" value="1" id="purge_homepage_on_del" name="purge_homepage_on_del"<?php checked( $rt_wp_nginx_helper->options['purge_homepage_on_del'], 1 ); ?>> when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>.</label><br />
|
130 |
+
</fieldset>
|
131 |
+
</td>
|
132 |
+
</tr>
|
133 |
+
</table>
|
134 |
+
<table class="form-table rtnginx-table">
|
135 |
+
<tr valign="top">
|
136 |
+
<th scope="row">
|
137 |
+
<h4>Purge Archives:</h4>
|
138 |
+
<small>(date, category, tag, author, custom taxonomies)</small>
|
139 |
+
</th>
|
140 |
+
<td>
|
141 |
+
<fieldset>
|
142 |
+
<legend class="screen-reader-text"><span> when an post/page/custom post is modified or added.</span></legend>
|
143 |
+
<label for="purge_archive_on_edit"><input type="checkbox" value="1" id="purge_archive_on_edit" name="purge_archive_on_edit"<?php checked( $rt_wp_nginx_helper->options['purge_archive_on_edit'], 1 ); ?>> when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.</label><br />
|
144 |
+
</fieldset>
|
145 |
+
<fieldset>
|
146 |
+
<legend class="screen-reader-text"><span> when an existing post/page/custom post is trashed.</span></legend>
|
147 |
+
<label for="purge_archive_on_del"><input type="checkbox" value="1" id="purge_archive_on_del" name="purge_archive_on_del"<?php checked( $rt_wp_nginx_helper->options['purge_archive_on_del'], 1 ); ?>> when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>.</label><br />
|
148 |
+
</fieldset>
|
149 |
+
<br />
|
150 |
+
<fieldset>
|
151 |
+
<legend class="screen-reader-text"><span> when a comment is approved/published.</span></legend>
|
152 |
+
<label for="purge_archive_on_new_comment"><input type="checkbox" value="1" id="purge_archive_on_new_comment" name="purge_page_on_new_comment"<?php checked( $rt_wp_nginx_helper->options['purge_archive_on_new_comment'], 1 ); ?>> when a <strong>comment</strong> is <strong>approved/published</strong>.</label><br />
|
153 |
+
</fieldset>
|
154 |
+
<fieldset>
|
155 |
+
<legend class="screen-reader-text"><span> when a comment is unapproved/deleted.</span></legend>
|
156 |
+
<label for="purge_archive_on_deleted_comment"><input type="checkbox" value="1" id="purge_archive_on_deleted_comment" name="purge_archive_on_deleted_comment"<?php checked( $rt_wp_nginx_helper->options['purge_archive_on_deleted_comment'], 1 ); ?>> when a <strong>comment</strong> is <strong>unapproved/deleted</strong>.</label><br />
|
157 |
+
</fieldset>
|
158 |
+
|
159 |
+
</td>
|
160 |
+
</tr>
|
161 |
+
</table>
|
162 |
+
<table class="form-table rtnginx-table">
|
163 |
+
<tr valign="top">
|
164 |
+
<th scope="row">
|
165 |
+
<h4>Purge Post/Page/Custom Post Type:</h4>
|
166 |
+
</th>
|
167 |
+
<td>
|
168 |
+
<fieldset>
|
169 |
+
<legend class="screen-reader-text"><span> when a post/page/custom post is published.</span></legend>
|
170 |
+
<label for="purge_page_on_mod"><input type="checkbox" value="1" id="purge_page_on_mod" name="purge_page_on_mod"<?php checked( $rt_wp_nginx_helper->options['purge_page_on_mod'], 1 ); ?>> when a <strong>post</strong> is <strong>published</strong>.</label><br />
|
171 |
+
</fieldset>
|
172 |
+
<fieldset>
|
173 |
+
<legend class="screen-reader-text"><span> when a comment is approved/published.</span></legend>
|
174 |
+
<label for="purge_page_on_new_comment"><input type="checkbox" value="1" id="purge_page_on_new_comment" name="purge_page_on_new_comment"<?php checked( $rt_wp_nginx_helper->options['purge_page_on_new_comment'], 1 ); ?>> when a <strong>comment</strong> is <strong>approved/published</strong>.</label><br />
|
175 |
+
</fieldset>
|
176 |
+
<fieldset>
|
177 |
+
<legend class="screen-reader-text"><span> when a comment is unapproved/deleted.</span></legend>
|
178 |
+
<label for="purge_page_on_deleted_comment"><input type="checkbox" value="1" id="purge_page_on_deleted_comment" name="purge_page_on_deleted_comment"<?php checked( $rt_wp_nginx_helper->options['purge_page_on_deleted_comment'], 1 ); ?>> when a <strong>comment</strong> is <strong>unapproved/deleted</strong>.</label><br />
|
179 |
+
</fieldset>
|
180 |
+
</td>
|
181 |
+
</tr>
|
182 |
+
</table>
|
183 |
+
|
184 |
+
<?php
|
185 |
+
}
|
186 |
+
if(is_network_admin() && $rt_wp_nginx_helper->options['enable_map']!=false){
|
187 |
+
?>
|
188 |
+
<h3>Nginx Map</h3>
|
189 |
+
<?php if (!is_writable(RT_WP_NGINX_HELPER_PATH .'map.conf')) { ?>
|
190 |
+
<span class="error fade" style="display : block"><p><?php printf (__("Can't write on map file.<br /><br />Check you have write permission on <strong>%s</strong>", "rt_wp_nginx_helper"), RT_WP_NGINX_HELPER_PATH .'map.conf'); ?></p></span>
|
191 |
+
<?php } ?>
|
192 |
+
|
193 |
+
<table class="form-table rtnginx-table">
|
194 |
+
<tr>
|
195 |
+
<th>
|
196 |
+
Nginx Map path to include in nginx settings<br />
|
197 |
+
<small>(recommended)</small>
|
198 |
+
</th>
|
199 |
+
<td>
|
200 |
+
<?php echo RT_WP_NGINX_HELPER_PATH.'map.conf'; ?>
|
201 |
+
</td>
|
202 |
+
</tr>
|
203 |
+
<tr>
|
204 |
+
<th>
|
205 |
+
Or,<br />
|
206 |
+
Text to manually copy and paste in nginx settings<br />
|
207 |
+
<small>(if your network is small and new sites are not added frequently)</small>
|
208 |
+
</th>
|
209 |
+
<td>
|
210 |
+
<pre id="map"><?php echo $rt_wp_nginx_helper->get_map() ?></pre>
|
211 |
+
</td>
|
212 |
+
</tr>
|
213 |
+
</table>
|
214 |
+
<?php } ?>
|
215 |
+
|
216 |
+
<?php
|
217 |
+
if($rt_wp_nginx_helper->options['enable_log']!=false){
|
218 |
+
?>
|
219 |
+
<h3>Logging</h3>
|
220 |
+
|
221 |
+
<?php if (!is_writable(RT_WP_NGINX_HELPER_PATH .'nginx.log')) { ?>
|
222 |
+
<span class="error fade" style="display : block"><p><?php printf (__("Can't write on log file.<br /><br />Check you have write permission on <strong>%s</strong>", "rt_wp_nginx_helper"), RT_WP_NGINX_HELPER_PATH .'nginx.log'); ?></p></span>
|
223 |
+
<?php } ?>
|
224 |
+
|
225 |
+
<table class="form-table rtnginx-table">
|
226 |
+
<tbody>
|
227 |
+
<tr>
|
228 |
+
<th><label for="rt_wp_nginx_helper_logs_path"><?php _e('Logs path', 'rt_wp_nginx_helper'); ?></label></th>
|
229 |
+
<td><?php echo RT_WP_NGINX_HELPER_PATH ?>nginx.log</td>
|
230 |
+
</tr>
|
231 |
+
<tr>
|
232 |
+
<th><label for="rt_wp_nginx_helper_logs_link"><?php _e('View Log', 'rt_wp_nginx_helper'); ?></label></th>
|
233 |
+
<td><a target="_blank" href="<?php echo RT_WP_NGINX_HELPER_URL ?>nginx.log">Log</a></td>
|
234 |
+
</tr>
|
235 |
+
|
236 |
+
<tr>
|
237 |
+
<th><label for="rt_wp_nginx_helper_log_level"><?php _e('Log level', 'rt_wp_nginx_helper'); ?></label></th>
|
238 |
+
<td>
|
239 |
+
<select name="log_level">
|
240 |
+
<option value="NONE"<?php selected( $rt_wp_nginx_helper->options['log_level'],'NONE' ); ?>><?php _e('None', 'rt_wp_nginx_helper'); ?></option>
|
241 |
+
<option value="INFO"<?php selected( $rt_wp_nginx_helper->options['log_level'],'INFO' ); ?>><?php _e('Info', 'rt_wp_nginx_helper'); ?></option>
|
242 |
+
<option value="WARNING"<?php selected( $rt_wp_nginx_helper->options['log_level'],'WARNING' ); ?>><?php _e('Warning', 'rt_wp_nginx_helper'); ?></option>
|
243 |
+
<option value="ERROR"<?php selected( $rt_wp_nginx_helper->options['log_level'],'ERROR' ); ?>><?php _e('Error', 'rt_wp_nginx_helper'); ?></option>
|
244 |
+
</select>
|
245 |
+
</td>
|
246 |
+
</tr>
|
247 |
+
|
248 |
+
<tr>
|
249 |
+
<th><label for="log_filesize"><?php _e('Max log file size', 'rt_wp_nginx_helper'); ?></label></th>
|
250 |
+
<td>
|
251 |
+
<input id="log_filesize" class="small-text" type="text" name="log_filesize" value="<?php echo $rt_wp_nginx_helper->options['log_filesize']?>" /> Mb
|
252 |
+
<?php if ($error_log_filesize) { ?>
|
253 |
+
<span class="error fade" style="display : block"><p><strong><?php echo $error_log_filesize; ?></strong></p></span>
|
254 |
+
<?php } ?>
|
255 |
+
</td>
|
256 |
+
</tr>
|
257 |
+
</tbody>
|
258 |
+
</table>
|
259 |
+
|
260 |
+
<br />
|
261 |
+
<?php } ?>
|
262 |
+
<?php } ?>
|
263 |
+
|
264 |
+
<p class="submit">
|
265 |
+
<input type="submit" name="smart_http_expire_save" class="button-primary" value="Save" />
|
266 |
+
</p>
|
267 |
+
</form>
|
268 |
+
</div>
|
269 |
+
<div id="rtads" class="metabox-holder align_left">
|
270 |
+
<?php $this->default_admin_sidebar(); ?>
|
271 |
+
</div>
|
272 |
+
</div>
|
273 |
+
<?php
|
274 |
+
break;
|
275 |
+
}
|
276 |
+
}
|
277 |
+
function default_admin_sidebar() {
|
278 |
+
?>
|
279 |
+
<div class="postbox" id="support">
|
280 |
+
<div title="<?php _e('Click to toggle', 'bp-media'); ?>" class="handlediv"><br /></div>
|
281 |
+
<h3 class="hndle"><span><?php _e('Need Help?', 'bp-media'); ?></span></h3>
|
282 |
+
<div class="inside"><p><?php printf(__(' Please use our <a href="%s">free support forum</a>.<br/><span class="bpm-aligncenter">OR</span><br/>
|
283 |
+
<a href="%s">Hire us!</a> for wordpress on nginx solutions ', 'rt-nginx'), 'http://rtcamp.com/support/forum/wordpress-nginx/','http://rtcamp.com/wordpress-nginx/'); ?>.</p></div>
|
284 |
+
</div>
|
285 |
+
<div class="postbox" id="social">
|
286 |
+
<div title="<?php _e('Click to toggle', 'bp-media'); ?>" class="handlediv"><br /></div>
|
287 |
+
<h3 class="hndle"><span><?php _e('Getting Social is Good', 'bp-media'); ?></span></h3>
|
288 |
+
<div class="inside" style="text-align:center;">
|
289 |
+
<a href="<?php printf('%s', 'http://www.facebook.com/rtCamp.solutions/'); ?>" target="_blank" title="<?php _e('Become a fan on Facebook', 'bp-media'); ?>" class="rt-nginx-facebook rt-nginx-social"><?php _e('Facebook', 'bp-media'); ?></a>
|
290 |
+
<a href="<?php printf('%s', 'https://twitter.com/rtcamp/'); ?>" target="_blank" title="<?php _e('Follow us on Twitter', 'bp-media'); ?>" class="rt-nginx-twitter rt-nginx-social"><?php _e('Twitter', 'bp-media'); ?></a>
|
291 |
+
<a href="<?php printf('%s', 'http://feeds.feedburner.com/rtcamp/'); ?>" target="_blank" title="<?php _e('Subscribe to our feeds', 'bp-media'); ?>" class="rt-nginx-rss rt-nginx-social"><?php _e('RSS Feed', 'bp-media'); ?></a>
|
292 |
+
</div>
|
293 |
+
</div>
|
294 |
+
|
295 |
+
<div class="postbox" id="latest_news">
|
296 |
+
<div title="<?php _e('Click to toggle', 'bp-media'); ?>" class="handlediv"><br /></div>
|
297 |
+
<h3 class="hndle"><span><?php _e('Latest News', 'bp-media'); ?></span></h3>
|
298 |
+
<div class="inside"><img src ="<?php echo admin_url(); ?>/images/wpspin_light.gif" /> Loading...</div>
|
299 |
+
</div><?php
|
300 |
+
}
|
301 |
+
|
302 |
+
|
303 |
+
|
304 |
+
function load_styles(){
|
305 |
+
wp_enqueue_style('rt-nginx-admin-css', plugins_url('admin/assets/style.css', dirname(__FILE__)));
|
306 |
+
}
|
307 |
+
|
308 |
+
|
309 |
+
|
310 |
+
|
311 |
+
function load_scripts(){
|
312 |
+
$admin_js = trailingslashit(site_url()).'?get_feeds=1';
|
313 |
+
wp_enqueue_script('nginx-js',plugins_url('admin/assets/nginx.js', dirname(__FILE__)));
|
314 |
+
wp_localize_script('nginx-js','news_url',$admin_js);
|
315 |
+
}
|
316 |
+
}
|
317 |
+
}
|
318 |
+
?>
|
admin/assets/logo.png
ADDED
Binary file
|
admin/assets/nginx-icon-32x32.png
ADDED
Binary file
|
admin/assets/nginx.js
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(document).ready(function(){
|
2 |
+
var news_section = jQuery('#latest_news');
|
3 |
+
if(news_section.length>0){
|
4 |
+
jQuery.get(news_url,function(data){
|
5 |
+
news_section.find('.inside').html(data);
|
6 |
+
});
|
7 |
+
}
|
8 |
+
});
|
admin/assets/rtp-social-icons-32-32.png
ADDED
Binary file
|
admin/assets/style.css
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
table.rtnginx-table{
|
2 |
+
padding: 10px;
|
3 |
+
border: 1px #CCC solid;
|
4 |
+
width: 95%;
|
5 |
+
margin-bottom: 10px;
|
6 |
+
}
|
7 |
+
pre#map{
|
8 |
+
background: #e5e5e5 none;
|
9 |
+
border-radius:10px;
|
10 |
+
padding:10px;
|
11 |
+
}
|
12 |
+
#icon-options-nginx{
|
13 |
+
background:transparent url(nginx-icon-32x32.png) center center no-repeat;
|
14 |
+
}
|
15 |
+
div#content_block form { padding-left: 25px }
|
16 |
+
div#content_block { width: 70% }
|
17 |
+
div#rtads{ width:30%}
|
18 |
+
.align_left, .alignleft {
|
19 |
+
float: left;
|
20 |
+
}
|
21 |
+
|
22 |
+
#social .inside a {
|
23 |
+
background: url(rtp-social-icons-32-32.png) no-repeat;
|
24 |
+
display: inline-block;
|
25 |
+
height: 35px;
|
26 |
+
margin: 0 0 0 9px;
|
27 |
+
padding: 0;
|
28 |
+
text-indent: -9999px;
|
29 |
+
text-transform: uppercase;
|
30 |
+
width: 35px;
|
31 |
+
}
|
32 |
+
#social .inside a.rt-nginx-facebook {
|
33 |
+
background-position: 0 0;
|
34 |
+
}
|
35 |
+
#social .inside a.rt-nginx-facebook:hover {
|
36 |
+
background-position: 0 -44px;
|
37 |
+
}
|
38 |
+
#social .inside a.rt-nginx-twitter {
|
39 |
+
background-position: -44px 0;
|
40 |
+
}
|
41 |
+
#social .inside a.rt-nginx-twitter:hover {
|
42 |
+
background-position: -44px -44px;
|
43 |
+
}
|
44 |
+
#social .inside a.rt-nginx-rss {
|
45 |
+
background-position: -88px 0;
|
46 |
+
}
|
47 |
+
#social .inside a.rt-nginx-rss:hover {
|
48 |
+
background-position: -88px -44px;
|
49 |
+
}
|
50 |
+
|
51 |
+
|
admin/install.php
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace rtCamp\WP\Nginx{
|
3 |
+
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
|
4 |
+
|
5 |
+
function rt_wp_nginx_helper_install () {
|
6 |
+
|
7 |
+
global $wp_roles, $rt_wp_nginx_helper;
|
8 |
+
|
9 |
+
if ( !current_user_can('activate_plugins') )
|
10 |
+
return;
|
11 |
+
|
12 |
+
$role = get_role('administrator');
|
13 |
+
|
14 |
+
|
15 |
+
if ( empty($role) ) {
|
16 |
+
update_site_option( "rt_wp_nginx_helper_init_check", __('Sorry, you need to be an administrator to use Nginx Helper',"rt_wp_nginx_helper") );
|
17 |
+
return;
|
18 |
+
}
|
19 |
+
|
20 |
+
$role->add_cap('Nginx Helper | Config');
|
21 |
+
$role->add_cap('Nginx Helper | Purge cache');
|
22 |
+
|
23 |
+
$rt_wp_nginx_helper_get_options = get_site_option('rt_wp_nginx_helper_global_options');
|
24 |
+
|
25 |
+
if ( empty( $rt_wp_nginx_helper_get_options ) ) {
|
26 |
+
$rt_wp_nginx_helper_get_options = rt_wp_nginx_helper_get_options();
|
27 |
+
update_site_option("rt_wp_nginx_helper_global_options", $rt_wp_nginx_helper_get_options);
|
28 |
+
}
|
29 |
+
|
30 |
+
if (is_multisite()) {
|
31 |
+
$blogs = get_blogs_of_user(true);
|
32 |
+
foreach ($blogs as $b) {
|
33 |
+
$rt_wp_nginx_helper_options = get_blog_option($b->userblog_id, 'rt_wp_nginx_helper_options');
|
34 |
+
if ( empty( $rt_wp_nginx_helper_options ) ) {
|
35 |
+
$rt_wp_nginx_helper_options = rt_wp_nginx_helper_get_options();
|
36 |
+
update_blog_option($b->userblog_id, "rt_wp_nginx_helper_options", $rt_wp_nginx_helper_options);
|
37 |
+
}
|
38 |
+
}
|
39 |
+
} else {
|
40 |
+
$rt_wp_nginx_helper_options = get_option('rt_wp_nginx_helper_options');
|
41 |
+
if ( empty( $rt_wp_nginx_helper_options ) ) {
|
42 |
+
$rt_wp_nginx_helper_options = rt_wp_nginx_helper_get_options();
|
43 |
+
update_option("rt_wp_nginx_helper_options", $rt_wp_nginx_helper_options);
|
44 |
+
}
|
45 |
+
}
|
46 |
+
wp_schedule_event(time(), 'daily', 'rt_wp_nginx_helper_check_log_file_size_daily');
|
47 |
+
|
48 |
+
}
|
49 |
+
|
50 |
+
function rt_wp_nginx_helper_uninstall() {
|
51 |
+
|
52 |
+
global $rt_wp_nginx_helper, $rt_wp_nginx_purger;
|
53 |
+
|
54 |
+
wp_clear_scheduled_hook('rt_wp_nginx_helper_check_log_file_size_daily');
|
55 |
+
|
56 |
+
delete_site_option( 'rt_wp_nginx_helper_options' );
|
57 |
+
|
58 |
+
|
59 |
+
rt_wp_nginx_helper_remove_capability('Nginx Helper | Config');
|
60 |
+
rt_wp_nginx_helper_remove_capability('Nginx Helper | Purge cache');
|
61 |
+
|
62 |
+
}
|
63 |
+
|
64 |
+
function rt_wp_nginx_helper_remove_capability($capability){
|
65 |
+
$check_order = array("subscriber", "contributor", "author", "editor", "administrator");
|
66 |
+
|
67 |
+
foreach ($check_order as $role) {
|
68 |
+
$role = get_role($role);
|
69 |
+
$role->remove_cap($capability) ;
|
70 |
+
}
|
71 |
+
|
72 |
+
}
|
73 |
+
|
74 |
+
function rt_wp_nginx_helper_get_options() {
|
75 |
+
|
76 |
+
global $rt_wp_nginx_helper;
|
77 |
+
|
78 |
+
$rt_wp_nginx_helper_get_options = array();
|
79 |
+
|
80 |
+
|
81 |
+
$rt_wp_nginx_helper_get_options['log_level'] = 'INFO';
|
82 |
+
$rt_wp_nginx_helper_get_options['log_filesize'] = 5;
|
83 |
+
|
84 |
+
$rt_wp_nginx_helper_get_options['current_db_version'] = $rt_wp_nginx_helper->db_version;
|
85 |
+
|
86 |
+
$rt_wp_nginx_helper_get_options['mobile_uncache'] = 1;
|
87 |
+
$rt_wp_nginx_helper_get_options['mobile_regexp'] = '#2.0 MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo Wii|Nitro|Nokia|Opera Mini|Palm|PlayStation Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows CE|WinWAP|YahooSeeker/M1A1-R2D2|NF-Browser|iPhone|iPod|Android|BlackBerry9530|G-TU915 Obigo|LGE VX|webOS|Nokia5800#';
|
88 |
+
|
89 |
+
$rt_wp_nginx_helper_get_options['enable_purge'] = 1;
|
90 |
+
$rt_wp_nginx_helper_get_options['enable_map'] = 0;
|
91 |
+
$rt_wp_nginx_helper_get_options['enable_log'] = 0;
|
92 |
+
|
93 |
+
$rt_wp_nginx_helper_get_options['purge_homepage_on_new'] = 1;
|
94 |
+
$rt_wp_nginx_helper_get_options['purge_homepage_on_edit'] = 1;
|
95 |
+
$rt_wp_nginx_helper_get_options['purge_homepage_on_del'] = 1;
|
96 |
+
|
97 |
+
$rt_wp_nginx_helper_get_options['purge_archive_on_new'] = 1;
|
98 |
+
$rt_wp_nginx_helper_get_options['purge_archive_on_edit'] = 1;
|
99 |
+
$rt_wp_nginx_helper_get_options['purge_archive_on_del'] = 1;
|
100 |
+
|
101 |
+
$rt_wp_nginx_helper_get_options['purge_archive_on_new_comment'] = 0;
|
102 |
+
$rt_wp_nginx_helper_get_options['purge_archive_on_deleted_comment'] = 0;
|
103 |
+
|
104 |
+
$rt_wp_nginx_helper_get_options['purge_page_on_mod'] = 1;
|
105 |
+
$rt_wp_nginx_helper_get_options['purge_page_on_new_comment'] = 1;
|
106 |
+
$rt_wp_nginx_helper_get_options['purge_page_on_deleted_comment'] = 1;
|
107 |
+
|
108 |
+
return $rt_wp_nginx_helper_get_options;
|
109 |
+
|
110 |
+
}
|
111 |
+
|
112 |
+
}
|
113 |
+
?>
|
compatibility.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace rtCamp\WP\Nginx {
|
3 |
+
class Compatibility {
|
4 |
+
protected $have_nginx;
|
5 |
+
|
6 |
+
public static function instance() {
|
7 |
+
static $self = false;
|
8 |
+
if (!$self) {
|
9 |
+
$self = new Compatibility();
|
10 |
+
}
|
11 |
+
|
12 |
+
return $self;
|
13 |
+
}
|
14 |
+
|
15 |
+
private function __construct() {
|
16 |
+
$this->have_nginx = ('nginx' == substr($_SERVER['SERVER_SOFTWARE'], 0, 5));
|
17 |
+
if ($this->have_nginx) {
|
18 |
+
add_filter('got_rewrite', array($this, 'got_rewrite'), 999);
|
19 |
+
|
20 |
+
// For compatibility with several plugins and nginx HTTPS proxying schemes
|
21 |
+
if (empty($_SERVER['HTTPS']) || 'off' == $_SERVER['HTTPS']) {
|
22 |
+
unset($_SERVER['HTTPS']);
|
23 |
+
}
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
public function got_rewrite($got) {
|
28 |
+
return true;
|
29 |
+
}
|
30 |
+
|
31 |
+
public function haveNginx() {
|
32 |
+
return $this->have_nginx;
|
33 |
+
}
|
34 |
+
}
|
35 |
+
}
|
36 |
+
?>
|
nginx.php
ADDED
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
Plugin Name: Nginx Helper
|
4 |
+
Plugin URI: http://rtcamp.com/
|
5 |
+
Description: An nginx helper that serves various functions.
|
6 |
+
Version: 1.0
|
7 |
+
Author: rtCamp
|
8 |
+
Author URI: http://rtcamp.com
|
9 |
+
Requires at least: 3.0
|
10 |
+
Tested up to: 3.4.2
|
11 |
+
*/
|
12 |
+
namespace rtCamp\WP\Nginx {
|
13 |
+
define( 'rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH', plugin_dir_path(__FILE__) );
|
14 |
+
define( 'rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_URL', plugin_dir_url(__FILE__) );
|
15 |
+
class Helper{
|
16 |
+
var $version = '1.0'; // Plugin version
|
17 |
+
var $db_version = '0.1'; // DB version, change it to show the upgrade page
|
18 |
+
var $minium_WP = '3.0';
|
19 |
+
var $minimum_PHP = '5.3';
|
20 |
+
var $options = null;
|
21 |
+
|
22 |
+
function __construct() {
|
23 |
+
|
24 |
+
if ( !$this->required_wp_version() )
|
25 |
+
if( !$this->required_php_version() )
|
26 |
+
return;
|
27 |
+
|
28 |
+
$this->load_options();
|
29 |
+
$this->define_constant();
|
30 |
+
$this->plugin_name = plugin_basename(__FILE__);
|
31 |
+
|
32 |
+
register_activation_hook( $this->plugin_name, array(&$this, 'activate') );
|
33 |
+
register_deactivation_hook( $this->plugin_name, array(&$this, 'deactivate') );
|
34 |
+
|
35 |
+
add_action( 'init', array(&$this, 'start_helper'), 15 );
|
36 |
+
|
37 |
+
}
|
38 |
+
function start_helper() {
|
39 |
+
|
40 |
+
global $rt_wp_nginx_purger;
|
41 |
+
|
42 |
+
add_action( 'publish_post', array(&$rt_wp_nginx_purger, 'purgePost'), 200, 1);
|
43 |
+
add_action( 'publish_page', array(&$rt_wp_nginx_purger, 'purgePost'), 200, 1);
|
44 |
+
add_action( 'comment_post', array(&$rt_wp_nginx_purger, 'purgePostOnComment'), 200, 1);
|
45 |
+
add_action( 'transition_comment_status', array(&$rt_wp_nginx_purger, 'purgePostOnComment'), 200, 2);
|
46 |
+
|
47 |
+
$args=array('_builtin'=>false);
|
48 |
+
$_rt_custom_post_types = get_post_types( $args );
|
49 |
+
if ( isset($post_types) && !empty($post_types) ) {
|
50 |
+
if($this->options['rt_wp_custom_post_types']==true){
|
51 |
+
foreach ( $_rt_custom_post_types as $post_type ) {
|
52 |
+
add_action( 'publish_'.trim($post_type), array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
add_action( 'transition_post_status', array(&$this, 'set_future_post_option_on_future_status'), 20, 3 );
|
59 |
+
add_action( 'delete_post', array(&$this, 'unset_future_post_option_on_delete'), 20, 1 );
|
60 |
+
|
61 |
+
add_action( 'wp_headers', array(&$rt_wp_nginx_purger, 'correctExpires'), 100, 1 );
|
62 |
+
|
63 |
+
add_action( 'nm_check_log_file_size_daily', array(&$rt_wp_nginx_purger, 'checkAndTruncateLogFile'), 100, 1 );
|
64 |
+
|
65 |
+
add_action( 'edit_attachment', array(&$rt_wp_nginx_purger, 'purgeImageOnEdit'), 100, 1 );
|
66 |
+
|
67 |
+
add_action( 'wpmu_new_blog', array(&$this, 'update_new_blog_options'), 10, 1 );
|
68 |
+
|
69 |
+
add_action( 'transition_post_status', array(&$rt_wp_nginx_purger, 'purge_on_post_moved_to_trash'), 20, 3 );
|
70 |
+
|
71 |
+
add_action( 'edit_term', array(&$rt_wp_nginx_purger, 'purge_on_term_taxonomy_edited'), 20, 3 );
|
72 |
+
add_action( 'delete_term', array(&$rt_wp_nginx_purger, 'purge_on_term_taxonomy_edited'), 20, 3 );
|
73 |
+
|
74 |
+
add_action( 'check_ajax_referer', array(&$rt_wp_nginx_purger, 'purge_on_check_ajax_referer'), 20, 2 );
|
75 |
+
|
76 |
+
}
|
77 |
+
|
78 |
+
function activate() {
|
79 |
+
include_once (RT_WP_NGINX_HELPER_PATH. 'admin/install.php');
|
80 |
+
rt_wp_nginx_helper_install();
|
81 |
+
}
|
82 |
+
|
83 |
+
function deactivate() {
|
84 |
+
include_once (RT_WP_NGINX_HELPER_PATH. 'admin/install.php');
|
85 |
+
rt_wp_nginx_helper_uninstall();
|
86 |
+
}
|
87 |
+
|
88 |
+
function define_constant() {
|
89 |
+
define('RT_WP_NGINX_HELPER_VERSION', $this->version );
|
90 |
+
define('RT_WP_NGINX_HELPER_DB_VERSION', $this->db_version );
|
91 |
+
define('RT_WP_NGINX_HELPER_FOLDER', plugin_basename( dirname(__FILE__)) );
|
92 |
+
}
|
93 |
+
|
94 |
+
function required_wp_version() {
|
95 |
+
|
96 |
+
global $wp_version;
|
97 |
+
$wp_ok = version_compare( $wp_version, $this->minium_WP, '>=' );
|
98 |
+
|
99 |
+
if ( ($wp_ok == FALSE) ) {
|
100 |
+
add_action(
|
101 |
+
'admin_notices',
|
102 |
+
create_function(
|
103 |
+
'',
|
104 |
+
'global $rt_wp_nginx_helper; printf (\'<div id="message" class="error"><p><strong>\' . __(\'Sorry, Nginx Helper requires WordPress %s or higher\', "rt_wp_nginx_helper" ) . \'</strong></p></div>\', $rt_wp_nginx_helper->minium_WP );'
|
105 |
+
)
|
106 |
+
);
|
107 |
+
return false;
|
108 |
+
}
|
109 |
+
|
110 |
+
return true;
|
111 |
+
|
112 |
+
}
|
113 |
+
function required_php_version(){
|
114 |
+
|
115 |
+
$php_ok = version_compare(PHP_VERSION, '5.3', '>=');
|
116 |
+
if ( ($php_ok == FALSE) ) {
|
117 |
+
add_action(
|
118 |
+
'admin_notices',
|
119 |
+
create_function(
|
120 |
+
'',
|
121 |
+
'global $rt_wp_nginx_helper; printf (\'<div id="message" class="error"><p><strong>\' . __(\'Sorry, Nginx Helper requires PHP %s or higher\', "rt_wp_nginx_helper" ) . \'</strong></p></div>\', $rt_wp_nginx_helper->minium_PHP );'
|
122 |
+
)
|
123 |
+
);
|
124 |
+
return false;
|
125 |
+
}
|
126 |
+
|
127 |
+
return true;
|
128 |
+
}
|
129 |
+
|
130 |
+
function load_options() {
|
131 |
+
$this->options = get_site_option( 'rt_wp_nginx_helper_options' );
|
132 |
+
}
|
133 |
+
|
134 |
+
function set_future_post_option_on_future_status($new_status, $old_status, $post) {
|
135 |
+
|
136 |
+
global $blog_id, $rt_wp_nginx_purger;
|
137 |
+
if(!$this->options['enable_purge']){
|
138 |
+
return;
|
139 |
+
}
|
140 |
+
if ( $old_status != $new_status
|
141 |
+
&& $old_status != 'inherit'
|
142 |
+
&& $new_status != 'inherit'
|
143 |
+
&& $old_status != 'auto-draft'
|
144 |
+
&& $new_status != 'auto-draft'
|
145 |
+
&& $new_status != 'publish'
|
146 |
+
&& !wp_is_post_revision( $post->ID ) ) {
|
147 |
+
$rt_wp_nginx_purger->log( "Purge post on transition post STATUS from ".$old_status." to ".$new_status );
|
148 |
+
$rt_wp_nginx_purger->purgePost($post->ID);
|
149 |
+
}
|
150 |
+
|
151 |
+
if ($new_status == 'future') {
|
152 |
+
if ( $post && $post->post_status == 'future' && ( ( $post->post_type == 'post' || $post->post_type == 'page' ) || ( in_array($post->post_type, $this->options['custom_post_types_recognized']) ) ) ) {
|
153 |
+
$rt_wp_nginx_purger->log( "Set/update future_posts option (post id = ".$post->ID." and blog id = ".$blog_id.")" );
|
154 |
+
$this->options['future_posts'][$blog_id][$post->ID] = strtotime($post->post_date_gmt)+60;
|
155 |
+
update_site_option("rt_wp_nginx_helper_global_options", $this->options);
|
156 |
+
}
|
157 |
+
}
|
158 |
+
}
|
159 |
+
|
160 |
+
function unset_future_post_option_on_delete($post_id) {
|
161 |
+
|
162 |
+
global $blog_id, $rt_wp_nginx_purger;
|
163 |
+
if(!$this->options['enable_purge']){
|
164 |
+
return;
|
165 |
+
}
|
166 |
+
if ($post_id && !wp_is_post_revision($post_id)) {
|
167 |
+
|
168 |
+
if ( isset($this->options['future_posts'][$blog_id][$post_id]) && count($this->options['future_posts'][$blog_id][$post_id]) ) {
|
169 |
+
$rt_wp_nginx_purger->log( "Unset future_posts option (post id = ".$post_id." and blog id = ".$blog_id.")" );
|
170 |
+
unset($this->options['future_posts'][$blog_id][$post_id]);
|
171 |
+
update_site_option("rt_wp_nginx_helper_global_options", $this->options);
|
172 |
+
|
173 |
+
if ( !count($this->options['future_posts'][$blog_id]) ) {
|
174 |
+
unset($this->options['future_posts'][$blog_id]);
|
175 |
+
update_site_option("rt_wp_nginx_helper_global_options", $this->options);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
}
|
179 |
+
}
|
180 |
+
|
181 |
+
function update_new_blog_options( $blog_id ) {
|
182 |
+
|
183 |
+
global $rt_wp_nginx_purger;
|
184 |
+
|
185 |
+
include_once (RT_WP_NGINX_HELPER_PATH . 'admin/install.php');
|
186 |
+
|
187 |
+
$rt_wp_nginx_purger->log( "New site added (id $blog_id)" );
|
188 |
+
|
189 |
+
$this->update_map();
|
190 |
+
|
191 |
+
$rt_wp_nginx_purger->log( "New site added to nginx map (id $blog_id)" );
|
192 |
+
|
193 |
+
$helper_options = rt_wp_nginx_helper_get_options();
|
194 |
+
|
195 |
+
update_blog_option( $blog_id, "rt_wp_nginx_helper_options", $helper_options, true );
|
196 |
+
|
197 |
+
$rt_wp_nginx_purger->log( "Default options updated for the new blog (id $blog_id)" );
|
198 |
+
|
199 |
+
}
|
200 |
+
function get_map(){
|
201 |
+
if(!$this->options['enable_map']){
|
202 |
+
return;
|
203 |
+
}
|
204 |
+
|
205 |
+
if (is_multisite()){
|
206 |
+
|
207 |
+
global $wpdb;
|
208 |
+
|
209 |
+
$rt_all_blogs = $wpdb->get_results($wpdb->prepare("SELECT blog_id, domain, path FROM " . $wpdb->blogs . " WHERE site_id = %d AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0'", $wpdb->siteid));
|
210 |
+
$wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
|
211 |
+
if($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->dmtable}'") != $wpdb->dmtable) {
|
212 |
+
$rt_domain_map_sites = $wpdb->get_results( "SELECT blog_id, domain FROM {$wpdb->dmtable} ORDER BY id DESC" );
|
213 |
+
}
|
214 |
+
$rt_nginx_map ="";
|
215 |
+
|
216 |
+
if ($rt_all_blogs)
|
217 |
+
foreach ($rt_all_blogs as $blog)
|
218 |
+
if ( SUBDOMAIN_INSTALL == "yes" )
|
219 |
+
$rt_nginx_map .= "\t" . $blog->domain . "\t" . $blog->blog_id . ";\n";
|
220 |
+
else
|
221 |
+
if ( $blog->blog_id != 1 )
|
222 |
+
$rt_nginx_map .= "\t" . $blog->path . "\t" . $blog->blog_id . ";\n";
|
223 |
+
|
224 |
+
if($rt_domain_map_sites)
|
225 |
+
foreach($rt_domain_map_sites as $site)
|
226 |
+
$rt_nginx_map .= "\t" . $site->domain . "\t" . $site->site_id . ";\n";
|
227 |
+
|
228 |
+
return $rt_nginx_map;
|
229 |
+
}
|
230 |
+
}
|
231 |
+
function update_map(){
|
232 |
+
if (is_multisite()){
|
233 |
+
$rt_nginx_map = $this->read_map();
|
234 |
+
if ($fp = fopen(RT_WP_NGINX_HELPER_PATH .'map.conf','w+')) {
|
235 |
+
fwrite($fp, $rt_nginx_map);
|
236 |
+
fclose($fp);
|
237 |
+
return true;
|
238 |
+
}
|
239 |
+
}
|
240 |
+
}
|
241 |
+
|
242 |
+
}
|
243 |
+
|
244 |
+
}
|
245 |
+
|
246 |
+
namespace{
|
247 |
+
global $current_blog;
|
248 |
+
|
249 |
+
if ( is_admin() ) {
|
250 |
+
require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH. '/admin/admin.php');
|
251 |
+
$rtwpAdminPanel = new \rtCamp\WP\Nginx\Admin();
|
252 |
+
}
|
253 |
+
|
254 |
+
require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH . 'purger.php');
|
255 |
+
|
256 |
+
require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH . 'compatibility.php');
|
257 |
+
|
258 |
+
global $rt_wp_nginx_helper,$rt_wp_nginx_purger,$rt_wp_nginx_compatibility;
|
259 |
+
$rt_wp_nginx_helper = new \rtCamp\WP\Nginx\Helper;
|
260 |
+
$rt_wp_nginx_purger = new \rtCamp\WP\Nginx\Purger;
|
261 |
+
$rt_wp_nginx_compatibility = namespace\rtCamp\WP\Nginx\Compatibility::instance();
|
262 |
+
if ($rt_wp_nginx_compatibility->haveNginx() && !function_exists('wp_redirect')) {
|
263 |
+
|
264 |
+
function wp_redirect($location, $status = 302){
|
265 |
+
$location = apply_filters('wp_redirect', $location, $status);
|
266 |
+
|
267 |
+
if (empty($location)) {
|
268 |
+
return false;
|
269 |
+
}
|
270 |
+
|
271 |
+
$status = apply_filters('wp_redirect_status', $status, $location);
|
272 |
+
if ($status < 300 || $status > 399) {
|
273 |
+
$status = 302;
|
274 |
+
}
|
275 |
+
|
276 |
+
$location = wp_sanitize_redirect($location);
|
277 |
+
header('Location: ' . $location, true, $status);
|
278 |
+
}
|
279 |
+
|
280 |
+
}
|
281 |
+
// Add settings link on plugin page
|
282 |
+
function nginx_settings_link($links) {
|
283 |
+
if(is_network_admin()){
|
284 |
+
$u='settings.php';
|
285 |
+
}else{
|
286 |
+
$u='options-general.php';
|
287 |
+
}
|
288 |
+
$settings_link = '<a href="'.$u.'?page=nginx">Settings</a>';
|
289 |
+
array_unshift($links, $settings_link);
|
290 |
+
return $links;
|
291 |
+
}
|
292 |
+
|
293 |
+
$plugin = plugin_basename(__FILE__);
|
294 |
+
if(is_multisite()){
|
295 |
+
add_filter("network_admin_plugin_action_links_$plugin", 'nginx_settings_link' );
|
296 |
+
}else{
|
297 |
+
add_filter("plugin_action_links_$plugin", 'nginx_settings_link' );
|
298 |
+
}
|
299 |
+
function get_feeds($feed_url = 'http://rtcamp.com/blog/feed/') {
|
300 |
+
// Get RSS Feed(s)
|
301 |
+
require_once( ABSPATH . WPINC . '/feed.php' );
|
302 |
+
$maxitems = 0;
|
303 |
+
// Get a SimplePie feed object from the specified feed source.
|
304 |
+
$rss = fetch_feed($feed_url);
|
305 |
+
if (!is_wp_error($rss)) { // Checks that the object is created correctly
|
306 |
+
// Figure out how many total items there are, but limit it to 5.
|
307 |
+
$maxitems = $rss->get_item_quantity(5);
|
308 |
+
|
309 |
+
// Build an array of all the items, starting with element 0 (first element).
|
310 |
+
$rss_items = $rss->get_items(0, $maxitems);
|
311 |
+
}
|
312 |
+
?>
|
313 |
+
<ul><?php
|
314 |
+
if ($maxitems == 0) {
|
315 |
+
echo '<li>' . __('No items', 'bp-media') . '.</li>';
|
316 |
+
} else {
|
317 |
+
// Loop through each feed item and display each item as a hyperlink.
|
318 |
+
foreach ($rss_items as $item) {
|
319 |
+
?>
|
320 |
+
<li>
|
321 |
+
<a href='<?php echo $item->get_permalink(); ?>' title='<?php echo __('Posted ', 'bp-media') . $item->get_date('j F Y | g:i a'); ?>'><?php echo $item->get_title(); ?></a>
|
322 |
+
</li><?php
|
323 |
+
}
|
324 |
+
}
|
325 |
+
?>
|
326 |
+
</ul><?php
|
327 |
+
}
|
328 |
+
function fetch_feeds() {
|
329 |
+
if(isset($_GET['get_feeds'])&&$_GET['get_feeds']=='1'){
|
330 |
+
get_feeds();
|
331 |
+
die();
|
332 |
+
}
|
333 |
+
}
|
334 |
+
add_action('init','fetch_feeds');
|
335 |
+
}
|
336 |
+
?>
|
purger.php
ADDED
@@ -0,0 +1,708 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace rtCamp\WP\Nginx{
|
3 |
+
class Purger {
|
4 |
+
|
5 |
+
function correctExpires($http_headers) {
|
6 |
+
|
7 |
+
global $rt_wp_nginx_helper;
|
8 |
+
|
9 |
+
$cache_ttl = $rt_wp_nginx_helper->options['cache_ttl'];
|
10 |
+
|
11 |
+
$http_headers['X-Accel-Expires'] = $cache_ttl;
|
12 |
+
|
13 |
+
if ($cache_ttl == 0) {
|
14 |
+
$http_headers['X-NGINX-CACHED'] = "NO";
|
15 |
+
} else {
|
16 |
+
$http_headers['X-NGINX-CACHED'] = "YES - ".$cache_ttl." secs";
|
17 |
+
$http_headers['X-NGINX-CACHED-AT'] = date('c');
|
18 |
+
}
|
19 |
+
|
20 |
+
return $http_headers;
|
21 |
+
|
22 |
+
}
|
23 |
+
|
24 |
+
function purgePostOnComment( $newstatus, $oldstatus, $comment ) {
|
25 |
+
|
26 |
+
global $rt_wp_nginx_helper,$blog_id;
|
27 |
+
if(!$rt_wp_nginx_helper->options['enable_purge']){
|
28 |
+
return;
|
29 |
+
}
|
30 |
+
|
31 |
+
$_post_id = $comment->comment_post_ID;
|
32 |
+
$_comment_id = $comment->comment_ID;
|
33 |
+
|
34 |
+
$this->log( "* * * * *" );
|
35 |
+
$this->log( "* Blog :: ".addslashes( get_bloginfo('name') )." ($blog_id)." );
|
36 |
+
$this->log( "* Post :: ".get_the_title($_post_id)." ($_post_id)." );
|
37 |
+
$this->log( "* Comment :: $_comment_id." );
|
38 |
+
|
39 |
+
switch ($newstatus){
|
40 |
+
case 'approve':
|
41 |
+
if($rt_wp_nginx_helper->options['purge_page_on_new_comment']==1){
|
42 |
+
$this->log( "* Comment ($_comment_id) approved. Post ($_post_id) purged." );
|
43 |
+
}
|
44 |
+
break;
|
45 |
+
case 'spam':
|
46 |
+
case 'trash':
|
47 |
+
if($rt_wp_nginx_helper->options['purge_page_on_deleted_comment']==1){
|
48 |
+
if($oldstatus=='approve'){
|
49 |
+
$this->log( "* Comment ($_comment_id) removed as ($newstatus). Post ($_post_id) purged." );
|
50 |
+
}
|
51 |
+
}
|
52 |
+
$this->log( "* * * * *" );
|
53 |
+
$this->purgePost( $_post_id );
|
54 |
+
break;
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
function purgePost($_ID) {
|
61 |
+
|
62 |
+
global $rt_wp_nginx_helper, $blog_id;
|
63 |
+
if(!$rt_wp_nginx_helper->options['enable_purge']){
|
64 |
+
return;
|
65 |
+
}
|
66 |
+
switch ( current_filter() ) {
|
67 |
+
case 'publish_post':
|
68 |
+
$this->log( "* * * * *" );
|
69 |
+
$this->log( "* Blog :: ".addslashes( get_bloginfo('name') )." ($blog_id)." );
|
70 |
+
$this->log( "* Post :: ".get_the_title($_ID)." ($_ID)." );
|
71 |
+
$this->log( "* Post ($_ID) published or edited and its status is published" );
|
72 |
+
$this->log( "* * * * *" );
|
73 |
+
break;
|
74 |
+
|
75 |
+
case 'publish_page':
|
76 |
+
$this->log( "* * * * *" );
|
77 |
+
$this->log( "* Blog :: ".addslashes( get_bloginfo('name') )." ($blog_id)." );
|
78 |
+
$this->log( "* Page :: ".get_the_title($_ID)." ($_ID)." );
|
79 |
+
$this->log( "* Page ($_ID) published or edited and its status is published" );
|
80 |
+
$this->log( "* * * * *" );
|
81 |
+
break;
|
82 |
+
|
83 |
+
case 'comment_post':
|
84 |
+
case 'wp_set_comment_status':
|
85 |
+
break;
|
86 |
+
|
87 |
+
default:
|
88 |
+
$_post_type = get_post_type($_ID);
|
89 |
+
$this->log( "* * * * *" );
|
90 |
+
$this->log( "* Blog :: ".addslashes( get_bloginfo('name') )." ($blog_id)." );
|
91 |
+
$this->log( "* Custom post type '$_post_type' :: ".get_the_title($_ID)." ($_ID)." );
|
92 |
+
$this->log( "* CPT '$_post_type' ($_ID) published or edited and its status is published" );
|
93 |
+
$this->log( "* * * * *" );
|
94 |
+
break;
|
95 |
+
}
|
96 |
+
|
97 |
+
$this->log( "Function purgePost BEGIN ===" );
|
98 |
+
|
99 |
+
if ($rt_wp_nginx_helper->options['purge_homepage_on_edit'] == 1) {
|
100 |
+
$homepage_url = trailingslashit(get_option('siteurl'));
|
101 |
+
|
102 |
+
$this->log( "Purging homepage '$homepage_url'" );
|
103 |
+
$this->purgeUrl($homepage_url);
|
104 |
+
}
|
105 |
+
|
106 |
+
|
107 |
+
if ( current_filter() == 'comment_post' || current_filter() == 'wp_set_comment_status' ) {
|
108 |
+
$this->_purge_by_options($_ID, $blog_id, $rt_wp_nginx_helper->options['purge_page_on_new_comment'], $rt_wp_nginx_helper->options['purge_archive_on_new_comment'], $rt_wp_nginx_helper->options['purge_archive_on_new_comment']);
|
109 |
+
} else {
|
110 |
+
$this->_purge_by_options($_ID, $blog_id, $rt_wp_nginx_helper_get_options['purge_page_on_mod'], $rt_wp_nginx_helper->options['purge_archive_on_edit'], $rt_wp_nginx_helper->options['purge_homepage_on_edit']);
|
111 |
+
}
|
112 |
+
|
113 |
+
$this->log( "Function purgePost END ^^^" );
|
114 |
+
|
115 |
+
}
|
116 |
+
|
117 |
+
|
118 |
+
private function _purge_by_options($_post_ID, $blog_id, $_purge_page, $_purge_archive, $_purge_custom_taxa) {
|
119 |
+
|
120 |
+
global $rt_wp_nginx_helper;
|
121 |
+
|
122 |
+
$_post_type = get_post_type( $_post_ID );
|
123 |
+
|
124 |
+
if ($_purge_page) {
|
125 |
+
if ( $_post_type == 'post' || $_post_type == 'page' ) {
|
126 |
+
$this->log( "Purging $_post_type (id $_post_ID, blog id $blog_id)" );
|
127 |
+
} else {
|
128 |
+
$this->log( "Purging custom post type '$_post_type' (id $_post_ID, blog id $blog_id)" );
|
129 |
+
}
|
130 |
+
|
131 |
+
$this->purgeUrl( get_permalink( $_post_ID ) );
|
132 |
+
}
|
133 |
+
|
134 |
+
if ($_purge_archive) {
|
135 |
+
|
136 |
+
if ( function_exists( 'get_post_type_archive_link' ) && ( $_post_type_archive_link = get_post_type_archive_link( $_post_type ) ) ) {
|
137 |
+
$this->log( "Purging post type archive (".$_post_type.")" );
|
138 |
+
$this->purgeUrl( $_post_type_archive_link );
|
139 |
+
}
|
140 |
+
|
141 |
+
if ( $_post_type == 'post' ) {
|
142 |
+
$this->log( "Purging date" );
|
143 |
+
|
144 |
+
$day = get_the_time('d', $_post_ID);
|
145 |
+
$month = get_the_time('m', $_post_ID);
|
146 |
+
$year = get_the_time('Y', $_post_ID);
|
147 |
+
|
148 |
+
if ( $year ) {
|
149 |
+
$this->purgeUrl( get_year_link( $year ) );
|
150 |
+
if ( $month ) {
|
151 |
+
$this->purgeUrl( get_month_link( $year, $month ) );
|
152 |
+
if ( $day )
|
153 |
+
$this->purgeUrl( get_day_link( $year, $month, $day ) );
|
154 |
+
}
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
if ( $categories = wp_get_post_categories( $_post_ID ) ) {
|
159 |
+
$this->log( "Purging category archives" );
|
160 |
+
|
161 |
+
foreach ( $categories as $category_id ) {
|
162 |
+
$this->log( "Purging category ".$category_id );
|
163 |
+
$this->purgeUrl( get_category_link( $category_id ) );
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
if ( $tags = get_the_tags( $_post_ID ) ) {
|
168 |
+
$this->log( "Purging tag archives" );
|
169 |
+
|
170 |
+
foreach ( $tags as $tag ) {
|
171 |
+
$this->log( "Purging tag ".$tag->term_id );
|
172 |
+
$this->purgeUrl( get_tag_link( $tag->term_id ) );
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
if ( $author_id = get_post($_post_ID)->post_author ) {
|
177 |
+
$this->log( "Purging author archive" );
|
178 |
+
$this->purgeUrl( get_author_posts_url( $author_id ) );
|
179 |
+
}
|
180 |
+
|
181 |
+
}
|
182 |
+
|
183 |
+
if ( $_purge_custom_taxa ) {
|
184 |
+
if ( $custom_taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) ) ) {
|
185 |
+
$this->log( "Purging custom taxonomies related" );
|
186 |
+
foreach ( $custom_taxonomies as $taxon ) {
|
187 |
+
|
188 |
+
if ( !in_array( $taxon, array( 'category', 'post_tag', 'link_category' ) ) ) {
|
189 |
+
|
190 |
+
if ( $terms = get_the_terms( $_post_ID, $taxon ) ) {
|
191 |
+
foreach ( $terms as $term ) {
|
192 |
+
$this->purgeUrl( get_term_link( $term, $taxon ) );
|
193 |
+
}
|
194 |
+
}
|
195 |
+
|
196 |
+
} else {
|
197 |
+
$this->log( "Your built-in taxonomy '".$taxon."' has param '_builtin' set to false.", "WARNING" );
|
198 |
+
}
|
199 |
+
|
200 |
+
}
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
}
|
205 |
+
|
206 |
+
function purgeUrl($url, $feed = true) {
|
207 |
+
|
208 |
+
$this->log( "- Purging URL | ".$url );
|
209 |
+
|
210 |
+
$parse = parse_url($url);
|
211 |
+
|
212 |
+
$_url_purge = $parse['scheme'].'://'.$parse['host'].'/purge'.$parse['path'];
|
213 |
+
|
214 |
+
if ( isset($parse['query']) && $parse['query'] != '' ) {
|
215 |
+
$_url_purge .= '?'.$parse['query'];
|
216 |
+
}
|
217 |
+
|
218 |
+
$this->_do_remote_get( $_url_purge );
|
219 |
+
|
220 |
+
if ($feed) {
|
221 |
+
$feed_string = (substr($parse['path'], -1) != '/') ? "/feed/" : "feed/";
|
222 |
+
$this->_do_remote_get($parse['scheme'].'://'.$parse['host'].'/purge'.$parse['path'].$feed_string);
|
223 |
+
}
|
224 |
+
|
225 |
+
}
|
226 |
+
|
227 |
+
private function _do_remote_get($url) {
|
228 |
+
|
229 |
+
$response = wp_remote_get($url);
|
230 |
+
|
231 |
+
if( is_wp_error( $response ) ) {
|
232 |
+
$_errors_str = implode(" - ",$response->get_error_messages());
|
233 |
+
$this->log( "Error while purging URL. ".$_errors_str, "ERROR" );
|
234 |
+
} else {
|
235 |
+
if ( $response['response']['code'] ) {
|
236 |
+
switch ( $response['response']['code'] ) {
|
237 |
+
case 200:
|
238 |
+
$this->log( "- - ".$url." *** PURGED ***" );
|
239 |
+
break;
|
240 |
+
case 404:
|
241 |
+
$this->log( "- - ".$url." is currently not cached" );
|
242 |
+
break;
|
243 |
+
default:
|
244 |
+
$this->log( "- - ".$url." not found (".$response['response']['code'].")", "WARNING" );
|
245 |
+
}
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
}
|
250 |
+
|
251 |
+
function checkHttpConnection() {
|
252 |
+
|
253 |
+
$purgeURL = plugins_url("nginx-manager/check-proxy.php");
|
254 |
+
$response = wp_remote_get($purgeURL);
|
255 |
+
|
256 |
+
if( !is_wp_error( $response ) && ($response['body'] == 'HTTP Connection OK')) {
|
257 |
+
return "OK";
|
258 |
+
}
|
259 |
+
|
260 |
+
return "KO";
|
261 |
+
|
262 |
+
}
|
263 |
+
|
264 |
+
function log( $msg, $level='INFO' ) {
|
265 |
+
|
266 |
+
global $rt_wp_nginx_helper;
|
267 |
+
if(!$rt_wp_nginx_helper->options['enable_log']){
|
268 |
+
return;
|
269 |
+
}
|
270 |
+
|
271 |
+
$log_levels = array("INFO" => 0, "WARNING" => 1, "ERROR" => 2, "NONE" => 3);
|
272 |
+
|
273 |
+
if ($log_levels[$level] >= $log_levels[$rt_wp_nginx_helper->options['log_level']]) {
|
274 |
+
if ($fp = fopen(RT_WP_NGINX_HELPER_PATH .'nginx.log',"a+")) {
|
275 |
+
fwrite($fp, "\n".gmdate("Y-m-d H:i:s ")." | ".$level." | ".$msg);
|
276 |
+
fclose($fp);
|
277 |
+
}
|
278 |
+
}
|
279 |
+
|
280 |
+
return true;
|
281 |
+
|
282 |
+
}
|
283 |
+
|
284 |
+
function checkAndTruncateLogFile() {
|
285 |
+
|
286 |
+
global $rt_wp_nginx_helper;
|
287 |
+
|
288 |
+
$maxSizeAllowed = (is_numeric($rt_wp_nginx_helper->options['log_filesize'])) ? $rt_wp_nginx_helper->options['log_filesize']*1048576 : 5242880;
|
289 |
+
|
290 |
+
$fileSize = filesize(RT_WP_NGINX_HELPER_PATH .'nginx.log');
|
291 |
+
|
292 |
+
if ($fileSize > $maxSizeAllowed) {
|
293 |
+
|
294 |
+
$offset = $fileSize - $maxSizeAllowed;
|
295 |
+
|
296 |
+
if ($file_content = file_get_contents(RT_WP_NGINX_HELPER_PATH .'nginx.log', NULL, NULL, $offset)) {
|
297 |
+
|
298 |
+
if ($file_content = strstr($file_content, "\n")) {
|
299 |
+
|
300 |
+
if ($fp = fopen( RT_WP_NGINX_HELPER_PATH .'nginx.log', "w+" )) {
|
301 |
+
fwrite($fp, $file_content);
|
302 |
+
fclose($fp);
|
303 |
+
}
|
304 |
+
}
|
305 |
+
}
|
306 |
+
}
|
307 |
+
}
|
308 |
+
|
309 |
+
function purgeImageOnEdit($attachment_id) {
|
310 |
+
|
311 |
+
$this->log( "Purging media on edit BEGIN ===" );
|
312 |
+
|
313 |
+
if ( wp_attachment_is_image( $attachment_id ) ) {
|
314 |
+
|
315 |
+
$this->purgeUrl( wp_get_attachment_url( $attachment_id ), false );
|
316 |
+
$attachment = wp_get_attachment_metadata( $attachment_id );
|
317 |
+
|
318 |
+
if ( $attachment['sizes'] ) {
|
319 |
+
foreach ( $attachment['sizes'] as $size_name => $size ) {
|
320 |
+
$resize_image = wp_get_attachment_image_src( $attachment_id, $size_name );
|
321 |
+
if ( $resize_image )
|
322 |
+
$this->purgeUrl( $resize_image[0], false );
|
323 |
+
}
|
324 |
+
}
|
325 |
+
|
326 |
+
} else {
|
327 |
+
$this->log( "Media (id $attachment_id) edited: no image", "WARNING" );
|
328 |
+
}
|
329 |
+
|
330 |
+
$this->log( "Purging media on edit END ^^^" );
|
331 |
+
|
332 |
+
}
|
333 |
+
|
334 |
+
function purge_on_post_moved_to_trash( $new_status, $old_status, $post ) {
|
335 |
+
|
336 |
+
global $rt_wp_nginx_helper, $blog_id;
|
337 |
+
if(!$rt_wp_nginx_helper->options['enable_purge']){
|
338 |
+
return;
|
339 |
+
}
|
340 |
+
if ($new_status == 'trash') {
|
341 |
+
|
342 |
+
$this->log( "# # # # #" );
|
343 |
+
$this->log( "# Post '$post->post_title' (id $post->ID) moved to the trash." );
|
344 |
+
$this->log( "# # # # #" );
|
345 |
+
|
346 |
+
$this->log( "Function purge_on_post_moved_to_trash (post id $post->ID) BEGIN ===" );
|
347 |
+
|
348 |
+
|
349 |
+
|
350 |
+
if ( $rt_wp_nginx_helper->options['purge_homepage_on_delete'] == 1 ) {
|
351 |
+
$this->_purge_homepage();
|
352 |
+
}
|
353 |
+
|
354 |
+
|
355 |
+
$this->_purge_by_options( $post->ID, $blog_id, false, $rt_wp_nginx_helper->options['purge_archive_on_delete'], $rt_wp_nginx_helper->options['purge_archive_on_delete'] );
|
356 |
+
|
357 |
+
|
358 |
+
|
359 |
+
$this->log( "Function purge_on_post_moved_to_trash (post id $post->ID) END ===" );
|
360 |
+
|
361 |
+
}
|
362 |
+
|
363 |
+
return true;
|
364 |
+
|
365 |
+
}
|
366 |
+
|
367 |
+
private function _purge_homepage() {
|
368 |
+
|
369 |
+
$homepage_url = trailingslashit( get_option( 'siteurl' ) );
|
370 |
+
|
371 |
+
$this->log( sprintf( __( "Purging homepage '%s'", "rt_wp_nginx_helper" ), $homepage_url ) );
|
372 |
+
$this->purgeUrl( $homepage_url );
|
373 |
+
|
374 |
+
return true;
|
375 |
+
|
376 |
+
}
|
377 |
+
|
378 |
+
private function _purge_personal_urls() {
|
379 |
+
|
380 |
+
global $rt_wp_nginx_helper;
|
381 |
+
|
382 |
+
$this->log( __( "Purging personal urls", "rt_wp_nginx_helper" ) );
|
383 |
+
|
384 |
+
if (isset($rt_wp_nginx_helper->options['purgeable_url']['urls'])) {
|
385 |
+
|
386 |
+
foreach ($rt_wp_nginx_helper->options['purgeable_url']['urls'] as $u) {
|
387 |
+
$this->purgeUrl($u, false);
|
388 |
+
}
|
389 |
+
|
390 |
+
} else {
|
391 |
+
$this->log( "- ".__( "No personal urls available", "rt_wp_nginx_helper" ) );
|
392 |
+
}
|
393 |
+
|
394 |
+
return true;
|
395 |
+
|
396 |
+
}
|
397 |
+
|
398 |
+
private function _purge_post_categories( $_post_id ) {
|
399 |
+
|
400 |
+
$this->log( __( "Purging category archives", "rt_wp_nginx_helper" ) );
|
401 |
+
|
402 |
+
if ( $categories = wp_get_post_categories( $_post_id ) ) {
|
403 |
+
foreach ( $categories as $category_id ) {
|
404 |
+
$this->log( sprintf( __( "Purging category '%d'", "rt_wp_nginx_helper" ), $category_id ) );
|
405 |
+
$this->purgeUrl( get_category_link( $category_id ) );
|
406 |
+
}
|
407 |
+
}
|
408 |
+
|
409 |
+
return true;
|
410 |
+
|
411 |
+
}
|
412 |
+
|
413 |
+
private function _purge_post_tags( $_post_id ) {
|
414 |
+
|
415 |
+
$this->log( __( "Purging tags archives", "rt_wp_nginx_helper" ) );
|
416 |
+
|
417 |
+
if ( $tags = get_the_tags( $_post_id ) ) {
|
418 |
+
foreach ( $tags as $tag ) {
|
419 |
+
$this->log( sprintf( __( "Purging tag '%s' (id %d)", "rt_wp_nginx_helper" ), $tag->name, $tag->term_id ) );
|
420 |
+
$this->purgeUrl( get_tag_link( $tag->term_id ) );
|
421 |
+
}
|
422 |
+
}
|
423 |
+
|
424 |
+
return true;
|
425 |
+
|
426 |
+
}
|
427 |
+
|
428 |
+
private function _purge_post_custom_taxa( $_post_id ) {
|
429 |
+
|
430 |
+
$this->log( __( "Purging post custom taxonomies related", "rt_wp_nginx_helper" ) );
|
431 |
+
|
432 |
+
if ( $custom_taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) ) ) {
|
433 |
+
foreach ( $custom_taxonomies as $taxon ) {
|
434 |
+
$this->log( sprintf( "+ ".__( "Purging custom taxonomy '%s'", "rt_wp_nginx_helper" ), $taxon ) );
|
435 |
+
|
436 |
+
if ( !in_array( $taxon, array( 'category', 'post_tag', 'link_category' ) ) ) {
|
437 |
+
|
438 |
+
if ( $terms = get_the_terms( $_post_id, $taxon ) ) {
|
439 |
+
foreach ( $terms as $term ) {
|
440 |
+
$this->purgeUrl( get_term_link( $term, $taxon ) );
|
441 |
+
}
|
442 |
+
}
|
443 |
+
|
444 |
+
} else {
|
445 |
+
$this->log( sprintf( "- ".__( "Your built-in taxonomy '%s' has param '_builtin' set to false.", "rt_wp_nginx_helper" ), $taxon ), "WARNING" );
|
446 |
+
}
|
447 |
+
}
|
448 |
+
|
449 |
+
} else {
|
450 |
+
$this->log( "- ".__( "No custom taxonomies", "rt_wp_nginx_helper" ) );
|
451 |
+
}
|
452 |
+
|
453 |
+
return true;
|
454 |
+
|
455 |
+
}
|
456 |
+
|
457 |
+
private function _purge_all_categories() {
|
458 |
+
|
459 |
+
$this->log( __( "Purging all categories", "rt_wp_nginx_helper" ) );
|
460 |
+
|
461 |
+
if ( $_categories = get_categories() ) {
|
462 |
+
|
463 |
+
foreach ( $_categories as $c ) {
|
464 |
+
$this->log( sprintf( __( "Purging category '%s' (id %d)", "rt_wp_nginx_helper" ), $c->name, $c->term_id ) );
|
465 |
+
$this->purgeUrl( get_category_link( $c->term_id ) );
|
466 |
+
}
|
467 |
+
|
468 |
+
} else {
|
469 |
+
$this->log( __( "No categories archives", "rt_wp_nginx_helper" ) );
|
470 |
+
}
|
471 |
+
|
472 |
+
return true;
|
473 |
+
|
474 |
+
}
|
475 |
+
|
476 |
+
private function _purge_all_posttags() {
|
477 |
+
|
478 |
+
$this->log( __( "Purging all tags", "rt_wp_nginx_helper" ) );
|
479 |
+
|
480 |
+
if ( $_posttags = get_tags() ) {
|
481 |
+
|
482 |
+
foreach ( $_posttags as $t ) {
|
483 |
+
$this->log( sprintf( __( "Purging tag '%s' (id %d)", "rt_wp_nginx_helper" ), $t->name, $t->term_id ) );
|
484 |
+
$this->purgeUrl( get_tag_link( $t->term_id ) );
|
485 |
+
}
|
486 |
+
|
487 |
+
} else {
|
488 |
+
$this->log( __( "No tags archives", "rt_wp_nginx_helper" ) );
|
489 |
+
}
|
490 |
+
|
491 |
+
return true;
|
492 |
+
|
493 |
+
}
|
494 |
+
|
495 |
+
private function _purge_all_customtaxa() {
|
496 |
+
|
497 |
+
$this->log( __( "Purging all custom taxonomies", "rt_wp_nginx_helper" ) );
|
498 |
+
|
499 |
+
if ( $custom_taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) ) ) {
|
500 |
+
|
501 |
+
foreach ( $custom_taxonomies as $taxon ) {
|
502 |
+
$this->log( sprintf( "+ ".__( "Purging custom taxonomy '%s'", "rt_wp_nginx_helper" ), $taxon ) );
|
503 |
+
|
504 |
+
if ( !in_array( $taxon, array( 'category', 'post_tag', 'link_category' ) ) ) {
|
505 |
+
|
506 |
+
if ( $terms = get_terms( $taxon ) ) {
|
507 |
+
foreach ( $terms as $term ) {
|
508 |
+
$this->purgeUrl( get_term_link( $term, $taxon ) );
|
509 |
+
}
|
510 |
+
}
|
511 |
+
|
512 |
+
} else {
|
513 |
+
$this->log( sprintf( "- ".__( "Your built-in taxonomy '%s' has param '_builtin' set to false.", "rt_wp_nginx_helper" ), $taxon ), "WARNING" );
|
514 |
+
}
|
515 |
+
}
|
516 |
+
|
517 |
+
} else {
|
518 |
+
$this->log( "- ".__( "No custom taxonomies", "rt_wp_nginx_helper" ) );
|
519 |
+
}
|
520 |
+
|
521 |
+
return true;
|
522 |
+
|
523 |
+
}
|
524 |
+
|
525 |
+
private function _purge_all_taxonomies() {
|
526 |
+
|
527 |
+
$this->_purge_all_categories();
|
528 |
+
$this->_purge_all_posttags();
|
529 |
+
$this->_purge_all_customtaxa();
|
530 |
+
|
531 |
+
return true;
|
532 |
+
}
|
533 |
+
|
534 |
+
private function _purge_all_posts() {
|
535 |
+
|
536 |
+
$this->log( __( "Purging all posts, pages and custom post types.", "rt_wp_nginx_helper" ) );
|
537 |
+
|
538 |
+
$args = array(
|
539 |
+
'numberposts' => 0,
|
540 |
+
'post_type' => 'any',
|
541 |
+
'post_status' => 'publish' );
|
542 |
+
|
543 |
+
if ( $_posts = get_posts($args) ) {
|
544 |
+
|
545 |
+
foreach ( $_posts as $p ) {
|
546 |
+
$this->log( sprintf( "+ ".__( "Purging post id '%d' (post type '%s')", "rt_wp_nginx_helper" ), $p->ID, $p->post_type ) );
|
547 |
+
$this->purgeUrl( get_permalink( $p->ID ) );
|
548 |
+
}
|
549 |
+
|
550 |
+
} else {
|
551 |
+
$this->log( "- ".__( "No posts", "rt_wp_nginx_helper" ) );
|
552 |
+
}
|
553 |
+
|
554 |
+
return true;
|
555 |
+
|
556 |
+
}
|
557 |
+
|
558 |
+
private function _purge_all_date_archives() {
|
559 |
+
|
560 |
+
$this->log( __( "Purging all date-based archives.", "rt_wp_nginx_helper" ) );
|
561 |
+
|
562 |
+
$this->_purge_all_daily_archives();
|
563 |
+
|
564 |
+
$this->_purge_all_monthly_archives();
|
565 |
+
|
566 |
+
$this->_purge_all_yearly_archives();
|
567 |
+
|
568 |
+
return true;
|
569 |
+
|
570 |
+
}
|
571 |
+
|
572 |
+
private function _purge_all_daily_archives() {
|
573 |
+
|
574 |
+
global $wpdb;
|
575 |
+
|
576 |
+
$this->log( __( "Purging all daily archives.", "rt_wp_nginx_helper" ) );
|
577 |
+
|
578 |
+
$_query_daily_archives = $wpdb->prepare(
|
579 |
+
"SELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month', DAYOFMONTH(post_date) AS 'dayofmonth', count(ID) as posts
|
580 |
+
FROM $wpdb->posts
|
581 |
+
WHERE post_type = 'post' AND post_status = 'publish'
|
582 |
+
GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date)
|
583 |
+
ORDER BY post_date DESC"
|
584 |
+
);
|
585 |
+
|
586 |
+
if ( $_daily_archives = $wpdb->get_results( $_query_daily_archives ) ) {
|
587 |
+
|
588 |
+
foreach( $_daily_archives as $_da ) {
|
589 |
+
$this->log( sprintf( "+ ".__( "Purging daily archive '%s/%s/%s'", "rt_wp_nginx_helper" ), $_da->year, $_da->month, $_da->dayofmonth ) );
|
590 |
+
$this->purgeUrl( get_day_link( $_da->year, $_da->month, $_da->dayofmonth ) );
|
591 |
+
}
|
592 |
+
|
593 |
+
} else {
|
594 |
+
$this->log( "- ".__( "No daily archives", "rt_wp_nginx_helper" ) );
|
595 |
+
}
|
596 |
+
|
597 |
+
}
|
598 |
+
|
599 |
+
private function _purge_all_monthly_archives() {
|
600 |
+
|
601 |
+
global $wpdb;
|
602 |
+
|
603 |
+
$this->log( __( "Purging all monthly archives.", "rt_wp_nginx_helper" ) );
|
604 |
+
|
605 |
+
$_query_monthly_archives = $wpdb->prepare(
|
606 |
+
"SELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month', count(ID) as posts
|
607 |
+
FROM $wpdb->posts
|
608 |
+
WHERE post_type = 'post' AND post_status = 'publish'
|
609 |
+
GROUP BY YEAR(post_date), MONTH(post_date)
|
610 |
+
ORDER BY post_date DESC"
|
611 |
+
);
|
612 |
+
|
613 |
+
if ( $_monthly_archives = $wpdb->get_results( $_query_monthly_archives ) ) {
|
614 |
+
|
615 |
+
foreach( $_monthly_archives as $_ma ) {
|
616 |
+
$this->log( sprintf( "+ ".__( "Purging monthly archive '%s/%s'", "rt_wp_nginx_helper" ), $_ma->year, $_ma->month ) );
|
617 |
+
$this->purgeUrl( get_month_link( $_ma->year, $_ma->month ) );
|
618 |
+
}
|
619 |
+
|
620 |
+
} else {
|
621 |
+
$this->log( "- ".__( "No monthly archives", "rt_wp_nginx_helper" ) );
|
622 |
+
}
|
623 |
+
|
624 |
+
}
|
625 |
+
|
626 |
+
private function _purge_all_yearly_archives() {
|
627 |
+
|
628 |
+
global $wpdb;
|
629 |
+
|
630 |
+
$this->log( __( "Purging all yearly archives.", "rt_wp_nginx_helper" ) );
|
631 |
+
|
632 |
+
$_query_yearly_archives = $wpdb->prepare(
|
633 |
+
"SELECT YEAR(post_date) AS 'year', count(ID) as posts
|
634 |
+
FROM $wpdb->posts
|
635 |
+
WHERE post_type = 'post' AND post_status = 'publish'
|
636 |
+
GROUP BY YEAR(post_date)
|
637 |
+
ORDER BY post_date DESC"
|
638 |
+
);
|
639 |
+
|
640 |
+
if ( $_yearly_archives = $wpdb->get_results( $_query_yearly_archives ) ) {
|
641 |
+
|
642 |
+
foreach( $_yearly_archives as $_ya ) {
|
643 |
+
$this->log( sprintf( "+ ".__( "Purging yearly archive '%s'", "rt_wp_nginx_helper" ), $_ya->year ) );
|
644 |
+
$this->purgeUrl( get_year_link( $_ya->year ) );
|
645 |
+
}
|
646 |
+
|
647 |
+
} else {
|
648 |
+
$this->log( "- ".__( "No yearly archives", "rt_wp_nginx_helper" ) );
|
649 |
+
}
|
650 |
+
|
651 |
+
}
|
652 |
+
|
653 |
+
private function _purge_them_all() {
|
654 |
+
|
655 |
+
$this->log( __( "LET'S PURGE ALL THE BLOG.", "rt_wp_nginx_helper" ) );
|
656 |
+
|
657 |
+
$this->_purge_homepage();
|
658 |
+
|
659 |
+
$this->_purge_personal_urls();
|
660 |
+
|
661 |
+
$this->_purge_all_posts();
|
662 |
+
|
663 |
+
$this->_purge_all_taxonomies();
|
664 |
+
|
665 |
+
$this->_purge_all_date_archives();
|
666 |
+
|
667 |
+
return true;
|
668 |
+
|
669 |
+
}
|
670 |
+
|
671 |
+
function purge_on_term_taxonomy_edited( $term_id, $tt_id, $taxon ) {
|
672 |
+
|
673 |
+
$this->log( __( "Term taxonomy edited or deleted", "rt_wp_nginx_helper" ) );
|
674 |
+
|
675 |
+
if ( current_filter() == 'edit_term' && $term = get_term( $term_id, $taxon ) ) {
|
676 |
+
$this->log( sprintf( __( "Term taxonomy '%s' edited, (tt_id '%d', term_id '%d', taxonomy '%s')", "rt_wp_nginx_helper" ) , $term->name, $tt_id, $term_id, $taxon ) );
|
677 |
+
} else if ( current_filter() == 'delete_term' ) {
|
678 |
+
$this->log( sprintf( __( "A term taxonomy has been deleted from taxonomy '%s', (tt_id '%d', term_id '%d')", "rt_wp_nginx_helper" ), $taxon, $term_id, $tt_id ) );
|
679 |
+
}
|
680 |
+
|
681 |
+
$this->_purge_homepage();
|
682 |
+
|
683 |
+
return true;
|
684 |
+
|
685 |
+
}
|
686 |
+
|
687 |
+
function purge_on_check_ajax_referer($action, $result) {
|
688 |
+
|
689 |
+
switch ($action) {
|
690 |
+
case 'save-sidebar-widgets' :
|
691 |
+
|
692 |
+
$this->log( __( "Widget saved, moved or removed in a sidebar", "rt_wp_nginx_helper" ) );
|
693 |
+
|
694 |
+
$this->_purge_homepage();
|
695 |
+
|
696 |
+
break;
|
697 |
+
|
698 |
+
default :
|
699 |
+
break;
|
700 |
+
}
|
701 |
+
|
702 |
+
return true;
|
703 |
+
|
704 |
+
}
|
705 |
+
|
706 |
+
}
|
707 |
+
}
|
708 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Nginx ===
|
2 |
+
Contributors: rtcamp,rahul286,saurabhshukla
|
3 |
+
Tags: nginx, cache, purge, nginx map, nginx cache
|
4 |
+
Requires at least: 3.0
|
5 |
+
Tested up to: 3.4.2
|
6 |
+
Stable tag: 1.0
|
7 |
+
|
8 |
+
Makes WordPress super fast and super friendly with nginx!
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
1. Adds index.php redirection to make your wordpress installation compatible with nginx.
|
15 |
+
2. Adds nginx proxy purge with detailed settings.
|
16 |
+
3. Adds support for nginx maps on a multisite/network installation to optimise performance, as described here:
|
17 |
+
<a href=\"http://rtcamp.com/tutorials/wordpress-nginx-multisite-subdirectories-nginx-map/\">http://rtcamp.com/tutorials/wordpress-nginx-multisite-subdirectories-nginx-map/</a>
|
18 |
+
|
19 |
+
== Installation ==
|
20 |
+
|
21 |
+
Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.
|
22 |
+
== Screenshots ==
|
23 |
+
1. nginx plugin settings
|
24 |
+
|
25 |
+
2. remaining settings
|
26 |
+
|
27 |
+
== Changelog ==
|
28 |
+
1.0: First release
|