Nginx Helper - Version 1.9.5

Version Description

Added custom purge URL option.

Download this release

Release Info

Developer rtcamp
Plugin Icon 128x128 Nginx Helper
Version 1.9.5
Comparing to
See all releases

Code changes from version 1.9.4 to 1.9.5

admin/assets/style.css CHANGED
@@ -18,4 +18,5 @@ form#purgeall .button-primary:hover, form#purgeall .button-primary:focus { backg
18
  #social .inside .nginx-helper-rss:hover { background-color: #FAA33D; }
19
  #social .inside .nginx-helper-facebook:hover { background-color: #537BBD; }
20
  #social .inside .nginx-helper-twitter:hover { background-color: #40BFF5; }
21
- #social .inside .nginx-helper-gplus:hover { background-color: #DD4B39; }
 
18
  #social .inside .nginx-helper-rss:hover { background-color: #FAA33D; }
19
  #social .inside .nginx-helper-facebook:hover { background-color: #537BBD; }
20
  #social .inside .nginx-helper-twitter:hover { background-color: #40BFF5; }
21
+ #social .inside .nginx-helper-gplus:hover { background-color: #DD4B39; }
22
+ .rt-purge_url { width: 100%; }
admin/lib/nginx-general.php CHANGED
@@ -52,6 +52,8 @@ namespace rtCamp\WP\Nginx {
52
  $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;
53
 
54
  $rt_wp_nginx_helper->options['purge_method'] = ( isset( $_POST['purge_method'] ) ) ? $_POST['purge_method'] : 'get_request';
 
 
55
  }
56
  if ( isset( $_POST['cache_method'] ) && $_POST['cache_method'] = "enable_redis" ) {
57
  $rt_wp_nginx_helper->options['redis_hostname'] = ( isset( $_POST['redis_hostname'] ) ) ? $_POST['redis_hostname'] : '127.0.0.1';
@@ -308,6 +310,23 @@ namespace rtCamp\WP\Nginx {
308
  </td>
309
  </tr>
310
  </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  </div> <!-- End of .inside -->
312
  </div>
313
  <div class="postbox">
52
  $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;
53
 
54
  $rt_wp_nginx_helper->options['purge_method'] = ( isset( $_POST['purge_method'] ) ) ? $_POST['purge_method'] : 'get_request';
55
+
56
+ $rt_wp_nginx_helper->options['purge_url'] = ( isset( $_POST['purge_url'] ) && ! empty( $_POST['purge_url'] ) ) ? esc_textarea( $_POST['purge_url'] ) : '';
57
  }
58
  if ( isset( $_POST['cache_method'] ) && $_POST['cache_method'] = "enable_redis" ) {
59
  $rt_wp_nginx_helper->options['redis_hostname'] = ( isset( $_POST['redis_hostname'] ) ) ? $_POST['redis_hostname'] : '127.0.0.1';
310
  </td>
311
  </tr>
312
  </table>
313
+ <table class="form-table rtnginx-table">
314
+ <tr valign="top">
315
+ <th scope="row">
316
+ <h4><?php _e( 'Custom Purge URL:', 'nginx-helper' ); ?></h4>
317
+ </th>
318
+ <td>
319
+ <textarea rows="5"class="rt-purge_url" id="purge_url" name="purge_url"><?php echo isset( $rt_wp_nginx_helper->options['purge_url'] ) ? $rt_wp_nginx_helper->options['purge_url'] : '';?></textarea>
320
+ <p class="description">
321
+ Add one URL per line. URL should not contain domain name.
322
+ <br>
323
+ Eg: To purge http://example.com/sample-page/ add <strong>/sample-page/</strong> in above textarea.
324
+ <br>
325
+ '*' will only work with redis cache server.
326
+ </p>
327
+ </td>
328
+ </tr>
329
+ </table>
330
  </div> <!-- End of .inside -->
331
  </div>
332
  <div class="postbox">
nginx-helper.php CHANGED
@@ -3,12 +3,12 @@
3
  Plugin Name: Nginx Helper
4
  Plugin URI: https://rtcamp.com/nginx-helper/
5
  Description: Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does few more things.
6
- Version: 1.9.4
7
  Author: rtCamp
8
  Author URI: https://rtcamp.com
9
  Text Domain: nginx-helper
10
  Requires at least: 3.0
11
- Tested up to: 4.2.2
12
  */
13
 
14
  namespace rtCamp\WP\Nginx {
3
  Plugin Name: Nginx Helper
4
  Plugin URI: https://rtcamp.com/nginx-helper/
5
  Description: Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does few more things.
6
+ Version: 1.9.5
7
  Author: rtCamp
8
  Author URI: https://rtcamp.com
9
  Text Domain: nginx-helper
10
  Requires at least: 3.0
11
+ Tested up to: 4.2.3
12
  */
13
 
14
  namespace rtCamp\WP\Nginx {
purger.php CHANGED
@@ -114,7 +114,9 @@ namespace rtCamp\WP\Nginx {
114
  } else {
115
  $this->_purge_by_options( $_ID, $blog_id, $rt_wp_nginx_helper->options[ 'purge_page_on_mod' ], $rt_wp_nginx_helper->options[ 'purge_archive_on_edit' ], $rt_wp_nginx_helper->options[ 'purge_archive_on_edit' ] );
116
  }
117
-
 
 
118
  $this->log( "Function purgePost END ^^^" );
119
  }
120
 
@@ -227,7 +229,7 @@ namespace rtCamp\WP\Nginx {
227
  $this->_delete_cache_file_for( $feed_url . 'atom/' );
228
  $this->_delete_cache_file_for( $feed_url . 'rdf/' );
229
  }
230
- break;
231
  case 'get_request':
232
  // Go to default case
233
  default:
@@ -246,7 +248,7 @@ namespace rtCamp\WP\Nginx {
246
  $this->_do_remote_get( $feed_url . 'atom/' );
247
  $this->_do_remote_get( $feed_url . 'rdf/' );
248
  }
249
- break;
250
  }
251
 
252
  }
@@ -777,5 +779,52 @@ namespace rtCamp\WP\Nginx {
777
 
778
  return;
779
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
780
  }
781
  }
114
  } else {
115
  $this->_purge_by_options( $_ID, $blog_id, $rt_wp_nginx_helper->options[ 'purge_page_on_mod' ], $rt_wp_nginx_helper->options[ 'purge_archive_on_edit' ], $rt_wp_nginx_helper->options[ 'purge_archive_on_edit' ] );
116
  }
117
+
118
+ $this->purge_urls();
119
+
120
  $this->log( "Function purgePost END ^^^" );
121
  }
122
 
229
  $this->_delete_cache_file_for( $feed_url . 'atom/' );
230
  $this->_delete_cache_file_for( $feed_url . 'rdf/' );
231
  }
232
+ break;
233
  case 'get_request':
234
  // Go to default case
235
  default:
248
  $this->_do_remote_get( $feed_url . 'atom/' );
249
  $this->_do_remote_get( $feed_url . 'rdf/' );
250
  }
251
+ break;
252
  }
253
 
254
  }
779
 
780
  return;
781
  }
782
+
783
+ function purge_urls() {
784
+
785
+ global $rt_wp_nginx_helper;
786
+
787
+ $parse = parse_url( site_url() );
788
+
789
+ switch ($rt_wp_nginx_helper->options['purge_method']) {
790
+ case 'unlink_files':
791
+ $_url_purge_base = $parse[ 'scheme' ] . '://' . $parse[ 'host' ];
792
+
793
+ if( isset( $rt_wp_nginx_helper->options['purge_url'] ) && ! empty( $rt_wp_nginx_helper->options['purge_url'] ) ) {
794
+ $purge_urls = explode( "\r\n", $rt_wp_nginx_helper->options['purge_url'] );
795
+
796
+ foreach ($purge_urls as $purge_url ) {
797
+ $purge_url = trim( $purge_url );
798
+
799
+ if( strpos( $purge_url, '*' ) === false ) {
800
+ $purge_url = $_url_purge_base . $purge_url;
801
+ $this->log( "- Purging URL | " . $url );
802
+ $this->_delete_cache_file_for( $purge_url );
803
+ }
804
+ }
805
+ }
806
+ break;
807
+ case 'get_request':
808
+ // Go to default case
809
+ default:
810
+ $_url_purge_base = $parse[ 'scheme' ] . '://' . $parse[ 'host' ] . '/purge';
811
+
812
+ if( isset( $rt_wp_nginx_helper->options['purge_url'] ) && ! empty( $rt_wp_nginx_helper->options['purge_url'] ) ) {
813
+ $purge_urls = explode( "\r\n", $rt_wp_nginx_helper->options['purge_url'] );
814
+
815
+ foreach ($purge_urls as $purge_url ) {
816
+ $purge_url = trim( $purge_url );
817
+
818
+ if( strpos( $purge_url, '*' ) === false ) {
819
+ $purge_url = $_url_purge_base . $purge_url;
820
+ $this->log( "- Purging URL | " . $url );
821
+ $this->_do_remote_get( $purge_url );
822
+ }
823
+ }
824
+ }
825
+ break;
826
+ }
827
+
828
+ }
829
  }
830
  }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123
3
  Tags: nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks
4
  Requires at least: 3.0
5
- Tested up to: 4.2.2
6
- Stable tag: 1.9.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/
@@ -114,6 +114,9 @@ Please post your problem in [our free support forum](http://community.rtcamp.com
114
 
115
  == Changelog ==
116
 
 
 
 
117
  = 1.9.4 =
118
  * Added redis server connection timeout.
119
  * Added RedisException handling.
@@ -315,6 +318,5 @@ Fix url escaping [#82](https://github.com/rtCamp/nginx-helper/pull/82) - by
315
 
316
  == Upgrade Notice ==
317
 
318
- = 1.9.4 =
319
- * Added redis server connection timeout.
320
- * Added RedisException handling.
2
  Contributors: rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123
3
  Tags: nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks
4
  Requires at least: 3.0
5
+ Tested up to: 4.2.3
6
+ Stable tag: 1.9.5
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/
114
 
115
  == Changelog ==
116
 
117
+ = 1.9.5 =
118
+ Added custom purge URL option.
119
+
120
  = 1.9.4 =
121
  * Added redis server connection timeout.
122
  * Added RedisException handling.
318
 
319
  == Upgrade Notice ==
320
 
321
+ = 1.9.5 =
322
+ Added custom purge URL option.
 
redis-purger.php CHANGED
@@ -121,7 +121,9 @@ namespace rtCamp\WP\Nginx {
121
  } else {
122
  $this->_purge_by_options( $_ID, $blog_id, $rt_wp_nginx_helper->options['purge_page_on_mod'], $rt_wp_nginx_helper->options['purge_archive_on_edit'], $rt_wp_nginx_helper->options['purge_archive_on_edit'] );
123
  }
124
-
 
 
125
  $this->log( "Function purgePost END ^^^" );
126
  }
127
 
@@ -220,7 +222,7 @@ namespace rtCamp\WP\Nginx {
220
  $prefix = $rt_wp_nginx_helper->options['redis_prefix'];
221
  $_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'];
222
  delete_single_key( $_url_purge_base );
223
- }
224
 
225
  function log( $msg, $level = 'INFO' )
226
  {
@@ -665,6 +667,42 @@ namespace rtCamp\WP\Nginx {
665
  //delete_multi_keys("*");
666
  delete_keys_by_wildcard("*");
667
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
668
 
669
  }
670
 
121
  } else {
122
  $this->_purge_by_options( $_ID, $blog_id, $rt_wp_nginx_helper->options['purge_page_on_mod'], $rt_wp_nginx_helper->options['purge_archive_on_edit'], $rt_wp_nginx_helper->options['purge_archive_on_edit'] );
123
  }
124
+
125
+ $this->purge_urls();
126
+
127
  $this->log( "Function purgePost END ^^^" );
128
  }
129
 
222
  $prefix = $rt_wp_nginx_helper->options['redis_prefix'];
223
  $_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'];
224
  delete_single_key( $_url_purge_base );
225
+ }
226
 
227
  function log( $msg, $level = 'INFO' )
228
  {
667
  //delete_multi_keys("*");
668
  delete_keys_by_wildcard("*");
669
  }
670
+
671
+ function purge_urls()
672
+ {
673
+ global $rt_wp_nginx_helper;
674
+
675
+ $parse = parse_url( site_url() );
676
+ $host = $rt_wp_nginx_helper->options['redis_hostname'];
677
+ $prefix = $rt_wp_nginx_helper->options['redis_prefix'];
678
+ $_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'];
679
+
680
+ if( isset( $rt_wp_nginx_helper->options['purge_url'] ) && ! empty( $rt_wp_nginx_helper->options['purge_url'] ) ) {
681
+ $purge_urls = explode( "\r\n", $rt_wp_nginx_helper->options['purge_url'] );
682
+
683
+ foreach ($purge_urls as $purge_url ) {
684
+ $purge_url = trim( $purge_url );
685
+
686
+ if( strpos( $purge_url, '*' ) === false ) {
687
+ $purge_url = $_url_purge_base . $purge_url;
688
+ $status = delete_single_key( $purge_url );
689
+ if( $status ) {
690
+ $this->log( "- Purge URL | " . $purge_url );
691
+ } else {
692
+ $this->log( "- Not Found | " . $purge_url, 'ERROR' );
693
+ }
694
+ } else {
695
+ $purge_url = $_url_purge_base . $purge_url;
696
+ $status = delete_keys_by_wildcard( $purge_url );
697
+ if( $status ) {
698
+ $this->log( "- Purge Wild Card URL | " . $purge_url . " | ". $status . " url purged" );
699
+ } else {
700
+ $this->log( "- Not Found | " . $purge_url, 'ERROR' );
701
+ }
702
+ }
703
+ }
704
+ }
705
+ }
706
 
707
  }
708