PluginProbe ʕ •ᴥ•ʔ
LiteSpeed Cache / 1.9.1.1
LiteSpeed Cache v1.9.1.1
trunk 1.0.15 1.9.1.1 2.9.9.2 3.6.4 4.6 5.7.0.1 6.5.4 7.0.0.1 7.0.1 7.1 7.2 7.3 7.3.0.1 7.4 7.5 7.5.0.1 7.6 7.6.1 7.6.2 7.7 7.8 7.8.0.1 7.8.1
litespeed-cache / lib / litespeed-php-compatibility.func.php
litespeed-cache / lib Last commit date
litespeed 8 years ago css_min.class.php 8 years ago css_min.colors.class.php 8 years ago css_min.utils.class.php 8 years ago html_min.class.php 8 years ago js_min.class.php 8 years ago litespeed-php-compatibility.func.php 8 years ago object-cache.php 8 years ago url_rewritter.class.php 8 years ago
litespeed-php-compatibility.func.php
123 lines
1 <?php
2 /**
3 * LiteSpeed PHP compatibility functions for lower PHP version
4 *
5 * @since 1.1.3
6 * @package LiteSpeed_Cache
7 * @subpackage LiteSpeed_Cache/lib
8 * @author LiteSpeed Technologies <info@litespeedtech.com>
9 */
10
11 if ( ! defined('WPINC') ) {
12 die ;
13 }
14
15
16
17 /**
18 * http_build_url() compatibility
19 *
20 */
21 if ( ! function_exists('http_build_url') ) {
22 if ( ! defined( 'HTTP_URL_REPLACE' ) ) define('HTTP_URL_REPLACE', 1); // Replace every part of the first URL when there's one of the second URL
23 if ( ! defined( 'HTTP_URL_JOIN_PATH' ) ) define('HTTP_URL_JOIN_PATH', 2); // Join relative paths
24 if ( ! defined( 'HTTP_URL_JOIN_QUERY' ) ) define('HTTP_URL_JOIN_QUERY', 4); // Join query strings
25 if ( ! defined( 'HTTP_URL_STRIP_USER' ) ) define('HTTP_URL_STRIP_USER', 8); // Strip any user authentication information
26 if ( ! defined( 'HTTP_URL_STRIP_PASS' ) ) define('HTTP_URL_STRIP_PASS', 16); // Strip any password authentication information
27 if ( ! defined( 'HTTP_URL_STRIP_AUTH' ) ) define('HTTP_URL_STRIP_AUTH', 32); // Strip any authentication information
28 if ( ! defined( 'HTTP_URL_STRIP_PORT' ) ) define('HTTP_URL_STRIP_PORT', 64); // Strip explicit port numbers
29 if ( ! defined( 'HTTP_URL_STRIP_PATH' ) ) define('HTTP_URL_STRIP_PATH', 128); // Strip complete path
30 if ( ! defined( 'HTTP_URL_STRIP_QUERY' ) ) define('HTTP_URL_STRIP_QUERY', 256); // Strip query string
31 if ( ! defined( 'HTTP_URL_STRIP_FRAGMENT' ) ) define('HTTP_URL_STRIP_FRAGMENT', 512); // Strip any fragments (#identifier)
32 if ( ! defined( 'HTTP_URL_STRIP_ALL' ) ) define('HTTP_URL_STRIP_ALL', 1024); // Strip anything but scheme and host
33
34 // Build an URL
35 // The parts of the second URL will be merged into the first according to the flags argument.
36 //
37 // @param mixed (Part(s) of) an URL in form of a string or associative array like parse_url() returns
38 // @param mixed Same as the first argument
39 // @param int A bitmask of binary or'ed HTTP_URL constants (Optional)HTTP_URL_REPLACE is the default
40 // @param array If set, it will be filled with the parts of the composed url like parse_url() would return
41 function http_build_url($url, $parts = array(), $flags = HTTP_URL_REPLACE, &$new_url = false)
42 {
43 $keys = array('user','pass','port','path','query','fragment');
44
45 // HTTP_URL_STRIP_ALL becomes all the HTTP_URL_STRIP_Xs
46 if ( $flags & HTTP_URL_STRIP_ALL ) {
47 $flags |= HTTP_URL_STRIP_USER;
48 $flags |= HTTP_URL_STRIP_PASS;
49 $flags |= HTTP_URL_STRIP_PORT;
50 $flags |= HTTP_URL_STRIP_PATH;
51 $flags |= HTTP_URL_STRIP_QUERY;
52 $flags |= HTTP_URL_STRIP_FRAGMENT;
53 }
54 // HTTP_URL_STRIP_AUTH becomes HTTP_URL_STRIP_USER and HTTP_URL_STRIP_PASS
55 else if ( $flags & HTTP_URL_STRIP_AUTH ) {
56 $flags |= HTTP_URL_STRIP_USER;
57 $flags |= HTTP_URL_STRIP_PASS;
58 }
59
60 // Parse the original URL
61 // - Suggestion by Sayed Ahad Abbas
62 // In case you send a parse_url array as input
63 $parse_url = !is_array($url) ? parse_url($url) : $url;
64
65 // Scheme and Host are always replaced
66 if ( isset($parts['scheme']) ) {
67 $parse_url['scheme'] = $parts['scheme'];
68 }
69 if ( isset($parts['host']) ) {
70 $parse_url['host'] = $parts['host'];
71 }
72
73 // (If applicable) Replace the original URL with it's new parts
74 if ( $flags & HTTP_URL_REPLACE ) {
75 foreach ($keys as $key) {
76 if ( isset($parts[$key]) ) {
77 $parse_url[$key] = $parts[$key];
78 }
79 }
80 }
81 else {
82 // Join the original URL path with the new path
83 if (isset($parts['path']) && ($flags & HTTP_URL_JOIN_PATH)) {
84 if ( isset($parse_url['path']) ) {
85 $parse_url['path'] = rtrim(str_replace(basename($parse_url['path']), '', $parse_url['path']), '/') . '/' . ltrim($parts['path'], '/');
86 }
87 else {
88 $parse_url['path'] = $parts['path'];
89 }
90 }
91
92 // Join the original query string with the new query string
93 if ( isset($parts['query']) && ($flags & HTTP_URL_JOIN_QUERY) ) {
94 if ( isset($parse_url['query']) ) {
95 $parse_url['query'] .= '&' . $parts['query'];
96 }
97 else {
98 $parse_url['query'] = $parts['query'];
99 }
100 }
101 }
102
103 // Strips all the applicable sections of the URL
104 // Note: Scheme and Host are never stripped
105 foreach ($keys as $key) {
106 if ( $flags & (int)constant('HTTP_URL_STRIP_' . strtoupper($key)) ) {
107 unset($parse_url[$key]);
108 }
109 }
110
111 $new_url = $parse_url;
112
113 return
114 (isset($parse_url['scheme']) ? $parse_url['scheme'] . '://' : '')
115 .(isset($parse_url['user']) ? $parse_url['user'] . (isset($parse_url['pass']) ? ':' . $parse_url['pass'] : '') .'@' : '')
116 .(isset($parse_url['host']) ? $parse_url['host'] : '')
117 .(isset($parse_url['port']) ? ':' . $parse_url['port'] : '')
118 .(isset($parse_url['path']) ? $parse_url['path'] : '')
119 .(isset($parse_url['query']) ? '?' . $parse_url['query'] : '')
120 .(isset($parse_url['fragment']) ? '#' . $parse_url['fragment'] : '')
121 ;
122 }
123 }