Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/deprecated/3.14.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
defined( 'ABSPATH' ) || exit;
4
+
5
+
/**
6
+
* Remove HTTP protocol on script, link, img and form tags.
7
+
*
8
+
* @since 2.7
9
+
* @deprecated 3.14
10
+
*
11
+
* @param string $buffer HTML content.
12
+
* @return string Updated HTML content
13
+
*/
14
+
function rocket_protocol_rewrite( $buffer ) {
15
+
_deprecated_function( __FUNCTION__, '3.14' );
16
+
17
+
$re = "/(<(script|link|img|form)([^>]*)(href|src|action)=[\"'])https?:\\/\\//i";
18
+
$subst = '$1//';
19
+
$return = preg_replace( $re, $subst, $buffer );
20
+
21
+
if ( $return ) {
22
+
$buffer = $return;
23
+
}
24
+
25
+
return $buffer;
26
+
}
27
+
28
+
/**
29
+
* Remove HTTP protocol on srcset attribute generated by WordPress
30
+
*
31
+
* @since 2.7
32
+
* @deprecated 3.14
33
+
*
34
+
* @param array $sources an Array of images sources for srcset.
35
+
* @return array Updated array of images sources
36
+
*/
37
+
function rocket_protocol_rewrite_srcset( $sources ) {
38
+
_deprecated_function( __FUNCTION__, '3.14' );
39
+
40
+
if ( (bool) $sources ) {
41
+
foreach ( $sources as $i => $source ) {
42
+
$sources[ $i ]['url'] = str_replace( [ 'http:', 'https:' ], '', $source['url'] );
43
+
}
44
+
}
45
+
46
+
return $sources;
47
+
}
48
+
49
+
/**
50
+
* Check if request is from Cloudflare
51
+
*
52
+
* @since 3.4.1
53
+
* @author Soponar Cristina
54
+
*
55
+
* @return bool
56
+
*/
57
+
function rocket_is_cloudflare() {
58
+
_deprecated_function( __FUNCTION__, '3.14' );
59
+
60
+
if ( ! isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
61
+
return false;
62
+
}
63
+
// Check if original ip has already been restored, e.g. by nginx - assume it was from cloudflare then.
64
+
if ( isset( $_SERVER['REMOTE_ADDR'] ) && $_SERVER['REMOTE_ADDR'] === $_SERVER['HTTP_CF_CONNECTING_IP'] ) {
65
+
return true;
66
+
}
67
+
68
+
return rocket_is_cf_ip();
69
+
}
70
+
71
+
/**
72
+
* Check if a request comes from a CloudFlare IP.
73
+
*
74
+
* @since 3.4.1
75
+
* @author Soponar Cristina
76
+
*
77
+
* @return bool
78
+
*/
79
+
function rocket_is_cf_ip() {
80
+
_deprecated_function( __FUNCTION__, '3.14' );
81
+
82
+
// Store original remote address in $original_ip.
83
+
$original_ip = filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP );
84
+
if ( ! isset( $original_ip ) ) {
85
+
return false;
86
+
}
87
+
88
+
$cf_ips_values = get_transient( 'rocket_cloudflare_ips' );
89
+
90
+
// Cloudflare IPS should always be populated because the code runs before loading Cloudflare addon.
91
+
if ( false === $cf_ips_values ) {
92
+
$cf_ips_values = (object) [
93
+
'success' => true,
94
+
'result' => (object) [],
95
+
];
96
+
97
+
$cf_ips_values->result->ipv4_cidrs = [
98
+
'103.21.244.0/22',
99
+
'103.22.200.0/22',
100
+
'103.31.4.0/22',
101
+
'104.16.0.0/12',
102
+
'108.162.192.0/18',
103
+
'131.0.72.0/22',
104
+
'141.101.64.0/18',
105
+
'162.158.0.0/15',
106
+
'172.64.0.0/13',
107
+
'173.245.48.0/20',
108
+
'188.114.96.0/20',
109
+
'190.93.240.0/20',
110
+
'197.234.240.0/22',
111
+
'198.41.128.0/17',
112
+
];
113
+
114
+
$cf_ips_values->result->ipv6_cidrs = [
115
+
'2400:cb00::/32',
116
+
'2405:8100::/32',
117
+
'2405:b500::/32',
118
+
'2606:4700::/32',
119
+
'2803:f800::/32',
120
+
'2c0f:f248::/32',
121
+
'2a06:98c0::/29',
122
+
];
123
+
}
124
+
125
+
if ( strpos( $original_ip, ':' ) === false ) {
126
+
$cf_ip_ranges = $cf_ips_values->result->ipv4_cidrs;
127
+
foreach ( $cf_ip_ranges as $range ) {
128
+
if ( rocket_ipv4_in_range( $original_ip, $range ) ) {
129
+
return true;
130
+
}
131
+
}
132
+
} else {
133
+
$cf_ip_ranges = $cf_ips_values->result->ipv6_cidrs;
134
+
$ipv6 = get_rocket_ipv6_full( $original_ip );
135
+
foreach ( $cf_ip_ranges as $range ) {
136
+
if ( rocket_ipv6_in_range( $ipv6, $range ) ) {
137
+
return true;
138
+
}
139
+
}
140
+
}
141
+
142
+
return false;
143
+
}
144
+
145
+
/**
146
+
* Fixes Cloudflare Flexible SSL redirect loop
147
+
*
148
+
* @since 3.4.1
149
+
* @author Soponar Cristina
150
+
*/
151
+
function rocket_fix_cf_flexible_ssl() {
152
+
_deprecated_function( __FUNCTION__, '3.14' );
153
+
154
+
$is_cf = rocket_is_cloudflare();
155
+
if ( $is_cf ) {
156
+
// Fixes Flexible SSL.
157
+
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
158
+
$_SERVER['HTTPS'] = 'on';
159
+
}
160
+
}
161
+
}
162
+
163
+
/*
164
+
* ip_in_range.php - Function to determine if an IP is located in a
165
+
* specific range as specified via several alternative
166
+
* formats.
167
+
*
168
+
* Network ranges can be specified as:
169
+
* 1. Wildcard format: 1.2.3.*
170
+
* 2. CIDR format: 1.2.3/24 OR 1.2.3.4/255.255.255.0
171
+
* 3. Start-End IP format: 1.2.3.0-1.2.3.255
172
+
*
173
+
* Return value BOOLEAN : ip_in_range($ip, $range);
174
+
*
175
+
* Copyright 2008: Paul Gregg <pgregg@pgregg.com>
176
+
* 10 January 2008
177
+
* Version: 1.2
178
+
*
179
+
* Source website: http://www.pgregg.com/projects/php/ip_in_range/
180
+
* Version 1.2
181
+
*
182
+
* This software is Donationware - if you feel you have benefited from
183
+
* the use of this tool then please consider a donation. The value of
184
+
* which is entirely left up to your discretion.
185
+
* http://www.pgregg.com/donate/
186
+
*
187
+
* Please do not remove this header, or source attibution from this file.
188
+
*/
189
+
190
+
/*
191
+
* Modified by James Greene <james@cloudflare.com> to include IPV6 support
192
+
* (original version only supported IPV4).
193
+
* 21 May 2012
194
+
*/
195
+
196
+
// In order to simplify working with IP addresses (in binary) and their
197
+
// netmasks, it is easier to ensure that the binary strings are padded
198
+
// with zeros out to 32 characters - IP addresses are 32 bit numbers
199
+
function rocket_decbin32($dec) {
200
+
_deprecated_function( __FUNCTION__, '3.14' );
201
+
202
+
return str_pad(decbin($dec), 32, '0', STR_PAD_LEFT);
203
+
}
204
+
205
+
// This function takes 2 arguments, an IP address and a "range" in several
206
+
// different formats.
207
+
// Network ranges can be specified as:
208
+
// 1. Wildcard format: 1.2.3.*
209
+
// 2. CIDR format: 1.2.3/24 OR 1.2.3.4/255.255.255.0
210
+
// 3. Start-End IP format: 1.2.3.0-1.2.3.255
211
+
// The function will return true if the supplied IP is within the range.
212
+
// Note little validation is done on the range inputs - it expects you to
213
+
// use one of the above 3 formats.
214
+
function rocket_ipv4_in_range($ip, $range) {
215
+
_deprecated_function( __FUNCTION__, '3.14' );
216
+
217
+
if (strpos($range, '/') !== false) {
218
+
// $range is in IP/NETMASK format
219
+
list($range, $netmask) = explode('/', $range, 2);
220
+
if (strpos($netmask, '.') !== false) {
221
+
// $netmask is a 255.255.0.0 format
222
+
$netmask = str_replace('*', '0', $netmask);
223
+
$netmask_dec = ip2long($netmask);
224
+
return ( (ip2long($ip) & $netmask_dec) == (ip2long($range) & $netmask_dec) );
225
+
} else {
226
+
// $netmask is a CIDR size block
227
+
// fix the range argument
228
+
$x = explode('.', $range);
229
+
while(count($x)<4) $x[] = '0';
230
+
list($a,$b,$c,$d) = $x;
231
+
$range = sprintf("%u.%u.%u.%u", empty($a)?'0':$a, empty($b)?'0':$b,empty($c)?'0':$c,empty($d)?'0':$d);
232
+
$range_dec = ip2long($range);
233
+
$ip_dec = ip2long($ip);
234
+
235
+
# Strategy 1 - Create the netmask with 'netmask' 1s and then fill it to 32 with 0s
236
+
#$netmask_dec = bindec(str_pad('', $netmask, '1') . str_pad('', 32-$netmask, '0'));
237
+
238
+
# Strategy 2 - Use math to create it
239
+
$wildcard_dec = pow(2, (32-$netmask)) - 1;
240
+
$netmask_dec = ~ $wildcard_dec;
241
+
242
+
return (($ip_dec & $netmask_dec) == ($range_dec & $netmask_dec));
243
+
}
244
+
} else {
245
+
// range might be 255.255.*.* or 1.2.3.0-1.2.3.255
246
+
if (strpos($range, '*') !==false) { // a.b.*.* format
247
+
// Just convert to A-B format by setting * to 0 for A and 255 for B
248
+
$lower = str_replace('*', '0', $range);
249
+
$upper = str_replace('*', '255', $range);
250
+
$range = "$lower-$upper";
251
+
}
252
+
253
+
if (strpos($range, '-')!==false) { // A-B format
254
+
list($lower, $upper) = explode('-', $range, 2);
255
+
$lower_dec = (float)sprintf("%u",ip2long($lower));
256
+
$upper_dec = (float)sprintf("%u",ip2long($upper));
257
+
$ip_dec = (float)sprintf("%u",ip2long($ip));
258
+
return ( ($ip_dec>=$lower_dec) && ($ip_dec<=$upper_dec) );
259
+
}
260
+
return false;
261
+
}
262
+
}
263
+
264
+
function rocket_ip2long6($ip) {
265
+
_deprecated_function( __FUNCTION__, '3.14' );
266
+
267
+
if (substr_count($ip, '::')) {
268
+
$ip = str_replace('::', str_repeat(':0000', 8 - substr_count($ip, ':')) . ':', $ip);
269
+
}
270
+
271
+
$ip = explode(':', $ip);
272
+
$r_ip = '';
273
+
foreach ($ip as $v) {
274
+
$r_ip .= str_pad( base_convert( preg_replace("/[^0-9a-fA-F]/", "", $v ), 16, 2 ), 16, 0, STR_PAD_LEFT );
275
+
}
276
+
277
+
return base_convert($r_ip, 2, 10);
278
+
}
279
+
280
+
// Get the ipv6 full format and return it as a decimal value.
281
+
function get_rocket_ipv6_full($ip) {
282
+
_deprecated_function( __FUNCTION__, '3.14' );
283
+
284
+
$pieces = explode ("/", $ip, 2);
285
+
$left_piece = $pieces[0];
286
+
$right_piece = null;
287
+
if (count($pieces) > 1) $right_piece = $pieces[1];
288
+
289
+
// Extract out the main IP pieces
290
+
$ip_pieces = explode("::", $left_piece, 2);
291
+
$main_ip_piece = $ip_pieces[0];
292
+
$last_ip_piece = "";
293
+
if (count($ip_pieces) > 1) $last_ip_piece = $ip_pieces[1];
294
+
295
+
// Pad out the shorthand entries.
296
+
$main_ip_pieces = explode(":", $main_ip_piece);
297
+
foreach($main_ip_pieces as $key=>$val) {
298
+
$main_ip_pieces[$key] = str_pad($main_ip_pieces[$key], 4, "0", STR_PAD_LEFT);
299
+
}
300
+
301
+
// Check to see if the last IP block (part after ::) is set
302
+
$last_piece = "";
303
+
$size = count($main_ip_pieces);
304
+
if (trim($last_ip_piece) != "") {
305
+
$last_piece = str_pad($last_ip_piece, 4, "0", STR_PAD_LEFT);
306
+
307
+
// Build the full form of the IPV6 address considering the last IP block set
308
+
for ($i = $size; $i < 7; $i++) {
309
+
$main_ip_pieces[$i] = "0000";
310
+
}
311
+
$main_ip_pieces[7] = $last_piece;
312
+
}
313
+
else {
314
+
// Build the full form of the IPV6 address
315
+
for ($i = $size; $i < 8; $i++) {
316
+
$main_ip_pieces[$i] = "0000";
317
+
}
318
+
}
319
+
320
+
// Rebuild the final long form IPV6 address
321
+
$final_ip = implode(":", $main_ip_pieces);
322
+
323
+
return rocket_ip2long6($final_ip);
324
+
}
325
+
326
+
// Determine whether the IPV6 address is within range.
327
+
// $ip is the IPV6 address in decimal format to check if its within the IP range created by the cloudflare IPV6 address, $range_ip.
328
+
// $ip and $range_ip are converted to full IPV6 format.
329
+
// Returns true if the IPV6 address, $ip, is within the range from $range_ip. False otherwise.
330
+
function rocket_ipv6_in_range($ip, $range_ip) {
331
+
_deprecated_function( __FUNCTION__, '3.14' );
332
+
333
+
$pieces = explode ("/", $range_ip, 2);
334
+
$left_piece = $pieces[0];
335
+
$right_piece = $pieces[1];
336
+
337
+
// Extract out the main IP pieces
338
+
$ip_pieces = explode("::", $left_piece, 2);
339
+
$main_ip_piece = $ip_pieces[0];
340
+
$last_ip_piece = $ip_pieces[1];
341
+
342
+
// Pad out the shorthand entries.
343
+
$main_ip_pieces = explode(":", $main_ip_piece);
344
+
foreach($main_ip_pieces as $key=>$val) {
345
+
$main_ip_pieces[$key] = str_pad($main_ip_pieces[$key], 4, "0", STR_PAD_LEFT);
346
+
}
347
+
348
+
// Create the first and last pieces that will denote the IPV6 range.
349
+
$first = $main_ip_pieces;
350
+
$last = $main_ip_pieces;
351
+
352
+
// Check to see if the last IP block (part after ::) is set
353
+
$last_piece = "";
354
+
$size = count($main_ip_pieces);
355
+
if (trim($last_ip_piece) != "") {
356
+
$last_piece = str_pad($last_ip_piece, 4, "0", STR_PAD_LEFT);
357
+
358
+
// Build the full form of the IPV6 address considering the last IP block set
359
+
for ($i = $size; $i < 7; $i++) {
360
+
$first[$i] = "0000";
361
+
$last[$i] = "ffff";
362
+
}
363
+
$main_ip_pieces[7] = $last_piece;
364
+
}
365
+
else {
366
+
// Build the full form of the IPV6 address
367
+
for ($i = $size; $i < 8; $i++) {
368
+
$first[$i] = "0000";
369
+
$last[$i] = "ffff";
370
+
}
371
+
}
372
+
373
+
// Rebuild the final long form IPV6 address
374
+
$first = rocket_ip2long6(implode(":", $first));
375
+
$last = rocket_ip2long6(implode(":", $last));
376
+
$in_range = ($ip >= $first && $ip <= $last);
377
+
378
+
return $in_range;
379
+
}
380
+
381
+
/**
382
+
* Filter plugin fetching API results to inject Imagify
383
+
*
384
+
* @since 2.10.7
385
+
* @since 3.14.2 deprecated
386
+
* @author Remy Perona
387
+
*
388
+
* @param object|WP_Error $result Response object or WP_Error.
389
+
* @param string $action The type of information being requested from the Plugin Install API.
390
+
* @param object $args Plugin API arguments.
391
+
*
392
+
* @return array Updated array of results
393
+
*/
394
+
function rocket_add_imagify_api_result( $result, $action, $args ) {
395
+
if ( empty( $args->browse ) ) {
396
+
return $result;
397
+
}
398
+
399
+
if ( 'featured' !== $args->browse && 'recommended' !== $args->browse && 'popular' !== $args->browse ) {
400
+
return $result;
401
+
}
402
+
403
+
if ( ! isset( $result->info['page'] ) || 1 < $result->info['page'] ) {
404
+
return $result;
405
+
}
406
+
407
+
if ( is_plugin_active( 'imagify/imagify.php' ) || is_plugin_active_for_network( 'imagify/imagify.php' ) ) {
408
+
return $result;
409
+
}
410
+
411
+
// grab all slugs from the api results.
412
+
$result_slugs = wp_list_pluck( $result->plugins, 'slug' );
413
+
414
+
if ( in_array( 'imagify', $result_slugs, true ) ) {
415
+
return $result;
416
+
}
417
+
418
+
$query_args = [
419
+
'slug' => 'imagify',
420
+
'fields' => [
421
+
'icons' => true,
422
+
'active_installs' => true,
423
+
'short_description' => true,
424
+
'group' => true,
425
+
],
426
+
];
427
+
$imagify_data = plugins_api( 'plugin_information', $query_args );
428
+
429
+
if ( is_wp_error( $imagify_data ) ) {
430
+
return $result;
431
+
}
432
+
433
+
if ( 'featured' === $args->browse ) {
434
+
array_push( $result->plugins, $imagify_data );
435
+
} else {
436
+
array_unshift( $result->plugins, $imagify_data );
437
+
}
438
+
439
+
return $result;
440
+
}
441
+