Version Description
- Fix: Extensions URL in settings
- Fix: Redis undefined array key warnings
- Fix: Redis connect issue based on phpredis version
- Fix: Sanitization of licensing messages
- Fix: DB cache error in Ajax
- Fix: Call to undefined function in DB cache query class
- Fix: PHP 8 compatibility: join
- Fix: WooCommerce Variation Image Gallery plugin CDN filter
- Enhancement: Add setting for AWS S3 public objects in ACL
- Enhancement: Check if post is empty before cache flush
- Enhancement: Add max lifetime setting for non-disk page cache
- Enhancement: Add notice when selecting CDN using CloudFront
- Update: CSS Tidy 1.7.3 => 2.0.1
- Update: Add sns-message-validator
- Security: Ensure cache writes in cache folders
Download this release
Release Info
Developer | joemoto |
Plugin | W3 Total Cache |
Version | 2.2.4 |
Comparing to | |
See all releases |
Code changes from version 2.2.3 to 2.2.4
- Cache_File_Generic.php +10 -0
- Cache_Redis.php +72 -31
- CdnEngine_GoogleDrive.php +1 -5
- Cdn_Core.php +1 -0
- Cdn_Plugin.php +30 -0
- ConfigCache.php +9 -0
- ConfigKeys.php +4 -0
- DbCache_WpdbInjection_QueryCaching.php +342 -252
- Generic_Plugin_Admin.php +30 -0
- Licensing_Plugin_Admin.php +18 -1
- PgCache_Flush.php +3 -0
- Util_File.php +11 -2
- inc/options/cdn.php +26 -1
- inc/options/cdn/cf.php +1 -1
- inc/options/cdn/s3.php +9 -0
- inc/options/extensions.php +1 -1
- inc/options/parts/redis.php +7 -0
- inc/options/parts/redis_extension.php +12 -9
- inc/options/pgcache.php +1 -1
- ini/config-db-sample.php +3 -0
- lib/CSSTidy/class.csstidy.php +8 -3
- lib/CSSTidy/class.csstidy_optimise.php +3 -3
- lib/CSSTidy/data.inc.php +1 -0
- pub/js/options.js +40 -1
- readme.txt +18 -1
- vendor/aws/aws-php-sns-message-validator/.github/ISSUE_TEMPLATE/bug-report.yml +73 -0
- vendor/aws/aws-php-sns-message-validator/.github/ISSUE_TEMPLATE/config.yml +6 -0
- vendor/aws/aws-php-sns-message-validator/.github/ISSUE_TEMPLATE/documentation.yml +23 -0
- vendor/aws/aws-php-sns-message-validator/.github/ISSUE_TEMPLATE/feature-request.yml +59 -0
- vendor/aws/aws-php-sns-message-validator/.github/PULL_REQUEST_TEMPLATE.md +6 -0
- vendor/aws/aws-php-sns-message-validator/.github/workflows/stale_issues.yml +45 -0
- vendor/aws/aws-php-sns-message-validator/.gitignore +10 -0
- vendor/aws/aws-php-sns-message-validator/.travis.yml +27 -0
- vendor/aws/aws-php-sns-message-validator/CODE_OF_CONDUCT.md +4 -0
- vendor/aws/aws-php-sns-message-validator/CONTRIBUTING.md +125 -0
- vendor/aws/aws-php-sns-message-validator/LICENSE.md +141 -0
- vendor/aws/aws-php-sns-message-validator/NOTICE.md +16 -0
- vendor/aws/aws-php-sns-message-validator/README.md +179 -0
- vendor/aws/aws-php-sns-message-validator/composer.json +37 -0
- vendor/aws/aws-php-sns-message-validator/phpunit.xml.dist +15 -0
- vendor/aws/aws-php-sns-message-validator/src/Exception/InvalidSnsMessageException.php +9 -0
- vendor/aws/aws-php-sns-message-validator/src/Message.php +161 -0
- vendor/aws/aws-php-sns-message-validator/src/MessageValidator.php +192 -0
- vendor/aws/aws-php-sns-message-validator/tests/FunctionalValidationsTest.php +148 -0
- vendor/aws/aws-php-sns-message-validator/tests/MessageTest.php +183 -0
- vendor/aws/aws-php-sns-message-validator/tests/MessageValidatorTest.php +209 -0
- vendor/aws/aws-php-sns-message-validator/tests/MockPhpStream.php +60 -0
- w3-total-cache-api.php +1 -1
- w3-total-cache.php +1 -1
Cache_File_Generic.php
CHANGED
@@ -203,6 +203,16 @@ class Cache_File_Generic extends Cache_File {
|
|
203 |
if ( !is_readable( $path ) )
|
204 |
return null;
|
205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
$fp = @fopen( $path, 'rb' );
|
207 |
if ( !$fp )
|
208 |
return null;
|
203 |
if ( !is_readable( $path ) )
|
204 |
return null;
|
205 |
|
206 |
+
// make sure reading from cache folder
|
207 |
+
// canonicalize to avoid unexpected variants
|
208 |
+
$base_path = realpath( $this->_cache_dir );
|
209 |
+
$path = realpath( $path );
|
210 |
+
|
211 |
+
if ( strlen( $base_path ) <= 0 ||
|
212 |
+
substr( $path, 0, strlen( $base_path ) ) != $base_path ) {
|
213 |
+
return null;
|
214 |
+
}
|
215 |
+
|
216 |
$fp = @fopen( $path, 'rb' );
|
217 |
if ( !$fp )
|
218 |
return null;
|
Cache_Redis.php
CHANGED
@@ -474,46 +474,87 @@ class Cache_Redis extends Cache_Base {
|
|
474 |
$server = $this->_servers[ $index ];
|
475 |
$accessor = new \Redis();
|
476 |
|
|
|
|
|
477 |
if ( substr( $server, 0, 5 ) === 'unix:' ) {
|
478 |
if ( $this->_persistent ) {
|
479 |
-
$
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
487 |
} else {
|
488 |
-
$
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
495 |
}
|
496 |
} else {
|
497 |
list( $ip, $port ) = Util_Content::endpoint_to_host_port( $server, null );
|
498 |
|
499 |
if ( $this->_persistent ) {
|
500 |
-
$
|
501 |
-
$
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
} else {
|
509 |
-
$
|
510 |
-
$
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
517 |
}
|
518 |
|
519 |
restore_error_handler();
|
474 |
$server = $this->_servers[ $index ];
|
475 |
$accessor = new \Redis();
|
476 |
|
477 |
+
$phpredis_modern = version_compare( phpversion( 'redis' ), '5', '>=' );
|
478 |
+
|
479 |
if ( substr( $server, 0, 5 ) === 'unix:' ) {
|
480 |
if ( $this->_persistent ) {
|
481 |
+
if ( $phpredis_modern ) {
|
482 |
+
$accessor->pconnect(
|
483 |
+
trim( substr( $server, 5 ) ),
|
484 |
+
null,
|
485 |
+
$this->_timeout,
|
486 |
+
$this->_instance_id . '_' . $this->_dbid,
|
487 |
+
$this->_retry_interval,
|
488 |
+
$this->_read_timeout
|
489 |
+
);
|
490 |
+
} else { // Old phpredis only supports a subset of parameters.
|
491 |
+
$accessor->pconnect(
|
492 |
+
trim( substr( $server, 5 ) ),
|
493 |
+
null,
|
494 |
+
$this->_timeout,
|
495 |
+
$this->_instance_id . '_' . $this->_dbid,
|
496 |
+
$this->_retry_interval
|
497 |
+
);
|
498 |
+
}
|
499 |
} else {
|
500 |
+
if ( $phpredis_modern ) {
|
501 |
+
$accessor->connect(
|
502 |
+
trim( substr( $server, 5 ) ),
|
503 |
+
$this->_timeout,
|
504 |
+
null,
|
505 |
+
$this->_retry_interval,
|
506 |
+
$this->_read_timeout
|
507 |
+
);
|
508 |
+
} else { // Old phpredis only supports a subset of parameters.
|
509 |
+
$accessor->connect(
|
510 |
+
trim( substr( $server, 5 ) ),
|
511 |
+
$this->_timeout,
|
512 |
+
null,
|
513 |
+
$this->_retry_interval
|
514 |
+
);
|
515 |
+
}
|
516 |
}
|
517 |
} else {
|
518 |
list( $ip, $port ) = Util_Content::endpoint_to_host_port( $server, null );
|
519 |
|
520 |
if ( $this->_persistent ) {
|
521 |
+
if ( $phpredis_modern ) {
|
522 |
+
$accessor->pconnect(
|
523 |
+
$ip,
|
524 |
+
$port,
|
525 |
+
$this->_timeout,
|
526 |
+
$this->_instance_id . '_' . $this->_dbid,
|
527 |
+
$this->_retry_interval,
|
528 |
+
$this->_read_timeout
|
529 |
+
);
|
530 |
+
} else { // Old phpredis only supports a subset of parameters.
|
531 |
+
$accessor->pconnect(
|
532 |
+
$ip,
|
533 |
+
$port,
|
534 |
+
$this->_timeout,
|
535 |
+
$this->_instance_id . '_' . $this->_dbid,
|
536 |
+
$this->_retry_interval
|
537 |
+
);
|
538 |
+
}
|
539 |
} else {
|
540 |
+
if ( $phpredis_modern ) {
|
541 |
+
$accessor->connect(
|
542 |
+
$ip,
|
543 |
+
$port,
|
544 |
+
$this->_timeout,
|
545 |
+
null,
|
546 |
+
$this->_retry_interval,
|
547 |
+
$this->_read_timeout
|
548 |
+
);
|
549 |
+
} else { // Old phpredis only supports a subset of parameters.
|
550 |
+
$accessor->connect(
|
551 |
+
$ip,
|
552 |
+
$port,
|
553 |
+
$this->_timeout,
|
554 |
+
null,
|
555 |
+
$this->_retry_interval
|
556 |
+
);
|
557 |
+
}
|
558 |
}
|
559 |
|
560 |
restore_error_handler();
|
CdnEngine_GoogleDrive.php
CHANGED
@@ -385,11 +385,7 @@ class CdnEngine_GoogleDrive extends CdnEngine_Base {
|
|
385 |
try {
|
386 |
try {
|
387 |
$listed_files = $this->_service->files->listFiles(
|
388 |
-
array(
|
389 |
-
'q' =>
|
390 |
-
'(' . join( $titles_filter, ' or ' ) . ') ' .
|
391 |
-
'and trashed = false'
|
392 |
-
)
|
393 |
);
|
394 |
} catch ( \W3TCG_Google_Auth_Exception $e ) {
|
395 |
if ( $allow_refresh_token )
|
385 |
try {
|
386 |
try {
|
387 |
$listed_files = $this->_service->files->listFiles(
|
388 |
+
array( 'q' => '(' . join( ' or ', $titles_filter ) . ') and trashed = false' )
|
|
|
|
|
|
|
|
|
389 |
);
|
390 |
} catch ( \W3TCG_Google_Auth_Exception $e ) {
|
391 |
if ( $allow_refresh_token )
|
Cdn_Core.php
CHANGED
@@ -564,6 +564,7 @@ class Cdn_Core {
|
|
564 |
'bucket_location' => $c->get_string( 'cdn.s3.bucket.location' ),
|
565 |
'cname' => $c->get_array( 'cdn.s3.cname' ),
|
566 |
'ssl' => $c->get_string( 'cdn.s3.ssl' ),
|
|
|
567 |
'compression' => $compression
|
568 |
);
|
569 |
break;
|
564 |
'bucket_location' => $c->get_string( 'cdn.s3.bucket.location' ),
|
565 |
'cname' => $c->get_array( 'cdn.s3.cname' ),
|
566 |
'ssl' => $c->get_string( 'cdn.s3.ssl' ),
|
567 |
+
'public_objects' => $c->get_string( 'cdn.s3.public_objects' ),
|
568 |
'compression' => $compression
|
569 |
);
|
570 |
break;
|
Cdn_Plugin.php
CHANGED
@@ -96,6 +96,9 @@ class Cdn_Plugin {
|
|
96 |
if ( !is_admin() || $this->_config->get_boolean( 'cdn.admin.media_library' ) ) {
|
97 |
add_filter( 'wp_prepare_attachment_for_js',
|
98 |
array( $this, 'wp_prepare_attachment_for_js' ), 0 );
|
|
|
|
|
|
|
99 |
}
|
100 |
|
101 |
/**
|
@@ -743,6 +746,33 @@ class Cdn_Plugin {
|
|
743 |
return $url;
|
744 |
}
|
745 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
746 |
/**
|
747 |
* Mutate http/2 header links
|
748 |
*/
|
96 |
if ( !is_admin() || $this->_config->get_boolean( 'cdn.admin.media_library' ) ) {
|
97 |
add_filter( 'wp_prepare_attachment_for_js',
|
98 |
array( $this, 'wp_prepare_attachment_for_js' ), 0 );
|
99 |
+
|
100 |
+
add_filter( 'wp_get_attachment_image_src',
|
101 |
+
array( $this, 'wp_get_attachment_image_src' ), 0 );
|
102 |
}
|
103 |
|
104 |
/**
|
746 |
return $url;
|
747 |
}
|
748 |
|
749 |
+
/**
|
750 |
+
* Adjusts attachment image src to cdn. This is for those who rely on
|
751 |
+
* wp_get_attachment_image_src()
|
752 |
+
*
|
753 |
+
* @param array $image Image object
|
754 |
+
* @return array
|
755 |
+
*/
|
756 |
+
function wp_get_attachment_image_src( $image ) {
|
757 |
+
$url = empty( $image[0] ) ? null : trim( $image[0] );
|
758 |
+
|
759 |
+
if ( ! empty( $url ) ) {
|
760 |
+
$parsed = parse_url( $url );
|
761 |
+
$uri = ( isset( $parsed['path'] ) ? $parsed['path'] : '/' ) . ( isset( $parsed['query'] ) ? '?' . $parsed['query'] : '' );
|
762 |
+
$wp_upload_dir = wp_upload_dir();
|
763 |
+
$upload_base_url = $wp_upload_dir['baseurl'];
|
764 |
+
if ( substr( $url, 0, strlen( $upload_base_url ) ) === $upload_base_url ) {
|
765 |
+
$common = Dispatcher::component( 'Cdn_Core' );
|
766 |
+
$new_url = $common->url_to_cdn_url( $url, $uri );
|
767 |
+
if ( ! is_null( $new_url ) ) {
|
768 |
+
$image[0] = $new_url;
|
769 |
+
}
|
770 |
+
}
|
771 |
+
}
|
772 |
+
|
773 |
+
return $image;
|
774 |
+
}
|
775 |
+
|
776 |
/**
|
777 |
* Mutate http/2 header links
|
778 |
*/
|
ConfigCache.php
CHANGED
@@ -82,6 +82,15 @@ class ConfigCache {
|
|
82 |
'password' =>
|
83 |
( defined( 'W3TC_CONFIG_CACHE_REDIS_PASSWORD' ) ?
|
84 |
W3TC_CONFIG_CACHE_REDIS_PASSWORD : '' ),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
'key_version_mode' => 'disabled'
|
86 |
);
|
87 |
break;
|
82 |
'password' =>
|
83 |
( defined( 'W3TC_CONFIG_CACHE_REDIS_PASSWORD' ) ?
|
84 |
W3TC_CONFIG_CACHE_REDIS_PASSWORD : '' ),
|
85 |
+
'timeout' =>
|
86 |
+
( defined( 'W3TC_CONFIG_CACHE_REDIS_TIMEOUT' ) ?
|
87 |
+
W3TC_CONFIG_CACHE_REDIS_TIMEOUT : 0 ),
|
88 |
+
'retry_interval' =>
|
89 |
+
( defined( 'W3TC_CONFIG_CACHE_REDIS_RETRY_INTERVAL' ) ?
|
90 |
+
W3TC_CONFIG_CACHE_REDIS_RETRY_INTERVAL : 0 ),
|
91 |
+
'read_timeout' =>
|
92 |
+
( defined( 'W3TC_CONFIG_CACHE_REDIS_READ_TIMEOUT' ) ?
|
93 |
+
W3TC_CONFIG_CACHE_REDIS_READ_TIMEOUT : 0 ),
|
94 |
'key_version_mode' => 'disabled'
|
95 |
);
|
96 |
break;
|
ConfigKeys.php
CHANGED
@@ -1368,6 +1368,10 @@ $keys = array(
|
|
1368 |
'type' => 'string',
|
1369 |
'default' => 'auto'
|
1370 |
),
|
|
|
|
|
|
|
|
|
1371 |
|
1372 |
'cdn.s3_compatible.api_host' => array(
|
1373 |
'type' => 'string',
|
1368 |
'type' => 'string',
|
1369 |
'default' => 'auto'
|
1370 |
),
|
1371 |
+
'cdn.s3.public_objects' => array(
|
1372 |
+
'type' => 'string',
|
1373 |
+
'default' => 'enabled',
|
1374 |
+
),
|
1375 |
|
1376 |
'cdn.s3_compatible.api_host' => array(
|
1377 |
'type' => 'string',
|
DbCache_WpdbInjection_QueryCaching.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
*
|
5 |
* @package W3TC
|
6 |
*
|
7 |
-
* phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
|
8 |
*/
|
9 |
|
10 |
namespace W3TC;
|
@@ -14,60 +14,63 @@ namespace W3TC;
|
|
14 |
*/
|
15 |
class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
16 |
/**
|
17 |
-
* Queries total
|
18 |
*
|
19 |
-
* @var
|
20 |
*/
|
21 |
-
|
22 |
|
23 |
/**
|
24 |
-
* Query cache hits
|
25 |
*
|
26 |
-
* @var
|
27 |
*/
|
28 |
-
|
29 |
|
30 |
/**
|
31 |
-
* Query cache misses
|
32 |
*
|
33 |
-
* @var
|
34 |
*/
|
35 |
-
|
|
|
36 |
/**
|
37 |
-
*
|
|
|
|
|
38 |
*/
|
39 |
-
|
40 |
|
41 |
/**
|
42 |
-
*
|
43 |
-
*
|
44 |
-
* @var integer
|
45 |
*/
|
46 |
-
|
47 |
|
48 |
/**
|
49 |
-
*
|
|
|
|
|
50 |
*/
|
51 |
-
|
52 |
|
53 |
/**
|
54 |
-
*
|
55 |
*
|
56 |
-
* @var
|
57 |
*/
|
58 |
-
|
59 |
|
60 |
/**
|
61 |
-
* Request-global cache reject reason
|
62 |
-
* null until filled
|
63 |
*
|
64 |
* @var string
|
65 |
*/
|
66 |
private $cache_reject_reason = null;
|
67 |
|
68 |
/**
|
69 |
-
* Request-global check reject scope
|
70 |
-
* false until set
|
71 |
*
|
72 |
* @var bool
|
73 |
*/
|
@@ -79,43 +82,42 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
79 |
private $log_filehandle = false;
|
80 |
|
81 |
/**
|
82 |
-
* Result of check if caching is possible at the level of current http request
|
83 |
-
* null until filled
|
|
|
|
|
84 |
*/
|
85 |
private $can_cache_once_per_request_result = null;
|
86 |
|
87 |
-
|
88 |
-
*
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
$c
|
95 |
-
$this->
|
96 |
-
$this->_lifetime = $c->get_integer( 'dbcache.lifetime' );
|
97 |
-
$this->debug = $c->get_boolean( 'dbcache.debug' );
|
98 |
-
$this->reject_logged = $c->get_boolean( 'dbcache.reject.logged' );
|
99 |
$this->reject_constants = $c->get_array( 'dbcache.reject.constants' );
|
100 |
-
$this->use_filters
|
101 |
}
|
102 |
|
103 |
/**
|
104 |
-
* Executes query
|
105 |
*
|
106 |
-
* @param string
|
107 |
-
* @return
|
108 |
*/
|
109 |
-
function query( $query ) {
|
110 |
-
if (
|
111 |
return $this->next_injection->query( $query );
|
112 |
}
|
113 |
|
114 |
-
$reject_reason
|
115 |
-
$is_cache_hit
|
116 |
-
$data
|
117 |
-
$time_total
|
118 |
-
$group
|
119 |
$flush_after_query = false;
|
120 |
|
121 |
$this->query_total++;
|
@@ -135,19 +137,20 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
135 |
}
|
136 |
|
137 |
if ( $this->use_filters && function_exists( 'apply_filters' ) ) {
|
138 |
-
$reject_reason = apply_filters(
|
139 |
-
|
|
|
|
|
|
|
140 |
|
141 |
$caching = empty( $reject_reason );
|
142 |
}
|
143 |
|
144 |
if ( $caching ) {
|
145 |
$this->wpdb_mixin->timer_start();
|
146 |
-
|
147 |
-
$
|
148 |
-
$
|
149 |
-
$data = $cache->get( md5( $query ), $group );
|
150 |
-
|
151 |
$time_total = $this->wpdb_mixin->timer_stop();
|
152 |
}
|
153 |
|
@@ -155,13 +158,12 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
155 |
$is_cache_hit = true;
|
156 |
$this->query_hits++;
|
157 |
|
158 |
-
$this->wpdb_mixin->last_error
|
159 |
-
$this->wpdb_mixin->last_query
|
160 |
$this->wpdb_mixin->last_result = $data['last_result'];
|
161 |
-
$this->wpdb_mixin->col_info
|
162 |
-
$this->wpdb_mixin->num_rows
|
163 |
-
|
164 |
-
$return_val = $data['return_val'];
|
165 |
} else {
|
166 |
$this->query_misses++;
|
167 |
|
@@ -172,28 +174,30 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
172 |
if ( $flush_after_query ) {
|
173 |
$group = $this->_get_group( $query );
|
174 |
|
175 |
-
$this->_flush_cache_for_sql_group(
|
176 |
-
|
|
|
|
|
177 |
}
|
178 |
|
179 |
if ( $caching ) {
|
180 |
$data = array(
|
181 |
-
'last_error'
|
182 |
-
'last_query'
|
183 |
'last_result' => $this->wpdb_mixin->last_result,
|
184 |
-
'col_info'
|
185 |
-
'num_rows'
|
186 |
-
'return_val'
|
187 |
);
|
188 |
|
189 |
$cache = $this->_get_cache();
|
190 |
$group = $this->_get_group( $query );
|
191 |
|
192 |
$filter_data = array(
|
193 |
-
'query'
|
194 |
-
'group'
|
195 |
-
'content'
|
196 |
-
'expiration' => $this->_lifetime
|
197 |
);
|
198 |
|
199 |
if ( $this->use_filters && function_exists( 'apply_filters' ) ) {
|
@@ -215,7 +219,7 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
215 |
gmdate( 'r' ),
|
216 |
strtr(
|
217 |
isset( $_SERVER['REQUEST_URI'] ) ?
|
218 |
-
|
219 |
"<>\r\n",
|
220 |
'.. '
|
221 |
),
|
@@ -234,98 +238,131 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
234 |
return $return_val;
|
235 |
}
|
236 |
|
237 |
-
|
|
|
|
|
|
|
|
|
|
|
238 |
return $this->next_injection->_escape( $data );
|
239 |
}
|
240 |
|
241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
return $this->next_injection->prepare( $query, $args );
|
243 |
}
|
244 |
|
245 |
/**
|
246 |
-
* Initializes object, calls underlying processor
|
247 |
*/
|
248 |
-
function initialize() {
|
249 |
return $this->next_injection->initialize();
|
250 |
}
|
251 |
|
252 |
/**
|
253 |
* Insert a row into a table.
|
254 |
*
|
255 |
-
* @param string
|
256 |
-
* @param array
|
257 |
-
* @param array|string $format
|
258 |
* @return int|false
|
259 |
*/
|
260 |
-
function insert( $table, $data, $format = null ) {
|
261 |
return $this->next_injection->insert( $table, $data, $format );
|
262 |
}
|
263 |
|
264 |
/**
|
265 |
* Replace a row into a table.
|
266 |
*
|
267 |
-
* @param string
|
268 |
-
* @param array
|
269 |
-
* @param array|string $format
|
270 |
* @return int|false
|
271 |
*/
|
272 |
-
function replace( $table, $data, $format = null ) {
|
273 |
$group = $this->_get_group( $table );
|
274 |
-
$this->_flush_cache_for_sql_group(
|
275 |
-
|
|
|
|
|
|
|
276 |
return $this->next_injection->replace( $table, $data, $format );
|
277 |
}
|
278 |
|
279 |
/**
|
280 |
* Update a row in the table
|
281 |
*
|
282 |
-
* @param string
|
283 |
-
* @param array
|
284 |
-
* @param array
|
285 |
-
* @param array|string $format
|
286 |
-
* @param array|string $
|
287 |
* @return int|false
|
288 |
*/
|
289 |
-
function update( $table, $data, $where, $format = null, $where_format = null ) {
|
290 |
$group = $this->_get_group( $table );
|
291 |
$this->_flush_cache_for_sql_group( $group, array( 'wpdb_update' => $table ) );
|
292 |
return $this->next_injection->update( $table, $data, $where, $format, $where_format );
|
293 |
}
|
294 |
|
295 |
/**
|
296 |
-
* Deletes from table
|
|
|
|
|
|
|
|
|
297 |
*/
|
298 |
-
function delete( $table, $where, $where_format = null ) {
|
299 |
$group = $this->_get_group( $table );
|
300 |
$this->_flush_cache_for_sql_group( $group, array( 'wpdb_delete' => $table ) );
|
301 |
return $this->next_injection->delete( $table, $where, $where_format );
|
302 |
}
|
303 |
|
304 |
/**
|
305 |
-
* Flushes cache
|
306 |
*
|
307 |
-
* @
|
|
|
308 |
*/
|
309 |
-
function flush_cache( $extras = array() ) {
|
310 |
return $this->_flush_cache_for_sql_group( 'remaining', $extras );
|
311 |
}
|
312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
private function _flush_cache_for_sql_group( $group, $extras = array() ) {
|
314 |
$this->wpdb_mixin->timer_start();
|
315 |
|
316 |
if ( $this->debug ) {
|
317 |
-
$filename = Util_Debug::log(
|
|
|
318 |
'flushing based on sqlquery group ' . $group .
|
319 |
-
' with extras ' . json_encode( $extras )
|
|
|
320 |
}
|
321 |
if ( $this->_config->get_boolean( 'dbcache.debug_purge' ) ) {
|
322 |
-
Util_Debug::log_purge(
|
323 |
-
|
|
|
|
|
|
|
324 |
}
|
325 |
|
326 |
-
$cache
|
327 |
$flush_groups = $this->_get_flush_groups( $group, $extras );
|
328 |
-
$v
|
329 |
|
330 |
$this->cache_flushes++;
|
331 |
|
@@ -342,94 +379,94 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
342 |
}
|
343 |
|
344 |
/**
|
345 |
-
* Returns cache object
|
346 |
*
|
347 |
* @return W3_Cache_Base
|
348 |
*/
|
349 |
-
function _get_cache() {
|
350 |
static $cache = array();
|
351 |
|
352 |
-
if ( !isset( $cache[0] ) ) {
|
353 |
$engine = $this->_config->get_string( 'dbcache.engine' );
|
354 |
|
355 |
switch ( $engine ) {
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
}
|
392 |
-
$
|
393 |
-
$
|
394 |
-
$
|
395 |
|
396 |
-
$cache[0] = Cache::instance( $engine, $
|
397 |
}
|
398 |
|
399 |
return $cache[0];
|
400 |
}
|
401 |
|
402 |
/**
|
403 |
-
* Check if can cache sql
|
404 |
*
|
405 |
-
* @param string
|
406 |
-
* @param string
|
407 |
* @return boolean
|
408 |
*/
|
409 |
-
function _can_cache( $sql, &$cache_reject_reason ) {
|
410 |
/**
|
411 |
* Skip if request-wide reject reason specified.
|
412 |
-
* Note - as a result requedt-wide checks are done only once per request
|
413 |
*/
|
414 |
-
if ( !is_null( $this->cache_reject_reason ) ) {
|
415 |
-
$cache_reject_reason
|
416 |
$this->cache_reject_request_wide = true;
|
417 |
return false;
|
418 |
}
|
419 |
|
420 |
/**
|
421 |
-
* Do once-per-request check if needed
|
422 |
*/
|
423 |
if ( is_null( $this->can_cache_once_per_request_result ) ) {
|
424 |
$this->can_cache_once_per_request_result = $this->_can_cache_once_per_request();
|
425 |
-
if (
|
426 |
$this->cache_reject_request_wide = true;
|
427 |
return false;
|
428 |
}
|
429 |
}
|
430 |
|
431 |
/**
|
432 |
-
* Check for constants
|
433 |
*/
|
434 |
foreach ( $this->reject_constants as $name ) {
|
435 |
if ( defined( $name ) && constant( $name ) ) {
|
@@ -441,12 +478,13 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
441 |
}
|
442 |
|
443 |
/**
|
444 |
-
* Check for AJAX requests
|
445 |
*/
|
446 |
$ajax_skip = false;
|
|
|
447 |
if ( defined( 'DOING_AJAX' ) ) {
|
448 |
$http_referer = isset( $_SERVER['HTTP_REFERER'] ) ?
|
449 |
-
filter_var(
|
450 |
|
451 |
// wp_admin is always defined for ajax requests, check by referrer.
|
452 |
if ( strpos( $http_referer, '/wp-admin/' ) === false ) {
|
@@ -455,28 +493,28 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
455 |
}
|
456 |
|
457 |
/**
|
458 |
-
* Skip if admin
|
459 |
*/
|
460 |
-
if ( defined( 'WP_ADMIN' ) &&
|
461 |
$this->cache_reject_reason = 'WP_ADMIN';
|
462 |
-
$cache_reject_reason
|
463 |
|
464 |
return false;
|
465 |
}
|
466 |
|
467 |
/**
|
468 |
-
* Skip if SQL is rejected
|
469 |
*/
|
470 |
-
if (
|
471 |
$cache_reject_reason = 'query not cacheable';
|
472 |
|
473 |
return false;
|
474 |
}
|
475 |
|
476 |
/**
|
477 |
-
* Skip if user is logged in
|
478 |
*/
|
479 |
-
if ( $this->reject_logged &&
|
480 |
$this->cache_reject_reason = 'user.logged_in';
|
481 |
$cache_reject_reason = $this->cache_reject_reason;
|
482 |
|
@@ -487,15 +525,15 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
487 |
}
|
488 |
|
489 |
/**
|
490 |
-
* Check if can cache sql, checks which have constant results during whole request
|
491 |
*
|
492 |
-
* @return
|
493 |
*/
|
494 |
-
function _can_cache_once_per_request() {
|
495 |
/**
|
496 |
* Skip if disabled
|
497 |
*/
|
498 |
-
if (
|
499 |
$this->cache_reject_reason = 'dbcache.disabled';
|
500 |
|
501 |
return false;
|
@@ -504,7 +542,7 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
504 |
/**
|
505 |
* Skip if request URI is rejected
|
506 |
*/
|
507 |
-
if (
|
508 |
$this->cache_reject_reason = 'request';
|
509 |
return false;
|
510 |
}
|
@@ -512,7 +550,7 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
512 |
/**
|
513 |
* Skip if cookie is rejected
|
514 |
*/
|
515 |
-
if (
|
516 |
$this->cache_reject_reason = 'cookie';
|
517 |
return false;
|
518 |
}
|
@@ -523,10 +561,10 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
523 |
/**
|
524 |
* Check SQL
|
525 |
*
|
526 |
-
* @param string
|
527 |
-
* @return
|
528 |
*/
|
529 |
-
function _check_sql( $sql ) {
|
530 |
|
531 |
$auto_reject_strings = $this->_config->get_array( 'dbcache.reject.words' );
|
532 |
|
@@ -539,7 +577,7 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
539 |
foreach ( $reject_sql as $expr ) {
|
540 |
$expr = trim( $expr );
|
541 |
$expr = str_replace( '{prefix}', $this->wpdb_mixin->prefix, $expr );
|
542 |
-
if ( $expr
|
543 |
return false;
|
544 |
}
|
545 |
}
|
@@ -552,14 +590,14 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
552 |
*
|
553 |
* @return boolean
|
554 |
*/
|
555 |
-
function _check_request_uri() {
|
556 |
$auto_reject_uri = array(
|
557 |
'wp-login',
|
558 |
'wp-register',
|
559 |
);
|
560 |
|
561 |
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ?
|
562 |
-
|
563 |
|
564 |
foreach ( $auto_reject_uri as $uri ) {
|
565 |
if ( strstr( $request_uri, $uri ) !== false ) {
|
@@ -572,7 +610,7 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
572 |
|
573 |
foreach ( $reject_uri as $expr ) {
|
574 |
$expr = trim( $expr );
|
575 |
-
if (
|
576 |
return false;
|
577 |
}
|
578 |
}
|
@@ -581,13 +619,13 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
581 |
}
|
582 |
|
583 |
/**
|
584 |
-
* Checks for WordPress cookies
|
585 |
*
|
586 |
-
* @return
|
587 |
*/
|
588 |
-
function _check_cookies() {
|
589 |
foreach ( array_keys( $_COOKIE ) as $cookie_name ) {
|
590 |
-
if (
|
591 |
continue;
|
592 |
}
|
593 |
if ( preg_match( '/^wp-postpass|^comment_author/', $cookie_name ) ) {
|
@@ -607,25 +645,33 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
607 |
}
|
608 |
|
609 |
/**
|
610 |
-
* Check if user is logged in
|
611 |
*
|
612 |
-
* @return
|
613 |
*/
|
614 |
-
function _check_logged_in() {
|
615 |
foreach ( array_keys( $_COOKIE ) as $cookie_name ) {
|
616 |
-
if ( strpos( $cookie_name, 'wordpress_logged_in' ) === 0 )
|
617 |
return false;
|
|
|
618 |
}
|
619 |
|
620 |
return true;
|
621 |
}
|
622 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
623 |
private function _get_group( $sql ) {
|
624 |
$sql = strtolower( $sql );
|
625 |
|
626 |
-
//
|
627 |
-
if ( preg_match_all(
|
628 |
-
'~(^|[\s,`])' . $this->wpdb_mixin->prefix . '([0-9a-zA-Z_]+)~i', $sql, $m ) ) {
|
629 |
$tables = array_unique( $m[2] );
|
630 |
} else {
|
631 |
$tables = array();
|
@@ -633,11 +679,10 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
633 |
|
634 |
if ( $this->contains_only_tables( $tables, array( 'options' => '*' ) ) ) {
|
635 |
$group = 'options';
|
636 |
-
} elseif ( $this->contains_only_tables( $tables, array(
|
637 |
-
'comments' => '*', 'commentsmeta' => '*' ) ) ) {
|
638 |
$group = 'comments';
|
639 |
} elseif ( count( $tables ) <= 1 ) {
|
640 |
-
$group = 'singletables'; //
|
641 |
} else {
|
642 |
$group = 'remaining';
|
643 |
}
|
@@ -649,13 +694,21 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
649 |
return $group;
|
650 |
}
|
651 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
652 |
private function contains_only_tables( $tables, $allowed ) {
|
653 |
if ( empty( $tables ) ) {
|
654 |
return false;
|
655 |
}
|
656 |
|
657 |
foreach ( $tables as $t ) {
|
658 |
-
if ( !isset( $allowed[$t] ) ) {
|
659 |
return false;
|
660 |
}
|
661 |
}
|
@@ -663,89 +716,112 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
663 |
return true;
|
664 |
}
|
665 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
666 |
private function _get_flush_groups( $group, $extras = array() ) {
|
667 |
$groups_to_flush = array();
|
668 |
|
669 |
switch ( $group ) {
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
}
|
693 |
|
694 |
if ( $this->use_filters && function_exists( 'apply_filters' ) ) {
|
695 |
-
$groups_to_flush = apply_filters( 'w3tc_dbcache_get_flush_groups',
|
696 |
-
$groups_to_flush, $group, $extras );
|
697 |
}
|
698 |
|
699 |
return $groups_to_flush;
|
700 |
}
|
701 |
|
|
|
|
|
|
|
|
|
|
|
702 |
public function get_reject_reason() {
|
703 |
-
if ( is_null( $this->cache_reject_reason ) )
|
704 |
return '';
|
|
|
|
|
705 |
$request_wide_string = $this->cache_reject_request_wide ?
|
706 |
( function_exists( '__' ) ? __( 'Request-wide', 'w3-total-cache' ).' ' : 'Request ' ) : '';
|
|
|
707 |
return $request_wide_string . $this->_get_reject_reason_message( $this->cache_reject_reason );
|
708 |
}
|
709 |
|
710 |
/**
|
|
|
711 |
*
|
712 |
-
*
|
713 |
-
* @param unknown $key
|
714 |
* @return string|void
|
715 |
*/
|
716 |
private function _get_reject_reason_message( $key ) {
|
717 |
-
if ( !function_exists( '__' ) )
|
718 |
return $key;
|
|
|
|
|
719 |
switch ( $key ) {
|
720 |
-
|
721 |
return __( 'Database caching is disabled', 'w3-total-cache' );
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
}
|
747 |
}
|
748 |
|
|
|
|
|
|
|
|
|
|
|
|
|
749 |
public function w3tc_footer_comment( $strings ) {
|
750 |
$reject_reason = $this->get_reject_reason();
|
751 |
$append = empty( $reject_reason ) ? '' : sprintf( ' (%1$s)', $reject_reason );
|
@@ -778,12 +854,18 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
778 |
}
|
779 |
|
780 |
if ( $this->log_filehandle ) {
|
781 |
-
fclose( $this->log_filehandle );
|
782 |
$this->log_filehandle = false;
|
783 |
}
|
784 |
return $strings;
|
785 |
}
|
786 |
|
|
|
|
|
|
|
|
|
|
|
|
|
787 |
public function w3tc_usage_statistics_of_request( $storage ) {
|
788 |
$storage->counter_add( 'dbcache_calls_total', $this->query_total );
|
789 |
$storage->counter_add( 'dbcache_calls_hits', $this->query_hits );
|
@@ -792,12 +874,20 @@ class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
|
792 |
$storage->counter_add( 'dbcache_time_ms', $time_ms );
|
793 |
}
|
794 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
795 |
private function log_query( $line ) {
|
796 |
-
if (
|
797 |
$filename = Util_Debug::log_filename( 'dbcache-queries' );
|
798 |
-
$this->log_filehandle = fopen( $filename, 'a' );
|
799 |
}
|
800 |
|
801 |
-
fputcsv
|
802 |
}
|
803 |
}
|
4 |
*
|
5 |
* @package W3TC
|
6 |
*
|
7 |
+
* phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize, PSR2.Methods.MethodDeclaration.Underscore, PSR2.Classes.PropertyDeclaration.Underscore
|
8 |
*/
|
9 |
|
10 |
namespace W3TC;
|
14 |
*/
|
15 |
class DbCache_WpdbInjection_QueryCaching extends DbCache_WpdbInjection {
|
16 |
/**
|
17 |
+
* Queries total.
|
18 |
*
|
19 |
+
* @var int
|
20 |
*/
|
21 |
+
public $query_total = 0;
|
22 |
|
23 |
/**
|
24 |
+
* Query cache hits.
|
25 |
*
|
26 |
+
* @var int
|
27 |
*/
|
28 |
+
public $query_hits = 0;
|
29 |
|
30 |
/**
|
31 |
+
* Query cache misses.
|
32 |
*
|
33 |
+
* @var int
|
34 |
*/
|
35 |
+
public $query_misses = 0;
|
36 |
+
|
37 |
/**
|
38 |
+
* Time total taken by queries, in microsecs.
|
39 |
+
*
|
40 |
+
* @var int
|
41 |
*/
|
42 |
+
public $time_total = 0;
|
43 |
|
44 |
/**
|
45 |
+
* Config.
|
|
|
|
|
46 |
*/
|
47 |
+
public $_config = null;
|
48 |
|
49 |
/**
|
50 |
+
* Lifetime.
|
51 |
+
*
|
52 |
+
* @var int
|
53 |
*/
|
54 |
+
public $_lifetime = null;
|
55 |
|
56 |
/**
|
57 |
+
* Number of cache flushes during http request processing.
|
58 |
*
|
59 |
+
* @var int
|
60 |
*/
|
61 |
+
private $cache_flushes = 0;
|
62 |
|
63 |
/**
|
64 |
+
* Request-global cache reject reason.
|
65 |
+
* null until filled.
|
66 |
*
|
67 |
* @var string
|
68 |
*/
|
69 |
private $cache_reject_reason = null;
|
70 |
|
71 |
/**
|
72 |
+
* Request-global check reject scope.
|
73 |
+
* false until set.
|
74 |
*
|
75 |
* @var bool
|
76 |
*/
|
82 |
private $log_filehandle = false;
|
83 |
|
84 |
/**
|
85 |
+
* Result of check if caching is possible at the level of current http request.
|
86 |
+
* null until filled.
|
87 |
+
*
|
88 |
+
* @var bool
|
89 |
*/
|
90 |
private $can_cache_once_per_request_result = null;
|
91 |
|
92 |
+
/**
|
93 |
+
* Constructor.
|
94 |
+
*/
|
95 |
+
public function __construct() {
|
96 |
+
$c = Dispatcher::config();
|
97 |
+
$this->_config = $c;
|
98 |
+
$this->_lifetime = $c->get_integer( 'dbcache.lifetime' );
|
99 |
+
$this->debug = $c->get_boolean( 'dbcache.debug' );
|
100 |
+
$this->reject_logged = $c->get_boolean( 'dbcache.reject.logged' );
|
|
|
|
|
|
|
101 |
$this->reject_constants = $c->get_array( 'dbcache.reject.constants' );
|
102 |
+
$this->use_filters = $this->_config->get_boolean( 'dbcache.use_filters' );
|
103 |
}
|
104 |
|
105 |
/**
|
106 |
+
* Executes query.
|
107 |
*
|
108 |
+
* @param string $query Query.
|
109 |
+
* @return int
|
110 |
*/
|
111 |
+
public function query( $query ) {
|
112 |
+
if ( ! $this->wpdb_mixin->ready ) {
|
113 |
return $this->next_injection->query( $query );
|
114 |
}
|
115 |
|
116 |
+
$reject_reason = '';
|
117 |
+
$is_cache_hit = false;
|
118 |
+
$data = false;
|
119 |
+
$time_total = 0;
|
120 |
+
$group = '';
|
121 |
$flush_after_query = false;
|
122 |
|
123 |
$this->query_total++;
|
137 |
}
|
138 |
|
139 |
if ( $this->use_filters && function_exists( 'apply_filters' ) ) {
|
140 |
+
$reject_reason = apply_filters(
|
141 |
+
'w3tc_dbcache_can_cache_sql',
|
142 |
+
( $caching ? '' : $reject_reason ),
|
143 |
+
$query
|
144 |
+
);
|
145 |
|
146 |
$caching = empty( $reject_reason );
|
147 |
}
|
148 |
|
149 |
if ( $caching ) {
|
150 |
$this->wpdb_mixin->timer_start();
|
151 |
+
$cache = $this->_get_cache();
|
152 |
+
$group = $this->_get_group( $query );
|
153 |
+
$data = $cache->get( md5( $query ), $group );
|
|
|
|
|
154 |
$time_total = $this->wpdb_mixin->timer_stop();
|
155 |
}
|
156 |
|
158 |
$is_cache_hit = true;
|
159 |
$this->query_hits++;
|
160 |
|
161 |
+
$this->wpdb_mixin->last_error = $data['last_error'];
|
162 |
+
$this->wpdb_mixin->last_query = $data['last_query'];
|
163 |
$this->wpdb_mixin->last_result = $data['last_result'];
|
164 |
+
$this->wpdb_mixin->col_info = $data['col_info'];
|
165 |
+
$this->wpdb_mixin->num_rows = $data['num_rows'];
|
166 |
+
$return_val = $data['return_val'];
|
|
|
167 |
} else {
|
168 |
$this->query_misses++;
|
169 |
|
174 |
if ( $flush_after_query ) {
|
175 |
$group = $this->_get_group( $query );
|
176 |
|
177 |
+
$this->_flush_cache_for_sql_group(
|
178 |
+
$group,
|
179 |
+
array( 'modification_query' => $query )
|
180 |
+
);
|
181 |
}
|
182 |
|
183 |
if ( $caching ) {
|
184 |
$data = array(
|
185 |
+
'last_error' => $this->wpdb_mixin->last_error,
|
186 |
+
'last_query' => $this->wpdb_mixin->last_query,
|
187 |
'last_result' => $this->wpdb_mixin->last_result,
|
188 |
+
'col_info' => $this->wpdb_mixin->col_info,
|
189 |
+
'num_rows' => $this->wpdb_mixin->num_rows,
|
190 |
+
'return_val' => $return_val,
|
191 |
);
|
192 |
|
193 |
$cache = $this->_get_cache();
|
194 |
$group = $this->_get_group( $query );
|
195 |
|
196 |
$filter_data = array(
|
197 |
+
'query' => $query,
|
198 |
+
'group' => $group,
|
199 |
+
'content' => $data,
|
200 |
+
'expiration' => $this->_lifetime,
|
201 |
);
|
202 |
|
203 |
if ( $this->use_filters && function_exists( 'apply_filters' ) ) {
|
219 |
gmdate( 'r' ),
|
220 |
strtr(
|
221 |
isset( $_SERVER['REQUEST_URI'] ) ?
|
222 |
+
esc_url_raw( stripslashes( $_SERVER['REQUEST_URI'] ) ) : '', // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
|
223 |
"<>\r\n",
|
224 |
'.. '
|
225 |
),
|
238 |
return $return_val;
|
239 |
}
|
240 |
|
241 |
+
/**
|
242 |
+
* Escape.
|
243 |
+
*
|
244 |
+
* @param array $data Data.
|
245 |
+
*/
|
246 |
+
public function _escape( $data ) {
|
247 |
return $this->next_injection->_escape( $data );
|
248 |
}
|
249 |
|
250 |
+
/**
|
251 |
+
* Prepare.
|
252 |
+
*
|
253 |
+
* @param string $query Query.
|
254 |
+
* @param array $args Arguments.
|
255 |
+
*/
|
256 |
+
public function prepare( $query, $args ) {
|
257 |
return $this->next_injection->prepare( $query, $args );
|
258 |
}
|
259 |
|
260 |
/**
|
261 |
+
* Initializes object, calls underlying processor.
|
262 |
*/
|
263 |
+
public function initialize() {
|
264 |
return $this->next_injection->initialize();
|
265 |
}
|
266 |
|
267 |
/**
|
268 |
* Insert a row into a table.
|
269 |
*
|
270 |
+
* @param string $table Table.
|
271 |
+
* @param array $data Data.
|
272 |
+
* @param array|string $format Format.
|
273 |
* @return int|false
|
274 |
*/
|
275 |
+
public function insert( $table, $data, $format = null ) {
|
276 |
return $this->next_injection->insert( $table, $data, $format );
|
277 |
}
|
278 |
|
279 |
/**
|
280 |
* Replace a row into a table.
|
281 |
*
|
282 |
+
* @param string $table Table.
|
283 |
+
* @param array $data Data.
|
284 |
+
* @param array|string $format Format.
|
285 |
* @return int|false
|
286 |
*/
|
287 |
+
public function replace( $table, $data, $format = null ) {
|
288 |
$group = $this->_get_group( $table );
|
289 |
+
$this->_flush_cache_for_sql_group(
|
290 |
+
$group,
|
291 |
+
array( 'wpdb_replace' => $table )
|
292 |
+
);
|
293 |
+
|
294 |
return $this->next_injection->replace( $table, $data, $format );
|
295 |
}
|
296 |
|
297 |
/**
|
298 |
* Update a row in the table
|
299 |
*
|
300 |
+
* @param string $table Table.
|
301 |
+
* @param array $data Data.
|
302 |
+
* @param array $where Where.
|
303 |
+
* @param array|string $format Format.
|
304 |
+
* @param array|string $where_format Format where.
|
305 |
* @return int|false
|
306 |
*/
|
307 |
+
public function update( $table, $data, $where, $format = null, $where_format = null ) {
|
308 |
$group = $this->_get_group( $table );
|
309 |
$this->_flush_cache_for_sql_group( $group, array( 'wpdb_update' => $table ) );
|
310 |
return $this->next_injection->update( $table, $data, $where, $format, $where_format );
|
311 |
}
|
312 |
|
313 |
/**
|
314 |
+
* Deletes from table.
|
315 |
+
*
|
316 |
+
* @param string $table Table.
|
317 |
+
* @param array $where Where.
|
318 |
+
* @param array|string $where_format Format where.
|
319 |
*/
|
320 |
+
public function delete( $table, $where, $where_format = null ) {
|
321 |
$group = $this->_get_group( $table );
|
322 |
$this->_flush_cache_for_sql_group( $group, array( 'wpdb_delete' => $table ) );
|
323 |
return $this->next_injection->delete( $table, $where, $where_format );
|
324 |
}
|
325 |
|
326 |
/**
|
327 |
+
* Flushes cache.
|
328 |
*
|
329 |
+
* @param array $extras Extra arguments.
|
330 |
+
* @return bool
|
331 |
*/
|
332 |
+
public function flush_cache( $extras = array() ) {
|
333 |
return $this->_flush_cache_for_sql_group( 'remaining', $extras );
|
334 |
}
|
335 |
|
336 |
+
/**
|
337 |
+
* Flush cache for SQL groups.
|
338 |
+
*
|
339 |
+
* @access private
|
340 |
+
*
|
341 |
+
* @param string $group Group.
|
342 |
+
* @param array $extras Extra arguments.
|
343 |
+
* @return bool
|
344 |
+
*/
|
345 |
private function _flush_cache_for_sql_group( $group, $extras = array() ) {
|
346 |
$this->wpdb_mixin->timer_start();
|
347 |
|
348 |
if ( $this->debug ) {
|
349 |
+
$filename = Util_Debug::log(
|
350 |
+
'dbcache',
|
351 |
'flushing based on sqlquery group ' . $group .
|
352 |
+
' with extras ' . json_encode( $extras )
|
353 |
+
);
|
354 |
}
|
355 |
if ( $this->_config->get_boolean( 'dbcache.debug_purge' ) ) {
|
356 |
+
Util_Debug::log_purge(
|
357 |
+
'dbcache',
|
358 |
+
'_flush_cache_for_sql_group',
|
359 |
+
array( $group, $extras )
|
360 |
+
);
|
361 |
}
|
362 |
|
363 |
+
$cache = $this->_get_cache();
|
364 |
$flush_groups = $this->_get_flush_groups( $group, $extras );
|
365 |
+
$v = true;
|
366 |
|
367 |
$this->cache_flushes++;
|
368 |
|
379 |
}
|
380 |
|
381 |
/**
|
382 |
+
* Returns cache object.
|
383 |
*
|
384 |
* @return W3_Cache_Base
|
385 |
*/
|
386 |
+
public function _get_cache() {
|
387 |
static $cache = array();
|
388 |
|
389 |
+
if ( ! isset( $cache[0] ) ) {
|
390 |
$engine = $this->_config->get_string( 'dbcache.engine' );
|
391 |
|
392 |
switch ( $engine ) {
|
393 |
+
case 'memcached':
|
394 |
+
$engine_config = array(
|
395 |
+
'servers' => $this->_config->get_array( 'dbcache.memcached.servers' ),
|
396 |
+
'persistent' => $this->_config->get_boolean( 'dbcache.memcached.persistent' ),
|
397 |
+
'aws_autodiscovery' => $this->_config->get_boolean( 'dbcache.memcached.aws_autodiscovery' ),
|
398 |
+
'username' => $this->_config->get_string( 'dbcache.memcached.username' ),
|
399 |
+
'password' => $this->_config->get_string( 'dbcache.memcached.password' ),
|
400 |
+
'binary_protocol' => $this->_config->get_boolean( 'dbcache.memcached.binary_protocol' )
|
401 |
+
);
|
402 |
+
break;
|
403 |
+
|
404 |
+
case 'redis':
|
405 |
+
$engine_config = array(
|
406 |
+
'servers' => $this->_config->get_array( 'dbcache.redis.servers' ),
|
407 |
+
'verify_tls_certificates' => $this->_config->get_boolean( 'dbcache.redis.verify_tls_certificates' ),
|
408 |
+
'persistent' => $this->_config->get_boolean( 'dbcache.redis.persistent' ),
|
409 |
+
'timeout' => $this->_config->get_integer( 'dbcache.redis.timeout' ),
|
410 |
+
'retry_interval' => $this->_config->get_integer( 'dbcache.redis.retry_interval' ),
|
411 |
+
'read_timeout' => $this->_config->get_integer( 'dbcache.redis.read_timeout' ),
|
412 |
+
'dbid' => $this->_config->get_integer( 'dbcache.redis.dbid' ),
|
413 |
+
'password' => $this->_config->get_string( 'dbcache.redis.password' )
|
414 |
+
);
|
415 |
+
break;
|
416 |
+
|
417 |
+
case 'file':
|
418 |
+
$engine_config = array(
|
419 |
+
'use_wp_hash' => true,
|
420 |
+
'section' => 'db',
|
421 |
+
'locking' => $this->_config->get_boolean( 'dbcache.file.locking' ),
|
422 |
+
'flush_timelimit' => $this->_config->get_integer( 'timelimit.cache_flush' )
|
423 |
+
);
|
424 |
+
break;
|
425 |
+
|
426 |
+
default:
|
427 |
+
$engine_config = array();
|
428 |
}
|
429 |
+
$engine_config['module'] = 'dbcache';
|
430 |
+
$engine_config['host'] = Util_Environment::host();
|
431 |
+
$engine_config['instance_id'] = Util_Environment::instance_id();
|
432 |
|
433 |
+
$cache[0] = Cache::instance( $engine, $engine_config );
|
434 |
}
|
435 |
|
436 |
return $cache[0];
|
437 |
}
|
438 |
|
439 |
/**
|
440 |
+
* Check if can cache sql.
|
441 |
*
|
442 |
+
* @param string $sql SQL query.
|
443 |
+
* @param string $cache_reject_reason Cache reject reason.
|
444 |
* @return boolean
|
445 |
*/
|
446 |
+
public function _can_cache( $sql, &$cache_reject_reason ) {
|
447 |
/**
|
448 |
* Skip if request-wide reject reason specified.
|
449 |
+
* Note - as a result requedt-wide checks are done only once per request.
|
450 |
*/
|
451 |
+
if ( ! is_null( $this->cache_reject_reason ) ) {
|
452 |
+
$cache_reject_reason = $this->cache_reject_reason;
|
453 |
$this->cache_reject_request_wide = true;
|
454 |
return false;
|
455 |
}
|
456 |
|
457 |
/**
|
458 |
+
* Do once-per-request check if needed.
|
459 |
*/
|
460 |
if ( is_null( $this->can_cache_once_per_request_result ) ) {
|
461 |
$this->can_cache_once_per_request_result = $this->_can_cache_once_per_request();
|
462 |
+
if ( ! $this->can_cache_once_per_request_result ) {
|
463 |
$this->cache_reject_request_wide = true;
|
464 |
return false;
|
465 |
}
|
466 |
}
|
467 |
|
468 |
/**
|
469 |
+
* Check for constants.
|
470 |
*/
|
471 |
foreach ( $this->reject_constants as $name ) {
|
472 |
if ( defined( $name ) && constant( $name ) ) {
|
478 |
}
|
479 |
|
480 |
/**
|
481 |
+
* Check for AJAX requests.
|
482 |
*/
|
483 |
$ajax_skip = false;
|
484 |
+
|
485 |
if ( defined( 'DOING_AJAX' ) ) {
|
486 |
$http_referer = isset( $_SERVER['HTTP_REFERER'] ) ?
|
487 |
+
filter_var( stripslashes( $_SERVER['HTTP_REFERER'] ), FILTER_SANITIZE_URL ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
|
488 |
|
489 |
// wp_admin is always defined for ajax requests, check by referrer.
|
490 |
if ( strpos( $http_referer, '/wp-admin/' ) === false ) {
|
493 |
}
|
494 |
|
495 |
/**
|
496 |
+
* Skip if admin.
|
497 |
*/
|
498 |
+
if ( defined( 'WP_ADMIN' ) && ! $ajax_skip ) {
|
499 |
$this->cache_reject_reason = 'WP_ADMIN';
|
500 |
+
$cache_reject_reason = $this->cache_reject_reason;
|
501 |
|
502 |
return false;
|
503 |
}
|
504 |
|
505 |
/**
|
506 |
+
* Skip if SQL is rejected.
|
507 |
*/
|
508 |
+
if ( ! $this->_check_sql( $sql ) ) {
|
509 |
$cache_reject_reason = 'query not cacheable';
|
510 |
|
511 |
return false;
|
512 |
}
|
513 |
|
514 |
/**
|
515 |
+
* Skip if user is logged in.
|
516 |
*/
|
517 |
+
if ( $this->reject_logged && ! $this->_check_logged_in() ) {
|
518 |
$this->cache_reject_reason = 'user.logged_in';
|
519 |
$cache_reject_reason = $this->cache_reject_reason;
|
520 |
|
525 |
}
|
526 |
|
527 |
/**
|
528 |
+
* Check if can cache sql, checks which have constant results during whole request.
|
529 |
*
|
530 |
+
* @return bool
|
531 |
*/
|
532 |
+
public function _can_cache_once_per_request() {
|
533 |
/**
|
534 |
* Skip if disabled
|
535 |
*/
|
536 |
+
if ( ! $this->_config->get_boolean( 'dbcache.enabled' ) ) {
|
537 |
$this->cache_reject_reason = 'dbcache.disabled';
|
538 |
|
539 |
return false;
|
542 |
/**
|
543 |
* Skip if request URI is rejected
|
544 |
*/
|
545 |
+
if ( ! $this->_check_request_uri() ) {
|
546 |
$this->cache_reject_reason = 'request';
|
547 |
return false;
|
548 |
}
|
550 |
/**
|
551 |
* Skip if cookie is rejected
|
552 |
*/
|
553 |
+
if ( ! $this->_check_cookies() ) {
|
554 |
$this->cache_reject_reason = 'cookie';
|
555 |
return false;
|
556 |
}
|
561 |
/**
|
562 |
* Check SQL
|
563 |
*
|
564 |
+
* @param string $sql SQL query.
|
565 |
+
* @return bool
|
566 |
*/
|
567 |
+
public function _check_sql( $sql ) {
|
568 |
|
569 |
$auto_reject_strings = $this->_config->get_array( 'dbcache.reject.words' );
|
570 |
|
577 |
foreach ( $reject_sql as $expr ) {
|
578 |
$expr = trim( $expr );
|
579 |
$expr = str_replace( '{prefix}', $this->wpdb_mixin->prefix, $expr );
|
580 |
+
if ( ! empty( $expr ) && preg_match( '~' . $expr . '~i', $sql ) ) {
|
581 |
return false;
|
582 |
}
|
583 |
}
|
590 |
*
|
591 |
* @return boolean
|
592 |
*/
|
593 |
+
public function _check_request_uri() {
|
594 |
$auto_reject_uri = array(
|
595 |
'wp-login',
|
596 |
'wp-register',
|
597 |
);
|
598 |
|
599 |
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ?
|
600 |
+
esc_url_raw( stripslashes( $_SERVER['REQUEST_URI'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
|
601 |
|
602 |
foreach ( $auto_reject_uri as $uri ) {
|
603 |
if ( strstr( $request_uri, $uri ) !== false ) {
|
610 |
|
611 |
foreach ( $reject_uri as $expr ) {
|
612 |
$expr = trim( $expr );
|
613 |
+
if ( ! empty( $expr ) && preg_match( '~' . $expr . '~i', $request_uri ) ) {
|
614 |
return false;
|
615 |
}
|
616 |
}
|
619 |
}
|
620 |
|
621 |
/**
|
622 |
+
* Checks for WordPress cookies.
|
623 |
*
|
624 |
+
* @return bool
|
625 |
*/
|
626 |
+
public function _check_cookies() {
|
627 |
foreach ( array_keys( $_COOKIE ) as $cookie_name ) {
|
628 |
+
if ( 'wordpress_test_cookie' === $cookie_name ) {
|
629 |
continue;
|
630 |
}
|
631 |
if ( preg_match( '/^wp-postpass|^comment_author/', $cookie_name ) ) {
|
645 |
}
|
646 |
|
647 |
/**
|
648 |
+
* Check if user is logged in.
|
649 |
*
|
650 |
+
* @return bool
|
651 |
*/
|
652 |
+
public function _check_logged_in() {
|
653 |
foreach ( array_keys( $_COOKIE ) as $cookie_name ) {
|
654 |
+
if ( strpos( $cookie_name, 'wordpress_logged_in' ) === 0 ) {
|
655 |
return false;
|
656 |
+
}
|
657 |
}
|
658 |
|
659 |
return true;
|
660 |
}
|
661 |
|
662 |
+
/**
|
663 |
+
* Get group.
|
664 |
+
*
|
665 |
+
* @access private
|
666 |
+
*
|
667 |
+
* @param string $sql SQL query.
|
668 |
+
* @return string
|
669 |
+
*/
|
670 |
private function _get_group( $sql ) {
|
671 |
$sql = strtolower( $sql );
|
672 |
|
673 |
+
// Collect list of tables used in query.
|
674 |
+
if ( preg_match_all( '~(^|[\s,`])' . $this->wpdb_mixin->prefix . '([0-9a-zA-Z_]+)~i', $sql, $m ) ) {
|
|
|
675 |
$tables = array_unique( $m[2] );
|
676 |
} else {
|
677 |
$tables = array();
|
679 |
|
680 |
if ( $this->contains_only_tables( $tables, array( 'options' => '*' ) ) ) {
|
681 |
$group = 'options';
|
682 |
+
} elseif ( $this->contains_only_tables( $tables, array( 'comments' => '*', 'commentsmeta' => '*' ) ) ) {
|
|
|
683 |
$group = 'comments';
|
684 |
} elseif ( count( $tables ) <= 1 ) {
|
685 |
+
$group = 'singletables'; // Request with single table affected.
|
686 |
} else {
|
687 |
$group = 'remaining';
|
688 |
}
|
694 |
return $group;
|
695 |
}
|
696 |
|
697 |
+
/**
|
698 |
+
* Contains only tables.
|
699 |
+
*
|
700 |
+
* @accress private
|
701 |
+
*
|
702 |
+
* @param array $tables Tables.
|
703 |
+
* #param array $allowed Allowed.
|
704 |
+
*/
|
705 |
private function contains_only_tables( $tables, $allowed ) {
|
706 |
if ( empty( $tables ) ) {
|
707 |
return false;
|
708 |
}
|
709 |
|
710 |
foreach ( $tables as $t ) {
|
711 |
+
if ( !isset( $allowed[ $t ] ) ) {
|
712 |
return false;
|
713 |
}
|
714 |
}
|
716 |
return true;
|
717 |
}
|
718 |
|
719 |
+
/**
|
720 |
+
* Get flush groups
|
721 |
+
*
|
722 |
+
* @access private
|
723 |
+
*
|
724 |
+
* @param string $group Group.
|
725 |
+
* @param array $extras Extra arguments.
|
726 |
+
*/
|
727 |
private function _get_flush_groups( $group, $extras = array() ) {
|
728 |
$groups_to_flush = array();
|
729 |
|
730 |
switch ( $group ) {
|
731 |
+
case 'remaining':
|
732 |
+
case 'singletables':
|
733 |
+
$groups_to_flush = array(
|
734 |
+
'remaining' => '*',
|
735 |
+
'options' => '*',
|
736 |
+
'comments' => '*',
|
737 |
+
'singletables' => '*',
|
738 |
+
);
|
739 |
+
break;
|
740 |
+
/**
|
741 |
+
* Options are updated on each second request,
|
742 |
+
* ignore by default probability that SELECTs with joins with options are critical and don't flush "remaining".
|
743 |
+
* That can be changed by w3tc_dbcache_get_flush_groups filter.
|
744 |
+
*/
|
745 |
+
case 'options':
|
746 |
+
$groups_to_flush = array( $group => '*' );
|
747 |
+
break;
|
748 |
+
default:
|
749 |
+
$groups_to_flush = array(
|
750 |
+
$group => '*',
|
751 |
+
'remaining' => '*',
|
752 |
+
);
|
753 |
}
|
754 |
|
755 |
if ( $this->use_filters && function_exists( 'apply_filters' ) ) {
|
756 |
+
$groups_to_flush = apply_filters( 'w3tc_dbcache_get_flush_groups', $groups_to_flush, $group, $extras );
|
|
|
757 |
}
|
758 |
|
759 |
return $groups_to_flush;
|
760 |
}
|
761 |
|
762 |
+
/**
|
763 |
+
* Get reject reason.
|
764 |
+
*
|
765 |
+
* @return string
|
766 |
+
*/
|
767 |
public function get_reject_reason() {
|
768 |
+
if ( is_null( $this->cache_reject_reason ) ) {
|
769 |
return '';
|
770 |
+
}
|
771 |
+
|
772 |
$request_wide_string = $this->cache_reject_request_wide ?
|
773 |
( function_exists( '__' ) ? __( 'Request-wide', 'w3-total-cache' ).' ' : 'Request ' ) : '';
|
774 |
+
|
775 |
return $request_wide_string . $this->_get_reject_reason_message( $this->cache_reject_reason );
|
776 |
}
|
777 |
|
778 |
/**
|
779 |
+
* Get reject reason message.
|
780 |
*
|
781 |
+
* @param string $key Key.
|
|
|
782 |
* @return string|void
|
783 |
*/
|
784 |
private function _get_reject_reason_message( $key ) {
|
785 |
+
if ( ! function_exists( '__' ) ) {
|
786 |
return $key;
|
787 |
+
}
|
788 |
+
|
789 |
switch ( $key ) {
|
790 |
+
case 'dbcache.disabled':
|
791 |
return __( 'Database caching is disabled', 'w3-total-cache' );
|
792 |
+
case 'DONOTCACHEDB':
|
793 |
+
return __( 'DONOTCACHEDB constant is defined', 'w3-total-cache' );
|
794 |
+
case 'DOING_AJAX':
|
795 |
+
return __( 'Doing AJAX', 'w3-total-cache' );
|
796 |
+
case 'request':
|
797 |
+
return __( 'Request URI is rejected', 'w3-total-cache' );
|
798 |
+
case 'cookie':
|
799 |
+
return __( 'Cookie is rejected', 'w3-total-cache' );
|
800 |
+
case 'DOING_CRONG':
|
801 |
+
return __( 'Doing cron', 'w3-total-cache' );
|
802 |
+
case 'APP_REQUEST':
|
803 |
+
return __( 'Application request', 'w3-total-cache' );
|
804 |
+
case 'XMLRPC_REQUEST':
|
805 |
+
return __( 'XMLRPC request', 'w3-total-cache' );
|
806 |
+
case 'WP_ADMIN':
|
807 |
+
return __( 'wp-admin', 'w3-total-cache' );
|
808 |
+
case 'SHORTINIT':
|
809 |
+
return __( 'Short init', 'w3-total-cache' );
|
810 |
+
case 'query':
|
811 |
+
return __( 'Query is rejected', 'w3-total-cache' );
|
812 |
+
case 'user.logged_in':
|
813 |
+
return __( 'User is logged in', 'w3-total-cache' );
|
814 |
+
default:
|
815 |
+
return $key;
|
816 |
}
|
817 |
}
|
818 |
|
819 |
+
/**
|
820 |
+
* Footer comment.
|
821 |
+
*
|
822 |
+
* @param array $strings Strings.
|
823 |
+
* @return array
|
824 |
+
*/
|
825 |
public function w3tc_footer_comment( $strings ) {
|
826 |
$reject_reason = $this->get_reject_reason();
|
827 |
$append = empty( $reject_reason ) ? '' : sprintf( ' (%1$s)', $reject_reason );
|
854 |
}
|
855 |
|
856 |
if ( $this->log_filehandle ) {
|
857 |
+
fclose( $this->log_filehandle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
|
858 |
$this->log_filehandle = false;
|
859 |
}
|
860 |
return $strings;
|
861 |
}
|
862 |
|
863 |
+
/**
|
864 |
+
* Usage statistics of request.
|
865 |
+
*
|
866 |
+
* @param object $storage Storage object.
|
867 |
+
* @return void
|
868 |
+
*/
|
869 |
public function w3tc_usage_statistics_of_request( $storage ) {
|
870 |
$storage->counter_add( 'dbcache_calls_total', $this->query_total );
|
871 |
$storage->counter_add( 'dbcache_calls_hits', $this->query_hits );
|
874 |
$storage->counter_add( 'dbcache_time_ms', $time_ms );
|
875 |
}
|
876 |
|
877 |
+
/**
|
878 |
+
* Log query.
|
879 |
+
*
|
880 |
+
* @access private
|
881 |
+
*
|
882 |
+
* @param string $line Line to add.
|
883 |
+
* @return void
|
884 |
+
*/
|
885 |
private function log_query( $line ) {
|
886 |
+
if ( ! $this->log_filehandle ) {
|
887 |
$filename = Util_Debug::log_filename( 'dbcache-queries' );
|
888 |
+
$this->log_filehandle = fopen( $filename, 'a' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen
|
889 |
}
|
890 |
|
891 |
+
fputcsv( $this->log_filehandle, $line, "\t" );
|
892 |
}
|
893 |
}
|
Generic_Plugin_Admin.php
CHANGED
@@ -439,6 +439,36 @@ class Generic_Plugin_Admin {
|
|
439 |
'w3tc_nonce',
|
440 |
array( wp_create_nonce( 'w3tc' ) )
|
441 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
}
|
443 |
|
444 |
switch ( $this->_page ) {
|
439 |
'w3tc_nonce',
|
440 |
array( wp_create_nonce( 'w3tc' ) )
|
441 |
);
|
442 |
+
|
443 |
+
wp_localize_script(
|
444 |
+
'w3tc-options',
|
445 |
+
'w3tcData',
|
446 |
+
array(
|
447 |
+
'cdnEnabled' => $this->_config->get_boolean( 'cdn.enabled' ),
|
448 |
+
'cdnEngine' => $this->_config->get_string( 'cdn.engine' ),
|
449 |
+
'cdnFlushManually' => $this->_config->get_boolean( 'cdn.flush_manually' ),
|
450 |
+
'cfWarning' => wp_kses(
|
451 |
+
sprintf(
|
452 |
+
// translators: 1: HTML break, 2: HTML anchor open tag, 3: HTML anchor close tag, 4: HTML anchor open tag.
|
453 |
+
__(
|
454 |
+
'Please see %2$sAmazon\'s CloudFront documentation -- Paying for file invalidation%3$s:%1$sThe first 1,000 invalidation paths that you submit per month are free; you pay for each invalidation path over 1,000 in a month.%1$sYou can disable automatic purging by enabling %4$sOnly purge CDN manually%3$s.',
|
455 |
+
'w3-total-cache'
|
456 |
+
),
|
457 |
+
'<br />',
|
458 |
+
'<a target="_blank" href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#PayingForInvalidation">',
|
459 |
+
'</a>',
|
460 |
+
'<a href="' . esc_url( admin_url( 'admin.php?page=w3tc_cdn#advanced' ) ) . '">'
|
461 |
+
),
|
462 |
+
array(
|
463 |
+
'a' => array(
|
464 |
+
'target' => array(),
|
465 |
+
'href' => array(),
|
466 |
+
),
|
467 |
+
'br' => array(),
|
468 |
+
)
|
469 |
+
),
|
470 |
+
)
|
471 |
+
);
|
472 |
}
|
473 |
|
474 |
switch ( $this->_page ) {
|
Licensing_Plugin_Admin.php
CHANGED
@@ -173,6 +173,16 @@ class Licensing_Plugin_Admin {
|
|
173 |
'<input type="button" class="button-primary button-buy-plugin" data-nonce="' .
|
174 |
esc_url( wp_create_nonce( 'w3tc' ) ) . '" data-renew-key="' . esc_attr( $this->get_license_key() ) .
|
175 |
'" data-src="licensing_expired" value="' . __( 'Renew Now', 'w3-total-cache' ) . '" />'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
)
|
177 |
);
|
178 |
} elseif ( $this->_status_is( $status, 'invalid' ) ) {
|
@@ -194,7 +204,14 @@ class Licensing_Plugin_Admin {
|
|
194 |
'page' => 'w3tc_general',
|
195 |
'w3tc_licensing_reset_rooturi' => 'y',
|
196 |
)
|
197 |
-
) . '"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
)
|
199 |
);
|
200 |
} elseif ( $this->_status_is( $status, 'inactive' ) ) {
|
173 |
'<input type="button" class="button-primary button-buy-plugin" data-nonce="' .
|
174 |
esc_url( wp_create_nonce( 'w3tc' ) ) . '" data-renew-key="' . esc_attr( $this->get_license_key() ) .
|
175 |
'" data-src="licensing_expired" value="' . __( 'Renew Now', 'w3-total-cache' ) . '" />'
|
176 |
+
),
|
177 |
+
array(
|
178 |
+
'input' => array(
|
179 |
+
'type' => array(),
|
180 |
+
'class' => array(),
|
181 |
+
'data-nonce' => array(),
|
182 |
+
'data-renew-key' => array(),
|
183 |
+
'data-src' => array(),
|
184 |
+
'value' => array(),
|
185 |
+
),
|
186 |
)
|
187 |
);
|
188 |
} elseif ( $this->_status_is( $status, 'invalid' ) ) {
|
204 |
'page' => 'w3tc_general',
|
205 |
'w3tc_licensing_reset_rooturi' => 'y',
|
206 |
)
|
207 |
+
) . '">',
|
208 |
+
'</a>'
|
209 |
+
),
|
210 |
+
array(
|
211 |
+
'a' => array(
|
212 |
+
'class' => array(),
|
213 |
+
'href' => array(),
|
214 |
+
),
|
215 |
)
|
216 |
);
|
217 |
} elseif ( $this->_status_is( $status, 'inactive' ) ) {
|
PgCache_Flush.php
CHANGED
@@ -76,6 +76,9 @@ class PgCache_Flush extends PgCache_ContentGrabber {
|
|
76 |
// calculate urls to purge
|
77 |
$full_urls = array();
|
78 |
$post = get_post( $post_id );
|
|
|
|
|
|
|
79 |
$is_cpt = Util_Environment::is_custom_post_type( $post );
|
80 |
$terms = array();
|
81 |
|
76 |
// calculate urls to purge
|
77 |
$full_urls = array();
|
78 |
$post = get_post( $post_id );
|
79 |
+
if ( empty( $post ) ) {
|
80 |
+
return true;
|
81 |
+
}
|
82 |
$is_cpt = Util_Environment::is_custom_post_type( $post );
|
83 |
$terms = array();
|
84 |
|
Util_File.php
CHANGED
@@ -93,7 +93,8 @@ class Util_File {
|
|
93 |
$path = trim( $path, '/' );
|
94 |
$dirs = explode( '/', $path );
|
95 |
|
96 |
-
$curr_path = $from_path;
|
|
|
97 |
|
98 |
foreach ( $dirs as $dir ) {
|
99 |
if ( $dir == '' )
|
@@ -104,8 +105,16 @@ class Util_File {
|
|
104 |
$curr_path .= ( $curr_path == '' ? '' : '/' ) . $dir;
|
105 |
|
106 |
if ( !@file_exists( $curr_path ) ) {
|
107 |
-
if ( !@mkdir( $curr_path, $mask ) )
|
108 |
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
}
|
111 |
|
93 |
$path = trim( $path, '/' );
|
94 |
$dirs = explode( '/', $path );
|
95 |
|
96 |
+
$curr_path = realpath( $from_path ); // use canonicalization
|
97 |
+
$curr_path_previous = $curr_path;
|
98 |
|
99 |
foreach ( $dirs as $dir ) {
|
100 |
if ( $dir == '' )
|
105 |
$curr_path .= ( $curr_path == '' ? '' : '/' ) . $dir;
|
106 |
|
107 |
if ( !@file_exists( $curr_path ) ) {
|
108 |
+
if ( !@mkdir( $curr_path, $mask ) ) {
|
109 |
return false;
|
110 |
+
}
|
111 |
+
$curr_path = realpath( $curr_path );
|
112 |
+
// make sure we grow from previous step and dont jump elsewhere
|
113 |
+
if ( strlen( $curr_path ) <= 0 ||
|
114 |
+
substr( $curr_path, 0, strlen( $curr_path_previous ) ) != $curr_path_previous ) {
|
115 |
+
return false;
|
116 |
+
}
|
117 |
+
$curr_path_previous = $curr_path;
|
118 |
}
|
119 |
}
|
120 |
|
inc/options/cdn.php
CHANGED
@@ -415,6 +415,31 @@ $upload_blogfiles_enabled = $cdn_mirror || ! is_network_admin() || ! Util_Enviro
|
|
415 |
)
|
416 |
);
|
417 |
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
</p>
|
419 |
</th>
|
420 |
</tr>
|
@@ -458,7 +483,7 @@ $upload_blogfiles_enabled = $cdn_mirror || ! is_network_admin() || ! Util_Enviro
|
|
458 |
echo wp_kses(
|
459 |
sprintf(
|
460 |
// translators: 1 opening HTML acronym tag, 2 closing HTML acronym tag.
|
461 |
-
__(
|
462 |
'All Media Library content will use %1$sCDN%2$s links on administration pages.',
|
463 |
'w3-total-cache'
|
464 |
),
|
415 |
)
|
416 |
);
|
417 |
?>
|
418 |
+
<div class="hidden" id="cdn-flushmanually-warning">
|
419 |
+
<div class="notice notice-warning inline"><p>
|
420 |
+
<?php
|
421 |
+
echo wp_kses(
|
422 |
+
sprintf(
|
423 |
+
// translators: 1: HTML break, 2: HTML anchor open tag, 3: HTML anchor close tag.
|
424 |
+
__(
|
425 |
+
'Please see %2$sAmazon\'s CloudFront documentation -- Paying for file invalidation%3$s:%1$sThe first 1,000 invalidation paths that you submit per month are free; you pay for each invalidation path over 1,000 in a month.%1$sYou can disable automatic purging by enabling "Only purge CDN manually".',
|
426 |
+
'w3-total-cache'
|
427 |
+
),
|
428 |
+
'<br />',
|
429 |
+
'<a target="_blank" href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#PayingForInvalidation">',
|
430 |
+
'</a>'
|
431 |
+
),
|
432 |
+
array(
|
433 |
+
'a' => array(
|
434 |
+
'target' => array(),
|
435 |
+
'href' => array(),
|
436 |
+
),
|
437 |
+
'br' => array(),
|
438 |
+
)
|
439 |
+
);
|
440 |
+
?>
|
441 |
+
</p></div>
|
442 |
+
</div>
|
443 |
</p>
|
444 |
</th>
|
445 |
</tr>
|
483 |
echo wp_kses(
|
484 |
sprintf(
|
485 |
// translators: 1 opening HTML acronym tag, 2 closing HTML acronym tag.
|
486 |
+
__(
|
487 |
'All Media Library content will use %1$sCDN%2$s links on administration pages.',
|
488 |
'w3-total-cache'
|
489 |
),
|
inc/options/cdn/cf.php
CHANGED
@@ -174,7 +174,7 @@ if ( ! defined( 'W3TC' ) ) {
|
|
174 |
<th><label for="cdn_cf_public_objects"><?php _e( 'Set objects to publicly accessible on upload:', 'w3-total-cache' ); ?></label></th>
|
175 |
<td>
|
176 |
<select id="cdn_cf_public_objects" name="cdn__cf__public_objects" <?php Util_Ui::sealing_disabled( 'cdn.' ) ?> >
|
177 |
-
<option value="enabled"<?php selected( $this->_config->get_string( 'cdn.cf.public_objects' ), 'enabled' ); ?>><?php esc_html_e( 'Enabled (apply the \'public-read\'
|
178 |
<option value="disabled"<?php selected( $this->_config->get_string( 'cdn.cf.public_objects' ), 'disabled' ); ?>><?php esc_html_e( 'Disabled (don\'t apply an ACL)', 'w3-total-cache' ); ?></option>
|
179 |
</select>
|
180 |
<p class="description"><?php _e( 'Objects in an S3 bucket served from CloudFront do not need to be publicly accessible. Set this value to disabled to ensure that objects are not publicly accessible and can only be accessed via CloudFront or with a suitable IAM role.', 'w3-total-cache' ); ?></p>
|
174 |
<th><label for="cdn_cf_public_objects"><?php _e( 'Set objects to publicly accessible on upload:', 'w3-total-cache' ); ?></label></th>
|
175 |
<td>
|
176 |
<select id="cdn_cf_public_objects" name="cdn__cf__public_objects" <?php Util_Ui::sealing_disabled( 'cdn.' ) ?> >
|
177 |
+
<option value="enabled"<?php selected( $this->_config->get_string( 'cdn.cf.public_objects' ), 'enabled' ); ?>><?php esc_html_e( 'Enabled (apply the \'public-read\' ACL)', 'w3-total-cache' ); ?></option>
|
178 |
<option value="disabled"<?php selected( $this->_config->get_string( 'cdn.cf.public_objects' ), 'disabled' ); ?>><?php esc_html_e( 'Disabled (don\'t apply an ACL)', 'w3-total-cache' ); ?></option>
|
179 |
</select>
|
180 |
<p class="description"><?php _e( 'Objects in an S3 bucket served from CloudFront do not need to be publicly accessible. Set this value to disabled to ensure that objects are not publicly accessible and can only be accessed via CloudFront or with a suitable IAM role.', 'w3-total-cache' ); ?></p>
|
inc/options/cdn/s3.php
CHANGED
@@ -174,6 +174,15 @@ if ( ! defined( 'W3TC' ) ) {
|
|
174 |
</p>
|
175 |
</td>
|
176 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
<tr>
|
178 |
<th colspan="2">
|
179 |
<input id="cdn_test" class="button {type: 's3', nonce: '<?php echo esc_attr( wp_create_nonce( 'w3tc' ) ); ?>'}" type="button" value="<?php esc_attr_e( 'Test S3 upload', 'w3-total-cache' ); ?>" /> <span id="cdn_test_status" class="w3tc-status w3tc-process"></span>
|
174 |
</p>
|
175 |
</td>
|
176 |
</tr>
|
177 |
+
<tr>
|
178 |
+
<th><label for="cdn_s3_public_objects"><?php _e( 'Set objects to publicly accessible on upload:', 'w3-total-cache' ); ?></label></th>
|
179 |
+
<td>
|
180 |
+
<select id="cdn_s3_public_objects" name="cdn__s3__public_objects" <?php Util_Ui::sealing_disabled( 'cdn.' ) ?> >
|
181 |
+
<option value="enabled"<?php selected( $this->_config->get_string( 'cdn.s3.public_objects' ), 'enabled' ); ?>><?php esc_html_e( 'Enabled (apply the \'public-read\' ACL)', 'w3-total-cache' ); ?></option>
|
182 |
+
<option value="disabled"<?php selected( $this->_config->get_string( 'cdn.s3.public_objects' ), 'disabled' ); ?>><?php esc_html_e( 'Disabled (don\'t apply an ACL)', 'w3-total-cache' ); ?></option>
|
183 |
+
</select>
|
184 |
+
</td>
|
185 |
+
</tr>
|
186 |
<tr>
|
187 |
<th colspan="2">
|
188 |
<input id="cdn_test" class="button {type: 's3', nonce: '<?php echo esc_attr( wp_create_nonce( 'w3tc' ) ); ?>'}" type="button" value="<?php esc_attr_e( 'Test S3 upload', 'w3-total-cache' ); ?>" /> <span id="cdn_test_status" class="w3tc-status w3tc-process"></span>
|
inc/options/extensions.php
CHANGED
@@ -28,7 +28,7 @@ if ( ! defined( 'W3TC' ) ) {
|
|
28 |
);
|
29 |
}
|
30 |
?>
|
31 |
-
<form action="admin.php?page=<?php echo esc_attr( $this->_page ); ?><?php echo $extension ? '&extension=
|
32 |
<div class="metabox-holder <?php echo $extension ? 'extension-settings' : ''; ?>">
|
33 |
<?php require W3TC_INC_OPTIONS_DIR . "/extensions/$sub_view.php"; ?>
|
34 |
</div>
|
28 |
);
|
29 |
}
|
30 |
?>
|
31 |
+
<form action="admin.php?page=<?php echo esc_attr( $this->_page ); ?><?php echo $extension ? '&extension=' . esc_attr( $extension ) . '&action=view' : ''; ?>" method="post">
|
32 |
<div class="metabox-holder <?php echo $extension ? 'extension-settings' : ''; ?>">
|
33 |
<?php require W3TC_INC_OPTIONS_DIR . "/extensions/$sub_view.php"; ?>
|
34 |
</div>
|
inc/options/parts/redis.php
CHANGED
@@ -64,6 +64,10 @@ if ( ! defined( 'W3TC' ) ) {
|
|
64 |
<p class="description"><?php esc_html_e( 'In miliseconds', 'w3-total-cache' ); ?></p>
|
65 |
</td>
|
66 |
</tr>
|
|
|
|
|
|
|
|
|
67 |
<tr>
|
68 |
<th style="width: 250px;"><label for="redis_read_timeout"><?php echo wp_kses( Util_ConfigLabel::get( 'redis.read_timeout' ), array( 'acronym' => array( 'title' => array() ) ) ); ?></label></th>
|
69 |
<td>
|
@@ -74,6 +78,9 @@ if ( ! defined( 'W3TC' ) ) {
|
|
74 |
<p class="description"><?php esc_html_e( 'In seconds', 'w3-total-cache' ); ?></p>
|
75 |
</td>
|
76 |
</tr>
|
|
|
|
|
|
|
77 |
<tr>
|
78 |
<th style="width: 250px;"><label for="redis_dbid"><?php echo wp_kses( Util_ConfigLabel::get( 'redis.dbid' ), array( 'acronym' => array( 'title' => array() ) ) ); ?></label></th>
|
79 |
<td>
|
64 |
<p class="description"><?php esc_html_e( 'In miliseconds', 'w3-total-cache' ); ?></p>
|
65 |
</td>
|
66 |
</tr>
|
67 |
+
<?php
|
68 |
+
if ( version_compare( phpversion( 'redis' ), '5', '>=' ) ) {
|
69 |
+
// PHP Redis 5 supports the read_timeout setting.
|
70 |
+
?>
|
71 |
<tr>
|
72 |
<th style="width: 250px;"><label for="redis_read_timeout"><?php echo wp_kses( Util_ConfigLabel::get( 'redis.read_timeout' ), array( 'acronym' => array( 'title' => array() ) ) ); ?></label></th>
|
73 |
<td>
|
78 |
<p class="description"><?php esc_html_e( 'In seconds', 'w3-total-cache' ); ?></p>
|
79 |
</td>
|
80 |
</tr>
|
81 |
+
<?php
|
82 |
+
}
|
83 |
+
?>
|
84 |
<tr>
|
85 |
<th style="width: 250px;"><label for="redis_dbid"><?php echo wp_kses( Util_ConfigLabel::get( 'redis.dbid' ), array( 'acronym' => array( 'title' => array() ) ) ); ?></label></th>
|
86 |
<td>
|
inc/options/parts/redis_extension.php
CHANGED
@@ -74,15 +74,18 @@ Util_Ui::config_item(
|
|
74 |
)
|
75 |
);
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
)
|
|
|
|
|
|
|
86 |
|
87 |
Util_Ui::config_item(
|
88 |
array(
|
74 |
)
|
75 |
);
|
76 |
|
77 |
+
if ( version_compare( phpversion( 'redis' ), '5', '>=' ) ) {
|
78 |
+
// PHP Redis 5 supports the read_timeout setting.
|
79 |
+
Util_Ui::config_item(
|
80 |
+
array(
|
81 |
+
'key' => array( $module, 'redis.read_timeout' ),
|
82 |
+
'label' => Util_ConfigLabel::get( 'redis.read_timeout' ),
|
83 |
+
'control' => 'textbox',
|
84 |
+
'textbox_type' => 'number',
|
85 |
+
'description' => __( 'In seconds', 'w3-total-cache' ),
|
86 |
+
)
|
87 |
+
);
|
88 |
+
}
|
89 |
|
90 |
Util_Ui::config_item(
|
91 |
array(
|
inc/options/pgcache.php
CHANGED
@@ -575,7 +575,7 @@ if ( ! defined( 'W3TC' ) ) {
|
|
575 |
</td>
|
576 |
</tr>
|
577 |
<?php endif; ?>
|
578 |
-
<?php if ( 'file_generic'
|
579 |
<tr>
|
580 |
<th><label for="pgcache_lifetime"><?php Util_Ui::e_config_label( 'pgcache.lifetime' ); ?></label></th>
|
581 |
<td>
|
575 |
</td>
|
576 |
</tr>
|
577 |
<?php endif; ?>
|
578 |
+
<?php if ( 'file_generic' !== $this->_config->get_string( 'pgcache.engine' ) ) : ?>
|
579 |
<tr>
|
580 |
<th><label for="pgcache_lifetime"><?php Util_Ui::e_config_label( 'pgcache.lifetime' ); ?></label></th>
|
581 |
<td>
|
ini/config-db-sample.php
CHANGED
@@ -32,3 +32,6 @@ define( 'W3TC_CONFIG_CACHE_REDIS_SERVERS', '127.0.0.1:6379' );
|
|
32 |
define( 'W3TC_CONFIG_CACHE_REDIS_PERSISTENT', true );
|
33 |
define( 'W3TC_CONFIG_CACHE_REDIS_DBID', 0 );
|
34 |
define( 'W3TC_CONFIG_CACHE_REDIS_PASSWORD', '' );
|
|
|
|
|
|
32 |
define( 'W3TC_CONFIG_CACHE_REDIS_PERSISTENT', true );
|
33 |
define( 'W3TC_CONFIG_CACHE_REDIS_DBID', 0 );
|
34 |
define( 'W3TC_CONFIG_CACHE_REDIS_PASSWORD', '' );
|
35 |
+
define( 'W3TC_CONFIG_CACHE_REDIS_TIMEOUT', 0 );
|
36 |
+
define( 'W3TC_CONFIG_CACHE_REDIS_RETRY_INTERVAL', 0 );
|
37 |
+
define( 'W3TC_CONFIG_CACHE_REDIS_READ_TIMEOUT', 0 );
|
lib/CSSTidy/class.csstidy.php
CHANGED
@@ -70,7 +70,7 @@ require('class.csstidy_optimise.php');
|
|
70 |
* An online version should be available here: http://cdburnerxp.se/cssparse/css_optimiser.php
|
71 |
* @package csstidy
|
72 |
* @author Florian Schmitz (floele at gmail dot com) 2005-2006
|
73 |
-
* @version
|
74 |
*/
|
75 |
class csstidy {
|
76 |
|
@@ -501,7 +501,7 @@ class csstidy {
|
|
501 |
if (!is_dir('temp')) {
|
502 |
$madedir = mkdir('temp');
|
503 |
if (!$madedir) {
|
504 |
-
print 'Could not make directory "temp" in ' .
|
505 |
exit;
|
506 |
}
|
507 |
}
|
@@ -1298,7 +1298,12 @@ class csstidy {
|
|
1298 |
* @version 1.0
|
1299 |
*/
|
1300 |
public function property_is_valid($property) {
|
1301 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
1302 |
$all_properties = & $this->data['csstidy']['all_properties'];
|
1303 |
return (isset($all_properties[$property]) && strpos($all_properties[$property], strtoupper($this->get_cfg('css_level'))) !== false );
|
1304 |
}
|
70 |
* An online version should be available here: http://cdburnerxp.se/cssparse/css_optimiser.php
|
71 |
* @package csstidy
|
72 |
* @author Florian Schmitz (floele at gmail dot com) 2005-2006
|
73 |
+
* @version 2.0.1
|
74 |
*/
|
75 |
class csstidy {
|
76 |
|
501 |
if (!is_dir('temp')) {
|
502 |
$madedir = mkdir('temp');
|
503 |
if (!$madedir) {
|
504 |
+
print 'Could not make directory "temp" in ' . dirname(__FILE__);
|
505 |
exit;
|
506 |
}
|
507 |
}
|
1298 |
* @version 1.0
|
1299 |
*/
|
1300 |
public function property_is_valid($property) {
|
1301 |
+
if (strpos($property, '--') === 0) {
|
1302 |
+
$property = "--custom";
|
1303 |
+
}
|
1304 |
+
elseif (in_array(trim($property), $this->data['csstidy']['multiple_properties'])) {
|
1305 |
+
$property = trim($property);
|
1306 |
+
}
|
1307 |
$all_properties = & $this->data['csstidy']['all_properties'];
|
1308 |
return (isset($all_properties[$property]) && strpos($all_properties[$property], strtoupper($this->get_cfg('css_level'))) !== false );
|
1309 |
}
|
lib/CSSTidy/class.csstidy_optimise.php
CHANGED
@@ -420,9 +420,9 @@ class csstidy_optimise {
|
|
420 |
if ($number[1] == '' && in_array($this->property, $unit_values, true)) {
|
421 |
$number[1] = 'px';
|
422 |
}
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
|
427 |
$temp[$l] = $number[0] . $number[1];
|
428 |
}
|
420 |
if ($number[1] == '' && in_array($this->property, $unit_values, true)) {
|
421 |
$number[1] = 'px';
|
422 |
}
|
423 |
+
} elseif ($number[1] != 's' && $number[1] != 'ms') {
|
424 |
+
$number[1] = '';
|
425 |
+
}
|
426 |
|
427 |
$temp[$l] = $number[0] . $number[1];
|
428 |
}
|
lib/CSSTidy/data.inc.php
CHANGED
@@ -566,6 +566,7 @@ $data['csstidy']['all_properties']['word-break'] = 'CSS3.0';
|
|
566 |
$data['csstidy']['all_properties']['word-spacing'] = 'CSS1.0,CSS2.0,CSS2.1,CSS3.0';
|
567 |
$data['csstidy']['all_properties']['word-wrap'] = 'CSS3.0';
|
568 |
$data['csstidy']['all_properties']['z-index'] = 'CSS2.0,CSS2.1,CSS3.0';
|
|
|
569 |
|
570 |
/**
|
571 |
* An array containing all properties that can accept a quoted string as a value.
|
566 |
$data['csstidy']['all_properties']['word-spacing'] = 'CSS1.0,CSS2.0,CSS2.1,CSS3.0';
|
567 |
$data['csstidy']['all_properties']['word-wrap'] = 'CSS3.0';
|
568 |
$data['csstidy']['all_properties']['z-index'] = 'CSS2.0,CSS2.1,CSS3.0';
|
569 |
+
$data['csstidy']['all_properties']['--custom'] = 'CSS3.0';
|
570 |
|
571 |
/**
|
572 |
* An array containing all properties that can accept a quoted string as a value.
|
pub/js/options.js
CHANGED
@@ -320,6 +320,34 @@ function w3tc_csp_reference() {
|
|
320 |
});
|
321 |
}
|
322 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
323 |
jQuery(function() {
|
324 |
// general page
|
325 |
jQuery('.w3tc_read_technical_info').on( 'click', function() {
|
@@ -354,9 +382,20 @@ jQuery(function() {
|
|
354 |
}
|
355 |
}).fail(function() {
|
356 |
jQuery('.w3tc_license_verification').html('Check failed');
|
357 |
-
})
|
358 |
});
|
359 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
360 |
// pagecache page
|
361 |
w3tc_input_enable('#pgcache_reject_roles input[type=checkbox]', jQuery('#pgcache__reject__logged_roles:checked').length);
|
362 |
jQuery('#pgcache__reject__logged_roles').on('click', function () {
|
320 |
});
|
321 |
}
|
322 |
|
323 |
+
function cdn_cf_check() {
|
324 |
+
var cdnEnabled = jQuery( '#cdn__enabled' ).is( ':checked' ),
|
325 |
+
cdnEngine = jQuery( '#cdn__engine' ).find( ':selected' ).val(),
|
326 |
+
cdnFlushManually = jQuery( '[name="cdn__flush_manually"]' ).is( ':checked' );
|
327 |
+
|
328 |
+
// Remove any cf admin notices.
|
329 |
+
jQuery( '.w3tc-cf-notice' ).remove();
|
330 |
+
|
331 |
+
// General page.
|
332 |
+
if ( ! w3tcData.cdnFlushManually && cdnEnabled && ( 'cf' === cdnEngine || 'cf2' === cdnEngine ) ) {
|
333 |
+
// Print cf admin notice.
|
334 |
+
jQuery( '#cdn .inside' ).prepend(
|
335 |
+
'<div class="notice notice-warning inline w3tc-cf-notice"><p>' +
|
336 |
+
w3tcData.cfWarning +
|
337 |
+
'</p></div>'
|
338 |
+
);
|
339 |
+
}
|
340 |
+
|
341 |
+
// CDN page.
|
342 |
+
if ( ! cdnFlushManually && w3tcData.cdnEnabled && ( 'cf' === w3tcData.cdnEngine || 'cf2' === w3tcData.cdnEngine ) ) {
|
343 |
+
// Show warning on the CDN page for flush manually.
|
344 |
+
jQuery( '#cdn-flushmanually-warning' ).show();
|
345 |
+
} else {
|
346 |
+
// Hide warning on the CDN page for flush manually.
|
347 |
+
jQuery( '#cdn-flushmanually-warning' ).hide();
|
348 |
+
}
|
349 |
+
}
|
350 |
+
|
351 |
jQuery(function() {
|
352 |
// general page
|
353 |
jQuery('.w3tc_read_technical_info').on( 'click', function() {
|
382 |
}
|
383 |
}).fail(function() {
|
384 |
jQuery('.w3tc_license_verification').html('Check failed');
|
385 |
+
});
|
386 |
});
|
387 |
|
388 |
+
// When CDN is enabled as "cf" or "cf2", then display a notice about possible charges.
|
389 |
+
cdn_cf_check();
|
390 |
+
jQuery( '#cdn__enabled' ).on( 'click', cdn_cf_check );
|
391 |
+
jQuery( '#cdn__engine' ).on( 'change', cdn_cf_check );
|
392 |
+
|
393 |
+
/**
|
394 |
+
* CDN page.
|
395 |
+
* When CDN is enabled as "cf" or "cf2", then display a notice about possible charges.
|
396 |
+
*/
|
397 |
+
jQuery( '[name="cdn__flush_manually"]' ).on( 'click', cdn_cf_check );
|
398 |
+
|
399 |
// pagecache page
|
400 |
w3tc_input_enable('#pgcache_reject_roles input[type=checkbox]', jQuery('#pgcache__reject__logged_roles:checked').length);
|
401 |
jQuery('#pgcache__reject__logged_roles').on('click', function () {
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: boldgrid, fredericktownes, maxicusc, gidomanders, bwmarkle, harryj
|
|
3 |
Tags: seo, cache, CDN, pagespeed, caching, performance, compression, optimize, cloudflare, nginx, apache, varnish, redis, aws, amazon web services, s3, cloudfront, azure
|
4 |
Requires at least: 3.8
|
5 |
Tested up to: 6.0
|
6 |
-
Stable tag: 2.2.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -285,6 +285,23 @@ Please reach out to all of these people and support their projects if you're so
|
|
285 |
|
286 |
== Changelog ==
|
287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
= 2.2.3 =
|
289 |
* Fix: Redis Cache: Removed exception on warnings
|
290 |
* Fix: Compatibility check for WP_CACHE
|
3 |
Tags: seo, cache, CDN, pagespeed, caching, performance, compression, optimize, cloudflare, nginx, apache, varnish, redis, aws, amazon web services, s3, cloudfront, azure
|
4 |
Requires at least: 3.8
|
5 |
Tested up to: 6.0
|
6 |
+
Stable tag: 2.2.4
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
285 |
|
286 |
== Changelog ==
|
287 |
|
288 |
+
= 2.2.4 =
|
289 |
+
* Fix: Extensions URL in settings
|
290 |
+
* Fix: Redis undefined array key warnings
|
291 |
+
* Fix: Redis connect issue based on phpredis version
|
292 |
+
* Fix: Sanitization of licensing messages
|
293 |
+
* Fix: DB cache error in Ajax
|
294 |
+
* Fix: Call to undefined function in DB cache query class
|
295 |
+
* Fix: PHP 8 compatibility: join
|
296 |
+
* Fix: WooCommerce Variation Image Gallery plugin CDN filter
|
297 |
+
* Enhancement: Add setting for AWS S3 public objects in ACL
|
298 |
+
* Enhancement: Check if post is empty before cache flush
|
299 |
+
* Enhancement: Add max lifetime setting for non-disk page cache
|
300 |
+
* Enhancement: Add notice when selecting CDN using CloudFront
|
301 |
+
* Update: CSS Tidy 1.7.3 => 2.0.1
|
302 |
+
* Update: Add sns-message-validator
|
303 |
+
* Security: Ensure cache writes in cache folders
|
304 |
+
|
305 |
= 2.2.3 =
|
306 |
* Fix: Redis Cache: Removed exception on warnings
|
307 |
* Fix: Compatibility check for WP_CACHE
|
vendor/aws/aws-php-sns-message-validator/.github/ISSUE_TEMPLATE/bug-report.yml
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
name: "🐛 Bug Report"
|
3 |
+
description: Report a bug
|
4 |
+
title: "(short issue description)"
|
5 |
+
labels: [bug, needs-triage]
|
6 |
+
assignees: []
|
7 |
+
body:
|
8 |
+
- type: textarea
|
9 |
+
id: description
|
10 |
+
attributes:
|
11 |
+
label: Describe the bug
|
12 |
+
description: What is the problem? A clear and concise description of the bug.
|
13 |
+
validations:
|
14 |
+
required: true
|
15 |
+
- type: textarea
|
16 |
+
id: expected
|
17 |
+
attributes:
|
18 |
+
label: Expected Behavior
|
19 |
+
description: |
|
20 |
+
What did you expect to happen?
|
21 |
+
validations:
|
22 |
+
required: true
|
23 |
+
- type: textarea
|
24 |
+
id: current
|
25 |
+
attributes:
|
26 |
+
label: Current Behavior
|
27 |
+
description: |
|
28 |
+
What actually happened?
|
29 |
+
|
30 |
+
Please include full errors, uncaught exceptions, stack traces, and relevant logs.
|
31 |
+
If service responses are relevant, please include wire logs.
|
32 |
+
validations:
|
33 |
+
required: true
|
34 |
+
- type: textarea
|
35 |
+
id: reproduction
|
36 |
+
attributes:
|
37 |
+
label: Reproduction Steps
|
38 |
+
description: |
|
39 |
+
Provide a self-contained, concise snippet of code that can be used to reproduce the issue.
|
40 |
+
For more complex issues provide a repo with the smallest sample that reproduces the bug.
|
41 |
+
|
42 |
+
Avoid including business logic or unrelated code, it makes diagnosis more difficult.
|
43 |
+
The code sample should be an SSCCE. See http://sscce.org/ for details. In short, please provide a code sample that we can copy/paste, run and reproduce.
|
44 |
+
validations:
|
45 |
+
required: true
|
46 |
+
- type: textarea
|
47 |
+
id: solution
|
48 |
+
attributes:
|
49 |
+
label: Possible Solution
|
50 |
+
description: |
|
51 |
+
Suggest a fix/reason for the bug
|
52 |
+
validations:
|
53 |
+
required: false
|
54 |
+
- type: textarea
|
55 |
+
id: context
|
56 |
+
attributes:
|
57 |
+
label: Additional Information/Context
|
58 |
+
description: |
|
59 |
+
Anything else that might be relevant for troubleshooting this bug. Providing context helps us come up with a solution that is most useful in the real world.
|
60 |
+
validations:
|
61 |
+
required: false
|
62 |
+
- type: input
|
63 |
+
id: sdk-version
|
64 |
+
attributes:
|
65 |
+
label: SDK version used
|
66 |
+
validations:
|
67 |
+
required: true
|
68 |
+
- type: input
|
69 |
+
id: environment
|
70 |
+
attributes:
|
71 |
+
label: Environment details (OS name and version, etc.)
|
72 |
+
validations:
|
73 |
+
required: true
|
vendor/aws/aws-php-sns-message-validator/.github/ISSUE_TEMPLATE/config.yml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
blank_issues_enabled: false
|
3 |
+
contact_links:
|
4 |
+
- name: 💬 General Question
|
5 |
+
url: https://github.com/aws/aws-php-sns-message-validator/discussions/categories/q-a
|
6 |
+
about: Please ask and answer questions as a discussion thread
|
vendor/aws/aws-php-sns-message-validator/.github/ISSUE_TEMPLATE/documentation.yml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
name: "📕 Documentation Issue"
|
3 |
+
description: Report an issue in the API Reference documentation or Developer Guide
|
4 |
+
title: "(short issue description)"
|
5 |
+
labels: [documentation, needs-triage]
|
6 |
+
assignees: []
|
7 |
+
body:
|
8 |
+
- type: textarea
|
9 |
+
id: description
|
10 |
+
attributes:
|
11 |
+
label: Describe the issue
|
12 |
+
description: A clear and concise description of the issue.
|
13 |
+
validations:
|
14 |
+
required: true
|
15 |
+
|
16 |
+
- type: textarea
|
17 |
+
id: links
|
18 |
+
attributes:
|
19 |
+
label: Links
|
20 |
+
description: |
|
21 |
+
Include links to affected documentation page(s).
|
22 |
+
validations:
|
23 |
+
required: true
|
vendor/aws/aws-php-sns-message-validator/.github/ISSUE_TEMPLATE/feature-request.yml
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
name: 🚀 Feature Request
|
3 |
+
description: Suggest an idea for this project
|
4 |
+
title: "(short issue description)"
|
5 |
+
labels: [feature-request, needs-triage]
|
6 |
+
assignees: []
|
7 |
+
body:
|
8 |
+
- type: textarea
|
9 |
+
id: description
|
10 |
+
attributes:
|
11 |
+
label: Describe the feature
|
12 |
+
description: A clear and concise description of the feature you are proposing.
|
13 |
+
validations:
|
14 |
+
required: true
|
15 |
+
- type: textarea
|
16 |
+
id: use-case
|
17 |
+
attributes:
|
18 |
+
label: Use Case
|
19 |
+
description: |
|
20 |
+
Why do you need this feature? For example: "I'm always frustrated when..."
|
21 |
+
validations:
|
22 |
+
required: true
|
23 |
+
- type: textarea
|
24 |
+
id: solution
|
25 |
+
attributes:
|
26 |
+
label: Proposed Solution
|
27 |
+
description: |
|
28 |
+
Suggest how to implement the addition or change. Please include prototype/workaround/sketch/reference implementation.
|
29 |
+
validations:
|
30 |
+
required: false
|
31 |
+
- type: textarea
|
32 |
+
id: other
|
33 |
+
attributes:
|
34 |
+
label: Other Information
|
35 |
+
description: |
|
36 |
+
Any alternative solutions or features you considered, a more detailed explanation, stack traces, related issues, links for context, etc.
|
37 |
+
validations:
|
38 |
+
required: false
|
39 |
+
- type: checkboxes
|
40 |
+
id: ack
|
41 |
+
attributes:
|
42 |
+
label: Acknowledgements
|
43 |
+
options:
|
44 |
+
- label: I may be able to implement this feature request
|
45 |
+
required: false
|
46 |
+
- label: This feature might incur a breaking change
|
47 |
+
required: false
|
48 |
+
- type: input
|
49 |
+
id: sdk-version
|
50 |
+
attributes:
|
51 |
+
label: SDK version used
|
52 |
+
validations:
|
53 |
+
required: true
|
54 |
+
- type: input
|
55 |
+
id: environment
|
56 |
+
attributes:
|
57 |
+
label: Environment details (OS name and version, etc.)
|
58 |
+
validations:
|
59 |
+
required: true
|
vendor/aws/aws-php-sns-message-validator/.github/PULL_REQUEST_TEMPLATE.md
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*Issue #, if available:*
|
2 |
+
|
3 |
+
*Description of changes:*
|
4 |
+
|
5 |
+
|
6 |
+
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
|
vendor/aws/aws-php-sns-message-validator/.github/workflows/stale_issues.yml
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "Close stale issues"
|
2 |
+
|
3 |
+
# Controls when the action will run.
|
4 |
+
on:
|
5 |
+
schedule:
|
6 |
+
- cron: "0 0 * * *"
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
cleanup:
|
10 |
+
runs-on: ubuntu-latest
|
11 |
+
name: Stale issue job
|
12 |
+
steps:
|
13 |
+
- uses: aws-actions/stale-issue-cleanup@v3
|
14 |
+
with:
|
15 |
+
# Setting messages to an empty string will cause the automation to skip
|
16 |
+
# that category
|
17 |
+
ancient-issue-message: We have noticed this issue has not recieved attention in 3 years. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.
|
18 |
+
stale-issue-message: This issue has not recieved a response in 1 week. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.
|
19 |
+
|
20 |
+
# These labels are required
|
21 |
+
stale-issue-label: closing-soon
|
22 |
+
exempt-issue-label: no-autoclose
|
23 |
+
stale-pr-label: no-pr-activity
|
24 |
+
exempt-pr-label: awaiting-approval
|
25 |
+
response-requested-label: response-requested
|
26 |
+
|
27 |
+
# Don't set closed-for-staleness label to skip closing very old issues
|
28 |
+
# regardless of label
|
29 |
+
closed-for-staleness-label: closed-for-staleness
|
30 |
+
|
31 |
+
# Issue timing
|
32 |
+
days-before-stale: 7
|
33 |
+
days-before-close: 4
|
34 |
+
days-before-ancient: 1095
|
35 |
+
|
36 |
+
# If you don't want to mark a issue as being ancient based on a
|
37 |
+
# threshold of "upvotes", you can set this here. An "upvote" is
|
38 |
+
# the total number of +1, heart, hooray, and rocket reactions
|
39 |
+
# on an issue.
|
40 |
+
minimum-upvotes-to-exempt: 10
|
41 |
+
|
42 |
+
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
43 |
+
loglevel: DEBUG
|
44 |
+
# Set dry-run to true to not perform label or close actions.
|
45 |
+
# dry-run: true
|
vendor/aws/aws-php-sns-message-validator/.gitignore
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
phpunit.xml
|
2 |
+
Makefile
|
3 |
+
/.idea/
|
4 |
+
/*.iml
|
5 |
+
atlassian-ide-plugin.xml
|
6 |
+
.DS_Store
|
7 |
+
.swp
|
8 |
+
.build
|
9 |
+
composer.lock
|
10 |
+
vendor/
|
vendor/aws/aws-php-sns-message-validator/.travis.yml
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
dist: trusty
|
2 |
+
|
3 |
+
language: php
|
4 |
+
|
5 |
+
php:
|
6 |
+
- 5.4
|
7 |
+
- 5.5
|
8 |
+
- 5.6
|
9 |
+
- 7.0
|
10 |
+
- 7.1
|
11 |
+
- 7.2
|
12 |
+
- 7.3
|
13 |
+
- hhvm
|
14 |
+
- nightly
|
15 |
+
|
16 |
+
matrix:
|
17 |
+
allow_failures:
|
18 |
+
- php: hhvm
|
19 |
+
- php: nightly
|
20 |
+
|
21 |
+
sudo: false
|
22 |
+
dist: trusty
|
23 |
+
|
24 |
+
install:
|
25 |
+
- travis_retry composer update --no-interaction --prefer-dist
|
26 |
+
|
27 |
+
script: vendor/bin/phpunit
|
vendor/aws/aws-php-sns-message-validator/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
## Code of Conduct
|
2 |
+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
|
3 |
+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
|
4 |
+
opensource-codeofconduct@amazon.com with any additional questions or comments.
|
vendor/aws/aws-php-sns-message-validator/CONTRIBUTING.md
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Contributing Guidelines
|
2 |
+
|
3 |
+
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
|
4 |
+
documentation, we greatly value feedback and contributions from our community.
|
5 |
+
|
6 |
+
Please read through this document before submitting any [issues][] or [pull requests][pull-requests] to ensure we have all the necessary
|
7 |
+
information to effectively respond to your bug report or contribution.
|
8 |
+
|
9 |
+
Jump To:
|
10 |
+
|
11 |
+
* [Bug Reports](_#Bug-Reports_)
|
12 |
+
* [Feature Requests](_#Feature-Requests_)
|
13 |
+
* [Code Contributions](_#Code-Contributions_)
|
14 |
+
* [Code of Conduct](_#Code-of-Conduct_)
|
15 |
+
* [Security issue notifications](_#Security-issue-notifications_)
|
16 |
+
* [Licensing](_#Licensing_)
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
## How to contribute
|
21 |
+
|
22 |
+
*Before you send us a pull request, please be sure that:*
|
23 |
+
|
24 |
+
1. You're working from the latest source on the master branch.
|
25 |
+
1. You check existing open, and recently closed, pull requests to be sure that
|
26 |
+
someone else hasn't already addressed the problem.
|
27 |
+
1. You create an issue before working on a contribution that will take a significant
|
28 |
+
amount of your time.
|
29 |
+
|
30 |
+
*Creating a Pull Request*
|
31 |
+
|
32 |
+
1. Fork the repository.
|
33 |
+
1. In your fork, make your change in a branch that's based on this repo's master branch.
|
34 |
+
1. Commit the change to your fork, using a clear and descriptive commit message.
|
35 |
+
1. Create a pull request, answering any questions in the pull request form.
|
36 |
+
|
37 |
+
For contributions that will take a significant amount of time, open a new issue to pitch
|
38 |
+
your idea before you get started. Explain the problem and describe the content you want to
|
39 |
+
see added to the documentation. Let us know if you'll write it yourself or if you'd like us
|
40 |
+
to help. We'll discuss your proposal with you and let you know whether we're likely to
|
41 |
+
accept it.
|
42 |
+
|
43 |
+
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
|
44 |
+
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
|
45 |
+
|
46 |
+
|
47 |
+
## Bug Reports
|
48 |
+
|
49 |
+
Bug reports are accepted through the [Issues][] page.
|
50 |
+
|
51 |
+
Before Submitting:
|
52 |
+
|
53 |
+
* Do a search through the existing issues to make sure it has not already been reported.
|
54 |
+
If it has, comment your experience or +1 so we prioritize it.
|
55 |
+
* If possible, upgrade to the latest release of the SDK. It's possible the bug has
|
56 |
+
already been fixed in the latest version.
|
57 |
+
|
58 |
+
Writing the Bug Report:
|
59 |
+
|
60 |
+
Please ensure that your bug report has the following:
|
61 |
+
|
62 |
+
* A short, descriptive title. Ideally, other community members should be able to get a
|
63 |
+
good idea of the issue just from reading the title.
|
64 |
+
* A detailed description of the problem you're experiencing. This should include:
|
65 |
+
* Expected behavior of the SDK and the actual behavior exhibited.
|
66 |
+
* Any details of your application environment that may be relevant.
|
67 |
+
* Debug information, stack trace or logs.
|
68 |
+
* If you are able to create one, include a Minimal Working Example that reproduces the issue.
|
69 |
+
* Use Markdown to make the report easier to read; i.e. use code blocks when pasting a
|
70 |
+
code snippet.
|
71 |
+
|
72 |
+
## Feature Requests:
|
73 |
+
|
74 |
+
Open an [issue][] with the following:
|
75 |
+
|
76 |
+
* A short, descriptive title. Ideally, other community members should be able to get a
|
77 |
+
good idea of the feature just from reading the title.
|
78 |
+
* A detailed description of the the proposed feature.
|
79 |
+
* Why it should be added to the SDK.
|
80 |
+
* If possible, example code to illustrate how it should work.
|
81 |
+
* Use Markdown to make the request easier to read;
|
82 |
+
* If you intend to implement this feature, indicate that you'd like to the issue to be
|
83 |
+
assigned to you.
|
84 |
+
|
85 |
+
## Bug Reports
|
86 |
+
|
87 |
+
Bug reports are accepted through the [Issues][] page.
|
88 |
+
|
89 |
+
Before Submitting:
|
90 |
+
|
91 |
+
* Do a search through the existing issues to make sure it has not already been reported.
|
92 |
+
If it has, comment your experience or +1 so we prioritize it.
|
93 |
+
* If possible, upgrade to the latest release of the SDK. It's possible the bug has
|
94 |
+
already been fixed in the latest version.
|
95 |
+
|
96 |
+
Writing the Bug Report:
|
97 |
+
|
98 |
+
Please ensure that your bug report has the following:
|
99 |
+
|
100 |
+
* A short, descriptive title. Ideally, other community members should be able to get a
|
101 |
+
good idea of the issue just from reading the title.
|
102 |
+
* A detailed description of the problem you're experiencing. This should include:
|
103 |
+
* Expected behavior of the SDK and the actual behavior exhibited.
|
104 |
+
* Any details of your application environment that may be relevant.
|
105 |
+
* Debug information, stack trace or logs.
|
106 |
+
* If you are able to create one, include a Minimal Working Example that reproduces the issue.
|
107 |
+
* Use Markdown to make the report easier to read; i.e. use code blocks when pasting a
|
108 |
+
code snippet.
|
109 |
+
|
110 |
+
|
111 |
+
## Code of Conduct
|
112 |
+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
|
113 |
+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
|
114 |
+
opensource-codeofconduct@amazon.com with any additional questions or comments.
|
115 |
+
|
116 |
+
|
117 |
+
## Security issue notifications
|
118 |
+
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
|
119 |
+
|
120 |
+
|
121 |
+
## Licensing
|
122 |
+
|
123 |
+
See the [LICENSE](https://github.com/aws/aws-php-sns-message-validator/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
|
124 |
+
|
125 |
+
We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes.
|
vendor/aws/aws-php-sns-message-validator/LICENSE.md
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
|
4 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
5 |
+
|
6 |
+
## 1. Definitions.
|
7 |
+
|
8 |
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1
|
9 |
+
through 9 of this document.
|
10 |
+
|
11 |
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the
|
12 |
+
License.
|
13 |
+
|
14 |
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled
|
15 |
+
by, or are under common control with that entity. For the purposes of this definition, "control" means
|
16 |
+
(i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract
|
17 |
+
or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
|
18 |
+
ownership of such entity.
|
19 |
+
|
20 |
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
21 |
+
|
22 |
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software
|
23 |
+
source code, documentation source, and configuration files.
|
24 |
+
|
25 |
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form,
|
26 |
+
including but not limited to compiled object code, generated documentation, and conversions to other media
|
27 |
+
types.
|
28 |
+
|
29 |
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License,
|
30 |
+
as indicated by a copyright notice that is included in or attached to the work (an example is provided in the
|
31 |
+
Appendix below).
|
32 |
+
|
33 |
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from)
|
34 |
+
the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent,
|
35 |
+
as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not
|
36 |
+
include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work
|
37 |
+
and Derivative Works thereof.
|
38 |
+
|
39 |
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any
|
40 |
+
modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to
|
41 |
+
Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to
|
42 |
+
submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of
|
43 |
+
electronic, verbal, or written communication sent to the Licensor or its representatives, including but not
|
44 |
+
limited to communication on electronic mailing lists, source code control systems, and issue tracking systems
|
45 |
+
that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but
|
46 |
+
excluding communication that is conspicuously marked or otherwise designated in writing by the copyright
|
47 |
+
owner as "Not a Contribution."
|
48 |
+
|
49 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been
|
50 |
+
received by Licensor and subsequently incorporated within the Work.
|
51 |
+
|
52 |
+
## 2. Grant of Copyright License.
|
53 |
+
|
54 |
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual,
|
55 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare
|
56 |
+
Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such
|
57 |
+
Derivative Works in Source or Object form.
|
58 |
+
|
59 |
+
## 3. Grant of Patent License.
|
60 |
+
|
61 |
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual,
|
62 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
63 |
+
license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such
|
64 |
+
license applies only to those patent claims licensable by such Contributor that are necessarily infringed by
|
65 |
+
their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such
|
66 |
+
Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim
|
67 |
+
or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work
|
68 |
+
constitutes direct or contributory patent infringement, then any patent licenses granted to You under this
|
69 |
+
License for that Work shall terminate as of the date such litigation is filed.
|
70 |
+
|
71 |
+
## 4. Redistribution.
|
72 |
+
|
73 |
+
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without
|
74 |
+
modifications, and in Source or Object form, provided that You meet the following conditions:
|
75 |
+
|
76 |
+
1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
77 |
+
|
78 |
+
2. You must cause any modified files to carry prominent notices stating that You changed the files; and
|
79 |
+
|
80 |
+
3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent,
|
81 |
+
trademark, and attribution notices from the Source form of the Work, excluding those notices that do
|
82 |
+
not pertain to any part of the Derivative Works; and
|
83 |
+
|
84 |
+
4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that
|
85 |
+
You distribute must include a readable copy of the attribution notices contained within such NOTICE
|
86 |
+
file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one
|
87 |
+
of the following places: within a NOTICE text file distributed as part of the Derivative Works; within
|
88 |
+
the Source form or documentation, if provided along with the Derivative Works; or, within a display
|
89 |
+
generated by the Derivative Works, if and wherever such third-party notices normally appear. The
|
90 |
+
contents of the NOTICE file are for informational purposes only and do not modify the License. You may
|
91 |
+
add Your own attribution notices within Derivative Works that You distribute, alongside or as an
|
92 |
+
addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be
|
93 |
+
construed as modifying the License.
|
94 |
+
|
95 |
+
You may add Your own copyright statement to Your modifications and may provide additional or different license
|
96 |
+
terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative
|
97 |
+
Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the
|
98 |
+
conditions stated in this License.
|
99 |
+
|
100 |
+
## 5. Submission of Contributions.
|
101 |
+
|
102 |
+
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by
|
103 |
+
You to the Licensor shall be under the terms and conditions of this License, without any additional terms or
|
104 |
+
conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate
|
105 |
+
license agreement you may have executed with Licensor regarding such Contributions.
|
106 |
+
|
107 |
+
## 6. Trademarks.
|
108 |
+
|
109 |
+
This License does not grant permission to use the trade names, trademarks, service marks, or product names of
|
110 |
+
the Licensor, except as required for reasonable and customary use in describing the origin of the Work and
|
111 |
+
reproducing the content of the NOTICE file.
|
112 |
+
|
113 |
+
## 7. Disclaimer of Warranty.
|
114 |
+
|
115 |
+
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor
|
116 |
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
117 |
+
or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
|
118 |
+
MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the
|
119 |
+
appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of
|
120 |
+
permissions under this License.
|
121 |
+
|
122 |
+
## 8. Limitation of Liability.
|
123 |
+
|
124 |
+
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless
|
125 |
+
required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any
|
126 |
+
Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential
|
127 |
+
damages of any character arising as a result of this License or out of the use or inability to use the Work
|
128 |
+
(including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
129 |
+
any and all other commercial damages or losses), even if such Contributor has been advised of the possibility
|
130 |
+
of such damages.
|
131 |
+
|
132 |
+
## 9. Accepting Warranty or Additional Liability.
|
133 |
+
|
134 |
+
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for,
|
135 |
+
acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this
|
136 |
+
License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole
|
137 |
+
responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold
|
138 |
+
each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason
|
139 |
+
of your accepting any such warranty or additional liability.
|
140 |
+
|
141 |
+
END OF TERMS AND CONDITIONS
|
vendor/aws/aws-php-sns-message-validator/NOTICE.md
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Amazon SNS Message Validator for PHP
|
2 |
+
|
3 |
+
<http://aws.amazon.com/php>
|
4 |
+
|
5 |
+
Copyright 2010-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
6 |
+
|
7 |
+
Licensed under the Apache License, Version 2.0 (the "License").
|
8 |
+
You may not use this file except in compliance with the License.
|
9 |
+
A copy of the License is located at
|
10 |
+
|
11 |
+
<http://aws.amazon.com/apache2.0>
|
12 |
+
|
13 |
+
or in the "license" file accompanying this file. This file is distributed
|
14 |
+
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
15 |
+
express or implied. See the License for the specific language governing
|
16 |
+
permissions and limitations under the License.
|
vendor/aws/aws-php-sns-message-validator/README.md
ADDED
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Amazon SNS Message Validator for PHP
|
2 |
+
|
3 |
+
[![@awsforphp on Twitter](http://img.shields.io/badge/twitter-%40awsforphp-blue.svg?style=flat)](https://twitter.com/awsforphp)
|
4 |
+
[![Total Downloads](https://img.shields.io/packagist/dt/aws/aws-php-sns-message-validator.svg?style=flat)](https://packagist.org/packages/aws/aws-php-sns-message-validator)
|
5 |
+
[![Build Status](https://img.shields.io/travis/aws/aws-php-sns-message-validator.svg?style=flat)](https://travis-ci.org/aws/aws-php-sns-message-validator)
|
6 |
+
[![Apache 2 License](https://img.shields.io/packagist/l/aws/aws-php-sns-message-validator.svg?style=flat)](http://aws.amazon.com/apache-2-0/)
|
7 |
+
|
8 |
+
The **Amazon SNS Message Validator for PHP** library allows you to validate that
|
9 |
+
incoming HTTP(S) POST messages are valid Amazon SNS notifications. This library
|
10 |
+
is standalone and does not depend on the AWS SDK for PHP or Guzzle; however, it
|
11 |
+
does require PHP 5.4+ and that the OpenSSL PHP extension is installed.
|
12 |
+
|
13 |
+
Jump To:
|
14 |
+
* [Basic Usage](_#Basic-Usage_)
|
15 |
+
* [Installation](_#Installation_)
|
16 |
+
* [About Amazon SNS](_#About-Amazon-SNS_)
|
17 |
+
* [Handling Messages](_#Handling-Messages_)
|
18 |
+
* [Testing Locally](_#Testing-Locally_)
|
19 |
+
* [Contributing](_#Contributing_)
|
20 |
+
|
21 |
+
## Basic Usage
|
22 |
+
|
23 |
+
To validate a message, you can instantiate a `Message` object from the POST
|
24 |
+
data using the `Message::fromRawPostData`. This reads the raw POST data from
|
25 |
+
the [`php://input` stream][php-input], decodes the JSON data, and validates
|
26 |
+
the message's type and structure.
|
27 |
+
|
28 |
+
Next, you must create an instance of `MessageValidator`, and then use either
|
29 |
+
the `isValid()` or `validate()`, methods to validate the message. The
|
30 |
+
message validator checks the `SigningCertURL`, `SignatureVersion`, and
|
31 |
+
`Signature` to make sure they are valid and consistent with the message data.
|
32 |
+
|
33 |
+
```php
|
34 |
+
<?php
|
35 |
+
|
36 |
+
require 'vendor/autoload.php';
|
37 |
+
|
38 |
+
use Aws\Sns\Message;
|
39 |
+
use Aws\Sns\MessageValidator;
|
40 |
+
|
41 |
+
$message = Message::fromRawPostData();
|
42 |
+
|
43 |
+
// Validate the message
|
44 |
+
$validator = new MessageValidator();
|
45 |
+
if ($validator->isValid($message)) {
|
46 |
+
// do something with the message
|
47 |
+
}
|
48 |
+
```
|
49 |
+
|
50 |
+
## Installation
|
51 |
+
|
52 |
+
The SNS Message Validator can be installed via [Composer][].
|
53 |
+
|
54 |
+
$ composer require aws/aws-php-sns-message-validator
|
55 |
+
|
56 |
+
## Getting Help
|
57 |
+
|
58 |
+
Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests and have limited bandwidth to address them.
|
59 |
+
|
60 |
+
* Ask a question on [StackOverflow](https://stackoverflow.com/) and tag it with [`aws-php-sdk`](http://stackoverflow.com/questions/tagged/aws-php-sdk)
|
61 |
+
* Come join the AWS SDK for PHP [gitter](https://gitter.im/aws/aws-sdk-php)
|
62 |
+
* Open a support ticket with [AWS Support](https://console.aws.amazon.com/support/home/)
|
63 |
+
* If it turns out that you may have found a bug, please [open an issue](https://github.com/aws/aws-php-sns-message-validator/issues/new/choose)
|
64 |
+
|
65 |
+
## About Amazon SNS
|
66 |
+
|
67 |
+
[Amazon Simple Notification Service (Amazon SNS)][sns] is a fast, fully-managed,
|
68 |
+
push messaging service. Amazon SNS can deliver messages to email, mobile devices
|
69 |
+
(i.e., SMS; iOS, Android and FireOS push notifications), Amazon SQS queues,and
|
70 |
+
— of course — HTTP/HTTPS endpoints.
|
71 |
+
|
72 |
+
With Amazon SNS, you can setup topics to publish custom messages to subscribed
|
73 |
+
endpoints. However, SNS messages are used by many of the other AWS services to
|
74 |
+
communicate information asynchronously about your AWS resources. Some examples
|
75 |
+
include:
|
76 |
+
|
77 |
+
* Configuring Amazon Glacier to notify you when a retrieval job is complete.
|
78 |
+
* Configuring AWS CloudTrail to notify you when a new log file has been written.
|
79 |
+
* Configuring Amazon Elastic Transcoder to notify you when a transcoding job
|
80 |
+
changes status (e.g., from "Progressing" to "Complete")
|
81 |
+
|
82 |
+
Though you can certainly subscribe your email address to receive SNS messages
|
83 |
+
from service events like these, your inbox would fill up rather quickly. There
|
84 |
+
is great power, however, in being able to subscribe an HTTP/HTTPS endpoint to
|
85 |
+
receive the messages. This allows you to program webhooks for your applications
|
86 |
+
to easily respond to various events.
|
87 |
+
|
88 |
+
## Handling Messages
|
89 |
+
|
90 |
+
### Confirming a Subscription to a Topic
|
91 |
+
|
92 |
+
In order to handle a `SubscriptionConfirmation` message, you must use the
|
93 |
+
`SubscribeURL` value in the incoming message:
|
94 |
+
|
95 |
+
```php
|
96 |
+
use Aws\Sns\Message;
|
97 |
+
use Aws\Sns\MessageValidator;
|
98 |
+
use Aws\Sns\Exception\InvalidSnsMessageException;
|
99 |
+
|
100 |
+
// Instantiate the Message and Validator
|
101 |
+
$message = Message::fromRawPostData();
|
102 |
+
$validator = new MessageValidator();
|
103 |
+
|
104 |
+
// Validate the message and log errors if invalid.
|
105 |
+
try {
|
106 |
+
$validator->validate($message);
|
107 |
+
} catch (InvalidSnsMessageException $e) {
|
108 |
+
// Pretend we're not here if the message is invalid.
|
109 |
+
http_response_code(404);
|
110 |
+
error_log('SNS Message Validation Error: ' . $e->getMessage());
|
111 |
+
die();
|
112 |
+
}
|
113 |
+
|
114 |
+
// Check the type of the message and handle the subscription.
|
115 |
+
if ($message['Type'] === 'SubscriptionConfirmation') {
|
116 |
+
// Confirm the subscription by sending a GET request to the SubscribeURL
|
117 |
+
file_get_contents($message['SubscribeURL']);
|
118 |
+
}
|
119 |
+
```
|
120 |
+
|
121 |
+
### Receiving a Notification
|
122 |
+
|
123 |
+
To receive a notification, use the same code as the preceding example, but
|
124 |
+
check for the `Notification` message type.
|
125 |
+
|
126 |
+
```php
|
127 |
+
if ($message['Type'] === 'Notification') {
|
128 |
+
// Do whatever you want with the message body and data.
|
129 |
+
echo $message['MessageId'] . ': ' . $message['Message'] . "\n";
|
130 |
+
}
|
131 |
+
```
|
132 |
+
|
133 |
+
The message body will be a string, and will hold whatever data was published
|
134 |
+
to the SNS topic.
|
135 |
+
|
136 |
+
### Unsubscribing
|
137 |
+
|
138 |
+
Unsubscribing looks the same as subscribing, except the message type will be
|
139 |
+
`UnsubscribeConfirmation`.
|
140 |
+
|
141 |
+
```php
|
142 |
+
if ($message['Type'] === 'UnsubscribeConfirmation') {
|
143 |
+
// Unsubscribed in error? You can resubscribe by visiting the endpoint
|
144 |
+
// provided as the message's SubscribeURL field.
|
145 |
+
file_get_contents($message['SubscribeURL']);
|
146 |
+
}
|
147 |
+
```
|
148 |
+
|
149 |
+
## Testing Locally
|
150 |
+
|
151 |
+
One challenge of using webhooks in a web application is testing the integration
|
152 |
+
with the service. Testing integrations with SNS notifications can be fairly easy
|
153 |
+
using tools like [ngrok][] and [PHP's built-in webserver][php-server]. One of
|
154 |
+
our blog posts, [*Testing Webhooks Locally for Amazon SNS*][blogpost], illustrates
|
155 |
+
a good technique for testing.
|
156 |
+
|
157 |
+
> **NOTE:** The code samples in the blog post are specific to the message
|
158 |
+
> validator in Version 2 of the SDK, but can be easily adapted to using this
|
159 |
+
> version.
|
160 |
+
|
161 |
+
### Special Thank You
|
162 |
+
|
163 |
+
A special thanks goes out to [Julian Vidal][] who helped create the [initial
|
164 |
+
implementation][] in Version 2 of the [AWS SDK for PHP][].
|
165 |
+
|
166 |
+
[php-input]: http://php.net/manual/en/wrappers.php.php#wrappers.php.input
|
167 |
+
[composer]: https://getcomposer.org/
|
168 |
+
[source code]: https://github.com/aws/aws-php-sns-message-validator/archive/master.zip
|
169 |
+
[sns]: http://aws.amazon.com/sns/
|
170 |
+
[ngrok]: https://ngrok.com/
|
171 |
+
[php-server]: http://www.php.net/manual/en/features.commandline.webserver.php
|
172 |
+
[blogpost]: http://blogs.aws.amazon.com/php/post/Tx2CO24DVG9CAK0/Testing-Webhooks-Locally-for-Amazon-SNS
|
173 |
+
[Julian Vidal]: https://github.com/poisa
|
174 |
+
[initial implementation]: https://github.com/aws/aws-sdk-php/tree/2.8/src/Aws/Sns/MessageValidator
|
175 |
+
[AWS SDK for PHP]: https://github.com/aws/aws-sdk-php
|
176 |
+
|
177 |
+
## Contributing
|
178 |
+
|
179 |
+
We work hard to provide a high-quality and useful SDK for our AWS services, and we greatly value feedback and contributions from our community. Please review our [contributing guidelines](./CONTRIBUTING.md) before submitting any issues or pull requests to ensure we have all the necessary information to effectively respond to your bug report or contribution.
|
vendor/aws/aws-php-sns-message-validator/composer.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "aws/aws-php-sns-message-validator",
|
3 |
+
"homepage": "http://aws.amazon.com/sdkforphp",
|
4 |
+
"description": "Amazon SNS message validation for PHP",
|
5 |
+
"keywords": ["aws","amazon","sdk","sns","message","webhooks","cloud"],
|
6 |
+
"type": "library",
|
7 |
+
"license": "Apache-2.0",
|
8 |
+
"authors": [
|
9 |
+
{
|
10 |
+
"name": "Amazon Web Services",
|
11 |
+
"homepage": "http://aws.amazon.com"
|
12 |
+
}
|
13 |
+
],
|
14 |
+
"support": {
|
15 |
+
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
|
16 |
+
"issues": "https://github.com/aws/aws-sns-message-validator/issues"
|
17 |
+
},
|
18 |
+
"require": {
|
19 |
+
"php": ">=5.4",
|
20 |
+
"ext-openssl": "*",
|
21 |
+
"psr/http-message": "^1.0"
|
22 |
+
},
|
23 |
+
"require-dev": {
|
24 |
+
"phpunit/phpunit": "^4.0",
|
25 |
+
"squizlabs/php_codesniffer": "^2.3",
|
26 |
+
"guzzlehttp/psr7": "^1.4"
|
27 |
+
},
|
28 |
+
"autoload": {
|
29 |
+
"psr-4": { "Aws\\Sns\\": "src/" }
|
30 |
+
},
|
31 |
+
"autoload-dev": {
|
32 |
+
"psr-4": { "Aws\\Sns\\": "tests/" }
|
33 |
+
},
|
34 |
+
"scripts": {
|
35 |
+
"test": "phpunit"
|
36 |
+
}
|
37 |
+
}
|
vendor/aws/aws-php-sns-message-validator/phpunit.xml.dist
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
|
3 |
+
<phpunit bootstrap="./vendor/autoload.php">
|
4 |
+
<testsuites>
|
5 |
+
<testsuite name="AWS SNS Message Validator Test Suite">
|
6 |
+
<directory>./tests</directory>
|
7 |
+
</testsuite>
|
8 |
+
</testsuites>
|
9 |
+
|
10 |
+
<filter>
|
11 |
+
<whitelist>
|
12 |
+
<directory suffix=".php">src/</directory>
|
13 |
+
</whitelist>
|
14 |
+
</filter>
|
15 |
+
</phpunit>
|
vendor/aws/aws-php-sns-message-validator/src/Exception/InvalidSnsMessageException.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace Aws\Sns\Exception;
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Runtime exception thrown by the SNS Message Validator.
|
6 |
+
*/
|
7 |
+
class InvalidSnsMessageException extends \RuntimeException
|
8 |
+
{
|
9 |
+
}
|
vendor/aws/aws-php-sns-message-validator/src/Message.php
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace Aws\Sns;
|
3 |
+
|
4 |
+
use Psr\Http\Message\RequestInterface;
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Represents an SNS message received over http(s).
|
8 |
+
*/
|
9 |
+
class Message implements \ArrayAccess, \IteratorAggregate
|
10 |
+
{
|
11 |
+
private static $requiredKeys = [
|
12 |
+
'Message',
|
13 |
+
'MessageId',
|
14 |
+
'Timestamp',
|
15 |
+
'TopicArn',
|
16 |
+
'Type',
|
17 |
+
'Signature',
|
18 |
+
['SigningCertURL', 'SigningCertUrl'],
|
19 |
+
'SignatureVersion',
|
20 |
+
];
|
21 |
+
|
22 |
+
private static $subscribeKeys = [
|
23 |
+
['SubscribeURL', 'SubscribeUrl'],
|
24 |
+
'Token'
|
25 |
+
];
|
26 |
+
|
27 |
+
/** @var array The message data */
|
28 |
+
private $data;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Creates a Message object from the raw POST data
|
32 |
+
*
|
33 |
+
* @return Message
|
34 |
+
* @throws \RuntimeException If the POST data is absent, or not a valid JSON document
|
35 |
+
*/
|
36 |
+
public static function fromRawPostData()
|
37 |
+
{
|
38 |
+
// Make sure the SNS-provided header exists.
|
39 |
+
if (!isset($_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE'])) {
|
40 |
+
throw new \RuntimeException('SNS message type header not provided.');
|
41 |
+
}
|
42 |
+
|
43 |
+
// Read the raw POST data and JSON-decode it into a message.
|
44 |
+
return self::fromJsonString(file_get_contents('php://input'));
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Creates a Message object from a PSR-7 Request or ServerRequest object.
|
49 |
+
*
|
50 |
+
* @param RequestInterface $request
|
51 |
+
* @return Message
|
52 |
+
*/
|
53 |
+
public static function fromPsrRequest(RequestInterface $request)
|
54 |
+
{
|
55 |
+
return self::fromJsonString($request->getBody());
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Creates a Message object from a JSON-decodable string.
|
60 |
+
*
|
61 |
+
* @param string $requestBody
|
62 |
+
* @return Message
|
63 |
+
*/
|
64 |
+
public static function fromJsonString($requestBody)
|
65 |
+
{
|
66 |
+
$data = json_decode($requestBody, true);
|
67 |
+
if (JSON_ERROR_NONE !== json_last_error() || !is_array($data)) {
|
68 |
+
throw new \RuntimeException('Invalid POST data.');
|
69 |
+
}
|
70 |
+
|
71 |
+
return new Message($data);
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Creates a Message object from an array of raw message data.
|
76 |
+
*
|
77 |
+
* @param array $data The message data.
|
78 |
+
*
|
79 |
+
* @throws \InvalidArgumentException If a valid type is not provided or
|
80 |
+
* there are other required keys missing.
|
81 |
+
*/
|
82 |
+
public function __construct(array $data)
|
83 |
+
{
|
84 |
+
// Ensure that all the required keys for the message's type are present.
|
85 |
+
$this->validateRequiredKeys($data, self::$requiredKeys);
|
86 |
+
if ($data['Type'] === 'SubscriptionConfirmation'
|
87 |
+
|| $data['Type'] === 'UnsubscribeConfirmation'
|
88 |
+
) {
|
89 |
+
$this->validateRequiredKeys($data, self::$subscribeKeys);
|
90 |
+
}
|
91 |
+
|
92 |
+
$this->data = $data;
|
93 |
+
}
|
94 |
+
|
95 |
+
#[\ReturnTypeWillChange]
|
96 |
+
public function getIterator()
|
97 |
+
{
|
98 |
+
return new \ArrayIterator($this->data);
|
99 |
+
}
|
100 |
+
|
101 |
+
#[\ReturnTypeWillChange]
|
102 |
+
public function offsetExists($key)
|
103 |
+
{
|
104 |
+
return isset($this->data[$key]);
|
105 |
+
}
|
106 |
+
|
107 |
+
#[\ReturnTypeWillChange]
|
108 |
+
public function offsetGet($key)
|
109 |
+
{
|
110 |
+
return isset($this->data[$key]) ? $this->data[$key] : null;
|
111 |
+
}
|
112 |
+
|
113 |
+
#[\ReturnTypeWillChange]
|
114 |
+
public function offsetSet($key, $value)
|
115 |
+
{
|
116 |
+
$this->data[$key] = $value;
|
117 |
+
}
|
118 |
+
|
119 |
+
#[\ReturnTypeWillChange]
|
120 |
+
public function offsetUnset($key)
|
121 |
+
{
|
122 |
+
unset($this->data[$key]);
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Get all the message data as a plain array.
|
127 |
+
*
|
128 |
+
* @return array
|
129 |
+
*/
|
130 |
+
public function toArray()
|
131 |
+
{
|
132 |
+
return $this->data;
|
133 |
+
}
|
134 |
+
|
135 |
+
private function validateRequiredKeys(array $data, array $keys)
|
136 |
+
{
|
137 |
+
foreach ($keys as $key) {
|
138 |
+
$keyIsArray = is_array($key);
|
139 |
+
if (!$keyIsArray) {
|
140 |
+
$found = isset($data[$key]);
|
141 |
+
} else {
|
142 |
+
$found = false;
|
143 |
+
foreach ($key as $keyOption) {
|
144 |
+
if (isset($data[$keyOption])) {
|
145 |
+
$found = true;
|
146 |
+
break;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
if (!$found) {
|
152 |
+
if ($keyIsArray) {
|
153 |
+
$key = $key[0];
|
154 |
+
}
|
155 |
+
throw new \InvalidArgumentException(
|
156 |
+
"\"{$key}\" is required to verify the SNS Message."
|
157 |
+
);
|
158 |
+
}
|
159 |
+
}
|
160 |
+
}
|
161 |
+
}
|
vendor/aws/aws-php-sns-message-validator/src/MessageValidator.php
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace Aws\Sns;
|
3 |
+
|
4 |
+
use Aws\Sns\Exception\InvalidSnsMessageException;
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Uses openssl to verify SNS messages to ensure that they were sent by AWS.
|
8 |
+
*/
|
9 |
+
class MessageValidator
|
10 |
+
{
|
11 |
+
const SIGNATURE_VERSION_1 = '1';
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @var callable Callable used to download the certificate content.
|
15 |
+
*/
|
16 |
+
private $certClient;
|
17 |
+
|
18 |
+
/** @var string */
|
19 |
+
private $hostPattern;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* @var string A pattern that will match all regional SNS endpoints, e.g.:
|
23 |
+
* - sns.<region>.amazonaws.com (AWS)
|
24 |
+
* - sns.us-gov-west-1.amazonaws.com (AWS GovCloud)
|
25 |
+
* - sns.cn-north-1.amazonaws.com.cn (AWS China)
|
26 |
+
*/
|
27 |
+
private static $defaultHostPattern
|
28 |
+
= '/^sns\.[a-zA-Z0-9\-]{3,}\.amazonaws\.com(\.cn)?$/';
|
29 |
+
|
30 |
+
private static function isLambdaStyle(Message $message)
|
31 |
+
{
|
32 |
+
return isset($message['SigningCertUrl']);
|
33 |
+
}
|
34 |
+
|
35 |
+
private static function convertLambdaMessage(Message $lambdaMessage)
|
36 |
+
{
|
37 |
+
$keyReplacements = [
|
38 |
+
'SigningCertUrl' => 'SigningCertURL',
|
39 |
+
'SubscribeUrl' => 'SubscribeURL',
|
40 |
+
'UnsubscribeUrl' => 'UnsubscribeURL',
|
41 |
+
];
|
42 |
+
|
43 |
+
$message = clone $lambdaMessage;
|
44 |
+
foreach ($keyReplacements as $lambdaKey => $canonicalKey) {
|
45 |
+
if (isset($message[$lambdaKey])) {
|
46 |
+
$message[$canonicalKey] = $message[$lambdaKey];
|
47 |
+
unset($message[$lambdaKey]);
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
return $message;
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Constructs the Message Validator object and ensures that openssl is
|
56 |
+
* installed.
|
57 |
+
*
|
58 |
+
* @param callable $certClient Callable used to download the certificate.
|
59 |
+
* Should have the following function signature:
|
60 |
+
* `function (string $certUrl) : string|false $certContent`
|
61 |
+
* @param string $hostNamePattern
|
62 |
+
*/
|
63 |
+
public function __construct(
|
64 |
+
callable $certClient = null,
|
65 |
+
$hostNamePattern = ''
|
66 |
+
) {
|
67 |
+
$this->certClient = $certClient ?: function($certUrl) {
|
68 |
+
return @ file_get_contents($certUrl);
|
69 |
+
};
|
70 |
+
$this->hostPattern = $hostNamePattern ?: self::$defaultHostPattern;
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Validates a message from SNS to ensure that it was delivered by AWS.
|
75 |
+
*
|
76 |
+
* @param Message $message Message to validate.
|
77 |
+
*
|
78 |
+
* @throws InvalidSnsMessageException If the cert cannot be retrieved or its
|
79 |
+
* source verified, or the message
|
80 |
+
* signature is invalid.
|
81 |
+
*/
|
82 |
+
public function validate(Message $message)
|
83 |
+
{
|
84 |
+
if (self::isLambdaStyle($message)) {
|
85 |
+
$message = self::convertLambdaMessage($message);
|
86 |
+
}
|
87 |
+
|
88 |
+
// Get the certificate.
|
89 |
+
$this->validateUrl($message['SigningCertURL']);
|
90 |
+
$certificate = call_user_func($this->certClient, $message['SigningCertURL']);
|
91 |
+
if ($certificate === false) {
|
92 |
+
throw new InvalidSnsMessageException(
|
93 |
+
"Cannot get the certificate from \"{$message['SigningCertURL']}\"."
|
94 |
+
);
|
95 |
+
}
|
96 |
+
|
97 |
+
// Extract the public key.
|
98 |
+
$key = openssl_get_publickey($certificate);
|
99 |
+
if (!$key) {
|
100 |
+
throw new InvalidSnsMessageException(
|
101 |
+
'Cannot get the public key from the certificate.'
|
102 |
+
);
|
103 |
+
}
|
104 |
+
|
105 |
+
// Verify the signature of the message.
|
106 |
+
$content = $this->getStringToSign($message);
|
107 |
+
$signature = base64_decode($message['Signature']);
|
108 |
+
if (openssl_verify($content, $signature, $key, OPENSSL_ALGO_SHA1) != 1) {
|
109 |
+
throw new InvalidSnsMessageException(
|
110 |
+
'The message signature is invalid.'
|
111 |
+
);
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Determines if a message is valid and that is was delivered by AWS. This
|
117 |
+
* method does not throw exceptions and returns a simple boolean value.
|
118 |
+
*
|
119 |
+
* @param Message $message The message to validate
|
120 |
+
*
|
121 |
+
* @return bool
|
122 |
+
*/
|
123 |
+
public function isValid(Message $message)
|
124 |
+
{
|
125 |
+
try {
|
126 |
+
$this->validate($message);
|
127 |
+
return true;
|
128 |
+
} catch (InvalidSnsMessageException $e) {
|
129 |
+
return false;
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Builds string-to-sign according to the SNS message spec.
|
135 |
+
*
|
136 |
+
* @param Message $message Message for which to build the string-to-sign.
|
137 |
+
*
|
138 |
+
* @return string
|
139 |
+
* @link http://docs.aws.amazon.com/sns/latest/gsg/SendMessageToHttp.verify.signature.html
|
140 |
+
*/
|
141 |
+
public function getStringToSign(Message $message)
|
142 |
+
{
|
143 |
+
static $signableKeys = [
|
144 |
+
'Message',
|
145 |
+
'MessageId',
|
146 |
+
'Subject',
|
147 |
+
'SubscribeURL',
|
148 |
+
'Timestamp',
|
149 |
+
'Token',
|
150 |
+
'TopicArn',
|
151 |
+
'Type',
|
152 |
+
];
|
153 |
+
|
154 |
+
if ($message['SignatureVersion'] !== self::SIGNATURE_VERSION_1) {
|
155 |
+
throw new InvalidSnsMessageException(
|
156 |
+
"The SignatureVersion \"{$message['SignatureVersion']}\" is not supported."
|
157 |
+
);
|
158 |
+
}
|
159 |
+
|
160 |
+
$stringToSign = '';
|
161 |
+
foreach ($signableKeys as $key) {
|
162 |
+
if (isset($message[$key])) {
|
163 |
+
$stringToSign .= "{$key}\n{$message[$key]}\n";
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
return $stringToSign;
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Ensures that the URL of the certificate is one belonging to AWS, and not
|
172 |
+
* just something from the amazonaws domain, which could include S3 buckets.
|
173 |
+
*
|
174 |
+
* @param string $url Certificate URL
|
175 |
+
*
|
176 |
+
* @throws InvalidSnsMessageException if the cert url is invalid.
|
177 |
+
*/
|
178 |
+
private function validateUrl($url)
|
179 |
+
{
|
180 |
+
$parsed = parse_url($url);
|
181 |
+
if (empty($parsed['scheme'])
|
182 |
+
|| empty($parsed['host'])
|
183 |
+
|| $parsed['scheme'] !== 'https'
|
184 |
+
|| substr($url, -4) !== '.pem'
|
185 |
+
|| !preg_match($this->hostPattern, $parsed['host'])
|
186 |
+
) {
|
187 |
+
throw new InvalidSnsMessageException(
|
188 |
+
'The certificate is located on an invalid domain.'
|
189 |
+
);
|
190 |
+
}
|
191 |
+
}
|
192 |
+
}
|
vendor/aws/aws-php-sns-message-validator/tests/FunctionalValidationsTest.php
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace Aws\Sns;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* @covers Aws\Sns\MessageValidator
|
7 |
+
* @covers Aws\Sns\Message
|
8 |
+
*/
|
9 |
+
class FunctionalValidationsTest extends \PHPUnit_Framework_TestCase
|
10 |
+
{
|
11 |
+
private static $certificate =
|
12 |
+
'-----BEGIN CERTIFICATE-----
|
13 |
+
MIIF5DCCBMygAwIBAgIQMlyV8Y5saUjyFgu3K5kFwTANBgkqhkiG9w0BAQsFADB+
|
14 |
+
MQswCQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAd
|
15 |
+
BgNVBAsTFlN5bWFudGVjIFRydXN0IE5ldHdvcmsxLzAtBgNVBAMTJlN5bWFudGVj
|
16 |
+
IENsYXNzIDMgU2VjdXJlIFNlcnZlciBDQSAtIEc0MB4XDTE2MDcyNzAwMDAwMFoX
|
17 |
+
DTE3MDgyMjIzNTk1OVowazELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0
|
18 |
+
b24xEDAOBgNVBAcMB1NlYXR0bGUxGTAXBgNVBAoMEEFtYXpvbi5jb20sIEluYy4x
|
19 |
+
GjAYBgNVBAMMEXNucy5hbWF6b25hd3MuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC
|
20 |
+
AQ8AMIIBCgKCAQEAmYrVPHC2QSE/OR8w9UfnjdPqEoAfOxhwJna/2W+/C+vTrMzd
|
21 |
+
4R9E3kfA3arf43LZFTSQ23Ed3Tao8srh/iK7DFv87bR+5uPnEO4fcHXDiJ1n3WMU
|
22 |
+
kjo+BEKXwSdR4AfIRUrJB2hk3mhXJoGkYJp3WBZ2ieoYBqwxpxuFRtNQW4ttqNwt
|
23 |
+
q4mONfxg0840e1kY+xFQa7ya8zg9FGaVgeLiN+e/gv5YYdrk8JG4P6kbzil9bETm
|
24 |
+
Xm+PXoxWy6cMAT3Coz1NNkPGQrKfNfGZSdPGh1d/89IwRh+eNUEIJ8PdnhzcvgN7
|
25 |
+
RQ5zs70V6u7StvrNukYftMwY0hIELlMUHYqRbQIDAQABo4ICbzCCAmswHAYDVR0R
|
26 |
+
BBUwE4IRc25zLmFtYXpvbmF3cy5jb20wCQYDVR0TBAIwADAOBgNVHQ8BAf8EBAMC
|
27 |
+
BaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMGEGA1UdIARaMFgwVgYG
|
28 |
+
Z4EMAQICMEwwIwYIKwYBBQUHAgEWF2h0dHBzOi8vZC5zeW1jYi5jb20vY3BzMCUG
|
29 |
+
CCsGAQUFBwICMBkMF2h0dHBzOi8vZC5zeW1jYi5jb20vcnBhMB8GA1UdIwQYMBaA
|
30 |
+
FF9gz2GQVd+EQxSKYCqy9Xr0QxjvMCsGA1UdHwQkMCIwIKAeoByGGmh0dHA6Ly9z
|
31 |
+
cy5zeW1jYi5jb20vc3MuY3JsMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYT
|
32 |
+
aHR0cDovL3NzLnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL3NzLnN5bWNi
|
33 |
+
LmNvbS9zcy5jcnQwggEFBgorBgEEAdZ5AgQCBIH2BIHzAPEAdgDd6x0reg1PpiCL
|
34 |
+
ga2BaHB+Lo6dAdVciI09EcTNtuy+zAAAAVYpz1FWAAAEAwBHMEUCIFYpMqHzT/IG
|
35 |
+
WKgBt6SwXJhfYmj3JKtAJWq5dabI7TuKAiEAqYyWQUjlFuKkIwEhx8x1I+WJz+hp
|
36 |
+
npW7Na0CzyUvZWMAdwCkuQmQtBhYFIe7E6LMZ3AKPDWYBPkb37jjd80OyA3cEAAA
|
37 |
+
AVYpz1H+AAAEAwBIMEYCIQCY+492bMMCU3kRQPDQ27TRv5x+YuVkg+6ULi1Ddyea
|
38 |
+
KgIhANIVUCbM918/jMu0xc2cvrfov6SNAgPIjRLDGmDkLdJ1MA0GCSqGSIb3DQEB
|
39 |
+
CwUAA4IBAQBpQS/LverJ6gD2vuESrRi1COa4ABSLf584sL1yHLTNtf1GCUfZUgO+
|
40 |
+
CKacKGHcqxALOUi3m4PPQmuiNa20i6ttu7Q6+aj9zbq3VfJYwISFP1jLGjkiFtR2
|
41 |
+
ufBiIuB2T6dbZeYJ7Yg9DDTwwEgxHMjlT/DLyKPPPRFa0I/l3PmXMZh8iJNuxGiY
|
42 |
+
qOSxwAm9QMCaBJj+64HLyw4ZwO4rTgAxqtI/muZC3vw1nGoL7fer2X6MdW6PtYD/
|
43 |
+
ysixQTQtyDdNpB6yOGYFJv+Sf/0AcZST1a7HwfHt14JD+0I180FhGV1qFtx7KRUE
|
44 |
+
6Kw4sQp+ZMgtgzM8l3fDTMEgqpLSQH+2
|
45 |
+
-----END CERTIFICATE-----';
|
46 |
+
|
47 |
+
public function getHttpFixtures()
|
48 |
+
{
|
49 |
+
return [
|
50 |
+
[
|
51 |
+
[
|
52 |
+
'Type' => "Notification",
|
53 |
+
'MessageId' => "9438aee6-d476-5e20-ba25-ff24bf09d6ce",
|
54 |
+
'TopicArn' => "arn:aws:sns:us-west-2:604091128280:testing1",
|
55 |
+
'Subject' => "A subject",
|
56 |
+
'Message' => "A message",
|
57 |
+
'Timestamp' => "2017-06-20T00:15:59.380Z",
|
58 |
+
'SignatureVersion' => "1",
|
59 |
+
'Signature' => "WT7qMHW+jPdj/brSAX7M1jbP5OoPjn9pYmGQqrWeQgbMyVvz3D2sV72ldhCxQLqj/3TLtcTyErVqzT3AfQ8Vk55Rzxd1xnBufJ+0vIyH98b82pKOqRHOqlB72la5nY9/GF/p71BXmIChQpfv/CEZumexgLWnweJsqSMe82I6/eMmrhVZdKpBvz4Sqj+wNQW+0eYEc9bdZmEKuYIvrvTGm1MWkXmqUGuCGj5o3vFFn1GTtM895B3MyMgaSeDHI08CVfs9y1nLcrxwMvqpkHZmIwTi1jzSipYMRD8FVF6Wvq0Scy+FoYSnOWHpEsELI0SGddSqYgli9ROYiqi3DQhvHw==",
|
60 |
+
'SigningCertURL' => "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-b95095beb82e8f6a046b3aafc7f4149a.pem",
|
61 |
+
'UnsubscribeURL' => "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:604091128280:testing1:b061e4fd-c468-458d-9736-91c8c0c18e29",
|
62 |
+
]
|
63 |
+
],
|
64 |
+
[
|
65 |
+
[
|
66 |
+
'Type' => "Notification",
|
67 |
+
'MessageId' => "7317aaf2-e97a-5cf3-8123-fb3a48fabd2a",
|
68 |
+
'TopicArn' => "arn:aws:sns:us-west-2:604091128280:testing1",
|
69 |
+
'Message' => "A subject-less message",
|
70 |
+
'Timestamp' => "2017-06-24T17:20:00.581Z",
|
71 |
+
'SignatureVersion' => "1",
|
72 |
+
'Signature' => "Lvtgxo8P2C3XUKT8fC7sfMRhxoK6dn/ed9B1DClmJ9GNuFF73G27lhKUsKWrLReawa+v7C1UY49qQb+lSMsBiTV0Hx7L2OKJjzll4fx+G09h2P8OK43Jk6/W05+xU0uvch6Ktp3XrBcI6KNyGFio5GAR2rCBHjdh8MsEYAWRtaVCBqJTLqnHscivOJD8u/m807wDbDhh9cQ5WnvjerUjtrDAfQJN5vHLjEPbL1owtu2FzC3rOHUL9j4TGOdZi2jhUYv8jwzNnJ05bhbtKd6HxKcTcv1JCp/4NLPa8LWYnbLRvWooDQdF2hr56EF6EKDzTtAWagoNYztwSvosQXNK+Q==",
|
73 |
+
'SigningCertURL' => "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-b95095beb82e8f6a046b3aafc7f4149a.pem",
|
74 |
+
'UnsubscribeURL' => "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:604091128280:testing1:f0dd49ac-c33d-471e-812d-1f0e5116c711",
|
75 |
+
]
|
76 |
+
],
|
77 |
+
];
|
78 |
+
}
|
79 |
+
|
80 |
+
public function getLambdaFixtures()
|
81 |
+
{
|
82 |
+
return [
|
83 |
+
[
|
84 |
+
[
|
85 |
+
'Type' => 'Notification',
|
86 |
+
'MessageId' => '9438aee6-d476-5e20-ba25-ff24bf09d6ce',
|
87 |
+
'TopicArn' => 'arn:aws:sns:us-west-2:604091128280:testing1',
|
88 |
+
'Subject' => 'A subject',
|
89 |
+
'Message' => 'A message',
|
90 |
+
'Timestamp' => '2017-06-20T00:15:59.380Z',
|
91 |
+
'SignatureVersion' => '1',
|
92 |
+
'Signature' => 'WT7qMHW+jPdj/brSAX7M1jbP5OoPjn9pYmGQqrWeQgbMyVvz3D2sV72ldhCxQLqj/3TLtcTyErVqzT3AfQ8Vk55Rzxd1xnBufJ+0vIyH98b82pKOqRHOqlB72la5nY9/GF/p71BXmIChQpfv/CEZumexgLWnweJsqSMe82I6/eMmrhVZdKpBvz4Sqj+wNQW+0eYEc9bdZmEKuYIvrvTGm1MWkXmqUGuCGj5o3vFFn1GTtM895B3MyMgaSeDHI08CVfs9y1nLcrxwMvqpkHZmIwTi1jzSipYMRD8FVF6Wvq0Scy+FoYSnOWHpEsELI0SGddSqYgli9ROYiqi3DQhvHw==',
|
93 |
+
'SigningCertUrl' => 'https://sns.us-west-2.amazonaws.com/SimpleNotificationService-b95095beb82e8f6a046b3aafc7f4149a.pem',
|
94 |
+
'UnsubscribeUrl' => 'https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:604091128280:testing1:7118d01a-202e-4a65-a372-f46b0994bdae',
|
95 |
+
]
|
96 |
+
],
|
97 |
+
[
|
98 |
+
[
|
99 |
+
'Type' => 'Notification',
|
100 |
+
'MessageId' => '7317aaf2-e97a-5cf3-8123-fb3a48fabd2a',
|
101 |
+
'TopicArn' => 'arn:aws:sns:us-west-2:604091128280:testing1',
|
102 |
+
'Subject' => null,
|
103 |
+
'Message' => 'A subject-less message',
|
104 |
+
'Timestamp' => '2017-06-24T17:20:00.581Z',
|
105 |
+
'SignatureVersion' => '1',
|
106 |
+
'Signature' => 'Lvtgxo8P2C3XUKT8fC7sfMRhxoK6dn/ed9B1DClmJ9GNuFF73G27lhKUsKWrLReawa+v7C1UY49qQb+lSMsBiTV0Hx7L2OKJjzll4fx+G09h2P8OK43Jk6/W05+xU0uvch6Ktp3XrBcI6KNyGFio5GAR2rCBHjdh8MsEYAWRtaVCBqJTLqnHscivOJD8u/m807wDbDhh9cQ5WnvjerUjtrDAfQJN5vHLjEPbL1owtu2FzC3rOHUL9j4TGOdZi2jhUYv8jwzNnJ05bhbtKd6HxKcTcv1JCp/4NLPa8LWYnbLRvWooDQdF2hr56EF6EKDzTtAWagoNYztwSvosQXNK+Q==',
|
107 |
+
'SigningCertUrl' => 'https://sns.us-west-2.amazonaws.com/SimpleNotificationService-b95095beb82e8f6a046b3aafc7f4149a.pem',
|
108 |
+
'UnsubscribeUrl' => 'https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:604091128280:testing1:7118d01a-202e-4a65-a372-f46b0994bdae',
|
109 |
+
]
|
110 |
+
],
|
111 |
+
];
|
112 |
+
}
|
113 |
+
|
114 |
+
private function getMockCertServerClient()
|
115 |
+
{
|
116 |
+
return function () {
|
117 |
+
return self::$certificate;
|
118 |
+
};
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* @dataProvider getHttpFixtures
|
123 |
+
*
|
124 |
+
* @param array $messageData
|
125 |
+
*/
|
126 |
+
public function testValidatesHttpFixtures($messageData)
|
127 |
+
{
|
128 |
+
$validator = new MessageValidator($this->getMockCertServerClient());
|
129 |
+
$message = new Message($messageData);
|
130 |
+
|
131 |
+
$this->assertTrue($validator->isValid($message));
|
132 |
+
$this->assertNotEmpty($message['SigningCertURL']);
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* @dataProvider getLambdaFixtures
|
137 |
+
*
|
138 |
+
* @param array $messageData
|
139 |
+
*/
|
140 |
+
public function testValidatesLambdaFixtures($messageData)
|
141 |
+
{
|
142 |
+
$validator = new MessageValidator($this->getMockCertServerClient());
|
143 |
+
$message = new Message($messageData);
|
144 |
+
|
145 |
+
$this->assertTrue($validator->isValid($message));
|
146 |
+
$this->assertNotEmpty($message['SigningCertUrl']);
|
147 |
+
}
|
148 |
+
}
|
vendor/aws/aws-php-sns-message-validator/tests/MessageTest.php
ADDED
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace Aws\Sns;
|
3 |
+
|
4 |
+
use GuzzleHttp\Psr7\Request;
|
5 |
+
|
6 |
+
/**
|
7 |
+
* @covers \Aws\Sns\Message
|
8 |
+
*/
|
9 |
+
class MessageTest extends \PHPUnit_Framework_TestCase
|
10 |
+
{
|
11 |
+
public $messageData = array(
|
12 |
+
'Message' => 'a',
|
13 |
+
'MessageId' => 'b',
|
14 |
+
'Timestamp' => 'c',
|
15 |
+
'TopicArn' => 'd',
|
16 |
+
'Type' => 'e',
|
17 |
+
'Subject' => 'f',
|
18 |
+
'Signature' => 'g',
|
19 |
+
'SignatureVersion' => '1',
|
20 |
+
'SigningCertURL' => 'h',
|
21 |
+
'SubscribeURL' => 'i',
|
22 |
+
'Token' => 'j',
|
23 |
+
);
|
24 |
+
|
25 |
+
public function testGetters()
|
26 |
+
{
|
27 |
+
$message = new Message($this->messageData);
|
28 |
+
$this->assertInternalType('array', $message->toArray());
|
29 |
+
|
30 |
+
foreach ($this->messageData as $key => $expectedValue) {
|
31 |
+
$this->assertTrue(isset($message[$key]));
|
32 |
+
$this->assertEquals($expectedValue, $message[$key]);
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
public function testIterable()
|
37 |
+
{
|
38 |
+
$message = new Message($this->messageData);
|
39 |
+
|
40 |
+
$this->assertInstanceOf('Traversable', $message);
|
41 |
+
foreach ($message as $key => $value) {
|
42 |
+
$this->assertTrue(isset($this->messageData[$key]));
|
43 |
+
$this->assertEquals($value, $this->messageData[$key]);
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @dataProvider messageTypeProvider
|
49 |
+
*
|
50 |
+
* @param string $messageType
|
51 |
+
*/
|
52 |
+
public function testConstructorSucceedsWithGoodData($messageType)
|
53 |
+
{
|
54 |
+
$this->assertInstanceOf('Aws\Sns\Message', new Message(
|
55 |
+
['Type' => $messageType] + $this->messageData
|
56 |
+
));
|
57 |
+
}
|
58 |
+
|
59 |
+
public function messageTypeProvider()
|
60 |
+
{
|
61 |
+
return [
|
62 |
+
['Notification'],
|
63 |
+
['SubscriptionConfirmation'],
|
64 |
+
['UnsubscribeConfirmation'],
|
65 |
+
];
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* @expectedException \InvalidArgumentException
|
70 |
+
*/
|
71 |
+
public function testConstructorFailsWithNoType()
|
72 |
+
{
|
73 |
+
$data = $this->messageData;
|
74 |
+
unset($data['Type']);
|
75 |
+
new Message($data);
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* @expectedException \InvalidArgumentException
|
80 |
+
*/
|
81 |
+
public function testConstructorFailsWithMissingData()
|
82 |
+
{
|
83 |
+
new Message(['Type' => 'Notification']);
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* @expectedException \InvalidArgumentException
|
88 |
+
*/
|
89 |
+
public function testRequiresTokenAndSubscribeUrlForSubscribeMessage()
|
90 |
+
{
|
91 |
+
new Message(
|
92 |
+
['Type' => 'SubscriptionConfirmation'] + array_diff_key(
|
93 |
+
$this->messageData,
|
94 |
+
array_flip(['Token', 'SubscribeURL'])
|
95 |
+
)
|
96 |
+
);
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* @expectedException \InvalidArgumentException
|
101 |
+
*/
|
102 |
+
public function testRequiresTokenAndSubscribeUrlForUnsubscribeMessage()
|
103 |
+
{
|
104 |
+
new Message(
|
105 |
+
['Type' => 'UnsubscribeConfirmation'] + array_diff_key(
|
106 |
+
$this->messageData,
|
107 |
+
array_flip(['Token', 'SubscribeURL'])
|
108 |
+
)
|
109 |
+
);
|
110 |
+
}
|
111 |
+
|
112 |
+
public function testCanCreateFromRawPost()
|
113 |
+
{
|
114 |
+
$_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE'] = 'Notification';
|
115 |
+
|
116 |
+
// Prep php://input with mocked data
|
117 |
+
MockPhpStream::setStartingData(json_encode($this->messageData));
|
118 |
+
stream_wrapper_unregister('php');
|
119 |
+
stream_wrapper_register('php', __NAMESPACE__ . '\MockPhpStream');
|
120 |
+
|
121 |
+
$message = Message::fromRawPostData();
|
122 |
+
$this->assertInstanceOf('Aws\Sns\Message', $message);
|
123 |
+
|
124 |
+
stream_wrapper_restore("php");
|
125 |
+
unset($_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE']);
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* @expectedException \RuntimeException
|
130 |
+
*/
|
131 |
+
public function testCreateFromRawPostFailsWithMissingHeader()
|
132 |
+
{
|
133 |
+
Message::fromRawPostData();
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* @expectedException \RuntimeException
|
138 |
+
*/
|
139 |
+
public function testCreateFromRawPostFailsWithMissingData()
|
140 |
+
{
|
141 |
+
$_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE'] = 'Notification';
|
142 |
+
Message::fromRawPostData();
|
143 |
+
unset($_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE']);
|
144 |
+
}
|
145 |
+
|
146 |
+
public function testCanCreateFromPsr7Request()
|
147 |
+
{
|
148 |
+
$request = new Request(
|
149 |
+
'POST',
|
150 |
+
'/',
|
151 |
+
[],
|
152 |
+
json_encode($this->messageData)
|
153 |
+
);
|
154 |
+
$message = Message::fromPsrRequest($request);
|
155 |
+
$this->assertInstanceOf('Aws\Sns\Message', $message);
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* @expectedException \RuntimeException
|
160 |
+
*/
|
161 |
+
public function testCreateFromPsr7RequestFailsWithMissingData()
|
162 |
+
{
|
163 |
+
$request = new Request(
|
164 |
+
'POST',
|
165 |
+
'/',
|
166 |
+
[],
|
167 |
+
'Not valid JSON'
|
168 |
+
);
|
169 |
+
Message::fromPsrRequest($request);
|
170 |
+
}
|
171 |
+
|
172 |
+
public function testArrayAccess()
|
173 |
+
{
|
174 |
+
$message = new Message($this->messageData);
|
175 |
+
|
176 |
+
$this->assertInstanceOf('ArrayAccess', $message);
|
177 |
+
$message['foo'] = 'bar';
|
178 |
+
$this->assertTrue(isset($message['foo']));
|
179 |
+
$this->assertTrue($message['foo'] === 'bar');
|
180 |
+
unset($message['foo']);
|
181 |
+
$this->assertFalse(isset($message['foo']));
|
182 |
+
}
|
183 |
+
}
|
vendor/aws/aws-php-sns-message-validator/tests/MessageValidatorTest.php
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace Aws\Sns;
|
3 |
+
|
4 |
+
/**
|
5 |
+
* @covers Aws\Sns\MessageValidator
|
6 |
+
*/
|
7 |
+
class MessageValidatorTest extends \PHPUnit_Framework_TestCase
|
8 |
+
{
|
9 |
+
const VALID_CERT_URL = 'https://sns.foo.amazonaws.com/bar.pem';
|
10 |
+
|
11 |
+
private static $pKey;
|
12 |
+
private static $certificate;
|
13 |
+
|
14 |
+
public static function setUpBeforeClass()
|
15 |
+
{
|
16 |
+
self::$pKey = openssl_pkey_new();
|
17 |
+
$csr = openssl_csr_new([], self::$pKey);
|
18 |
+
$x509 = openssl_csr_sign($csr, null, self::$pKey, 1);
|
19 |
+
openssl_x509_export($x509, self::$certificate);
|
20 |
+
openssl_x509_free($x509);
|
21 |
+
}
|
22 |
+
|
23 |
+
public static function tearDownAfterClass()
|
24 |
+
{
|
25 |
+
openssl_pkey_free(self::$pKey);
|
26 |
+
}
|
27 |
+
|
28 |
+
public function testIsValidReturnsFalseOnFailedValidation()
|
29 |
+
{
|
30 |
+
$validator = new MessageValidator($this->getMockHttpClient());
|
31 |
+
$message = $this->getTestMessage([
|
32 |
+
'SignatureVersion' => '2',
|
33 |
+
]);
|
34 |
+
$this->assertFalse($validator->isValid($message));
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
|
39 |
+
* @expectedExceptionMessage The SignatureVersion "2" is not supported.
|
40 |
+
*/
|
41 |
+
public function testValidateFailsWhenSignatureVersionIsInvalid()
|
42 |
+
{
|
43 |
+
$validator = new MessageValidator($this->getMockCertServerClient());
|
44 |
+
$message = $this->getTestMessage([
|
45 |
+
'SignatureVersion' => '2',
|
46 |
+
]);
|
47 |
+
$validator->validate($message);
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
|
52 |
+
* @expectedExceptionMessage The certificate is located on an invalid domain.
|
53 |
+
*/
|
54 |
+
public function testValidateFailsWhenCertUrlInvalid()
|
55 |
+
{
|
56 |
+
$validator = new MessageValidator();
|
57 |
+
$message = $this->getTestMessage([
|
58 |
+
'SigningCertURL' => 'https://foo.amazonaws.com/bar.pem',
|
59 |
+
]);
|
60 |
+
$validator->validate($message);
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
|
65 |
+
* @expectedExceptionMessage The certificate is located on an invalid domain.
|
66 |
+
*/
|
67 |
+
public function testValidateFailsWhenCertUrlNotAPemFile()
|
68 |
+
{
|
69 |
+
$validator = new MessageValidator();
|
70 |
+
$message = $this->getTestMessage([
|
71 |
+
'SigningCertURL' => 'https://foo.amazonaws.com/bar',
|
72 |
+
]);
|
73 |
+
$validator->validate($message);
|
74 |
+
}
|
75 |
+
|
76 |
+
public function testValidatesAgainstCustomDomains()
|
77 |
+
{
|
78 |
+
$validator = new MessageValidator(
|
79 |
+
function () {
|
80 |
+
return self::$certificate;
|
81 |
+
},
|
82 |
+
'/^(foo|bar).example.com$/'
|
83 |
+
);
|
84 |
+
$message = $this->getTestMessage([
|
85 |
+
'SigningCertURL' => 'https://foo.example.com/baz.pem',
|
86 |
+
]);
|
87 |
+
$message['Signature'] = $this->getSignature($validator->getStringToSign($message));
|
88 |
+
$this->assertTrue($validator->isValid($message));
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
|
93 |
+
* @expectedExceptionMessageRegExp /Cannot get the certificate from ".+"./
|
94 |
+
*/
|
95 |
+
public function testValidateFailsWhenCannotGetCertificate()
|
96 |
+
{
|
97 |
+
$validator = new MessageValidator($this->getMockHttpClient(false));
|
98 |
+
$message = $this->getTestMessage();
|
99 |
+
$validator->validate($message);
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
|
104 |
+
* @expectedExceptionMessage Cannot get the public key from the certificate.
|
105 |
+
*/
|
106 |
+
public function testValidateFailsWhenCannotDeterminePublicKey()
|
107 |
+
{
|
108 |
+
$validator = new MessageValidator($this->getMockHttpClient());
|
109 |
+
$message = $this->getTestMessage();
|
110 |
+
$validator->validate($message);
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
|
115 |
+
* @expectedExceptionMessage The message signature is invalid.
|
116 |
+
*/
|
117 |
+
public function testValidateFailsWhenMessageIsInvalid()
|
118 |
+
{
|
119 |
+
$validator = new MessageValidator($this->getMockCertServerClient());
|
120 |
+
$message = $this->getTestMessage([
|
121 |
+
'Signature' => $this->getSignature('foo'),
|
122 |
+
]);
|
123 |
+
$validator->validate($message);
|
124 |
+
}
|
125 |
+
|
126 |
+
public function testValidateSucceedsWhenMessageIsValid()
|
127 |
+
{
|
128 |
+
$validator = new MessageValidator($this->getMockCertServerClient());
|
129 |
+
$message = $this->getTestMessage();
|
130 |
+
|
131 |
+
// Get the signature for a real message
|
132 |
+
$message['Signature'] = $this->getSignature($validator->getStringToSign($message));
|
133 |
+
|
134 |
+
// The message should validate
|
135 |
+
$this->assertTrue($validator->isValid($message));
|
136 |
+
}
|
137 |
+
|
138 |
+
public function testBuildsStringToSignCorrectly()
|
139 |
+
{
|
140 |
+
$validator = new MessageValidator();
|
141 |
+
$stringToSign = <<< STRINGTOSIGN
|
142 |
+
Message
|
143 |
+
foo
|
144 |
+
MessageId
|
145 |
+
bar
|
146 |
+
Timestamp
|
147 |
+
1435697129
|
148 |
+
TopicArn
|
149 |
+
baz
|
150 |
+
Type
|
151 |
+
Notification
|
152 |
+
|
153 |
+
STRINGTOSIGN;
|
154 |
+
|
155 |
+
$this->assertEquals(
|
156 |
+
$stringToSign,
|
157 |
+
$validator->getStringToSign($this->getTestMessage())
|
158 |
+
);
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* @param array $customData
|
163 |
+
*
|
164 |
+
* @return Message
|
165 |
+
*/
|
166 |
+
private function getTestMessage(array $customData = [])
|
167 |
+
{
|
168 |
+
return new Message($customData + [
|
169 |
+
'Message' => 'foo',
|
170 |
+
'MessageId' => 'bar',
|
171 |
+
'Timestamp' => time(),
|
172 |
+
'TopicArn' => 'baz',
|
173 |
+
'Type' => 'Notification',
|
174 |
+
'SigningCertURL' => self::VALID_CERT_URL,
|
175 |
+
'Signature' => true,
|
176 |
+
'SignatureVersion' => '1',
|
177 |
+
]);
|
178 |
+
}
|
179 |
+
|
180 |
+
private function getMockHttpClient($responseBody = '')
|
181 |
+
{
|
182 |
+
return function () use ($responseBody) {
|
183 |
+
return $responseBody;
|
184 |
+
};
|
185 |
+
}
|
186 |
+
|
187 |
+
private function getMockCertServerClient()
|
188 |
+
{
|
189 |
+
return function ($url) {
|
190 |
+
if ($url !== self::VALID_CERT_URL) {
|
191 |
+
return '';
|
192 |
+
}
|
193 |
+
|
194 |
+
return self::$certificate;
|
195 |
+
};
|
196 |
+
}
|
197 |
+
|
198 |
+
private function getSignature($stringToSign)
|
199 |
+
{
|
200 |
+
openssl_sign($stringToSign, $signature, self::$pKey);
|
201 |
+
|
202 |
+
return base64_encode($signature);
|
203 |
+
}
|
204 |
+
}
|
205 |
+
|
206 |
+
function time()
|
207 |
+
{
|
208 |
+
return 1435697129;
|
209 |
+
}
|
vendor/aws/aws-php-sns-message-validator/tests/MockPhpStream.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace Aws\Sns;
|
3 |
+
|
4 |
+
class MockPhpStream
|
5 |
+
{
|
6 |
+
private static $startingData = '';
|
7 |
+
private $index;
|
8 |
+
private $length;
|
9 |
+
private $data;
|
10 |
+
|
11 |
+
public static function setStartingData($data)
|
12 |
+
{
|
13 |
+
self::$startingData = $data;
|
14 |
+
}
|
15 |
+
|
16 |
+
public function __construct()
|
17 |
+
{
|
18 |
+
$this->data = self::$startingData;
|
19 |
+
$this->index = 0;
|
20 |
+
$this->length = strlen(self::$startingData);
|
21 |
+
}
|
22 |
+
|
23 |
+
public function stream_open($path, $mode, $options, &$opened_path)
|
24 |
+
{
|
25 |
+
return true;
|
26 |
+
}
|
27 |
+
|
28 |
+
public function stream_close()
|
29 |
+
{
|
30 |
+
}
|
31 |
+
|
32 |
+
public function stream_stat()
|
33 |
+
{
|
34 |
+
return array();
|
35 |
+
}
|
36 |
+
|
37 |
+
public function stream_flush()
|
38 |
+
{
|
39 |
+
return true;
|
40 |
+
}
|
41 |
+
|
42 |
+
public function stream_read($count)
|
43 |
+
{
|
44 |
+
$length = min($count, $this->length - $this->index);
|
45 |
+
$data = substr($this->data, $this->index);
|
46 |
+
$this->index = $this->index + $length;
|
47 |
+
|
48 |
+
return $data;
|
49 |
+
}
|
50 |
+
|
51 |
+
public function stream_eof()
|
52 |
+
{
|
53 |
+
return ($this->index >= $this->length);
|
54 |
+
}
|
55 |
+
|
56 |
+
public function stream_write($data)
|
57 |
+
{
|
58 |
+
return 0;
|
59 |
+
}
|
60 |
+
}
|
w3-total-cache-api.php
CHANGED
@@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
12 |
}
|
13 |
|
14 |
define( 'W3TC', true );
|
15 |
-
define( 'W3TC_VERSION', '2.2.
|
16 |
define( 'W3TC_POWERED_BY', 'W3 Total Cache' );
|
17 |
define( 'W3TC_EMAIL', 'w3tc@w3-edge.com' );
|
18 |
define( 'W3TC_TEXT_DOMAIN', 'w3-total-cache' );
|
12 |
}
|
13 |
|
14 |
define( 'W3TC', true );
|
15 |
+
define( 'W3TC_VERSION', '2.2.4' );
|
16 |
define( 'W3TC_POWERED_BY', 'W3 Total Cache' );
|
17 |
define( 'W3TC_EMAIL', 'w3tc@w3-edge.com' );
|
18 |
define( 'W3TC_TEXT_DOMAIN', 'w3-total-cache' );
|
w3-total-cache.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: W3 Total Cache
|
4 |
* Plugin URI: https://www.boldgrid.com/totalcache/
|
5 |
* Description: The highest rated and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.
|
6 |
-
* Version: 2.2.
|
7 |
* Requires at least: 3.8
|
8 |
* Requires PHP: 5.6
|
9 |
* Author: BoldGrid
|
3 |
* Plugin Name: W3 Total Cache
|
4 |
* Plugin URI: https://www.boldgrid.com/totalcache/
|
5 |
* Description: The highest rated and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.
|
6 |
+
* Version: 2.2.4
|
7 |
* Requires at least: 3.8
|
8 |
* Requires PHP: 5.6
|
9 |
* Author: BoldGrid
|