Nginx Helper - Version 1.4

Version Description

  • Fixed bug related to nomenclature of comment status that caused purge to fail.
Download this release

Release Info

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

Code changes from version 1.3.9 to 1.4

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.3.9
7
  Author: rtCamp
8
  Author URI: http://rtcamp.com
9
  Requires at least: 3.0
@@ -13,7 +13,7 @@ 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.3.9'; // 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';
@@ -42,8 +42,8 @@ namespace rtCamp\WP\Nginx {
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( 'comment_post', array(&$rt_wp_nginx_purger, 'purgePostOnComment'), 200, 1);
46
- add_action( 'transition_comment_status', array(&$rt_wp_nginx_purger, 'purgePostOnComment'), 200, 2);
47
 
48
  $args=array('_builtin'=>false);
49
  $_rt_custom_post_types = get_post_types( $args );
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
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';
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 );
purger.php CHANGED
@@ -1,39 +1,60 @@
1
  <?php
2
  namespace rtCamp\WP\Nginx{
3
  class Purger {
4
-
5
- function purgePostOnComment( $newstatus, $oldstatus, $comment ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  global $rt_wp_nginx_helper,$blog_id;
8
  if(!$rt_wp_nginx_helper->options['enable_purge']){
9
  return;
10
  }
11
-
 
12
  $_post_id = $comment->comment_post_ID;
13
  $_comment_id = $comment->comment_ID;
14
-
15
  $this->log( "* * * * *" );
16
  $this->log( "* Blog :: ".addslashes( get_bloginfo('name') )." ($blog_id)." );
17
  $this->log( "* Post :: ".get_the_title($_post_id)." ($_post_id)." );
18
  $this->log( "* Comment :: $_comment_id." );
19
-
20
  switch ($newstatus){
21
- case 'approve':
22
  if($rt_wp_nginx_helper->options['purge_page_on_new_comment']==1){
23
- $this->log( "* Comment ($_comment_id) approved. Post ($_post_id) purged." );
 
 
24
  }
25
  break;
26
  case 'spam':
 
27
  case 'trash':
28
- if($rt_wp_nginx_helper->options['purge_page_on_deleted_comment']==1){
29
- if($oldstatus=='approve'){
30
- $this->log( "* Comment ($_comment_id) removed as ($newstatus). Post ($_post_id) purged." );
 
 
31
  }
32
  }
33
- $this->log( "* * * * *" );
34
- $this->purgePost( $_post_id );
35
  break;
36
-
37
  }
38
 
39
  }
1
  <?php
2
  namespace rtCamp\WP\Nginx{
3
  class Purger {
4
+ function purgePostOnComment( $comment_id, $comment ) {
5
+ $oldstatus ='';
6
+ $approved = $comment->comment_approved;
7
+
8
+ if ( $approved == null )
9
+ $newstatus = false;
10
+ elseif ( $approved == '1' )
11
+ $newstatus = 'approved';
12
+ elseif ( $approved == '0' )
13
+ $newstatus = 'unapproved';
14
+ elseif ( $approved == 'spam' )
15
+ $newstatus = 'spam';
16
+ elseif ( $approved == 'trash' )
17
+ $newstatus = 'trash';
18
+ else
19
+ $newstatus = false;
20
+
21
+ $this->purgePostOnCommentChange( $newstatus, $oldstatus, $comment );
22
+ }
23
+ function purgePostOnCommentChange( $newstatus, $oldstatus, $comment ) {
24
 
25
  global $rt_wp_nginx_helper,$blog_id;
26
  if(!$rt_wp_nginx_helper->options['enable_purge']){
27
  return;
28
  }
29
+
30
+
31
  $_post_id = $comment->comment_post_ID;
32
  $_comment_id = $comment->comment_ID;
33
+
34
  $this->log( "* * * * *" );
35
  $this->log( "* Blog :: ".addslashes( get_bloginfo('name') )." ($blog_id)." );
36
  $this->log( "* Post :: ".get_the_title($_post_id)." ($_post_id)." );
37
  $this->log( "* Comment :: $_comment_id." );
38
+ $this->log( "* Status Changed from $oldstatus to $newstatus" );
39
  switch ($newstatus){
40
+ case 'approved':
41
  if($rt_wp_nginx_helper->options['purge_page_on_new_comment']==1){
42
+ $this->log( "* Comment ($_comment_id) approved. Post ($_post_id) purging..." );
43
+ $this->log( "* * * * *" );
44
+ $this->purgePost( $_post_id );
45
  }
46
  break;
47
  case 'spam':
48
+ case 'unapproved':
49
  case 'trash':
50
+ if($oldstatus=='approve'){
51
+ if($rt_wp_nginx_helper->options['purge_page_on_deleted_comment']==1){
52
+ $this->log( "* Comment ($_comment_id) removed as ($newstatus). Post ($_post_id) purging..." );
53
+ $this->log( "* * * * *" );
54
+ $this->purgePost( $_post_id );
55
  }
56
  }
 
 
57
  break;
 
58
  }
59
 
60
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: rtcamp, rahul286, saurabhshukla
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.3.9
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/
@@ -101,6 +101,9 @@ Its just that we are hyperactive on our own forum!
101
  2. Remaining settings
102
 
103
  == Changelog ==
 
 
 
104
  = 1.3.9 =
105
  * Removed extraneous headers.
106
 
@@ -162,5 +165,5 @@ Its just that we are hyperactive on our own forum!
162
 
163
  == Upgrade Notice ==
164
 
165
- = 1.3.9 =
166
- Removed unnecessary headers being added.
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.4
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/
101
  2. Remaining settings
102
 
103
  == Changelog ==
104
+ = 1.4 =
105
+ * Fixed bug related to nomenclature of comment status that caused purge to fail.
106
+
107
  = 1.3.9 =
108
  * Removed extraneous headers.
109
 
165
 
166
  == Upgrade Notice ==
167
 
168
+ = 1.4 =
169
+ Bug fix for improper purging on comment.
trunk/admin/admin.php ADDED
@@ -0,0 +1,320 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ?>
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,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ table.rtnginx-table{
2
+ padding: 10px;
3
+ border: 1px #CCC solid;
4
+ width: 95%;
5
+ margin-bottom: 10px;
6
+ }
7
+ pre#map{
8
+ background: #e5e5e5 none;
9
+ border-radius:10px;
10
+ padding:10px;
11
+ }
12
+ #icon-options-nginx{
13
+ background:transparent url(nginx-icon-32x32.png) center center no-repeat;
14
+ }
15
+ div#content_block form { padding-left: 25px }
16
+ div#content_block { width: 70% }
17
+ div#rtads{ width:30%}
18
+ .align_left, .alignleft {
19
+ float: left;
20
+ }
21
+
22
+ #social .inside a {
23
+ background: url(rtp-social-icons-32-32.png) no-repeat;
24
+ display: inline-block;
25
+ height: 35px;
26
+ margin: 0 0 0 9px;
27
+ padding: 0;
28
+ text-indent: -9999px;
29
+ text-transform: uppercase;
30
+ width: 35px;
31
+ }
32
+ #social .inside a.rt-nginx-facebook {
33
+ background-position: 0 0;
34
+ }
35
+ #social .inside a.rt-nginx-facebook:hover {
36
+ background-position: 0 -44px;
37
+ }
38
+ #social .inside a.rt-nginx-twitter {
39
+ background-position: -44px 0;
40
+ }
41
+ #social .inside a.rt-nginx-twitter:hover {
42
+ background-position: -44px -44px;
43
+ }
44
+ #social .inside a.rt-nginx-rss {
45
+ background-position: -88px 0;
46
+ }
47
+ #social .inside a.rt-nginx-rss:hover {
48
+ background-position: -88px -44px;
49
+ }
50
+
51
+
trunk/admin/install.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace rtCamp\WP\Nginx{
3
+ if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
4
+
5
+ function rt_wp_nginx_helper_install () {
6
+
7
+ global $wp_roles, $rt_wp_nginx_helper;
8
+
9
+ if ( !current_user_can('activate_plugins') )
10
+ return;
11
+
12
+ $role = get_role('administrator');
13
+
14
+
15
+ if ( empty($role) ) {
16
+ update_site_option( "rt_wp_nginx_helper_init_check", __('Sorry, you need to be an administrator to use Nginx Helper',"rt_wp_nginx_helper") );
17
+ return;
18
+ }
19
+
20
+ $role->add_cap('Nginx Helper | Config');
21
+ $role->add_cap('Nginx Helper | Purge cache');
22
+
23
+ $rt_wp_nginx_helper_get_options = get_site_option('rt_wp_nginx_helper_global_options');
24
+
25
+ if ( empty( $rt_wp_nginx_helper_get_options ) ) {
26
+ $rt_wp_nginx_helper_get_options = rt_wp_nginx_helper_get_options();
27
+ update_site_option("rt_wp_nginx_helper_global_options", $rt_wp_nginx_helper_get_options);
28
+ }
29
+
30
+ if (is_multisite()) {
31
+ $blogs = get_blogs_of_user(true);
32
+ foreach ($blogs as $b) {
33
+ $rt_wp_nginx_helper_options = get_blog_option($b->userblog_id, 'rt_wp_nginx_helper_options');
34
+ if ( empty( $rt_wp_nginx_helper_options ) ) {
35
+ $rt_wp_nginx_helper_options = rt_wp_nginx_helper_get_options();
36
+ update_blog_option($b->userblog_id, "rt_wp_nginx_helper_options", $rt_wp_nginx_helper_options);
37
+ }
38
+ }
39
+ } else {
40
+ $rt_wp_nginx_helper_options = get_option('rt_wp_nginx_helper_options');
41
+ if ( empty( $rt_wp_nginx_helper_options ) ) {
42
+ $rt_wp_nginx_helper_options = rt_wp_nginx_helper_get_options();
43
+ update_option("rt_wp_nginx_helper_options", $rt_wp_nginx_helper_options);
44
+ }
45
+ }
46
+ wp_schedule_event(time(), 'daily', 'rt_wp_nginx_helper_check_log_file_size_daily');
47
+
48
+ }
49
+
50
+ function rt_wp_nginx_helper_uninstall() {
51
+
52
+ global $rt_wp_nginx_helper, $rt_wp_nginx_purger;
53
+
54
+ wp_clear_scheduled_hook('rt_wp_nginx_helper_check_log_file_size_daily');
55
+
56
+ delete_site_option( 'rt_wp_nginx_helper_options' );
57
+
58
+
59
+ rt_wp_nginx_helper_remove_capability('Nginx Helper | Config');
60
+ rt_wp_nginx_helper_remove_capability('Nginx Helper | Purge cache');
61
+
62
+ }
63
+
64
+ function rt_wp_nginx_helper_remove_capability($capability){
65
+ $check_order = array("subscriber", "contributor", "author", "editor", "administrator");
66
+
67
+ foreach ($check_order as $role) {
68
+ $role = get_role($role);
69
+ $role->remove_cap($capability) ;
70
+ }
71
+
72
+ }
73
+
74
+ function rt_wp_nginx_helper_get_options() {
75
+
76
+ global $rt_wp_nginx_helper;
77
+
78
+ $rt_wp_nginx_helper_get_options = array();
79
+
80
+
81
+ $rt_wp_nginx_helper_get_options['log_level'] = 'INFO';
82
+ $rt_wp_nginx_helper_get_options['log_filesize'] = 5;
83
+
84
+ $rt_wp_nginx_helper_get_options['current_db_version'] = $rt_wp_nginx_helper->db_version;
85
+
86
+ $rt_wp_nginx_helper_get_options['mobile_uncache'] = 1;
87
+ $rt_wp_nginx_helper_get_options['mobile_regexp'] = '#2.0 MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo Wii|Nitro|Nokia|Opera Mini|Palm|PlayStation Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows CE|WinWAP|YahooSeeker/M1A1-R2D2|NF-Browser|iPhone|iPod|Android|BlackBerry9530|G-TU915 Obigo|LGE VX|webOS|Nokia5800#';
88
+
89
+ $rt_wp_nginx_helper_get_options['enable_purge'] = 1;
90
+ $rt_wp_nginx_helper_get_options['enable_map'] = 0;
91
+ $rt_wp_nginx_helper_get_options['enable_log'] = 0;
92
+
93
+ $rt_wp_nginx_helper_get_options['purge_homepage_on_new'] = 1;
94
+ $rt_wp_nginx_helper_get_options['purge_homepage_on_edit'] = 1;
95
+ $rt_wp_nginx_helper_get_options['purge_homepage_on_del'] = 1;
96
+
97
+ $rt_wp_nginx_helper_get_options['purge_archive_on_new'] = 1;
98
+ $rt_wp_nginx_helper_get_options['purge_archive_on_edit'] = 1;
99
+ $rt_wp_nginx_helper_get_options['purge_archive_on_del'] = 1;
100
+
101
+ $rt_wp_nginx_helper_get_options['purge_archive_on_new_comment'] = 0;
102
+ $rt_wp_nginx_helper_get_options['purge_archive_on_deleted_comment'] = 0;
103
+
104
+ $rt_wp_nginx_helper_get_options['purge_page_on_mod'] = 1;
105
+ $rt_wp_nginx_helper_get_options['purge_page_on_new_comment'] = 1;
106
+ $rt_wp_nginx_helper_get_options['purge_page_on_deleted_comment'] = 1;
107
+
108
+ return $rt_wp_nginx_helper_get_options;
109
+
110
+ }
111
+
112
+ }
113
+ ?>
trunk/compatibility.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace rtCamp\WP\Nginx {
3
+ class Compatibility {
4
+ protected $have_nginx;
5
+
6
+ public static function instance() {
7
+ static $self = false;
8
+ if (!$self) {
9
+ $self = new Compatibility();
10
+ }
11
+
12
+ return $self;
13
+ }
14
+
15
+ private function __construct() {
16
+ $this->have_nginx = ('nginx' == substr($_SERVER['SERVER_SOFTWARE'], 0, 5));
17
+ if ($this->have_nginx) {
18
+ add_filter('got_rewrite', array($this, 'got_rewrite'), 999);
19
+
20
+ // For compatibility with several plugins and nginx HTTPS proxying schemes
21
+ if (empty($_SERVER['HTTPS']) || 'off' == $_SERVER['HTTPS']) {
22
+ unset($_SERVER['HTTPS']);
23
+ }
24
+ }
25
+ }
26
+
27
+ public function got_rewrite($got) {
28
+ return true;
29
+ }
30
+
31
+ public function haveNginx() {
32
+ return $this->have_nginx;
33
+ }
34
+ }
35
+ }
36
+ ?>
trunk/nginx-helper.php ADDED
@@ -0,0 +1,351 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.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
+ ?>
trunk/purger.php ADDED
@@ -0,0 +1,710 @@