@@ -14,87 +14,87 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @deprecated 4.9.53 |
|
19 | - * @param EE_Request $request |
|
20 | - * @param EE_Response $response |
|
21 | - * @return EE_Response |
|
22 | - */ |
|
23 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
24 | - { |
|
25 | - $this->_request = $request; |
|
26 | - $this->_response = $response; |
|
27 | - $this->display_alpha_banner_warning(); |
|
28 | - $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
29 | - return $this->_response; |
|
30 | - } |
|
17 | + /** |
|
18 | + * @deprecated 4.9.53 |
|
19 | + * @param EE_Request $request |
|
20 | + * @param EE_Response $response |
|
21 | + * @return EE_Response |
|
22 | + */ |
|
23 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
24 | + { |
|
25 | + $this->_request = $request; |
|
26 | + $this->_response = $response; |
|
27 | + $this->display_alpha_banner_warning(); |
|
28 | + $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
29 | + return $this->_response; |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @deprecated |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function display_alpha_banner_warning() |
|
38 | - { |
|
39 | - EE_Error::doing_it_wrong( |
|
40 | - __METHOD__, |
|
41 | - sprintf( |
|
42 | - esc_html__( |
|
43 | - 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::displayPreProductionVersionWarning()', |
|
47 | - '\core\services\request', |
|
48 | - 'EventEspresso\core\services\request' |
|
49 | - ), |
|
50 | - '4.9.52', |
|
51 | - '4.10.0' |
|
52 | - ); |
|
53 | - } |
|
33 | + /** |
|
34 | + * @deprecated |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function display_alpha_banner_warning() |
|
38 | + { |
|
39 | + EE_Error::doing_it_wrong( |
|
40 | + __METHOD__, |
|
41 | + sprintf( |
|
42 | + esc_html__( |
|
43 | + 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::displayPreProductionVersionWarning()', |
|
47 | + '\core\services\request', |
|
48 | + 'EventEspresso\core\services\request' |
|
49 | + ), |
|
50 | + '4.9.52', |
|
51 | + '4.10.0' |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * @deprecated |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function alpha_banner_admin_notice() |
|
61 | - { |
|
62 | - EE_Error::doing_it_wrong( |
|
63 | - __METHOD__, |
|
64 | - sprintf( |
|
65 | - esc_html__( |
|
66 | - 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
67 | - 'event_espresso' |
|
68 | - ), |
|
69 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::preProductionVersionAdminNotice()', |
|
70 | - '\core\services\request', |
|
71 | - 'EventEspresso\core\services\request' |
|
72 | - ), |
|
73 | - '4.9.52', |
|
74 | - '4.10.0' |
|
75 | - ); |
|
76 | - } |
|
56 | + /** |
|
57 | + * @deprecated |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function alpha_banner_admin_notice() |
|
61 | + { |
|
62 | + EE_Error::doing_it_wrong( |
|
63 | + __METHOD__, |
|
64 | + sprintf( |
|
65 | + esc_html__( |
|
66 | + 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
67 | + 'event_espresso' |
|
68 | + ), |
|
69 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::preProductionVersionAdminNotice()', |
|
70 | + '\core\services\request', |
|
71 | + 'EventEspresso\core\services\request' |
|
72 | + ), |
|
73 | + '4.9.52', |
|
74 | + '4.10.0' |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @deprecated |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public function alpha_banner_warning_notice() |
|
84 | - { |
|
85 | - EE_Error::doing_it_wrong( |
|
86 | - __METHOD__, |
|
87 | - sprintf( |
|
88 | - esc_html__( |
|
89 | - 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
90 | - 'event_espresso' |
|
91 | - ), |
|
92 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::preProductionVersionWarningNotice()', |
|
93 | - '\core\services\request', |
|
94 | - 'EventEspresso\core\services\request' |
|
95 | - ), |
|
96 | - '4.9.52', |
|
97 | - '4.10.0' |
|
98 | - ); |
|
99 | - } |
|
79 | + /** |
|
80 | + * @deprecated |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public function alpha_banner_warning_notice() |
|
84 | + { |
|
85 | + EE_Error::doing_it_wrong( |
|
86 | + __METHOD__, |
|
87 | + sprintf( |
|
88 | + esc_html__( |
|
89 | + 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
90 | + 'event_espresso' |
|
91 | + ), |
|
92 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::preProductionVersionWarningNotice()', |
|
93 | + '\core\services\request', |
|
94 | + 'EventEspresso\core\services\request' |
|
95 | + ), |
|
96 | + '4.9.52', |
|
97 | + '4.10.0' |
|
98 | + ); |
|
99 | + } |
|
100 | 100 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function __construct() |
105 | 105 | { |
106 | - if (! defined('ESPRESSO_ENCRYPT')) { |
|
106 | + if ( ! defined('ESPRESSO_ENCRYPT')) { |
|
107 | 107 | define('ESPRESSO_ENCRYPT', true); |
108 | 108 | } |
109 | 109 | if (extension_loaded('openssl')) { |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | public static function instance() |
126 | 126 | { |
127 | 127 | // check if class object is instantiated |
128 | - if (! EE_Encryption::$_instance instanceof EE_Encryption) { |
|
128 | + if ( ! EE_Encryption::$_instance instanceof EE_Encryption) { |
|
129 | 129 | EE_Encryption::$_instance = new self(); |
130 | 130 | } |
131 | 131 | return EE_Encryption::$_instance; |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $iv |
333 | 333 | ); |
334 | 334 | // append the initialization vector |
335 | - $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
335 | + $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER.$iv; |
|
336 | 336 | // trim and maybe encode |
337 | 337 | return $this->_use_base64_encode |
338 | 338 | ? trim(base64_encode($encrypted_text)) |
@@ -525,8 +525,8 @@ discard block |
||
525 | 525 | ); |
526 | 526 | $string_bits = str_split($text_string); |
527 | 527 | foreach ($string_bits as $k => $v) { |
528 | - $temp = ord($v) + ord($key_bits[ $k ]); |
|
529 | - $string_bits[ $k ] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
528 | + $temp = ord($v) + ord($key_bits[$k]); |
|
529 | + $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
530 | 530 | } |
531 | 531 | $encrypted_text = implode('', $string_bits); |
532 | 532 | $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
@@ -570,8 +570,8 @@ discard block |
||
570 | 570 | ); |
571 | 571 | $string_bits = str_split($encrypted_text); |
572 | 572 | foreach ($string_bits as $k => $v) { |
573 | - $temp = ord($v) - ord($key_bits[ $k ]); |
|
574 | - $string_bits[ $k ] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
573 | + $temp = ord($v) - ord($key_bits[$k]); |
|
574 | + $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
575 | 575 | } |
576 | 576 | return implode('', $string_bits); |
577 | 577 | } |
@@ -585,16 +585,16 @@ discard block |
||
585 | 585 | protected function valid_base_64($string) |
586 | 586 | { |
587 | 587 | // ensure data is a string |
588 | - if (! is_string($string) || ! $this->_use_base64_encode) { |
|
588 | + if ( ! is_string($string) || ! $this->_use_base64_encode) { |
|
589 | 589 | return false; |
590 | 590 | } |
591 | 591 | $decoded = base64_decode($string, true); |
592 | 592 | // Check if there is no invalid character in string |
593 | - if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
593 | + if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
594 | 594 | return false; |
595 | 595 | } |
596 | 596 | // Decode the string in strict mode and send the response |
597 | - if (! base64_decode($string, true)) { |
|
597 | + if ( ! base64_decode($string, true)) { |
|
598 | 598 | return false; |
599 | 599 | } |
600 | 600 | // Encode and compare it to original one |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | $iterations = ceil($length / 40); |
615 | 615 | $random_string = ''; |
616 | 616 | for ($i = 0; $i < $iterations; $i++) { |
617 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
617 | + $random_string .= sha1(microtime(true).mt_rand(10000, 90000)); |
|
618 | 618 | } |
619 | 619 | $random_string = substr($random_string, 0, $length); |
620 | 620 | return $random_string; |
@@ -25,581 +25,581 @@ |
||
25 | 25 | class EE_Encryption implements InterminableInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * key used for saving the encryption key to the wp_options table |
|
30 | - */ |
|
31 | - const ENCRYPTION_OPTION_KEY = 'ee_encryption_key'; |
|
32 | - |
|
33 | - /** |
|
34 | - * the OPENSSL cipher method used |
|
35 | - */ |
|
36 | - const OPENSSL_CIPHER_METHOD = 'AES-128-CBC'; |
|
37 | - |
|
38 | - /** |
|
39 | - * WP "options_name" used to store a verified available cipher method |
|
40 | - */ |
|
41 | - const OPENSSL_CIPHER_METHOD_OPTION_NAME = 'ee_openssl_cipher_method'; |
|
42 | - |
|
43 | - /** |
|
44 | - * the OPENSSL digest method used |
|
45 | - */ |
|
46 | - const OPENSSL_DIGEST_METHOD = 'sha512'; |
|
47 | - |
|
48 | - /** |
|
49 | - * separates the encrypted text from the initialization vector |
|
50 | - */ |
|
51 | - const OPENSSL_IV_DELIMITER = ':iv:'; |
|
52 | - |
|
53 | - /** |
|
54 | - * appended to text encrypted using the acme encryption |
|
55 | - */ |
|
56 | - const ACME_ENCRYPTION_FLAG = '::ae'; |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * instance of the EE_Encryption object |
|
61 | - */ |
|
62 | - protected static $_instance; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var string $_encryption_key |
|
66 | - */ |
|
67 | - protected $_encryption_key; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var string $cipher_method |
|
71 | - */ |
|
72 | - private $cipher_method = ''; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var array $cipher_methods |
|
76 | - */ |
|
77 | - private $cipher_methods = array(); |
|
78 | - |
|
79 | - /** |
|
80 | - * @var array $digest_methods |
|
81 | - */ |
|
82 | - private $digest_methods = array(); |
|
83 | - |
|
84 | - /** |
|
85 | - * @var boolean $_use_openssl_encrypt |
|
86 | - */ |
|
87 | - protected $_use_openssl_encrypt = false; |
|
88 | - |
|
89 | - /** |
|
90 | - * @var boolean $_use_base64_encode |
|
91 | - */ |
|
92 | - protected $_use_base64_encode = false; |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * protected constructor to prevent direct creation |
|
97 | - */ |
|
98 | - protected function __construct() |
|
99 | - { |
|
100 | - if (! defined('ESPRESSO_ENCRYPT')) { |
|
101 | - define('ESPRESSO_ENCRYPT', true); |
|
102 | - } |
|
103 | - if (extension_loaded('openssl')) { |
|
104 | - $this->_use_openssl_encrypt = true; |
|
105 | - } |
|
106 | - if (function_exists('base64_encode')) { |
|
107 | - $this->_use_base64_encode = true; |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * singleton method used to instantiate class object |
|
114 | - * |
|
115 | - * @return EE_Encryption |
|
116 | - */ |
|
117 | - public static function instance() |
|
118 | - { |
|
119 | - // check if class object is instantiated |
|
120 | - if (! EE_Encryption::$_instance instanceof EE_Encryption) { |
|
121 | - EE_Encryption::$_instance = new self(); |
|
122 | - } |
|
123 | - return EE_Encryption::$_instance; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * get encryption key |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function get_encryption_key() |
|
133 | - { |
|
134 | - // if encryption key has not been set |
|
135 | - if (empty($this->_encryption_key)) { |
|
136 | - // retrieve encryption_key from db |
|
137 | - $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, ''); |
|
138 | - // WHAT?? No encryption_key in the db ?? |
|
139 | - if ($this->_encryption_key === '') { |
|
140 | - // let's make one. And md5 it to make it just the right size for a key |
|
141 | - $new_key = md5($this->generate_random_string()); |
|
142 | - // now save it to the db for later |
|
143 | - add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key); |
|
144 | - // here's the key - FINALLY ! |
|
145 | - $this->_encryption_key = $new_key; |
|
146 | - } |
|
147 | - } |
|
148 | - return $this->_encryption_key; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * encrypts data |
|
154 | - * |
|
155 | - * @param string $text_string - the text to be encrypted |
|
156 | - * @return string |
|
157 | - * @throws RuntimeException |
|
158 | - */ |
|
159 | - public function encrypt($text_string = '') |
|
160 | - { |
|
161 | - // you give me nothing??? GET OUT ! |
|
162 | - if (empty($text_string)) { |
|
163 | - return $text_string; |
|
164 | - } |
|
165 | - if ($this->_use_openssl_encrypt) { |
|
166 | - $encrypted_text = $this->openssl_encrypt($text_string); |
|
167 | - } else { |
|
168 | - $encrypted_text = $this->acme_encrypt($text_string); |
|
169 | - } |
|
170 | - return $encrypted_text; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * decrypts data |
|
176 | - * |
|
177 | - * @param string $encrypted_text - the text to be decrypted |
|
178 | - * @return string |
|
179 | - * @throws RuntimeException |
|
180 | - */ |
|
181 | - public function decrypt($encrypted_text = '') |
|
182 | - { |
|
183 | - // you give me nothing??? GET OUT ! |
|
184 | - if (empty($encrypted_text)) { |
|
185 | - return $encrypted_text; |
|
186 | - } |
|
187 | - // if PHP's mcrypt functions are installed then we'll use them |
|
188 | - if ($this->_use_openssl_encrypt) { |
|
189 | - $decrypted_text = $this->openssl_decrypt($encrypted_text); |
|
190 | - } else { |
|
191 | - $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
192 | - } |
|
193 | - return $decrypted_text; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * encodes string with PHP's base64 encoding |
|
199 | - * |
|
200 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
201 | - * @param string $text_string the text to be encoded |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - public function base64_string_encode($text_string = '') |
|
205 | - { |
|
206 | - // you give me nothing??? GET OUT ! |
|
207 | - if (empty($text_string) || ! $this->_use_base64_encode) { |
|
208 | - return $text_string; |
|
209 | - } |
|
210 | - // encode |
|
211 | - return base64_encode($text_string); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * decodes string that has been encoded with PHP's base64 encoding |
|
217 | - * |
|
218 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
219 | - * @param string $encoded_string the text to be decoded |
|
220 | - * @return string |
|
221 | - * @throws RuntimeException |
|
222 | - */ |
|
223 | - public function base64_string_decode($encoded_string = '') |
|
224 | - { |
|
225 | - // you give me nothing??? GET OUT ! |
|
226 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
227 | - return $encoded_string; |
|
228 | - } |
|
229 | - // decode |
|
230 | - $decoded_string = base64_decode($encoded_string); |
|
231 | - if ($decoded_string === false) { |
|
232 | - throw new RuntimeException( |
|
233 | - esc_html__('Base 64 decoding failed.', 'event_espresso') |
|
234 | - ); |
|
235 | - } |
|
236 | - return $decoded_string; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * encodes url string with PHP's base64 encoding |
|
242 | - * |
|
243 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
244 | - * @param string $text_string the text to be encoded |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - public function base64_url_encode($text_string = '') |
|
248 | - { |
|
249 | - // you give me nothing??? GET OUT ! |
|
250 | - if (empty($text_string) || ! $this->_use_base64_encode) { |
|
251 | - return $text_string; |
|
252 | - } |
|
253 | - // encode |
|
254 | - $encoded_string = base64_encode($text_string); |
|
255 | - // remove chars to make encoding more URL friendly |
|
256 | - return strtr($encoded_string, '+/=', '-_,'); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * decodes url string that has been encoded with PHP's base64 encoding |
|
262 | - * |
|
263 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
264 | - * @param string $encoded_string the text to be decoded |
|
265 | - * @return string |
|
266 | - * @throws RuntimeException |
|
267 | - */ |
|
268 | - public function base64_url_decode($encoded_string = '') |
|
269 | - { |
|
270 | - // you give me nothing??? GET OUT ! |
|
271 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
272 | - return $encoded_string; |
|
273 | - } |
|
274 | - // replace previously removed characters |
|
275 | - $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
276 | - // decode |
|
277 | - $decoded_string = base64_decode($encoded_string); |
|
278 | - if ($decoded_string === false) { |
|
279 | - throw new RuntimeException( |
|
280 | - esc_html__('Base 64 decoding failed.', 'event_espresso') |
|
281 | - ); |
|
282 | - } |
|
283 | - return $decoded_string; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * encrypts data using PHP's openssl functions |
|
289 | - * |
|
290 | - * @param string $text_string the text to be encrypted |
|
291 | - * @param string $cipher_method |
|
292 | - * @param string $encryption_key |
|
293 | - * @return string |
|
294 | - * @throws RuntimeException |
|
295 | - */ |
|
296 | - protected function openssl_encrypt( |
|
297 | - $text_string = '', |
|
298 | - $cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
299 | - $encryption_key = '' |
|
300 | - ) { |
|
301 | - // you give me nothing??? GET OUT ! |
|
302 | - if (empty($text_string)) { |
|
303 | - return $text_string; |
|
304 | - } |
|
305 | - $this->cipher_method = $this->getCipherMethod($cipher_method); |
|
306 | - // get initialization vector size |
|
307 | - $iv_size = openssl_cipher_iv_length($this->cipher_method); |
|
308 | - // generate initialization vector. |
|
309 | - // The second parameter ("crypto_strong") is passed by reference, |
|
310 | - // and is used to determines if the algorithm used was "cryptographically strong" |
|
311 | - // openssl_random_pseudo_bytes() will toggle it to either true or false |
|
312 | - $iv = openssl_random_pseudo_bytes($iv_size, $is_strong); |
|
313 | - if ($iv === false || $is_strong === false) { |
|
314 | - throw new RuntimeException( |
|
315 | - esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso') |
|
316 | - ); |
|
317 | - } |
|
318 | - // encrypt it |
|
319 | - $encrypted_text = openssl_encrypt( |
|
320 | - $text_string, |
|
321 | - $this->cipher_method, |
|
322 | - $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key), |
|
323 | - 0, |
|
324 | - $iv |
|
325 | - ); |
|
326 | - // append the initialization vector |
|
327 | - $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
328 | - // trim and maybe encode |
|
329 | - return $this->_use_base64_encode |
|
330 | - ? trim(base64_encode($encrypted_text)) |
|
331 | - : trim($encrypted_text); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * Returns a cipher method that has been verified to work. |
|
337 | - * First checks if the cached cipher has been set already and if so, returns that. |
|
338 | - * Then tests the incoming default and returns that if it's good. |
|
339 | - * If not, then it retrieves the previously tested and saved cipher method. |
|
340 | - * But if that doesn't exist, then calls getAvailableCipherMethod() |
|
341 | - * to see what is available on the server, and returns the results. |
|
342 | - * |
|
343 | - * @param string $cipher_method |
|
344 | - * @return string |
|
345 | - * @throws RuntimeException |
|
346 | - */ |
|
347 | - protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD) |
|
348 | - { |
|
349 | - if ($this->cipher_method !== '') { |
|
350 | - return $this->cipher_method; |
|
351 | - } |
|
352 | - // verify that the default cipher method can produce an initialization vector |
|
353 | - if (openssl_cipher_iv_length($cipher_method) === false) { |
|
354 | - // nope? okay let's get what we found in the past to work |
|
355 | - $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, ''); |
|
356 | - // oops... haven't tested available cipher methods yet |
|
357 | - if ($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) { |
|
358 | - $cipher_method = $this->getAvailableCipherMethod($cipher_method); |
|
359 | - } |
|
360 | - } |
|
361 | - return $cipher_method; |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * @param string $cipher_method |
|
367 | - * @return string |
|
368 | - * @throws \RuntimeException |
|
369 | - */ |
|
370 | - protected function getAvailableCipherMethod($cipher_method) |
|
371 | - { |
|
372 | - // verify that the incoming cipher method can produce an initialization vector |
|
373 | - if (openssl_cipher_iv_length($cipher_method) === false) { |
|
374 | - // nope? then check the next cipher in the list of available cipher methods |
|
375 | - $cipher_method = next($this->cipher_methods); |
|
376 | - // what? there's no list? then generate that list and cache it, |
|
377 | - if (empty($this->cipher_methods)) { |
|
378 | - $this->cipher_methods = openssl_get_cipher_methods(); |
|
379 | - // then grab the first item from the list |
|
380 | - $cipher_method = reset($this->cipher_methods); |
|
381 | - } |
|
382 | - if ($cipher_method === false) { |
|
383 | - throw new RuntimeException( |
|
384 | - esc_html__( |
|
385 | - 'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.', |
|
386 | - 'event_espresso' |
|
387 | - ) |
|
388 | - ); |
|
389 | - } |
|
390 | - // verify that the next cipher method works |
|
391 | - return $this->getAvailableCipherMethod($cipher_method); |
|
392 | - } |
|
393 | - // if we've gotten this far, then we found an available cipher method that works |
|
394 | - // so save that for next time |
|
395 | - update_option( |
|
396 | - EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, |
|
397 | - $cipher_method |
|
398 | - ); |
|
399 | - return $cipher_method; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * decrypts data that has been encrypted with PHP's openssl functions |
|
405 | - * |
|
406 | - * @param string $encrypted_text the text to be decrypted |
|
407 | - * @param string $cipher_method |
|
408 | - * @param string $encryption_key |
|
409 | - * @return string |
|
410 | - * @throws RuntimeException |
|
411 | - */ |
|
412 | - protected function openssl_decrypt( |
|
413 | - $encrypted_text = '', |
|
414 | - $cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
415 | - $encryption_key = '' |
|
416 | - ) { |
|
417 | - // you give me nothing??? GET OUT ! |
|
418 | - if (empty($encrypted_text)) { |
|
419 | - return $encrypted_text; |
|
420 | - } |
|
421 | - // decode |
|
422 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
423 | - ? $this->base64_url_decode($encrypted_text) |
|
424 | - : $encrypted_text; |
|
425 | - $encrypted_components = explode( |
|
426 | - EE_Encryption::OPENSSL_IV_DELIMITER, |
|
427 | - $encrypted_text, |
|
428 | - 2 |
|
429 | - ); |
|
430 | - // decrypt it |
|
431 | - $decrypted_text = openssl_decrypt( |
|
432 | - $encrypted_components[0], |
|
433 | - $this->getCipherMethod($cipher_method), |
|
434 | - $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key), |
|
435 | - 0, |
|
436 | - $encrypted_components[1] |
|
437 | - ); |
|
438 | - $decrypted_text = trim($decrypted_text); |
|
439 | - return $decrypted_text; |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * Computes the digest hash value using the specified digest method. |
|
445 | - * If that digest method fails to produce a valid hash value, |
|
446 | - * then we'll grab the next digest method and recursively try again until something works. |
|
447 | - * |
|
448 | - * @param string $digest_method |
|
449 | - * @param string $encryption_key |
|
450 | - * @return string |
|
451 | - * @throws RuntimeException |
|
452 | - */ |
|
453 | - protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key = '') |
|
454 | - { |
|
455 | - $encryption_key = $encryption_key !== '' |
|
456 | - ? $encryption_key |
|
457 | - : $this->get_encryption_key(); |
|
458 | - $digest_hash_value = openssl_digest($encryption_key, $digest_method); |
|
459 | - if ($digest_hash_value === false) { |
|
460 | - return $this->getDigestHashValue($this->getDigestMethod()); |
|
461 | - } |
|
462 | - return $digest_hash_value; |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * Returns the NEXT element in the $digest_methods array. |
|
468 | - * If the $digest_methods array is empty, then we populate it |
|
469 | - * with the available values returned from openssl_get_md_methods(). |
|
470 | - * |
|
471 | - * @return string |
|
472 | - * @throws \RuntimeException |
|
473 | - */ |
|
474 | - protected function getDigestMethod() |
|
475 | - { |
|
476 | - $digest_method = prev($this->digest_methods); |
|
477 | - if (empty($this->digest_methods)) { |
|
478 | - $this->digest_methods = openssl_get_md_methods(); |
|
479 | - $digest_method = end($this->digest_methods); |
|
480 | - } |
|
481 | - if ($digest_method === false) { |
|
482 | - throw new RuntimeException( |
|
483 | - esc_html__( |
|
484 | - 'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.', |
|
485 | - 'event_espresso' |
|
486 | - ) |
|
487 | - ); |
|
488 | - } |
|
489 | - return $digest_method; |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
495 | - * |
|
496 | - * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
497 | - * @param string $text_string the text to be decrypted |
|
498 | - * @return string |
|
499 | - */ |
|
500 | - protected function acme_encrypt($text_string = '') |
|
501 | - { |
|
502 | - // you give me nothing??? GET OUT ! |
|
503 | - if (empty($text_string)) { |
|
504 | - return $text_string; |
|
505 | - } |
|
506 | - $key_bits = str_split( |
|
507 | - str_pad( |
|
508 | - '', |
|
509 | - strlen($text_string), |
|
510 | - $this->get_encryption_key(), |
|
511 | - STR_PAD_RIGHT |
|
512 | - ) |
|
513 | - ); |
|
514 | - $string_bits = str_split($text_string); |
|
515 | - foreach ($string_bits as $k => $v) { |
|
516 | - $temp = ord($v) + ord($key_bits[ $k ]); |
|
517 | - $string_bits[ $k ] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
518 | - } |
|
519 | - $encrypted_text = implode('', $string_bits); |
|
520 | - $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
|
521 | - return $this->_use_base64_encode |
|
522 | - ? base64_encode($encrypted_text) |
|
523 | - : $encrypted_text; |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
529 | - * |
|
530 | - * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
531 | - * @param string $encrypted_text the text to be decrypted |
|
532 | - * @return string |
|
533 | - * @throws RuntimeException |
|
534 | - */ |
|
535 | - protected function acme_decrypt($encrypted_text = '') |
|
536 | - { |
|
537 | - // you give me nothing??? GET OUT ! |
|
538 | - if (empty($encrypted_text)) { |
|
539 | - return $encrypted_text; |
|
540 | - } |
|
541 | - // decode the data ? |
|
542 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
543 | - ? $this->base64_url_decode($encrypted_text) |
|
544 | - : $encrypted_text; |
|
545 | - $encrypted_text = substr($encrypted_text, 0, -4); |
|
546 | - $key_bits = str_split( |
|
547 | - str_pad( |
|
548 | - '', |
|
549 | - strlen($encrypted_text), |
|
550 | - $this->get_encryption_key(), |
|
551 | - STR_PAD_RIGHT |
|
552 | - ) |
|
553 | - ); |
|
554 | - $string_bits = str_split($encrypted_text); |
|
555 | - foreach ($string_bits as $k => $v) { |
|
556 | - $temp = ord($v) - ord($key_bits[ $k ]); |
|
557 | - $string_bits[ $k ] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
558 | - } |
|
559 | - return implode('', $string_bits); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
565 | - * @param $string |
|
566 | - * @return bool |
|
567 | - */ |
|
568 | - protected function valid_base_64($string) |
|
569 | - { |
|
570 | - // ensure data is a string |
|
571 | - if (! is_string($string) || ! $this->_use_base64_encode) { |
|
572 | - return false; |
|
573 | - } |
|
574 | - $decoded = base64_decode($string, true); |
|
575 | - // Check if there is no invalid character in string |
|
576 | - if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
577 | - return false; |
|
578 | - } |
|
579 | - // Decode the string in strict mode and send the response |
|
580 | - if (! base64_decode($string, true)) { |
|
581 | - return false; |
|
582 | - } |
|
583 | - // Encode and compare it to original one |
|
584 | - return base64_encode($decoded) === $string; |
|
585 | - } |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * generate random string |
|
590 | - * |
|
591 | - * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
592 | - * @param int $length number of characters for random string |
|
593 | - * @return string |
|
594 | - */ |
|
595 | - public function generate_random_string($length = 40) |
|
596 | - { |
|
597 | - $iterations = ceil($length / 40); |
|
598 | - $random_string = ''; |
|
599 | - for ($i = 0; $i < $iterations; $i++) { |
|
600 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
601 | - } |
|
602 | - $random_string = substr($random_string, 0, $length); |
|
603 | - return $random_string; |
|
604 | - } |
|
28 | + /** |
|
29 | + * key used for saving the encryption key to the wp_options table |
|
30 | + */ |
|
31 | + const ENCRYPTION_OPTION_KEY = 'ee_encryption_key'; |
|
32 | + |
|
33 | + /** |
|
34 | + * the OPENSSL cipher method used |
|
35 | + */ |
|
36 | + const OPENSSL_CIPHER_METHOD = 'AES-128-CBC'; |
|
37 | + |
|
38 | + /** |
|
39 | + * WP "options_name" used to store a verified available cipher method |
|
40 | + */ |
|
41 | + const OPENSSL_CIPHER_METHOD_OPTION_NAME = 'ee_openssl_cipher_method'; |
|
42 | + |
|
43 | + /** |
|
44 | + * the OPENSSL digest method used |
|
45 | + */ |
|
46 | + const OPENSSL_DIGEST_METHOD = 'sha512'; |
|
47 | + |
|
48 | + /** |
|
49 | + * separates the encrypted text from the initialization vector |
|
50 | + */ |
|
51 | + const OPENSSL_IV_DELIMITER = ':iv:'; |
|
52 | + |
|
53 | + /** |
|
54 | + * appended to text encrypted using the acme encryption |
|
55 | + */ |
|
56 | + const ACME_ENCRYPTION_FLAG = '::ae'; |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * instance of the EE_Encryption object |
|
61 | + */ |
|
62 | + protected static $_instance; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var string $_encryption_key |
|
66 | + */ |
|
67 | + protected $_encryption_key; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var string $cipher_method |
|
71 | + */ |
|
72 | + private $cipher_method = ''; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var array $cipher_methods |
|
76 | + */ |
|
77 | + private $cipher_methods = array(); |
|
78 | + |
|
79 | + /** |
|
80 | + * @var array $digest_methods |
|
81 | + */ |
|
82 | + private $digest_methods = array(); |
|
83 | + |
|
84 | + /** |
|
85 | + * @var boolean $_use_openssl_encrypt |
|
86 | + */ |
|
87 | + protected $_use_openssl_encrypt = false; |
|
88 | + |
|
89 | + /** |
|
90 | + * @var boolean $_use_base64_encode |
|
91 | + */ |
|
92 | + protected $_use_base64_encode = false; |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * protected constructor to prevent direct creation |
|
97 | + */ |
|
98 | + protected function __construct() |
|
99 | + { |
|
100 | + if (! defined('ESPRESSO_ENCRYPT')) { |
|
101 | + define('ESPRESSO_ENCRYPT', true); |
|
102 | + } |
|
103 | + if (extension_loaded('openssl')) { |
|
104 | + $this->_use_openssl_encrypt = true; |
|
105 | + } |
|
106 | + if (function_exists('base64_encode')) { |
|
107 | + $this->_use_base64_encode = true; |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * singleton method used to instantiate class object |
|
114 | + * |
|
115 | + * @return EE_Encryption |
|
116 | + */ |
|
117 | + public static function instance() |
|
118 | + { |
|
119 | + // check if class object is instantiated |
|
120 | + if (! EE_Encryption::$_instance instanceof EE_Encryption) { |
|
121 | + EE_Encryption::$_instance = new self(); |
|
122 | + } |
|
123 | + return EE_Encryption::$_instance; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * get encryption key |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function get_encryption_key() |
|
133 | + { |
|
134 | + // if encryption key has not been set |
|
135 | + if (empty($this->_encryption_key)) { |
|
136 | + // retrieve encryption_key from db |
|
137 | + $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, ''); |
|
138 | + // WHAT?? No encryption_key in the db ?? |
|
139 | + if ($this->_encryption_key === '') { |
|
140 | + // let's make one. And md5 it to make it just the right size for a key |
|
141 | + $new_key = md5($this->generate_random_string()); |
|
142 | + // now save it to the db for later |
|
143 | + add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key); |
|
144 | + // here's the key - FINALLY ! |
|
145 | + $this->_encryption_key = $new_key; |
|
146 | + } |
|
147 | + } |
|
148 | + return $this->_encryption_key; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * encrypts data |
|
154 | + * |
|
155 | + * @param string $text_string - the text to be encrypted |
|
156 | + * @return string |
|
157 | + * @throws RuntimeException |
|
158 | + */ |
|
159 | + public function encrypt($text_string = '') |
|
160 | + { |
|
161 | + // you give me nothing??? GET OUT ! |
|
162 | + if (empty($text_string)) { |
|
163 | + return $text_string; |
|
164 | + } |
|
165 | + if ($this->_use_openssl_encrypt) { |
|
166 | + $encrypted_text = $this->openssl_encrypt($text_string); |
|
167 | + } else { |
|
168 | + $encrypted_text = $this->acme_encrypt($text_string); |
|
169 | + } |
|
170 | + return $encrypted_text; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * decrypts data |
|
176 | + * |
|
177 | + * @param string $encrypted_text - the text to be decrypted |
|
178 | + * @return string |
|
179 | + * @throws RuntimeException |
|
180 | + */ |
|
181 | + public function decrypt($encrypted_text = '') |
|
182 | + { |
|
183 | + // you give me nothing??? GET OUT ! |
|
184 | + if (empty($encrypted_text)) { |
|
185 | + return $encrypted_text; |
|
186 | + } |
|
187 | + // if PHP's mcrypt functions are installed then we'll use them |
|
188 | + if ($this->_use_openssl_encrypt) { |
|
189 | + $decrypted_text = $this->openssl_decrypt($encrypted_text); |
|
190 | + } else { |
|
191 | + $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
192 | + } |
|
193 | + return $decrypted_text; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * encodes string with PHP's base64 encoding |
|
199 | + * |
|
200 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
201 | + * @param string $text_string the text to be encoded |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + public function base64_string_encode($text_string = '') |
|
205 | + { |
|
206 | + // you give me nothing??? GET OUT ! |
|
207 | + if (empty($text_string) || ! $this->_use_base64_encode) { |
|
208 | + return $text_string; |
|
209 | + } |
|
210 | + // encode |
|
211 | + return base64_encode($text_string); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * decodes string that has been encoded with PHP's base64 encoding |
|
217 | + * |
|
218 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
219 | + * @param string $encoded_string the text to be decoded |
|
220 | + * @return string |
|
221 | + * @throws RuntimeException |
|
222 | + */ |
|
223 | + public function base64_string_decode($encoded_string = '') |
|
224 | + { |
|
225 | + // you give me nothing??? GET OUT ! |
|
226 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
227 | + return $encoded_string; |
|
228 | + } |
|
229 | + // decode |
|
230 | + $decoded_string = base64_decode($encoded_string); |
|
231 | + if ($decoded_string === false) { |
|
232 | + throw new RuntimeException( |
|
233 | + esc_html__('Base 64 decoding failed.', 'event_espresso') |
|
234 | + ); |
|
235 | + } |
|
236 | + return $decoded_string; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * encodes url string with PHP's base64 encoding |
|
242 | + * |
|
243 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
244 | + * @param string $text_string the text to be encoded |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + public function base64_url_encode($text_string = '') |
|
248 | + { |
|
249 | + // you give me nothing??? GET OUT ! |
|
250 | + if (empty($text_string) || ! $this->_use_base64_encode) { |
|
251 | + return $text_string; |
|
252 | + } |
|
253 | + // encode |
|
254 | + $encoded_string = base64_encode($text_string); |
|
255 | + // remove chars to make encoding more URL friendly |
|
256 | + return strtr($encoded_string, '+/=', '-_,'); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * decodes url string that has been encoded with PHP's base64 encoding |
|
262 | + * |
|
263 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
264 | + * @param string $encoded_string the text to be decoded |
|
265 | + * @return string |
|
266 | + * @throws RuntimeException |
|
267 | + */ |
|
268 | + public function base64_url_decode($encoded_string = '') |
|
269 | + { |
|
270 | + // you give me nothing??? GET OUT ! |
|
271 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
272 | + return $encoded_string; |
|
273 | + } |
|
274 | + // replace previously removed characters |
|
275 | + $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
276 | + // decode |
|
277 | + $decoded_string = base64_decode($encoded_string); |
|
278 | + if ($decoded_string === false) { |
|
279 | + throw new RuntimeException( |
|
280 | + esc_html__('Base 64 decoding failed.', 'event_espresso') |
|
281 | + ); |
|
282 | + } |
|
283 | + return $decoded_string; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * encrypts data using PHP's openssl functions |
|
289 | + * |
|
290 | + * @param string $text_string the text to be encrypted |
|
291 | + * @param string $cipher_method |
|
292 | + * @param string $encryption_key |
|
293 | + * @return string |
|
294 | + * @throws RuntimeException |
|
295 | + */ |
|
296 | + protected function openssl_encrypt( |
|
297 | + $text_string = '', |
|
298 | + $cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
299 | + $encryption_key = '' |
|
300 | + ) { |
|
301 | + // you give me nothing??? GET OUT ! |
|
302 | + if (empty($text_string)) { |
|
303 | + return $text_string; |
|
304 | + } |
|
305 | + $this->cipher_method = $this->getCipherMethod($cipher_method); |
|
306 | + // get initialization vector size |
|
307 | + $iv_size = openssl_cipher_iv_length($this->cipher_method); |
|
308 | + // generate initialization vector. |
|
309 | + // The second parameter ("crypto_strong") is passed by reference, |
|
310 | + // and is used to determines if the algorithm used was "cryptographically strong" |
|
311 | + // openssl_random_pseudo_bytes() will toggle it to either true or false |
|
312 | + $iv = openssl_random_pseudo_bytes($iv_size, $is_strong); |
|
313 | + if ($iv === false || $is_strong === false) { |
|
314 | + throw new RuntimeException( |
|
315 | + esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso') |
|
316 | + ); |
|
317 | + } |
|
318 | + // encrypt it |
|
319 | + $encrypted_text = openssl_encrypt( |
|
320 | + $text_string, |
|
321 | + $this->cipher_method, |
|
322 | + $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key), |
|
323 | + 0, |
|
324 | + $iv |
|
325 | + ); |
|
326 | + // append the initialization vector |
|
327 | + $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
328 | + // trim and maybe encode |
|
329 | + return $this->_use_base64_encode |
|
330 | + ? trim(base64_encode($encrypted_text)) |
|
331 | + : trim($encrypted_text); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * Returns a cipher method that has been verified to work. |
|
337 | + * First checks if the cached cipher has been set already and if so, returns that. |
|
338 | + * Then tests the incoming default and returns that if it's good. |
|
339 | + * If not, then it retrieves the previously tested and saved cipher method. |
|
340 | + * But if that doesn't exist, then calls getAvailableCipherMethod() |
|
341 | + * to see what is available on the server, and returns the results. |
|
342 | + * |
|
343 | + * @param string $cipher_method |
|
344 | + * @return string |
|
345 | + * @throws RuntimeException |
|
346 | + */ |
|
347 | + protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD) |
|
348 | + { |
|
349 | + if ($this->cipher_method !== '') { |
|
350 | + return $this->cipher_method; |
|
351 | + } |
|
352 | + // verify that the default cipher method can produce an initialization vector |
|
353 | + if (openssl_cipher_iv_length($cipher_method) === false) { |
|
354 | + // nope? okay let's get what we found in the past to work |
|
355 | + $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, ''); |
|
356 | + // oops... haven't tested available cipher methods yet |
|
357 | + if ($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) { |
|
358 | + $cipher_method = $this->getAvailableCipherMethod($cipher_method); |
|
359 | + } |
|
360 | + } |
|
361 | + return $cipher_method; |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * @param string $cipher_method |
|
367 | + * @return string |
|
368 | + * @throws \RuntimeException |
|
369 | + */ |
|
370 | + protected function getAvailableCipherMethod($cipher_method) |
|
371 | + { |
|
372 | + // verify that the incoming cipher method can produce an initialization vector |
|
373 | + if (openssl_cipher_iv_length($cipher_method) === false) { |
|
374 | + // nope? then check the next cipher in the list of available cipher methods |
|
375 | + $cipher_method = next($this->cipher_methods); |
|
376 | + // what? there's no list? then generate that list and cache it, |
|
377 | + if (empty($this->cipher_methods)) { |
|
378 | + $this->cipher_methods = openssl_get_cipher_methods(); |
|
379 | + // then grab the first item from the list |
|
380 | + $cipher_method = reset($this->cipher_methods); |
|
381 | + } |
|
382 | + if ($cipher_method === false) { |
|
383 | + throw new RuntimeException( |
|
384 | + esc_html__( |
|
385 | + 'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.', |
|
386 | + 'event_espresso' |
|
387 | + ) |
|
388 | + ); |
|
389 | + } |
|
390 | + // verify that the next cipher method works |
|
391 | + return $this->getAvailableCipherMethod($cipher_method); |
|
392 | + } |
|
393 | + // if we've gotten this far, then we found an available cipher method that works |
|
394 | + // so save that for next time |
|
395 | + update_option( |
|
396 | + EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, |
|
397 | + $cipher_method |
|
398 | + ); |
|
399 | + return $cipher_method; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * decrypts data that has been encrypted with PHP's openssl functions |
|
405 | + * |
|
406 | + * @param string $encrypted_text the text to be decrypted |
|
407 | + * @param string $cipher_method |
|
408 | + * @param string $encryption_key |
|
409 | + * @return string |
|
410 | + * @throws RuntimeException |
|
411 | + */ |
|
412 | + protected function openssl_decrypt( |
|
413 | + $encrypted_text = '', |
|
414 | + $cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
415 | + $encryption_key = '' |
|
416 | + ) { |
|
417 | + // you give me nothing??? GET OUT ! |
|
418 | + if (empty($encrypted_text)) { |
|
419 | + return $encrypted_text; |
|
420 | + } |
|
421 | + // decode |
|
422 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
423 | + ? $this->base64_url_decode($encrypted_text) |
|
424 | + : $encrypted_text; |
|
425 | + $encrypted_components = explode( |
|
426 | + EE_Encryption::OPENSSL_IV_DELIMITER, |
|
427 | + $encrypted_text, |
|
428 | + 2 |
|
429 | + ); |
|
430 | + // decrypt it |
|
431 | + $decrypted_text = openssl_decrypt( |
|
432 | + $encrypted_components[0], |
|
433 | + $this->getCipherMethod($cipher_method), |
|
434 | + $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key), |
|
435 | + 0, |
|
436 | + $encrypted_components[1] |
|
437 | + ); |
|
438 | + $decrypted_text = trim($decrypted_text); |
|
439 | + return $decrypted_text; |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * Computes the digest hash value using the specified digest method. |
|
445 | + * If that digest method fails to produce a valid hash value, |
|
446 | + * then we'll grab the next digest method and recursively try again until something works. |
|
447 | + * |
|
448 | + * @param string $digest_method |
|
449 | + * @param string $encryption_key |
|
450 | + * @return string |
|
451 | + * @throws RuntimeException |
|
452 | + */ |
|
453 | + protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key = '') |
|
454 | + { |
|
455 | + $encryption_key = $encryption_key !== '' |
|
456 | + ? $encryption_key |
|
457 | + : $this->get_encryption_key(); |
|
458 | + $digest_hash_value = openssl_digest($encryption_key, $digest_method); |
|
459 | + if ($digest_hash_value === false) { |
|
460 | + return $this->getDigestHashValue($this->getDigestMethod()); |
|
461 | + } |
|
462 | + return $digest_hash_value; |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * Returns the NEXT element in the $digest_methods array. |
|
468 | + * If the $digest_methods array is empty, then we populate it |
|
469 | + * with the available values returned from openssl_get_md_methods(). |
|
470 | + * |
|
471 | + * @return string |
|
472 | + * @throws \RuntimeException |
|
473 | + */ |
|
474 | + protected function getDigestMethod() |
|
475 | + { |
|
476 | + $digest_method = prev($this->digest_methods); |
|
477 | + if (empty($this->digest_methods)) { |
|
478 | + $this->digest_methods = openssl_get_md_methods(); |
|
479 | + $digest_method = end($this->digest_methods); |
|
480 | + } |
|
481 | + if ($digest_method === false) { |
|
482 | + throw new RuntimeException( |
|
483 | + esc_html__( |
|
484 | + 'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.', |
|
485 | + 'event_espresso' |
|
486 | + ) |
|
487 | + ); |
|
488 | + } |
|
489 | + return $digest_method; |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
495 | + * |
|
496 | + * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
497 | + * @param string $text_string the text to be decrypted |
|
498 | + * @return string |
|
499 | + */ |
|
500 | + protected function acme_encrypt($text_string = '') |
|
501 | + { |
|
502 | + // you give me nothing??? GET OUT ! |
|
503 | + if (empty($text_string)) { |
|
504 | + return $text_string; |
|
505 | + } |
|
506 | + $key_bits = str_split( |
|
507 | + str_pad( |
|
508 | + '', |
|
509 | + strlen($text_string), |
|
510 | + $this->get_encryption_key(), |
|
511 | + STR_PAD_RIGHT |
|
512 | + ) |
|
513 | + ); |
|
514 | + $string_bits = str_split($text_string); |
|
515 | + foreach ($string_bits as $k => $v) { |
|
516 | + $temp = ord($v) + ord($key_bits[ $k ]); |
|
517 | + $string_bits[ $k ] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
518 | + } |
|
519 | + $encrypted_text = implode('', $string_bits); |
|
520 | + $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
|
521 | + return $this->_use_base64_encode |
|
522 | + ? base64_encode($encrypted_text) |
|
523 | + : $encrypted_text; |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
529 | + * |
|
530 | + * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
531 | + * @param string $encrypted_text the text to be decrypted |
|
532 | + * @return string |
|
533 | + * @throws RuntimeException |
|
534 | + */ |
|
535 | + protected function acme_decrypt($encrypted_text = '') |
|
536 | + { |
|
537 | + // you give me nothing??? GET OUT ! |
|
538 | + if (empty($encrypted_text)) { |
|
539 | + return $encrypted_text; |
|
540 | + } |
|
541 | + // decode the data ? |
|
542 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
543 | + ? $this->base64_url_decode($encrypted_text) |
|
544 | + : $encrypted_text; |
|
545 | + $encrypted_text = substr($encrypted_text, 0, -4); |
|
546 | + $key_bits = str_split( |
|
547 | + str_pad( |
|
548 | + '', |
|
549 | + strlen($encrypted_text), |
|
550 | + $this->get_encryption_key(), |
|
551 | + STR_PAD_RIGHT |
|
552 | + ) |
|
553 | + ); |
|
554 | + $string_bits = str_split($encrypted_text); |
|
555 | + foreach ($string_bits as $k => $v) { |
|
556 | + $temp = ord($v) - ord($key_bits[ $k ]); |
|
557 | + $string_bits[ $k ] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
558 | + } |
|
559 | + return implode('', $string_bits); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
565 | + * @param $string |
|
566 | + * @return bool |
|
567 | + */ |
|
568 | + protected function valid_base_64($string) |
|
569 | + { |
|
570 | + // ensure data is a string |
|
571 | + if (! is_string($string) || ! $this->_use_base64_encode) { |
|
572 | + return false; |
|
573 | + } |
|
574 | + $decoded = base64_decode($string, true); |
|
575 | + // Check if there is no invalid character in string |
|
576 | + if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
577 | + return false; |
|
578 | + } |
|
579 | + // Decode the string in strict mode and send the response |
|
580 | + if (! base64_decode($string, true)) { |
|
581 | + return false; |
|
582 | + } |
|
583 | + // Encode and compare it to original one |
|
584 | + return base64_encode($decoded) === $string; |
|
585 | + } |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * generate random string |
|
590 | + * |
|
591 | + * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
592 | + * @param int $length number of characters for random string |
|
593 | + * @return string |
|
594 | + */ |
|
595 | + public function generate_random_string($length = 40) |
|
596 | + { |
|
597 | + $iterations = ceil($length / 40); |
|
598 | + $random_string = ''; |
|
599 | + for ($i = 0; $i < $iterations; $i++) { |
|
600 | + $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
601 | + } |
|
602 | + $random_string = substr($random_string, 0, $length); |
|
603 | + return $random_string; |
|
604 | + } |
|
605 | 605 | } |
@@ -15,255 +15,255 @@ |
||
15 | 15 | final class EE_Module_Request_Router implements InterminableInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var EE_Request $request |
|
20 | - */ |
|
21 | - private $request; |
|
18 | + /** |
|
19 | + * @var EE_Request $request |
|
20 | + */ |
|
21 | + private $request; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var array $_previous_routes |
|
25 | - */ |
|
26 | - private static $_previous_routes = array(); |
|
23 | + /** |
|
24 | + * @var array $_previous_routes |
|
25 | + */ |
|
26 | + private static $_previous_routes = array(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var WP_Query $WP_Query |
|
30 | - */ |
|
31 | - public $WP_Query; |
|
28 | + /** |
|
29 | + * @var WP_Query $WP_Query |
|
30 | + */ |
|
31 | + public $WP_Query; |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * EE_Module_Request_Router constructor. |
|
36 | - * |
|
37 | - * @param EE_Request $request |
|
38 | - */ |
|
39 | - public function __construct(EE_Request $request) |
|
40 | - { |
|
41 | - $this->request = $request; |
|
42 | - } |
|
34 | + /** |
|
35 | + * EE_Module_Request_Router constructor. |
|
36 | + * |
|
37 | + * @param EE_Request $request |
|
38 | + */ |
|
39 | + public function __construct(EE_Request $request) |
|
40 | + { |
|
41 | + $this->request = $request; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
47 | - * on subsequent calls to this method, |
|
48 | - * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
49 | - * and checks if the last called route has any forwarding routes registered for it |
|
50 | - * |
|
51 | - * @param WP_Query $WP_Query |
|
52 | - * @return NULL|string |
|
53 | - * @throws EE_Error |
|
54 | - * @throws ReflectionException |
|
55 | - */ |
|
56 | - public function get_route(WP_Query $WP_Query) |
|
57 | - { |
|
58 | - $this->WP_Query = $WP_Query; |
|
59 | - // assume this if first route being called |
|
60 | - $previous_route = false; |
|
61 | - // but is it really ??? |
|
62 | - if (! empty(self::$_previous_routes)) { |
|
63 | - // get last run route |
|
64 | - $previous_routes = array_values(self::$_previous_routes); |
|
65 | - $previous_route = array_pop($previous_routes); |
|
66 | - } |
|
67 | - // has another route already been run ? |
|
68 | - if ($previous_route) { |
|
69 | - // check if forwarding has been set |
|
70 | - $current_route = $this->get_forward($previous_route); |
|
71 | - try { |
|
72 | - // check for recursive forwarding |
|
73 | - if (isset(self::$_previous_routes[ $current_route ])) { |
|
74 | - throw new EE_Error( |
|
75 | - sprintf( |
|
76 | - __( |
|
77 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
78 | - 'event_espresso' |
|
79 | - ), |
|
80 | - $current_route |
|
81 | - ) |
|
82 | - ); |
|
83 | - } |
|
84 | - } catch (EE_Error $e) { |
|
85 | - $e->get_error(); |
|
86 | - return null; |
|
87 | - } |
|
88 | - } else { |
|
89 | - // first route called |
|
90 | - $current_route = null; |
|
91 | - // grab all routes |
|
92 | - $routes = EE_Config::get_routes(); |
|
93 | - foreach ($routes as $key => $route) { |
|
94 | - // first determine if route key uses w?ldc*rds |
|
95 | - $uses_wildcards = strpos($key, '?') !== false |
|
96 | - || strpos($key, '*') !== false; |
|
97 | - // check request for module route |
|
98 | - $route_found = $uses_wildcards |
|
99 | - ? $this->request->matches($key) |
|
100 | - : $this->request->is_set($key); |
|
101 | - if ($route_found) { |
|
102 | - $current_route = $uses_wildcards |
|
103 | - ? $this->request->getMatch($key) |
|
104 | - : $this->request->get($key); |
|
105 | - $current_route = sanitize_text_field($current_route); |
|
106 | - if ($current_route) { |
|
107 | - $current_route = array($key, $current_route); |
|
108 | - break; |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
113 | - // sorry, but I can't read what you route ! |
|
114 | - if (empty($current_route)) { |
|
115 | - return null; |
|
116 | - } |
|
117 | - // add route to previous routes array |
|
118 | - self::$_previous_routes[] = $current_route; |
|
119 | - return $current_route; |
|
120 | - } |
|
45 | + /** |
|
46 | + * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
47 | + * on subsequent calls to this method, |
|
48 | + * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
49 | + * and checks if the last called route has any forwarding routes registered for it |
|
50 | + * |
|
51 | + * @param WP_Query $WP_Query |
|
52 | + * @return NULL|string |
|
53 | + * @throws EE_Error |
|
54 | + * @throws ReflectionException |
|
55 | + */ |
|
56 | + public function get_route(WP_Query $WP_Query) |
|
57 | + { |
|
58 | + $this->WP_Query = $WP_Query; |
|
59 | + // assume this if first route being called |
|
60 | + $previous_route = false; |
|
61 | + // but is it really ??? |
|
62 | + if (! empty(self::$_previous_routes)) { |
|
63 | + // get last run route |
|
64 | + $previous_routes = array_values(self::$_previous_routes); |
|
65 | + $previous_route = array_pop($previous_routes); |
|
66 | + } |
|
67 | + // has another route already been run ? |
|
68 | + if ($previous_route) { |
|
69 | + // check if forwarding has been set |
|
70 | + $current_route = $this->get_forward($previous_route); |
|
71 | + try { |
|
72 | + // check for recursive forwarding |
|
73 | + if (isset(self::$_previous_routes[ $current_route ])) { |
|
74 | + throw new EE_Error( |
|
75 | + sprintf( |
|
76 | + __( |
|
77 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
78 | + 'event_espresso' |
|
79 | + ), |
|
80 | + $current_route |
|
81 | + ) |
|
82 | + ); |
|
83 | + } |
|
84 | + } catch (EE_Error $e) { |
|
85 | + $e->get_error(); |
|
86 | + return null; |
|
87 | + } |
|
88 | + } else { |
|
89 | + // first route called |
|
90 | + $current_route = null; |
|
91 | + // grab all routes |
|
92 | + $routes = EE_Config::get_routes(); |
|
93 | + foreach ($routes as $key => $route) { |
|
94 | + // first determine if route key uses w?ldc*rds |
|
95 | + $uses_wildcards = strpos($key, '?') !== false |
|
96 | + || strpos($key, '*') !== false; |
|
97 | + // check request for module route |
|
98 | + $route_found = $uses_wildcards |
|
99 | + ? $this->request->matches($key) |
|
100 | + : $this->request->is_set($key); |
|
101 | + if ($route_found) { |
|
102 | + $current_route = $uses_wildcards |
|
103 | + ? $this->request->getMatch($key) |
|
104 | + : $this->request->get($key); |
|
105 | + $current_route = sanitize_text_field($current_route); |
|
106 | + if ($current_route) { |
|
107 | + $current_route = array($key, $current_route); |
|
108 | + break; |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | + // sorry, but I can't read what you route ! |
|
114 | + if (empty($current_route)) { |
|
115 | + return null; |
|
116 | + } |
|
117 | + // add route to previous routes array |
|
118 | + self::$_previous_routes[] = $current_route; |
|
119 | + return $current_route; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | - /** |
|
124 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
125 | - * |
|
126 | - * @param string $key |
|
127 | - * @param string $current_route |
|
128 | - * @return mixed EED_Module | boolean |
|
129 | - * @throws EE_Error |
|
130 | - * @throws ReflectionException |
|
131 | - */ |
|
132 | - public function resolve_route($key, $current_route) |
|
133 | - { |
|
134 | - // get module method that route has been mapped to |
|
135 | - $module_method = EE_Config::get_route($current_route, $key); |
|
136 | - // verify result was returned |
|
137 | - if (empty($module_method)) { |
|
138 | - $msg = sprintf( |
|
139 | - __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
140 | - $current_route |
|
141 | - ); |
|
142 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
143 | - return false; |
|
144 | - } |
|
145 | - // verify that result is an array |
|
146 | - if (! is_array($module_method)) { |
|
147 | - $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
148 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
149 | - return false; |
|
150 | - } |
|
151 | - // grab module name |
|
152 | - $module_name = $module_method[0]; |
|
153 | - // verify that a class method was registered properly |
|
154 | - if (! isset($module_method[1])) { |
|
155 | - $msg = sprintf( |
|
156 | - __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
157 | - $current_route |
|
158 | - ); |
|
159 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | - return false; |
|
161 | - } |
|
162 | - // grab method |
|
163 | - $method = $module_method[1]; |
|
164 | - // verify that class exists |
|
165 | - if (! class_exists($module_name)) { |
|
166 | - $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
167 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | - return false; |
|
169 | - } |
|
170 | - // verify that method exists |
|
171 | - if (! method_exists($module_name, $method)) { |
|
172 | - $msg = sprintf( |
|
173 | - __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
|
174 | - $method, |
|
175 | - $current_route |
|
176 | - ); |
|
177 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
178 | - return false; |
|
179 | - } |
|
180 | - // instantiate module and call route method |
|
181 | - return $this->_module_router($module_name, $method); |
|
182 | - } |
|
123 | + /** |
|
124 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
125 | + * |
|
126 | + * @param string $key |
|
127 | + * @param string $current_route |
|
128 | + * @return mixed EED_Module | boolean |
|
129 | + * @throws EE_Error |
|
130 | + * @throws ReflectionException |
|
131 | + */ |
|
132 | + public function resolve_route($key, $current_route) |
|
133 | + { |
|
134 | + // get module method that route has been mapped to |
|
135 | + $module_method = EE_Config::get_route($current_route, $key); |
|
136 | + // verify result was returned |
|
137 | + if (empty($module_method)) { |
|
138 | + $msg = sprintf( |
|
139 | + __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
140 | + $current_route |
|
141 | + ); |
|
142 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
143 | + return false; |
|
144 | + } |
|
145 | + // verify that result is an array |
|
146 | + if (! is_array($module_method)) { |
|
147 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
148 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
149 | + return false; |
|
150 | + } |
|
151 | + // grab module name |
|
152 | + $module_name = $module_method[0]; |
|
153 | + // verify that a class method was registered properly |
|
154 | + if (! isset($module_method[1])) { |
|
155 | + $msg = sprintf( |
|
156 | + __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
157 | + $current_route |
|
158 | + ); |
|
159 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | + return false; |
|
161 | + } |
|
162 | + // grab method |
|
163 | + $method = $module_method[1]; |
|
164 | + // verify that class exists |
|
165 | + if (! class_exists($module_name)) { |
|
166 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
167 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | + return false; |
|
169 | + } |
|
170 | + // verify that method exists |
|
171 | + if (! method_exists($module_name, $method)) { |
|
172 | + $msg = sprintf( |
|
173 | + __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
|
174 | + $method, |
|
175 | + $current_route |
|
176 | + ); |
|
177 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
178 | + return false; |
|
179 | + } |
|
180 | + // instantiate module and call route method |
|
181 | + return $this->_module_router($module_name, $method); |
|
182 | + } |
|
183 | 183 | |
184 | 184 | |
185 | - /** |
|
186 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
187 | - * |
|
188 | - * @param string $module_name |
|
189 | - * @return EED_Module|object|null |
|
190 | - * @throws ReflectionException |
|
191 | - */ |
|
192 | - public static function module_factory($module_name) |
|
193 | - { |
|
194 | - if ($module_name === 'EED_Module') { |
|
195 | - EE_Error::add_error( |
|
196 | - sprintf( |
|
197 | - __( |
|
198 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
199 | - 'event_espresso' |
|
200 | - ), |
|
201 | - $module_name |
|
202 | - ), |
|
203 | - __FILE__, |
|
204 | - __FUNCTION__, |
|
205 | - __LINE__ |
|
206 | - ); |
|
207 | - return null; |
|
208 | - } |
|
209 | - // instantiate module class |
|
210 | - $module = new $module_name(); |
|
211 | - // ensure that class is actually a module |
|
212 | - if (! $module instanceof EED_Module) { |
|
213 | - EE_Error::add_error( |
|
214 | - sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
215 | - __FILE__, |
|
216 | - __FUNCTION__, |
|
217 | - __LINE__ |
|
218 | - ); |
|
219 | - return null; |
|
220 | - } |
|
221 | - return $module; |
|
222 | - } |
|
185 | + /** |
|
186 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
187 | + * |
|
188 | + * @param string $module_name |
|
189 | + * @return EED_Module|object|null |
|
190 | + * @throws ReflectionException |
|
191 | + */ |
|
192 | + public static function module_factory($module_name) |
|
193 | + { |
|
194 | + if ($module_name === 'EED_Module') { |
|
195 | + EE_Error::add_error( |
|
196 | + sprintf( |
|
197 | + __( |
|
198 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
199 | + 'event_espresso' |
|
200 | + ), |
|
201 | + $module_name |
|
202 | + ), |
|
203 | + __FILE__, |
|
204 | + __FUNCTION__, |
|
205 | + __LINE__ |
|
206 | + ); |
|
207 | + return null; |
|
208 | + } |
|
209 | + // instantiate module class |
|
210 | + $module = new $module_name(); |
|
211 | + // ensure that class is actually a module |
|
212 | + if (! $module instanceof EED_Module) { |
|
213 | + EE_Error::add_error( |
|
214 | + sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
215 | + __FILE__, |
|
216 | + __FUNCTION__, |
|
217 | + __LINE__ |
|
218 | + ); |
|
219 | + return null; |
|
220 | + } |
|
221 | + return $module; |
|
222 | + } |
|
223 | 223 | |
224 | 224 | |
225 | - /** |
|
226 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
227 | - * |
|
228 | - * @param string $module_name |
|
229 | - * @param string $method |
|
230 | - * @return EED_Module|null |
|
231 | - * @throws EE_Error |
|
232 | - * @throws ReflectionException |
|
233 | - */ |
|
234 | - private function _module_router($module_name, $method) |
|
235 | - { |
|
236 | - // instantiate module class |
|
237 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
238 | - if ($module instanceof EED_Module) { |
|
239 | - // and call whatever action the route was for |
|
240 | - try { |
|
241 | - call_user_func(array($module, $method), $this->WP_Query); |
|
242 | - } catch (EE_Error $e) { |
|
243 | - $e->get_error(); |
|
244 | - return null; |
|
245 | - } |
|
246 | - } |
|
247 | - return $module; |
|
248 | - } |
|
225 | + /** |
|
226 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
227 | + * |
|
228 | + * @param string $module_name |
|
229 | + * @param string $method |
|
230 | + * @return EED_Module|null |
|
231 | + * @throws EE_Error |
|
232 | + * @throws ReflectionException |
|
233 | + */ |
|
234 | + private function _module_router($module_name, $method) |
|
235 | + { |
|
236 | + // instantiate module class |
|
237 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
238 | + if ($module instanceof EED_Module) { |
|
239 | + // and call whatever action the route was for |
|
240 | + try { |
|
241 | + call_user_func(array($module, $method), $this->WP_Query); |
|
242 | + } catch (EE_Error $e) { |
|
243 | + $e->get_error(); |
|
244 | + return null; |
|
245 | + } |
|
246 | + } |
|
247 | + return $module; |
|
248 | + } |
|
249 | 249 | |
250 | 250 | |
251 | - /** |
|
252 | - * @param $current_route |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function get_forward($current_route) |
|
256 | - { |
|
257 | - return EE_Config::get_forward($current_route); |
|
258 | - } |
|
251 | + /** |
|
252 | + * @param $current_route |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function get_forward($current_route) |
|
256 | + { |
|
257 | + return EE_Config::get_forward($current_route); |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | - /** |
|
262 | - * @param $current_route |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function get_view($current_route) |
|
266 | - { |
|
267 | - return EE_Config::get_view($current_route); |
|
268 | - } |
|
261 | + /** |
|
262 | + * @param $current_route |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function get_view($current_route) |
|
266 | + { |
|
267 | + return EE_Config::get_view($current_route); |
|
268 | + } |
|
269 | 269 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | // assume this if first route being called |
60 | 60 | $previous_route = false; |
61 | 61 | // but is it really ??? |
62 | - if (! empty(self::$_previous_routes)) { |
|
62 | + if ( ! empty(self::$_previous_routes)) { |
|
63 | 63 | // get last run route |
64 | 64 | $previous_routes = array_values(self::$_previous_routes); |
65 | 65 | $previous_route = array_pop($previous_routes); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $current_route = $this->get_forward($previous_route); |
71 | 71 | try { |
72 | 72 | // check for recursive forwarding |
73 | - if (isset(self::$_previous_routes[ $current_route ])) { |
|
73 | + if (isset(self::$_previous_routes[$current_route])) { |
|
74 | 74 | throw new EE_Error( |
75 | 75 | sprintf( |
76 | 76 | __( |
@@ -143,38 +143,38 @@ discard block |
||
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | // verify that result is an array |
146 | - if (! is_array($module_method)) { |
|
146 | + if ( ! is_array($module_method)) { |
|
147 | 147 | $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
148 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
149 | 149 | return false; |
150 | 150 | } |
151 | 151 | // grab module name |
152 | 152 | $module_name = $module_method[0]; |
153 | 153 | // verify that a class method was registered properly |
154 | - if (! isset($module_method[1])) { |
|
154 | + if ( ! isset($module_method[1])) { |
|
155 | 155 | $msg = sprintf( |
156 | 156 | __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
157 | 157 | $current_route |
158 | 158 | ); |
159 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
159 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | 160 | return false; |
161 | 161 | } |
162 | 162 | // grab method |
163 | 163 | $method = $module_method[1]; |
164 | 164 | // verify that class exists |
165 | - if (! class_exists($module_name)) { |
|
165 | + if ( ! class_exists($module_name)) { |
|
166 | 166 | $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
167 | 167 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | // verify that method exists |
171 | - if (! method_exists($module_name, $method)) { |
|
171 | + if ( ! method_exists($module_name, $method)) { |
|
172 | 172 | $msg = sprintf( |
173 | 173 | __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
174 | 174 | $method, |
175 | 175 | $current_route |
176 | 176 | ); |
177 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
177 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
178 | 178 | return false; |
179 | 179 | } |
180 | 180 | // instantiate module and call route method |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | // instantiate module class |
210 | 210 | $module = new $module_name(); |
211 | 211 | // ensure that class is actually a module |
212 | - if (! $module instanceof EED_Module) { |
|
212 | + if ( ! $module instanceof EED_Module) { |
|
213 | 213 | EE_Error::add_error( |
214 | 214 | sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
215 | 215 | __FILE__, |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <div id="espresso-ajax-loading" style="display:none;"> |
2 | 2 | <span class="ee-spinner ee-spin"></span><span style="display:none;"> |
3 | 3 | <?php _e( |
4 | - 'loading...', |
|
5 | - 'event_espresso' |
|
6 | - ); ?></span> |
|
4 | + 'loading...', |
|
5 | + 'event_espresso' |
|
6 | + ); ?></span> |
|
7 | 7 | </div> |
8 | 8 | |
9 | 9 | <div id="espresso-ajax-notices"> |
@@ -14,78 +14,78 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * load_espresso_addons |
|
19 | - * runs during the WP 'plugins_loaded' action at priority 1 |
|
20 | - * and is the initial loading phase for EE addons |
|
21 | - * no other logic should be performed at this point |
|
22 | - */ |
|
23 | - public static function load_espresso_addons() |
|
24 | - { |
|
25 | - do_action('AHEE__EE_Bootstrap__load_espresso_addons'); |
|
26 | - } |
|
17 | + /** |
|
18 | + * load_espresso_addons |
|
19 | + * runs during the WP 'plugins_loaded' action at priority 1 |
|
20 | + * and is the initial loading phase for EE addons |
|
21 | + * no other logic should be performed at this point |
|
22 | + */ |
|
23 | + public static function load_espresso_addons() |
|
24 | + { |
|
25 | + do_action('AHEE__EE_Bootstrap__load_espresso_addons'); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * detect_activations_or_upgrades |
|
31 | - * runs during the WP 'plugins_loaded' action at priority 3 |
|
32 | - * Now that all of the addons have been loaded, |
|
33 | - * we can determine if anything needs activating or upgrading |
|
34 | - */ |
|
35 | - public static function detect_activations_or_upgrades() |
|
36 | - { |
|
37 | - do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades'); |
|
38 | - } |
|
29 | + /** |
|
30 | + * detect_activations_or_upgrades |
|
31 | + * runs during the WP 'plugins_loaded' action at priority 3 |
|
32 | + * Now that all of the addons have been loaded, |
|
33 | + * we can determine if anything needs activating or upgrading |
|
34 | + */ |
|
35 | + public static function detect_activations_or_upgrades() |
|
36 | + { |
|
37 | + do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades'); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * load_core_configuration |
|
43 | - * runs during the WP 'plugins_loaded' action at priority 5 |
|
44 | - * Now that the database is assumed to be at the correct version |
|
45 | - * we can load and set all of the system configurations |
|
46 | - */ |
|
47 | - public static function load_core_configuration() |
|
48 | - { |
|
49 | - do_action('AHEE__EE_Bootstrap__load_core_configuration'); |
|
50 | - } |
|
41 | + /** |
|
42 | + * load_core_configuration |
|
43 | + * runs during the WP 'plugins_loaded' action at priority 5 |
|
44 | + * Now that the database is assumed to be at the correct version |
|
45 | + * we can load and set all of the system configurations |
|
46 | + */ |
|
47 | + public static function load_core_configuration() |
|
48 | + { |
|
49 | + do_action('AHEE__EE_Bootstrap__load_core_configuration'); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * register_shortcodes_modules_and_widgets |
|
55 | - * runs during the WP 'plugins_loaded' action at priority 7 |
|
56 | - * and handles registering all o four shortcodes, modules and widgets |
|
57 | - * so that they are ready to be used throughout the system |
|
58 | - */ |
|
59 | - public static function register_shortcodes_modules_and_widgets() |
|
60 | - { |
|
61 | - do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'); |
|
62 | - } |
|
53 | + /** |
|
54 | + * register_shortcodes_modules_and_widgets |
|
55 | + * runs during the WP 'plugins_loaded' action at priority 7 |
|
56 | + * and handles registering all o four shortcodes, modules and widgets |
|
57 | + * so that they are ready to be used throughout the system |
|
58 | + */ |
|
59 | + public static function register_shortcodes_modules_and_widgets() |
|
60 | + { |
|
61 | + do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * brew_espresso |
|
67 | - * runs during the WP 'plugins_loaded' action at priority 9 |
|
68 | - * bootstrapping is considered complete at this point, |
|
69 | - * so let the fun begin... |
|
70 | - */ |
|
71 | - public static function brew_espresso() |
|
72 | - { |
|
73 | - do_action('AHEE__EE_Bootstrap__brew_espresso'); |
|
74 | - } |
|
65 | + /** |
|
66 | + * brew_espresso |
|
67 | + * runs during the WP 'plugins_loaded' action at priority 9 |
|
68 | + * bootstrapping is considered complete at this point, |
|
69 | + * so let the fun begin... |
|
70 | + */ |
|
71 | + public static function brew_espresso() |
|
72 | + { |
|
73 | + do_action('AHEE__EE_Bootstrap__brew_espresso'); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * @deprecated 4.9.53 |
|
79 | - */ |
|
80 | - public function run_request_stack() |
|
81 | - { |
|
82 | - } |
|
77 | + /** |
|
78 | + * @deprecated 4.9.53 |
|
79 | + */ |
|
80 | + public function run_request_stack() |
|
81 | + { |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * @deprecated 4.9.53 |
|
87 | - */ |
|
88 | - public function build_request_stack() |
|
89 | - { |
|
90 | - } |
|
85 | + /** |
|
86 | + * @deprecated 4.9.53 |
|
87 | + */ |
|
88 | + public function build_request_stack() |
|
89 | + { |
|
90 | + } |
|
91 | 91 | } |
@@ -13,124 +13,124 @@ |
||
13 | 13 | |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * format - output formatted EE object address information |
|
18 | - * |
|
19 | - * @access public |
|
20 | - * @param object EEI_Address $obj_with_address |
|
21 | - * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
22 | - * @param boolean $use_schema whether to apply schema.org formatting to the address |
|
23 | - * @param bool $add_wrapper |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public static function format( |
|
27 | - $obj_with_address = null, |
|
28 | - $type = 'multiline', |
|
29 | - $use_schema = true, |
|
30 | - $add_wrapper = true |
|
31 | - ) { |
|
32 | - // check that incoming object implements the EEI_Address interface |
|
33 | - if (! $obj_with_address instanceof EEI_Address) { |
|
34 | - $msg = __('The address could not be formatted.', 'event_espresso'); |
|
35 | - $dev_msg = __( |
|
36 | - 'The Address Formatter requires passed objects to implement the EEI_Address interface.', |
|
37 | - 'event_espresso' |
|
38 | - ); |
|
39 | - EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
40 | - return null; |
|
41 | - } |
|
42 | - // obtain an address formatter |
|
43 | - $formatter = EEH_Address::_get_formatter($type); |
|
44 | - // apply schema.org formatting ? |
|
45 | - $use_schema = ! is_admin() ? $use_schema : false; |
|
46 | - $formatted_address = $use_schema |
|
47 | - ? EEH_Address::_schema_formatting($formatter, $obj_with_address) |
|
48 | - : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper); |
|
49 | - $formatted_address = $add_wrapper && ! $use_schema |
|
50 | - ? '<div class="espresso-address-dv">' . $formatted_address . '</div>' |
|
51 | - : $formatted_address; |
|
52 | - // return the formatted address |
|
53 | - return $formatted_address; |
|
54 | - } |
|
16 | + /** |
|
17 | + * format - output formatted EE object address information |
|
18 | + * |
|
19 | + * @access public |
|
20 | + * @param object EEI_Address $obj_with_address |
|
21 | + * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
22 | + * @param boolean $use_schema whether to apply schema.org formatting to the address |
|
23 | + * @param bool $add_wrapper |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public static function format( |
|
27 | + $obj_with_address = null, |
|
28 | + $type = 'multiline', |
|
29 | + $use_schema = true, |
|
30 | + $add_wrapper = true |
|
31 | + ) { |
|
32 | + // check that incoming object implements the EEI_Address interface |
|
33 | + if (! $obj_with_address instanceof EEI_Address) { |
|
34 | + $msg = __('The address could not be formatted.', 'event_espresso'); |
|
35 | + $dev_msg = __( |
|
36 | + 'The Address Formatter requires passed objects to implement the EEI_Address interface.', |
|
37 | + 'event_espresso' |
|
38 | + ); |
|
39 | + EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
40 | + return null; |
|
41 | + } |
|
42 | + // obtain an address formatter |
|
43 | + $formatter = EEH_Address::_get_formatter($type); |
|
44 | + // apply schema.org formatting ? |
|
45 | + $use_schema = ! is_admin() ? $use_schema : false; |
|
46 | + $formatted_address = $use_schema |
|
47 | + ? EEH_Address::_schema_formatting($formatter, $obj_with_address) |
|
48 | + : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper); |
|
49 | + $formatted_address = $add_wrapper && ! $use_schema |
|
50 | + ? '<div class="espresso-address-dv">' . $formatted_address . '</div>' |
|
51 | + : $formatted_address; |
|
52 | + // return the formatted address |
|
53 | + return $formatted_address; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * _get_formatter - obtain the requester formatter class |
|
60 | - * |
|
61 | - * @access private |
|
62 | - * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
63 | - * @return EEI_Address_Formatter |
|
64 | - */ |
|
65 | - private static function _get_formatter($type) |
|
66 | - { |
|
67 | - switch ($type) { |
|
68 | - case 'multiline': |
|
69 | - return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter(); |
|
70 | - case 'inline': |
|
71 | - return new EventEspresso\core\services\address\formatters\InlineAddressFormatter(); |
|
72 | - default: |
|
73 | - return new EventEspresso\core\services\address\formatters\NullAddressFormatter(); |
|
74 | - } |
|
75 | - } |
|
58 | + /** |
|
59 | + * _get_formatter - obtain the requester formatter class |
|
60 | + * |
|
61 | + * @access private |
|
62 | + * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
63 | + * @return EEI_Address_Formatter |
|
64 | + */ |
|
65 | + private static function _get_formatter($type) |
|
66 | + { |
|
67 | + switch ($type) { |
|
68 | + case 'multiline': |
|
69 | + return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter(); |
|
70 | + case 'inline': |
|
71 | + return new EventEspresso\core\services\address\formatters\InlineAddressFormatter(); |
|
72 | + default: |
|
73 | + return new EventEspresso\core\services\address\formatters\NullAddressFormatter(); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * _regular_formatting |
|
81 | - * adds formatting to an address |
|
82 | - * |
|
83 | - * @access private |
|
84 | - * @param object EEI_Address_Formatter $formatter |
|
85 | - * @param object EEI_Address $obj_with_address |
|
86 | - * @param bool $add_wrapper |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - private static function _regular_formatting( |
|
90 | - EEI_Address_Formatter $formatter, |
|
91 | - EEI_Address $obj_with_address, |
|
92 | - $add_wrapper = true |
|
93 | - ) { |
|
94 | - $formatted_address = $add_wrapper ? '<div>' : ''; |
|
95 | - $formatted_address .= $formatter->format( |
|
96 | - $obj_with_address->address(), |
|
97 | - $obj_with_address->address2(), |
|
98 | - $obj_with_address->city(), |
|
99 | - $obj_with_address->state_name(), |
|
100 | - $obj_with_address->zip(), |
|
101 | - $obj_with_address->country_name(), |
|
102 | - $obj_with_address->country_ID() |
|
103 | - ); |
|
104 | - $formatted_address .= $add_wrapper ? '</div>' : ''; |
|
105 | - // return the formatted address |
|
106 | - return $formatted_address; |
|
107 | - } |
|
79 | + /** |
|
80 | + * _regular_formatting |
|
81 | + * adds formatting to an address |
|
82 | + * |
|
83 | + * @access private |
|
84 | + * @param object EEI_Address_Formatter $formatter |
|
85 | + * @param object EEI_Address $obj_with_address |
|
86 | + * @param bool $add_wrapper |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + private static function _regular_formatting( |
|
90 | + EEI_Address_Formatter $formatter, |
|
91 | + EEI_Address $obj_with_address, |
|
92 | + $add_wrapper = true |
|
93 | + ) { |
|
94 | + $formatted_address = $add_wrapper ? '<div>' : ''; |
|
95 | + $formatted_address .= $formatter->format( |
|
96 | + $obj_with_address->address(), |
|
97 | + $obj_with_address->address2(), |
|
98 | + $obj_with_address->city(), |
|
99 | + $obj_with_address->state_name(), |
|
100 | + $obj_with_address->zip(), |
|
101 | + $obj_with_address->country_name(), |
|
102 | + $obj_with_address->country_ID() |
|
103 | + ); |
|
104 | + $formatted_address .= $add_wrapper ? '</div>' : ''; |
|
105 | + // return the formatted address |
|
106 | + return $formatted_address; |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * _schema_formatting |
|
113 | - * adds schema.org formatting to an address |
|
114 | - * |
|
115 | - * @access private |
|
116 | - * @param object EEI_Address_Formatter $formatter |
|
117 | - * @param object EEI_Address $obj_with_address |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - private static function _schema_formatting(EEI_Address_Formatter $formatter, EEI_Address $obj_with_address) |
|
121 | - { |
|
122 | - $formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">'; |
|
123 | - $formatted_address .= $formatter->format( |
|
124 | - EEH_Schema::streetAddress($obj_with_address), |
|
125 | - EEH_Schema::postOfficeBoxNumber($obj_with_address), |
|
126 | - EEH_Schema::addressLocality($obj_with_address), |
|
127 | - EEH_Schema::addressRegion($obj_with_address), |
|
128 | - EEH_Schema::postalCode($obj_with_address), |
|
129 | - EEH_Schema::addressCountry($obj_with_address), |
|
130 | - $obj_with_address->country_ID() |
|
131 | - ); |
|
132 | - $formatted_address .= '</div>'; |
|
133 | - // return the formatted address |
|
134 | - return $formatted_address; |
|
135 | - } |
|
111 | + /** |
|
112 | + * _schema_formatting |
|
113 | + * adds schema.org formatting to an address |
|
114 | + * |
|
115 | + * @access private |
|
116 | + * @param object EEI_Address_Formatter $formatter |
|
117 | + * @param object EEI_Address $obj_with_address |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + private static function _schema_formatting(EEI_Address_Formatter $formatter, EEI_Address $obj_with_address) |
|
121 | + { |
|
122 | + $formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">'; |
|
123 | + $formatted_address .= $formatter->format( |
|
124 | + EEH_Schema::streetAddress($obj_with_address), |
|
125 | + EEH_Schema::postOfficeBoxNumber($obj_with_address), |
|
126 | + EEH_Schema::addressLocality($obj_with_address), |
|
127 | + EEH_Schema::addressRegion($obj_with_address), |
|
128 | + EEH_Schema::postalCode($obj_with_address), |
|
129 | + EEH_Schema::addressCountry($obj_with_address), |
|
130 | + $obj_with_address->country_ID() |
|
131 | + ); |
|
132 | + $formatted_address .= '</div>'; |
|
133 | + // return the formatted address |
|
134 | + return $formatted_address; |
|
135 | + } |
|
136 | 136 | } |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | $add_wrapper = true |
31 | 31 | ) { |
32 | 32 | // check that incoming object implements the EEI_Address interface |
33 | - if (! $obj_with_address instanceof EEI_Address) { |
|
33 | + if ( ! $obj_with_address instanceof EEI_Address) { |
|
34 | 34 | $msg = __('The address could not be formatted.', 'event_espresso'); |
35 | 35 | $dev_msg = __( |
36 | 36 | 'The Address Formatter requires passed objects to implement the EEI_Address interface.', |
37 | 37 | 'event_espresso' |
38 | 38 | ); |
39 | - EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
39 | + EE_Error::add_error($msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
40 | 40 | return null; |
41 | 41 | } |
42 | 42 | // obtain an address formatter |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | ? EEH_Address::_schema_formatting($formatter, $obj_with_address) |
48 | 48 | : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper); |
49 | 49 | $formatted_address = $add_wrapper && ! $use_schema |
50 | - ? '<div class="espresso-address-dv">' . $formatted_address . '</div>' |
|
50 | + ? '<div class="espresso-address-dv">'.$formatted_address.'</div>' |
|
51 | 51 | : $formatted_address; |
52 | 52 | // return the formatted address |
53 | 53 | return $formatted_address; |
@@ -12,108 +12,108 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * _admin_format_content |
|
17 | - * Text formatting function for wp_editor. |
|
18 | - * This should fix all of the formatting issues of text output from the database. |
|
19 | - * |
|
20 | - * @static |
|
21 | - * @access public |
|
22 | - * @param string $content content to format |
|
23 | - * @return string formatted content |
|
24 | - */ |
|
25 | - public static function admin_format_content($content = '') |
|
26 | - { |
|
27 | - return wpautop(stripslashes_deep(html_entity_decode($content, ENT_QUOTES, "UTF-8"))); |
|
28 | - } |
|
15 | + /** |
|
16 | + * _admin_format_content |
|
17 | + * Text formatting function for wp_editor. |
|
18 | + * This should fix all of the formatting issues of text output from the database. |
|
19 | + * |
|
20 | + * @static |
|
21 | + * @access public |
|
22 | + * @param string $content content to format |
|
23 | + * @return string formatted content |
|
24 | + */ |
|
25 | + public static function admin_format_content($content = '') |
|
26 | + { |
|
27 | + return wpautop(stripslashes_deep(html_entity_decode($content, ENT_QUOTES, "UTF-8"))); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * ee_tep_output_string |
|
34 | - * todo: we need a description for this. |
|
35 | - * |
|
36 | - * @static |
|
37 | - * @access public |
|
38 | - * @param string $string string to handle |
|
39 | - * @param boolean $translate //todo what is this for? |
|
40 | - * @param boolean $protected true then we run htmlspecialchars and return |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public static function ee_tep_output_string($string, $translate = false, $protected = false) |
|
44 | - { |
|
45 | - if ($protected === true) { |
|
46 | - return htmlspecialchars($string); |
|
47 | - } else { |
|
48 | - if ($translate === false) { |
|
49 | - return self::ee_tep_parse_input_field_data($string, array( '"' => '"' )); |
|
50 | - } else { |
|
51 | - return self::ee_tep_parse_input_field_data($string, $translate); |
|
52 | - } |
|
53 | - } |
|
54 | - } |
|
32 | + /** |
|
33 | + * ee_tep_output_string |
|
34 | + * todo: we need a description for this. |
|
35 | + * |
|
36 | + * @static |
|
37 | + * @access public |
|
38 | + * @param string $string string to handle |
|
39 | + * @param boolean $translate //todo what is this for? |
|
40 | + * @param boolean $protected true then we run htmlspecialchars and return |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public static function ee_tep_output_string($string, $translate = false, $protected = false) |
|
44 | + { |
|
45 | + if ($protected === true) { |
|
46 | + return htmlspecialchars($string); |
|
47 | + } else { |
|
48 | + if ($translate === false) { |
|
49 | + return self::ee_tep_parse_input_field_data($string, array( '"' => '"' )); |
|
50 | + } else { |
|
51 | + return self::ee_tep_parse_input_field_data($string, $translate); |
|
52 | + } |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * ee_tep_parse_input_field_data |
|
60 | - * |
|
61 | - * @param string $data string to be "translated" |
|
62 | - * @param array ] $parse array in the form array( 'from' => 'to', ... ) |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public static function ee_tep_parse_input_field_data($data, $parse) |
|
66 | - { |
|
67 | - return strtr(trim($data), $parse); |
|
68 | - } |
|
58 | + /** |
|
59 | + * ee_tep_parse_input_field_data |
|
60 | + * |
|
61 | + * @param string $data string to be "translated" |
|
62 | + * @param array ] $parse array in the form array( 'from' => 'to', ... ) |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public static function ee_tep_parse_input_field_data($data, $parse) |
|
66 | + { |
|
67 | + return strtr(trim($data), $parse); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * [ee_tep_not_null description] |
|
74 | - * |
|
75 | - * @param string | array $value [description] |
|
76 | - * @return bool [description] |
|
77 | - */ |
|
78 | - public static function ee_tep_not_null($value) |
|
79 | - { |
|
80 | - if (is_array($value)) { |
|
81 | - if (count($value) > 0) { |
|
82 | - return true; |
|
83 | - } else { |
|
84 | - return false; |
|
85 | - } |
|
86 | - } else { |
|
87 | - if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) { |
|
88 | - return true; |
|
89 | - } else { |
|
90 | - return false; |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
72 | + /** |
|
73 | + * [ee_tep_not_null description] |
|
74 | + * |
|
75 | + * @param string | array $value [description] |
|
76 | + * @return bool [description] |
|
77 | + */ |
|
78 | + public static function ee_tep_not_null($value) |
|
79 | + { |
|
80 | + if (is_array($value)) { |
|
81 | + if (count($value) > 0) { |
|
82 | + return true; |
|
83 | + } else { |
|
84 | + return false; |
|
85 | + } |
|
86 | + } else { |
|
87 | + if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) { |
|
88 | + return true; |
|
89 | + } else { |
|
90 | + return false; |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * Formats a date |
|
99 | - * |
|
100 | - * @param string $date |
|
101 | - * @param string $format - format for the date |
|
102 | - * @deprecated 4.6.12 Note, a search revealed this was not used anywhere in core or in our |
|
103 | - * addons at time of writing this. So just deprecated in case of third party use. |
|
104 | - * @return string |
|
105 | - * @deprecated v4.6.21 |
|
106 | - */ |
|
107 | - public static function event_date_display($date, $format = '') |
|
108 | - { |
|
109 | - EE_Error::doing_it_wrong( |
|
110 | - __METHOD__, |
|
111 | - __( |
|
112 | - 'This method is deprecated as of EE 4.6.12. Currently it does not reformat as with prior behaviour but just returns the incoming string. Please use the EE_Datetime helpers for Datetime on the event to display as desired.', |
|
113 | - 'event_espresso' |
|
114 | - ), |
|
115 | - '4.6.21' |
|
116 | - ); |
|
117 | - return $date; |
|
118 | - } |
|
97 | + /** |
|
98 | + * Formats a date |
|
99 | + * |
|
100 | + * @param string $date |
|
101 | + * @param string $format - format for the date |
|
102 | + * @deprecated 4.6.12 Note, a search revealed this was not used anywhere in core or in our |
|
103 | + * addons at time of writing this. So just deprecated in case of third party use. |
|
104 | + * @return string |
|
105 | + * @deprecated v4.6.21 |
|
106 | + */ |
|
107 | + public static function event_date_display($date, $format = '') |
|
108 | + { |
|
109 | + EE_Error::doing_it_wrong( |
|
110 | + __METHOD__, |
|
111 | + __( |
|
112 | + 'This method is deprecated as of EE 4.6.12. Currently it does not reformat as with prior behaviour but just returns the incoming string. Please use the EE_Datetime helpers for Datetime on the event to display as desired.', |
|
113 | + 'event_espresso' |
|
114 | + ), |
|
115 | + '4.6.21' |
|
116 | + ); |
|
117 | + return $date; |
|
118 | + } |
|
119 | 119 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | return htmlspecialchars($string); |
47 | 47 | } else { |
48 | 48 | if ($translate === false) { |
49 | - return self::ee_tep_parse_input_field_data($string, array( '"' => '"' )); |
|
49 | + return self::ee_tep_parse_input_field_data($string, array('"' => '"')); |
|
50 | 50 | } else { |
51 | 51 | return self::ee_tep_parse_input_field_data($string, $translate); |
52 | 52 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | return false; |
85 | 85 | } |
86 | 86 | } else { |
87 | - if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) { |
|
87 | + if (($value !== '') && (strtolower($value) !== 'null') && (strlen(trim($value)) > 0)) { |
|
88 | 88 | return true; |
89 | 89 | } else { |
90 | 90 | return false; |
@@ -11,42 +11,42 @@ |
||
11 | 11 | class EEH_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @var array $uri_segment_array URL segments |
|
16 | - * @access private |
|
17 | - */ |
|
14 | + /** |
|
15 | + * @var array $uri_segment_array URL segments |
|
16 | + * @access private |
|
17 | + */ |
|
18 | 18 | // final private function __construct() {} |
19 | 19 | |
20 | - /** |
|
21 | - * @ override magic methods |
|
22 | - * @ return void |
|
23 | - */ |
|
24 | - public function __set($a, $b) |
|
25 | - { |
|
26 | - return false; |
|
27 | - } |
|
28 | - public function __get($a) |
|
29 | - { |
|
30 | - return false; |
|
31 | - } |
|
32 | - public function __isset($a) |
|
33 | - { |
|
34 | - return false; |
|
35 | - } |
|
36 | - public function __unset($a) |
|
37 | - { |
|
38 | - return false; |
|
39 | - } |
|
40 | - public function __clone() |
|
41 | - { |
|
42 | - return false; |
|
43 | - } |
|
44 | - public function __wakeup() |
|
45 | - { |
|
46 | - return false; |
|
47 | - } |
|
48 | - public function __destruct() |
|
49 | - { |
|
50 | - return false; |
|
51 | - } |
|
20 | + /** |
|
21 | + * @ override magic methods |
|
22 | + * @ return void |
|
23 | + */ |
|
24 | + public function __set($a, $b) |
|
25 | + { |
|
26 | + return false; |
|
27 | + } |
|
28 | + public function __get($a) |
|
29 | + { |
|
30 | + return false; |
|
31 | + } |
|
32 | + public function __isset($a) |
|
33 | + { |
|
34 | + return false; |
|
35 | + } |
|
36 | + public function __unset($a) |
|
37 | + { |
|
38 | + return false; |
|
39 | + } |
|
40 | + public function __clone() |
|
41 | + { |
|
42 | + return false; |
|
43 | + } |
|
44 | + public function __wakeup() |
|
45 | + { |
|
46 | + return false; |
|
47 | + } |
|
48 | + public function __destruct() |
|
49 | + { |
|
50 | + return false; |
|
51 | + } |
|
52 | 52 | } |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | if (is_array($arr)) { |
66 | 66 | $first_item = reset($arr); |
67 | 67 | if (is_array($first_item)) { |
68 | - return true;// yep, there's at least 2 levels to this array |
|
68 | + return true; // yep, there's at least 2 levels to this array |
|
69 | 69 | } else { |
70 | - return false;// nope, only 1 level |
|
70 | + return false; // nope, only 1 level |
|
71 | 71 | } |
72 | 72 | } else { |
73 | - return false;// its not an array at all! |
|
73 | + return false; // its not an array at all! |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public static function is_set($arr, $index, $default) |
86 | 86 | { |
87 | - return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
87 | + return isset($arr[$index]) ? $arr[$index] : $default; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
172 | 172 | { |
173 | 173 | foreach ($array2 as $key => $value) { |
174 | - $array1[ $key ] = $value; |
|
174 | + $array1[$key] = $value; |
|
175 | 175 | } |
176 | 176 | return $array1; |
177 | 177 | } |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | $multidimensional = array(); |
194 | 194 | $reference = &$multidimensional; |
195 | 195 | foreach ($flat_array as $key) { |
196 | - $reference[ $key ] = array(); |
|
197 | - $reference = &$reference[ $key ]; |
|
196 | + $reference[$key] = array(); |
|
197 | + $reference = &$reference[$key]; |
|
198 | 198 | } |
199 | 199 | if ($final_value !== null) { |
200 | 200 | $reference = $final_value; |
@@ -13,203 +13,203 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays |
|
18 | - * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects |
|
19 | - * |
|
20 | - * @uses array_udiff core php function for setting up our own array comparison |
|
21 | - * @uses self::_compare_objects as the custom method for array_udiff |
|
22 | - * @param array $array1 an array of objects |
|
23 | - * @param array $array2 an array of objects |
|
24 | - * @return array an array of objects found in array 1 that aren't found in array 2. |
|
25 | - */ |
|
26 | - public static function object_array_diff($array1, $array2) |
|
27 | - { |
|
28 | - return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed |
|
33 | - * |
|
34 | - * @param array $array |
|
35 | - * @return boolean |
|
36 | - */ |
|
37 | - public static function is_associative_array(array $array): bool |
|
38 | - { |
|
39 | - return ! empty($array) && array_keys($array) !== range(0, count($array) - 1); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Gets an item from the array and leave the array intact. Use in place of end() |
|
44 | - * when you don't want to change the array |
|
45 | - * |
|
46 | - * @param array $arr |
|
47 | - * @return mixed what ever is in the array |
|
48 | - */ |
|
49 | - public static function get_one_item_from_array($arr) |
|
50 | - { |
|
51 | - $item = end($arr); |
|
52 | - reset($arr); |
|
53 | - return $item; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Detects if this is a multi-dimensional array (meaning that the top-level |
|
58 | - * values are themselves array. Eg array(array(...),...) |
|
59 | - * |
|
60 | - * @param mixed $arr |
|
61 | - * @return boolean |
|
62 | - */ |
|
63 | - public static function is_multi_dimensional_array($arr) |
|
64 | - { |
|
65 | - if (is_array($arr)) { |
|
66 | - $first_item = reset($arr); |
|
67 | - if (is_array($first_item)) { |
|
68 | - return true;// yep, there's at least 2 levels to this array |
|
69 | - } else { |
|
70 | - return false;// nope, only 1 level |
|
71 | - } |
|
72 | - } else { |
|
73 | - return false;// its not an array at all! |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default |
|
79 | - * |
|
80 | - * @param array $arr |
|
81 | - * @param mixed $index |
|
82 | - * @param mixed $default |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - public static function is_set($arr, $index, $default) |
|
86 | - { |
|
87 | - return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118 |
|
92 | - * |
|
93 | - * @param mixed $value usually a string, but could be an array or object |
|
94 | - * @return mixed the UN-serialized data |
|
95 | - */ |
|
96 | - public static function maybe_unserialize($value) |
|
97 | - { |
|
98 | - $data = maybe_unserialize($value); |
|
99 | - // it's possible that this still has serialized data if its the session. WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesnt' unserialize this automatically. |
|
100 | - $token = 'C'; |
|
101 | - $data = is_string($data) ? trim($data) : $data; |
|
102 | - if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
103 | - return unserialize($data); |
|
104 | - } else { |
|
105 | - return $data; |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * insert_into_array |
|
112 | - * |
|
113 | - * @param array $target_array the array to insert new data into |
|
114 | - * @param array $array_to_insert the new data to be inserted |
|
115 | - * @param int | string $offset a known key within $target_array where new data will be inserted |
|
116 | - * @param bool $add_before whether to add new data before or after the offset key |
|
117 | - * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public static function insert_into_array( |
|
121 | - $target_array = array(), |
|
122 | - $array_to_insert = array(), |
|
123 | - $offset = null, |
|
124 | - $add_before = true, |
|
125 | - $preserve_keys = true |
|
126 | - ) { |
|
127 | - // ensure incoming arrays are actually arrays |
|
128 | - $target_array = (array) $target_array; |
|
129 | - $array_to_insert = (array) $array_to_insert; |
|
130 | - // if no offset key was supplied |
|
131 | - if (empty($offset)) { |
|
132 | - // use start or end of $target_array based on whether we are adding before or not |
|
133 | - $offset = $add_before ? 0 : count($target_array); |
|
134 | - } |
|
135 | - // if offset key is a string, then find the corresponding numeric location for that element |
|
136 | - $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array)); |
|
137 | - // add one to the offset if adding after |
|
138 | - $offset = $add_before ? $offset : $offset + 1; |
|
139 | - // but ensure offset does not exceed the length of the array |
|
140 | - $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
141 | - // reindex array ??? |
|
142 | - if ($preserve_keys) { |
|
143 | - // take a slice of the target array from the beginning till the offset, |
|
144 | - // then add the new data |
|
145 | - // then add another slice that starts at the offset and goes till the end |
|
146 | - return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice( |
|
147 | - $target_array, |
|
148 | - $offset, |
|
149 | - null, |
|
150 | - true |
|
151 | - ); |
|
152 | - } else { |
|
153 | - // since we don't want to preserve keys, we can use array_splice |
|
154 | - array_splice($target_array, $offset, 0, $array_to_insert); |
|
155 | - return $target_array; |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * array_merge() is slow and should never be used while looping over data |
|
162 | - * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster |
|
163 | - * so really this acts more like array_replace( $array1, $array2 ) |
|
164 | - * or a union with the arrays flipped ( $array2 + $array1 ) |
|
165 | - * this saves a few lines of code and improves readability |
|
166 | - * |
|
167 | - * @param array $array1 |
|
168 | - * @param array $array2 |
|
169 | - * @return array |
|
170 | - */ |
|
171 | - public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
|
172 | - { |
|
173 | - foreach ($array2 as $key => $value) { |
|
174 | - $array1[ $key ] = $value; |
|
175 | - } |
|
176 | - return $array1; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * given a flat array like $array = array('A', 'B', 'C') |
|
182 | - * will convert into a multidimensional array like $array[A][B][C] |
|
183 | - * if $final_value is provided and is anything other than null, |
|
184 | - * then that will be set as the value for the innermost array key |
|
185 | - * like so: $array[A][B][C] = $final_value |
|
186 | - * |
|
187 | - * @param array $flat_array |
|
188 | - * @param mixed $final_value |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - public static function convert_array_values_to_keys(array $flat_array, $final_value = null) |
|
192 | - { |
|
193 | - $multidimensional = array(); |
|
194 | - $reference = &$multidimensional; |
|
195 | - foreach ($flat_array as $key) { |
|
196 | - $reference[ $key ] = array(); |
|
197 | - $reference = &$reference[ $key ]; |
|
198 | - } |
|
199 | - if ($final_value !== null) { |
|
200 | - $reference = $final_value; |
|
201 | - } |
|
202 | - return $multidimensional; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
208 | - * @param array $array |
|
209 | - * @return bool |
|
210 | - */ |
|
211 | - public static function is_array_numerically_and_sequentially_indexed(array $array) |
|
212 | - { |
|
213 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
214 | - } |
|
16 | + /** |
|
17 | + * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays |
|
18 | + * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects |
|
19 | + * |
|
20 | + * @uses array_udiff core php function for setting up our own array comparison |
|
21 | + * @uses self::_compare_objects as the custom method for array_udiff |
|
22 | + * @param array $array1 an array of objects |
|
23 | + * @param array $array2 an array of objects |
|
24 | + * @return array an array of objects found in array 1 that aren't found in array 2. |
|
25 | + */ |
|
26 | + public static function object_array_diff($array1, $array2) |
|
27 | + { |
|
28 | + return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed |
|
33 | + * |
|
34 | + * @param array $array |
|
35 | + * @return boolean |
|
36 | + */ |
|
37 | + public static function is_associative_array(array $array): bool |
|
38 | + { |
|
39 | + return ! empty($array) && array_keys($array) !== range(0, count($array) - 1); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Gets an item from the array and leave the array intact. Use in place of end() |
|
44 | + * when you don't want to change the array |
|
45 | + * |
|
46 | + * @param array $arr |
|
47 | + * @return mixed what ever is in the array |
|
48 | + */ |
|
49 | + public static function get_one_item_from_array($arr) |
|
50 | + { |
|
51 | + $item = end($arr); |
|
52 | + reset($arr); |
|
53 | + return $item; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Detects if this is a multi-dimensional array (meaning that the top-level |
|
58 | + * values are themselves array. Eg array(array(...),...) |
|
59 | + * |
|
60 | + * @param mixed $arr |
|
61 | + * @return boolean |
|
62 | + */ |
|
63 | + public static function is_multi_dimensional_array($arr) |
|
64 | + { |
|
65 | + if (is_array($arr)) { |
|
66 | + $first_item = reset($arr); |
|
67 | + if (is_array($first_item)) { |
|
68 | + return true;// yep, there's at least 2 levels to this array |
|
69 | + } else { |
|
70 | + return false;// nope, only 1 level |
|
71 | + } |
|
72 | + } else { |
|
73 | + return false;// its not an array at all! |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default |
|
79 | + * |
|
80 | + * @param array $arr |
|
81 | + * @param mixed $index |
|
82 | + * @param mixed $default |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + public static function is_set($arr, $index, $default) |
|
86 | + { |
|
87 | + return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118 |
|
92 | + * |
|
93 | + * @param mixed $value usually a string, but could be an array or object |
|
94 | + * @return mixed the UN-serialized data |
|
95 | + */ |
|
96 | + public static function maybe_unserialize($value) |
|
97 | + { |
|
98 | + $data = maybe_unserialize($value); |
|
99 | + // it's possible that this still has serialized data if its the session. WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesnt' unserialize this automatically. |
|
100 | + $token = 'C'; |
|
101 | + $data = is_string($data) ? trim($data) : $data; |
|
102 | + if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
103 | + return unserialize($data); |
|
104 | + } else { |
|
105 | + return $data; |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * insert_into_array |
|
112 | + * |
|
113 | + * @param array $target_array the array to insert new data into |
|
114 | + * @param array $array_to_insert the new data to be inserted |
|
115 | + * @param int | string $offset a known key within $target_array where new data will be inserted |
|
116 | + * @param bool $add_before whether to add new data before or after the offset key |
|
117 | + * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public static function insert_into_array( |
|
121 | + $target_array = array(), |
|
122 | + $array_to_insert = array(), |
|
123 | + $offset = null, |
|
124 | + $add_before = true, |
|
125 | + $preserve_keys = true |
|
126 | + ) { |
|
127 | + // ensure incoming arrays are actually arrays |
|
128 | + $target_array = (array) $target_array; |
|
129 | + $array_to_insert = (array) $array_to_insert; |
|
130 | + // if no offset key was supplied |
|
131 | + if (empty($offset)) { |
|
132 | + // use start or end of $target_array based on whether we are adding before or not |
|
133 | + $offset = $add_before ? 0 : count($target_array); |
|
134 | + } |
|
135 | + // if offset key is a string, then find the corresponding numeric location for that element |
|
136 | + $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array)); |
|
137 | + // add one to the offset if adding after |
|
138 | + $offset = $add_before ? $offset : $offset + 1; |
|
139 | + // but ensure offset does not exceed the length of the array |
|
140 | + $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
141 | + // reindex array ??? |
|
142 | + if ($preserve_keys) { |
|
143 | + // take a slice of the target array from the beginning till the offset, |
|
144 | + // then add the new data |
|
145 | + // then add another slice that starts at the offset and goes till the end |
|
146 | + return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice( |
|
147 | + $target_array, |
|
148 | + $offset, |
|
149 | + null, |
|
150 | + true |
|
151 | + ); |
|
152 | + } else { |
|
153 | + // since we don't want to preserve keys, we can use array_splice |
|
154 | + array_splice($target_array, $offset, 0, $array_to_insert); |
|
155 | + return $target_array; |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * array_merge() is slow and should never be used while looping over data |
|
162 | + * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster |
|
163 | + * so really this acts more like array_replace( $array1, $array2 ) |
|
164 | + * or a union with the arrays flipped ( $array2 + $array1 ) |
|
165 | + * this saves a few lines of code and improves readability |
|
166 | + * |
|
167 | + * @param array $array1 |
|
168 | + * @param array $array2 |
|
169 | + * @return array |
|
170 | + */ |
|
171 | + public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
|
172 | + { |
|
173 | + foreach ($array2 as $key => $value) { |
|
174 | + $array1[ $key ] = $value; |
|
175 | + } |
|
176 | + return $array1; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * given a flat array like $array = array('A', 'B', 'C') |
|
182 | + * will convert into a multidimensional array like $array[A][B][C] |
|
183 | + * if $final_value is provided and is anything other than null, |
|
184 | + * then that will be set as the value for the innermost array key |
|
185 | + * like so: $array[A][B][C] = $final_value |
|
186 | + * |
|
187 | + * @param array $flat_array |
|
188 | + * @param mixed $final_value |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + public static function convert_array_values_to_keys(array $flat_array, $final_value = null) |
|
192 | + { |
|
193 | + $multidimensional = array(); |
|
194 | + $reference = &$multidimensional; |
|
195 | + foreach ($flat_array as $key) { |
|
196 | + $reference[ $key ] = array(); |
|
197 | + $reference = &$reference[ $key ]; |
|
198 | + } |
|
199 | + if ($final_value !== null) { |
|
200 | + $reference = $final_value; |
|
201 | + } |
|
202 | + return $multidimensional; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
208 | + * @param array $array |
|
209 | + * @return bool |
|
210 | + */ |
|
211 | + public static function is_array_numerically_and_sequentially_indexed(array $array) |
|
212 | + { |
|
213 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
214 | + } |
|
215 | 215 | } |