Nginx Helper - Version 1.5

Version Description

  • Timestamp now only gets added to content-type text/html
  • Added option to toggle timestamp creation
Download this release

Release Info

Developer saurabhshukla
Plugin Icon 128x128 Nginx Helper
Version 1.5
Comparing to
See all releases

Code changes from version 1.4 to 1.5

admin/admin.php CHANGED
@@ -1,320 +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 Helper', __( 'Nginx Helper', '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 Helper', __( 'Nginx Helper', '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(isset($_POST['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_site_option( "rt_wp_nginx_helper_options", $rt_wp_nginx_helper->options );
81
-
82
-
83
- $update = 1;
84
- }
85
- $rt_wp_nginx_helper->options = get_site_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
- $displayvar='';
116
- if($rt_wp_nginx_helper->options['enable_purge']==false){
117
- $displayvar = ' style="display:none"';
118
- }
119
- ?>
120
- <h3<?php echo $displayvar; ?>>Purging Options</h3>
121
-
122
- <table class="form-table rtnginx-table"<?php echo $displayvar; ?>>
123
- <tr valign="top">
124
- <th scope="row"><h4>Purge Homepage:</h4></th>
125
- <td>
126
- <fieldset>
127
- <legend class="screen-reader-text"><span>&nbsp;when a post/page/custom post is modified or added.</span></legend>
128
- <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 ); ?>>&nbsp;when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.</label><br />
129
- </fieldset>
130
- <fieldset>
131
- <legend class="screen-reader-text"><span>&nbsp;when an existing post/page/custom post is modified.</span></legend>
132
- <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 ); ?>>&nbsp;when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>.</label><br />
133
- </fieldset>
134
- </td>
135
- </tr>
136
- </table>
137
- <table class="form-table rtnginx-table"<?php echo $displayvar; ?>>
138
- <tr valign="top">
139
- <th scope="row">
140
- <h4>Purge Post/Page/Custom Post Type:</h4>
141
- </th>
142
- <td>
143
- <fieldset>
144
- <legend class="screen-reader-text"><span>&nbsp;when a post/page/custom post is published.</span></legend>
145
- <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 ); ?>>&nbsp;when a <strong>post</strong> is <strong>published</strong>.</label><br />
146
- </fieldset>
147
- <fieldset>
148
- <legend class="screen-reader-text"><span>&nbsp;when a comment is approved/published.</span></legend>
149
- <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 ); ?>>&nbsp;when a <strong>comment</strong> is <strong>approved/published</strong>.</label><br />
150
- </fieldset>
151
- <fieldset>
152
- <legend class="screen-reader-text"><span>&nbsp;when a comment is unapproved/deleted.</span></legend>
153
- <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 ); ?>>&nbsp;when a <strong>comment</strong> is <strong>unapproved/deleted</strong>.</label><br />
154
- </fieldset>
155
- </td>
156
- </tr>
157
- </table>
158
- <table class="form-table rtnginx-table"<?php echo $displayvar; ?>>
159
- <tr valign="top">
160
- <th scope="row">
161
- <h4>Purge Archives:</h4>
162
- <small>(date, category, tag, author, custom taxonomies)</small>
163
- </th>
164
- <td>
165
- <fieldset>
166
- <legend class="screen-reader-text"><span>&nbsp;when an post/page/custom post is modified or added.</span></legend>
167
- <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 ); ?>>&nbsp;when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.</label><br />
168
- </fieldset>
169
- <fieldset>
170
- <legend class="screen-reader-text"><span>&nbsp;when an existing post/page/custom post is trashed.</span></legend>
171
- <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 ); ?>>&nbsp;when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>.</label><br />
172
- </fieldset>
173
- <br />
174
- <fieldset>
175
- <legend class="screen-reader-text"><span>&nbsp;when a comment is approved/published.</span></legend>
176
- <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 ); ?>>&nbsp;when a <strong>comment</strong> is <strong>approved/published</strong>.</label><br />
177
- </fieldset>
178
- <fieldset>
179
- <legend class="screen-reader-text"><span>&nbsp;when a comment is unapproved/deleted.</span></legend>
180
- <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 ); ?>>&nbsp;when a <strong>comment</strong> is <strong>unapproved/deleted</strong>.</label><br />
181
- </fieldset>
182
-
183
- </td>
184
- </tr>
185
- </table>
186
-
187
- <?php
188
- }
189
- if(is_network_admin() && $rt_wp_nginx_helper->options['enable_map']!=false){
190
- ?>
191
- <h3>Nginx Map</h3>
192
- <?php if (!is_writable(RT_WP_NGINX_HELPER_PATH .'map.conf')) { ?>
193
- <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>
194
- <?php } ?>
195
-
196
- <table class="form-table rtnginx-table">
197
- <tr>
198
- <th>
199
- Nginx Map path to include in nginx settings<br />
200
- <small>(recommended)</small>
201
- </th>
202
- <td>
203
- <?php echo RT_WP_NGINX_HELPER_PATH.'map.conf'; ?>
204
- </td>
205
- </tr>
206
- <tr>
207
- <th>
208
- Or,<br />
209
- Text to manually copy and paste in nginx settings<br />
210
- <small>(if your network is small and new sites are not added frequently)</small>
211
- </th>
212
- <td>
213
- <pre id="map"><?php echo $rt_wp_nginx_helper->get_map() ?></pre>
214
- </td>
215
- </tr>
216
- </table>
217
-
218
- <?php
219
- if($rt_wp_nginx_helper->options['enable_log']!=false){
220
- ?>
221
- <h3>Logging</h3>
222
-
223
- <?php if (!is_writable(RT_WP_NGINX_HELPER_PATH .'nginx.log')) { ?>
224
- <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>
225
- <?php } ?>
226
-
227
- <table class="form-table rtnginx-table">
228
- <tbody>
229
- <tr>
230
- <th><label for="rt_wp_nginx_helper_logs_path"><?php _e('Logs path', 'rt_wp_nginx_helper'); ?></label></th>
231
- <td><?php echo RT_WP_NGINX_HELPER_PATH ?>nginx.log</td>
232
- </tr>
233
- <tr>
234
- <th><label for="rt_wp_nginx_helper_logs_link"><?php _e('View Log', 'rt_wp_nginx_helper'); ?></label></th>
235
- <td><a target="_blank" href="<?php echo RT_WP_NGINX_HELPER_URL ?>nginx.log">Log</a></td>
236
- </tr>
237
-
238
- <tr>
239
- <th><label for="rt_wp_nginx_helper_log_level"><?php _e('Log level', 'rt_wp_nginx_helper'); ?></label></th>
240
- <td>
241
- <select name="log_level">
242
- <option value="NONE"<?php selected( $rt_wp_nginx_helper->options['log_level'],'NONE' ); ?>><?php _e('None', 'rt_wp_nginx_helper'); ?></option>
243
- <option value="INFO"<?php selected( $rt_wp_nginx_helper->options['log_level'],'INFO' ); ?>><?php _e('Info', 'rt_wp_nginx_helper'); ?></option>
244
- <option value="WARNING"<?php selected( $rt_wp_nginx_helper->options['log_level'],'WARNING' ); ?>><?php _e('Warning', 'rt_wp_nginx_helper'); ?></option>
245
- <option value="ERROR"<?php selected( $rt_wp_nginx_helper->options['log_level'],'ERROR' ); ?>><?php _e('Error', 'rt_wp_nginx_helper'); ?></option>
246
- </select>
247
- </td>
248
- </tr>
249
-
250
- <tr>
251
- <th><label for="log_filesize"><?php _e('Max log file size', 'rt_wp_nginx_helper'); ?></label></th>
252
- <td>
253
- <input id="log_filesize" class="small-text" type="text" name="log_filesize" value="<?php echo $rt_wp_nginx_helper->options['log_filesize']?>" /> Mb
254
- <?php if ($error_log_filesize) { ?>
255
- <span class="error fade" style="display : block"><p><strong><?php echo $error_log_filesize; ?></strong></p></span>
256
- <?php } ?>
257
- </td>
258
- </tr>
259
- </tbody>
260
- </table>
261
-
262
- <br />
263
- <?php } ?>
264
- <?php } ?>
265
-
266
- <p class="submit">
267
- <input type="submit" name="smart_http_expire_save" class="button-primary" value="Save" />
268
- </p>
269
- </form>
270
- </div>
271
- <div id="rtads" class="metabox-holder align_left">
272
- <?php $this->default_admin_sidebar(); ?>
273
- </div>
274
- </div>
275
- <?php
276
- break;
277
- }
278
  }
279
- function default_admin_sidebar() {
280
- ?>
281
- <div class="postbox" id="support">
282
- <div title="<?php _e('Click to toggle', 'bp-media'); ?>" class="handlediv"><br /></div>
283
- <h3 class="hndle"><span><?php _e('Need Help?', 'bp-media'); ?></span></h3>
284
- <div class="inside"><p><?php printf(__(' Please use our <a href="%s">free support forum</a>.<br/><span class="bpm-aligncenter">OR</span><br/>
285
- <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>
286
- </div>
287
- <div class="postbox" id="social">
288
- <div title="<?php _e('Click to toggle', 'bp-media'); ?>" class="handlediv"><br /></div>
289
- <h3 class="hndle"><span><?php _e('Getting Social is Good', 'bp-media'); ?></span></h3>
290
- <div class="inside" style="text-align:center;">
291
- <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>
292
- <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>
293
- <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>
294
- </div>
295
- </div>
296
-
297
- <div class="postbox" id="latest_news">
298
- <div title="<?php _e('Click to toggle', 'bp-media'); ?>" class="handlediv"><br /></div>
299
- <h3 class="hndle"><span><?php _e('Latest News', 'bp-media'); ?></span></h3>
300
- <div class="inside"><img src ="<?php echo admin_url(); ?>/images/wpspin_light.gif" /> Loading...</div>
301
- </div><?php
302
- }
303
-
304
-
305
-
306
- function load_styles(){
307
- wp_enqueue_style('rt-nginx-admin-css', plugins_url('admin/assets/style.css', dirname(__FILE__)));
308
- }
309
-
310
-
311
-
312
-
313
- function load_scripts(){
314
- $admin_js = trailingslashit(site_url()).'?get_feeds=1';
315
- wp_enqueue_script('nginx-js',plugins_url('admin/assets/nginx.js', dirname(__FILE__)));
316
- wp_localize_script('nginx-js','news_url',$admin_js);
317
- }
318
- }
319
  }
320
  ?>
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ namespace rtCamp\WP\Nginx {
4
+
5
+ class Admin {
6
+
7
+ function __construct() {
8
+ if ( is_multisite() ) {
9
+ add_action( 'network_admin_menu', array( &$this, 'add_network_menu' ) );
10
+ } else {
11
+ add_action( 'admin_menu', array( &$this, 'add_menu' ) );
12
+ }
13
+ add_action( 'admin_print_scripts', array( &$this, 'load_scripts' ) );
14
+ add_action( 'admin_print_styles', array( &$this, 'load_styles' ) );
15
+ }
16
+
17
+ function add_menu() {
18
+ add_submenu_page( 'options-general.php', 'Nginx Helper', __( 'Nginx Helper', 'rt_wp_nginx_helper' ), 'install_plugins', 'nginx', array( &$this, 'show_menu' ) );
19
+ //add_submenu_page($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function)
20
+ }
21
+
22
+ function add_network_menu() {
23
+ add_submenu_page( 'settings.php', 'Nginx Helper', __( 'Nginx Helper', 'rt_wp_nginx_helper' ), 'install_plugins', 'nginx', array( &$this, 'show_menu' ) );
24
+ }
25
+
26
+ // load the script for the defined page and load only this code
27
+ function show_menu() {
28
+
29
+ global $rt_wp_nginx_helper;
30
+
31
+ $required_page = $_GET[ 'page' ];
32
+ switch ( $required_page ) {
33
+
34
+ default :
35
+
36
+ $update = 0;
37
+ $error_time = false;
38
+ $error_log_filesize = false;
39
+ $rt_wp_nginx_helper->options[ 'enable_purge' ] = (isset( $_POST[ 'enable_purge' ] ) and ($_POST[ 'enable_purge' ] == 1) ) ? 1 : 0;
40
+ $rt_wp_nginx_helper->options[ 'enable_map' ] = (isset( $_POST[ 'enable_map' ] ) and ($_POST[ 'enable_map' ] == 1) ) ? 1 : 0;
41
+ $rt_wp_nginx_helper->options[ 'enable_log' ] = (isset( $_POST[ 'enable_log' ] ) and ($_POST[ 'enable_log' ] == 1) ) ? 1 : 0;
42
+ $rt_wp_nginx_helper->options[ 'enable_stamp' ] = (isset( $_POST[ 'enable_stamp' ] ) and ($_POST[ 'enable_stamp' ] == 1) ) ? 1 : 0;
43
+
44
+ if ( isset( $_POST[ 'is_submit' ] ) && ($_POST[ 'is_submit' ] == 1) ) {
45
+ if ( ! ( ! is_network_admin() && is_multisite()) ) {
46
+ if ( $rt_wp_nginx_helper->options[ 'enable_log' ] ) {
47
+ if ( isset( $_POST[ 'log_level' ] ) && ! empty( $_POST[ 'log_level' ] ) && $_POST[ 'log_level' ] != '' ) {
48
+ $rt_wp_nginx_helper->options[ 'log_level' ] = $_POST[ 'log_level' ];
49
+ } else {
50
+ $rt_wp_nginx_helper->options[ 'log_level' ] = 'INFO';
51
+ }
52
+ if ( isset( $_POST[ 'log_filesize' ] ) && ! empty( $_POST[ 'log_filesize' ] ) && $_POST[ 'log_filesize' ] != '' ) {
53
+ if ( ( ! is_numeric( $_POST[ 'log_filesize' ] )) || (empty( $_POST[ 'log_filesize' ] )) ) {
54
+ $error_log_filesize = "Log file size must be a number";
55
+ } else {
56
+ $rt_wp_nginx_helper->options[ 'log_filesize' ] = $_POST[ 'log_filesize' ];
57
+ }
58
+ } else {
59
+ $rt_wp_nginx_helper->options[ 'log_filesize' ] = 5;
60
+ }
61
+ }
62
+ if ( $rt_wp_nginx_helper->options[ 'enable_map' ] ) {
63
+ $rt_wp_nginx_helper->update_map();
64
+ }
65
+ }
66
+ if ( isset( $_POST[ 'enable_purge' ] ) ) {
67
+
68
+ $rt_wp_nginx_helper->options[ 'purge_homepage_on_edit' ] = (isset( $_POST[ 'purge_homepage_on_edit' ] ) and ($_POST[ 'purge_homepage_on_edit' ] == 1) ) ? 1 : 0;
69
+ $rt_wp_nginx_helper->options[ 'purge_homepage_on_del' ] = (isset( $_POST[ 'purge_homepage_on_del' ] ) and ($_POST[ 'purge_homepage_on_del' ] == 1) ) ? 1 : 0;
70
+
71
+ $rt_wp_nginx_helper->options[ 'purge_archive_on_edit' ] = (isset( $_POST[ 'purge_archive_on_edit' ] ) and ($_POST[ 'purge_archive_on_edit' ] == 1) ) ? 1 : 0;
72
+ $rt_wp_nginx_helper->options[ 'purge_archive_on_del' ] = (isset( $_POST[ 'purge_archive_on_del' ] ) and ($_POST[ 'purge_archive_on_del' ] == 1) ) ? 1 : 0;
73
+
74
+ $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;
75
+ $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;
76
+
77
+ $rt_wp_nginx_helper->options[ 'purge_page_on_mod' ] = (isset( $_POST[ 'purge_page_on_mod' ] ) and ($_POST[ 'purge_page_on_mod' ] == 1) ) ? 1 : 0;
78
+ $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;
79
+ $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;
80
+ }
81
+ update_site_option( "rt_wp_nginx_helper_options", $rt_wp_nginx_helper->options );
82
+
83
+
84
+ $update = 1;
85
+ }
86
+ $rt_wp_nginx_helper->options = get_site_option( "rt_wp_nginx_helper_options" );
87
+ ?>
88
+
89
+ <div class="wrap">
90
+
91
+ <div class="icon32" id="icon-options-nginx"><br /></div>
92
+ <h2>Nginx Settings</h2>
93
+ <div id="content_block" class="align_left">
94
+ <form id="post_form" method="post" action="#" name="smart_http_expire_form">
95
+ <?php if ( ! ( ! is_network_admin() && is_multisite()) ) { ?>
96
+
97
+ <input type="hidden" name="is_submit" value="1" />
98
+
99
+ <h3>Plugin Options</h3>
100
+
101
+ <table class="form-table">
102
+ <tr valign="top">
103
+ <td>
104
+ <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 />
105
+ <?php if ( is_network_admin() ) { ?>
106
+ <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 />
107
+ <?php } ?>
108
+ <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 />
109
+ <label for="enable_stamp"><input type="checkbox" value="1" id="enable_stamp" name="enable_stamp"<?php checked( $rt_wp_nginx_helper->options[ 'enable_stamp' ], 1 ); ?>>Enable Nginx Timestamp in HTML</label>
110
+ </td>
111
+ </tr>
112
+ </table>
113
+
114
+ <?php
115
+ $displayvar = '';
116
+ if ( $rt_wp_nginx_helper->options[ 'enable_purge' ] == false ) {
117
+ $displayvar = ' style="display:none"';
118
+ }
119
+ ?>
120
+ <h3<?php echo $displayvar; ?>>Purging Options</h3>
121
+
122
+ <table class="form-table rtnginx-table"<?php echo $displayvar; ?>>
123
+ <tr valign="top">
124
+ <th scope="row"><h4>Purge Homepage:</h4></th>
125
+ <td>
126
+ <fieldset>
127
+ <legend class="screen-reader-text"><span>&nbsp;when a post/page/custom post is modified or added.</span></legend>
128
+ <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 ); ?>>&nbsp;when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.</label><br />
129
+ </fieldset>
130
+ <fieldset>
131
+ <legend class="screen-reader-text"><span>&nbsp;when an existing post/page/custom post is modified.</span></legend>
132
+ <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 ); ?>>&nbsp;when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>.</label><br />
133
+ </fieldset>
134
+ </td>
135
+ </tr>
136
+ </table>
137
+ <table class="form-table rtnginx-table"<?php echo $displayvar; ?>>
138
+ <tr valign="top">
139
+ <th scope="row">
140
+ <h4>Purge Post/Page/Custom Post Type:</h4>
141
+ </th>
142
+ <td>
143
+ <fieldset>
144
+ <legend class="screen-reader-text"><span>&nbsp;when a post/page/custom post is published.</span></legend>
145
+ <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 ); ?>>&nbsp;when a <strong>post</strong> is <strong>published</strong>.</label><br />
146
+ </fieldset>
147
+ <fieldset>
148
+ <legend class="screen-reader-text"><span>&nbsp;when a comment is approved/published.</span></legend>
149
+ <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 ); ?>>&nbsp;when a <strong>comment</strong> is <strong>approved/published</strong>.</label><br />
150
+ </fieldset>
151
+ <fieldset>
152
+ <legend class="screen-reader-text"><span>&nbsp;when a comment is unapproved/deleted.</span></legend>
153
+ <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 ); ?>>&nbsp;when a <strong>comment</strong> is <strong>unapproved/deleted</strong>.</label><br />
154
+ </fieldset>
155
+ </td>
156
+ </tr>
157
+ </table>
158
+ <table class="form-table rtnginx-table"<?php echo $displayvar; ?>>
159
+ <tr valign="top">
160
+ <th scope="row">
161
+ <h4>Purge Archives:</h4>
162
+ <small>(date, category, tag, author, custom taxonomies)</small>
163
+ </th>
164
+ <td>
165
+ <fieldset>
166
+ <legend class="screen-reader-text"><span>&nbsp;when an post/page/custom post is modified or added.</span></legend>
167
+ <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 ); ?>>&nbsp;when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.</label><br />
168
+ </fieldset>
169
+ <fieldset>
170
+ <legend class="screen-reader-text"><span>&nbsp;when an existing post/page/custom post is trashed.</span></legend>
171
+ <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 ); ?>>&nbsp;when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>.</label><br />
172
+ </fieldset>
173
+ <br />
174
+ <fieldset>
175
+ <legend class="screen-reader-text"><span>&nbsp;when a comment is approved/published.</span></legend>
176
+ <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 ); ?>>&nbsp;when a <strong>comment</strong> is <strong>approved/published</strong>.</label><br />
177
+ </fieldset>
178
+ <fieldset>
179
+ <legend class="screen-reader-text"><span>&nbsp;when a comment is unapproved/deleted.</span></legend>
180
+ <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 ); ?>>&nbsp;when a <strong>comment</strong> is <strong>unapproved/deleted</strong>.</label><br />
181
+ </fieldset>
182
+
183
+ </td>
184
+ </tr>
185
+ </table>
186
+
187
+ <?php
188
+ }
189
+ if ( is_network_admin() && $rt_wp_nginx_helper->options[ 'enable_map' ] != false ) {
190
+ ?>
191
+ <h3>Nginx Map</h3>
192
+ <?php if ( ! is_writable( RT_WP_NGINX_HELPER_PATH . 'map.conf' ) ) { ?>
193
+ <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>
194
+ <?php } ?>
195
+
196
+ <table class="form-table rtnginx-table">
197
+ <tr>
198
+ <th>
199
+ Nginx Map path to include in nginx settings<br />
200
+ <small>(recommended)</small>
201
+ </th>
202
+ <td>
203
+ <?php echo RT_WP_NGINX_HELPER_PATH . 'map.conf'; ?>
204
+ </td>
205
+ </tr>
206
+ <tr>
207
+ <th>
208
+ Or,<br />
209
+ Text to manually copy and paste in nginx settings<br />
210
+ <small>(if your network is small and new sites are not added frequently)</small>
211
+ </th>
212
+ <td>
213
+ <pre id="map"><?php echo $rt_wp_nginx_helper->get_map() ?></pre>
214
+ </td>
215
+ </tr>
216
+ </table>
217
+
218
+ <?php
219
+ if ( $rt_wp_nginx_helper->options[ 'enable_log' ] != false ) {
220
+ ?>
221
+ <h3>Logging</h3>
222
+
223
+ <?php if ( ! is_writable( RT_WP_NGINX_HELPER_PATH . 'nginx.log' ) ) { ?>
224
+ <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>
225
+ <?php } ?>
226
+
227
+ <table class="form-table rtnginx-table">
228
+ <tbody>
229
+ <tr>
230
+ <th><label for="rt_wp_nginx_helper_logs_path"><?php _e( 'Logs path', 'rt_wp_nginx_helper' ); ?></label></th>
231
+ <td><?php echo RT_WP_NGINX_HELPER_PATH ?>nginx.log</td>
232
+ </tr>
233
+ <tr>
234
+ <th><label for="rt_wp_nginx_helper_logs_link"><?php _e( 'View Log', 'rt_wp_nginx_helper' ); ?></label></th>
235
+ <td><a target="_blank" href="<?php echo RT_WP_NGINX_HELPER_URL ?>nginx.log">Log</a></td>
236
+ </tr>
237
+
238
+ <tr>
239
+ <th><label for="rt_wp_nginx_helper_log_level"><?php _e( 'Log level', 'rt_wp_nginx_helper' ); ?></label></th>
240
+ <td>
241
+ <select name="log_level">
242
+ <option value="NONE"<?php selected( $rt_wp_nginx_helper->options[ 'log_level' ], 'NONE' ); ?>><?php _e( 'None', 'rt_wp_nginx_helper' ); ?></option>
243
+ <option value="INFO"<?php selected( $rt_wp_nginx_helper->options[ 'log_level' ], 'INFO' ); ?>><?php _e( 'Info', 'rt_wp_nginx_helper' ); ?></option>
244
+ <option value="WARNING"<?php selected( $rt_wp_nginx_helper->options[ 'log_level' ], 'WARNING' ); ?>><?php _e( 'Warning', 'rt_wp_nginx_helper' ); ?></option>
245
+ <option value="ERROR"<?php selected( $rt_wp_nginx_helper->options[ 'log_level' ], 'ERROR' ); ?>><?php _e( 'Error', 'rt_wp_nginx_helper' ); ?></option>
246
+ </select>
247
+ </td>
248
+ </tr>
249
+
250
+ <tr>
251
+ <th><label for="log_filesize"><?php _e( 'Max log file size', 'rt_wp_nginx_helper' ); ?></label></th>
252
+ <td>
253
+ <input id="log_filesize" class="small-text" type="text" name="log_filesize" value="<?php echo $rt_wp_nginx_helper->options[ 'log_filesize' ] ?>" /> Mb
254
+ <?php if ( $error_log_filesize ) { ?>
255
+ <span class="error fade" style="display : block"><p><strong><?php echo $error_log_filesize; ?></strong></p></span>
256
+ <?php } ?>
257
+ </td>
258
+ </tr>
259
+ </tbody>
260
+ </table>
261
+
262
+ <br />
263
+ <?php } ?>
264
+ <?php } ?>
265
+
266
+ <p class="submit">
267
+ <input type="submit" name="smart_http_expire_save" class="button-primary" value="Save" />
268
+ </p>
269
+ </form>
270
+ </div>
271
+ <div id="rtads" class="metabox-holder align_left">
272
+ <?php $this->default_admin_sidebar(); ?>
273
+ </div>
274
+ </div>
275
+ <?php
276
+ break;
277
+ }
278
+ }
279
+
280
+ function default_admin_sidebar() {
281
+ ?>
282
+ <div class="postbox" id="support">
283
+ <div title="<?php _e( 'Click to toggle', 'bp-media' ); ?>" class="handlediv"><br /></div>
284
+ <h3 class="hndle"><span><?php _e( 'Need Help?', 'bp-media' ); ?></span></h3>
285
+ <div class="inside"><p><?php printf( __( ' Please use our <a href="%s">free support forum</a>.<br/><span class="bpm-aligncenter">OR</span><br/>
286
+ <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>
287
+ </div>
288
+ <div class="postbox" id="social">
289
+ <div title="<?php _e( 'Click to toggle', 'bp-media' ); ?>" class="handlediv"><br /></div>
290
+ <h3 class="hndle"><span><?php _e( 'Getting Social is Good', 'bp-media' ); ?></span></h3>
291
+ <div class="inside" style="text-align:center;">
292
+ <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>
293
+ <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>
294
+ <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>
295
+ </div>
296
+ </div>
297
+
298
+ <div class="postbox" id="latest_news">
299
+ <div title="<?php _e( 'Click to toggle', 'bp-media' ); ?>" class="handlediv"><br /></div>
300
+ <h3 class="hndle"><span><?php _e( 'Latest News', 'bp-media' ); ?></span></h3>
301
+ <div class="inside"><img src ="<?php echo admin_url(); ?>/images/wpspin_light.gif" /> Loading...</div>
302
+ </div><?php
303
+ }
304
+
305
+ function load_styles() {
306
+ wp_enqueue_style( 'rt-nginx-admin-css', plugins_url( 'admin/assets/style.css', dirname( __FILE__ ) ) );
307
+ }
308
+
309
+ function load_scripts() {
310
+ $admin_js = trailingslashit( site_url() ) . '?get_feeds=1';
311
+ wp_enqueue_script( 'nginx-js', plugins_url( 'admin/assets/nginx.js', dirname( __FILE__ ) ) );
312
+ wp_localize_script( 'nginx-js', 'news_url', $admin_js );
313
+ }
314
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  }
316
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  }
318
  ?>
admin/install.php CHANGED
@@ -1,113 +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
  ?>
1
  <?php
 
 
2
 
3
+ namespace rtCamp\WP\Nginx {
4
+ if ( preg_match( '#' . basename( __FILE__ ) . '#', $_SERVER[ 'PHP_SELF' ] ) ) {
5
+ die( 'You are not allowed to call this page directly.' );
6
+ }
7
 
8
+ function rt_wp_nginx_helper_install() {
9
 
10
+ global $wp_roles, $rt_wp_nginx_helper;
 
11
 
12
+ if ( ! current_user_can( 'activate_plugins' ) )
13
+ return;
14
 
15
+ $role = get_role( 'administrator' );
16
 
 
 
 
 
17
 
18
+ if ( empty( $role ) ) {
19
+ update_site_option( "rt_wp_nginx_helper_init_check", __( 'Sorry, you need to be an administrator to use Nginx Helper', "rt_wp_nginx_helper" ) );
20
+ return;
21
+ }
22
 
23
+ $role->add_cap( 'Nginx Helper | Config' );
24
+ $role->add_cap( 'Nginx Helper | Purge cache' );
25
 
26
+ $rt_wp_nginx_helper_get_options = get_site_option( 'rt_wp_nginx_helper_global_options' );
 
 
 
27
 
28
+ if ( empty( $rt_wp_nginx_helper_get_options ) ) {
29
+ $rt_wp_nginx_helper_get_options = rt_wp_nginx_helper_get_options();
30
+ update_site_option( "rt_wp_nginx_helper_global_options", $rt_wp_nginx_helper_get_options );
31
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ if ( is_multisite() ) {
34
+ $blogs = get_blogs_of_user( true );
35
+ foreach ( $blogs as $b ) {
36
+ $rt_wp_nginx_helper_options = get_blog_option( $b->userblog_id, 'rt_wp_nginx_helper_options' );
37
+ if ( empty( $rt_wp_nginx_helper_options ) ) {
38
+ $rt_wp_nginx_helper_options = rt_wp_nginx_helper_get_options();
39
+ update_blog_option( $b->userblog_id, "rt_wp_nginx_helper_options", $rt_wp_nginx_helper_options );
40
+ }
41
+ }
42
+ } else {
43
+ $rt_wp_nginx_helper_options = get_option( 'rt_wp_nginx_helper_options' );
44
+ if ( empty( $rt_wp_nginx_helper_options ) ) {
45
+ $rt_wp_nginx_helper_options = rt_wp_nginx_helper_get_options();
46
+ update_option( "rt_wp_nginx_helper_options", $rt_wp_nginx_helper_options );
47
+ }
48
+ }
49
+ wp_schedule_event( time(), 'daily', 'rt_wp_nginx_helper_check_log_file_size_daily' );
50
+ }
51
 
52
+ function rt_wp_nginx_helper_uninstall() {
53
 
54
+ global $rt_wp_nginx_helper, $rt_wp_nginx_purger;
55
 
56
+ wp_clear_scheduled_hook( 'rt_wp_nginx_helper_check_log_file_size_daily' );
57
 
58
+ delete_site_option( 'rt_wp_nginx_helper_options' );
59
 
60
 
61
+ rt_wp_nginx_helper_remove_capability( 'Nginx Helper | Config' );
62
+ rt_wp_nginx_helper_remove_capability( 'Nginx Helper | Purge cache' );
63
+ }
64
 
65
+ function rt_wp_nginx_helper_remove_capability( $capability ) {
66
+ $check_order = array( "subscriber", "contributor", "author", "editor", "administrator" );
67
 
68
+ foreach ( $check_order as $role ) {
69
+ $role = get_role( $role );
70
+ $role->remove_cap( $capability );
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
+ $rt_wp_nginx_helper_get_options[ 'enable_stamp' ] = 1;
93
 
94
+ $rt_wp_nginx_helper_get_options[ 'purge_homepage_on_new' ] = 1;
95
+ $rt_wp_nginx_helper_get_options[ 'purge_homepage_on_edit' ] = 1;
96
+ $rt_wp_nginx_helper_get_options[ 'purge_homepage_on_del' ] = 1;
97
 
98
+ $rt_wp_nginx_helper_get_options[ 'purge_archive_on_new' ] = 1;
99
+ $rt_wp_nginx_helper_get_options[ 'purge_archive_on_edit' ] = 1;
100
+ $rt_wp_nginx_helper_get_options[ 'purge_archive_on_del' ] = 1;
101
 
102
+ $rt_wp_nginx_helper_get_options[ 'purge_archive_on_new_comment' ] = 0;
103
+ $rt_wp_nginx_helper_get_options[ 'purge_archive_on_deleted_comment' ] = 0;
 
104
 
105
+ $rt_wp_nginx_helper_get_options[ 'purge_page_on_mod' ] = 1;
106
+ $rt_wp_nginx_helper_get_options[ 'purge_page_on_new_comment' ] = 1;
107
+ $rt_wp_nginx_helper_get_options[ 'purge_page_on_deleted_comment' ] = 1;
108
 
109
+ return $rt_wp_nginx_helper_get_options;
110
+ }
 
 
 
 
 
 
 
 
111
 
112
  }
113
  ?>
nginx-helper.php CHANGED
@@ -3,349 +3,357 @@
3
  Plugin Name: Nginx Helper
4
  Plugin URI: http://rtcamp.com/
5
  Description: An nginx helper that serves various functions.
6
- Version: 1.4
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.4'; // 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
- add_action( 'shutdown', array(&$this, 'add_timestamps'), 99999);
42
 
43
- add_action( 'publish_post', array(&$rt_wp_nginx_purger, 'purgePost'), 200, 1);
44
- add_action( 'publish_page', array(&$rt_wp_nginx_purger, 'purgePost'), 200, 1);
45
- add_action( 'wp_insert_comment', array(&$rt_wp_nginx_purger, 'purgePostOnComment'), 200, 2);
46
- add_action( 'transition_comment_status', array(&$rt_wp_nginx_purger, 'purgePostOnCommentChange'), 200, 3 );
47
 
48
- $args=array('_builtin'=>false);
49
- $_rt_custom_post_types = get_post_types( $args );
50
- if ( isset($post_types) && !empty($post_types) ) {
51
- if($this->options['rt_wp_custom_post_types']==true){
52
- foreach ( $_rt_custom_post_types as $post_type ) {
53
- add_action( 'publish_'.trim($post_type), array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
54
- }
55
- }
56
 
57
- }
 
58
 
59
- add_action( 'transition_post_status', array(&$this, 'set_future_post_option_on_future_status'), 20, 3 );
60
- add_action( 'delete_post', array(&$this, 'unset_future_post_option_on_delete'), 20, 1 );
61
 
62
- add_action( 'nm_check_log_file_size_daily', array(&$rt_wp_nginx_purger, 'checkAndTruncateLogFile'), 100, 1 );
 
 
 
63
 
64
- add_action( 'edit_attachment', array(&$rt_wp_nginx_purger, 'purgeImageOnEdit'), 100, 1 );
 
 
 
 
 
 
 
 
 
65
 
66
- add_action( 'wpmu_new_blog', array(&$this, 'update_new_blog_options'), 10, 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- add_action( 'transition_post_status', array(&$rt_wp_nginx_purger, 'purge_on_post_moved_to_trash'), 20, 3 );
69
 
70
- add_action( 'edit_term', array(&$rt_wp_nginx_purger, 'purge_on_term_taxonomy_edited'), 20, 3 );
71
- add_action( 'delete_term', array(&$rt_wp_nginx_purger, 'purge_on_term_taxonomy_edited'), 20, 3 );
 
 
 
 
 
 
 
72
 
73
- add_action( 'check_ajax_referer', array(&$rt_wp_nginx_purger, 'purge_on_check_ajax_referer'), 20, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
- }
 
 
 
76
 
77
- function activate() {
78
- include_once (RT_WP_NGINX_HELPER_PATH. 'admin/install.php');
79
- rt_wp_nginx_helper_install();
80
- }
81
 
82
- function deactivate() {
83
- include_once (RT_WP_NGINX_HELPER_PATH. 'admin/install.php');
84
- rt_wp_nginx_helper_uninstall();
85
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
- function define_constant() {
88
- define('RT_WP_NGINX_HELPER_VERSION', $this->version );
89
- define('RT_WP_NGINX_HELPER_DB_VERSION', $this->db_version );
90
- define('RT_WP_NGINX_HELPER_FOLDER', plugin_basename( dirname(__FILE__)) );
91
  }
92
 
93
- function required_wp_version() {
94
-
95
- global $wp_version;
96
- $wp_ok = version_compare( $wp_version, $this->minium_WP, '>=' );
97
-
98
- if ( ($wp_ok == FALSE) ) {
99
- add_action(
100
- 'admin_notices',
101
- create_function(
102
- '',
103
- '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 );'
104
- )
105
- );
106
- return false;
107
- }
108
-
109
- return true;
110
-
111
- }
112
- function required_php_version(){
113
-
114
- $php_ok = version_compare(PHP_VERSION, '5.3', '>=');
115
- if ( ($php_ok == FALSE) ) {
116
- add_action(
117
- 'admin_notices',
118
- create_function(
119
- '',
120
- '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 );'
121
- )
122
- );
123
- return false;
124
- }
125
-
126
- return true;
127
- }
128
-
129
- function load_options() {
130
- $this->options = get_site_option( 'rt_wp_nginx_helper_options' );
131
- }
132
-
133
- function set_future_post_option_on_future_status($new_status, $old_status, $post) {
134
-
135
- global $blog_id, $rt_wp_nginx_purger;
136
- if(!$this->options['enable_purge']){
137
- return;
138
- }
139
- if ( $old_status != $new_status
140
- && $old_status != 'inherit'
141
- && $new_status != 'inherit'
142
- && $old_status != 'auto-draft'
143
- && $new_status != 'auto-draft'
144
- && $new_status != 'publish'
145
- && !wp_is_post_revision( $post->ID ) ) {
146
- $rt_wp_nginx_purger->log( "Purge post on transition post STATUS from ".$old_status." to ".$new_status );
147
- $rt_wp_nginx_purger->purgePost($post->ID);
148
- }
149
-
150
- if ($new_status == 'future') {
151
- 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']) ) ) ) {
152
- $rt_wp_nginx_purger->log( "Set/update future_posts option (post id = ".$post->ID." and blog id = ".$blog_id.")" );
153
- $this->options['future_posts'][$blog_id][$post->ID] = strtotime($post->post_date_gmt)+60;
154
- update_site_option("rt_wp_nginx_helper_global_options", $this->options);
155
  }
156
- }
157
- }
158
-
159
- function unset_future_post_option_on_delete($post_id) {
160
-
161
- global $blog_id, $rt_wp_nginx_purger;
162
- if(!$this->options['enable_purge']){
163
- return;
164
- }
165
- if ($post_id && !wp_is_post_revision($post_id)) {
166
-
167
- if ( isset($this->options['future_posts'][$blog_id][$post_id]) && count($this->options['future_posts'][$blog_id][$post_id]) ) {
168
- $rt_wp_nginx_purger->log( "Unset future_posts option (post id = ".$post_id." and blog id = ".$blog_id.")" );
169
- unset($this->options['future_posts'][$blog_id][$post_id]);
170
- update_site_option("rt_wp_nginx_helper_global_options", $this->options);
171
-
172
- if ( !count($this->options['future_posts'][$blog_id]) ) {
173
- unset($this->options['future_posts'][$blog_id]);
174
- update_site_option("rt_wp_nginx_helper_global_options", $this->options);
175
- }
176
- }
177
- }
178
  }
179
 
180
- function update_new_blog_options( $blog_id ) {
181
-
182
- global $rt_wp_nginx_purger;
183
-
184
- include_once (RT_WP_NGINX_HELPER_PATH . 'admin/install.php');
185
-
186
- $rt_wp_nginx_purger->log( "New site added (id $blog_id)" );
187
-
188
- $this->update_map();
189
-
190
- $rt_wp_nginx_purger->log( "New site added to nginx map (id $blog_id)" );
191
-
192
- $helper_options = rt_wp_nginx_helper_get_options();
193
-
194
- update_blog_option( $blog_id, "rt_wp_nginx_helper_options", $helper_options, true );
195
-
196
- $rt_wp_nginx_purger->log( "Default options updated for the new blog (id $blog_id)" );
197
-
198
- }
199
- function get_map(){
200
- if(!$this->options['enable_map']){
201
- return;
202
- }
203
-
204
- if (is_multisite()){
205
-
206
- global $wpdb;
207
-
208
- $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));
209
- $wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
210
- if($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->dmtable}'") == $wpdb->dmtable) {
211
- $rt_domain_map_sites = $wpdb->get_results( "SELECT blog_id, domain FROM {$wpdb->dmtable} ORDER BY id DESC" );
212
- }
213
- $rt_nginx_map = "";
214
- $rt_nginx_map_array = array();
215
-
216
-
217
- if ($rt_all_blogs)
218
- foreach ($rt_all_blogs as $blog)
219
- if ( SUBDOMAIN_INSTALL == "yes" )
220
- $rt_nginx_map_array[$blog->blog_id] .= $blog->domain;
221
- else
222
- if ( $blog->blog_id != 1 )
223
- $rt_nginx_map_array[$blog->blog_id] = $blog->path;
224
-
225
- if($rt_domain_map_sites)
226
- foreach($rt_domain_map_sites as $site)
227
- $rt_nginx_map_array[$site->blog_id] .= $site->domain;
228
-
229
- foreach ($rt_nginx_map_array as $blog_id=>$blog)
230
- $rt_nginx_map .= "\t" . $blog . "\t" . $blog_id . ";\n";
231
-
232
- return $rt_nginx_map;
233
- }
234
- }
235
- function update_map(){
236
- if (is_multisite()){
237
- $rt_nginx_map = $this->get_map();
238
- if ($fp = fopen(RT_WP_NGINX_HELPER_PATH .'map.conf','w+')) {
239
- fwrite($fp, $rt_nginx_map);
240
- fclose($fp);
241
- return true;
242
- }
243
- }
244
- }
245
- function add_timestamps(){
246
- global $xrequest;
247
- if($this->options['enable_purge']!=1) return;
248
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) return;
249
- $timestamps = "\n<!--".
250
- "Cached using Nginx-Helper on ".current_time('mysql').". ".
251
- "It took ".get_num_queries()." queries executed in ".timer_stop()." seconds.".
252
- "-->\n".
253
- "<!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->";
254
- echo $timestamps;
255
- }
256
-
257
- }
258
 
259
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
 
261
- namespace{
262
- global $current_blog;
263
-
264
- if ( is_admin() ) {
265
- require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH. '/admin/admin.php');
266
- $rtwpAdminPanel = new \rtCamp\WP\Nginx\Admin();
267
- }
268
-
269
- require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH . 'purger.php');
270
-
271
- require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH . 'compatibility.php');
272
-
273
- global $rt_wp_nginx_helper,$rt_wp_nginx_purger,$rt_wp_nginx_compatibility;
274
- $rt_wp_nginx_helper = new \rtCamp\WP\Nginx\Helper;
275
- $rt_wp_nginx_purger = new \rtCamp\WP\Nginx\Purger;
276
- $rt_wp_nginx_compatibility = namespace\rtCamp\WP\Nginx\Compatibility::instance();
277
- if ($rt_wp_nginx_compatibility->haveNginx() && !function_exists('wp_redirect')) {
278
-
279
- function wp_redirect($location, $status = 302){
280
- $location = apply_filters('wp_redirect', $location, $status);
281
-
282
- if (empty($location)) {
283
- return false;
284
- }
285
-
286
- $status = apply_filters('wp_redirect_status', $status, $location);
287
- if ($status < 300 || $status > 399) {
288
- $status = 302;
289
- }
290
-
291
- $location = wp_sanitize_redirect($location);
292
- header('Location: ' . $location, true, $status);
293
- }
294
-
295
- }
296
- // Add settings link on plugin page
297
- function nginx_settings_link($links) {
298
- if(is_network_admin()){
299
- $u='settings.php';
300
- }else{
301
- $u='options-general.php';
302
- }
303
- $settings_link = '<a href="'.$u.'?page=nginx">Settings</a>';
304
- array_unshift($links, $settings_link);
305
- return $links;
306
- }
307
-
308
- $plugin = plugin_basename(__FILE__);
309
- if(is_multisite()){
310
- add_filter("network_admin_plugin_action_links_$plugin", 'nginx_settings_link' );
311
- }else{
312
- add_filter("plugin_action_links_$plugin", 'nginx_settings_link' );
313
- }
314
- function get_feeds($feed_url = 'http://rtcamp.com/blog/feed/') {
315
- // Get RSS Feed(s)
316
- require_once( ABSPATH . WPINC . '/feed.php' );
317
- $maxitems = 0;
318
- // Get a SimplePie feed object from the specified feed source.
319
- $rss = fetch_feed($feed_url);
320
- if (!is_wp_error($rss)) { // Checks that the object is created correctly
321
- // Figure out how many total items there are, but limit it to 5.
322
- $maxitems = $rss->get_item_quantity(5);
323
-
324
- // Build an array of all the items, starting with element 0 (first element).
325
- $rss_items = $rss->get_items(0, $maxitems);
326
- }
327
- ?>
328
- <ul><?php
329
- if ($maxitems == 0) {
330
- echo '<li>' . __('No items', 'bp-media') . '.</li>';
331
- } else {
332
- // Loop through each feed item and display each item as a hyperlink.
333
- foreach ($rss_items as $item) {
334
- ?>
335
- <li>
336
- <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>
337
- </li><?php
338
- }
339
- }
340
- ?>
341
- </ul><?php
342
- }
343
- function fetch_feeds() {
344
- if(isset($_GET['get_feeds'])&&$_GET['get_feeds']=='1'){
345
- get_feeds();
346
- die();
347
- }
348
- }
349
- add_action('init','fetch_feeds');
350
  }
351
  ?>
3
  Plugin Name: Nginx Helper
4
  Plugin URI: http://rtcamp.com/
5
  Description: An nginx helper that serves various functions.
6
+ Version: 1.5
7
  Author: rtCamp
8
  Author URI: http://rtcamp.com
9
  Requires at least: 3.0
10
  Tested up to: 3.4.2
11
+ */
12
+
13
  namespace rtCamp\WP\Nginx {
14
+ define( 'rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH', plugin_dir_path( __FILE__ ) );
15
+ define( 'rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_URL', plugin_dir_url( __FILE__ ) );
16
+
17
+ class Helper {
18
+
19
+ var $version = '1.4'; // Plugin version
20
+ var $db_version = '0.1'; // DB version, change it to show the upgrade page
21
+ var $minium_WP = '3.0';
22
+ var $minimum_PHP = '5.3';
23
+ var $options = null;
24
+
25
+ function __construct() {
26
+
27
+ if ( ! $this->required_wp_version() )
28
+ if ( ! $this->required_php_version() )
29
+ return;
30
+
31
+ $this->load_options();
32
+ $this->define_constant();
33
+ $this->plugin_name = plugin_basename( __FILE__ );
34
+
35
+ register_activation_hook( $this->plugin_name, array( &$this, 'activate' ) );
36
+ register_deactivation_hook( $this->plugin_name, array( &$this, 'deactivate' ) );
37
+
38
+ add_action( 'init', array( &$this, 'start_helper' ), 15 );
39
+ }
40
 
41
+ function start_helper() {
42
 
43
+ global $rt_wp_nginx_purger;
44
+ add_action( 'shutdown', array( &$this, 'add_timestamps' ), 99999 );
 
45
 
46
+ add_action( 'publish_post', array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
47
+ add_action( 'publish_page', array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
48
+ add_action( 'wp_insert_comment', array( &$rt_wp_nginx_purger, 'purgePostOnComment' ), 200, 2 );
49
+ add_action( 'transition_comment_status', array( &$rt_wp_nginx_purger, 'purgePostOnCommentChange' ), 200, 3 );
50
 
51
+ $args = array( '_builtin' => false );
52
+ $_rt_custom_post_types = get_post_types( $args );
53
+ if ( isset( $post_types ) && ! empty( $post_types ) ) {
54
+ if ( $this->options[ 'rt_wp_custom_post_types' ] == true ) {
55
+ foreach ( $_rt_custom_post_types as $post_type ) {
56
+ add_action( 'publish_' . trim( $post_type ), array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
57
+ }
58
+ }
59
+ }
60
 
61
+ add_action( 'transition_post_status', array( &$this, 'set_future_post_option_on_future_status' ), 20, 3 );
62
+ add_action( 'delete_post', array( &$this, 'unset_future_post_option_on_delete' ), 20, 1 );
63
 
64
+ add_action( 'nm_check_log_file_size_daily', array( &$rt_wp_nginx_purger, 'checkAndTruncateLogFile' ), 100, 1 );
 
65
 
66
+ add_action( 'edit_attachment', array( &$rt_wp_nginx_purger, 'purgeImageOnEdit' ), 100, 1 );
 
67
 
68
+ add_action( 'wpmu_new_blog', array( &$this, 'update_new_blog_options' ), 10, 1 );
 
 
 
69
 
70
+ add_action( 'transition_post_status', array( &$rt_wp_nginx_purger, 'purge_on_post_moved_to_trash' ), 20, 3 );
 
 
 
 
 
 
 
71
 
72
+ add_action( 'edit_term', array( &$rt_wp_nginx_purger, 'purge_on_term_taxonomy_edited' ), 20, 3 );
73
+ add_action( 'delete_term', array( &$rt_wp_nginx_purger, 'purge_on_term_taxonomy_edited' ), 20, 3 );
74
 
75
+ add_action( 'check_ajax_referer', array( &$rt_wp_nginx_purger, 'purge_on_check_ajax_referer' ), 20, 2 );
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', create_function(
102
+ '', '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 );'
103
+ )
104
+ );
105
+ return false;
106
+ }
107
+
108
+ return true;
109
+ }
110
 
111
+ function required_php_version() {
112
 
113
+ $php_ok = version_compare( PHP_VERSION, '5.3', '>=' );
114
+ if ( ($php_ok == FALSE ) ) {
115
+ add_action(
116
+ 'admin_notices', create_function(
117
+ '', '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 );'
118
+ )
119
+ );
120
+ return false;
121
+ }
122
 
123
+ return true;
124
+ }
125
+
126
+ function load_options() {
127
+ $this->options = get_site_option( 'rt_wp_nginx_helper_options' );
128
+ }
129
+
130
+ function set_future_post_option_on_future_status( $new_status, $old_status, $post ) {
131
+
132
+ global $blog_id, $rt_wp_nginx_purger;
133
+ if ( ! $this->options[ 'enable_purge' ] ) {
134
+ return;
135
+ }
136
+ if ( $old_status != $new_status
137
+ && $old_status != 'inherit'
138
+ && $new_status != 'inherit'
139
+ && $old_status != 'auto-draft'
140
+ && $new_status != 'auto-draft'
141
+ && $new_status != 'publish'
142
+ && ! wp_is_post_revision( $post->ID ) ) {
143
+ $rt_wp_nginx_purger->log( "Purge post on transition post STATUS from " . $old_status . " to " . $new_status );
144
+ $rt_wp_nginx_purger->purgePost( $post->ID );
145
+ }
146
+
147
+ if ( $new_status == 'future' ) {
148
+ 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' ] ) ) ) ) {
149
+ $rt_wp_nginx_purger->log( "Set/update future_posts option (post id = " . $post->ID . " and blog id = " . $blog_id . ")" );
150
+ $this->options[ 'future_posts' ][ $blog_id ][ $post->ID ] = strtotime( $post->post_date_gmt ) + 60;
151
+ update_site_option( "rt_wp_nginx_helper_global_options", $this->options );
152
+ }
153
+ }
154
+ }
155
+
156
+ function unset_future_post_option_on_delete( $post_id ) {
157
+
158
+ global $blog_id, $rt_wp_nginx_purger;
159
+ if ( ! $this->options[ 'enable_purge' ] ) {
160
+ return;
161
+ }
162
+ if ( $post_id && ! wp_is_post_revision( $post_id ) ) {
163
+
164
+ if ( isset( $this->options[ 'future_posts' ][ $blog_id ][ $post_id ] ) && count( $this->options[ 'future_posts' ][ $blog_id ][ $post_id ] ) ) {
165
+ $rt_wp_nginx_purger->log( "Unset future_posts option (post id = " . $post_id . " and blog id = " . $blog_id . ")" );
166
+ unset( $this->options[ 'future_posts' ][ $blog_id ][ $post_id ] );
167
+ update_site_option( "rt_wp_nginx_helper_global_options", $this->options );
168
+
169
+ if ( ! count( $this->options[ 'future_posts' ][ $blog_id ] ) ) {
170
+ unset( $this->options[ 'future_posts' ][ $blog_id ] );
171
+ update_site_option( "rt_wp_nginx_helper_global_options", $this->options );
172
+ }
173
+ }
174
+ }
175
+ }
176
+
177
+ function update_new_blog_options( $blog_id ) {
178
+
179
+ global $rt_wp_nginx_purger;
180
+
181
+ include_once (RT_WP_NGINX_HELPER_PATH . 'admin/install.php');
182
+
183
+ $rt_wp_nginx_purger->log( "New site added (id $blog_id)" );
184
+
185
+ $this->update_map();
186
+
187
+ $rt_wp_nginx_purger->log( "New site added to nginx map (id $blog_id)" );
188
+
189
+ $helper_options = rt_wp_nginx_helper_get_options();
190
+
191
+ update_blog_option( $blog_id, "rt_wp_nginx_helper_options", $helper_options, true );
192
+
193
+ $rt_wp_nginx_purger->log( "Default options updated for the new blog (id $blog_id)" );
194
+ }
195
 
196
+ function get_map() {
197
+ if ( ! $this->options[ 'enable_map' ] ) {
198
+ return;
199
+ }
200
 
201
+ if ( is_multisite() ) {
 
 
 
202
 
203
+ global $wpdb;
204
+
205
+ $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 ) );
206
+ $wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
207
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->dmtable}'" ) == $wpdb->dmtable ) {
208
+ $rt_domain_map_sites = $wpdb->get_results( "SELECT blog_id, domain FROM {$wpdb->dmtable} ORDER BY id DESC" );
209
+ }
210
+ $rt_nginx_map = "";
211
+ $rt_nginx_map_array = array( );
212
+
213
+
214
+ if ( $rt_all_blogs )
215
+ foreach ( $rt_all_blogs as $blog )
216
+ if ( SUBDOMAIN_INSTALL == "yes" )
217
+ $rt_nginx_map_array[ $blog->blog_id ] .= $blog->domain;
218
+ else
219
+ if ( $blog->blog_id != 1 )
220
+ $rt_nginx_map_array[ $blog->blog_id ] = $blog->path;
221
+
222
+ if ( $rt_domain_map_sites )
223
+ foreach ( $rt_domain_map_sites as $site )
224
+ $rt_nginx_map_array[ $site->blog_id ] .= $site->domain;
225
+
226
+ foreach ( $rt_nginx_map_array as $blog_id => $blog )
227
+ $rt_nginx_map .= "\t" . $blog . "\t" . $blog_id . ";\n";
228
+
229
+ return $rt_nginx_map;
230
+ }
231
+ }
232
+
233
+ function update_map() {
234
+ if ( is_multisite() ) {
235
+ $rt_nginx_map = $this->get_map();
236
+ if ( $fp = fopen( RT_WP_NGINX_HELPER_PATH . 'map.conf', 'w+' ) ) {
237
+ fwrite( $fp, $rt_nginx_map );
238
+ fclose( $fp );
239
+ return true;
240
+ }
241
+ }
242
+ }
243
+
244
+ function add_timestamps() {
245
+ if ( $this->options[ 'enable_purge' ] != 1 )
246
+ return;
247
+ if ( $this->options[ 'enable_stamp' ] != 1 )
248
+ return;
249
+ if ($_SERVER["CONTENT_TYPE"]!='text/html')
250
+ return;
251
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
252
+ return;
253
+ $timestamps = "\n<!--" .
254
+ "Cached using Nginx-Helper on " . current_time( 'mysql' ) . ". " .
255
+ "It took " . get_num_queries() . " queries executed in " . timer_stop() . " seconds." .
256
+ "-->\n" .
257
+ "<!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->";
258
+ echo $timestamps;
259
+ }
260
+
261
+ }
262
+
263
+ }
264
+
265
+ namespace {
266
+ global $current_blog;
267
+
268
+ if ( is_admin() ) {
269
+ require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH . '/admin/admin.php');
270
+ $rtwpAdminPanel = new \rtCamp\WP\Nginx\Admin();
271
+ }
272
+
273
+ require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH . 'purger.php');
274
+
275
+ require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH . 'compatibility.php');
276
+
277
+ global $rt_wp_nginx_helper, $rt_wp_nginx_purger, $rt_wp_nginx_compatibility;
278
+ $rt_wp_nginx_helper = new \rtCamp\WP\Nginx\Helper;
279
+ $rt_wp_nginx_purger = new \rtCamp\WP\Nginx\Purger;
280
+ $rt_wp_nginx_compatibility = namespace\rtCamp\WP\Nginx\Compatibility::instance();
281
+ if ( $rt_wp_nginx_compatibility->haveNginx() && ! function_exists( 'wp_redirect' ) ) {
282
+
283
+ function wp_redirect( $location, $status = 302 ) {
284
+ $location = apply_filters( 'wp_redirect', $location, $status );
285
+
286
+ if ( empty( $location ) ) {
287
+ return false;
288
+ }
289
+
290
+ $status = apply_filters( 'wp_redirect_status', $status, $location );
291
+ if ( $status < 300 || $status > 399 ) {
292
+ $status = 302;
293
+ }
294
+
295
+ $location = wp_sanitize_redirect( $location );
296
+ header( 'Location: ' . $location, true, $status );
297
+ }
298
 
 
 
 
 
299
  }
300
 
301
+ // Add settings link on plugin page
302
+ function nginx_settings_link( $links ) {
303
+ if ( is_network_admin() ) {
304
+ $u = 'settings.php';
305
+ } else {
306
+ $u = 'options-general.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  }
308
+ $settings_link = '<a href="' . $u . '?page=nginx">Settings</a>';
309
+ array_unshift( $links, $settings_link );
310
+ return $links;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  }
312
 
313
+ $plugin = plugin_basename( __FILE__ );
314
+ if ( is_multisite() ) {
315
+ add_filter( "network_admin_plugin_action_links_$plugin", 'nginx_settings_link' );
316
+ } else {
317
+ add_filter( "plugin_action_links_$plugin", 'nginx_settings_link' );
318
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
 
320
+ function get_feeds( $feed_url = 'http://rtcamp.com/blog/feed/' ) {
321
+ // Get RSS Feed(s)
322
+ require_once( ABSPATH . WPINC . '/feed.php' );
323
+ $maxitems = 0;
324
+ // Get a SimplePie feed object from the specified feed source.
325
+ $rss = fetch_feed( $feed_url );
326
+ if ( ! is_wp_error( $rss ) ) { // Checks that the object is created correctly
327
+ // Figure out how many total items there are, but limit it to 5.
328
+ $maxitems = $rss->get_item_quantity( 5 );
329
+
330
+ // Build an array of all the items, starting with element 0 (first element).
331
+ $rss_items = $rss->get_items( 0, $maxitems );
332
+ }
333
+ ?>
334
+ <ul><?php
335
+ if ( $maxitems == 0 ) {
336
+ echo '<li>' . __( 'No items', 'bp-media' ) . '.</li>';
337
+ } else {
338
+ // Loop through each feed item and display each item as a hyperlink.
339
+ foreach ( $rss_items as $item ) {
340
+ ?>
341
+ <li>
342
+ <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>
343
+ </li><?php
344
+ }
345
+ }
346
+ ?>
347
+ </ul><?php
348
+ }
349
+
350
+ function fetch_feeds() {
351
+ if ( isset( $_GET[ 'get_feeds' ] ) && $_GET[ 'get_feeds' ] == '1' ) {
352