Nginx Helper - Version 1.6.7

Version Description

  • Better content-type detection for cache verification comments (by jk3us
Download this release

Release Info

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

Code changes from version 1.6.6 to 1.6.7

nginx-helper.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Nginx Helper
4
  Plugin URI: http://rtcamp.com/
5
  Description: An nginx helper that serves various functions.
6
- Version: 1.6.6
7
  Author: rtCamp
8
  Author URI: http://rtcamp.com
9
  Requires at least: 3.0
@@ -254,8 +254,13 @@ namespace rtCamp\WP\Nginx {
254
  return;
255
  if ( $this->options[ 'enable_stamp' ] != 1 )
256
  return;
257
- if ( $_SERVER[ "CONTENT_TYPE" ] != 'text/html' )
258
- return;
 
 
 
 
 
259
  if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
260
  return;
261
  $timestamps = "\n<!--" .
@@ -394,4 +399,4 @@ namespace {
394
 
395
  add_action( 'init', 'fetch_feeds' );
396
  }
397
- ?>
3
  Plugin Name: Nginx Helper
4
  Plugin URI: http://rtcamp.com/
5
  Description: An nginx helper that serves various functions.
6
+ Version: 1.6.7
7
  Author: rtCamp
8
  Author URI: http://rtcamp.com
9
  Requires at least: 3.0
254
  return;
255
  if ( $this->options[ 'enable_stamp' ] != 1 )
256
  return;
257
+ foreach (headers_list() as $header) {
258
+ list($key,$value) = explode(':',$header,2);
259
+ if($key == 'Content-Type' && strpos(trim($value),'text/html') !== 0) {
260
+ return;
261
+ }
262
+ if($key == 'Content-Type') break;
263
+ }
264
  if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
265
  return;
266
  $timestamps = "\n<!--" .
399
 
400
  add_action( 'init', 'fetch_feeds' );
401
  }
402
+ ?>
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Nginx ===
2
- Contributors: rtcamp, rahul286, saurabhshukla, darren-slatten
3
  Tags: nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, rewrite, permalinks
4
  Requires at least: 3.0
5
  Tested up to: 3.4.2
6
- Stable tag: 1.6.6
7
  License: GPLv2 or later (of-course)
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate Link: http://rtcamp.com/donate/
@@ -105,8 +105,11 @@ Its just that we are hyperactive on our own forum!
105
 
106
  == Changelog ==
107
 
 
 
 
108
  = 1.6.6 =
109
- * Added Manual 'Purge all URLs' functionality (by [darren-slatten](http://profiles.wordpress.org/darren-slatten/)
110
 
111
  = 1.6.5 =
112
  * Fixed typo that interfered with archive purge settings. Thanks to [Daan Kortenbach](http://profiles.wordpress.org/daankortenbach/) for pointing this out.
@@ -195,5 +198,5 @@ Its just that we are hyperactive on our own forum!
195
 
196
  == Upgrade Notice ==
197
 
198
- = 1.6.6 =
199
- Added manual 'purge all urls' feature
1
  === Nginx ===
2
+ Contributors: rtcamp, rahul286, saurabhshukla, Darren Slatten, jk3us
3
  Tags: nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, rewrite, permalinks
4
  Requires at least: 3.0
5
  Tested up to: 3.4.2
6
+ Stable tag: 1.6.7
7
  License: GPLv2 or later (of-course)
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate Link: http://rtcamp.com/donate/
105
 
106
  == Changelog ==
107
 
108
+ = 1.6.7 =
109
+ * Better content-type detection for cache verification comments (by [jk3us](http://profiles.wordpress.org/jk3us)
110
+
111
  = 1.6.6 =
112
+ * Added Manual 'Purge all URLs' functionality (by [darren-slatten](http://profiles.wordpress.org/darren-slatten/))
113
 
114
  = 1.6.5 =
115
  * Fixed typo that interfered with archive purge settings. Thanks to [Daan Kortenbach](http://profiles.wordpress.org/daankortenbach/) for pointing this out.
198
 
199
  == Upgrade Notice ==
200
 
201
+ = 1.6.7 =
202
+ Improved cache verification comments.
trunk/admin/admin.php ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="purgeall" action="" method="post">
95
+ <?php $purge_url = add_query_arg( array( 'nginx_helper_action' => 'purge', 'nginx_helper_urls' => 'all' ) ); ?>
96
+ <?php $nonced_url = wp_nonce_url( $purge_url, 'nginx_helper-purge_all' ); ?>
97
+ <a href="<?php echo $nonced_url; ?>" class="button-primary">Purge all URLs</a>
98
+ </form>
99
+ <form id="post_form" method="post" action="#" name="smart_http_expire_form">
100
+ <?php if ( ! ( ! is_network_admin() && is_multisite()) ) { ?>
101
+
102
+ <input type="hidden" name="is_submit" value="1" />
103
+
104
+ <h3>Plugin Options</h3>
105
+
106
+ <table class="form-table">
107
+ <tr valign="top">
108
+ <td>
109
+ <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 ); ?>>&nbsp;Enable Cache Purge (requires external settings for nginx).</label><br />
110
+ <?php if ( is_network_admin() ) { ?>
111
+ <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 ); ?>>&nbsp;Enable Nginx Map.</label><br />
112
+ <?php } ?>
113
+ <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 ); ?>>&nbsp;Enable Logging</label><br />
114
+ <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 ); ?>>&nbsp;Enable Nginx Timestamp in HTML</label>
115
+ </td>
116
+ </tr>
117
+ </table>
118
+
119
+ <?php
120
+ $displayvar = '';
121
+ if ( $rt_wp_nginx_helper->options[ 'enable_purge' ] == false ) {
122
+ $displayvar = ' style="display:none"';
123
+ }
124
+ ?>
125
+ <h3<?php echo $displayvar; ?>>Purging Options</h3>
126
+
127
+ <table class="form-table rtnginx-table"<?php echo $displayvar; ?>>
128
+ <tr valign="top">
129
+ <th scope="row"><h4>Purge Homepage:</h4></th>
130
+ <td>
131
+ <fieldset>
132
+ <legend class="screen-reader-text"><span>&nbsp;when a post/page/custom post is modified or added.</span></legend>
133
+ <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 />
134
+ </fieldset>
135
+ <fieldset>
136
+ <legend class="screen-reader-text"><span>&nbsp;when an existing post/page/custom post is modified.</span></legend>
137
+ <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 />
138
+ </fieldset>
139
+ </td>
140
+ </tr>
141
+ </table>
142
+ <table class="form-table rtnginx-table"<?php echo $displayvar; ?>>
143
+ <tr valign="top">
144
+ <th scope="row">
145
+ <h4>Purge Post/Page/Custom Post Type:</h4>
146
+ </th>
147
+ <td>
148
+ <fieldset>
149
+ <legend class="screen-reader-text"><span>&nbsp;when a post/page/custom post is published.</span></legend>
150
+ <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 />
151
+ </fieldset>
152
+ <fieldset>
153
+ <legend class="screen-reader-text"><span>&nbsp;when a comment is approved/published.</span></legend>
154
+ <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 />
155
+ </fieldset>
156
+ <fieldset>
157
+ <legend class="screen-reader-text"><span>&nbsp;when a comment is unapproved/deleted.</span></legend>
158
+ <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 />
159
+ </fieldset>
160
+ </td>
161
+ </tr>
162
+ </table>
163
+ <table class="form-table rtnginx-table"<?php echo $displayvar; ?>>
164
+ <tr valign="top">
165
+ <th scope="row">
166
+ <h4>Purge Archives:</h4>
167
+ <small>(date, category, tag, author, custom taxonomies)</small>
168
+ </th>
169
+ <td>
170
+ <fieldset>
171
+ <legend class="screen-reader-text"><span>&nbsp;when an post/page/custom post is modified or added.</span></legend>
172
+ <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 />
173
+ </fieldset>
174
+ <fieldset>
175
+ <legend class="screen-reader-text"><span>&nbsp;when an existing post/page/custom post is trashed.</span></legend>
176
+ <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 />
177
+ </fieldset>
178
+ <br />
179
+ <fieldset>
180
+ <legend class="screen-reader-text"><span>&nbsp;when a comment is approved/published.</span></legend>
181
+ <label for="purge_archive_on_new_comment"><input type="checkbox" value="1" id="purge_archive_on_new_comment" name="purge_archive_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 />
182
+ </fieldset>
183
+ <fieldset>
184
+ <legend class="screen-reader-text"><span>&nbsp;when a comment is unapproved/deleted.</span></legend>
185
+ <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 />
186
+ </fieldset>
187
+
188
+ </td>
189
+ </tr>
190
+ </table>
191
+
192
+ <?php
193
+ }
194
+ if ( is_network_admin() && $rt_wp_nginx_helper->options[ 'enable_map' ] != false ) {
195
+ ?>
196
+ <h3>Nginx Map</h3>
197
+ <?php if ( ! is_writable( RT_WP_NGINX_HELPER_PATH . 'map.conf' ) ) { ?>
198
+ <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>
199
+ <?php } ?>
200
+
201
+ <table class="form-table rtnginx-table">
202
+ <tr>
203
+ <th>
204
+ Nginx Map path to include in nginx settings<br />
205
+ <small>(recommended)</small>
206
+ </th>
207
+ <td>
208
+ <?php echo RT_WP_NGINX_HELPER_PATH . 'map.conf'; ?>
209
+ </td>
210
+ </tr>
211
+ <tr>
212
+ <th>
213
+ Or,<br />
214
+ Text to manually copy and paste in nginx settings<br />
215
+ <small>(if your network is small and new sites are not added frequently)</small>
216
+ </th>
217
+ <td>
218
+ <pre id="map"><?php echo $rt_wp_nginx_helper->get_map() ?></pre>
219
+ </td>
220
+ </tr>
221
+ </table>
222
+
223
+ <?php
224
+ if ( $rt_wp_nginx_helper->options[ 'enable_log' ] != false ) {
225
+ ?>
226
+ <h3>Logging</h3>
227
+
228
+ <?php if ( ! is_writable( RT_WP_NGINX_HELPER_PATH . 'nginx.log' ) ) { ?>
229
+ <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>
230
+ <?php } ?>
231
+
232
+ <table class="form-table rtnginx-table">
233
+ <tbody>
234
+ <tr>
235
+ <th><label for="rt_wp_nginx_helper_logs_path"><?php _e( 'Logs path', 'rt_wp_nginx_helper' ); ?></label></th>
236
+ <td><?php echo RT_WP_NGINX_HELPER_PATH ?>nginx.log</td>
237
+ </tr>
238
+ <tr>
239
+ <th><label for="rt_wp_nginx_helper_logs_link"><?php _e( 'View Log', 'rt_wp_nginx_helper' ); ?></label></th>
240
+ <td><a target="_blank" href="<?php echo RT_WP_NGINX_HELPER_URL ?>nginx.log">Log</a></td>
241
+ </tr>
242
+
243
+ <tr>
244
+ <th><label for="rt_wp_nginx_helper_log_level"><?php _e( 'Log level', 'rt_wp_nginx_helper' ); ?></label></th>
245
+ <td>
246
+ <select name="log_level">
247
+ <option value="NONE"<?php selected( $rt_wp_nginx_helper->options[ 'log_level' ], 'NONE' ); ?>><?php _e( 'None', 'rt_wp_nginx_helper' ); ?></option>
248
+ <option value="INFO"<?php selected( $rt_wp_nginx_helper->options[ 'log_level' ], 'INFO' ); ?>><?php _e( 'Info', 'rt_wp_nginx_helper' ); ?></option>
249
+ <option value="WARNING"<?php selected( $rt_wp_nginx_helper->options[ 'log_level' ], 'WARNING' ); ?>><?php _e( 'Warning', 'rt_wp_nginx_helper' ); ?></option>
250
+ <option value="ERROR"<?php selected( $rt_wp_nginx_helper->options[ 'log_level' ], 'ERROR' ); ?>><?php _e( 'Error', 'rt_wp_nginx_helper' ); ?></option>
251
+ </select>
252
+ </td>
253
+ </tr>
254
+
255
+ <tr>
256
+ <th><label for="log_filesize"><?php _e( 'Max log file size', 'rt_wp_nginx_helper' ); ?></label></th>
257
+ <td>
258
+ <input id="log_filesize" class="small-text" type="text" name="log_filesize" value="<?php echo $rt_wp_nginx_helper->options[ 'log_filesize' ] ?>" /> Mb
259
+ <?php if ( $error_log_filesize ) { ?>
260
+ <span class="error fade" style="display : block"><p><strong><?php echo $error_log_filesize; ?></strong></p></span>
261
+ <?php } ?>
262
+ </td>
263
+ </tr>
264
+ </tbody>
265
+ </table>
266
+
267
+ <br />
268
+ <?php } ?>
269
+ <?php } ?>
270
+
271
+ <p class="submit">
272
+ <input type="submit" name="smart_http_expire_save" class="button-primary" value="Save" />
273
+ </p>
274
+ </form>
275
+
276
+ </div>
277
+ <div id="rtads" class="metabox-holder align_left">
278
+ <?php $this->default_admin_sidebar(); ?>
279
+ </div>
280
+ </div>
281
+ <?php
282
+ break;
283
+ }
284
+ }
285
+
286
+ function default_admin_sidebar() {
287
+ ?>
288
+ <div class="postbox" id="support">
289
+ <div title="<?php _e( 'Click to toggle', 'bp-media' ); ?>" class="handlediv"><br /></div>
290
+ <h3 class="hndle"><span><?php _e( 'Need Help?', 'bp-media' ); ?></span></h3>
291
+ <div class="inside"><p><?php printf( __( ' Please use our <a href="%s">free support forum</a>.<br/><span class="bpm-aligncenter">OR</span><br/>
292
+ <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>
293
+ </div>
294
+ <div class="postbox" id="social">
295
+ <div title="<?php _e( 'Click to toggle', 'bp-media' ); ?>" class="handlediv"><br /></div>
296
+ <h3 class="hndle"><span><?php _e( 'Getting Social is Good', 'bp-media' ); ?></span></h3>
297
+ <div class="inside" style="text-align:center;">
298
+ <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>
299
+ <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>
300
+ <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>
301
+ </div>
302
+ </div>
303
+
304
+ <div class="postbox" id="latest_news">
305
+ <div title="<?php _e( 'Click to toggle', 'bp-media' ); ?>" class="handlediv"><br /></div>
306
+ <h3 class="hndle"><span><?php _e( 'Latest News', 'bp-media' ); ?></span></h3>
307
+ <div class="inside"><img src ="<?php echo admin_url(); ?>/images/wpspin_light.gif" /> Loading...</div>
308
+ </div><?php
309
+ }
310
+
311
+ function load_styles() {
312
+ wp_enqueue_style( 'rt-nginx-admin-css', plugins_url( 'admin/assets/style.css', dirname( __FILE__ ) ) );
313
+ }
314
+
315
+ function load_scripts() {
316
+ $admin_js = trailingslashit( site_url() ) . '?get_feeds=1';
317
+ wp_enqueue_script( 'nginx-js', plugins_url( 'admin/assets/nginx.js', dirname( __FILE__ ) ) );
318
+ wp_localize_script( 'nginx-js', 'news_url', $admin_js );
319
+ }
320
+
321
+ }
322
+
323
+ }
324
+ ?>
trunk/admin/assets/logo.png ADDED
Binary file
trunk/admin/assets/nginx-icon-32x32.png ADDED
Binary file
trunk/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
+ });
trunk/admin/assets/rtp-social-icons-32-32.png ADDED
Binary file
trunk/admin/assets/style.css ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ form#purgeall .button-primary{
22
+ float: right;
23
+ margin-right: 100px;
24
+ height: 32px;
25
+ line-height: 32px;
26
+ font-weight: bold;
27
+ font-size: 16px;
28
+ }
29
+
30
+ #social .inside a {
31
+ background: url(rtp-social-icons-32-32.png) no-repeat;
32
+ display: inline-block;
33
+ height: 35px;
34
+ margin: 0 0 0 9px;
35
+ padding: 0;
36
+ text-indent: -9999px;
37
+ text-transform: uppercase;
38
+ width: 35px;
39
+ }
40
+ #social .inside a.rt-nginx-facebook {
41
+ background-position: 0 0;
42
+ }
43
+ #social .inside a.rt-nginx-facebook:hover {
44
+ background-position: 0 -44px;
45
+ }
46
+ #social .inside a.rt-nginx-twitter {
47
+ background-position: -44px 0;
48
+ }
49
+ #social .inside a.rt-nginx-twitter:hover {
50
+ background-position: -44px -44px;
51
+ }
52
+ #social .inside a.rt-nginx-rss {
53
+ background-position: -88px 0;
54
+ }
55
+ #social .inside a.rt-nginx-rss:hover {
56
+ background-position: -88px -44px;
57
+ }
58
+
59
+
trunk/admin/install.php ADDED
@@ -0,0 +1,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
+ ?>
trunk/compatibility.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace rtCamp\WP\Nginx {
4
+
5
+ class Compatibility {
6
+
7
+ protected $have_nginx;
8
+
9
+ public static function instance() {
10
+ static $self = false;
11
+ if ( ! $self ) {
12
+ $self = new Compatibility();
13
+ }
14
+
15
+ return $self;
16
+ }
17
+
18
+ private function __construct() {
19
+ $this->have_nginx = ('nginx' == substr( $_SERVER[ 'SERVER_SOFTWARE' ], 0, 5 ));
20
+ if ( $this->have_nginx ) {
21
+ add_filter( 'got_rewrite', array( $this, 'got_rewrite' ), 999 );
22
+
23
+ // For compatibility with several plugins and nginx HTTPS proxying schemes
24
+ if ( empty( $_SERVER[ 'HTTPS' ] ) || 'off' == $_SERVER[ 'HTTPS' ] ) {
25
+ unset( $_SERVER[ 'HTTPS' ] );
26
+ }
27
+ }
28
+ }
29
+
30
+ public function got_rewrite( $got ) {
31
+ return true;
32
+ }
33
+
34
+ public function haveNginx() {
35
+ return $this->have_nginx;
36
+ }
37
+
38
+ }
39
+
40
+ }
41
+ ?>
trunk/nginx-helper.php ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.6.7
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
+ add_action( 'add_init', array( &$this, 'update_map' ) );
46
+
47
+ add_action( 'publish_post', array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
48
+ add_action( 'publish_page', array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
49
+ add_action( 'wp_insert_comment', array( &$rt_wp_nginx_purger, 'purgePostOnComment' ), 200, 2 );
50
+ add_action( 'transition_comment_status', array( &$rt_wp_nginx_purger, 'purgePostOnCommentChange' ), 200, 3 );
51
+
52
+ $args = array( '_builtin' => false );
53
+ $_rt_custom_post_types = get_post_types( $args );
54
+ if ( isset( $post_types ) && ! empty( $post_types ) ) {
55
+ if ( $this->options[ 'rt_wp_custom_post_types' ] == true ) {
56
+ foreach ( $_rt_custom_post_types as $post_type ) {
57
+ add_action( 'publish_' . trim( $post_type ), array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
58
+ }
59
+ }
60
+ }
61
+
62
+ add_action( 'transition_post_status', array( &$this, 'set_future_post_option_on_future_status' ), 20, 3 );
63
+ add_action( 'delete_post', array( &$this, 'unset_future_post_option_on_delete' ), 20, 1 );
64
+
65
+ add_action( 'nm_check_log_file_size_daily', array( &$rt_wp_nginx_purger, 'checkAndTruncateLogFile' ), 100, 1 );
66
+
67
+ add_action( 'edit_attachment', array( &$rt_wp_nginx_purger, 'purgeImageOnEdit' ), 100, 1 );
68
+
69
+ add_action( 'wpmu_new_blog', array( &$this, 'update_new_blog_options' ), 10, 1 );
70
+
71
+ add_action( 'transition_post_status', array( &$rt_wp_nginx_purger, 'purge_on_post_moved_to_trash' ), 20, 3 );
72
+
73
+ add_action( 'edit_term', array( &$rt_wp_nginx_purger, 'purge_on_term_taxonomy_edited' ), 20, 3 );
74
+ add_action( 'delete_term', array( &$rt_wp_nginx_purger, 'purge_on_term_taxonomy_edited' ), 20, 3 );
75
+
76
+ add_action( 'check_ajax_referer', array( &$rt_wp_nginx_purger, 'purge_on_check_ajax_referer' ), 20, 2 );
77
+ add_action( 'admin_init', array( &$this, 'purge_all' ) );
78
+ }
79
+
80
+ function activate() {
81
+ include_once (RT_WP_NGINX_HELPER_PATH . 'admin/install.php');
82
+ rt_wp_nginx_helper_install();
83
+ }
84
+
85
+ function deactivate() {
86
+ include_once (RT_WP_NGINX_HELPER_PATH . 'admin/install.php');
87
+ rt_wp_nginx_helper_uninstall();
88
+ }
89
+
90
+ function define_constant() {
91
+ define( 'RT_WP_NGINX_HELPER_VERSION', $this->version );
92
+ define( 'RT_WP_NGINX_HELPER_DB_VERSION', $this->db_version );
93
+ define( 'RT_WP_NGINX_HELPER_FOLDER', plugin_basename( dirname( __FILE__ ) ) );
94
+ }
95
+
96
+ function required_wp_version() {
97
+
98
+ global $wp_version;
99
+ $wp_ok = version_compare( $wp_version, $this->minium_WP, '>=' );
100
+
101
+ if ( ($wp_ok == FALSE ) ) {
102
+ add_action(
103
+ 'admin_notices', create_function(
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', create_function(
119
+ '', '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 );'
120
+ )
121
+ );
122
+ return false;
123
+ }
124
+
125
+ return true;
126
+ }
127
+
128
+ function load_options() {
129
+ $this->options = get_site_option( 'rt_wp_nginx_helper_options' );
130
+ }
131
+
132
+ function set_future_post_option_on_future_status( $new_status, $old_status, $post ) {
133
+
134
+ global $blog_id, $rt_wp_nginx_purger;
135
+ if ( ! $this->options[ 'enable_purge' ] ) {
136
+ return;
137
+ }
138
+ if ( $old_status != $new_status
139
+ && $old_status != 'inherit'
140
+ && $new_status != 'inherit'
141
+ && $old_status != 'auto-draft'
142
+ && $new_status != 'auto-draft'
143
+ && $new_status != 'publish'
144
+ && ! wp_is_post_revision( $post->ID ) ) {
145
+ $rt_wp_nginx_purger->log( "Purge post on transition post STATUS from " . $old_status . " to " . $new_status );
146
+ $rt_wp_nginx_purger->purgePost( $post->ID );
147
+ }
148
+
149
+ if ( $new_status == 'future' ) {
150
+ 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' ] ) ) ) ) {
151
+ $rt_wp_nginx_purger->log( "Set/update future_posts option (post id = " . $post->ID . " and blog id = " . $blog_id . ")" );
152
+ $this->options[ 'future_posts' ][ $blog_id ][ $post->ID ] = strtotime( $post->post_date_gmt ) + 60;
153
+ update_site_option( "rt_wp_nginx_helper_global_options", $this->options );
154
+ }
155
+ }
156
+ }
157
+
158
+ function unset_future_post_option_on_delete( $post_id ) {
159
+
160
+ global $blog_id, $rt_wp_nginx_purger;
161
+ if ( ! $this->options[ 'enable_purge' ] ) {
162
+ return;
163
+ }
164
+ if ( $post_id && ! wp_is_post_revision( $post_id ) ) {
165
+
166
+ if ( isset( $this->options[ 'future_posts' ][ $blog_id ][ $post_id ] ) && count( $this->options[ 'future_posts' ][ $blog_id ][ $post_id ] ) ) {
167
+ $rt_wp_nginx_purger->log( "Unset future_posts option (post id = " . $post_id . " and blog id = " . $blog_id . ")" );
168
+ unset( $this->options[ 'future_posts' ][ $blog_id ][ $post_id ] );
169
+ update_site_option( "rt_wp_nginx_helper_global_options", $this->options );
170
+
171
+ if ( ! count( $this->options[ 'future_posts' ][ $blog_id ] ) ) {
172
+ unset( $this->options[ 'future_posts' ][ $blog_id ] );
173
+ update_site_option( "rt_wp_nginx_helper_global_options", $this->options );
174
+ }
175
+ }
176
+ }
177
+ }
178
+
179
+ function update_new_blog_options( $blog_id ) {
180
+
181
+ global $rt_wp_nginx_purger;
182
+
183
+ include_once (RT_WP_NGINX_HELPER_PATH . 'admin/install.php');
184
+
185
+ $rt_wp_nginx_purger->log( "New site added (id $blog_id)" );
186
+
187
+ $this->update_map();
188
+
189
+ $rt_wp_nginx_purger->log( "New site added to nginx map (id $blog_id)" );
190
+
191
+ $helper_options = rt_wp_nginx_helper_get_options();
192
+
193
+ update_blog_option( $blog_id, "rt_wp_nginx_helper_options", $helper_options, true );
194
+
195
+ $rt_wp_nginx_purger->log( "Default options updated for the new blog (id $blog_id)" );
196
+ }
197
+
198
+ function get_map() {
199
+ if ( ! $this->options[ 'enable_map' ] ) {
200
+ return;
201
+ }
202
+
203
+ if ( is_multisite() ) {
204
+
205
+ global $wpdb;
206
+
207
+ $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 ) );
208
+ $wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
209
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->dmtable}'" ) == $wpdb->dmtable ) {
210
+ $rt_domain_map_sites = $wpdb->get_results( "SELECT blog_id, domain FROM {$wpdb->dmtable} ORDER BY id DESC" );
211
+ }
212
+ $rt_nginx_map = "";
213
+ $rt_nginx_map_array = array( );
214
+
215
+
216
+ if ( $rt_all_blogs )
217
+ foreach ( $rt_all_blogs as $blog ) {
218
+ if ( SUBDOMAIN_INSTALL == "yes" ) {
219
+ $rt_nginx_map_array[ $blog->domain ] = $blog->blog_id;
220
+ } else {
221
+ if ( $blog->blog_id != 1 ) {
222
+ $rt_nginx_map_array[ $blog->path ] = $blog->blog_id;
223
+ }
224
+ }
225
+ }
226
+
227
+ if ( $rt_domain_map_sites ) {
228
+ foreach ( $rt_domain_map_sites as $site ) {
229
+ $rt_nginx_map_array[ $site->domain ] = $site->blog_id;
230
+ }
231
+ }
232
+
233
+ foreach ( $rt_nginx_map_array as $domain => $domain_id ) {
234
+ $rt_nginx_map .= "\t" . $domain . "\t" . $domain_id . ";\n";
235
+ }
236
+
237
+ return $rt_nginx_map;
238
+ }
239
+ }
240
+
241
+ function update_map() {
242
+ if ( is_multisite() ) {
243
+ $rt_nginx_map = $this->get_map();
244
+ if ( $fp = fopen( RT_WP_NGINX_HELPER_PATH . 'map.conf', 'w+' ) ) {
245
+ fwrite( $fp, $rt_nginx_map );
246
+ fclose( $fp );
247
+ return true;
248
+ }
249
+ }
250
+ }
251
+
252
+ function add_timestamps() {
253
+ if ( $this->options[ 'enable_purge' ] != 1 )
254
+ return;
255
+ if ( $this->options[ 'enable_stamp' ] != 1 )
256
+ return;
257
+ foreach (headers_list() as $header) {
258
+ list($key,$value) = explode(':',$header,2);
259
+ if($key == 'Content-Type' && strpos(trim($value),'text/html') !== 0) {
260
+ return;
261
+ }
262
+ if($key == 'Content-Type') break;
263
+ }
264
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
265
+ return;
266
+ $timestamps = "\n<!--" .
267
+ "Cached using Nginx-Helper on " . current_time( 'mysql' ) . ". " .
268
+ "It took " . get_num_queries() . " queries executed in " . timer_stop() . " seconds." .
269
+ "-->\n" .
270
+ "<!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->";
271
+ echo $timestamps;
272
+ }
273
+
274
+ function show_notice() {
275
+ echo '<div class="updated"><p>Purge initiated</p></div>';
276
+ }
277
+
278
+ function purge_all() {
279
+ global $rt_wp_nginx_purger;
280
+ if ( ! isset( $_REQUEST[ 'nginx_helper_action' ] ) )
281
+ return;
282
+
283
+ if ( ! current_user_can( 'manage_options' ) )
284
+ wp_die( 'Sorry, you do not have the necessary privileges to edit these options.' );
285
+
286
+ $action = $_REQUEST[ 'nginx_helper_action' ];
287
+
288
+ if ( $action == 'done' ) {
289
+ add_action( 'admin_notices', array( &$this, 'show_notice' ) );
290
+ return;
291
+ }
292
+
293
+ check_admin_referer( 'nginx_helper-purge_all' );
294
+
295
+ switch ( $action ) {
296
+ case 'purge':
297
+ $rt_wp_nginx_purger->purge_them_all();
298
+ break;
299
+ }
300
+
301
+ wp_redirect( add_query_arg( array( 'nginx_helper_action' => 'done' ) ) );
302
+ }
303
+
304
+ }
305
+
306
+ }
307
+
308
+ namespace {
309
+ global $current_blog;
310
+
311
+ if ( is_admin() ) {
312
+ require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH . '/admin/admin.php');
313
+ $rtwpAdminPanel = new \rtCamp\WP\Nginx\Admin();
314
+ }
315
+
316
+ require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH . 'purger.php');
317
+
318
+ require_once (rtCamp\WP\Nginx\RT_WP_NGINX_HELPER_PATH . 'compatibility.php');
319
+
320
+ global $rt_wp_nginx_helper, $rt_wp_nginx_purger, $rt_wp_nginx_compatibility;
321
+ $rt_wp_nginx_helper = new \rtCamp\WP\Nginx\Helper;
322
+ $rt_wp_nginx_purger = new \rtCamp\WP\Nginx\Purger;
323
+ $rt_wp_nginx_compatibility = namespace\rtCamp\WP\Nginx\Compatibility::instance();
324
+ if ( $rt_wp_nginx_compatibility->haveNginx() && ! function_exists( 'wp_redirect' ) ) {
325
+
326
+ function wp_redirect( $location, $status = 302 ) {
327
+ $location = apply_filters( 'wp_redirect', $location, $status );
328
+
329
+ if ( empty( $location ) ) {
330
+ return false;
331
+ }
332
+
333
+ $status = apply_filters( 'wp_redirect_status', $status, $location );
334
+ if ( $status < 300 || $status > 399 ) {
335
+ $status = 302;
336
+ }
337
+
338
+ $location = wp_sanitize_redirect( $location );
339
+ header( 'Location: ' . $location, true, $status );
340
+ }
341
+
342
+ }
343
+
344
+ // Add settings link on plugin page
345
+ function nginx_settings_link( $links ) {
346
+ if ( is_network_admin() ) {
347
+ $u = 'settings.php';
348
+ } else {
349
+ $u = 'options-general.php';
350
+ }
351
+ $settings_link = '<a href="' . $u . '?page=nginx">Settings</a>';
352
+ array_unshift( $links, $settings_link );
353
+ return $links;
354
+ }
355
+
356
+ $plugin = plugin_basename( __FILE__ );
357
+ if ( is_multisite() ) {
358
+ add_filter( "network_admin_plugin_action_links_$plugin", 'nginx_settings_link' );
359
+ } else {
360
+ add_filter( "plugin_action_links_$plugin", 'nginx_settings_link' );
361
+ }
362
+
363
+ function get_feeds( $feed_url = 'http://rtcamp.com/blog/feed/' ) {
364
+ // Get RSS Feed(s)
365
+ require_once( ABSPATH . WPINC . '/feed.php' );
366
+ $maxitems = 0;
367
+ // Get a SimplePie feed object from the specified feed source.
368
+ $rss = fetch_feed( $feed_url );
369
+ if ( ! is_wp_error( $rss ) ) { // Checks that the object is created correctly
370
+ // Figure out how many total items there are, but limit it to 5.
371
+ $maxitems = $rss->get_item_quantity( 5 );
372
+
373
+ // Build an array of all the items, starting with element 0 (first element).
374
+ $rss_items = $rss->get_items( 0, $maxitems );
375
+ }
376
+ ?>
377
+ <ul><?php
378
+ if ( $maxitems == 0 ) {
379
+ echo '<li>' . __( 'No items', 'bp-media' ) . '.</li>';
380
+ } else {
381
+ // Loop through each feed item and display each item as a hyperlink.
382
+ foreach ( $rss_items as $item ) {
383
+ ?>
384
+ <li>
385
+ <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>
386
+ </li><?php
387
+ }
388
+ }
389
+ ?>
390
+ </ul><?php
391
+ }
392
+
393
+ function fetch_feeds() {
394
+ if ( isset( $_GET[ 'get_feeds' ] ) && $_GET[ 'get_feeds' ] == '1' ) {
395
+ get_feeds();
396
+ die();
397
+ }
398
+ }
399
+
400
+ add_action( 'init', 'fetch_feeds' );
401
+ }
402
+ ?>
trunk/purger.php ADDED
@@ -0,0 +1,675 @@