css_js_min
8 months ago
guest.cls.php
8 months ago
html-min.cls.php
8 months ago
object-cache.php
8 months ago
php-compatibility.func.php
8 months ago
urirewriter.cls.php
8 months ago
php-compatibility.func.php
157 lines
| 1 | <?php |
| 2 | // phpcs:ignoreFile |
| 3 | /** |
| 4 | * LiteSpeed PHP compatibility functions for lower PHP version |
| 5 | * |
| 6 | * @since 1.1.3 |
| 7 | * @package LiteSpeed |
| 8 | * @subpackage LiteSpeed_Cache/lib |
| 9 | */ |
| 10 | |
| 11 | defined( 'WPINC' ) || exit; |
| 12 | |
| 13 | |
| 14 | /** |
| 15 | * http_build_url() compatibility |
| 16 | */ |
| 17 | if ( ! function_exists( 'http_build_url' ) ) { |
| 18 | if ( ! defined( 'HTTP_URL_REPLACE' ) ) { |
| 19 | define( 'HTTP_URL_REPLACE', 1 ); // Replace every part of the first URL when there's one of the second URL |
| 20 | } |
| 21 | if ( ! defined( 'HTTP_URL_JOIN_PATH' ) ) { |
| 22 | define( 'HTTP_URL_JOIN_PATH', 2 ); // Join relative paths |
| 23 | } |
| 24 | if ( ! defined( 'HTTP_URL_JOIN_QUERY' ) ) { |
| 25 | define( 'HTTP_URL_JOIN_QUERY', 4 ); // Join query strings |
| 26 | } |
| 27 | if ( ! defined( 'HTTP_URL_STRIP_USER' ) ) { |
| 28 | define( 'HTTP_URL_STRIP_USER', 8 ); // Strip any user authentication information |
| 29 | } |
| 30 | if ( ! defined( 'HTTP_URL_STRIP_PASS' ) ) { |
| 31 | define( 'HTTP_URL_STRIP_PASS', 16 ); // Strip any password authentication information |
| 32 | } |
| 33 | if ( ! defined( 'HTTP_URL_STRIP_AUTH' ) ) { |
| 34 | define( 'HTTP_URL_STRIP_AUTH', 32 ); // Strip any authentication information |
| 35 | } |
| 36 | if ( ! defined( 'HTTP_URL_STRIP_PORT' ) ) { |
| 37 | define( 'HTTP_URL_STRIP_PORT', 64 ); // Strip explicit port numbers |
| 38 | } |
| 39 | if ( ! defined( 'HTTP_URL_STRIP_PATH' ) ) { |
| 40 | define( 'HTTP_URL_STRIP_PATH', 128 ); // Strip complete path |
| 41 | } |
| 42 | if ( ! defined( 'HTTP_URL_STRIP_QUERY' ) ) { |
| 43 | define( 'HTTP_URL_STRIP_QUERY', 256 ); // Strip query string |
| 44 | } |
| 45 | if ( ! defined( 'HTTP_URL_STRIP_FRAGMENT' ) ) { |
| 46 | define( 'HTTP_URL_STRIP_FRAGMENT', 512 ); // Strip any fragments (#identifier) |
| 47 | } |
| 48 | if ( ! defined( 'HTTP_URL_STRIP_ALL' ) ) { |
| 49 | define( 'HTTP_URL_STRIP_ALL', 1024 ); // Strip anything but scheme and host |
| 50 | } |
| 51 | |
| 52 | // Build an URL |
| 53 | // The parts of the second URL will be merged into the first according to the flags argument. |
| 54 | // |
| 55 | // @param mixed (Part(s) of) an URL in form of a string or associative array like parse_url() returns |
| 56 | // @param mixed Same as the first argument |
| 57 | // @param int A bitmask of binary or'ed HTTP_URL constants (Optional)HTTP_URL_REPLACE is the default |
| 58 | // @param array If set, it will be filled with the parts of the composed url like parse_url() would return |
| 59 | function http_build_url( $url, $parts = array(), $flags = HTTP_URL_REPLACE, &$new_url = false ) { |
| 60 | $keys = array( 'user', 'pass', 'port', 'path', 'query', 'fragment' ); |
| 61 | |
| 62 | // HTTP_URL_STRIP_ALL becomes all the HTTP_URL_STRIP_Xs |
| 63 | if ( $flags & HTTP_URL_STRIP_ALL ) { |
| 64 | $flags |= HTTP_URL_STRIP_USER; |
| 65 | $flags |= HTTP_URL_STRIP_PASS; |
| 66 | $flags |= HTTP_URL_STRIP_PORT; |
| 67 | $flags |= HTTP_URL_STRIP_PATH; |
| 68 | $flags |= HTTP_URL_STRIP_QUERY; |
| 69 | $flags |= HTTP_URL_STRIP_FRAGMENT; |
| 70 | } |
| 71 | // HTTP_URL_STRIP_AUTH becomes HTTP_URL_STRIP_USER and HTTP_URL_STRIP_PASS |
| 72 | elseif ( $flags & HTTP_URL_STRIP_AUTH ) { |
| 73 | $flags |= HTTP_URL_STRIP_USER; |
| 74 | $flags |= HTTP_URL_STRIP_PASS; |
| 75 | } |
| 76 | |
| 77 | // Parse the original URL |
| 78 | // - Suggestion by Sayed Ahad Abbas |
| 79 | // In case you send a parse_url array as input |
| 80 | $parse_url = ! is_array( $url ) ? parse_url( $url ) : $url; |
| 81 | |
| 82 | // Scheme and Host are always replaced |
| 83 | if ( isset( $parts['scheme'] ) ) { |
| 84 | $parse_url['scheme'] = $parts['scheme']; |
| 85 | } |
| 86 | if ( isset( $parts['host'] ) ) { |
| 87 | $parse_url['host'] = $parts['host']; |
| 88 | } |
| 89 | |
| 90 | // (If applicable) Replace the original URL with it's new parts |
| 91 | if ( $flags & HTTP_URL_REPLACE ) { |
| 92 | foreach ( $keys as $key ) { |
| 93 | if ( isset( $parts[ $key ] ) ) { |
| 94 | $parse_url[ $key ] = $parts[ $key ]; |
| 95 | } |
| 96 | } |
| 97 | } else { |
| 98 | // Join the original URL path with the new path |
| 99 | if ( isset( $parts['path'] ) && ( $flags & HTTP_URL_JOIN_PATH ) ) { |
| 100 | if ( isset( $parse_url['path'] ) ) { |
| 101 | $parse_url['path'] = rtrim( str_replace( basename( $parse_url['path'] ), '', $parse_url['path'] ), '/' ) . '/' . ltrim( $parts['path'], '/' ); |
| 102 | } else { |
| 103 | $parse_url['path'] = $parts['path']; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // Join the original query string with the new query string |
| 108 | if ( isset( $parts['query'] ) && ( $flags & HTTP_URL_JOIN_QUERY ) ) { |
| 109 | if ( isset( $parse_url['query'] ) ) { |
| 110 | $parse_url['query'] .= '&' . $parts['query']; |
| 111 | } else { |
| 112 | $parse_url['query'] = $parts['query']; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | // Strips all the applicable sections of the URL |
| 118 | // Note: Scheme and Host are never stripped |
| 119 | foreach ( $keys as $key ) { |
| 120 | if ( $flags & (int) constant( 'HTTP_URL_STRIP_' . strtoupper( $key ) ) ) { |
| 121 | unset( $parse_url[ $key ] ); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | $new_url = $parse_url; |
| 126 | |
| 127 | return ( isset( $parse_url['scheme'] ) ? $parse_url['scheme'] . '://' : '' ) |
| 128 | . ( isset( $parse_url['user'] ) ? $parse_url['user'] . ( isset( $parse_url['pass'] ) ? ':' . $parse_url['pass'] : '' ) . '@' : '' ) |
| 129 | . ( isset( $parse_url['host'] ) ? $parse_url['host'] : '' ) |
| 130 | . ( isset( $parse_url['port'] ) ? ':' . $parse_url['port'] : '' ) |
| 131 | . ( isset( $parse_url['path'] ) ? $parse_url['path'] : '' ) |
| 132 | . ( isset( $parse_url['query'] ) ? '?' . $parse_url['query'] : '' ) |
| 133 | . ( isset( $parse_url['fragment'] ) ? '#' . $parse_url['fragment'] : '' ); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | |
| 138 | if ( ! function_exists( 'array_key_first' ) ) { |
| 139 | function array_key_first( array $arr ) { |
| 140 | foreach ( $arr as $k => $unused ) { |
| 141 | return $k; |
| 142 | } |
| 143 | return null; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if ( ! function_exists( 'array_column' ) ) { |
| 148 | function array_column( $array, $column_name ) { |
| 149 | return array_map( |
| 150 | function ( $element ) use ( $column_name ) { |
| 151 | return $element[ $column_name ]; |
| 152 | }, |
| 153 | $array |
| 154 | ); |
| 155 | } |
| 156 | } |
| 157 |