@@ -20,27 +20,27 @@ |
||
20 | 20 | abstract class EE_Middleware implements EEI_Request_Decorator |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @deprecated |
|
25 | - * @param EE_Request $request |
|
26 | - * @param EE_Response $response |
|
27 | - * @return EE_Response |
|
28 | - */ |
|
29 | - protected function process_request_stack(EE_Request $request, EE_Response $response) |
|
30 | - { |
|
31 | - EE_Error::doing_it_wrong( |
|
32 | - __METHOD__, |
|
33 | - sprintf( |
|
34 | - esc_html__( |
|
35 | - 'This class 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', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - 'EventEspresso\core\services\request\middleware\Middleware', |
|
39 | - '\core\services\request', |
|
40 | - 'EventEspresso\core\services\request' |
|
41 | - ), |
|
42 | - '4.9.52' |
|
43 | - ); |
|
44 | - return $response; |
|
45 | - } |
|
23 | + /** |
|
24 | + * @deprecated |
|
25 | + * @param EE_Request $request |
|
26 | + * @param EE_Response $response |
|
27 | + * @return EE_Response |
|
28 | + */ |
|
29 | + protected function process_request_stack(EE_Request $request, EE_Response $response) |
|
30 | + { |
|
31 | + EE_Error::doing_it_wrong( |
|
32 | + __METHOD__, |
|
33 | + sprintf( |
|
34 | + esc_html__( |
|
35 | + 'This class 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', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + 'EventEspresso\core\services\request\middleware\Middleware', |
|
39 | + '\core\services\request', |
|
40 | + 'EventEspresso\core\services\request' |
|
41 | + ), |
|
42 | + '4.9.52' |
|
43 | + ); |
|
44 | + return $response; |
|
45 | + } |
|
46 | 46 | } |
@@ -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,98 +15,98 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * instance of the EE_Data_Mapper Object |
|
20 | - * |
|
21 | - * @private _instance |
|
22 | - */ |
|
23 | - private static $_instance = null; |
|
24 | - |
|
25 | - |
|
26 | - public $data = array(); |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - *private constructor to prevent direct creation |
|
31 | - * |
|
32 | - * @Constructor |
|
33 | - * @access private |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - private function __construct() |
|
37 | - { |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - *@ singleton method used to instantiate class object |
|
43 | - *@ access public |
|
44 | - *@ return class instance |
|
45 | - */ |
|
46 | - public function &instance() |
|
47 | - { |
|
48 | - // check if class object is instantiated |
|
49 | - if (self::$_instance === null |
|
50 | - || ! is_object(self::$_instance) |
|
51 | - || ! self::$_instance instanceof EE_Data_Mapper |
|
52 | - ) { |
|
53 | - self::$_instance = new self(); |
|
54 | - } |
|
55 | - return self::$_instance; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @ override magic methods |
|
61 | - * @ return void |
|
62 | - */ |
|
63 | - final public function __destruct() |
|
64 | - { |
|
65 | - } |
|
66 | - |
|
67 | - final public function __call($a, $b) |
|
68 | - { |
|
69 | - } |
|
70 | - |
|
71 | - public static function __callStatic($a, $b) |
|
72 | - { |
|
73 | - } |
|
74 | - |
|
75 | - final public function __get($a) |
|
76 | - { |
|
77 | - } |
|
78 | - |
|
79 | - final public function __set($a, $b) |
|
80 | - { |
|
81 | - } |
|
82 | - |
|
83 | - final public function __isset($a) |
|
84 | - { |
|
85 | - } |
|
86 | - |
|
87 | - final public function __unset($a) |
|
88 | - { |
|
89 | - } |
|
90 | - |
|
91 | - final public function __sleep() |
|
92 | - { |
|
93 | - return array(); |
|
94 | - } |
|
95 | - |
|
96 | - final public function __wakeup() |
|
97 | - { |
|
98 | - } |
|
99 | - |
|
100 | - final public function __toString() |
|
101 | - { |
|
102 | - return ''; |
|
103 | - } |
|
104 | - |
|
105 | - final public function __invoke() |
|
106 | - { |
|
107 | - } |
|
108 | - |
|
109 | - final public function __clone() |
|
110 | - { |
|
111 | - } |
|
18 | + /** |
|
19 | + * instance of the EE_Data_Mapper Object |
|
20 | + * |
|
21 | + * @private _instance |
|
22 | + */ |
|
23 | + private static $_instance = null; |
|
24 | + |
|
25 | + |
|
26 | + public $data = array(); |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + *private constructor to prevent direct creation |
|
31 | + * |
|
32 | + * @Constructor |
|
33 | + * @access private |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + private function __construct() |
|
37 | + { |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + *@ singleton method used to instantiate class object |
|
43 | + *@ access public |
|
44 | + *@ return class instance |
|
45 | + */ |
|
46 | + public function &instance() |
|
47 | + { |
|
48 | + // check if class object is instantiated |
|
49 | + if (self::$_instance === null |
|
50 | + || ! is_object(self::$_instance) |
|
51 | + || ! self::$_instance instanceof EE_Data_Mapper |
|
52 | + ) { |
|
53 | + self::$_instance = new self(); |
|
54 | + } |
|
55 | + return self::$_instance; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @ override magic methods |
|
61 | + * @ return void |
|
62 | + */ |
|
63 | + final public function __destruct() |
|
64 | + { |
|
65 | + } |
|
66 | + |
|
67 | + final public function __call($a, $b) |
|
68 | + { |
|
69 | + } |
|
70 | + |
|
71 | + public static function __callStatic($a, $b) |
|
72 | + { |
|
73 | + } |
|
74 | + |
|
75 | + final public function __get($a) |
|
76 | + { |
|
77 | + } |
|
78 | + |
|
79 | + final public function __set($a, $b) |
|
80 | + { |
|
81 | + } |
|
82 | + |
|
83 | + final public function __isset($a) |
|
84 | + { |
|
85 | + } |
|
86 | + |
|
87 | + final public function __unset($a) |
|
88 | + { |
|
89 | + } |
|
90 | + |
|
91 | + final public function __sleep() |
|
92 | + { |
|
93 | + return array(); |
|
94 | + } |
|
95 | + |
|
96 | + final public function __wakeup() |
|
97 | + { |
|
98 | + } |
|
99 | + |
|
100 | + final public function __toString() |
|
101 | + { |
|
102 | + return ''; |
|
103 | + } |
|
104 | + |
|
105 | + final public function __invoke() |
|
106 | + { |
|
107 | + } |
|
108 | + |
|
109 | + final public function __clone() |
|
110 | + { |
|
111 | + } |
|
112 | 112 | } |
@@ -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,268 +13,268 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * holds the template |
|
18 | - * |
|
19 | - * @access private |
|
20 | - * @var mixed (string|array) |
|
21 | - */ |
|
22 | - private $_template; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * holds the incoming data object |
|
27 | - * |
|
28 | - * @access private |
|
29 | - * @var object |
|
30 | - */ |
|
31 | - private $_data; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * will hold an array of EE_Shortcodes library objects. |
|
36 | - * |
|
37 | - * @access private |
|
38 | - * @var EE_Shortcodes[] |
|
39 | - */ |
|
40 | - private $_shortcode_objs = array(); |
|
41 | - |
|
42 | - |
|
43 | - public function __construct() |
|
44 | - { |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * This kicks off the parsing of shortcodes in message templates |
|
50 | - * |
|
51 | - * @param string $template This is the incoming string to be parsed |
|
52 | - * @param EE_Messages_Addressee $data This is the incoming data object |
|
53 | - * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
54 | - * @param EE_message_type $message_type The message type that called the parser |
|
55 | - * @param EE_messenger $messenger The active messenger for this parsing session. |
|
56 | - * @param EE_Message $message |
|
57 | - * @return string The parsed template string |
|
58 | - */ |
|
59 | - public function parse_message_template( |
|
60 | - $template, |
|
61 | - EE_Messages_Addressee $data, |
|
62 | - $valid_shortcodes, |
|
63 | - EE_message_type $message_type, |
|
64 | - EE_messenger $messenger, |
|
65 | - EE_Message $message |
|
66 | - ) { |
|
67 | - $extra_data = array( |
|
68 | - 'messenger' => $messenger, |
|
69 | - 'message_type' => $message_type, |
|
70 | - 'message' => $message, |
|
71 | - ); |
|
72 | - $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
73 | - $this->_template = is_array($template) ? $template['main'] : $template; |
|
74 | - return $this->_parse_message_template(); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - public function parse_attendee_list_template( |
|
79 | - $template, |
|
80 | - EE_Registration $registration, |
|
81 | - $valid_shortcodes, |
|
82 | - $extra_data = array() |
|
83 | - ) { |
|
84 | - $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
85 | - $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
86 | - return $this->_parse_message_template(); |
|
87 | - } |
|
88 | - |
|
89 | - public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
90 | - { |
|
91 | - $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
92 | - $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
93 | - return $this->_parse_message_template(); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
98 | - { |
|
99 | - $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
100 | - $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
101 | - return $this->_parse_message_template(); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - public function parse_line_item_list_template( |
|
106 | - $template, |
|
107 | - EE_Line_Item $line_item, |
|
108 | - $valid_shortcodes, |
|
109 | - $extra_data = array() |
|
110 | - ) { |
|
111 | - $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
112 | - $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
113 | - return $this->_parse_message_template(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - public function parse_payment_list_template( |
|
118 | - $template, |
|
119 | - EE_Payment $payment_item, |
|
120 | - $valid_shortcodes, |
|
121 | - $extra_data = array() |
|
122 | - ) { |
|
123 | - $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
124 | - $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
125 | - return $this->_parse_message_template(); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - public function parse_datetime_list_template( |
|
130 | - $template, |
|
131 | - EE_Datetime $datetime, |
|
132 | - $valid_shortcodes, |
|
133 | - $extra_data = array() |
|
134 | - ) { |
|
135 | - $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
136 | - $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
137 | - return $this->_parse_message_template(); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
142 | - { |
|
143 | - $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
144 | - $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
145 | - return $this->_parse_message_template(); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
150 | - { |
|
151 | - $this->_reset_props(); |
|
152 | - $this->_data['template'] = $template; |
|
153 | - $this->_data['data'] = $data; |
|
154 | - $this->_data['extra_data'] = $extra_data; |
|
155 | - $this->_set_shortcodes($valid_shortcodes); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - private function _reset_props() |
|
160 | - { |
|
161 | - $this->_template = $this->_data = null; |
|
162 | - $this->_shortcode_objs = array(); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * takes the given template and parses it with the $_shortcodes property |
|
168 | - * |
|
169 | - * @access private |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - private function _parse_message_template() |
|
173 | - { |
|
174 | - // now let's get a list of shortcodes that are found in the given template |
|
175 | - preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
176 | - $shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string. |
|
177 | - |
|
178 | - $matched_code = array(); |
|
179 | - $sc_values = array(); |
|
180 | - |
|
181 | - $list_type_shortcodes = array( |
|
182 | - '[ATTENDEE_LIST]', |
|
183 | - '[EVENT_LIST]', |
|
184 | - '[TICKET_LIST]', |
|
185 | - '[DATETIME_LIST]', |
|
186 | - '[QUESTION_LIST]', |
|
187 | - '[RECIPIENT_QUESTION_LIST]', |
|
188 | - '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
189 | - '[RECIPIENT_TICKET_LIST]', |
|
190 | - '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
191 | - '[RECIPIENT_DATETIME_LIST]', |
|
192 | - '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
193 | - '[TICKET_LINE_ITEM_LIST]', |
|
194 | - '[TAX_LINE_ITEM_LIST]', |
|
195 | - '[ADDITIONAL_LINE_ITEM_LIST]', |
|
196 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
197 | - '[PAYMENT_LIST_*]', |
|
198 | - ); |
|
199 | - |
|
200 | - $list_type_shortcodes = apply_filters( |
|
201 | - 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
202 | - $list_type_shortcodes |
|
203 | - ); |
|
204 | - |
|
205 | - // now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
206 | - foreach ($shortcodes as $shortcode) { |
|
207 | - foreach ($this->_shortcode_objs as $sc_obj) { |
|
208 | - if ($sc_obj instanceof EE_Shortcodes) { |
|
209 | - // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
210 | - preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
211 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
212 | - |
|
213 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
214 | - continue; // the given shortcode isn't in this object |
|
215 | - } |
|
216 | - |
|
217 | - // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
218 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
219 | - $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
220 | - } else { |
|
221 | - $data_send = $this->_data; |
|
222 | - } |
|
223 | - |
|
224 | - // is this a conditional type shortcode? If it is then we actually parse the template here. |
|
225 | - if ($this->_is_conditional_shortcode($shortcode)) { |
|
226 | - // most shortcode parsers are not going to have a match for this shortcode and will return an |
|
227 | - // empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
228 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
229 | - if ($parsed) { |
|
230 | - $this->_template = $parsed; |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
235 | - |
|
236 | - $matched_code[] = $shortcode; |
|
237 | - $sc_values[] = $parsed; |
|
238 | - } |
|
239 | - } |
|
240 | - } |
|
241 | - |
|
242 | - // now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
243 | - $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
244 | - return $parsed; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
250 | - * |
|
251 | - * Does it match this format: `[IF_` |
|
252 | - * |
|
253 | - * @param $shortcode |
|
254 | - */ |
|
255 | - protected function _is_conditional_shortcode($shortcode) |
|
256 | - { |
|
257 | - return strpos($shortcode, '[IF_') === 0; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
263 | - * various EE_Shortcode library objects |
|
264 | - * |
|
265 | - * @access private |
|
266 | - * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
267 | - * @return void |
|
268 | - */ |
|
269 | - private function _set_shortcodes($valid_shortcodes) |
|
270 | - { |
|
271 | - foreach ($valid_shortcodes as $shortcode_ref) { |
|
272 | - $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
273 | - $ref = str_replace(' ', '_', $ref); |
|
274 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
275 | - if (class_exists($classname)) { |
|
276 | - $this->_shortcode_objs[] = new $classname; |
|
277 | - } |
|
278 | - } |
|
279 | - } |
|
16 | + /** |
|
17 | + * holds the template |
|
18 | + * |
|
19 | + * @access private |
|
20 | + * @var mixed (string|array) |
|
21 | + */ |
|
22 | + private $_template; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * holds the incoming data object |
|
27 | + * |
|
28 | + * @access private |
|
29 | + * @var object |
|
30 | + */ |
|
31 | + private $_data; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * will hold an array of EE_Shortcodes library objects. |
|
36 | + * |
|
37 | + * @access private |
|
38 | + * @var EE_Shortcodes[] |
|
39 | + */ |
|
40 | + private $_shortcode_objs = array(); |
|
41 | + |
|
42 | + |
|
43 | + public function __construct() |
|
44 | + { |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * This kicks off the parsing of shortcodes in message templates |
|
50 | + * |
|
51 | + * @param string $template This is the incoming string to be parsed |
|
52 | + * @param EE_Messages_Addressee $data This is the incoming data object |
|
53 | + * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
54 | + * @param EE_message_type $message_type The message type that called the parser |
|
55 | + * @param EE_messenger $messenger The active messenger for this parsing session. |
|
56 | + * @param EE_Message $message |
|
57 | + * @return string The parsed template string |
|
58 | + */ |
|
59 | + public function parse_message_template( |
|
60 | + $template, |
|
61 | + EE_Messages_Addressee $data, |
|
62 | + $valid_shortcodes, |
|
63 | + EE_message_type $message_type, |
|
64 | + EE_messenger $messenger, |
|
65 | + EE_Message $message |
|
66 | + ) { |
|
67 | + $extra_data = array( |
|
68 | + 'messenger' => $messenger, |
|
69 | + 'message_type' => $message_type, |
|
70 | + 'message' => $message, |
|
71 | + ); |
|
72 | + $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
73 | + $this->_template = is_array($template) ? $template['main'] : $template; |
|
74 | + return $this->_parse_message_template(); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + public function parse_attendee_list_template( |
|
79 | + $template, |
|
80 | + EE_Registration $registration, |
|
81 | + $valid_shortcodes, |
|
82 | + $extra_data = array() |
|
83 | + ) { |
|
84 | + $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
85 | + $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
86 | + return $this->_parse_message_template(); |
|
87 | + } |
|
88 | + |
|
89 | + public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
90 | + { |
|
91 | + $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
92 | + $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
93 | + return $this->_parse_message_template(); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
98 | + { |
|
99 | + $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
100 | + $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
101 | + return $this->_parse_message_template(); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + public function parse_line_item_list_template( |
|
106 | + $template, |
|
107 | + EE_Line_Item $line_item, |
|
108 | + $valid_shortcodes, |
|
109 | + $extra_data = array() |
|
110 | + ) { |
|
111 | + $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
112 | + $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
113 | + return $this->_parse_message_template(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + public function parse_payment_list_template( |
|
118 | + $template, |
|
119 | + EE_Payment $payment_item, |
|
120 | + $valid_shortcodes, |
|
121 | + $extra_data = array() |
|
122 | + ) { |
|
123 | + $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
124 | + $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
125 | + return $this->_parse_message_template(); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + public function parse_datetime_list_template( |
|
130 | + $template, |
|
131 | + EE_Datetime $datetime, |
|
132 | + $valid_shortcodes, |
|
133 | + $extra_data = array() |
|
134 | + ) { |
|
135 | + $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
136 | + $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
137 | + return $this->_parse_message_template(); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
142 | + { |
|
143 | + $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
144 | + $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
145 | + return $this->_parse_message_template(); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
150 | + { |
|
151 | + $this->_reset_props(); |
|
152 | + $this->_data['template'] = $template; |
|
153 | + $this->_data['data'] = $data; |
|
154 | + $this->_data['extra_data'] = $extra_data; |
|
155 | + $this->_set_shortcodes($valid_shortcodes); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + private function _reset_props() |
|
160 | + { |
|
161 | + $this->_template = $this->_data = null; |
|
162 | + $this->_shortcode_objs = array(); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * takes the given template and parses it with the $_shortcodes property |
|
168 | + * |
|
169 | + * @access private |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + private function _parse_message_template() |
|
173 | + { |
|
174 | + // now let's get a list of shortcodes that are found in the given template |
|
175 | + preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
176 | + $shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string. |
|
177 | + |
|
178 | + $matched_code = array(); |
|
179 | + $sc_values = array(); |
|
180 | + |
|
181 | + $list_type_shortcodes = array( |
|
182 | + '[ATTENDEE_LIST]', |
|
183 | + '[EVENT_LIST]', |
|
184 | + '[TICKET_LIST]', |
|
185 | + '[DATETIME_LIST]', |
|
186 | + '[QUESTION_LIST]', |
|
187 | + '[RECIPIENT_QUESTION_LIST]', |
|
188 | + '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
189 | + '[RECIPIENT_TICKET_LIST]', |
|
190 | + '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
191 | + '[RECIPIENT_DATETIME_LIST]', |
|
192 | + '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
193 | + '[TICKET_LINE_ITEM_LIST]', |
|
194 | + '[TAX_LINE_ITEM_LIST]', |
|
195 | + '[ADDITIONAL_LINE_ITEM_LIST]', |
|
196 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
197 | + '[PAYMENT_LIST_*]', |
|
198 | + ); |
|
199 | + |
|
200 | + $list_type_shortcodes = apply_filters( |
|
201 | + 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
202 | + $list_type_shortcodes |
|
203 | + ); |
|
204 | + |
|
205 | + // now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
206 | + foreach ($shortcodes as $shortcode) { |
|
207 | + foreach ($this->_shortcode_objs as $sc_obj) { |
|
208 | + if ($sc_obj instanceof EE_Shortcodes) { |
|
209 | + // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
210 | + preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
211 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
212 | + |
|
213 | + if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
214 | + continue; // the given shortcode isn't in this object |
|
215 | + } |
|
216 | + |
|
217 | + // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
218 | + if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
219 | + $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
220 | + } else { |
|
221 | + $data_send = $this->_data; |
|
222 | + } |
|
223 | + |
|
224 | + // is this a conditional type shortcode? If it is then we actually parse the template here. |
|
225 | + if ($this->_is_conditional_shortcode($shortcode)) { |
|
226 | + // most shortcode parsers are not going to have a match for this shortcode and will return an |
|
227 | + // empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
228 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
229 | + if ($parsed) { |
|
230 | + $this->_template = $parsed; |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
235 | + |
|
236 | + $matched_code[] = $shortcode; |
|
237 | + $sc_values[] = $parsed; |
|
238 | + } |
|
239 | + } |
|
240 | + } |
|
241 | + |
|
242 | + // now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
243 | + $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
244 | + return $parsed; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
250 | + * |
|
251 | + * Does it match this format: `[IF_` |
|
252 | + * |
|
253 | + * @param $shortcode |
|
254 | + */ |
|
255 | + protected function _is_conditional_shortcode($shortcode) |
|
256 | + { |
|
257 | + return strpos($shortcode, '[IF_') === 0; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
263 | + * various EE_Shortcode library objects |
|
264 | + * |
|
265 | + * @access private |
|
266 | + * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
267 | + * @return void |
|
268 | + */ |
|
269 | + private function _set_shortcodes($valid_shortcodes) |
|
270 | + { |
|
271 | + foreach ($valid_shortcodes as $shortcode_ref) { |
|
272 | + $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
273 | + $ref = str_replace(' ', '_', $ref); |
|
274 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
275 | + if (class_exists($classname)) { |
|
276 | + $this->_shortcode_objs[] = new $classname; |
|
277 | + } |
|
278 | + } |
|
279 | + } |
|
280 | 280 | } |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | if ($sc_obj instanceof EE_Shortcodes) { |
209 | 209 | // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
210 | 210 | preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
211 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
211 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
212 | 212 | |
213 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
213 | + if ( ! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
214 | 214 | continue; // the given shortcode isn't in this object |
215 | 215 | } |
216 | 216 | |
217 | 217 | // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
218 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
218 | + if ( ! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
219 | 219 | $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
220 | 220 | } else { |
221 | 221 | $data_send = $this->_data; |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | foreach ($valid_shortcodes as $shortcode_ref) { |
272 | 272 | $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
273 | 273 | $ref = str_replace(' ', '_', $ref); |
274 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
274 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
275 | 275 | if (class_exists($classname)) { |
276 | 276 | $this->_shortcode_objs[] = new $classname; |
277 | 277 | } |
@@ -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; |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | // the post already contains the related EE_Venue object AND one of the following is TRUE: |
59 | 59 | // the requested Venue ID matches the post ID OR... |
60 | 60 | // there was no specific Venue ID requested |
61 | - if (isset($post->EE_Venue) && ( $VNU_ID == $post->ID || ! $VNU_ID )) { |
|
61 | + if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) { |
|
62 | 62 | // use existing related EE_Venue object |
63 | - EEH_Venue_View::$_venue = $post->EE_Venue; |
|
63 | + EEH_Venue_View::$_venue = $post->EE_Venue; |
|
64 | 64 | } elseif ($VNU_ID) { |
65 | 65 | // there WAS a specific Venue ID requested, but it's NOT the current post object |
66 | 66 | EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | } |
101 | 101 | // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
102 | - if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
102 | + if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
103 | 103 | // sigh... pull it from the db |
104 | 104 | EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
105 | 105 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | public static function is_venue_private($VNU_ID = false) |
172 | 172 | { |
173 | 173 | $venue = EEH_Venue_View::get_venue($VNU_ID, true, true); |
174 | - if (! $venue instanceof EE_Venue) { |
|
174 | + if ( ! $venue instanceof EE_Venue) { |
|
175 | 175 | return null; |
176 | 176 | } |
177 | 177 | |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
251 | 251 | if ($venue instanceof EE_Venue) { |
252 | 252 | $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
253 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso') . '…'); |
|
254 | - return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
253 | + $venue_link = ' '.EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso').'…'); |
|
254 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '').$venue_link : ''; |
|
255 | 255 | } |
256 | 256 | return ''; |
257 | 257 | } |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | // loop thru terms and create links |
277 | 277 | foreach ($venue_categories as $term) { |
278 | 278 | $url = get_term_link($term, 'espresso_venue_categories'); |
279 | - if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) { |
|
280 | - $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
279 | + if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) { |
|
280 | + $category_links[] = '<a href="'.esc_url($url).'" rel="tag">'.$term->name.'</a> '; |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | } |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | $venue_name = apply_filters( |
342 | 342 | 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
343 | 343 | EEH_Venue_View::is_venue_private() |
344 | - ? EEH_Venue_View::$_venue->name() . " " . __('(Private)', 'event_espresso') |
|
344 | + ? EEH_Venue_View::$_venue->name()." ".__('(Private)', 'event_espresso') |
|
345 | 345 | : EEH_Venue_View::$_venue->name(), |
346 | 346 | EEH_Venue_View::$_venue |
347 | 347 | ); |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
451 | 451 | $details_page = is_single(); |
452 | 452 | $options = array(); |
453 | - $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
453 | + $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID.'-'.$venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
454 | 454 | |
455 | 455 | $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
456 | 456 | |
@@ -468,15 +468,15 @@ discard block |
||
468 | 468 | ; |
469 | 469 | |
470 | 470 | $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size; |
471 | - $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
471 | + $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) ? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
472 | 472 | |
473 | 473 | $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type; |
474 | - $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
474 | + $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) ? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
475 | 475 | |
476 | 476 | $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align; |
477 | - $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
477 | + $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) ? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
478 | 478 | |
479 | - $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link(); |
|
479 | + $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link(); |
|
480 | 480 | |
481 | 481 | return EEH_Maps::google_map($options); |
482 | 482 | } |
@@ -535,13 +535,13 @@ discard block |
||
535 | 535 | // generate nonce |
536 | 536 | $nonce = wp_create_nonce('edit_nonce'); |
537 | 537 | // generate url to venue editor for this venue |
538 | - $url = add_query_arg(array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url('admin.php')); |
|
538 | + $url = add_query_arg(array('page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce), admin_url('admin.php')); |
|
539 | 539 | // get edit CPT text |
540 | 540 | $post_type_obj = get_post_type_object('espresso_venues'); |
541 | 541 | // build final link html |
542 | - $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr($post_type_obj->labels->edit_item) . '">' . $link . '</a>'; |
|
542 | + $link = '<a class="post-edit-link" href="'.$url.'" title="'.esc_attr($post_type_obj->labels->edit_item).'">'.$link.'</a>'; |
|
543 | 543 | // put it all together |
544 | - return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
544 | + return $before.apply_filters('edit_post_link', $link, $venue->ID()).$after; |
|
545 | 545 | } |
546 | 546 | } |
547 | 547 | return ''; |
@@ -11,539 +11,538 @@ |
||
11 | 11 | class EEH_Venue_View extends EEH_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @access private |
|
16 | - * @var EE_Venue |
|
17 | - */ |
|
18 | - private static $_venue = null; |
|
19 | - |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * get_venue |
|
24 | - * attempts to retrieve an EE_Venue object any way it can |
|
25 | - * |
|
26 | - * @access public |
|
27 | - * @param int $VNU_ID |
|
28 | - * @param bool $look_in_event |
|
29 | - * @param bool $privacy_check Defaults to true. |
|
30 | - * When false, means even if the venue is private we return it regardless of access. |
|
31 | - * @param bool $password_check |
|
32 | - * @return \EE_Venue|null |
|
33 | - */ |
|
34 | - public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true) |
|
35 | - { |
|
36 | - $VNU_ID = absint($VNU_ID); |
|
37 | - // do we already have the Venue you are looking for? |
|
38 | - if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
39 | - // If the Venue ID matches $VNU_ID, return the venue. |
|
40 | - if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
41 | - return EEH_Venue_View::_get_venue($privacy_check); |
|
42 | - } |
|
43 | - // If the Venue ID does not match, try pulling a venue using $VNU_ID. |
|
44 | - $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
45 | - if ($venue instanceof EE_Venue) { |
|
46 | - EEH_Venue_View::$_venue = $venue; |
|
47 | - return EEH_Venue_View::_get_venue($privacy_check); |
|
48 | - } |
|
49 | - } |
|
50 | - // international newspaper? |
|
51 | - global $post; |
|
52 | - if ($post instanceof WP_Post) { |
|
53 | - switch ($post->post_type) { |
|
54 | - // if this is being called from an EE_Venue post, |
|
55 | - // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
|
56 | - // then we can try to just grab the attached EE_Venue object |
|
57 | - case 'espresso_venues': |
|
58 | - // the post already contains the related EE_Venue object AND one of the following is TRUE: |
|
59 | - // the requested Venue ID matches the post ID OR... |
|
60 | - // there was no specific Venue ID requested |
|
61 | - if (isset($post->EE_Venue) && ( $VNU_ID == $post->ID || ! $VNU_ID )) { |
|
62 | - // use existing related EE_Venue object |
|
63 | - EEH_Venue_View::$_venue = $post->EE_Venue; |
|
64 | - } elseif ($VNU_ID) { |
|
65 | - // there WAS a specific Venue ID requested, but it's NOT the current post object |
|
66 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
67 | - } else { |
|
68 | - // no specific Venue ID requested, so use post ID to generate EE_Venue object |
|
69 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
70 | - } |
|
71 | - break; |
|
72 | - |
|
73 | - case 'espresso_events': |
|
74 | - if ($look_in_event) { |
|
75 | - // grab the events related venues |
|
76 | - $venues = EEH_Venue_View::get_event_venues(); |
|
77 | - // make sure the result is an array |
|
78 | - $venues = is_array($venues) ? $venues : array(); |
|
79 | - // do we have an ID for a specific venue? |
|
80 | - if ($VNU_ID) { |
|
81 | - // loop thru the related venues |
|
82 | - foreach ($venues as $venue) { |
|
83 | - if ($venue instanceof EE_Venue) { |
|
84 | - // until we find the venue we're looking for |
|
85 | - if ($venue->ID() == $VNU_ID) { |
|
86 | - EEH_Venue_View::$_venue = $venue; |
|
87 | - break; |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - // no venue ID ? |
|
92 | - // then the global post is an events post and this function was called with no argument |
|
93 | - } else { |
|
94 | - // just grab the first related event venue |
|
95 | - EEH_Venue_View::$_venue = reset($venues); |
|
96 | - } |
|
97 | - } |
|
98 | - break; |
|
99 | - } |
|
100 | - } |
|
101 | - // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
|
102 | - if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
103 | - // sigh... pull it from the db |
|
104 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
105 | - } |
|
106 | - return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * return a single venue |
|
113 | - * |
|
114 | - * @param bool $privacy_check Defaults to true. |
|
115 | - * When false, means even if the venue is private we return it regardless of access. |
|
116 | - * @param bool $password_check |
|
117 | - * @return EE_Venue |
|
118 | - */ |
|
119 | - protected static function _get_venue($privacy_check = true, $password_check = true) |
|
120 | - { |
|
121 | - // check for private venues. |
|
122 | - if (EEH_Venue_View::$_venue instanceof EE_Venue |
|
123 | - && EEH_Venue_View::$_venue->status() == 'private' |
|
124 | - && $privacy_check |
|
125 | - && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
126 | - ) { |
|
127 | - return null; |
|
128 | - } |
|
129 | - // check for password protected venues |
|
130 | - if (EEH_Venue_View::$_venue instanceof EE_Venue |
|
131 | - && $password_check |
|
132 | - && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
133 | - ) { |
|
134 | - return null; |
|
135 | - } |
|
136 | - return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * get_event_venues |
|
143 | - * |
|
144 | - * @access public |
|
145 | - * @return EE_Venue[] |
|
146 | - */ |
|
147 | - public static function get_event_venues() |
|
148 | - { |
|
149 | - global $post; |
|
150 | - if ($post->post_type == 'espresso_events') { |
|
151 | - if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
152 | - return $post->EE_Event->venues(); |
|
153 | - } |
|
154 | - } |
|
155 | - return array(); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Simply checks whether a venue for the given ID (or the internally derived venue is private). |
|
163 | - * |
|
164 | - * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but is not |
|
165 | - * private. So it is important to do explicit boolean checks when using this conditional. |
|
166 | - * |
|
167 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
168 | - * |
|
169 | - * @return bool|null |
|
170 | - */ |
|
171 | - public static function is_venue_private($VNU_ID = false) |
|
172 | - { |
|
173 | - $venue = EEH_Venue_View::get_venue($VNU_ID, true, true); |
|
174 | - if (! $venue instanceof EE_Venue) { |
|
175 | - return null; |
|
176 | - } |
|
177 | - |
|
178 | - return $venue->status() == 'private' ? true : false; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * returns true or false if a venue is password protected or not |
|
186 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
187 | - * @return bool |
|
188 | - */ |
|
189 | - public static function is_venue_password_protected($VNU_ID = false) |
|
190 | - { |
|
191 | - $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
192 | - if ($venue instanceof EE_Venue |
|
193 | - && post_password_required($venue->ID()) |
|
194 | - ) { |
|
195 | - return true; |
|
196 | - } |
|
197 | - return false; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * If a venue is password protected, this will return the password form for gaining access |
|
204 | - * returns an empty string otherwise |
|
205 | - |
|
206 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
207 | - * |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - public static function password_protected_venue_form($VNU_ID = false) |
|
211 | - { |
|
212 | - $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
213 | - if ($venue instanceof EE_Venue |
|
214 | - && post_password_required($venue->ID()) |
|
215 | - ) { |
|
216 | - return get_the_password_form($venue->ID()); |
|
217 | - } |
|
218 | - return ''; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * venue_description |
|
225 | - * |
|
226 | - * @access public |
|
227 | - * @param int $VNU_ID |
|
228 | - * @return string |
|
229 | - */ |
|
230 | - public static function venue_description($VNU_ID = 0) |
|
231 | - { |
|
232 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
233 | - if ($venue instanceof EE_Venue) { |
|
234 | - return $venue->get_pretty('VNU_desc'); |
|
235 | - } |
|
236 | - return ''; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * venue_excerpt |
|
243 | - * |
|
244 | - * @access public |
|
245 | - * @param int $VNU_ID |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public static function venue_excerpt($VNU_ID = 0) |
|
249 | - { |
|
250 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
251 | - if ($venue instanceof EE_Venue) { |
|
252 | - $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
|
253 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso') . '…'); |
|
254 | - return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
255 | - } |
|
256 | - return ''; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * venue_categories |
|
263 | - * |
|
264 | - * @access public |
|
265 | - * @param int $VNU_ID |
|
266 | - * @param bool $hide_uncategorized |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true) |
|
270 | - { |
|
271 | - $category_links = array(); |
|
272 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
273 | - if ($venue instanceof EE_Venue) { |
|
274 | - // get category terms |
|
275 | - if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
276 | - // loop thru terms and create links |
|
277 | - foreach ($venue_categories as $term) { |
|
278 | - $url = get_term_link($term, 'espresso_venue_categories'); |
|
279 | - if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) { |
|
280 | - $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
284 | - } |
|
285 | - return implode(', ', $category_links); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * venue_address |
|
292 | - * |
|
293 | - * @access public |
|
294 | - * @param string $type |
|
295 | - * @param int $VNU_ID |
|
296 | - * @param bool $use_schema |
|
297 | - * @param bool $add_wrapper |
|
298 | - * @return string |
|
299 | - */ |
|
300 | - public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) |
|
301 | - { |
|
302 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
303 | - if ($venue instanceof EE_Venue) { |
|
304 | - return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
305 | - } |
|
306 | - return ''; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * venue_has_address |
|
313 | - * |
|
314 | - * @access public |
|
315 | - * @param int $VNU_ID |
|
316 | - * @return bool|string |
|
317 | - */ |
|
318 | - public static function venue_has_address($VNU_ID = 0) |
|
319 | - { |
|
320 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
321 | - if ($venue instanceof EE_Venue) { |
|
322 | - return EEH_Address::format($venue, 'inline', false, false); |
|
323 | - } |
|
324 | - return false; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * venue_name |
|
331 | - * |
|
332 | - * @access public |
|
333 | - * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website |
|
334 | - * @param int $VNU_ID |
|
335 | - * @return string |
|
336 | - */ |
|
337 | - public static function venue_name($link_to = 'details', $VNU_ID = 0) |
|
338 | - { |
|
339 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
340 | - if ($venue instanceof EE_Venue) { |
|
341 | - $venue_name = apply_filters( |
|
342 | - 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
|
343 | - EEH_Venue_View::is_venue_private() |
|
344 | - ? EEH_Venue_View::$_venue->name() . " " . __('(Private)', 'event_espresso') |
|
345 | - : EEH_Venue_View::$_venue->name(), |
|
346 | - EEH_Venue_View::$_venue |
|
347 | - ); |
|
348 | - $venue_name = EEH_Schema::name($venue_name); |
|
349 | - |
|
350 | - // if venue is trashed then ignore the "link to" setting because the venue is trashed. |
|
351 | - if ($venue->get('status') == 'trash') { |
|
352 | - $link_to = ''; |
|
353 | - } |
|
354 | - switch ($link_to) { |
|
355 | - case 'details': |
|
356 | - return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
357 | - break; |
|
358 | - |
|
359 | - case 'website': |
|
360 | - return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
361 | - break; |
|
362 | - |
|
363 | - default: |
|
364 | - return $venue_name; |
|
365 | - } |
|
366 | - } |
|
367 | - return ''; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * venue_details_link |
|
374 | - * |
|
375 | - * @access public |
|
376 | - * @param int $VNU_ID |
|
377 | - * @param string $text |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public static function venue_details_link($VNU_ID = 0, $text = '') |
|
381 | - { |
|
382 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
383 | - if ($venue instanceof EE_Venue) { |
|
384 | - return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
385 | - } |
|
386 | - return ''; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * venue_website_link |
|
393 | - * |
|
394 | - * @access public |
|
395 | - * @param int $VNU_ID |
|
396 | - * @param string $text |
|
397 | - * @return string |
|
398 | - */ |
|
399 | - public static function venue_website_link($VNU_ID = 0, $text = '') |
|
400 | - { |
|
401 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
402 | - if ($venue instanceof EE_Venue) { |
|
403 | - $url = $venue->venue_url(); |
|
404 | - $text = ! empty($text) ? $text : $url; |
|
405 | - return ! empty($url) ? EEH_Schema::url($url, $text) : ''; |
|
406 | - } |
|
407 | - return ''; |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * venue_phone |
|
414 | - * |
|
415 | - * @access public |
|
416 | - * @param int $VNU_ID |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - public static function venue_phone($VNU_ID = 0) |
|
420 | - { |
|
421 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
422 | - if ($venue instanceof EE_Venue) { |
|
423 | - return EEH_Schema::telephone($venue->phone()); |
|
424 | - } |
|
425 | - return ''; |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * venue_gmap |
|
432 | - * |
|
433 | - * @access public |
|
434 | - * @param int $VNU_ID |
|
435 | - * @param bool|string $map_ID a unique identifier for this map |
|
436 | - * @param array $gmap map options |
|
437 | - * @return string |
|
438 | - */ |
|
439 | - public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = array()) |
|
440 | - { |
|
441 | - |
|
442 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
443 | - if ($venue instanceof EE_Venue) { |
|
444 | - // check for global espresso_events post and use it's ID if no map_ID is set |
|
445 | - global $post; |
|
446 | - $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
447 | - // grab map settings |
|
448 | - $map_cfg = EE_Registry::instance()->CFG->map_settings; |
|
449 | - // are maps enabled ? |
|
450 | - if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
451 | - $details_page = is_single(); |
|
452 | - $options = array(); |
|
453 | - $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
454 | - |
|
455 | - $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
|
456 | - |
|
457 | - $options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width; |
|
458 | - $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
459 | - |
|
460 | - $options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height; |
|
461 | - $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
462 | - |
|
463 | - $options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom; |
|
464 | - $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
465 | - |
|
466 | - $options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav; |
|
467 | - $options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display']; |
|
468 | - ; |
|
469 | - |
|
470 | - $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size; |
|
471 | - $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
472 | - |
|
473 | - $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type; |
|
474 | - $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
475 | - |
|
476 | - $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align; |
|
477 | - $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
478 | - |
|
479 | - $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link(); |
|
480 | - |
|
481 | - return EEH_Maps::google_map($options); |
|
482 | - } |
|
483 | - } |
|
484 | - |
|
485 | - return ''; |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Gets the HTML to display a static map of the venue |
|
490 | - * @param EE_Venue $venue |
|
491 | - * @param array $atts like EEH_Maps::google_map_link |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public static function espresso_google_static_map(EE_Venue $venue, $atts = array()) |
|
495 | - { |
|
496 | - $state = $venue->state_obj(); |
|
497 | - $country = $venue->country_obj(); |
|
498 | - $atts = shortcode_atts( |
|
499 | - array( |
|
500 | - 'id' => $venue->ID(), |
|
501 | - 'address' => $venue->get('VNU_address'), |
|
502 | - 'city' => $venue->get('VNU_city'), |
|
503 | - 'state' => $state instanceof EE_State ? $state->name() : '', |
|
504 | - 'zip' => $venue->get('VNU_zip'), |
|
505 | - 'country' => $country instanceof EE_Country ? $country->name() : '', |
|
506 | - 'type' => 'map', |
|
507 | - 'map_w' => 200, |
|
508 | - 'map_h' => 200 |
|
509 | - ), |
|
510 | - $atts |
|
511 | - ); |
|
512 | - return EEH_Maps::google_map_link($atts); |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * edit_venue_link |
|
519 | - * |
|
520 | - * @access public |
|
521 | - * @param int $VNU_ID |
|
522 | - * @param string $link |
|
523 | - * @param string $before |
|
524 | - * @param string $after |
|
525 | - * @return string |
|
526 | - */ |
|
527 | - public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>') |
|
528 | - { |
|
529 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
530 | - if ($venue instanceof EE_Venue) { |
|
531 | - // can the user edit this post ? |
|
532 | - if (current_user_can('edit_post', $venue->ID())) { |
|
533 | - // set link text |
|
534 | - $link = ! empty($link) ? $link : __('edit this venue', 'event_espresso'); |
|
535 | - // generate nonce |
|
536 | - $nonce = wp_create_nonce('edit_nonce'); |
|
537 | - // generate url to venue editor for this venue |
|
538 | - $url = add_query_arg(array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url('admin.php')); |
|
539 | - // get edit CPT text |
|
540 | - $post_type_obj = get_post_type_object('espresso_venues'); |
|
541 | - // build final link html |
|
542 | - $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr($post_type_obj->labels->edit_item) . '">' . $link . '</a>'; |
|
543 | - // put it all together |
|
544 | - return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
545 | - } |
|
546 | - } |
|
547 | - return ''; |
|
548 | - } |
|
14 | + /** |
|
15 | + * @access private |
|
16 | + * @var EE_Venue |
|
17 | + */ |
|
18 | + private static $_venue = null; |
|
19 | + |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * get_venue |
|
24 | + * attempts to retrieve an EE_Venue object any way it can |
|
25 | + * |
|
26 | + * @access public |
|
27 | + * @param int $VNU_ID |
|
28 | + * @param bool $look_in_event |
|
29 | + * @param bool $privacy_check Defaults to true. |
|
30 | + * When false, means even if the venue is private we return it regardless of access. |
|
31 | + * @param bool $password_check |
|
32 | + * @return \EE_Venue|null |
|
33 | + */ |
|
34 | + public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true) |
|
35 | + { |
|
36 | + $VNU_ID = absint($VNU_ID); |
|
37 | + // do we already have the Venue you are looking for? |
|
38 | + if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
39 | + // If the Venue ID matches $VNU_ID, return the venue. |
|
40 | + if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
41 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
42 | + } |
|
43 | + // If the Venue ID does not match, try pulling a venue using $VNU_ID. |
|
44 | + $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
45 | + if ($venue instanceof EE_Venue) { |
|
46 | + EEH_Venue_View::$_venue = $venue; |
|
47 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
48 | + } |
|
49 | + } |
|
50 | + // international newspaper? |
|
51 | + global $post; |
|
52 | + if ($post instanceof WP_Post) { |
|
53 | + switch ($post->post_type) { |
|
54 | + // if this is being called from an EE_Venue post, |
|
55 | + // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
|
56 | + // then we can try to just grab the attached EE_Venue object |
|
57 | + case 'espresso_venues': |
|
58 | + // the post already contains the related EE_Venue object AND one of the following is TRUE: |
|
59 | + // the requested Venue ID matches the post ID OR... |
|
60 | + // there was no specific Venue ID requested |
|
61 | + if (isset($post->EE_Venue) && ( $VNU_ID == $post->ID || ! $VNU_ID )) { |
|
62 | + // use existing related EE_Venue object |
|
63 | + EEH_Venue_View::$_venue = $post->EE_Venue; |
|
64 | + } elseif ($VNU_ID) { |
|
65 | + // there WAS a specific Venue ID requested, but it's NOT the current post object |
|
66 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
67 | + } else { |
|
68 | + // no specific Venue ID requested, so use post ID to generate EE_Venue object |
|
69 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
70 | + } |
|
71 | + break; |
|
72 | + |
|
73 | + case 'espresso_events': |
|
74 | + if ($look_in_event) { |
|
75 | + // grab the events related venues |
|
76 | + $venues = EEH_Venue_View::get_event_venues(); |
|
77 | + // make sure the result is an array |
|
78 | + $venues = is_array($venues) ? $venues : array(); |
|
79 | + // do we have an ID for a specific venue? |
|
80 | + if ($VNU_ID) { |
|
81 | + // loop thru the related venues |
|
82 | + foreach ($venues as $venue) { |
|
83 | + if ($venue instanceof EE_Venue) { |
|
84 | + // until we find the venue we're looking for |
|
85 | + if ($venue->ID() == $VNU_ID) { |
|
86 | + EEH_Venue_View::$_venue = $venue; |
|
87 | + break; |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + // no venue ID ? |
|
92 | + // then the global post is an events post and this function was called with no argument |
|
93 | + } else { |
|
94 | + // just grab the first related event venue |
|
95 | + EEH_Venue_View::$_venue = reset($venues); |
|
96 | + } |
|
97 | + } |
|
98 | + break; |
|
99 | + } |
|
100 | + } |
|
101 | + // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
|
102 | + if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
103 | + // sigh... pull it from the db |
|
104 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
105 | + } |
|
106 | + return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * return a single venue |
|
113 | + * |
|
114 | + * @param bool $privacy_check Defaults to true. |
|
115 | + * When false, means even if the venue is private we return it regardless of access. |
|
116 | + * @param bool $password_check |
|
117 | + * @return EE_Venue |
|
118 | + */ |
|
119 | + protected static function _get_venue($privacy_check = true, $password_check = true) |
|
120 | + { |
|
121 | + // check for private venues. |
|
122 | + if (EEH_Venue_View::$_venue instanceof EE_Venue |
|
123 | + && EEH_Venue_View::$_venue->status() == 'private' |
|
124 | + && $privacy_check |
|
125 | + && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
126 | + ) { |
|
127 | + return null; |
|
128 | + } |
|
129 | + // check for password protected venues |
|
130 | + if (EEH_Venue_View::$_venue instanceof EE_Venue |
|
131 | + && $password_check |
|
132 | + && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
133 | + ) { |
|
134 | + return null; |
|
135 | + } |
|
136 | + return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * get_event_venues |
|
143 | + * |
|
144 | + * @access public |
|
145 | + * @return EE_Venue[] |
|
146 | + */ |
|
147 | + public static function get_event_venues() |
|
148 | + { |
|
149 | + global $post; |
|
150 | + if ($post->post_type == 'espresso_events') { |
|
151 | + if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
152 | + return $post->EE_Event->venues(); |
|
153 | + } |
|
154 | + } |
|
155 | + return array(); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Simply checks whether a venue for the given ID (or the internally derived venue is private). |
|
163 | + * |
|
164 | + * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but is not |
|
165 | + * private. So it is important to do explicit boolean checks when using this conditional. |
|
166 | + * |
|
167 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
168 | + * |
|
169 | + * @return bool|null |
|
170 | + */ |
|
171 | + public static function is_venue_private($VNU_ID = false) |
|
172 | + { |
|
173 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true); |
|
174 | + if (! $venue instanceof EE_Venue) { |
|
175 | + return null; |
|
176 | + } |
|
177 | + |
|
178 | + return $venue->status() == 'private' ? true : false; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * returns true or false if a venue is password protected or not |
|
186 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
187 | + * @return bool |
|
188 | + */ |
|
189 | + public static function is_venue_password_protected($VNU_ID = false) |
|
190 | + { |
|
191 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
192 | + if ($venue instanceof EE_Venue |
|
193 | + && post_password_required($venue->ID()) |
|
194 | + ) { |
|
195 | + return true; |
|
196 | + } |
|
197 | + return false; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * If a venue is password protected, this will return the password form for gaining access |
|
204 | + * returns an empty string otherwise |
|
205 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
206 | + * |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + public static function password_protected_venue_form($VNU_ID = false) |
|
210 | + { |
|
211 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
212 | + if ($venue instanceof EE_Venue |
|
213 | + && post_password_required($venue->ID()) |
|
214 | + ) { |
|
215 | + return get_the_password_form($venue->ID()); |
|
216 | + } |
|
217 | + return ''; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * venue_description |
|
224 | + * |
|
225 | + * @access public |
|
226 | + * @param int $VNU_ID |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public static function venue_description($VNU_ID = 0) |
|
230 | + { |
|
231 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
232 | + if ($venue instanceof EE_Venue) { |
|
233 | + return $venue->get_pretty('VNU_desc'); |
|
234 | + } |
|
235 | + return ''; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * venue_excerpt |
|
242 | + * |
|
243 | + * @access public |
|
244 | + * @param int $VNU_ID |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + public static function venue_excerpt($VNU_ID = 0) |
|
248 | + { |
|
249 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
250 | + if ($venue instanceof EE_Venue) { |
|
251 | + $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
|
252 | + $venue_link = ' ' . EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso') . '…'); |
|
253 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
254 | + } |
|
255 | + return ''; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * venue_categories |
|
262 | + * |
|
263 | + * @access public |
|
264 | + * @param int $VNU_ID |
|
265 | + * @param bool $hide_uncategorized |
|
266 | + * @return string |
|
267 | + */ |
|
268 | + public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true) |
|
269 | + { |
|
270 | + $category_links = array(); |
|
271 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
272 | + if ($venue instanceof EE_Venue) { |
|
273 | + // get category terms |
|
274 | + if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
275 | + // loop thru terms and create links |
|
276 | + foreach ($venue_categories as $term) { |
|
277 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
278 | + if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) { |
|
279 | + $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
280 | + } |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | + return implode(', ', $category_links); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * venue_address |
|
291 | + * |
|
292 | + * @access public |
|
293 | + * @param string $type |
|
294 | + * @param int $VNU_ID |
|
295 | + * @param bool $use_schema |
|
296 | + * @param bool $add_wrapper |
|
297 | + * @return string |
|
298 | + */ |
|
299 | + public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) |
|
300 | + { |
|
301 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
302 | + if ($venue instanceof EE_Venue) { |
|
303 | + return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
304 | + } |
|
305 | + return ''; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * venue_has_address |
|
312 | + * |
|
313 | + * @access public |
|
314 | + * @param int $VNU_ID |
|
315 | + * @return bool|string |
|
316 | + */ |
|
317 | + public static function venue_has_address($VNU_ID = 0) |
|
318 | + { |
|
319 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
320 | + if ($venue instanceof EE_Venue) { |
|
321 | + return EEH_Address::format($venue, 'inline', false, false); |
|
322 | + } |
|
323 | + return false; |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * venue_name |
|
330 | + * |
|
331 | + * @access public |
|
332 | + * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website |
|
333 | + * @param int $VNU_ID |
|
334 | + * @return string |
|
335 | + */ |
|
336 | + public static function venue_name($link_to = 'details', $VNU_ID = 0) |
|
337 | + { |
|
338 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
339 | + if ($venue instanceof EE_Venue) { |
|
340 | + $venue_name = apply_filters( |
|
341 | + 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
|
342 | + EEH_Venue_View::is_venue_private() |
|
343 | + ? EEH_Venue_View::$_venue->name() . " " . __('(Private)', 'event_espresso') |
|
344 | + : EEH_Venue_View::$_venue->name(), |
|
345 | + EEH_Venue_View::$_venue |
|
346 | + ); |
|
347 | + $venue_name = EEH_Schema::name($venue_name); |
|
348 | + |
|
349 | + // if venue is trashed then ignore the "link to" setting because the venue is trashed. |
|
350 | + if ($venue->get('status') == 'trash') { |
|
351 | + $link_to = ''; |
|
352 | + } |
|
353 | + switch ($link_to) { |
|
354 | + case 'details': |
|
355 | + return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
356 | + break; |
|
357 | + |
|
358 | + case 'website': |
|
359 | + return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
360 | + break; |
|
361 | + |
|
362 | + default: |
|
363 | + return $venue_name; |
|
364 | + } |
|
365 | + } |
|
366 | + return ''; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * venue_details_link |
|
373 | + * |
|
374 | + * @access public |
|
375 | + * @param int $VNU_ID |
|
376 | + * @param string $text |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public static function venue_details_link($VNU_ID = 0, $text = '') |
|
380 | + { |
|
381 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
382 | + if ($venue instanceof EE_Venue) { |
|
383 | + return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
384 | + } |
|
385 | + return ''; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * venue_website_link |
|
392 | + * |
|
393 | + * @access public |
|
394 | + * @param int $VNU_ID |
|
395 | + * @param string $text |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + public static function venue_website_link($VNU_ID = 0, $text = '') |
|
399 | + { |
|
400 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
401 | + if ($venue instanceof EE_Venue) { |
|
402 | + $url = $venue->venue_url(); |
|
403 | + $text = ! empty($text) ? $text : $url; |
|
404 | + return ! empty($url) ? EEH_Schema::url($url, $text) : ''; |
|
405 | + } |
|
406 | + return ''; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * venue_phone |
|
413 | + * |
|
414 | + * @access public |
|
415 | + * @param int $VNU_ID |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public static function venue_phone($VNU_ID = 0) |
|
419 | + { |
|
420 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
421 | + if ($venue instanceof EE_Venue) { |
|
422 | + return EEH_Schema::telephone($venue->phone()); |
|
423 | + } |
|
424 | + return ''; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * venue_gmap |
|
431 | + * |
|
432 | + * @access public |
|
433 | + * @param int $VNU_ID |
|
434 | + * @param bool|string $map_ID a unique identifier for this map |
|
435 | + * @param array $gmap map options |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = array()) |
|
439 | + { |
|
440 | + |
|
441 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
442 | + if ($venue instanceof EE_Venue) { |
|
443 | + // check for global espresso_events post and use it's ID if no map_ID is set |
|
444 | + global $post; |
|
445 | + $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
446 | + // grab map settings |
|
447 | + $map_cfg = EE_Registry::instance()->CFG->map_settings; |
|
448 | + // are maps enabled ? |
|
449 | + if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
450 | + $details_page = is_single(); |
|
451 | + $options = array(); |
|
452 | + $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
453 | + |
|
454 | + $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
|
455 | + |
|
456 | + $options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width; |
|
457 | + $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
458 | + |
|
459 | + $options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height; |
|
460 | + $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
461 | + |
|
462 | + $options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom; |
|
463 | + $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
464 | + |
|
465 | + $options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav; |
|
466 | + $options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display']; |
|
467 | + ; |
|
468 | + |
|
469 | + $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size; |
|
470 | + $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
471 | + |
|
472 | + $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type; |
|
473 | + $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
474 | + |
|
475 | + $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align; |
|
476 | + $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
477 | + |
|
478 | + $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link(); |
|
479 | + |
|
480 | + return EEH_Maps::google_map($options); |
|
481 | + } |
|
482 | + } |
|
483 | + |
|
484 | + return ''; |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * Gets the HTML to display a static map of the venue |
|
489 | + * @param EE_Venue $venue |
|
490 | + * @param array $atts like EEH_Maps::google_map_link |
|
491 | + * @return string |
|
492 | + */ |
|
493 | + public static function espresso_google_static_map(EE_Venue $venue, $atts = array()) |
|
494 | + { |
|
495 | + $state = $venue->state_obj(); |
|
496 | + $country = $venue->country_obj(); |
|
497 | + $atts = shortcode_atts( |
|
498 | + array( |
|
499 | + 'id' => $venue->ID(), |
|
500 | + 'address' => $venue->get('VNU_address'), |
|
501 | + 'city' => $venue->get('VNU_city'), |
|
502 | + 'state' => $state instanceof EE_State ? $state->name() : '', |
|
503 | + 'zip' => $venue->get('VNU_zip'), |
|
504 | + 'country' => $country instanceof EE_Country ? $country->name() : '', |
|
505 | + 'type' => 'map', |
|
506 | + 'map_w' => 200, |
|
507 | + 'map_h' => 200 |
|
508 | + ), |
|
509 | + $atts |
|
510 | + ); |
|
511 | + return EEH_Maps::google_map_link($atts); |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * edit_venue_link |
|
518 | + * |
|
519 | + * @access public |
|
520 | + * @param int $VNU_ID |
|
521 | + * @param string $link |
|
522 | + * @param string $before |
|
523 | + * @param string $after |
|
524 | + * @return string |
|
525 | + */ |
|
526 | + public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>') |
|
527 | + { |
|
528 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
529 | + if ($venue instanceof EE_Venue) { |
|
530 | + // can the user edit this post ? |
|
531 | + if (current_user_can('edit_post', $venue->ID())) { |
|
532 | + // set link text |
|
533 | + $link = ! empty($link) ? $link : __('edit this venue', 'event_espresso'); |
|
534 | + // generate nonce |
|
535 | + $nonce = wp_create_nonce('edit_nonce'); |
|
536 | + // generate url to venue editor for this venue |
|
537 | + $url = add_query_arg(array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url('admin.php')); |
|
538 | + // get edit CPT text |
|
539 | + $post_type_obj = get_post_type_object('espresso_venues'); |
|
540 | + // build final link html |
|
541 | + $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr($post_type_obj->labels->edit_item) . '">' . $link . '</a>'; |
|
542 | + // put it all together |
|
543 | + return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
544 | + } |
|
545 | + } |
|
546 | + return ''; |
|
547 | + } |
|
549 | 548 | } |