Nginx Helper - Version 2.0.1

Version Description

  • Fix settings url for multisite: use network_admin_url to get network correct settings url. #163 - by Joel-James
  • Fix php error with arbitrary statement in empty - Prior to PHP 5.5. #165 - by PatelUtkarsh
Download this release

Release Info

Developer rahulsprajapati
Plugin Icon 128x128 Nginx Helper
Version 2.0.1
Comparing to
See all releases

Code changes from version 2.0.0 to 2.0.1

Files changed (38) hide show
  1. admin/admin.php +0 -139
  2. admin/assets/logo.png +0 -0
  3. admin/assets/nginx-helper-icons/config.json +0 -34
  4. admin/assets/nginx-helper-icons/css/nginx-fontello.css +0 -56
  5. admin/assets/nginx-helper-icons/font/nginx-fontello.eot +0 -0
  6. admin/assets/nginx-helper-icons/font/nginx-fontello.svg +0 -15
  7. admin/assets/nginx-helper-icons/font/nginx-fontello.ttf +0 -0
  8. admin/assets/nginx-helper-icons/font/nginx-fontello.woff +0 -0
  9. admin/assets/nginx-icon-32x32.png +0 -0
  10. admin/assets/nginx.js +0 -42
  11. admin/assets/rtp-social-icons-32-32.png +0 -0
  12. admin/assets/style.css +0 -22
  13. admin/class-nginx-helper-admin.php +2 -2
  14. admin/install.php +0 -103
  15. admin/lib/nginx-general.php +0 -464
  16. admin/lib/nginx-sidebar.php +0 -67
  17. admin/lib/nginx-support.php +0 -29
  18. compatibility.php +0 -37
  19. includes/class-nginx-helper.php +2 -2
  20. includes/predis.php +0 -15203
  21. includes/redis-delete.php +0 -147
  22. nginx-helper.php +1 -1
  23. purger.php +0 -848
  24. readme.txt +6 -2
  25. redis-purger.php +0 -741
  26. tests/functional/custom-commands/enableAllPurgeCheckbox.js +0 -74
  27. tests/functional/custom-commands/goToAddNewPage.js +0 -14
  28. tests/functional/custom-commands/goToAddNewPost.js +0 -16
  29. tests/functional/custom-commands/nginxSettings.js +0 -15
  30. tests/functional/custom-commands/wplogin.js +0 -14
  31. tests/functional/custom-commands/wplogout.js +0 -16
  32. tests/functional/nightwatch.json +0 -23
  33. tests/functional/package.json +0 -22
  34. tests/functional/res/constants.js +0 -15
  35. tests/functional/src/purge-method-get-request-page-test.js +0 -95
  36. tests/functional/src/purge-method-get-request-post-test.js +0 -145
  37. tests/functional/src/purge-method-unlink-files-page-test.js +0 -95
  38. tests/functional/src/purge-method-unlink-files-post-test.js +0 -145
admin/admin.php DELETED
@@ -1,139 +0,0 @@
1
- <?php
2
-
3
- namespace rtCamp\WP\Nginx {
4
-
5
- class Admin {
6
-
7
- /**
8
- * Holds the values to be used in the fields callbacks
9
- */
10
- private $nginx_helper_tabs;
11
-
12
- function __construct() {
13
- if ( is_multisite() ) {
14
- add_action( 'network_admin_menu', array( &$this, 'add_network_menu' ) );
15
- } else {
16
- add_action( 'admin_menu', array( &$this, 'add_menu' ) );
17
- }
18
-
19
- add_action( 'admin_init', array( $this, 'nginx_admin_page_init' ) );
20
-
21
- /**
22
- * Define Tabs
23
- */
24
- $this->nginx_helper_tabs = apply_filters( 'rt_nginx_helper_tabs', array(
25
- 'general' => array(
26
- 'menu_title' => __( 'General', 'nginx-helper' ),
27
- 'menu_slug' => 'general'
28
- ),
29
- 'support' => array(
30
- 'menu_title' => __( 'Support', 'nginx-helper' ),
31
- 'menu_slug' => 'support'
32
- ) )
33
- );
34
- }
35
-
36
- /**
37
- * Add setting sub-menu for single site
38
- */
39
- function add_menu() {
40
- add_submenu_page( 'options-general.php', __( 'Nginx Helper', 'nginx-helper' ), __( 'Nginx Helper', 'nginx-helper' ), 'manage_options', 'nginx', array( &$this, 'nginx_create_admin_page' ) );
41
- }
42
-
43
- /**
44
- * Add setting sub-menu for multi site
45
- */
46
- function add_network_menu() {
47
- add_submenu_page( 'settings.php', __( 'Nginx Helper', 'nginx-helper' ), __( 'Nginx Helper', 'nginx-helper' ), 'manage_options', 'nginx', array( &$this, 'nginx_create_admin_page' ) );
48
- }
49
-
50
- /**
51
- * Create tab with links
52
- *
53
- * @param type $current current tab
54
- */
55
- function nginx_admin_page_tabs( $current = 'general' ) {
56
- echo '<h2 class="nav-tab-wrapper">';
57
- foreach ( $this->nginx_helper_tabs as $tab => $name ) {
58
- $class = ( $tab == $current ) ? ' nav-tab-active' : '';
59
- echo '<a class="nav-tab' . $class . '" href="?page=nginx&tab=' . $name['menu_slug'] . '">' . $name['menu_title'] . '</a>';
60
- }
61
- echo '</h2>';
62
- }
63
-
64
- /**
65
- * Options page callback
66
- */
67
- function nginx_create_admin_page() {
68
- global $pagenow;
69
-
70
- /**
71
- * Includes PHP files located in 'admin/lib/' folder
72
- */
73
- foreach (glob(plugin_dir_path(__FILE__) . "lib/*.php") as $lib_filename) {
74
- require_once( $lib_filename );
75
- } ?>
76
-
77
- <div class="wrap rt-nginx-wrapper">
78
- <h2 class="rt_option_title"><?php _e( 'Nginx Settings', 'nginx-helper' ); ?></h2>
79
- <div id="poststuff">
80
- <div id="post-body" class="metabox-holder columns-2">
81
- <div id="post-body-content"><?php
82
-
83
- /* Show Tabs */
84
- if ( ( 'options-general.php' == $pagenow || 'settings.php' == $pagenow ) && isset( $_GET['tab'] ) ) {
85
- $this->nginx_admin_page_tabs( $_GET['tab'] );
86
- } else {
87
- $this->nginx_admin_page_tabs( 'general' );
88
- }
89
-
90
- /* Fetch Page Content */
91
- $current = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
92
- if ( ( 'options-general.php' == $pagenow || 'settings.php' == $pagenow ) && isset( $_GET['page'] ) ) {
93
- switch ( $current ) {
94
- case 'general' :
95
- nginx_general_options_page();
96
- break;
97
- case 'support' :
98
- nginx_support_options_page();
99
- break;
100
- }
101
- } ?>
102
- </div> <!-- End of #post-body-content -->
103
- <div id="postbox-container-1" class="postbox-container"><?php
104
- default_admin_sidebar(); ?>
105
- </div> <!-- End of #postbox-container-1 -->
106
- </div> <!-- End of #post-body -->
107
- </div> <!-- End of #poststuff -->
108
- </div> <!-- End of .wrap .rt-nginx-wrapper -->
109
- <?php
110
- }
111
-
112
- function nginx_admin_page_init() {
113
- add_action( 'admin_enqueue_scripts', array( $this, 'nginx_admin_enqueue_assets' ), 999 );
114
- add_action( 'admin_bar_menu', array( &$this, 'nginx_toolbar_purge_item' ), 100 );
115
- }
116
-
117
- function nginx_toolbar_purge_item( $admin_bar ) {
118
- if ( !current_user_can( 'manage_options' ) ) {
119
- return;
120
- }
121
- $purge_url = add_query_arg( array( 'nginx_helper_action' => 'purge', 'nginx_helper_urls' => 'all' ) );
122
- $nonced_url = wp_nonce_url( $purge_url, 'nginx_helper-purge_all' );
123
- $admin_bar->add_menu( array( 'id' => 'nginx-helper-purge-all', 'title' => __( 'Purge Cache', 'nginx-helper' ), 'href' => $nonced_url, 'meta' => array( 'title' => __( 'Purge Cache', 'nginx-helper' ), ), ) );
124
- }
125
-
126
- function nginx_admin_enqueue_assets($hook) {
127
- if ( 'settings_page_nginx' != $hook ) {
128
- return;
129
- }
130
-
131
- /* Load Plugin CSS */
132
- wp_enqueue_style('rt-nginx-admin-icon', plugin_dir_url(__FILE__) . 'assets/nginx-helper-icons/css/nginx-fontello.css');
133
- wp_enqueue_style('rt-nginx-admin-css', plugin_dir_url(__FILE__) . 'assets/style.css');
134
-
135
- /* Load Plugin Scripts */
136
- wp_enqueue_script( 'nginx-js', plugin_dir_url( __FILE__ ) . 'assets/nginx.js', '', '', true );
137
- }
138
- }
139
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/assets/logo.png DELETED
Binary file
admin/assets/nginx-helper-icons/config.json DELETED
@@ -1,34 +0,0 @@
1
- {
2
- "name": "nginx-fontello",
3
- "css_prefix_text": "nginx-helper-",
4
- "css_use_suffix": false,
5
- "hinting": true,
6
- "units_per_em": 1000,
7
- "ascent": 850,
8
- "glyphs": [
9
- {
10
- "uid": "72b1277834cba5b7944b0a6cac7ddb0d",
11
- "css": "rss",
12
- "code": 59395,
13
- "src": "fontawesome"
14
- },
15
- {
16
- "uid": "627abcdb627cb1789e009c08e2678ef9",
17
- "css": "twitter",
18
- "code": 59394,
19
- "src": "fontawesome"
20
- },
21
- {
22
- "uid": "bc50457410acf467b8b5721240768742",
23
- "css": "facebook",
24
- "code": 59393,
25
- "src": "entypo"
26
- },
27
- {
28
- "uid": "b945f4ac2439565661e8e4878e35d379",
29
- "css": "gplus",
30
- "code": 59392,
31
- "src": "entypo"
32
- }
33
- ]
34
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/assets/nginx-helper-icons/css/nginx-fontello.css DELETED
@@ -1,56 +0,0 @@
1
- @font-face {
2
- font-family: 'nginx-fontello';
3
- src: url('../font/nginx-fontello.eot?7388141');
4
- src: url('../font/nginx-fontello.eot?7388141#iefix') format('embedded-opentype'),
5
- url('../font/nginx-fontello.woff?7388141') format('woff'),
6
- url('../font/nginx-fontello.ttf?7388141') format('truetype'),
7
- url('../font/nginx-fontello.svg?7388141#nginx-fontello') format('svg');
8
- font-weight: normal;
9
- font-style: normal;
10
- }
11
- /* Chrome hack: SVG is rendered more smooth in Windozze. 100% magic, uncomment if you need it. */
12
- /* Note, that will break hinting! In other OS-es font will be not as sharp as it could be */
13
- /*
14
- @media screen and (-webkit-min-device-pixel-ratio:0) {
15
- @font-face {
16
- font-family: 'nginx-fontello';
17
- src: url('../font/nginx-fontello.svg?7388141#nginx-fontello') format('svg');
18
- }
19
- }
20
- */
21
-
22
- [class^="nginx-helper-"]:before, [class*=" nginx-helper-"]:before {
23
- font-family: "nginx-fontello";
24
- font-style: normal;
25
- font-weight: normal;
26
- speak: none;
27
-
28
- display: inline-block;
29
- text-decoration: inherit;
30
- width: 1em;
31
- margin-right: .2em;
32
- text-align: center;
33
- /* opacity: .8; */
34
-
35
- /* For safety - reset parent styles, that can break glyph codes*/
36
- font-variant: normal;
37
- text-transform: none;
38
-
39
- /* fix buttons height, for twitter bootstrap */
40
- line-height: 1em;
41
-
42
- /* Animation center compensation - margins should be symmetric */
43
- /* remove if not needed */
44
- margin-left: .2em;
45
-
46
- /* you can be more comfortable with increased icons size */
47
- /* font-size: 120%; */
48
-
49
- /* Uncomment for 3D effect */
50
- /* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */
51
- }
52
-
53
- .nginx-helper-rss:before { content: '\e803'; } /* '' */
54
- .nginx-helper-twitter:before { content: '\e802'; } /* '' */
55
- .nginx-helper-facebook:before { content: '\e801'; } /* '' */
56
- .nginx-helper-gplus:before { content: '\e800'; } /* '' */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/assets/nginx-helper-icons/font/nginx-fontello.eot DELETED
Binary file
admin/assets/nginx-helper-icons/font/nginx-fontello.svg DELETED
@@ -1,15 +0,0 @@
1
- <?xml version="1.0" standalone="no"?>
2
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
- <svg xmlns="http://www.w3.org/2000/svg">
4
- <metadata>Copyright (C) 2013 by original authors @ fontello.com</metadata>
5
- <defs>
6
- <font id="nginx-fontello" horiz-adv-x="1000" >
7
- <font-face font-family="nginx-fontello" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
8
- <missing-glyph horiz-adv-x="1000" />
9
- <glyph glyph-name="rss" unicode="&#xe803;" d="m214 100q0-45-31-76t-76-31t-76 31t-31 76t31 76t76 31t76-31t31-76z m286-69q1-15-9-26q-11-12-27-12h-75q-14 0-24 9t-11 23q-12 128-103 219t-219 103q-14 1-23 11t-9 24v75q0 16 12 26q9 10 24 10h3q89-7 170-45t145-101q63-63 101-145t45-171z m286-1q1-15-10-26q-10-11-26-11h-80q-14 0-25 10t-11 23q-6 120-56 228t-129 188t-188 129t-227 57q-14 0-24 11t-10 24v80q0 15 11 26q10 10 25 10h1q147-8 280-67t238-164q104-104 164-238t67-280z" horiz-adv-x="785.7" />
10
- <glyph glyph-name="twitter" unicode="&#xe802;" d="m904 622q-37-54-90-93q0-8 0-23q0-73-21-145t-64-139t-103-117t-144-82t-181-30q-151 0-276 81q19-3 43-3q126 0 224 77q-59 2-105 36t-64 89q19-2 34-2q24 0 48 6q-63 13-104 62t-41 115v2q38-21 82-23q-37 25-59 64t-22 86q0 49 25 91q68-83 164-133t208-55q-5 21-5 41q0 75 53 127t127 53q79 0 132-57q61 12 114 44q-20-64-79-100q52 6 104 28z" horiz-adv-x="928.6" />
11
- <glyph glyph-name="facebook" unicode="&#xe801;" d="m500 644l-142 0q-14 0-25-15t-11-37l0-102l178 0l0-148l-178 0l0-442l-170 0l0 442l-152 0l0 148l152 0l0 86q0 94 59 159t147 65l142 0l0-156z" horiz-adv-x="500" />
12
- <glyph glyph-name="gplus" unicode="&#xe800;" d="m48 572q0 58 25 102t56 65t69 34t56 15t26 2l230 0l0-4q0-22-78-36q-28 0-38-6q40-20 54-56t14-96q0-102-68-158q-38-38-38-54q0-18 50-64q104-90 104-178q0-140-116-194q-68-34-150-34l-4 0l-4 2q-2-2-4-2q-24 0-54 5t-75 21t-74 57t-29 103q0 60 32 101t83 57t88 22t71 6l2 0q-16 22-24 47t-8 39l2 14l-14 0q-64 0-110 30q-74 44-74 160z m370-452q-4 52-43 84t-103 32l-16 0q-64-2-114-46q-46-42-42-94t53-80t119-24q68 4 109 40t37 88z m-60 500q-30 108-122 108q-12 0-20-2q-40-12-58-62q-16-50-2-106q14-52 47-85t71-33q12 0 18 2q42 12 63 65t3 113z m388-174l150 0l0-94l-150 0l0-150l-94 0l0 150l-150 0l0 94l150 0l0 150l94 0l0-150z" horiz-adv-x="896" />
13
- </font>
14
- </defs>
15
- </svg>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/assets/nginx-helper-icons/font/nginx-fontello.ttf DELETED
Binary file
admin/assets/nginx-helper-icons/font/nginx-fontello.woff DELETED
Binary file
admin/assets/nginx-icon-32x32.png DELETED
Binary file
admin/assets/nginx.js DELETED
@@ -1,42 +0,0 @@
1
- jQuery( document ).ready( function() {
2
- var news_section = jQuery( '#latest_news' );
3
- if ( news_section.length > 0 ) {
4
- jQuery.get( ajaxurl, { action: 'rt_nginx_get_news' }, function( data ) {
5
- news_section.find( '.inside' ).html( data );
6
- } );
7
- }
8
-
9
- jQuery( "form#purgeall a" ).click( function( e ) {
10
- if ( confirm( "Purging entire cache is not recommended. Would you like to continue ?" ) == true ) {
11
- // continue submitting form
12
- } else {
13
- e.preventDefault();
14
- }
15
-
16
- } );
17
-
18
- /**
19
- * Show OR Hide options on option checkbox
20
- * @param {type} selector Selector of Checkbox and PostBox
21
- */
22
- function nginx_show_option( selector ) {
23
- jQuery( '#' + selector ).on( 'change', function() {
24
- if ( jQuery( this ).is( ':checked' ) ) {
25
- jQuery( '.' + selector ).show();
26
- if ( selector == "cache_method_redis" ) {
27
- jQuery( '.cache_method_fastcgi' ).hide();
28
- } else if ( selector == "cache_method_fastcgi" ) {
29
- jQuery( '.cache_method_redis' ).hide();
30
- }
31
- } else {
32
- jQuery( '.' + selector ).hide();
33
- }
34
- } );
35
- }
36
- /* Function call with parameter */
37
- nginx_show_option( 'cache_method_fastcgi' );
38
- nginx_show_option( 'cache_method_redis' );
39
- nginx_show_option( 'enable_map' );
40
- nginx_show_option( 'enable_log' );
41
- nginx_show_option( 'enable_purge' );
42
- } );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/assets/rtp-social-icons-32-32.png DELETED
Binary file
admin/assets/style.css DELETED
@@ -1,22 +0,0 @@
1
- .clearfix { *zoom: 1; }
2
- .clearfix:before, .clearfix:after { content: " "; display: table; }
3
- .clearfix:after { clear: both; }
4
- h4 { margin: 0; }
5
- .form-table th, .form-wrap label { vertical-align: middle; }
6
- table.rtnginx-table { border-bottom: 1px solid #EEE; }
7
- table.rtnginx-table:last-child { border-bottom: 0; }
8
- .rtnginx-table p.error { color: red; }
9
- pre#map { background: #e5e5e5 none; border-radius: 10px; padding: 10px; }
10
- .wrap h2.rt_option_title { background: url(nginx-icon-32x32.png) 0 6px no-repeat rgba(0, 0, 0, 0); padding-left: 40px; }
11
- #poststuff h2 { padding: 0 0 0 10px; margin-top: 0; }
12
- form#purgeall .button-primary { margin-bottom: 20px; box-shadow: inset 0 -2px rgba(0, 0, 0, 0.14);padding: 15px 30px;font-size: 1rem;border: 0;border-radius: 5px;color: #FFF;background: #DD3D36; height: auto; }
13
- form#purgeall .button-primary:hover, form#purgeall .button-primary:focus { background: #d52c24; }
14
- .nh-aligncenter { display: block; text-align: center; line-height: 2; }
15
- #latest_news .inside ul, #useful-links .inside ul { margin: 0 0 0 12px }
16
- #latest_news .inside ul li, #useful-links .inside ul li { list-style: square; padding: 0 0 7px; }
17
- #social .inside a { background-color: #666;color: #FFF;display: inline-block;height: 30px;font-size: 1.25rem;line-height: 30px;margin: 10px 20px 0 0;overflow: hidden;padding: 0;text-align: center;text-decoration: none;width: 30px;-webkit-border-radius: 1000px;-moz-border-radius: 1000px;border-radius: 1000px; }
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/class-nginx-helper-admin.php CHANGED
@@ -316,7 +316,7 @@ class Nginx_Helper_Admin {
316
  $setting_page = 'options-general.php';
317
  }
318
 
319
- $settings_link = '<a href="' . admin_url( $setting_page . '?page=nginx' ) . '">' . __( 'Settings', 'nginx-helper' ) . '</a>';
320
  array_unshift( $links, $settings_link );
321
 
322
  return $links;
@@ -602,7 +602,7 @@ class Nginx_Helper_Admin {
602
  ! $this->options['enable_purge'] ||
603
  empty( $this->options['future_posts'] ) ||
604
  empty( $this->options['future_posts'][ $blog_id ] ) ||
605
- empty( isset( $this->options['future_posts'][ $blog_id ][ $post_id ] ) ) ||
606
  wp_is_post_revision( $post_id )
607
  ) {
608
  return;
316
  $setting_page = 'options-general.php';
317
  }
318
 
319
+ $settings_link = '<a href="' . network_admin_url( $setting_page . '?page=nginx' ) . '">' . __( 'Settings', 'nginx-helper' ) . '</a>';
320
  array_unshift( $links, $settings_link );
321
 
322
  return $links;
602
  ! $this->options['enable_purge'] ||
603
  empty( $this->options['future_posts'] ) ||
604
  empty( $this->options['future_posts'][ $blog_id ] ) ||
605
+ isset( $this->options['future_posts'][ $blog_id ][ $post_id ] ) ||
606
  wp_is_post_revision( $post_id )
607
  ) {
608
  return;
admin/install.php DELETED
@@ -1,103 +0,0 @@
1
- <?php
2
- /**
3
- * @author: Saurabh Shukla <saurabh.shukla@rtcamp.com>
4
- *
5
- * Parts of code based off http://wordpress.org/extend/plugins/nginx-manager/ by http://profiles.wordpress.org/hpatoio/ and http://profiles.wordpress.org/rukbat/
6
- */
7
- namespace rtCamp\WP\Nginx {
8
- if ( preg_match( '#' . basename( __FILE__ ) . '#', $_SERVER[ 'PHP_SELF' ] ) ) {
9
- die( 'You are not allowed to call this page directly.' );
10
- }
11
-
12
- function rt_wp_nginx_helper_install() {
13
- global $wp_roles, $rt_wp_nginx_helper;
14
-
15
- if ( ! current_user_can( 'activate_plugins' ) ) {
16
- return;
17
- }
18
-
19
- $role = get_role( 'administrator' );
20
-
21
- if ( empty( $role ) ) {
22
- update_site_option( "rt_wp_nginx_helper_init_check", __( 'Sorry, you need to be an administrator to use Nginx Helper', 'nginx-helper' ) );
23
- return;
24
- }
25
-
26
- $role->add_cap( 'Nginx Helper | Config' );
27
- $role->add_cap( 'Nginx Helper | Purge cache' );
28
-
29
- $rt_wp_nginx_helper_get_options = get_site_option( 'rt_wp_nginx_helper_global_options' );
30
-
31
- if ( empty( $rt_wp_nginx_helper_get_options ) ) {
32
- $rt_wp_nginx_helper_get_options = rt_wp_nginx_helper_get_options();
33
- update_site_option( "rt_wp_nginx_helper_global_options", $rt_wp_nginx_helper_get_options );
34
- }
35
-
36
- if ( is_multisite() ) {
37
- $blogs = get_blogs_of_user( true );
38
- foreach ( $blogs as $b ) {
39
- $rt_wp_nginx_helper_options = get_blog_option( $b->userblog_id, 'rt_wp_nginx_helper_options' );
40
- if ( empty( $rt_wp_nginx_helper_options ) ) {
41
- $rt_wp_nginx_helper_options = rt_wp_nginx_helper_get_options();
42
- update_blog_option( $b->userblog_id, "rt_wp_nginx_helper_options", $rt_wp_nginx_helper_options );
43
- }
44
- }
45
- } else {
46
- $rt_wp_nginx_helper_options = get_option( 'rt_wp_nginx_helper_options' );
47
- if ( empty( $rt_wp_nginx_helper_options ) ) {
48
- $rt_wp_nginx_helper_options = rt_wp_nginx_helper_get_options();
49
- update_option( "rt_wp_nginx_helper_options", $rt_wp_nginx_helper_options );
50
- }
51
- }
52
- wp_schedule_event( time(), 'daily', 'rt_wp_nginx_helper_check_log_file_size_daily' );
53
- }
54
-
55
- function rt_wp_nginx_helper_uninstall() {
56
- wp_clear_scheduled_hook( 'rt_wp_nginx_helper_check_log_file_size_daily' );
57
- delete_site_option( 'rt_wp_nginx_helper_options' );
58
- rt_wp_nginx_helper_remove_capability( 'Nginx Helper | Config' );
59
- rt_wp_nginx_helper_remove_capability( 'Nginx Helper | Purge cache' );
60
- }
61
-
62
- function rt_wp_nginx_helper_remove_capability( $capability ) {
63
- $check_order = array( 'subscriber', 'contributor', 'author', 'editor', 'administrator' );
64
-
65
- foreach ( $check_order as $role ) {
66
- $role = get_role( $role );
67
-
68
- if ( ! empty( $role ) && is_object( $role ) ) {
69
- $role->remove_cap( $capability );
70
- }
71
- }
72
- }
73
-
74
- function rt_wp_nginx_helper_get_options() {
75
- $rt_wp_nginx_helper_get_options = array( );
76
- $rt_wp_nginx_helper_get_options[ 'log_level' ] = 'INFO';
77
- $rt_wp_nginx_helper_get_options[ 'log_filesize' ] = 5;
78
-
79
- $rt_wp_nginx_helper_get_options[ 'enable_purge' ] = 0;
80
- $rt_wp_nginx_helper_get_options[ 'enable_map' ] = 0;
81
- $rt_wp_nginx_helper_get_options[ 'enable_log' ] = 0;
82
- $rt_wp_nginx_helper_get_options[ 'enable_stamp' ] = 0;
83
-
84
- $rt_wp_nginx_helper_get_options[ 'purge_homepage_on_new' ] = 1;
85
- $rt_wp_nginx_helper_get_options[ 'purge_homepage_on_edit' ] = 1;
86
- $rt_wp_nginx_helper_get_options[ 'purge_homepage_on_del' ] = 1;
87
-
88
- $rt_wp_nginx_helper_get_options[ 'purge_archive_on_new' ] = 1;
89
- $rt_wp_nginx_helper_get_options[ 'purge_archive_on_edit' ] = 1;
90
- $rt_wp_nginx_helper_get_options[ 'purge_archive_on_del' ] = 1;
91
-
92
- $rt_wp_nginx_helper_get_options[ 'purge_archive_on_new_comment' ] = 0;
93
- $rt_wp_nginx_helper_get_options[ 'purge_archive_on_deleted_comment' ] = 0;
94
-
95
- $rt_wp_nginx_helper_get_options[ 'purge_page_on_mod' ] = 1;
96
- $rt_wp_nginx_helper_get_options[ 'purge_page_on_new_comment' ] = 1;
97
- $rt_wp_nginx_helper_get_options[ 'purge_page_on_deleted_comment' ] = 1;
98
-
99
- $rt_wp_nginx_helper_get_options[ 'purge_method' ] = 'get_request';
100
-
101
- return $rt_wp_nginx_helper_get_options;
102
- }
103
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/lib/nginx-general.php DELETED
@@ -1,464 +0,0 @@
1
- <?php
2
-
3
- namespace rtCamp\WP\Nginx {
4
-
5
- function nginx_general_options_page()
6
- {
7
- global $rt_wp_nginx_helper, $rt_wp_nginx_purger;
8
-
9
- $update = 0;
10
- $error_time = false;
11
- $error_log_filesize = false;
12
- $rt_wp_nginx_helper->options['enable_purge'] = (isset( $_POST['enable_purge'] ) and ( $_POST['enable_purge'] == 1) ) ? 1 : 0;
13
- $rt_wp_nginx_helper->options['cache_method'] = (isset( $_POST['cache_method'] ) ) ? $_POST['cache_method'] : 'enable_fastcgi';
14
- $rt_wp_nginx_helper->options['enable_map'] = (isset( $_POST['enable_map'] ) and ( $_POST['enable_map'] == 1) ) ? 1 : 0;
15
- $rt_wp_nginx_helper->options['enable_log'] = (isset( $_POST['enable_log'] ) and ( $_POST['enable_log'] == 1) ) ? 1 : 0;
16
- $rt_wp_nginx_helper->options['enable_stamp'] = (isset( $_POST['enable_stamp'] ) and ( $_POST['enable_stamp'] == 1) ) ? 1 : 0;
17
-
18
- if ( isset( $_POST['is_submit'] ) && ( $_POST['is_submit'] == 1 ) ) {
19
- if ( !(!is_network_admin() && is_multisite() ) ) {
20
- if ( $rt_wp_nginx_helper->options['enable_log'] ) {
21
- if ( isset( $_POST['log_level'] ) && !empty( $_POST['log_level'] ) && $_POST['log_level'] != '' ) {
22
- $rt_wp_nginx_helper->options['log_level'] = $_POST['log_level'];
23
- } else {
24
- $rt_wp_nginx_helper->options['log_level'] = 'INFO';
25
- }
26
- if ( isset( $_POST['log_filesize'] ) && !empty( $_POST['log_filesize'] ) && $_POST['log_filesize'] != '' ) {
27
- if ( (!is_numeric( $_POST['log_filesize'] ) ) || ( empty( $_POST['log_filesize'] ) ) ) {
28
- $error_log_filesize = __( 'Log file size must be a number', 'nginx-helper' );
29
- } else {
30
- $rt_wp_nginx_helper->options['log_filesize'] = $_POST['log_filesize'];
31
- }
32
- } else {
33
- $rt_wp_nginx_helper->options['log_filesize'] = 5;
34
- }
35
- }
36
- if ( $rt_wp_nginx_helper->options['enable_map'] ) {
37
- $rt_wp_nginx_helper->update_map();
38
- }
39
- }
40
- if ( isset( $_POST['enable_purge'] ) ) {
41
- $rt_wp_nginx_helper->options['purge_homepage_on_edit'] = ( isset( $_POST['purge_homepage_on_edit'] ) and ( $_POST['purge_homepage_on_edit'] == 1 ) ) ? 1 : 0;
42
- $rt_wp_nginx_helper->options['purge_homepage_on_del'] = ( isset( $_POST['purge_homepage_on_del'] ) and ( $_POST['purge_homepage_on_del'] == 1 ) ) ? 1 : 0;
43
-
44
- $rt_wp_nginx_helper->options['purge_archive_on_edit'] = ( isset( $_POST['purge_archive_on_edit'] ) and ( $_POST['purge_archive_on_edit'] == 1 ) ) ? 1 : 0;
45
- $rt_wp_nginx_helper->options['purge_archive_on_del'] = ( isset( $_POST['purge_archive_on_del'] ) and ( $_POST['purge_archive_on_del'] == 1 ) ) ? 1 : 0;
46
-
47
- $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;
48
- $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;
49
-
50
- $rt_wp_nginx_helper->options['purge_page_on_mod'] = ( isset( $_POST['purge_page_on_mod'] ) and ( $_POST['purge_page_on_mod'] == 1 ) ) ? 1 : 0;
51
- $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;
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';
60
- $rt_wp_nginx_helper->options['redis_port'] = ( isset( $_POST['redis_port'] ) ) ? $_POST['redis_port'] : '6379';
61
- $rt_wp_nginx_helper->options['redis_prefix'] = ( isset( $_POST['redis_prefix'] ) ) ? $_POST['redis_prefix'] : 'nginx-cache:';
62
- }
63
- update_site_option( 'rt_wp_nginx_helper_options', $rt_wp_nginx_helper->options );
64
- $update = 1;
65
- }
66
- $rt_wp_nginx_helper->options = get_site_option( 'rt_wp_nginx_helper_options' );
67
-
68
- // set default purge method to fastcgi
69
- if ( empty( $rt_wp_nginx_helper->options['cache_method'] ) ) {
70
- $rt_wp_nginx_helper->options['cache_method'] = "enable_fastcgi";
71
- }
72
- /**
73
- * Show Update Message
74
- */
75
- if ( isset( $_POST['smart_http_expire_save'] ) ) {
76
- echo '<div class="updated"><p>' . __( 'Settings saved.', 'nginx-helper' ) . '</p></div>';
77
- }
78
-
79
- /**
80
- * Check for single multiple with subdomain OR multiple with subdirectory site
81
- */
82
- $nginx_setting_link = '#';
83
- if ( is_multisite() ) {
84
- if ( SUBDOMAIN_INSTALL == false ) {
85
- $nginx_setting_link = 'https://rtcamp.com/wordpress-nginx/tutorials/multisite/subdirectories/fastcgi-cache-with-purging/';
86
- } else {
87
- $nginx_setting_link = 'https://rtcamp.com/wordpress-nginx/tutorials/multisite/subdomains/fastcgi-cache-with-purging/';
88
- }
89
- } else {
90
- $nginx_setting_link = 'https://rtcamp.com/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/';
91
- }
92
- ?>
93
- <form id="post_form" method="post" action="#" name="smart_http_expire_form" class="clearfix">
94
- <div class="postbox">
95
- <h3 class="hndle">
96
- <span><?php _e( 'Purging Options', 'nginx-helper' ); ?></span>
97
- </h3>
98
- <div class="inside">
99
- <table class="form-table">
100
- <tr valign="top">
101
- <td>
102
- <input type="checkbox" value="1" id="enable_purge" name="enable_purge"<?php checked( $rt_wp_nginx_helper->options['enable_purge'], 1 ); ?> />
103
- <label for="enable_purge"><?php _e( 'Enable Purge', 'nginx-helper' ); ?></label>
104
- </td>
105
- </tr>
106
- </table>
107
- </div> <!-- End of .inside -->
108
- </div>
109
- <div class="postbox enable_purge"<?php echo ( $rt_wp_nginx_helper->options['enable_purge'] == false ) ? ' style="display: none;"' : ''; ?>>
110
- <h3 class="hndle">
111
- <span><?php _e( 'Caching Method', 'nginx-helper' ); ?></span>
112
- </h3>
113
- <?php if ( !(!is_network_admin() && is_multisite() ) ) { ?>
114
- <div class="inside">
115
- <input type="hidden" name="is_submit" value="1" />
116
- <table class="form-table">
117
- <tr valign="top">
118
- <td>
119
- <input type="radio" value="enable_fastcgi" id="cache_method_fastcgi" name="cache_method" <?php checked( $rt_wp_nginx_helper->options['cache_method'], "enable_fastcgi" ); ?> />
120
- <label for="cache_method_fastcgi">
121
- <?php printf( __( 'nginx Fastcgi cache (<a target="_blank" href="%s" title="External settings for nginx">requires external settings for nginx</a>)', 'nginx-helper' ), $nginx_setting_link ); ?>
122
- </label>
123
- </td>
124
- </tr>
125
- <tr valign="top">
126
- <td>
127
- <input type="radio" value="enable_redis" id="cache_method_redis" name="cache_method" <?php checked( $rt_wp_nginx_helper->options['cache_method'], "enable_redis" ); ?> />
128
- <label for="cache_method_redis">
129
- <?php printf( __( 'Redis cache', 'nginx-helper' ) ); ?>
130
- </label>
131
- </td>
132
- </tr>
133
- </table>
134
- </div> <!-- End of .inside -->
135
- </div>
136
- <div class="enable_purge">
137
- <div class="postbox cache_method_fastcgi"<?php echo ( $rt_wp_nginx_helper->options['enable_purge'] == true && $rt_wp_nginx_helper->options['cache_method'] == "enable_fastcgi" ) ? '' : ' style="display: none;"'; ?>>
138
- <h3 class="hndle">
139
- <span><?php _e( 'Purge Method', 'nginx-helper' ); ?></span>
140
- </h3>
141
- <div class="inside">
142
- <table class="form-table rtnginx-table">
143
- <tr valign="top">
144
- <td>
145
- <fieldset>
146
- <legend class="screen-reader-text">
147
- <span>&nbsp;<?php _e( 'when a post/page/custom post is published.', 'nginx-helper' ); ?></span>
148
- </legend>
149
- <label for="purge_method_get_request">
150
- <input type="radio" value="get_request" id="purge_method_get_request" name="purge_method"<?php checked( isset( $rt_wp_nginx_helper->options['purge_method'] ) ? $rt_wp_nginx_helper->options['purge_method'] : 'get_request', 'get_request' ); ?>>
151
- &nbsp;<?php _e( 'Using a GET request to <strong>PURGE/url</strong> (Default option)', 'nginx-helper' ); ?><br />
152
- <small><?php _e( 'Uses the <strong><a href="https://github.com/FRiCKLE/ngx_cache_purge">ngx_cache_purge</a></strong> module. ', 'nginx-helper' ); ?></small>
153
- </label><br />
154
- <label for="purge_method_unlink_files">
155
- <input type="radio" value="unlink_files" id="purge_method_unlink_files" name="purge_method"<?php checked( isset( $rt_wp_nginx_helper->options['purge_method'] ) ? $rt_wp_nginx_helper->options['purge_method'] : '', 'unlink_files' ); ?>>
156
- &nbsp;<?php _e( 'Delete local server cache files', 'nginx-helper' ); ?><br />
157
- <small><?php _e( 'Checks for matching cache file in <strong>RT_WP_NGINX_HELPER_CACHE_PATH</strong>. Does not require any other modules. Requires that the cache be stored on the same server as WordPress. You must also be using the default nginx cache options (levels=1:2) and (fastcgi_cache_key "$scheme$request_method$host$request_uri"). ', 'nginx-helper' ); ?></small>
158
-
159
- </label><br />
160
- </fieldset>
161
- </td>
162
- </tr>
163
- </table>
164
- </div> <!-- End of .inside -->
165
- </div>
166
- <div class="postbox cache_method_redis"<?php echo ( $rt_wp_nginx_helper->options['enable_purge'] == true && $rt_wp_nginx_helper->options['cache_method'] == "enable_redis" ) ? '' : ' style="display: none;"'; ?>>
167
- <h3 class="hndle">
168
- <span><?php _e( 'Redis Settings', 'nginx-helper' ); ?></span>
169
- </h3>
170
- <div class="inside">
171
- <table class="form-table rtnginx-table">
172
- <?php
173
- $redis_hostname = ( empty( $rt_wp_nginx_helper->options['redis_hostname'] ) ) ? '127.0.0.1' : $rt_wp_nginx_helper->options['redis_hostname'];
174
- $redis_port = ( empty( $rt_wp_nginx_helper->options['redis_port'] ) ) ? '6379' : $rt_wp_nginx_helper->options['redis_port'];
175
- $redis_prefix = ( empty( $rt_wp_nginx_helper->options['redis_prefix'] ) ) ? 'nginx-cache:' : $rt_wp_nginx_helper->options['redis_prefix'];
176
-
177
- $redis_hostname = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $redis_hostname;
178
- $redis_port = defined('RT_WP_NGINX_HELPER_REDIS_PORT') ? RT_WP_NGINX_HELPER_REDIS_PORT : $redis_port;
179
- $redis_prefix = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $redis_prefix;
180
-
181
- $redis_hostname_readonly = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? 'readonly="readonly"' : '';
182
- $redis_port_readonly = defined('RT_WP_NGINX_HELPER_REDIS_PORT') ? 'readonly="readonly"' : '';
183
- $redis_prefix_readonly = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? 'readonly="readonly"' : '';
184
- ?>
185
- <tr>
186
- <th><label for="redis_hostname"><?php _e( 'Hostname', 'nginx-helper' ); ?></label></th>
187
- <td>
188
- <input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo $redis_hostname; ?>" <?php echo $redis_hostname_readonly; ?> />
189
- <?php if ($redis_hostname_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
190
- </td>
191
- </tr>
192
- <tr>
193
- <th><label for="redis_port"><?php _e( 'Port', 'nginx-helper' ); ?></label></th>
194
- <td>
195
- <input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo $redis_port; ?>" <?php echo $redis_port_readonly; ?> />
196
- <?php if ($redis_port_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
197
- </td>
198
- </tr>
199
- <tr>
200
- <th><label for="redis_prefix"><?php _e( 'Prefix', 'nginx-helper' ); ?></label></th>
201
- <td>
202
- <input id="redis_prefix" class="medium-text" type="text" name="redis_prefix" value="<?php echo $redis_prefix; ?>" <?php echo $redis_prefix_readonly; ?> />
203
- <?php if ($redis_prefix_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
204
- </td>
205
- </tr>
206
- </table>
207
- </div> <!-- End of .inside -->
208
- </div>
209
- </div>
210
- <div class="postbox enable_purge"<?php echo ( $rt_wp_nginx_helper->options['enable_purge'] == false ) ? ' style="display: none;"' : ''; ?>>
211
- <h3 class="hndle">
212
- <span><?php _e( 'Purging Conditions', 'nginx-helper' ); ?></span>
213
- </h3>
214
- <div class="inside">
215
-
216
- <table class="form-table rtnginx-table">
217
- <tr valign="top">
218
- <th scope="row"><h4><?php _e( 'Purge Homepage:', 'nginx-helper' ); ?></h4></th>
219
- <td>
220
- <fieldset>
221
- <legend class="screen-reader-text">
222
- <span>&nbsp;<?php _e( 'when a post/page/custom post is modified or added.', 'nginx-helper' ); ?></span>
223
- </legend>
224
- <label for="purge_homepage_on_edit">
225
- <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 ); ?> />
226
- &nbsp;<?php _e( 'when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.', 'nginx-helper' ); ?>
227
- </label><br />
228
- </fieldset>
229
- <fieldset>
230
- <legend class="screen-reader-text">
231
- <span>&nbsp;<?php _e( 'when an existing post/page/custom post is modified.', 'nginx-helper' ); ?></span>
232
- </legend>
233
- <label for="purge_homepage_on_del">
234
- <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 ); ?> />
235
- &nbsp;<?php _e( 'when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>.', 'nginx-helper' ); ?></label><br />
236
- </fieldset>
237
- </td>
238
- </tr>
239
- </table>
240
- <table class="form-table rtnginx-table">
241
- <tr valign="top">
242
- <th scope="row">
243
- <h4><?php _e( 'Purge Post/Page/Custom Post Type:', 'nginx-helper' ); ?></h4>
244
- </th>
245
- <td>
246
- <fieldset>
247
- <legend class="screen-reader-text">
248
- <span>&nbsp;<?php _e( 'when a post/page/custom post is published.', 'nginx-helper' ); ?></span>
249
- </legend>
250
- <label for="purge_page_on_mod">
251
- <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 ); ?>>
252
- &nbsp;<?php _e( 'when a <strong>post</strong> is <strong>published</strong>.', 'nginx-helper' ); ?>
253
- </label><br />
254
- </fieldset>
255
- <fieldset>
256
- <legend class="screen-reader-text">
257
- <span>&nbsp;<?php _e( 'when a comment is approved/published.', 'nginx-helper' ); ?></span>
258
- </legend>
259
- <label for="purge_page_on_new_comment">
260
- <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 ); ?>>
261
- &nbsp;<?php _e( 'when a <strong>comment</strong> is <strong>approved/published</strong>.', 'nginx-helper' ); ?>
262
- </label><br />
263
- </fieldset>
264
- <fieldset>
265
- <legend class="screen-reader-text">
266
- <span>&nbsp;<?php _e( 'when a comment is unapproved/deleted.', 'nginx-helper' ); ?></span>
267
- </legend>
268
- <label for="purge_page_on_deleted_comment">
269
- <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 ); ?>>
270
- &nbsp;<?php _e( 'when a <strong>comment</strong> is <strong>unapproved/deleted</strong>.', 'nginx-helper' ); ?>
271
- </label><br />
272
- </fieldset>
273
- </td>
274
- </tr>
275
- </table>
276
- <table class="form-table rtnginx-table">
277
- <tr valign="top">
278
- <th scope="row">
279
- <h4><?php _e( 'Purge Archives:', 'nginx-helper' ); ?></h4>
280
- <small><?php _e( '(date, category, tag, author, custom taxonomies)', 'nginx-helper' ); ?></small>
281
- </th>
282
- <td>
283
- <fieldset>
284
- <legend class="screen-reader-text">
285
- <span>&nbsp;<?php _e( 'when an post/page/custom post is modified or added.</span>', 'nginx-helper' ); ?>
286
- </legend>
287
- <label for="purge_archive_on_edit">
288
- <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 ); ?> />
289
- &nbsp;<?php _e( 'when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.', 'nginx-helper' ); ?>
290
- </label><br />
291
- </fieldset>
292
- <fieldset>
293
- <legend class="screen-reader-text">
294
- <span>&nbsp;<?php _e( 'when an existing post/page/custom post is trashed.</span>', 'nginx-helper' ); ?>
295
- </legend>
296
- <label for="purge_archive_on_del">
297
- <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 ); ?> />
298
- &nbsp;<?php _e( 'when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>.', 'nginx-helper' ); ?>
299
- </label><br />
300
- </fieldset>
301
- <br />
302
- <fieldset>
303
- <legend class="screen-reader-text">
304
- <span>&nbsp;<?php _e( 'when a comment is approved/published.</span>', 'nginx-helper' ); ?>
305
- </legend>
306
- <label for="purge_archive_on_new_comment">
307
- <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 ); ?> />
308
- &nbsp;<?php _e( 'when a <strong>comment</strong> is <strong>approved/published</strong>.', 'nginx-helper' ); ?>
309
- </label><br />
310
- </fieldset>
311
- <fieldset>
312
- <legend class="screen-reader-text">
313
- <span>&nbsp;<?php _e( 'when a comment is unapproved/deleted.</span>', 'nginx-helper' ); ?>
314
- </legend>
315
- <label for="purge_archive_on_deleted_comment">
316
- <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 ); ?> />
317
- &nbsp;<?php _e( 'when a <strong>comment</strong> is <strong>unapproved/deleted</strong>.', 'nginx-helper' ); ?>
318
- </label><br />
319
- </fieldset>
320
-
321
- </td>
322
- </tr>
323
- </table>
324
- <table class="form-table rtnginx-table">
325
- <tr valign="top">
326
- <th scope="row">
327
- <h4><?php _e( 'Custom Purge URL:', 'nginx-helper' ); ?></h4>
328
- </th>
329
- <td>
330
- <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>
331
- <p class="description">
332
- Add one URL per line. URL should not contain domain name.
333
- <br>
334
- Eg: To purge http://example.com/sample-page/ add <strong>/sample-page/</strong> in above textarea.
335
- <br>
336
- '*' will only work with redis cache server.
337
- </p>
338
- </td>
339
- </tr>
340
- </table>
341
- </div> <!-- End of .inside -->
342
- </div>
343
- <div class="postbox">
344
- <h3 class="hndle">
345
- <span><?php _e( 'Debug Options', 'nginx-helper' ); ?></span>
346
- </h3>
347
- <div class="inside">
348
- <input type="hidden" name="is_submit" value="1" />
349
- <table class="form-table">
350
- <?php if ( is_network_admin() ) { ?>
351
- <tr valign="top">
352
- <td>
353
- <input type="checkbox" value="1" id="enable_map" name="enable_map"<?php checked( $rt_wp_nginx_helper->options['enable_map'], 1 ); ?> />
354
- <label for="enable_map"><?php _e( 'Enable Nginx Map.', 'nginx-helper' ); ?></label>
355
- </td>
356
- </tr>
357
- <?php } ?>
358
- <tr valign="top">
359
- <td>
360
- <input type="checkbox" value="1" id="enable_log" name="enable_log"<?php checked( $rt_wp_nginx_helper->options['enable_log'], 1 ); ?> />
361
- <label for="enable_log"><?php _e( 'Enable Logging', 'nginx-helper' ); ?></label>
362
- </td>
363
- </tr>
364
- <tr valign="top">
365
- <td>
366
- <input type="checkbox" value="1" id="enable_stamp" name="enable_stamp"<?php checked( $rt_wp_nginx_helper->options['enable_stamp'], 1 ); ?> />
367
- <label for="enable_stamp"><?php _e( 'Enable Nginx Timestamp in HTML', 'nginx-helper' ); ?></label>
368
- </td>
369
- </tr>
370
- </table>
371
- </div> <!-- End of .inside -->
372
- </div>
373
- <?php
374
- } // End of if ( !( !is_network_admin() && is_multisite() ) )
375
-
376
-
377
- if ( is_network_admin() ) {
378
- ?>
379
- <div class="postbox enable_map"<?php echo ( $rt_wp_nginx_helper->options['enable_map'] == false ) ? ' style="display: none;"' : ''; ?>>
380
- <h3 class="hndle">
381
- <span><?php _e( 'Nginx Map', 'nginx-helper' ); ?></span>
382
- </h3>
383
- <div class="inside"><?php if ( !is_writable( $rt_wp_nginx_helper->functional_asset_path() . 'map.conf' ) ) { ?>
384
- <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>', 'nginx-helper' ), $rt_wp_nginx_helper->functional_asset_path() . 'map.conf' ); ?></p></span><?php }
385
- ?>
386
-
387
- <table class="form-table rtnginx-table">
388
- <tr>
389
- <th><?php _e( 'Nginx Map path to include in nginx settings<br /><small>(recommended)</small>', 'nginx-helper' ); ?></th>
390
- <td>
391
- <pre><?php echo $rt_wp_nginx_helper->functional_asset_path() . 'map.conf'; ?></pre>
392
- </td>
393
- </tr>
394
- <tr>
395
- <th><?php _e( 'Or,<br />Text to manually copy and paste in nginx settings<br /><small>(if your network is small and new sites are not added frequently)</small>', 'nginx-helper' ); ?></th>
396
- <td>
397
- <pre id="map"><?php echo $rt_wp_nginx_helper->get_map() ?></pre>
398
- </td>
399
- </tr>
400
- </table>
401
- </div> <!-- End of .inside -->
402
- </div>
403
- <?php } ?>
404
-
405
- <div class="postbox enable_log"<?php echo ( $rt_wp_nginx_helper->options['enable_log'] == false ) ? ' style="display: none;"' : ''; ?>>
406
- <h3 class="hndle">
407
- <span><?php _e( 'Logging Options', 'nginx-helper' ); ?></span>
408
- </h3>
409
- <div class="inside">
410
- <?php
411
- $path = $rt_wp_nginx_helper->functional_asset_path();
412
- if ( !is_dir( $path ) ) {
413
- mkdir( $path );
414
- }
415
- if ( !file_exists( $path . 'nginx.log' ) ) {
416
- $log = fopen( $path . 'nginx.log', 'w' );
417
- fclose( $log );
418
- }
419
-
420
- if ( !is_writable( $path . 'nginx.log' ) ) {
421
- ?>
422
- <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>', 'nginx-helper' ), $rt_wp_nginx_helper->functional_asset_path() . 'nginx.log' ); ?></p></span><?php }
423
- ?>
424
-
425
- <table class="form-table rtnginx-table">
426
- <tbody>
427
- <tr>
428
- <th><label for="rt_wp_nginx_helper_logs_path"><?php _e( 'Logs path', 'nginx-helper' ); ?></label></th>
429
- <td><pre><?php echo $rt_wp_nginx_helper->functional_asset_path(); ?>nginx.log</pre></td>
430
- </tr>
431
- <tr>
432
- <th><label for="rt_wp_nginx_helper_logs_link"><?php _e( 'View Log', 'nginx-helper' ); ?></label></th>
433
- <td><a target="_blank" href="<?php echo $rt_wp_nginx_helper->functional_asset_url(); ?>nginx.log"><?php _e( 'Log', 'nginx-helper' ); ?></a></td>
434
- </tr>
435
- <tr>
436
- <th><label for="rt_wp_nginx_helper_log_level"><?php _e( 'Log level', 'nginx-helper' ); ?></label></th>
437
- <td>
438
- <select name="log_level">
439
- <option value="NONE"<?php selected( $rt_wp_nginx_helper->options['log_level'], 'NONE' ); ?>><?php _e( 'None', 'nginx-helper' ); ?></option>
440
- <option value="INFO"<?php selected( $rt_wp_nginx_helper->options['log_level'], 'INFO' ); ?>><?php _e( 'Info', 'nginx-helper' ); ?></option>
441
- <option value="WARNING"<?php selected( $rt_wp_nginx_helper->options['log_level'], 'WARNING' ); ?>><?php _e( 'Warning', 'nginx-helper' ); ?></option>
442
- <option value="ERROR"<?php selected( $rt_wp_nginx_helper->options['log_level'], 'ERROR' ); ?>><?php _e( 'Error', 'nginx-helper' ); ?></option>
443
- </select>
444
- </td>
445
- </tr>
446
- <tr>
447
- <th><label for="log_filesize"><?php _e( 'Max log file size', 'nginx-helper' ); ?></label></th>
448
- <td>
449
- <input id="log_filesize" class="small-text" type="text" name="log_filesize" value="<?php echo $rt_wp_nginx_helper->options['log_filesize'] ?>" /> <?php
450
- _e( 'Mb', 'nginx-helper' );
451
- if ( $error_log_filesize ) {
452
- ?>
453
- <p class="error fade" style="display: block;"><?php echo $error_log_filesize; ?></p><?php }
454
- ?>
455
- </td>
456
- </tr>
457
- </tbody>
458
- </table>
459
- </div> <!-- End of .inside -->
460
- </div><?php submit_button( __( 'Save All Changes', 'nginx-helper' ), 'primary large', 'smart_http_expire_save', true ); ?>
461
- </form><!-- End of #post_form --><?php
462
- }
463
-
464
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/lib/nginx-sidebar.php DELETED
@@ -1,67 +0,0 @@
1
- <?php
2
-
3
- namespace rtCamp\WP\Nginx {
4
-
5
- function default_admin_sidebar()
6
- {
7
- ?>
8
- <?php $purge_url = add_query_arg( array( 'nginx_helper_action' => 'purge', 'nginx_helper_urls' => 'all' ) ); ?>
9
- <?php $nonced_url = wp_nonce_url( $purge_url, 'nginx_helper-purge_all' ); ?>
10
- <form id="purgeall" action="" method="post" class="clearfix">
11
- <a href="<?php echo $nonced_url; ?>" class="button-primary"><?php _e( 'Purge Entire Cache', 'nginx-helper' ); ?></a>
12
- </form>
13
- <div class="postbox" id="support">
14
- <h3 class="hndle">
15
- <span><?php _e( 'Need Help?', 'nginx-helper' ); ?></span>
16
- </h3>
17
- <div class="inside">
18
- <p><?php printf( __( 'Please use our <a href="%s">free support forum</a>.', 'nginx-helper' ), 'http://rtcamp.com/support/forum/wordpress-nginx/' ); ?></p>
19
- </div>
20
- </div>
21
-
22
- <div class="postbox" id="social">
23
- <h3 class="hndle">
24
- <span><?php _e( 'Getting Social is Good', 'nginx-helper' ); ?></span>
25
- </h3>
26
- <div style="text-align:center;" class="inside">
27
- <a class="nginx-helper-facebook" title="<?php _e( 'Become a fan on Facebook', 'nginx-helper' ); ?>" target="_blank" href="http://www.facebook.com/rtCamp.solutions/"></a>
28
- <a class="nginx-helper-twitter" title="<?php _e( 'Follow us on Twitter', 'nginx-helper' ); ?>" target="_blank" href="https://twitter.com/rtcamp/"></a>
29
- <a class="nginx-helper-gplus" title="<?php _e( 'Add to Circle', 'nginx-helper' ); ?>" target="_blank" href="https://plus.google.com/110214156830549460974/posts"></a>
30
- <a class="nginx-helper-rss" title="<?php _e( 'Subscribe to our feeds', 'nginx-helper' ); ?>" target="_blank" href="http://feeds.feedburner.com/rtcamp/"></a>
31
- </div>
32
- </div>
33
-
34
- <div class="postbox" id="useful-links">
35
- <h3 class="hndle">
36
- <span><?php _e( 'Useful Links', 'nginx-helper' ); ?></span>
37
- </h3>
38
- <div class="inside">
39
- <ul role="list">
40
- <li role="listitem">
41
- <a href="https://rtcamp.com/wordpress-nginx/" title="<?php _e( 'WordPress-Nginx Solutions', 'nginx-helper' ); ?>"><?php _e( 'WordPress-Nginx Solutions', 'nginx-helper' ); ?></a>
42
- </li>
43
- <li role="listitem">
44
- <a href="https://rtcamp.com/services/wordPress-themes-design-development/" title="<?php _e( 'WordPress Theme Devleopment', 'nginx-helper' ); ?>"><?php _e( 'WordPress Theme Devleopment', 'nginx-helper' ); ?></a>
45
- </li>
46
- <li role="listitem">
47
- <a href="http://rtcamp.com/services/wordpress-plugins/" title="<?php _e( 'WordPress Plugin Development', 'nginx-helper' ); ?>"><?php _e( 'WordPress Plugin Development', 'nginx-helper' ); ?></a>
48
- </li>
49
- <li role="listitem">
50
- <a href="http://rtcamp.com/services/custom-wordpress-solutions/" title="<?php _e( 'WordPress Consultancy', 'nginx-helper' ); ?>"><?php _e( 'WordPress Consultancy', 'nginx-helper' ); ?></a>
51
- </li>
52
- <li role="listitem">
53
- <a href="https://rtcamp.com/easyengine/" title="<?php _e( 'easyengine (ee)', 'nginx-helper' ); ?>"><?php _e( 'easyengine (ee)', 'nginx-helper' ); ?></a>
54
- </li>
55
- </ul>
56
- </div>
57
- </div>
58
-
59
- <div class="postbox" id="latest_news">
60
- <div title="<?php _e( 'Click to toggle', 'nginx-helper' ); ?>" class="handlediv"><br /></div>
61
- <h3 class="hndle"><span><?php _e( 'Latest News', 'nginx-helper' ); ?></span></h3>
62
- <div class="inside"><img src ="<?php echo admin_url(); ?>/images/wpspin_light.gif" /><?php _e( 'Loading...', 'nginx-helper' ); ?></div>
63
- </div><?php
64
- }
65
-
66
- // End of default_admin_sidebar()
67
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/lib/nginx-support.php DELETED
@@ -1,29 +0,0 @@
1
- <?php
2
-
3
- namespace rtCamp\WP\Nginx {
4
- function nginx_support_options_page() { ?>
5
- <form id="support" action="" method="post" class="clearfix">
6
- <div class="postbox">
7
- <h3 class="hndle">
8
- <span><?php _e( 'Support Forums', 'nginx-helper' ); ?></span>
9
- </h3>
10
- <div class="inside">
11
- <table class="form-table">
12
- <tr valign="top">
13
- <th><?php _e( 'Free Support', 'nginx-helper' ); ?></th>
14
- <td>
15
- <a href="https://rtcamp.com/support/forum/wordpress-nginx/" title="<?php _e( 'Free Support Forum', 'nginx-helper' ); ?>" target="_blank"><?php _e( 'Link to forum', 'nginx-helper' ); ?></a>
16
- </td>
17
- </tr>
18
- <tr valign="top">
19
- <th><?php _e( 'Premium Support', 'nginx-helper' ); ?></th>
20
- <td>
21
- <a href="https://rtcamp.com/wordpress-nginx/pricing/" title="<?php _e( 'Premium Support Forum', 'nginx-helper' ); ?>" target="_blank"><?php _e( 'Link to forum', 'nginx-helper' ); ?></a>
22
- </td>
23
- </tr>
24
- </table>
25
- </div>
26
- </div>
27
- </form><?php
28
- }
29
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
compatibility.php DELETED
@@ -1,37 +0,0 @@
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
- return $self;
15
- }
16
-
17
- private function __construct() {
18
- $this->have_nginx = ('nginx' == substr($_SERVER['SERVER_SOFTWARE'], 0, 5));
19
- if ($this->have_nginx) {
20
- add_filter('got_rewrite', array($this, 'got_rewrite'), 999);
21
-
22
- // For compatibility with several plugins and nginx HTTPS proxying schemes
23
- if (empty($_SERVER['HTTPS']) || 'off' == $_SERVER['HTTPS']) {
24
- unset($_SERVER['HTTPS']);
25
- }
26
- }
27
- }
28
-
29
- public function got_rewrite($got) {
30
- return true;
31
- }
32
-
33
- public function haveNginx() {
34
- return $this->have_nginx;
35
- }
36
- }
37
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-nginx-helper.php CHANGED
@@ -77,7 +77,7 @@ class Nginx_Helper {
77
  public function __construct() {
78
 
79
  $this->plugin_name = 'nginx-helper';
80
- $this->version = '2.0.0';
81
  $this->minimum_WP = '3.0';
82
 
83
  if ( ! $this->required_wp_version() ) {
@@ -299,7 +299,7 @@ class Nginx_Helper {
299
  * Dispay plugin notices.
300
  */
301
  public function display_notices() {
302
- ?>
303
  <div id="message" class="error">
304
  <p>
305
  <strong>
77
  public function __construct() {
78
 
79
  $this->plugin_name = 'nginx-helper';
80
+ $this->version = '2.0.1';
81
  $this->minimum_WP = '3.0';
82
 
83
  if ( ! $this->required_wp_version() ) {
299
  * Dispay plugin notices.
300
  */
301
  public function display_notices() {
302
+ ?>
303
  <div id="message" class="error">
304
  <p>
305
  <strong>
includes/predis.php DELETED
@@ -1,15203 +0,0 @@
1
- <?php
2
-
3
- /*
4
- * This file is part of the Predis package.
5
- *
6
- * (c) Daniele Alessandri <suppakilla@gmail.com>
7
- *
8
- * For the full copyright and license information, please view the LICENSE
9
- * file that was distributed with this source code.
10
- */
11
-
12
- namespace Predis\Command;
13
-
14
- use InvalidArgumentException;
15
-
16
- /**
17
- * Defines an abstraction representing a Redis command.
18
- *
19
- * @author Daniele Alessandri <suppakilla@gmail.com>
20
- */
21
- interface CommandInterface
22
- {
23
- /**
24
- * Returns the ID of the Redis command. By convention, command identifiers
25
- * must always be uppercase.
26
- *
27
- * @return string
28
- */
29
- public function getId();
30
-
31
- /**
32
- * Assign the specified slot to the command for clustering distribution.
33
- *
34
- * @param int $slot Slot ID.
35
- */
36
- public function setSlot($slot);
37
-
38
- /**
39
- * Returns the assigned slot of the command for clustering distribution.
40
- *
41
- * @return int|null
42
- */
43
- public function getSlot();
44
-
45
- /**
46
- * Sets the arguments for the command.
47
- *
48
- * @param array $arguments List of arguments.
49
- */
50
- public function setArguments(array $arguments);
51
-
52
- /**
53
- * Sets the raw arguments for the command without processing them.
54
- *
55
- * @param array $arguments List of arguments.
56
- */
57
- public function setRawArguments(array $arguments);
58
-
59
- /**
60
- * Gets the arguments of the command.
61
- *
62
- * @return array
63
- */
64
- public function getArguments();
65
-
66
- /**
67
- * Gets the argument of the command at the specified index.
68
- *
69
- * @param int $index Index of the desired argument.
70
- *
71
- * @return mixed|null
72
- */
73
- public function getArgument($index);
74
-
75
- /**
76
- * Parses a raw response and returns a PHP object.
77
- *
78
- * @param string $data Binary string containing the whole response.
79
- *
80
- * @return mixed
81
- */
82
- public function parseResponse($data);
83
- }
84
-
85
- /**
86
- * Base class for Redis commands.
87
- *
88
- * @author Daniele Alessandri <suppakilla@gmail.com>
89
- */
90
- abstract class Command implements CommandInterface
91
- {
92
- private $slot;
93
- private $arguments = array();
94
-
95
- /**
96
- * Returns a filtered array of the arguments.
97
- *
98
- * @param array $arguments List of arguments.
99
- *
100
- * @return array
101
- */
102
- protected function filterArguments(array $arguments)
103
- {
104
- return $arguments;
105
- }
106
-
107
- /**
108
- * {@inheritdoc}
109
- */
110
- public function setArguments(array $arguments)
111
- {
112
- $this->arguments = $this->filterArguments($arguments);
113
- unset($this->slot);
114
- }
115
-
116
- /**
117
- * {@inheritdoc}
118
- */
119
- public function setRawArguments(array $arguments)
120
- {
121
- $this->arguments = $arguments;
122
- unset($this->slot);
123
- }
124
-
125
- /**
126
- * {@inheritdoc}
127
- */
128
- public function getArguments()
129
- {
130
- return $this->arguments;
131
- }
132
-
133
- /**
134
- * {@inheritdoc}
135
- */
136
- public function getArgument($index)
137
- {
138
- if (isset($this->arguments[$index])) {
139
- return $this->arguments[$index];
140
- }
141
- }
142
-
143
- /**
144
- * {@inheritdoc}
145
- */
146
- public function setSlot($slot)
147
- {
148
- $this->slot = $slot;
149
- }
150
-
151
- /**
152
- * {@inheritdoc}
153
- */
154
- public function getSlot()
155
- {
156
- if (isset($this->slot)) {
157
- return $this->slot;
158
- }
159
- }
160
-
161
- /**
162
- * {@inheritdoc}
163
- */
164
- public function parseResponse($data)
165
- {
166
- return $data;
167
- }
168
-
169
- /**
170
- * Normalizes the arguments array passed to a Redis command.
171
- *
172
- * @param array $arguments Arguments for a command.
173
- *
174
- * @return array
175
- */
176
- public static function normalizeArguments(array $arguments)
177
- {
178
- if (count($arguments) === 1 && is_array($arguments[0])) {
179
- return $arguments[0];
180
- }
181
-
182
- return $arguments;
183
- }
184
-
185
- /**
186
- * Normalizes the arguments array passed to a variadic Redis command.
187
- *
188
- * @param array $arguments Arguments for a command.
189
- *
190
- * @return array
191
- */
192
- public static function normalizeVariadic(array $arguments)
193
- {
194
- if (count($arguments) === 2 && is_array($arguments[1])) {
195
- return array_merge(array($arguments[0]), $arguments[1]);
196
- }
197
-
198
- return $arguments;
199
- }
200
- }
201
-
202
- /**
203
- * @link http://redis.io/commands/zrange
204
- * @author Daniele Alessandri <suppakilla@gmail.com>
205
- */
206
- class ZSetRange extends Command
207
- {
208
- /**
209
- * {@inheritdoc}
210
- */
211
- public function getId()
212
- {
213
- return 'ZRANGE';
214
- }
215
-
216
- /**
217
- * {@inheritdoc}
218
- */
219
- protected function filterArguments(array $arguments)
220
- {
221
- if (count($arguments) === 4) {
222
- $lastType = gettype($arguments[3]);
223
-
224
- if ($lastType === 'string' && strtoupper($arguments[3]) === 'WITHSCORES') {
225
- // Used for compatibility with older versions
226
- $arguments[3] = array('WITHSCORES' => true);
227
- $lastType = 'array';
228
- }
229
-
230
- if ($lastType === 'array') {
231
- $options = $this->prepareOptions(array_pop($arguments));
232
-
233
- return array_merge($arguments, $options);
234
- }
235
- }
236
-
237
- return $arguments;
238
- }
239
-
240
- /**
241
- * Returns a list of options and modifiers compatible with Redis.
242
- *
243
- * @param array $options List of options.
244
- *
245
- * @return array
246
- */
247
- protected function prepareOptions($options)
248
- {
249
- $opts = array_change_key_case($options, CASE_UPPER);
250
- $finalizedOpts = array();
251
-
252
- if (!empty($opts['WITHSCORES'])) {
253
- $finalizedOpts[] = 'WITHSCORES';
254
- }
255
-
256
- return $finalizedOpts;
257
- }
258
-
259
- /**
260
- * Checks for the presence of the WITHSCORES modifier.
261
- *
262
- * @return bool
263
- */
264
- protected function withScores()
265
- {
266
- $arguments = $this->getArguments();
267
-
268
- if (count($arguments) < 4) {
269
- return false;
270
- }
271
-
272
- return strtoupper($arguments[3]) === 'WITHSCORES';
273
- }
274
-
275
- /**
276
- * {@inheritdoc}
277
- */
278
- public function parseResponse($data)
279
- {
280
- if ($this->withScores()) {
281
- $result = array();
282
-
283
- for ($i = 0; $i < count($data); $i++) {
284
- $result[$data[$i]] = $data[++$i];
285
- }
286
-
287
- return $result;
288
- }
289
-
290
- return $data;
291
- }
292
- }
293
-
294
- /**
295
- * @link http://redis.io/commands/sinterstore
296
- * @author Daniele Alessandri <suppakilla@gmail.com>
297
- */
298
- class SetIntersectionStore extends Command
299
- {
300
- /**
301
- * {@inheritdoc}
302
- */
303
- public function getId()
304
- {
305
- return 'SINTERSTORE';
306
- }
307
-
308
- /**
309
- * {@inheritdoc}
310
- */
311
- protected function filterArguments(array $arguments)
312
- {
313
- if (count($arguments) === 2 && is_array($arguments[1])) {
314
- return array_merge(array($arguments[0]), $arguments[1]);
315
- }
316
-
317
- return $arguments;
318
- }
319
- }
320
-
321
- /**
322
- * @link http://redis.io/commands/sinter
323
- * @author Daniele Alessandri <suppakilla@gmail.com>
324
- */
325
- class SetIntersection extends Command
326
- {
327
- /**
328
- * {@inheritdoc}
329
- */
330
- public function getId()
331
- {
332
- return 'SINTER';
333
- }
334
-
335
- /**
336
- * {@inheritdoc}
337
- */
338
- protected function filterArguments(array $arguments)
339
- {
340
- return self::normalizeArguments($arguments);
341
- }
342
- }
343
-
344
- /**
345
- * @link http://redis.io/commands/eval
346
- * @author Daniele Alessandri <suppakilla@gmail.com>
347
- */
348
- class ServerEval extends Command
349
- {
350
- /**
351
- * {@inheritdoc}
352
- */
353
- public function getId()
354
- {
355
- return 'EVAL';
356
- }
357
-
358
- /**
359
- * Calculates the SHA1 hash of the body of the script.
360
- *
361
- * @return string SHA1 hash.
362
- */
363
- public function getScriptHash()
364
- {
365
- return sha1($this->getArgument(0));
366
- }
367
- }
368
-
369
- /**
370
- * @link http://redis.io/commands/rename
371
- * @author Daniele Alessandri <suppakilla@gmail.com>
372
- */
373
- class KeyRename extends Command
374
- {
375
- /**
376
- * {@inheritdoc}
377
- */
378
- public function getId()
379
- {
380
- return 'RENAME';
381
- }
382
- }
383
-
384
- /**
385
- * @link http://redis.io/commands/setex
386
- * @author Daniele Alessandri <suppakilla@gmail.com>
387
- */
388
- class StringSetExpire extends Command
389
- {
390
- /**
391
- * {@inheritdoc}
392
- */
393
- public function getId()
394
- {
395
- return 'SETEX';
396
- }
397
- }
398
-
399
- /**
400
- * @link http://redis.io/commands/mset
401
- * @author Daniele Alessandri <suppakilla@gmail.com>
402
- */
403
- class StringSetMultiple extends Command
404
- {
405
- /**
406
- * {@inheritdoc}
407
- */
408
- public function getId()
409
- {
410
- return 'MSET';
411
- }
412
-
413
- /**
414
- * {@inheritdoc}
415
- */
416
- protected function filterArguments(array $arguments)
417
- {
418
- if (count($arguments) === 1 && is_array($arguments[0])) {
419
- $flattenedKVs = array();
420
- $args = $arguments[0];
421
-
422
- foreach ($args as $k => $v) {
423
- $flattenedKVs[] = $k;
424
- $flattenedKVs[] = $v;
425
- }
426
-
427
- return $flattenedKVs;
428
- }
429
-
430
- return $arguments;
431
- }
432
- }
433
-
434
- /**
435
- * @link http://redis.io/commands/expireat
436
- * @author Daniele Alessandri <suppakilla@gmail.com>
437
- */
438
- class KeyExpireAt extends Command
439
- {
440
- /**
441
- * {@inheritdoc}
442
- */
443
- public function getId()
444
- {
445
- return 'EXPIREAT';
446
- }
447
-
448
- /**
449
- * {@inheritdoc}
450
- */
451
- public function parseResponse($data)
452
- {
453
- return (bool) $data;
454
- }
455
- }
456
-
457
- /**
458
- * @link http://redis.io/commands/blpop
459
- * @author Daniele Alessandri <suppakilla@gmail.com>
460
- */
461
- class ListPopFirstBlocking extends Command
462
- {
463
- /**
464
- * {@inheritdoc}
465
- */
466
- public function getId()
467
- {
468
- return 'BLPOP';
469
- }
470
-
471
- /**
472
- * {@inheritdoc}
473
- */
474
- protected function filterArguments(array $arguments)
475
- {
476
- if (count($arguments) === 2 && is_array($arguments[0])) {
477
- list($arguments, $timeout) = $arguments;
478
- array_push($arguments, $timeout);
479
- }
480
-
481
- return $arguments;
482
- }
483
- }
484
-
485
- /**
486
- * @link http://redis.io/commands/unsubscribe
487
- * @author Daniele Alessandri <suppakilla@gmail.com>
488
- */
489
- class PubSubUnsubscribe extends Command
490
- {
491
- /**
492
- * {@inheritdoc}
493
- */
494
- public function getId()
495
- {
496
- return 'UNSUBSCRIBE';
497
- }
498
-
499
- /**
500
- * {@inheritdoc}
501
- */
502
- protected function filterArguments(array $arguments)
503
- {
504
- return self::normalizeArguments($arguments);
505
- }
506
- }
507
-
508
- /**
509
- * @link http://redis.io/commands/info
510
- * @author Daniele Alessandri <suppakilla@gmail.com>
511
- */
512
- class ServerInfo extends Command
513
- {
514
- /**
515
- * {@inheritdoc}
516
- */
517
- public function getId()
518
- {
519
- return 'INFO';
520
- }
521
-
522
- /**
523
- * {@inheritdoc}
524
- */
525
- public function parseResponse($data)
526
- {
527
- $info = array();
528
- $infoLines = preg_split('/\r?\n/', $data);
529
-
530
- foreach ($infoLines as $row) {
531
- if (strpos($row, ':') === false) {
532
- continue;
533
- }
534
-
535
- list($k, $v) = $this->parseRow($row);
536
- $info[$k] = $v;
537
- }
538
-
539
- return $info;
540
- }
541
-
542
- /**
543
- * Parses a single row of the response and returns the key-value pair.
544
- *
545
- * @param string $row Single row of the response.
546
- *
547
- * @return array
548
- */
549
- protected function parseRow($row)
550
- {
551
- list($k, $v) = explode(':', $row, 2);
552
-
553
- if (preg_match('/^db\d+$/', $k)) {
554
- $v = $this->parseDatabaseStats($v);
555
- }
556
-
557
- return array($k, $v);
558
- }
559
-
560
- /**
561
- * Extracts the statistics of each logical DB from the string buffer.
562
- *
563
- * @param string $str Response buffer.
564
- *
565
- * @return array
566
- */
567
- protected function parseDatabaseStats($str)
568
- {
569
- $db = array();
570
-
571
- foreach (explode(',', $str) as $dbvar) {
572
- list($dbvk, $dbvv) = explode('=', $dbvar);
573
- $db[trim($dbvk)] = $dbvv;
574
- }
575
-
576
- return $db;
577
- }
578
-
579
- /**
580
- * Parses the response and extracts the allocation statistics.
581
- *
582
- * @param string $str Response buffer.
583
- *
584
- * @return array
585
- */
586
- protected function parseAllocationStats($str)
587
- {
588
- $stats = array();
589
-
590
- foreach (explode(',', $str) as $kv) {
591
- @list($size, $objects, $extra) = explode('=', $kv);
592
-
593
- // hack to prevent incorrect values when parsing the >=256 key
594
- if (isset($extra)) {
595
-