Skip to content

Commit

Permalink
Merge pull request #153 from kelin1003/nginx-helper-2
Browse files Browse the repository at this point in the history
Added missing code from master
  • Loading branch information
rahulsprajapati committed Sep 4, 2018
2 parents 15af58e + 0a8eabd commit 8704ed9
Show file tree
Hide file tree
Showing 23 changed files with 2,835 additions and 2,262 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ tests/functional/node_modules/
/tests/functional/reports/
selenium-*.jar
vendor
.vscode/
42 changes: 42 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
sudo: required

language: node_js
node_js:
- "0.10"


before_install:
- rm -rf ~/.gnupg


before_script:
- export PLUGIN_DIR=$(pwd)
- ls -l
- sudo rm -rf /etc/mysql/
- sudo apt-get -qq purge mysql* graphviz*
- sudo apt-get -qq autoremove
- sudo apt-get update
- sudo bash -c 'echo -e "[user]\n\tname = abc\n\temail = root@localhost.com" > /home/travis/.gitconfig'
- sudo wget -qO ee rt.cx/ee && sudo bash ee
- source /etc/bash_completion.d/ee_auto.rc
- sudo ee -v
- sudo lsb_release -a
- sudo ee site create wp.localtest.me --wpfc --user=ADMINUSER --email=prabuddha.chakraborty@rtcamp.com --pass=ADMINPASS
- sudo chmod 777 -R /var/www
- sudo nginx -t
- sudo service nginx reload
- cd /var/www/wp.localtest.me/htdocs/wp-content/plugins/ && ls
- wp --allow-root plugin deactivate w3-total-cache
- wp --allow-root plugin delete nginx-helper
- mkdir nginx-helper
- cd $PLUGIN_DIR
- cp -Rf * /var/www/wp.localtest.me/htdocs/wp-content/plugins/nginx-helper/
- cd /var/www/wp.localtest.me/htdocs/
- wp plugin activate --all
- cd $PLUGIN_DIR
- cd tests/functional/
- npm install -g nightwatch
- npm install

script:
- nightwatch
66 changes: 50 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Nginx Helper #
**Contributors:** rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123
**Contributors:** rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123, ravanh, michaelbeil, samedwards, niwreg, entr, nuvoPoint

**Tags:** nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks
**Requires at least:** 3.0
**Tested up to:** 4.2.2
**Stable tag:** 1.9.3
**Tested up to:** 4.9.5
**Stable tag:** 1.9.11
**License:** GPLv2 or later (of-course)
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html
**Donate Link:** http://rtcamp.com/donate/

Cleans nginx's fastcgi/proxy cache or redis-cahce whenever a post is edited/published. Also does few more things.
Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does a few more things.

## Description ##

Expand All @@ -21,11 +22,11 @@ Cleans nginx's fastcgi/proxy cache or redis-cahce whenever a post is edited/publ

You will need to follow one or more tutorials below to get desired functionality:

* [Nginx Map + WordPress-Multisite + Static Files Handling](http://rtcamp.com/tutorials/nginx-maps-wordpress-multisite-static-files-handling/)
* [Nginx + WordPress + fastcgi_purge_cache](http://rtcamp.com/tutorials/wordpress-nginx-fastcgi-cache-purge-conditional/)
* [Nginx + WordPress-Multisite (Subdirectories) + fastcgi_purge_cache](http://rtcamp.com/tutorials/wordpress-multisite-subdirectories-nginx-fastcgi-cache-purge/)
* [Nginx + WordPress-Multisite (Subdomains/domain-mapping) + fastcgi_purge_cache](http://rtcamp.com/tutorials/wordpress-multisite-subdomains-domain-mapping-nginx-fastcgi-cache-purge/)
* [Other WordPress-Nginx Tutorials](http://rtcamp.com/wordpress-nginx/tutorials/)
* [Nginx Map + WordPress-Multisite + Static Files Handling](https://easyengine.io/wordpress-nginx/tutorials/multisite/static-files-handling/)
* [Nginx + WordPress + fastcgi_purge_cache](https://easyengine.io/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/)
* [Nginx + WordPress-Multisite (Subdirectories) + fastcgi_purge_cache](https://easyengine.io/wordpress-nginx/tutorials/multisite/subdirectories/fastcgi-cache-with-purging/)
* [Nginx + WordPress-Multisite (Subdomains/domain-mapping) + fastcgi_purge_cache](https://easyengine.io/wordpress-nginx/tutorials/multisite/subdomains/fastcgi-cache-with-purging/)
* [Other WordPress-Nginx Tutorials](https://easyengine.io/wordpress-nginx/tutorials/)


## Installation ##
Expand All @@ -45,13 +46,13 @@ For proper configuration, check out our **tutorial list** in the [Description ta

## Frequently Asked Questions ##

**Important** - Please refer to [http://rtcamp.com/nginx-helper/faq](http://rtcamp.com/nginx-helper/faq) for up-to-date FAQs.
**Important** - Please refer to [https://easyengine.io/nginx-helper/faq](https://easyengine.io/nginx-helper/faq) for up-to-date FAQs.

### FAQ - Installation/Comptability ###

**Q. Will this work out of the box?**

No. You need to make some changes at the Nginx end. Please check our [tutorial list](http://rtcamp.com/wordpress-nginx/tutorials).
No. You need to make some changes at the Nginx end. Please check our [tutorial list](https://easyengine.io/wordpress-nginx/tutorials/).

### FAQ - Nginx Fastcgi Cache Purge ###

Expand Down Expand Up @@ -109,15 +110,48 @@ Most likely yes. A wordpress plugin, if not using explicitly any Apache-only mod
Please post your problem in [our free support forum](http://community.rtcamp.com/c/wordpress-nginx).

## Screenshots ##
###1. Nginx plugin settings###
### 1. Nginx plugin settings ###
![Nginx plugin settings](https://ps.w.org/nginx-helper/assets/screenshot-1.png)

###2. Remaining settings###
### 2. Remaining settings ###
![Remaining settings](https://ps.w.org/nginx-helper/assets/screenshot-2.png)


## Changelog ##

### 1.9.11 ###
* Fixed issue where permalinks without trailing slash does not purging [#124](https://github.com/rtCamp/nginx-helper/issues/124) - by Patrick
* Check whether role exist or not before removing capability. [#134](https://github.com/rtCamp/nginx-helper/pull/134) - by [1gor](https://github.com/1gor)

### 1.9.10 ###
* Fixed issue where Nginx cache folders deleted on purge. [#123](https://github.com/rtCamp/nginx-helper/pull/123) - by [johan-chassaing](https://github.com/johan-chassaing)
* Fixed Redis purge all feature for installation where WordPress lives in a separate folder. [#130](https://github.com/rtCamp/nginx-helper/pull/130) - by [pySilver](https://github.com/pySilver)

### 1.9.9 ###
* Fix wp_redirect issue. [#131](https://github.com/rtCamp/nginx-helper/pull/131) - by [matt-h](https://github.com/matt-h)

### 1.9.8 ###
* Fixed homepage cache cleared when WPML plugin used [#116](https://github.com/rtCamp/nginx-helper/pull/116) - by [Niwreg](https://profiles.wordpress.org/niwreg/)
* Fixed Purge Cache clears the whole Redis cache [#113](https://github.com/rtCamp/nginx-helper/issues/113) - by HansVanEijsden
* One log file for all site in WPMU.
* Single site Redis cache purge when click on Purge Cache button in WPMU [#122](https://github.com/rtCamp/nginx-helper/pull/122) - by Lars Støttrup Nielsen
* Fixed notices and warnings.

### 1.9.7 ###
* Remove timestamp if cron or wp-cli [#114](https://github.com/rtCamp/nginx-helper/pull/114) - by [samedwards](https://profiles.wordpress.org/samedwards/)
* Fixed notices and warnings.

### 1.9.6 ###
* Fixed cache purging on post publish.
* Error fixed when redis server not installed.

### 1.9.5 ###
Added custom purge URL option.

### 1.9.4 ###
* Added redis server connection timeout.
* Added RedisException handling.

### 1.9.3 ###
* Added PhpRedis API support.
* Added redis-lua script support to purge complete cache very fast.
Expand Down Expand Up @@ -315,6 +349,6 @@ Fix url escaping [#82](https://github.com/rtCamp/nginx-helper/pull/82) - by

## Upgrade Notice ##

### 1.9.3 ###
* Added PhpRedis API support.
* Fixed cache purging link in admin bar.
### 1.9.11 ###
* Fixed issue where permalinks without trailing slash does not purging [#124](https://github.com/rtCamp/nginx-helper/issues/124) - by Patrick
* Check whether role exist or not before removing capability. [#134](https://github.com/rtCamp/nginx-helper/pull/134) - by [1gor](https://github.com/1gor)
204 changes: 104 additions & 100 deletions admin/class-fastcgi-purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,104 +19,108 @@
*/
class FastCGI_Purger extends Purger {

public function purgeUrl( $url, $feed = true ) {
global $nginx_helper_admin;

$this->log( "- Purging URL | " . $url );

$parse = parse_url( $url );

switch ( $nginx_helper_admin->options['purge_method'] ) {
case 'unlink_files':
$_url_purge_base = $parse['scheme'] . '://' . $parse['host'] . $parse['path'];
$_url_purge = $_url_purge_base;

if ( isset( $parse['query']) && $parse['query'] != '' ) {
$_url_purge .= '?' . $parse['query'];
}

$this->_delete_cache_file_for( $_url_purge );

if ( $feed ) {
$feed_url = rtrim( $_url_purge_base, '/' ) . '/feed/';
$this->_delete_cache_file_for( $feed_url );
$this->_delete_cache_file_for( $feed_url . 'atom/' );
$this->_delete_cache_file_for( $feed_url . 'rdf/' );
}
break;
case 'get_request':
// Go to default case
default:
$_url_purge_base = $parse['scheme'] . '://' . $parse['host'] . '/purge' . $parse['path'];
$_url_purge = $_url_purge_base;

if ( isset( $parse['query']) && '' != $parse['query'] ) {
$_url_purge .= '?' . $parse['query'];
}

$this->_do_remote_get( $_url_purge );

if ( $feed ) {
$feed_url = rtrim($_url_purge_base, '/' ) . '/feed/';
$this->_do_remote_get( $feed_url );
$this->_do_remote_get( $feed_url . 'atom/' );
$this->_do_remote_get( $feed_url . 'rdf/' );
}
break;
}
}

public function customPurgeUrls() {
global $nginx_helper_admin;

$parse = parse_url( site_url() );

$purge_urls = isset( $nginx_helper_admin->options['purge_url'] ) && ! empty( $nginx_helper_admin->options['purge_url'] ) ?
explode( "\r\n", $nginx_helper_admin->options['purge_url'] ) : array();

// Allow plugins/themes to modify/extend urls. Pass urls array in first parameter, second says if wildcards are allowed
$purge_urls = apply_filters( 'rt_nginx_helper_purge_urls', $purge_urls, false );

switch ( $nginx_helper_admin->options['purge_method'] ) {
case 'unlink_files':
$_url_purge_base = $parse['scheme'] . '://' . $parse['host'];

if( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
foreach ( $purge_urls as $purge_url ) {
$purge_url = trim( $purge_url );

if ( strpos($purge_url, '*' ) === false ) {
$purge_url = $_url_purge_base . $purge_url;
$this->log( "- Purging URL | " . $url );
$this->_delete_cache_file_for( $purge_url );
}
}
}
break;
case 'get_request':
// Go to default case
default:
$_url_purge_base = $parse['scheme'] . '://' . $parse['host'] . '/purge';

if( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
foreach ( $purge_urls as $purge_url ) {
$purge_url = trim( $purge_url );

if ( strpos( $purge_url, '*' ) === false ) {
$purge_url = $_url_purge_base . $purge_url;
$this->log( "- Purging URL | " . $url );
$this->_do_remote_get( $purge_url );
}
}
}
break;
}
}

public function purgeAll() {
$this->unlinkRecursive( RT_WP_NGINX_HELPER_CACHE_PATH, false );
$this->log( "* * * * *" );
$this->log( "* Purged Everything!" );
$this->log( "* * * * *" );
}
public function purgeUrl( $url, $feed = true ) {
global $nginx_helper_admin;

$this->log( '- Purging URL | ' . $url );

$parse = parse_url( $url );

if ( ! isset( $parse['path'] ) ) {
$parse['path'] = '';
}

switch ( $nginx_helper_admin->options['purge_method'] ) {
case 'unlink_files':
$_url_purge_base = $parse['scheme'] . '://' . $parse['host'] . $parse['path'];
$_url_purge = $_url_purge_base;

if ( isset( $parse['query'] ) && $parse['query'] != '' ) {
$_url_purge .= '?' . $parse['query'];
}

$this->_delete_cache_file_for( $_url_purge );

if ( $feed ) {
$feed_url = rtrim( $_url_purge_base, '/' ) . '/feed/';
$this->_delete_cache_file_for( $feed_url );
$this->_delete_cache_file_for( $feed_url . 'atom/' );
$this->_delete_cache_file_for( $feed_url . 'rdf/' );
}
break;
case 'get_request':
// Go to default case
default:
$_url_purge_base = $parse['scheme'] . '://' . $parse['host'] . '/purge' . $parse['path'];
$_url_purge = $_url_purge_base;

if ( isset( $parse['query'] ) && '' != $parse['query'] ) {
$_url_purge .= '?' . $parse['query'];
}

$this->_do_remote_get( $_url_purge );

if ( $feed ) {
$feed_url = rtrim( $_url_purge_base, '/' ) . '/feed/';
$this->_do_remote_get( $feed_url );
$this->_do_remote_get( $feed_url . 'atom/' );
$this->_do_remote_get( $feed_url . 'rdf/' );
}
break;
}
}

public function customPurgeUrls() {
global $nginx_helper_admin;

$parse = parse_url( site_url() );

$purge_urls = isset( $nginx_helper_admin->options['purge_url'] ) && ! empty( $nginx_helper_admin->options['purge_url'] ) ?
explode( "\r\n", $nginx_helper_admin->options['purge_url'] ) : array();

// Allow plugins/themes to modify/extend urls. Pass urls array in first parameter, second says if wildcards are allowed
$purge_urls = apply_filters( 'rt_nginx_helper_purge_urls', $purge_urls, false );

switch ( $nginx_helper_admin->options['purge_method'] ) {
case 'unlink_files':
$_url_purge_base = $parse['scheme'] . '://' . $parse['host'];

if ( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
foreach ( $purge_urls as $purge_url ) {
$purge_url = trim( $purge_url );

if ( strpos( $purge_url, '*' ) === false ) {
$purge_url = $_url_purge_base . $purge_url;
$this->log( '- Purging URL | ' . $url );
$this->_delete_cache_file_for( $purge_url );
}
}
}
break;
case 'get_request':
// Go to default case
default:
$_url_purge_base = $parse['scheme'] . '://' . $parse['host'] . '/purge';

if ( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
foreach ( $purge_urls as $purge_url ) {
$purge_url = trim( $purge_url );

if ( strpos( $purge_url, '*' ) === false ) {
$purge_url = $_url_purge_base . $purge_url;
$this->log( '- Purging URL | ' . $url );
$this->_do_remote_get( $purge_url );
}
}
}
break;
}
}

public function purgeAll() {
$this->unlinkRecursive( RT_WP_NGINX_HELPER_CACHE_PATH, false );
$this->log( '* * * * *' );
$this->log( '* Purged Everything!' );
$this->log( '* * * * *' );
}
}
Loading

0 comments on commit 8704ed9

Please sign in to comment.