@@ -396,7 +396,7 @@ |
||
396 | 396 | |
397 | 397 | /** |
398 | 398 | * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
399 | - * @param $string |
|
399 | + * @param string $string |
|
400 | 400 | * @return bool |
401 | 401 | */ |
402 | 402 | protected function valid_base_64($string) |
@@ -16,669 +16,669 @@ |
||
16 | 16 | class EE_Encryption |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * key used for saving the encryption key to the wp_options table |
|
21 | - */ |
|
22 | - const ENCRYPTION_OPTION_KEY = 'ee_encryption_key'; |
|
23 | - |
|
24 | - /** |
|
25 | - * the OPENSSL cipher method used |
|
26 | - */ |
|
27 | - const OPENSSL_CIPHER_METHOD = 'AES-128-CBC'; |
|
28 | - |
|
29 | - /** |
|
30 | - * WP "options_name" used to store a verified available cipher method |
|
31 | - */ |
|
32 | - const OPENSSL_CIPHER_METHOD_OPTION_NAME = 'ee_openssl_cipher_method'; |
|
33 | - |
|
34 | - /** |
|
35 | - * the OPENSSL digest method used |
|
36 | - */ |
|
37 | - const OPENSSL_DIGEST_METHOD = 'sha512'; |
|
38 | - |
|
39 | - /** |
|
40 | - * separates the encrypted text from the initialization vector |
|
41 | - */ |
|
42 | - const OPENSSL_IV_DELIMITER = ':iv:'; |
|
43 | - |
|
44 | - /** |
|
45 | - * appended to text encrypted using the acme encryption |
|
46 | - */ |
|
47 | - const ACME_ENCRYPTION_FLAG = '::ae'; |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * instance of the EE_Encryption object |
|
53 | - */ |
|
54 | - protected static $_instance; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var string $_encryption_key |
|
58 | - */ |
|
59 | - protected $_encryption_key; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var string $cipher_method |
|
63 | - */ |
|
64 | - private $cipher_method = ''; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var array $cipher_methods |
|
68 | - */ |
|
69 | - private $cipher_methods = array(); |
|
70 | - |
|
71 | - /** |
|
72 | - * @var array $digest_methods |
|
73 | - */ |
|
74 | - private $digest_methods = array(); |
|
75 | - |
|
76 | - /** |
|
77 | - * @var boolean $_use_openssl_encrypt |
|
78 | - */ |
|
79 | - protected $_use_openssl_encrypt = false; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var boolean $_use_mcrypt |
|
83 | - */ |
|
84 | - protected $_use_mcrypt = false; |
|
85 | - |
|
86 | - /** |
|
87 | - * @var boolean $_use_base64_encode |
|
88 | - */ |
|
89 | - protected $_use_base64_encode = false; |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * protected constructor to prevent direct creation |
|
95 | - */ |
|
96 | - protected function __construct() |
|
97 | - { |
|
98 | - if (! defined('ESPRESSO_ENCRYPT')) { |
|
99 | - define('ESPRESSO_ENCRYPT', true); |
|
100 | - } |
|
101 | - if (extension_loaded('openssl')) { |
|
102 | - $this->_use_openssl_encrypt = true; |
|
103 | - } else if (extension_loaded('mcrypt')) { |
|
104 | - $this->_use_mcrypt = true; |
|
105 | - } |
|
106 | - if (function_exists('base64_encode')) { |
|
107 | - $this->_use_base64_encode = true; |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * singleton method used to instantiate class object |
|
115 | - * |
|
116 | - * @return EE_Encryption |
|
117 | - */ |
|
118 | - public static function instance() |
|
119 | - { |
|
120 | - // check if class object is instantiated |
|
121 | - if (! self::$_instance instanceof EE_Encryption) { |
|
122 | - self::$_instance = new self(); |
|
123 | - } |
|
124 | - return self::$_instance; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * get encryption key |
|
131 | - * |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function get_encryption_key() |
|
135 | - { |
|
136 | - // if encryption key has not been set |
|
137 | - if (empty($this->_encryption_key)) { |
|
138 | - // retrieve encryption_key from db |
|
139 | - $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, ''); |
|
140 | - // WHAT?? No encryption_key in the db ?? |
|
141 | - if ($this->_encryption_key === '') { |
|
142 | - // let's make one. And md5 it to make it just the right size for a key |
|
143 | - $new_key = md5($this->generate_random_string()); |
|
144 | - // now save it to the db for later |
|
145 | - add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key); |
|
146 | - // here's the key - FINALLY ! |
|
147 | - $this->_encryption_key = $new_key; |
|
148 | - } |
|
149 | - } |
|
150 | - return $this->_encryption_key; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * encrypts data |
|
157 | - * |
|
158 | - * @param string $text_string - the text to be encrypted |
|
159 | - * @return string |
|
160 | - * @throws RuntimeException |
|
161 | - */ |
|
162 | - public function encrypt($text_string = '') |
|
163 | - { |
|
164 | - // you give me nothing??? GET OUT ! |
|
165 | - if (empty($text_string)) { |
|
166 | - return $text_string; |
|
167 | - } |
|
168 | - if ($this->_use_openssl_encrypt) { |
|
169 | - $encrypted_text = $this->openssl_encrypt($text_string); |
|
170 | - } else { |
|
171 | - $encrypted_text = $this->acme_encrypt($text_string); |
|
172 | - } |
|
173 | - return $encrypted_text; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * decrypts data |
|
180 | - * |
|
181 | - * @param string $encrypted_text - the text to be decrypted |
|
182 | - * @return string |
|
183 | - * @throws RuntimeException |
|
184 | - */ |
|
185 | - public function decrypt($encrypted_text = '') |
|
186 | - { |
|
187 | - // you give me nothing??? GET OUT ! |
|
188 | - if (empty($encrypted_text)) { |
|
189 | - return $encrypted_text; |
|
190 | - } |
|
191 | - // if PHP's mcrypt functions are installed then we'll use them |
|
192 | - if ($this->_use_openssl_encrypt) { |
|
193 | - $decrypted_text = $this->openssl_decrypt($encrypted_text); |
|
194 | - } else { |
|
195 | - $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
196 | - } |
|
197 | - return $decrypted_text; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * encodes string with PHP's base64 encoding |
|
204 | - * |
|
205 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
206 | - * @param string $text_string the text to be encoded |
|
207 | - * @return string |
|
208 | - */ |
|
209 | - public function base64_string_encode($text_string = '') |
|
210 | - { |
|
211 | - // you give me nothing??? GET OUT ! |
|
212 | - if (empty($text_string) || ! $this->_use_base64_encode) { |
|
213 | - return $text_string; |
|
214 | - } |
|
215 | - // encode |
|
216 | - return base64_encode($text_string); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * decodes string that has been encoded with PHP's base64 encoding |
|
223 | - * |
|
224 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
225 | - * @param string $encoded_string the text to be decoded |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public function base64_string_decode($encoded_string = '') |
|
229 | - { |
|
230 | - // you give me nothing??? GET OUT ! |
|
231 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
232 | - return $encoded_string; |
|
233 | - } |
|
234 | - // decode |
|
235 | - return base64_decode($encoded_string); |
|
236 | - } |
|
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 | - /** |
|
262 | - * decodes url string that has been encoded with PHP's base64 encoding |
|
263 | - * |
|
264 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
265 | - * @param string $encoded_string the text to be decoded |
|
266 | - * @return string |
|
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 | - return base64_decode($encoded_string); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * encrypts data using PHP's openssl functions |
|
284 | - * |
|
285 | - * @param string $text_string the text to be encrypted |
|
286 | - * @return string |
|
287 | - * @throws RuntimeException |
|
288 | - */ |
|
289 | - protected function openssl_encrypt($text_string = '') |
|
290 | - { |
|
291 | - // you give me nothing??? GET OUT ! |
|
292 | - if (empty($text_string)) { |
|
293 | - return $text_string; |
|
294 | - } |
|
295 | - $this->cipher_method = $this->getCipherMethod(); |
|
296 | - // get initialization vector size |
|
297 | - $iv_size = openssl_cipher_iv_length($this->cipher_method); |
|
298 | - // generate initialization vector. |
|
299 | - // The second parameter ("crypto_strong") is passed by reference, |
|
300 | - // and is used to determines if the algorithm used was "cryptographically strong" |
|
301 | - // openssl_random_pseudo_bytes() will toggle it to either true or false |
|
302 | - $iv = openssl_random_pseudo_bytes($iv_size, $is_strong); |
|
303 | - if ($iv === false || $is_strong === false) { |
|
304 | - throw new RuntimeException( |
|
305 | - esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso') |
|
306 | - ); |
|
307 | - } |
|
308 | - // encrypt it |
|
309 | - $encrypted_text = openssl_encrypt( |
|
310 | - $text_string, |
|
311 | - $this->cipher_method, |
|
312 | - $this->getDigestHashValue(), |
|
313 | - 0, |
|
314 | - $iv |
|
315 | - ); |
|
316 | - // append the initialization vector |
|
317 | - $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
318 | - // trim and maybe encode |
|
319 | - return $this->_use_base64_encode |
|
320 | - ? trim(base64_encode($encrypted_text)) |
|
321 | - : trim($encrypted_text); |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * Returns a cipher method that has been verified to work. |
|
328 | - * First checks if the cached cipher has been set already and if so, returns that. |
|
329 | - * Then tests the incoming default and returns that if it's good. |
|
330 | - * If not, then it retrieves the previously tested and saved cipher method. |
|
331 | - * But if that doesn't exist, then calls getAvailableCipherMethod() |
|
332 | - * to see what is available on the server, and returns the results. |
|
333 | - * |
|
334 | - * @param string $cipher_method |
|
335 | - * @return string |
|
336 | - * @throws RuntimeException |
|
337 | - */ |
|
338 | - protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD) |
|
339 | - { |
|
340 | - if($this->cipher_method !== ''){ |
|
341 | - return $this->cipher_method; |
|
342 | - } |
|
343 | - // verify that the default cipher method can produce an initialization vector |
|
344 | - if (openssl_cipher_iv_length($cipher_method) === false) { |
|
345 | - // nope? okay let's get what we found in the past to work |
|
346 | - $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, ''); |
|
347 | - // oops... haven't tested available cipher methods yet |
|
348 | - if($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) { |
|
349 | - $cipher_method = $this->getAvailableCipherMethod($cipher_method); |
|
350 | - } |
|
351 | - } |
|
352 | - return $cipher_method; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * @param string $cipher_method |
|
359 | - * @return string |
|
360 | - * @throws \RuntimeException |
|
361 | - */ |
|
362 | - protected function getAvailableCipherMethod($cipher_method) |
|
363 | - { |
|
364 | - // verify that the incoming cipher method can produce an initialization vector |
|
365 | - if (openssl_cipher_iv_length($cipher_method) === false) { |
|
366 | - // nope? then check the next cipher in the list of available cipher methods |
|
367 | - $cipher_method = next($this->cipher_methods); |
|
368 | - // what? there's no list? then generate that list and cache it, |
|
369 | - if (empty($this->cipher_methods)) { |
|
370 | - $this->cipher_methods = openssl_get_cipher_methods(); |
|
371 | - // then grab the first item from the list |
|
372 | - $cipher_method = reset($this->cipher_methods); |
|
373 | - } |
|
374 | - if($cipher_method === false){ |
|
375 | - throw new RuntimeException( |
|
376 | - esc_html__( |
|
377 | - 'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.', |
|
378 | - 'event_espresso' |
|
379 | - ) |
|
380 | - ); |
|
381 | - } |
|
382 | - // verify that the next cipher method works |
|
383 | - return $this->getAvailableCipherMethod($cipher_method); |
|
384 | - } |
|
385 | - // if we've gotten this far, then we found an available cipher method that works |
|
386 | - // so save that for next time |
|
387 | - update_option( |
|
388 | - EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, |
|
389 | - $cipher_method |
|
390 | - ); |
|
391 | - return $cipher_method; |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * decrypts data that has been encrypted with PHP's openssl functions |
|
398 | - * |
|
399 | - * @param string $encrypted_text the text to be decrypted |
|
400 | - * @return string |
|
401 | - * @throws RuntimeException |
|
402 | - */ |
|
403 | - protected function openssl_decrypt($encrypted_text = '') |
|
404 | - { |
|
405 | - // you give me nothing??? GET OUT ! |
|
406 | - if (empty($encrypted_text)) { |
|
407 | - return $encrypted_text; |
|
408 | - } |
|
409 | - // decode |
|
410 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
411 | - ? base64_decode($encrypted_text) |
|
412 | - : $encrypted_text; |
|
413 | - $encrypted_components = explode( |
|
414 | - EE_Encryption::OPENSSL_IV_DELIMITER, |
|
415 | - $encrypted_text, |
|
416 | - 2 |
|
417 | - ); |
|
418 | - // check that iv exists, and if not, maybe text was encoded using mcrypt? |
|
419 | - if ($this->_use_mcrypt && ! isset($encrypted_components[1])) { |
|
420 | - return $this->m_decrypt($encrypted_text); |
|
421 | - } |
|
422 | - // decrypt it |
|
423 | - $decrypted_text = openssl_decrypt( |
|
424 | - $encrypted_components[0], |
|
425 | - $this->getCipherMethod(), |
|
426 | - $this->getDigestHashValue(), |
|
427 | - 0, |
|
428 | - $encrypted_components[1] |
|
429 | - ); |
|
430 | - $decrypted_text = trim($decrypted_text); |
|
431 | - return $decrypted_text; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Computes the digest hash value using the specified digest method. |
|
438 | - * If that digest method fails to produce a valid hash value, |
|
439 | - * then we'll grab the next digest method and recursively try again until something works. |
|
440 | - * |
|
441 | - * @param string $digest_method |
|
442 | - * @return string |
|
443 | - * @throws RuntimeException |
|
444 | - */ |
|
445 | - protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD){ |
|
446 | - $digest_hash_value = openssl_digest($this->get_encryption_key(), $digest_method); |
|
447 | - if ($digest_hash_value === false) { |
|
448 | - return $this->getDigestHashValue($this->getDigestMethod()); |
|
449 | - } |
|
450 | - return $digest_hash_value; |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * Returns the NEXT element in the $digest_methods array. |
|
457 | - * If the $digest_methods array is empty, then we populate it |
|
458 | - * with the available values returned from openssl_get_md_methods(). |
|
459 | - * |
|
460 | - * @return string |
|
461 | - * @throws \RuntimeException |
|
462 | - */ |
|
463 | - protected function getDigestMethod(){ |
|
464 | - $digest_method = prev($this->digest_methods); |
|
465 | - if (empty($this->digest_methods)) { |
|
466 | - $this->digest_methods = openssl_get_md_methods(); |
|
467 | - $digest_method = end($this->digest_methods); |
|
468 | - } |
|
469 | - if ($digest_method === false) { |
|
470 | - throw new RuntimeException( |
|
471 | - esc_html__( |
|
472 | - 'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.', |
|
473 | - 'event_espresso' |
|
474 | - ) |
|
475 | - ); |
|
476 | - } |
|
477 | - return $digest_method; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
483 | - * |
|
484 | - * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
485 | - * @param string $text_string the text to be decrypted |
|
486 | - * @return string |
|
487 | - */ |
|
488 | - protected function acme_encrypt($text_string = '') |
|
489 | - { |
|
490 | - // you give me nothing??? GET OUT ! |
|
491 | - if (empty($text_string)) { |
|
492 | - return $text_string; |
|
493 | - } |
|
494 | - $key_bits = str_split( |
|
495 | - str_pad( |
|
496 | - '', |
|
497 | - strlen($text_string), |
|
498 | - $this->get_encryption_key(), |
|
499 | - STR_PAD_RIGHT |
|
500 | - ) |
|
501 | - ); |
|
502 | - $string_bits = str_split($text_string); |
|
503 | - foreach ($string_bits as $k => $v) { |
|
504 | - $temp = ord($v) + ord($key_bits[$k]); |
|
505 | - $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
506 | - } |
|
507 | - $encrypted_text = implode('', $string_bits); |
|
508 | - $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
|
509 | - return $this->_use_base64_encode |
|
510 | - ? base64_encode($encrypted_text) |
|
511 | - : $encrypted_text; |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
518 | - * |
|
519 | - * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
520 | - * @param string $encrypted_text the text to be decrypted |
|
521 | - * @return string |
|
522 | - * @throws RuntimeException |
|
523 | - */ |
|
524 | - protected function acme_decrypt($encrypted_text = '') |
|
525 | - { |
|
526 | - // you give me nothing??? GET OUT ! |
|
527 | - if (empty($encrypted_text)) { |
|
528 | - return $encrypted_text; |
|
529 | - } |
|
530 | - // decode the data ? |
|
531 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
532 | - ? base64_decode($encrypted_text) |
|
533 | - : $encrypted_text; |
|
534 | - if ( |
|
535 | - $this->_use_mcrypt |
|
536 | - && strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false |
|
537 | - ){ |
|
538 | - return $this->m_decrypt($encrypted_text); |
|
539 | - } |
|
540 | - $encrypted_text = substr($encrypted_text, 0, -4); |
|
541 | - $key_bits = str_split( |
|
542 | - str_pad( |
|
543 | - '', |
|
544 | - strlen($encrypted_text), |
|
545 | - $this->get_encryption_key(), |
|
546 | - STR_PAD_RIGHT |
|
547 | - ) |
|
548 | - ); |
|
549 | - $string_bits = str_split($encrypted_text); |
|
550 | - foreach ($string_bits as $k => $v) { |
|
551 | - $temp = ord($v) - ord($key_bits[$k]); |
|
552 | - $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
553 | - } |
|
554 | - return implode('', $string_bits); |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
561 | - * @param $string |
|
562 | - * @return bool |
|
563 | - */ |
|
564 | - protected function valid_base_64($string) |
|
565 | - { |
|
566 | - // ensure data is a string |
|
567 | - if (! is_string($string) || ! $this->_use_base64_encode) { |
|
568 | - return false; |
|
569 | - } |
|
570 | - $decoded = base64_decode($string, true); |
|
571 | - // Check if there is no invalid character in string |
|
572 | - if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
573 | - return false; |
|
574 | - } |
|
575 | - // Decode the string in strict mode and send the response |
|
576 | - if (! base64_decode($string, true)) { |
|
577 | - return false; |
|
578 | - } |
|
579 | - // Encode and compare it to original one |
|
580 | - return base64_encode($decoded) === $string; |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * generate random string |
|
587 | - * |
|
588 | - * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
589 | - * @param int $length number of characters for random string |
|
590 | - * @return string |
|
591 | - */ |
|
592 | - public function generate_random_string($length = 40) |
|
593 | - { |
|
594 | - $iterations = ceil($length / 40); |
|
595 | - $random_string = ''; |
|
596 | - for ($i = 0; $i < $iterations; $i++) { |
|
597 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
598 | - } |
|
599 | - $random_string = substr($random_string, 0, $length); |
|
600 | - return $random_string; |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - |
|
605 | - /** |
|
606 | - * encrypts data using PHP's mcrypt functions |
|
607 | - * |
|
608 | - * @deprecated 4.9.39 |
|
609 | - * @param string $text_string |
|
610 | - * @internal param $string - the text to be encrypted |
|
611 | - * @return string |
|
612 | - * @throws RuntimeException |
|
613 | - */ |
|
614 | - protected function m_encrypt($text_string = '') |
|
615 | - { |
|
616 | - // you give me nothing??? GET OUT ! |
|
617 | - if (empty($text_string)) { |
|
618 | - return $text_string; |
|
619 | - } |
|
620 | - // get the initialization vector size |
|
621 | - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
622 | - // initialization vector |
|
623 | - $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
624 | - if ($iv === false) { |
|
625 | - throw new RuntimeException( |
|
626 | - esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
627 | - ); |
|
628 | - } |
|
629 | - // encrypt it |
|
630 | - $encrypted_text = mcrypt_encrypt( |
|
631 | - MCRYPT_RIJNDAEL_256, |
|
632 | - $this->get_encryption_key(), |
|
633 | - $text_string, |
|
634 | - MCRYPT_MODE_ECB, |
|
635 | - $iv |
|
636 | - ); |
|
637 | - // trim and maybe encode |
|
638 | - return $this->_use_base64_encode |
|
639 | - ? trim(base64_encode($encrypted_text)) |
|
640 | - : trim($encrypted_text); |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - |
|
645 | - /** |
|
646 | - * decrypts data that has been encrypted with PHP's mcrypt functions |
|
647 | - * |
|
648 | - * @deprecated 4.9.39 |
|
649 | - * @param string $encrypted_text the text to be decrypted |
|
650 | - * @return string |
|
651 | - * @throws RuntimeException |
|
652 | - */ |
|
653 | - protected function m_decrypt($encrypted_text = '') |
|
654 | - { |
|
655 | - // you give me nothing??? GET OUT ! |
|
656 | - if (empty($encrypted_text)) { |
|
657 | - return $encrypted_text; |
|
658 | - } |
|
659 | - // decode |
|
660 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
661 | - ? base64_decode($encrypted_text) |
|
662 | - : $encrypted_text; |
|
663 | - // get the initialization vector size |
|
664 | - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
665 | - $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
666 | - if ($iv === false) { |
|
667 | - throw new RuntimeException( |
|
668 | - esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
669 | - ); |
|
670 | - } |
|
671 | - // decrypt it |
|
672 | - $decrypted_text = mcrypt_decrypt( |
|
673 | - MCRYPT_RIJNDAEL_256, |
|
674 | - $this->get_encryption_key(), |
|
675 | - $encrypted_text, |
|
676 | - MCRYPT_MODE_ECB, |
|
677 | - $iv |
|
678 | - ); |
|
679 | - $decrypted_text = trim($decrypted_text); |
|
680 | - return $decrypted_text; |
|
681 | - } |
|
19 | + /** |
|
20 | + * key used for saving the encryption key to the wp_options table |
|
21 | + */ |
|
22 | + const ENCRYPTION_OPTION_KEY = 'ee_encryption_key'; |
|
23 | + |
|
24 | + /** |
|
25 | + * the OPENSSL cipher method used |
|
26 | + */ |
|
27 | + const OPENSSL_CIPHER_METHOD = 'AES-128-CBC'; |
|
28 | + |
|
29 | + /** |
|
30 | + * WP "options_name" used to store a verified available cipher method |
|
31 | + */ |
|
32 | + const OPENSSL_CIPHER_METHOD_OPTION_NAME = 'ee_openssl_cipher_method'; |
|
33 | + |
|
34 | + /** |
|
35 | + * the OPENSSL digest method used |
|
36 | + */ |
|
37 | + const OPENSSL_DIGEST_METHOD = 'sha512'; |
|
38 | + |
|
39 | + /** |
|
40 | + * separates the encrypted text from the initialization vector |
|
41 | + */ |
|
42 | + const OPENSSL_IV_DELIMITER = ':iv:'; |
|
43 | + |
|
44 | + /** |
|
45 | + * appended to text encrypted using the acme encryption |
|
46 | + */ |
|
47 | + const ACME_ENCRYPTION_FLAG = '::ae'; |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * instance of the EE_Encryption object |
|
53 | + */ |
|
54 | + protected static $_instance; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var string $_encryption_key |
|
58 | + */ |
|
59 | + protected $_encryption_key; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var string $cipher_method |
|
63 | + */ |
|
64 | + private $cipher_method = ''; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var array $cipher_methods |
|
68 | + */ |
|
69 | + private $cipher_methods = array(); |
|
70 | + |
|
71 | + /** |
|
72 | + * @var array $digest_methods |
|
73 | + */ |
|
74 | + private $digest_methods = array(); |
|
75 | + |
|
76 | + /** |
|
77 | + * @var boolean $_use_openssl_encrypt |
|
78 | + */ |
|
79 | + protected $_use_openssl_encrypt = false; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var boolean $_use_mcrypt |
|
83 | + */ |
|
84 | + protected $_use_mcrypt = false; |
|
85 | + |
|
86 | + /** |
|
87 | + * @var boolean $_use_base64_encode |
|
88 | + */ |
|
89 | + protected $_use_base64_encode = false; |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * protected constructor to prevent direct creation |
|
95 | + */ |
|
96 | + protected function __construct() |
|
97 | + { |
|
98 | + if (! defined('ESPRESSO_ENCRYPT')) { |
|
99 | + define('ESPRESSO_ENCRYPT', true); |
|
100 | + } |
|
101 | + if (extension_loaded('openssl')) { |
|
102 | + $this->_use_openssl_encrypt = true; |
|
103 | + } else if (extension_loaded('mcrypt')) { |
|
104 | + $this->_use_mcrypt = true; |
|
105 | + } |
|
106 | + if (function_exists('base64_encode')) { |
|
107 | + $this->_use_base64_encode = true; |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * singleton method used to instantiate class object |
|
115 | + * |
|
116 | + * @return EE_Encryption |
|
117 | + */ |
|
118 | + public static function instance() |
|
119 | + { |
|
120 | + // check if class object is instantiated |
|
121 | + if (! self::$_instance instanceof EE_Encryption) { |
|
122 | + self::$_instance = new self(); |
|
123 | + } |
|
124 | + return self::$_instance; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * get encryption key |
|
131 | + * |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function get_encryption_key() |
|
135 | + { |
|
136 | + // if encryption key has not been set |
|
137 | + if (empty($this->_encryption_key)) { |
|
138 | + // retrieve encryption_key from db |
|
139 | + $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, ''); |
|
140 | + // WHAT?? No encryption_key in the db ?? |
|
141 | + if ($this->_encryption_key === '') { |
|
142 | + // let's make one. And md5 it to make it just the right size for a key |
|
143 | + $new_key = md5($this->generate_random_string()); |
|
144 | + // now save it to the db for later |
|
145 | + add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key); |
|
146 | + // here's the key - FINALLY ! |
|
147 | + $this->_encryption_key = $new_key; |
|
148 | + } |
|
149 | + } |
|
150 | + return $this->_encryption_key; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * encrypts data |
|
157 | + * |
|
158 | + * @param string $text_string - the text to be encrypted |
|
159 | + * @return string |
|
160 | + * @throws RuntimeException |
|
161 | + */ |
|
162 | + public function encrypt($text_string = '') |
|
163 | + { |
|
164 | + // you give me nothing??? GET OUT ! |
|
165 | + if (empty($text_string)) { |
|
166 | + return $text_string; |
|
167 | + } |
|
168 | + if ($this->_use_openssl_encrypt) { |
|
169 | + $encrypted_text = $this->openssl_encrypt($text_string); |
|
170 | + } else { |
|
171 | + $encrypted_text = $this->acme_encrypt($text_string); |
|
172 | + } |
|
173 | + return $encrypted_text; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * decrypts data |
|
180 | + * |
|
181 | + * @param string $encrypted_text - the text to be decrypted |
|
182 | + * @return string |
|
183 | + * @throws RuntimeException |
|
184 | + */ |
|
185 | + public function decrypt($encrypted_text = '') |
|
186 | + { |
|
187 | + // you give me nothing??? GET OUT ! |
|
188 | + if (empty($encrypted_text)) { |
|
189 | + return $encrypted_text; |
|
190 | + } |
|
191 | + // if PHP's mcrypt functions are installed then we'll use them |
|
192 | + if ($this->_use_openssl_encrypt) { |
|
193 | + $decrypted_text = $this->openssl_decrypt($encrypted_text); |
|
194 | + } else { |
|
195 | + $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
196 | + } |
|
197 | + return $decrypted_text; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * encodes string with PHP's base64 encoding |
|
204 | + * |
|
205 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
206 | + * @param string $text_string the text to be encoded |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + public function base64_string_encode($text_string = '') |
|
210 | + { |
|
211 | + // you give me nothing??? GET OUT ! |
|
212 | + if (empty($text_string) || ! $this->_use_base64_encode) { |
|
213 | + return $text_string; |
|
214 | + } |
|
215 | + // encode |
|
216 | + return base64_encode($text_string); |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * decodes string that has been encoded with PHP's base64 encoding |
|
223 | + * |
|
224 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
225 | + * @param string $encoded_string the text to be decoded |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public function base64_string_decode($encoded_string = '') |
|
229 | + { |
|
230 | + // you give me nothing??? GET OUT ! |
|
231 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
232 | + return $encoded_string; |
|
233 | + } |
|
234 | + // decode |
|
235 | + return base64_decode($encoded_string); |
|
236 | + } |
|
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 | + /** |
|
262 | + * decodes url string that has been encoded with PHP's base64 encoding |
|
263 | + * |
|
264 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
265 | + * @param string $encoded_string the text to be decoded |
|
266 | + * @return string |
|
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 | + return base64_decode($encoded_string); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * encrypts data using PHP's openssl functions |
|
284 | + * |
|
285 | + * @param string $text_string the text to be encrypted |
|
286 | + * @return string |
|
287 | + * @throws RuntimeException |
|
288 | + */ |
|
289 | + protected function openssl_encrypt($text_string = '') |
|
290 | + { |
|
291 | + // you give me nothing??? GET OUT ! |
|
292 | + if (empty($text_string)) { |
|
293 | + return $text_string; |
|
294 | + } |
|
295 | + $this->cipher_method = $this->getCipherMethod(); |
|
296 | + // get initialization vector size |
|
297 | + $iv_size = openssl_cipher_iv_length($this->cipher_method); |
|
298 | + // generate initialization vector. |
|
299 | + // The second parameter ("crypto_strong") is passed by reference, |
|
300 | + // and is used to determines if the algorithm used was "cryptographically strong" |
|
301 | + // openssl_random_pseudo_bytes() will toggle it to either true or false |
|
302 | + $iv = openssl_random_pseudo_bytes($iv_size, $is_strong); |
|
303 | + if ($iv === false || $is_strong === false) { |
|
304 | + throw new RuntimeException( |
|
305 | + esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso') |
|
306 | + ); |
|
307 | + } |
|
308 | + // encrypt it |
|
309 | + $encrypted_text = openssl_encrypt( |
|
310 | + $text_string, |
|
311 | + $this->cipher_method, |
|
312 | + $this->getDigestHashValue(), |
|
313 | + 0, |
|
314 | + $iv |
|
315 | + ); |
|
316 | + // append the initialization vector |
|
317 | + $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
318 | + // trim and maybe encode |
|
319 | + return $this->_use_base64_encode |
|
320 | + ? trim(base64_encode($encrypted_text)) |
|
321 | + : trim($encrypted_text); |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * Returns a cipher method that has been verified to work. |
|
328 | + * First checks if the cached cipher has been set already and if so, returns that. |
|
329 | + * Then tests the incoming default and returns that if it's good. |
|
330 | + * If not, then it retrieves the previously tested and saved cipher method. |
|
331 | + * But if that doesn't exist, then calls getAvailableCipherMethod() |
|
332 | + * to see what is available on the server, and returns the results. |
|
333 | + * |
|
334 | + * @param string $cipher_method |
|
335 | + * @return string |
|
336 | + * @throws RuntimeException |
|
337 | + */ |
|
338 | + protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD) |
|
339 | + { |
|
340 | + if($this->cipher_method !== ''){ |
|
341 | + return $this->cipher_method; |
|
342 | + } |
|
343 | + // verify that the default cipher method can produce an initialization vector |
|
344 | + if (openssl_cipher_iv_length($cipher_method) === false) { |
|
345 | + // nope? okay let's get what we found in the past to work |
|
346 | + $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, ''); |
|
347 | + // oops... haven't tested available cipher methods yet |
|
348 | + if($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) { |
|
349 | + $cipher_method = $this->getAvailableCipherMethod($cipher_method); |
|
350 | + } |
|
351 | + } |
|
352 | + return $cipher_method; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * @param string $cipher_method |
|
359 | + * @return string |
|
360 | + * @throws \RuntimeException |
|
361 | + */ |
|
362 | + protected function getAvailableCipherMethod($cipher_method) |
|
363 | + { |
|
364 | + // verify that the incoming cipher method can produce an initialization vector |
|
365 | + if (openssl_cipher_iv_length($cipher_method) === false) { |
|
366 | + // nope? then check the next cipher in the list of available cipher methods |
|
367 | + $cipher_method = next($this->cipher_methods); |
|
368 | + // what? there's no list? then generate that list and cache it, |
|
369 | + if (empty($this->cipher_methods)) { |
|
370 | + $this->cipher_methods = openssl_get_cipher_methods(); |
|
371 | + // then grab the first item from the list |
|
372 | + $cipher_method = reset($this->cipher_methods); |
|
373 | + } |
|
374 | + if($cipher_method === false){ |
|
375 | + throw new RuntimeException( |
|
376 | + esc_html__( |
|
377 | + 'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.', |
|
378 | + 'event_espresso' |
|
379 | + ) |
|
380 | + ); |
|
381 | + } |
|
382 | + // verify that the next cipher method works |
|
383 | + return $this->getAvailableCipherMethod($cipher_method); |
|
384 | + } |
|
385 | + // if we've gotten this far, then we found an available cipher method that works |
|
386 | + // so save that for next time |
|
387 | + update_option( |
|
388 | + EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, |
|
389 | + $cipher_method |
|
390 | + ); |
|
391 | + return $cipher_method; |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * decrypts data that has been encrypted with PHP's openssl functions |
|
398 | + * |
|
399 | + * @param string $encrypted_text the text to be decrypted |
|
400 | + * @return string |
|
401 | + * @throws RuntimeException |
|
402 | + */ |
|
403 | + protected function openssl_decrypt($encrypted_text = '') |
|
404 | + { |
|
405 | + // you give me nothing??? GET OUT ! |
|
406 | + if (empty($encrypted_text)) { |
|
407 | + return $encrypted_text; |
|
408 | + } |
|
409 | + // decode |
|
410 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
411 | + ? base64_decode($encrypted_text) |
|
412 | + : $encrypted_text; |
|
413 | + $encrypted_components = explode( |
|
414 | + EE_Encryption::OPENSSL_IV_DELIMITER, |
|
415 | + $encrypted_text, |
|
416 | + 2 |
|
417 | + ); |
|
418 | + // check that iv exists, and if not, maybe text was encoded using mcrypt? |
|
419 | + if ($this->_use_mcrypt && ! isset($encrypted_components[1])) { |
|
420 | + return $this->m_decrypt($encrypted_text); |
|
421 | + } |
|
422 | + // decrypt it |
|
423 | + $decrypted_text = openssl_decrypt( |
|
424 | + $encrypted_components[0], |
|
425 | + $this->getCipherMethod(), |
|
426 | + $this->getDigestHashValue(), |
|
427 | + 0, |
|
428 | + $encrypted_components[1] |
|
429 | + ); |
|
430 | + $decrypted_text = trim($decrypted_text); |
|
431 | + return $decrypted_text; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Computes the digest hash value using the specified digest method. |
|
438 | + * If that digest method fails to produce a valid hash value, |
|
439 | + * then we'll grab the next digest method and recursively try again until something works. |
|
440 | + * |
|
441 | + * @param string $digest_method |
|
442 | + * @return string |
|
443 | + * @throws RuntimeException |
|
444 | + */ |
|
445 | + protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD){ |
|
446 | + $digest_hash_value = openssl_digest($this->get_encryption_key(), $digest_method); |
|
447 | + if ($digest_hash_value === false) { |
|
448 | + return $this->getDigestHashValue($this->getDigestMethod()); |
|
449 | + } |
|
450 | + return $digest_hash_value; |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * Returns the NEXT element in the $digest_methods array. |
|
457 | + * If the $digest_methods array is empty, then we populate it |
|
458 | + * with the available values returned from openssl_get_md_methods(). |
|
459 | + * |
|
460 | + * @return string |
|
461 | + * @throws \RuntimeException |
|
462 | + */ |
|
463 | + protected function getDigestMethod(){ |
|
464 | + $digest_method = prev($this->digest_methods); |
|
465 | + if (empty($this->digest_methods)) { |
|
466 | + $this->digest_methods = openssl_get_md_methods(); |
|
467 | + $digest_method = end($this->digest_methods); |
|
468 | + } |
|
469 | + if ($digest_method === false) { |
|
470 | + throw new RuntimeException( |
|
471 | + esc_html__( |
|
472 | + 'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.', |
|
473 | + 'event_espresso' |
|
474 | + ) |
|
475 | + ); |
|
476 | + } |
|
477 | + return $digest_method; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
483 | + * |
|
484 | + * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
485 | + * @param string $text_string the text to be decrypted |
|
486 | + * @return string |
|
487 | + */ |
|
488 | + protected function acme_encrypt($text_string = '') |
|
489 | + { |
|
490 | + // you give me nothing??? GET OUT ! |
|
491 | + if (empty($text_string)) { |
|
492 | + return $text_string; |
|
493 | + } |
|
494 | + $key_bits = str_split( |
|
495 | + str_pad( |
|
496 | + '', |
|
497 | + strlen($text_string), |
|
498 | + $this->get_encryption_key(), |
|
499 | + STR_PAD_RIGHT |
|
500 | + ) |
|
501 | + ); |
|
502 | + $string_bits = str_split($text_string); |
|
503 | + foreach ($string_bits as $k => $v) { |
|
504 | + $temp = ord($v) + ord($key_bits[$k]); |
|
505 | + $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
506 | + } |
|
507 | + $encrypted_text = implode('', $string_bits); |
|
508 | + $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
|
509 | + return $this->_use_base64_encode |
|
510 | + ? base64_encode($encrypted_text) |
|
511 | + : $encrypted_text; |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
518 | + * |
|
519 | + * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
520 | + * @param string $encrypted_text the text to be decrypted |
|
521 | + * @return string |
|
522 | + * @throws RuntimeException |
|
523 | + */ |
|
524 | + protected function acme_decrypt($encrypted_text = '') |
|
525 | + { |
|
526 | + // you give me nothing??? GET OUT ! |
|
527 | + if (empty($encrypted_text)) { |
|
528 | + return $encrypted_text; |
|
529 | + } |
|
530 | + // decode the data ? |
|
531 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
532 | + ? base64_decode($encrypted_text) |
|
533 | + : $encrypted_text; |
|
534 | + if ( |
|
535 | + $this->_use_mcrypt |
|
536 | + && strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false |
|
537 | + ){ |
|
538 | + return $this->m_decrypt($encrypted_text); |
|
539 | + } |
|
540 | + $encrypted_text = substr($encrypted_text, 0, -4); |
|
541 | + $key_bits = str_split( |
|
542 | + str_pad( |
|
543 | + '', |
|
544 | + strlen($encrypted_text), |
|
545 | + $this->get_encryption_key(), |
|
546 | + STR_PAD_RIGHT |
|
547 | + ) |
|
548 | + ); |
|
549 | + $string_bits = str_split($encrypted_text); |
|
550 | + foreach ($string_bits as $k => $v) { |
|
551 | + $temp = ord($v) - ord($key_bits[$k]); |
|
552 | + $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
553 | + } |
|
554 | + return implode('', $string_bits); |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
561 | + * @param $string |
|
562 | + * @return bool |
|
563 | + */ |
|
564 | + protected function valid_base_64($string) |
|
565 | + { |
|
566 | + // ensure data is a string |
|
567 | + if (! is_string($string) || ! $this->_use_base64_encode) { |
|
568 | + return false; |
|
569 | + } |
|
570 | + $decoded = base64_decode($string, true); |
|
571 | + // Check if there is no invalid character in string |
|
572 | + if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
573 | + return false; |
|
574 | + } |
|
575 | + // Decode the string in strict mode and send the response |
|
576 | + if (! base64_decode($string, true)) { |
|
577 | + return false; |
|
578 | + } |
|
579 | + // Encode and compare it to original one |
|
580 | + return base64_encode($decoded) === $string; |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * generate random string |
|
587 | + * |
|
588 | + * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
589 | + * @param int $length number of characters for random string |
|
590 | + * @return string |
|
591 | + */ |
|
592 | + public function generate_random_string($length = 40) |
|
593 | + { |
|
594 | + $iterations = ceil($length / 40); |
|
595 | + $random_string = ''; |
|
596 | + for ($i = 0; $i < $iterations; $i++) { |
|
597 | + $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
598 | + } |
|
599 | + $random_string = substr($random_string, 0, $length); |
|
600 | + return $random_string; |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + |
|
605 | + /** |
|
606 | + * encrypts data using PHP's mcrypt functions |
|
607 | + * |
|
608 | + * @deprecated 4.9.39 |
|
609 | + * @param string $text_string |
|
610 | + * @internal param $string - the text to be encrypted |
|
611 | + * @return string |
|
612 | + * @throws RuntimeException |
|
613 | + */ |
|
614 | + protected function m_encrypt($text_string = '') |
|
615 | + { |
|
616 | + // you give me nothing??? GET OUT ! |
|
617 | + if (empty($text_string)) { |
|
618 | + return $text_string; |
|
619 | + } |
|
620 | + // get the initialization vector size |
|
621 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
622 | + // initialization vector |
|
623 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
624 | + if ($iv === false) { |
|
625 | + throw new RuntimeException( |
|
626 | + esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
627 | + ); |
|
628 | + } |
|
629 | + // encrypt it |
|
630 | + $encrypted_text = mcrypt_encrypt( |
|
631 | + MCRYPT_RIJNDAEL_256, |
|
632 | + $this->get_encryption_key(), |
|
633 | + $text_string, |
|
634 | + MCRYPT_MODE_ECB, |
|
635 | + $iv |
|
636 | + ); |
|
637 | + // trim and maybe encode |
|
638 | + return $this->_use_base64_encode |
|
639 | + ? trim(base64_encode($encrypted_text)) |
|
640 | + : trim($encrypted_text); |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + |
|
645 | + /** |
|
646 | + * decrypts data that has been encrypted with PHP's mcrypt functions |
|
647 | + * |
|
648 | + * @deprecated 4.9.39 |
|
649 | + * @param string $encrypted_text the text to be decrypted |
|
650 | + * @return string |
|
651 | + * @throws RuntimeException |
|
652 | + */ |
|
653 | + protected function m_decrypt($encrypted_text = '') |
|
654 | + { |
|
655 | + // you give me nothing??? GET OUT ! |
|
656 | + if (empty($encrypted_text)) { |
|
657 | + return $encrypted_text; |
|
658 | + } |
|
659 | + // decode |
|
660 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
661 | + ? base64_decode($encrypted_text) |
|
662 | + : $encrypted_text; |
|
663 | + // get the initialization vector size |
|
664 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
665 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
666 | + if ($iv === false) { |
|
667 | + throw new RuntimeException( |
|
668 | + esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
669 | + ); |
|
670 | + } |
|
671 | + // decrypt it |
|
672 | + $decrypted_text = mcrypt_decrypt( |
|
673 | + MCRYPT_RIJNDAEL_256, |
|
674 | + $this->get_encryption_key(), |
|
675 | + $encrypted_text, |
|
676 | + MCRYPT_MODE_ECB, |
|
677 | + $iv |
|
678 | + ); |
|
679 | + $decrypted_text = trim($decrypted_text); |
|
680 | + return $decrypted_text; |
|
681 | + } |
|
682 | 682 | |
683 | 683 | } |
684 | 684 | /* End of file EE_Encryption.class.php */ |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | protected function __construct() |
97 | 97 | { |
98 | - if (! defined('ESPRESSO_ENCRYPT')) { |
|
98 | + if ( ! defined('ESPRESSO_ENCRYPT')) { |
|
99 | 99 | define('ESPRESSO_ENCRYPT', true); |
100 | 100 | } |
101 | 101 | if (extension_loaded('openssl')) { |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | public static function instance() |
119 | 119 | { |
120 | 120 | // check if class object is instantiated |
121 | - if (! self::$_instance instanceof EE_Encryption) { |
|
121 | + if ( ! self::$_instance instanceof EE_Encryption) { |
|
122 | 122 | self::$_instance = new self(); |
123 | 123 | } |
124 | 124 | return self::$_instance; |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | $iv |
315 | 315 | ); |
316 | 316 | // append the initialization vector |
317 | - $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
317 | + $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER.$iv; |
|
318 | 318 | // trim and maybe encode |
319 | 319 | return $this->_use_base64_encode |
320 | 320 | ? trim(base64_encode($encrypted_text)) |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | */ |
338 | 338 | protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD) |
339 | 339 | { |
340 | - if($this->cipher_method !== ''){ |
|
340 | + if ($this->cipher_method !== '') { |
|
341 | 341 | return $this->cipher_method; |
342 | 342 | } |
343 | 343 | // verify that the default cipher method can produce an initialization vector |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | // nope? okay let's get what we found in the past to work |
346 | 346 | $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, ''); |
347 | 347 | // oops... haven't tested available cipher methods yet |
348 | - if($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) { |
|
348 | + if ($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) { |
|
349 | 349 | $cipher_method = $this->getAvailableCipherMethod($cipher_method); |
350 | 350 | } |
351 | 351 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | // then grab the first item from the list |
372 | 372 | $cipher_method = reset($this->cipher_methods); |
373 | 373 | } |
374 | - if($cipher_method === false){ |
|
374 | + if ($cipher_method === false) { |
|
375 | 375 | throw new RuntimeException( |
376 | 376 | esc_html__( |
377 | 377 | 'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.', |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | * @return string |
443 | 443 | * @throws RuntimeException |
444 | 444 | */ |
445 | - protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD){ |
|
445 | + protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD) { |
|
446 | 446 | $digest_hash_value = openssl_digest($this->get_encryption_key(), $digest_method); |
447 | 447 | if ($digest_hash_value === false) { |
448 | 448 | return $this->getDigestHashValue($this->getDigestMethod()); |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * @return string |
461 | 461 | * @throws \RuntimeException |
462 | 462 | */ |
463 | - protected function getDigestMethod(){ |
|
463 | + protected function getDigestMethod() { |
|
464 | 464 | $digest_method = prev($this->digest_methods); |
465 | 465 | if (empty($this->digest_methods)) { |
466 | 466 | $this->digest_methods = openssl_get_md_methods(); |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | if ( |
535 | 535 | $this->_use_mcrypt |
536 | 536 | && strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false |
537 | - ){ |
|
537 | + ) { |
|
538 | 538 | return $this->m_decrypt($encrypted_text); |
539 | 539 | } |
540 | 540 | $encrypted_text = substr($encrypted_text, 0, -4); |
@@ -564,16 +564,16 @@ discard block |
||
564 | 564 | protected function valid_base_64($string) |
565 | 565 | { |
566 | 566 | // ensure data is a string |
567 | - if (! is_string($string) || ! $this->_use_base64_encode) { |
|
567 | + if ( ! is_string($string) || ! $this->_use_base64_encode) { |
|
568 | 568 | return false; |
569 | 569 | } |
570 | 570 | $decoded = base64_decode($string, true); |
571 | 571 | // Check if there is no invalid character in string |
572 | - if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
572 | + if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
573 | 573 | return false; |
574 | 574 | } |
575 | 575 | // Decode the string in strict mode and send the response |
576 | - if (! base64_decode($string, true)) { |
|
576 | + if ( ! base64_decode($string, true)) { |
|
577 | 577 | return false; |
578 | 578 | } |
579 | 579 | // Encode and compare it to original one |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | $iterations = ceil($length / 40); |
595 | 595 | $random_string = ''; |
596 | 596 | for ($i = 0; $i < $iterations; $i++) { |
597 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
597 | + $random_string .= sha1(microtime(true).mt_rand(10000, 90000)); |
|
598 | 598 | } |
599 | 599 | $random_string = substr($random_string, 0, $length); |
600 | 600 | return $random_string; |
@@ -409,7 +409,7 @@ |
||
409 | 409 | * This provides a count of events using this custom template |
410 | 410 | * |
411 | 411 | * @param EE_Message_Template_Group $item message_template group data |
412 | - * @return string column output |
|
412 | + * @return integer column output |
|
413 | 413 | */ |
414 | 414 | function column_events($item) |
415 | 415 | { |
@@ -12,481 +12,481 @@ |
||
12 | 12 | class Custom_Messages_Template_List_Table extends EE_Admin_List_Table |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Custom_Messages_Template_List_Table constructor. |
|
17 | - * |
|
18 | - * @param EE_Admin_Page $admin_page |
|
19 | - */ |
|
20 | - public function __construct($admin_page) |
|
21 | - { |
|
22 | - //Set parent defaults |
|
23 | - parent::__construct($admin_page); |
|
24 | - } |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @return Messages_Admin_Page |
|
29 | - */ |
|
30 | - public function get_admin_page() |
|
31 | - { |
|
32 | - return $this->_admin_page; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Setup initial data. |
|
37 | - */ |
|
38 | - protected function _setup_data() |
|
39 | - { |
|
40 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
41 | - $this->_per_page, |
|
42 | - $this->_view, |
|
43 | - false, |
|
44 | - false, |
|
45 | - false |
|
46 | - ); |
|
47 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
48 | - $this->_per_page, |
|
49 | - $this->_view, |
|
50 | - true, |
|
51 | - true, |
|
52 | - false |
|
53 | - ); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Set initial properties |
|
59 | - */ |
|
60 | - protected function _set_properties() |
|
61 | - { |
|
62 | - $this->_wp_list_args = array( |
|
63 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
64 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
65 | - 'ajax' => true, //for now, |
|
66 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
67 | - ); |
|
68 | - |
|
69 | - $this->_columns = array( |
|
70 | - 'cb' => '<input type="checkbox" />', |
|
71 | - 'name' => esc_html__('Template Name', 'event_espresso'), |
|
72 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
73 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
74 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
75 | - 'events' => esc_html__('Events', 'event_espresso'), |
|
76 | - //count of events using this template. |
|
77 | - 'actions' => '' |
|
78 | - ); |
|
79 | - |
|
80 | - $this->_sortable_columns = array( |
|
81 | - 'messenger' => array('MTP_messenger' => true), |
|
82 | - ); |
|
83 | - |
|
84 | - $this->_hidden_columns = array(); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
90 | - * message_type or messenger object before generating the row. |
|
91 | - * |
|
92 | - * @param EE_Message_Template_Group $item |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function single_row($item) |
|
96 | - { |
|
97 | - $message_type = $item->message_type_obj(); |
|
98 | - $messenger = $item->messenger_obj(); |
|
99 | - |
|
100 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
101 | - echo ''; |
|
102 | - return; |
|
103 | - } |
|
104 | - |
|
105 | - parent::single_row($item); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - protected function _get_table_filters() |
|
113 | - { |
|
114 | - $filters = array(); |
|
115 | - |
|
116 | - //get select inputs |
|
117 | - $select_inputs = array( |
|
118 | - $this->_get_messengers_dropdown_filter(), |
|
119 | - $this->_get_message_types_dropdown_filter(), |
|
120 | - ); |
|
121 | - |
|
122 | - //set filters to select inputs if they aren't empty |
|
123 | - foreach ($select_inputs as $select_input) { |
|
124 | - if ($select_input) { |
|
125 | - $filters[] = $select_input; |
|
126 | - } |
|
127 | - } |
|
128 | - return $filters; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * we're just removing the search box for message templates, not needed. |
|
133 | - * |
|
134 | - * @return string (empty); |
|
135 | - */ |
|
136 | - function search_box($text, $input_id) |
|
137 | - { |
|
138 | - return ''; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Set the view counts on the _views property |
|
144 | - */ |
|
145 | - protected function _add_view_counts() |
|
146 | - { |
|
147 | - foreach ($this->_views as $view => $args) { |
|
148 | - $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
149 | - $this->_per_page, |
|
150 | - $view, |
|
151 | - true, |
|
152 | - true, |
|
153 | - false |
|
154 | - ); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Custom message for when there are no items found. |
|
161 | - * |
|
162 | - * @since 4.3.0 |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public function no_items() |
|
166 | - { |
|
167 | - if ($this->_view !== 'trashed') { |
|
168 | - printf( |
|
169 | - esc_html__( |
|
170 | - '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
171 | - 'event_espresso' |
|
172 | - ), |
|
173 | - '<strong>', |
|
174 | - '</strong>' |
|
175 | - ); |
|
176 | - } else { |
|
177 | - parent::no_items(); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param EE_Message_Template_Group $item |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - public function column_cb($item) |
|
187 | - { |
|
188 | - return sprintf('<input type="checkbox" name="checkbox[%s] value="1" />', $item->GRP_ID()); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * @param EE_Message_Template_Group $item |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - function column_name($item) |
|
197 | - { |
|
198 | - return '<p>' . $item->name() . '</p>'; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param EE_Message_Template_Group $item |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - function column_description($item) |
|
207 | - { |
|
208 | - return '<p>' . $item->description() . '</p>'; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @param EE_Message_Template_Group $item |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - function column_actions($item) |
|
217 | - { |
|
218 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
219 | - 'ee_edit_messages', |
|
220 | - 'espresso_messages_add_new_message_template' |
|
221 | - )) { |
|
222 | - $create_args = array( |
|
223 | - 'GRP_ID' => $item->ID(), |
|
224 | - 'messenger' => $item->messenger(), |
|
225 | - 'message_type' => $item->message_type(), |
|
226 | - 'action' => 'add_new_message_template', |
|
227 | - ); |
|
228 | - $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
229 | - return sprintf( |
|
230 | - '<p><a href="%s" class="button button-small">%s</a></p>', |
|
231 | - $create_link, |
|
232 | - esc_html__('Create Custom', 'event_espresso') |
|
233 | - ); |
|
234 | - } |
|
235 | - return ''; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Return the content for the messenger column |
|
241 | - * @param EE_Message_Template_Group $item |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - function column_messenger($item) |
|
245 | - { |
|
246 | - |
|
247 | - //Build row actions |
|
248 | - $actions = array(); |
|
249 | - $edit_lnk_url = ''; |
|
250 | - |
|
251 | - // edit link but only if item isn't trashed. |
|
252 | - if (! $item->get('MTP_deleted') |
|
253 | - && EE_Registry::instance()->CAP->current_user_can( |
|
254 | - 'ee_edit_message', |
|
255 | - 'espresso_messages_edit_message_template', |
|
256 | - $item->ID() |
|
257 | - ) |
|
258 | - ) { |
|
259 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
260 | - 'action' => 'edit_message_template', |
|
261 | - 'id' => $item->GRP_ID(), |
|
262 | - ), EE_MSG_ADMIN_URL); |
|
263 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
264 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
265 | - . ' title="' |
|
266 | - . esc_attr__('Edit Template', 'event_espresso') |
|
267 | - . '">' |
|
268 | - . esc_html__('Edit', 'event_espresso') |
|
269 | - . '</a>'; |
|
270 | - } |
|
271 | - |
|
272 | - $name_link = ! $item->get('MTP_deleted') |
|
273 | - && EE_Registry::instance()->CAP->current_user_can( |
|
274 | - 'ee_edit_message', |
|
275 | - 'espresso_messages_edit_message_template', |
|
276 | - $item->ID() |
|
277 | - ) |
|
278 | - && $edit_lnk_url |
|
279 | - ? '<a href="' |
|
280 | - . $edit_lnk_url |
|
281 | - . '" title="' |
|
282 | - . esc_attr__('Edit Template', 'event_espresso') |
|
283 | - . '">' |
|
284 | - . ucwords($item->messenger_obj()->label['singular']) |
|
285 | - . '</a>' |
|
286 | - : ucwords($item->messenger_obj()->label['singular']); |
|
287 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'trash_message_template', |
|
288 | - 'id' => $item->GRP_ID(), |
|
289 | - 'noheader' => true, |
|
290 | - ), EE_MSG_ADMIN_URL); |
|
291 | - // restore link |
|
292 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'restore_message_template', |
|
293 | - 'id' => $item->GRP_ID(), |
|
294 | - 'noheader' => true, |
|
295 | - ), EE_MSG_ADMIN_URL); |
|
296 | - // delete price link |
|
297 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_message_template', |
|
298 | - 'id' => $item->GRP_ID(), |
|
299 | - 'noheader' => true, |
|
300 | - ), EE_MSG_ADMIN_URL); |
|
301 | - |
|
302 | - if (! $item->get('MTP_deleted') |
|
303 | - && EE_Registry::instance()->CAP->current_user_can( |
|
304 | - 'ee_delete_message', |
|
305 | - 'espresso_messages_trash_message_template', |
|
306 | - $item->ID() |
|
307 | - ) |
|
308 | - ) { |
|
309 | - $actions['trash'] = '<a href="' |
|
310 | - . $trash_lnk_url |
|
311 | - . '" title="' |
|
312 | - . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
313 | - . '">' |
|
314 | - . esc_html__('Move to Trash', 'event_espresso') |
|
315 | - . '</a>'; |
|
316 | - } else { |
|
317 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
318 | - 'ee_delete_message', |
|
319 | - 'espresso_messages_restore_message_template', |
|
320 | - $item->ID() |
|
321 | - )) { |
|
322 | - $actions['restore'] = '<a href="' |
|
323 | - . $restore_lnk_url |
|
324 | - . '" title="' |
|
325 | - . esc_attr__('Restore Message Template', 'event_espresso') |
|
326 | - . '">' |
|
327 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
328 | - } |
|
329 | - |
|
330 | - if ($this->_view == 'trashed' |
|
331 | - && EE_Registry::instance()->CAP->current_user_can( |
|
332 | - 'ee_delete_message', |
|
333 | - 'espresso_messages_delete_message_template', |
|
334 | - $item->ID() |
|
335 | - )) { |
|
336 | - $actions['delete'] = '<a href="' |
|
337 | - . $delete_lnk_url |
|
338 | - . '" title="' |
|
339 | - . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
340 | - . '">' |
|
341 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
342 | - . '</a>'; |
|
343 | - } |
|
344 | - } |
|
345 | - |
|
346 | - //we want to display the contexts in here so we need to set them up |
|
347 | - $c_label = $item->context_label(); |
|
348 | - $c_configs = $item->contexts_config(); |
|
349 | - $ctxt = array(); |
|
350 | - $context_templates = $item->context_templates(); |
|
351 | - foreach ($context_templates as $context => $template_fields) { |
|
352 | - $mtp_to = ! empty($context_templates[$context]['to']) |
|
353 | - && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
354 | - ? $context_templates[$context]['to']->get('MTP_content') |
|
355 | - : null; |
|
356 | - $inactive = empty($mtp_to) && ! empty($context_templates[$context]['to']) |
|
357 | - ? ' class="mtp-inactive"' |
|
358 | - : ''; |
|
359 | - $context_title = ucwords($c_configs[$context]['label']); |
|
360 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_message_template', |
|
361 | - 'id' => $item->GRP_ID(), |
|
362 | - 'context' => $context, |
|
363 | - ), EE_MSG_ADMIN_URL); |
|
364 | - $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
365 | - 'ee_edit_message', |
|
366 | - 'espresso_messages_edit_message_template', |
|
367 | - $item->ID() |
|
368 | - ) |
|
369 | - ? '<a' |
|
370 | - . $inactive |
|
371 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
372 | - . ' href="' . $edit_link . '"' |
|
373 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
374 | - . $context_title |
|
375 | - . '</a>' |
|
376 | - : $context_title; |
|
377 | - } |
|
378 | - |
|
379 | - $ctx_content = ! $item->get('MTP_deleted') |
|
380 | - && EE_Registry::instance()->CAP->current_user_can( |
|
381 | - 'ee_edit_message', |
|
382 | - 'espresso_messages_edit_message_template', |
|
383 | - $item->ID() |
|
384 | - ) |
|
385 | - ? sprintf( |
|
386 | - '<strong>%s:</strong> ', |
|
387 | - ucwords($c_label['plural']) |
|
388 | - ) |
|
389 | - . implode(' | ', $ctxt) |
|
390 | - : ''; |
|
391 | - |
|
392 | - |
|
393 | - //Return the name contents |
|
394 | - return sprintf( |
|
395 | - '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
396 | - /* $1%s */ |
|
397 | - $name_link, |
|
398 | - /* $2%s */ |
|
399 | - $item->GRP_ID(), |
|
400 | - /* %4$s */ |
|
401 | - $ctx_content, |
|
402 | - /* $3%s */ |
|
403 | - $this->row_actions($actions) |
|
404 | - ); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * column_events |
|
409 | - * This provides a count of events using this custom template |
|
410 | - * |
|
411 | - * @param EE_Message_Template_Group $item message_template group data |
|
412 | - * @return string column output |
|
413 | - */ |
|
414 | - function column_events($item) |
|
415 | - { |
|
416 | - return $item->count_events(); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * column_message_type |
|
421 | - * |
|
422 | - * @param EE_Message_Template_Group $item message info for the row |
|
423 | - * @return string message_type name |
|
424 | - */ |
|
425 | - function column_message_type($item) |
|
426 | - { |
|
427 | - return ucwords($item->message_type_obj()->label['singular']); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Generate dropdown filter select input for messengers |
|
433 | - * |
|
434 | - * @return string |
|
435 | - */ |
|
436 | - protected function _get_messengers_dropdown_filter() |
|
437 | - { |
|
438 | - $messenger_options = array(); |
|
439 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
440 | - array( |
|
441 | - array( |
|
442 | - 'MTP_is_active' => true, |
|
443 | - 'MTP_is_global' => false, |
|
444 | - ), |
|
445 | - 'group_by' => 'MTP_messenger', |
|
446 | - ) |
|
447 | - ); |
|
448 | - |
|
449 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
450 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
451 | - $messenger = $active_message_template_group->messenger_obj(); |
|
452 | - $messenger_label = $messenger instanceof EE_messenger |
|
453 | - ? $messenger->label['singular'] |
|
454 | - : $active_message_template_group->messenger(); |
|
455 | - $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
456 | - } |
|
457 | - } |
|
458 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * Generate dropdown filter select input for message types |
|
464 | - * |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - protected function _get_message_types_dropdown_filter() |
|
468 | - { |
|
469 | - $message_type_options = array(); |
|
470 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
471 | - array( |
|
472 | - array( |
|
473 | - 'MTP_is_active' => true, |
|
474 | - 'MTP_is_global' => false, |
|
475 | - ), |
|
476 | - 'group_by' => 'MTP_message_type', |
|
477 | - ) |
|
478 | - ); |
|
479 | - |
|
480 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
481 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
482 | - $message_type = $active_message_template_group->message_type_obj(); |
|
483 | - $message_type_label = $message_type instanceof EE_message_type |
|
484 | - ? $message_type->label['singular'] |
|
485 | - : $active_message_template_group->message_type(); |
|
486 | - $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
487 | - } |
|
488 | - } |
|
489 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
490 | - } |
|
15 | + /** |
|
16 | + * Custom_Messages_Template_List_Table constructor. |
|
17 | + * |
|
18 | + * @param EE_Admin_Page $admin_page |
|
19 | + */ |
|
20 | + public function __construct($admin_page) |
|
21 | + { |
|
22 | + //Set parent defaults |
|
23 | + parent::__construct($admin_page); |
|
24 | + } |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @return Messages_Admin_Page |
|
29 | + */ |
|
30 | + public function get_admin_page() |
|
31 | + { |
|
32 | + return $this->_admin_page; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Setup initial data. |
|
37 | + */ |
|
38 | + protected function _setup_data() |
|
39 | + { |
|
40 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
41 | + $this->_per_page, |
|
42 | + $this->_view, |
|
43 | + false, |
|
44 | + false, |
|
45 | + false |
|
46 | + ); |
|
47 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
48 | + $this->_per_page, |
|
49 | + $this->_view, |
|
50 | + true, |
|
51 | + true, |
|
52 | + false |
|
53 | + ); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Set initial properties |
|
59 | + */ |
|
60 | + protected function _set_properties() |
|
61 | + { |
|
62 | + $this->_wp_list_args = array( |
|
63 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
64 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
65 | + 'ajax' => true, //for now, |
|
66 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
67 | + ); |
|
68 | + |
|
69 | + $this->_columns = array( |
|
70 | + 'cb' => '<input type="checkbox" />', |
|
71 | + 'name' => esc_html__('Template Name', 'event_espresso'), |
|
72 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
73 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
74 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
75 | + 'events' => esc_html__('Events', 'event_espresso'), |
|
76 | + //count of events using this template. |
|
77 | + 'actions' => '' |
|
78 | + ); |
|
79 | + |
|
80 | + $this->_sortable_columns = array( |
|
81 | + 'messenger' => array('MTP_messenger' => true), |
|
82 | + ); |
|
83 | + |
|
84 | + $this->_hidden_columns = array(); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
90 | + * message_type or messenger object before generating the row. |
|
91 | + * |
|
92 | + * @param EE_Message_Template_Group $item |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function single_row($item) |
|
96 | + { |
|
97 | + $message_type = $item->message_type_obj(); |
|
98 | + $messenger = $item->messenger_obj(); |
|
99 | + |
|
100 | + if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
101 | + echo ''; |
|
102 | + return; |
|
103 | + } |
|
104 | + |
|
105 | + parent::single_row($item); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + protected function _get_table_filters() |
|
113 | + { |
|
114 | + $filters = array(); |
|
115 | + |
|
116 | + //get select inputs |
|
117 | + $select_inputs = array( |
|
118 | + $this->_get_messengers_dropdown_filter(), |
|
119 | + $this->_get_message_types_dropdown_filter(), |
|
120 | + ); |
|
121 | + |
|
122 | + //set filters to select inputs if they aren't empty |
|
123 | + foreach ($select_inputs as $select_input) { |
|
124 | + if ($select_input) { |
|
125 | + $filters[] = $select_input; |
|
126 | + } |
|
127 | + } |
|
128 | + return $filters; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * we're just removing the search box for message templates, not needed. |
|
133 | + * |
|
134 | + * @return string (empty); |
|
135 | + */ |
|
136 | + function search_box($text, $input_id) |
|
137 | + { |
|
138 | + return ''; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Set the view counts on the _views property |
|
144 | + */ |
|
145 | + protected function _add_view_counts() |
|
146 | + { |
|
147 | + foreach ($this->_views as $view => $args) { |
|
148 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
149 | + $this->_per_page, |
|
150 | + $view, |
|
151 | + true, |
|
152 | + true, |
|
153 | + false |
|
154 | + ); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Custom message for when there are no items found. |
|
161 | + * |
|
162 | + * @since 4.3.0 |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public function no_items() |
|
166 | + { |
|
167 | + if ($this->_view !== 'trashed') { |
|
168 | + printf( |
|
169 | + esc_html__( |
|
170 | + '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
171 | + 'event_espresso' |
|
172 | + ), |
|
173 | + '<strong>', |
|
174 | + '</strong>' |
|
175 | + ); |
|
176 | + } else { |
|
177 | + parent::no_items(); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param EE_Message_Template_Group $item |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + public function column_cb($item) |
|
187 | + { |
|
188 | + return sprintf('<input type="checkbox" name="checkbox[%s] value="1" />', $item->GRP_ID()); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * @param EE_Message_Template_Group $item |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + function column_name($item) |
|
197 | + { |
|
198 | + return '<p>' . $item->name() . '</p>'; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param EE_Message_Template_Group $item |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + function column_description($item) |
|
207 | + { |
|
208 | + return '<p>' . $item->description() . '</p>'; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @param EE_Message_Template_Group $item |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + function column_actions($item) |
|
217 | + { |
|
218 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
219 | + 'ee_edit_messages', |
|
220 | + 'espresso_messages_add_new_message_template' |
|
221 | + )) { |
|
222 | + $create_args = array( |
|
223 | + 'GRP_ID' => $item->ID(), |
|
224 | + 'messenger' => $item->messenger(), |
|
225 | + 'message_type' => $item->message_type(), |
|
226 | + 'action' => 'add_new_message_template', |
|
227 | + ); |
|
228 | + $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
229 | + return sprintf( |
|
230 | + '<p><a href="%s" class="button button-small">%s</a></p>', |
|
231 | + $create_link, |
|
232 | + esc_html__('Create Custom', 'event_espresso') |
|
233 | + ); |
|
234 | + } |
|
235 | + return ''; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Return the content for the messenger column |
|
241 | + * @param EE_Message_Template_Group $item |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + function column_messenger($item) |
|
245 | + { |
|
246 | + |
|
247 | + //Build row actions |
|
248 | + $actions = array(); |
|
249 | + $edit_lnk_url = ''; |
|
250 | + |
|
251 | + // edit link but only if item isn't trashed. |
|
252 | + if (! $item->get('MTP_deleted') |
|
253 | + && EE_Registry::instance()->CAP->current_user_can( |
|
254 | + 'ee_edit_message', |
|
255 | + 'espresso_messages_edit_message_template', |
|
256 | + $item->ID() |
|
257 | + ) |
|
258 | + ) { |
|
259 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
260 | + 'action' => 'edit_message_template', |
|
261 | + 'id' => $item->GRP_ID(), |
|
262 | + ), EE_MSG_ADMIN_URL); |
|
263 | + $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
264 | + . ' class="' . $item->message_type() . '-edit-link"' |
|
265 | + . ' title="' |
|
266 | + . esc_attr__('Edit Template', 'event_espresso') |
|
267 | + . '">' |
|
268 | + . esc_html__('Edit', 'event_espresso') |
|
269 | + . '</a>'; |
|
270 | + } |
|
271 | + |
|
272 | + $name_link = ! $item->get('MTP_deleted') |
|
273 | + && EE_Registry::instance()->CAP->current_user_can( |
|
274 | + 'ee_edit_message', |
|
275 | + 'espresso_messages_edit_message_template', |
|
276 | + $item->ID() |
|
277 | + ) |
|
278 | + && $edit_lnk_url |
|
279 | + ? '<a href="' |
|
280 | + . $edit_lnk_url |
|
281 | + . '" title="' |
|
282 | + . esc_attr__('Edit Template', 'event_espresso') |
|
283 | + . '">' |
|
284 | + . ucwords($item->messenger_obj()->label['singular']) |
|
285 | + . '</a>' |
|
286 | + : ucwords($item->messenger_obj()->label['singular']); |
|
287 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'trash_message_template', |
|
288 | + 'id' => $item->GRP_ID(), |
|
289 | + 'noheader' => true, |
|
290 | + ), EE_MSG_ADMIN_URL); |
|
291 | + // restore link |
|
292 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'restore_message_template', |
|
293 | + 'id' => $item->GRP_ID(), |
|
294 | + 'noheader' => true, |
|
295 | + ), EE_MSG_ADMIN_URL); |
|
296 | + // delete price link |
|
297 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_message_template', |
|
298 | + 'id' => $item->GRP_ID(), |
|
299 | + 'noheader' => true, |
|
300 | + ), EE_MSG_ADMIN_URL); |
|
301 | + |
|
302 | + if (! $item->get('MTP_deleted') |
|
303 | + && EE_Registry::instance()->CAP->current_user_can( |
|
304 | + 'ee_delete_message', |
|
305 | + 'espresso_messages_trash_message_template', |
|
306 | + $item->ID() |
|
307 | + ) |
|
308 | + ) { |
|
309 | + $actions['trash'] = '<a href="' |
|
310 | + . $trash_lnk_url |
|
311 | + . '" title="' |
|
312 | + . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
313 | + . '">' |
|
314 | + . esc_html__('Move to Trash', 'event_espresso') |
|
315 | + . '</a>'; |
|
316 | + } else { |
|
317 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
318 | + 'ee_delete_message', |
|
319 | + 'espresso_messages_restore_message_template', |
|
320 | + $item->ID() |
|
321 | + )) { |
|
322 | + $actions['restore'] = '<a href="' |
|
323 | + . $restore_lnk_url |
|
324 | + . '" title="' |
|
325 | + . esc_attr__('Restore Message Template', 'event_espresso') |
|
326 | + . '">' |
|
327 | + . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
328 | + } |
|
329 | + |
|
330 | + if ($this->_view == 'trashed' |
|
331 | + && EE_Registry::instance()->CAP->current_user_can( |
|
332 | + 'ee_delete_message', |
|
333 | + 'espresso_messages_delete_message_template', |
|
334 | + $item->ID() |
|
335 | + )) { |
|
336 | + $actions['delete'] = '<a href="' |
|
337 | + . $delete_lnk_url |
|
338 | + . '" title="' |
|
339 | + . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
340 | + . '">' |
|
341 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
342 | + . '</a>'; |
|
343 | + } |
|
344 | + } |
|
345 | + |
|
346 | + //we want to display the contexts in here so we need to set them up |
|
347 | + $c_label = $item->context_label(); |
|
348 | + $c_configs = $item->contexts_config(); |
|
349 | + $ctxt = array(); |
|
350 | + $context_templates = $item->context_templates(); |
|
351 | + foreach ($context_templates as $context => $template_fields) { |
|
352 | + $mtp_to = ! empty($context_templates[$context]['to']) |
|
353 | + && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
354 | + ? $context_templates[$context]['to']->get('MTP_content') |
|
355 | + : null; |
|
356 | + $inactive = empty($mtp_to) && ! empty($context_templates[$context]['to']) |
|
357 | + ? ' class="mtp-inactive"' |
|
358 | + : ''; |
|
359 | + $context_title = ucwords($c_configs[$context]['label']); |
|
360 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_message_template', |
|
361 | + 'id' => $item->GRP_ID(), |
|
362 | + 'context' => $context, |
|
363 | + ), EE_MSG_ADMIN_URL); |
|
364 | + $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
365 | + 'ee_edit_message', |
|
366 | + 'espresso_messages_edit_message_template', |
|
367 | + $item->ID() |
|
368 | + ) |
|
369 | + ? '<a' |
|
370 | + . $inactive |
|
371 | + . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
372 | + . ' href="' . $edit_link . '"' |
|
373 | + . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
374 | + . $context_title |
|
375 | + . '</a>' |
|
376 | + : $context_title; |
|
377 | + } |
|
378 | + |
|
379 | + $ctx_content = ! $item->get('MTP_deleted') |
|
380 | + && EE_Registry::instance()->CAP->current_user_can( |
|
381 | + 'ee_edit_message', |
|
382 | + 'espresso_messages_edit_message_template', |
|
383 | + $item->ID() |
|
384 | + ) |
|
385 | + ? sprintf( |
|
386 | + '<strong>%s:</strong> ', |
|
387 | + ucwords($c_label['plural']) |
|
388 | + ) |
|
389 | + . implode(' | ', $ctxt) |
|
390 | + : ''; |
|
391 | + |
|
392 | + |
|
393 | + //Return the name contents |
|
394 | + return sprintf( |
|
395 | + '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
396 | + /* $1%s */ |
|
397 | + $name_link, |
|
398 | + /* $2%s */ |
|
399 | + $item->GRP_ID(), |
|
400 | + /* %4$s */ |
|
401 | + $ctx_content, |
|
402 | + /* $3%s */ |
|
403 | + $this->row_actions($actions) |
|
404 | + ); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * column_events |
|
409 | + * This provides a count of events using this custom template |
|
410 | + * |
|
411 | + * @param EE_Message_Template_Group $item message_template group data |
|
412 | + * @return string column output |
|
413 | + */ |
|
414 | + function column_events($item) |
|
415 | + { |
|
416 | + return $item->count_events(); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * column_message_type |
|
421 | + * |
|
422 | + * @param EE_Message_Template_Group $item message info for the row |
|
423 | + * @return string message_type name |
|
424 | + */ |
|
425 | + function column_message_type($item) |
|
426 | + { |
|
427 | + return ucwords($item->message_type_obj()->label['singular']); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Generate dropdown filter select input for messengers |
|
433 | + * |
|
434 | + * @return string |
|
435 | + */ |
|
436 | + protected function _get_messengers_dropdown_filter() |
|
437 | + { |
|
438 | + $messenger_options = array(); |
|
439 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
440 | + array( |
|
441 | + array( |
|
442 | + 'MTP_is_active' => true, |
|
443 | + 'MTP_is_global' => false, |
|
444 | + ), |
|
445 | + 'group_by' => 'MTP_messenger', |
|
446 | + ) |
|
447 | + ); |
|
448 | + |
|
449 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
450 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
451 | + $messenger = $active_message_template_group->messenger_obj(); |
|
452 | + $messenger_label = $messenger instanceof EE_messenger |
|
453 | + ? $messenger->label['singular'] |
|
454 | + : $active_message_template_group->messenger(); |
|
455 | + $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
456 | + } |
|
457 | + } |
|
458 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * Generate dropdown filter select input for message types |
|
464 | + * |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + protected function _get_message_types_dropdown_filter() |
|
468 | + { |
|
469 | + $message_type_options = array(); |
|
470 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
471 | + array( |
|
472 | + array( |
|
473 | + 'MTP_is_active' => true, |
|
474 | + 'MTP_is_global' => false, |
|
475 | + ), |
|
476 | + 'group_by' => 'MTP_message_type', |
|
477 | + ) |
|
478 | + ); |
|
479 | + |
|
480 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
481 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
482 | + $message_type = $active_message_template_group->message_type_obj(); |
|
483 | + $message_type_label = $message_type instanceof EE_message_type |
|
484 | + ? $message_type->label['singular'] |
|
485 | + : $active_message_template_group->message_type(); |
|
486 | + $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
487 | + } |
|
488 | + } |
|
489 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
490 | + } |
|
491 | 491 | |
492 | 492 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | protected function _setup_data() |
39 | 39 | { |
40 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
40 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
41 | 41 | $this->_per_page, |
42 | 42 | $this->_view, |
43 | 43 | false, |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $message_type = $item->message_type_obj(); |
98 | 98 | $messenger = $item->messenger_obj(); |
99 | 99 | |
100 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
100 | + if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
101 | 101 | echo ''; |
102 | 102 | return; |
103 | 103 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | function column_name($item) |
197 | 197 | { |
198 | - return '<p>' . $item->name() . '</p>'; |
|
198 | + return '<p>'.$item->name().'</p>'; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | function column_description($item) |
207 | 207 | { |
208 | - return '<p>' . $item->description() . '</p>'; |
|
208 | + return '<p>'.$item->description().'</p>'; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -249,19 +249,19 @@ discard block |
||
249 | 249 | $edit_lnk_url = ''; |
250 | 250 | |
251 | 251 | // edit link but only if item isn't trashed. |
252 | - if (! $item->get('MTP_deleted') |
|
252 | + if ( ! $item->get('MTP_deleted') |
|
253 | 253 | && EE_Registry::instance()->CAP->current_user_can( |
254 | 254 | 'ee_edit_message', |
255 | 255 | 'espresso_messages_edit_message_template', |
256 | 256 | $item->ID() |
257 | 257 | ) |
258 | 258 | ) { |
259 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
259 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
260 | 260 | 'action' => 'edit_message_template', |
261 | 261 | 'id' => $item->GRP_ID(), |
262 | 262 | ), EE_MSG_ADMIN_URL); |
263 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
264 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
263 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'"' |
|
264 | + . ' class="'.$item->message_type().'-edit-link"' |
|
265 | 265 | . ' title="' |
266 | 266 | . esc_attr__('Edit Template', 'event_espresso') |
267 | 267 | . '">' |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | . '</a>'; |
270 | 270 | } |
271 | 271 | |
272 | - $name_link = ! $item->get('MTP_deleted') |
|
272 | + $name_link = ! $item->get('MTP_deleted') |
|
273 | 273 | && EE_Registry::instance()->CAP->current_user_can( |
274 | 274 | 'ee_edit_message', |
275 | 275 | 'espresso_messages_edit_message_template', |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | 'noheader' => true, |
300 | 300 | ), EE_MSG_ADMIN_URL); |
301 | 301 | |
302 | - if (! $item->get('MTP_deleted') |
|
302 | + if ( ! $item->get('MTP_deleted') |
|
303 | 303 | && EE_Registry::instance()->CAP->current_user_can( |
304 | 304 | 'ee_delete_message', |
305 | 305 | 'espresso_messages_trash_message_template', |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | . '" title="' |
325 | 325 | . esc_attr__('Restore Message Template', 'event_espresso') |
326 | 326 | . '">' |
327 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
327 | + . esc_html__('Restore', 'event_espresso').'</a>'; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | if ($this->_view == 'trashed' |
@@ -361,16 +361,16 @@ discard block |
||
361 | 361 | 'id' => $item->GRP_ID(), |
362 | 362 | 'context' => $context, |
363 | 363 | ), EE_MSG_ADMIN_URL); |
364 | - $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
364 | + $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
365 | 365 | 'ee_edit_message', |
366 | 366 | 'espresso_messages_edit_message_template', |
367 | 367 | $item->ID() |
368 | 368 | ) |
369 | 369 | ? '<a' |
370 | 370 | . $inactive |
371 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
372 | - . ' href="' . $edit_link . '"' |
|
373 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
371 | + . ' class="'.$item->message_type().'-'.$context.'-edit-link"' |
|
372 | + . ' href="'.$edit_link.'"' |
|
373 | + . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">' |
|
374 | 374 | . $context_title |
375 | 375 | . '</a>' |
376 | 376 | : $context_title; |
@@ -13,325 +13,325 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @return Messages_Admin_Page |
|
18 | - */ |
|
19 | - public function get_admin_page() |
|
20 | - { |
|
21 | - return $this->_admin_page; |
|
22 | - } |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Setup data object |
|
27 | - */ |
|
28 | - protected function _setup_data() |
|
29 | - { |
|
30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | - $this->_per_page, |
|
32 | - $this->_view, |
|
33 | - false |
|
34 | - ); |
|
35 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
36 | - $this->_per_page, |
|
37 | - $this->_view, |
|
38 | - true, |
|
39 | - true |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * Set internal properties |
|
46 | - */ |
|
47 | - protected function _set_properties() |
|
48 | - { |
|
49 | - $this->_wp_list_args = array( |
|
50 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
51 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
52 | - 'ajax' => true, //for now, |
|
53 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
54 | - ); |
|
55 | - $this->_columns = array( |
|
56 | - //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
57 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
58 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
59 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
60 | - ); |
|
61 | - |
|
62 | - $this->_sortable_columns = array( |
|
63 | - 'messenger' => array('MTP_messenger' => true), |
|
64 | - ); |
|
65 | - |
|
66 | - $this->_hidden_columns = array(); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
72 | - * message_type or messenger object before generating the row. |
|
73 | - * |
|
74 | - * @param EE_Message_Template_Group $item |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function single_row($item) |
|
78 | - { |
|
79 | - $message_type = $item->message_type_obj(); |
|
80 | - $messenger = $item->messenger_obj(); |
|
81 | - |
|
82 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
83 | - echo ''; |
|
84 | - return; |
|
85 | - } |
|
86 | - |
|
87 | - parent::single_row($item); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - protected function _get_table_filters() |
|
95 | - { |
|
96 | - $filters = array(); |
|
97 | - |
|
98 | - //get select inputs |
|
99 | - $select_inputs = array( |
|
100 | - $this->_get_messengers_dropdown_filter(), |
|
101 | - $this->_get_message_types_dropdown_filter(), |
|
102 | - ); |
|
103 | - |
|
104 | - //set filters to select inputs if they aren't empty |
|
105 | - foreach ($select_inputs as $select_input) { |
|
106 | - if ($select_input) { |
|
107 | - $filters[] = $select_input; |
|
108 | - } |
|
109 | - } |
|
110 | - return $filters; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * we're just removing the search box for message templates, not needed. |
|
115 | - * |
|
116 | - * @return string (empty); |
|
117 | - */ |
|
118 | - function search_box($text, $input_id) |
|
119 | - { |
|
120 | - return ''; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * Add counts to the _views property |
|
126 | - */ |
|
127 | - protected function _add_view_counts() |
|
128 | - { |
|
129 | - foreach ($this->_views as $view => $args) { |
|
130 | - $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
131 | - $this->_per_page, |
|
132 | - $view, |
|
133 | - true, |
|
134 | - true |
|
135 | - ); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param EE_Message_Template_Group $item |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - public function column_cb($item) |
|
145 | - { |
|
146 | - return ''; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param EE_Message_Template_Group $item |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - function column_description($item) |
|
155 | - { |
|
156 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param EE_Message_Template_Group $item |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - function column_messenger($item) |
|
165 | - { |
|
166 | - //Build row actions |
|
167 | - $actions = array(); |
|
168 | - |
|
169 | - // edit link but only if item isn't trashed. |
|
170 | - if (! $item->get('MTP_deleted') |
|
171 | - && EE_Registry::instance()->CAP->current_user_can( |
|
172 | - 'ee_edit_message', |
|
173 | - 'espresso_messages_edit_message_template', |
|
174 | - $item->ID() |
|
175 | - )) { |
|
176 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
177 | - array( |
|
178 | - 'action' => 'edit_message_template', |
|
179 | - 'id' => $item->GRP_ID(), |
|
180 | - ), |
|
181 | - EE_MSG_ADMIN_URL |
|
182 | - ); |
|
183 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
184 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
185 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
186 | - . esc_html__('Edit', 'event_espresso') |
|
187 | - . '</a>'; |
|
188 | - } |
|
189 | - |
|
190 | - $name_link = ! $item->get('MTP_deleted') |
|
191 | - && EE_Registry::instance()->CAP->current_user_can( |
|
192 | - 'ee_edit_message', |
|
193 | - 'espresso_messages_edit_message_template', |
|
194 | - $item->ID() |
|
195 | - ) |
|
196 | - ? '<a href="' . $edit_lnk_url . '"' |
|
197 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
198 | - . ucwords($item->messenger_obj()->label['singular']) |
|
199 | - . '</a>' |
|
200 | - : ucwords($item->messenger_obj()->label['singular']); |
|
201 | - |
|
202 | - //we want to display the contexts in here so we need to set them up |
|
203 | - $c_label = $item->context_label(); |
|
204 | - $c_configs = $item->contexts_config(); |
|
205 | - $ctxt = array(); |
|
206 | - $context_templates = $item->context_templates(); |
|
207 | - foreach ($context_templates as $context => $template_fields) { |
|
208 | - $mtp_to = ! empty($context_templates[$context]['to']) |
|
209 | - && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
210 | - ? $context_templates[$context]['to']->get('MTP_content') |
|
211 | - : null; |
|
212 | - $inactive = empty($mtp_to) |
|
213 | - && ! empty($context_templates[$context]['to']) |
|
214 | - ? ' class="mtp-inactive"' |
|
215 | - : ''; |
|
216 | - $context_title = ucwords($c_configs[$context]['label']); |
|
217 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_message_template', |
|
218 | - 'id' => $item->GRP_ID(), |
|
219 | - 'context' => $context, |
|
220 | - ), EE_MSG_ADMIN_URL); |
|
221 | - $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
222 | - 'ee_edit_message', |
|
223 | - 'espresso_messages_edit_message_template', |
|
224 | - $item->ID() |
|
225 | - ) |
|
226 | - ? '<a' . $inactive |
|
227 | - . ' href="' . $edit_link . '"' |
|
228 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
229 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
230 | - . $context_title |
|
231 | - . '</a>' |
|
232 | - : $context_title; |
|
233 | - } |
|
234 | - |
|
235 | - $ctx_content = ! $item->get('MTP_deleted') |
|
236 | - && EE_Registry::instance()->CAP->current_user_can( |
|
237 | - 'ee_edit_message', |
|
238 | - 'espresso_messages_edit_message_template', |
|
239 | - $item->ID() |
|
240 | - ) |
|
241 | - ? sprintf( |
|
242 | - '<strong>%s:</strong> ', |
|
243 | - ucwords($c_label['plural']) |
|
244 | - ) |
|
245 | - . implode(' | ', $ctxt) |
|
246 | - : ''; |
|
247 | - |
|
248 | - |
|
249 | - //Return the name contents |
|
250 | - return sprintf( |
|
251 | - '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
252 | - /* $1%s */ |
|
253 | - $name_link, |
|
254 | - /* $2%s */ |
|
255 | - $item->GRP_ID(), |
|
256 | - /* %4$s */ |
|
257 | - $ctx_content, |
|
258 | - /* $3%s */ |
|
259 | - $this->row_actions($actions) |
|
260 | - ); |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * column_message_type |
|
265 | - * |
|
266 | - * @param EE_Message_Template_Group $item message info for the row |
|
267 | - * @return string message_type name |
|
268 | - */ |
|
269 | - function column_message_type($item) |
|
270 | - { |
|
271 | - return ucwords($item->message_type_obj()->label['singular']); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Generate dropdown filter select input for messengers |
|
278 | - * |
|
279 | - * @return string |
|
280 | - */ |
|
281 | - protected function _get_messengers_dropdown_filter() |
|
282 | - { |
|
283 | - $messenger_options = array(); |
|
284 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
285 | - array( |
|
286 | - array( |
|
287 | - 'MTP_is_active' => true, |
|
288 | - 'MTP_is_global' => true, |
|
289 | - ), |
|
290 | - 'group_by' => 'MTP_messenger', |
|
291 | - ) |
|
292 | - ); |
|
293 | - |
|
294 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
295 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
296 | - $messenger = $active_message_template_group->messenger_obj(); |
|
297 | - $messenger_label = $messenger instanceof EE_messenger |
|
298 | - ? $messenger->label['singular'] |
|
299 | - : $active_message_template_group->messenger(); |
|
300 | - $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
301 | - } |
|
302 | - } |
|
303 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Generate dropdown filter select input for message types |
|
309 | - * |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - protected function _get_message_types_dropdown_filter() |
|
313 | - { |
|
314 | - $message_type_options = array(); |
|
315 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
316 | - array( |
|
317 | - array( |
|
318 | - 'MTP_is_active' => true, |
|
319 | - 'MTP_is_global' => true, |
|
320 | - ), |
|
321 | - 'group_by' => 'MTP_message_type', |
|
322 | - ) |
|
323 | - ); |
|
324 | - |
|
325 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
326 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
327 | - $message_type = $active_message_template_group->message_type_obj(); |
|
328 | - $message_type_label = $message_type instanceof EE_message_type |
|
329 | - ? $message_type->label['singular'] |
|
330 | - : $active_message_template_group->message_type(); |
|
331 | - $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
332 | - } |
|
333 | - } |
|
334 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
335 | - } |
|
16 | + /** |
|
17 | + * @return Messages_Admin_Page |
|
18 | + */ |
|
19 | + public function get_admin_page() |
|
20 | + { |
|
21 | + return $this->_admin_page; |
|
22 | + } |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Setup data object |
|
27 | + */ |
|
28 | + protected function _setup_data() |
|
29 | + { |
|
30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | + $this->_per_page, |
|
32 | + $this->_view, |
|
33 | + false |
|
34 | + ); |
|
35 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
36 | + $this->_per_page, |
|
37 | + $this->_view, |
|
38 | + true, |
|
39 | + true |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * Set internal properties |
|
46 | + */ |
|
47 | + protected function _set_properties() |
|
48 | + { |
|
49 | + $this->_wp_list_args = array( |
|
50 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
51 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
52 | + 'ajax' => true, //for now, |
|
53 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
54 | + ); |
|
55 | + $this->_columns = array( |
|
56 | + //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
57 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
58 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
59 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
60 | + ); |
|
61 | + |
|
62 | + $this->_sortable_columns = array( |
|
63 | + 'messenger' => array('MTP_messenger' => true), |
|
64 | + ); |
|
65 | + |
|
66 | + $this->_hidden_columns = array(); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
72 | + * message_type or messenger object before generating the row. |
|
73 | + * |
|
74 | + * @param EE_Message_Template_Group $item |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function single_row($item) |
|
78 | + { |
|
79 | + $message_type = $item->message_type_obj(); |
|
80 | + $messenger = $item->messenger_obj(); |
|
81 | + |
|
82 | + if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
83 | + echo ''; |
|
84 | + return; |
|
85 | + } |
|
86 | + |
|
87 | + parent::single_row($item); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + protected function _get_table_filters() |
|
95 | + { |
|
96 | + $filters = array(); |
|
97 | + |
|
98 | + //get select inputs |
|
99 | + $select_inputs = array( |
|
100 | + $this->_get_messengers_dropdown_filter(), |
|
101 | + $this->_get_message_types_dropdown_filter(), |
|
102 | + ); |
|
103 | + |
|
104 | + //set filters to select inputs if they aren't empty |
|
105 | + foreach ($select_inputs as $select_input) { |
|
106 | + if ($select_input) { |
|
107 | + $filters[] = $select_input; |
|
108 | + } |
|
109 | + } |
|
110 | + return $filters; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * we're just removing the search box for message templates, not needed. |
|
115 | + * |
|
116 | + * @return string (empty); |
|
117 | + */ |
|
118 | + function search_box($text, $input_id) |
|
119 | + { |
|
120 | + return ''; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * Add counts to the _views property |
|
126 | + */ |
|
127 | + protected function _add_view_counts() |
|
128 | + { |
|
129 | + foreach ($this->_views as $view => $args) { |
|
130 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
131 | + $this->_per_page, |
|
132 | + $view, |
|
133 | + true, |
|
134 | + true |
|
135 | + ); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param EE_Message_Template_Group $item |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + public function column_cb($item) |
|
145 | + { |
|
146 | + return ''; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param EE_Message_Template_Group $item |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + function column_description($item) |
|
155 | + { |
|
156 | + return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param EE_Message_Template_Group $item |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + function column_messenger($item) |
|
165 | + { |
|
166 | + //Build row actions |
|
167 | + $actions = array(); |
|
168 | + |
|
169 | + // edit link but only if item isn't trashed. |
|
170 | + if (! $item->get('MTP_deleted') |
|
171 | + && EE_Registry::instance()->CAP->current_user_can( |
|
172 | + 'ee_edit_message', |
|
173 | + 'espresso_messages_edit_message_template', |
|
174 | + $item->ID() |
|
175 | + )) { |
|
176 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
177 | + array( |
|
178 | + 'action' => 'edit_message_template', |
|
179 | + 'id' => $item->GRP_ID(), |
|
180 | + ), |
|
181 | + EE_MSG_ADMIN_URL |
|
182 | + ); |
|
183 | + $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
184 | + . ' class="' . $item->message_type() . '-edit-link"' |
|
185 | + . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
186 | + . esc_html__('Edit', 'event_espresso') |
|
187 | + . '</a>'; |
|
188 | + } |
|
189 | + |
|
190 | + $name_link = ! $item->get('MTP_deleted') |
|
191 | + && EE_Registry::instance()->CAP->current_user_can( |
|
192 | + 'ee_edit_message', |
|
193 | + 'espresso_messages_edit_message_template', |
|
194 | + $item->ID() |
|
195 | + ) |
|
196 | + ? '<a href="' . $edit_lnk_url . '"' |
|
197 | + . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
198 | + . ucwords($item->messenger_obj()->label['singular']) |
|
199 | + . '</a>' |
|
200 | + : ucwords($item->messenger_obj()->label['singular']); |
|
201 | + |
|
202 | + //we want to display the contexts in here so we need to set them up |
|
203 | + $c_label = $item->context_label(); |
|
204 | + $c_configs = $item->contexts_config(); |
|
205 | + $ctxt = array(); |
|
206 | + $context_templates = $item->context_templates(); |
|
207 | + foreach ($context_templates as $context => $template_fields) { |
|
208 | + $mtp_to = ! empty($context_templates[$context]['to']) |
|
209 | + && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
210 | + ? $context_templates[$context]['to']->get('MTP_content') |
|
211 | + : null; |
|
212 | + $inactive = empty($mtp_to) |
|
213 | + && ! empty($context_templates[$context]['to']) |
|
214 | + ? ' class="mtp-inactive"' |
|
215 | + : ''; |
|
216 | + $context_title = ucwords($c_configs[$context]['label']); |
|
217 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_message_template', |
|
218 | + 'id' => $item->GRP_ID(), |
|
219 | + 'context' => $context, |
|
220 | + ), EE_MSG_ADMIN_URL); |
|
221 | + $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
222 | + 'ee_edit_message', |
|
223 | + 'espresso_messages_edit_message_template', |
|
224 | + $item->ID() |
|
225 | + ) |
|
226 | + ? '<a' . $inactive |
|
227 | + . ' href="' . $edit_link . '"' |
|
228 | + . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
229 | + . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
230 | + . $context_title |
|
231 | + . '</a>' |
|
232 | + : $context_title; |
|
233 | + } |
|
234 | + |
|
235 | + $ctx_content = ! $item->get('MTP_deleted') |
|
236 | + && EE_Registry::instance()->CAP->current_user_can( |
|
237 | + 'ee_edit_message', |
|
238 | + 'espresso_messages_edit_message_template', |
|
239 | + $item->ID() |
|
240 | + ) |
|
241 | + ? sprintf( |
|
242 | + '<strong>%s:</strong> ', |
|
243 | + ucwords($c_label['plural']) |
|
244 | + ) |
|
245 | + . implode(' | ', $ctxt) |
|
246 | + : ''; |
|
247 | + |
|
248 | + |
|
249 | + //Return the name contents |
|
250 | + return sprintf( |
|
251 | + '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
252 | + /* $1%s */ |
|
253 | + $name_link, |
|
254 | + /* $2%s */ |
|
255 | + $item->GRP_ID(), |
|
256 | + /* %4$s */ |
|
257 | + $ctx_content, |
|
258 | + /* $3%s */ |
|
259 | + $this->row_actions($actions) |
|
260 | + ); |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * column_message_type |
|
265 | + * |
|
266 | + * @param EE_Message_Template_Group $item message info for the row |
|
267 | + * @return string message_type name |
|
268 | + */ |
|
269 | + function column_message_type($item) |
|
270 | + { |
|
271 | + return ucwords($item->message_type_obj()->label['singular']); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Generate dropdown filter select input for messengers |
|
278 | + * |
|
279 | + * @return string |
|
280 | + */ |
|
281 | + protected function _get_messengers_dropdown_filter() |
|
282 | + { |
|
283 | + $messenger_options = array(); |
|
284 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
285 | + array( |
|
286 | + array( |
|
287 | + 'MTP_is_active' => true, |
|
288 | + 'MTP_is_global' => true, |
|
289 | + ), |
|
290 | + 'group_by' => 'MTP_messenger', |
|
291 | + ) |
|
292 | + ); |
|
293 | + |
|
294 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
295 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
296 | + $messenger = $active_message_template_group->messenger_obj(); |
|
297 | + $messenger_label = $messenger instanceof EE_messenger |
|
298 | + ? $messenger->label['singular'] |
|
299 | + : $active_message_template_group->messenger(); |
|
300 | + $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
301 | + } |
|
302 | + } |
|
303 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Generate dropdown filter select input for message types |
|
309 | + * |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + protected function _get_message_types_dropdown_filter() |
|
313 | + { |
|
314 | + $message_type_options = array(); |
|
315 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
316 | + array( |
|
317 | + array( |
|
318 | + 'MTP_is_active' => true, |
|
319 | + 'MTP_is_global' => true, |
|
320 | + ), |
|
321 | + 'group_by' => 'MTP_message_type', |
|
322 | + ) |
|
323 | + ); |
|
324 | + |
|
325 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
326 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
327 | + $message_type = $active_message_template_group->message_type_obj(); |
|
328 | + $message_type_label = $message_type instanceof EE_message_type |
|
329 | + ? $message_type->label['singular'] |
|
330 | + : $active_message_template_group->message_type(); |
|
331 | + $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
332 | + } |
|
333 | + } |
|
334 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
335 | + } |
|
336 | 336 | |
337 | 337 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | protected function _setup_data() |
29 | 29 | { |
30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | 31 | $this->_per_page, |
32 | 32 | $this->_view, |
33 | 33 | false |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | 'ajax' => true, //for now, |
53 | 53 | 'screen' => $this->get_admin_page()->get_current_screen()->id, |
54 | 54 | ); |
55 | - $this->_columns = array( |
|
55 | + $this->_columns = array( |
|
56 | 56 | //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
57 | 57 | 'message_type' => esc_html__('Message Type', 'event_espresso'), |
58 | 58 | 'messenger' => esc_html__('Messenger', 'event_espresso'), |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $message_type = $item->message_type_obj(); |
80 | 80 | $messenger = $item->messenger_obj(); |
81 | 81 | |
82 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
82 | + if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
83 | 83 | echo ''; |
84 | 84 | return; |
85 | 85 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | */ |
154 | 154 | function column_description($item) |
155 | 155 | { |
156 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
156 | + return '<p>'.$item->message_type_obj()->description.'</p>'; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | |
@@ -167,22 +167,22 @@ discard block |
||
167 | 167 | $actions = array(); |
168 | 168 | |
169 | 169 | // edit link but only if item isn't trashed. |
170 | - if (! $item->get('MTP_deleted') |
|
170 | + if ( ! $item->get('MTP_deleted') |
|
171 | 171 | && EE_Registry::instance()->CAP->current_user_can( |
172 | 172 | 'ee_edit_message', |
173 | 173 | 'espresso_messages_edit_message_template', |
174 | 174 | $item->ID() |
175 | 175 | )) { |
176 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
176 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
177 | 177 | array( |
178 | 178 | 'action' => 'edit_message_template', |
179 | 179 | 'id' => $item->GRP_ID(), |
180 | 180 | ), |
181 | 181 | EE_MSG_ADMIN_URL |
182 | 182 | ); |
183 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
184 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
185 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
183 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'"' |
|
184 | + . ' class="'.$item->message_type().'-edit-link"' |
|
185 | + . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">' |
|
186 | 186 | . esc_html__('Edit', 'event_espresso') |
187 | 187 | . '</a>'; |
188 | 188 | } |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | 'espresso_messages_edit_message_template', |
194 | 194 | $item->ID() |
195 | 195 | ) |
196 | - ? '<a href="' . $edit_lnk_url . '"' |
|
197 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
196 | + ? '<a href="'.$edit_lnk_url.'"' |
|
197 | + . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">' |
|
198 | 198 | . ucwords($item->messenger_obj()->label['singular']) |
199 | 199 | . '</a>' |
200 | 200 | : ucwords($item->messenger_obj()->label['singular']); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | && $context_templates[$context]['to'] instanceof EE_Message_Template |
210 | 210 | ? $context_templates[$context]['to']->get('MTP_content') |
211 | 211 | : null; |
212 | - $inactive = empty($mtp_to) |
|
212 | + $inactive = empty($mtp_to) |
|
213 | 213 | && ! empty($context_templates[$context]['to']) |
214 | 214 | ? ' class="mtp-inactive"' |
215 | 215 | : ''; |
@@ -218,15 +218,15 @@ discard block |
||
218 | 218 | 'id' => $item->GRP_ID(), |
219 | 219 | 'context' => $context, |
220 | 220 | ), EE_MSG_ADMIN_URL); |
221 | - $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
221 | + $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
222 | 222 | 'ee_edit_message', |
223 | 223 | 'espresso_messages_edit_message_template', |
224 | 224 | $item->ID() |
225 | 225 | ) |
226 | - ? '<a' . $inactive |
|
227 | - . ' href="' . $edit_link . '"' |
|
228 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
229 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
226 | + ? '<a'.$inactive |
|
227 | + . ' href="'.$edit_link.'"' |
|
228 | + . ' class="'.$item->message_type().'-'.$context.'-edit-link"' |
|
229 | + . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">' |
|
230 | 230 | . $context_title |
231 | 231 | . '</a>' |
232 | 232 | : $context_title; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -15,129 +15,129 @@ discard block |
||
15 | 15 | class EEM_WP_User extends EEM_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * private instance of the EEM_WP_User object |
|
20 | - * |
|
21 | - * @type EEM_WP_User |
|
22 | - */ |
|
23 | - protected static $_instance = null; |
|
18 | + /** |
|
19 | + * private instance of the EEM_WP_User object |
|
20 | + * |
|
21 | + * @type EEM_WP_User |
|
22 | + */ |
|
23 | + protected static $_instance = null; |
|
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * constructor |
|
29 | - * |
|
30 | - * @param null $timezone |
|
31 | - * @throws \EE_Error |
|
32 | - */ |
|
33 | - protected function __construct($timezone = null) |
|
34 | - { |
|
35 | - $this->singular_item = __('WP_User', 'event_espresso'); |
|
36 | - $this->plural_item = __('WP_Users', 'event_espresso'); |
|
37 | - global $wpdb; |
|
38 | - $this->_tables = array( |
|
39 | - 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
40 | - ); |
|
41 | - $this->_fields = array( |
|
42 | - 'WP_User' => array( |
|
43 | - 'ID' => new EE_Primary_Key_Int_Field('ID', __('WP_User ID', 'event_espresso')), |
|
44 | - 'user_login' => new EE_Plain_Text_Field( |
|
45 | - 'user_login', |
|
46 | - __('User Login', 'event_espresso'), |
|
47 | - false, |
|
48 | - '' |
|
49 | - ), |
|
50 | - 'user_pass' => new EE_Plain_Text_Field( |
|
51 | - 'user_pass', |
|
52 | - __('User Password', 'event_espresso'), |
|
53 | - false, |
|
54 | - '' |
|
55 | - ), |
|
56 | - 'user_nicename' => new EE_Plain_Text_Field( |
|
57 | - 'user_nicename', |
|
58 | - __(' User Nice Name', 'event_espresso'), |
|
59 | - false, |
|
60 | - '' |
|
61 | - ), |
|
62 | - 'user_email' => new EE_Email_Field( |
|
63 | - 'user_email', |
|
64 | - __('User Email', 'event_espresso'), |
|
65 | - false |
|
66 | - ), |
|
67 | - 'user_registered' => new EE_Datetime_Field( |
|
68 | - 'user_registered', |
|
69 | - __('Date User Registered', 'event_espresso'), |
|
70 | - false, |
|
71 | - EE_Datetime_Field::now, |
|
72 | - $timezone |
|
73 | - ), |
|
74 | - 'user_activation_key' => new EE_Plain_Text_Field( |
|
75 | - 'user_activation_key', |
|
76 | - __('User Activation Key', 'event_espresso'), |
|
77 | - false, |
|
78 | - '' |
|
79 | - ), |
|
80 | - 'user_status' => new EE_Integer_Field( |
|
81 | - 'user_status', |
|
82 | - __('User Status', 'event_espresso'), |
|
83 | - false, |
|
84 | - 0 |
|
85 | - ), |
|
86 | - 'display_name' => new EE_Plain_Text_Field( |
|
87 | - 'display_name', |
|
88 | - __('Display Name', 'event_espresso'), |
|
89 | - false, |
|
90 | - '' |
|
91 | - ), |
|
92 | - ), |
|
93 | - ); |
|
94 | - $this->_model_relations = array( |
|
95 | - 'Attendee' => new EE_Has_Many_Relation(), |
|
96 | - 'Change_Log' => new EE_Has_Many_Relation(), |
|
97 | - 'Event' => new EE_Has_Many_Relation(), |
|
98 | - 'Payment_Method' => new EE_Has_Many_Relation(), |
|
99 | - 'Price' => new EE_Has_Many_Relation(), |
|
100 | - 'Price_Type' => new EE_Has_Many_Relation(), |
|
101 | - 'Question' => new EE_Has_Many_Relation(), |
|
102 | - 'Question_Group' => new EE_Has_Many_Relation(), |
|
103 | - 'Ticket' => new EE_Has_Many_Relation(), |
|
104 | - 'Venue' => new EE_Has_Many_Relation(), |
|
105 | - 'Message' => new EE_Has_Many_Relation(), |
|
106 | - ); |
|
107 | - $this->_wp_core_model = true; |
|
108 | - $this->_caps_slug = 'users'; |
|
109 | - $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list'; |
|
110 | - $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list'; |
|
111 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
112 | - $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User(); |
|
113 | - } |
|
114 | - //@todo: account for create_users controls whether they can create users at all |
|
115 | - parent::__construct($timezone); |
|
116 | - } |
|
27 | + /** |
|
28 | + * constructor |
|
29 | + * |
|
30 | + * @param null $timezone |
|
31 | + * @throws \EE_Error |
|
32 | + */ |
|
33 | + protected function __construct($timezone = null) |
|
34 | + { |
|
35 | + $this->singular_item = __('WP_User', 'event_espresso'); |
|
36 | + $this->plural_item = __('WP_Users', 'event_espresso'); |
|
37 | + global $wpdb; |
|
38 | + $this->_tables = array( |
|
39 | + 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
40 | + ); |
|
41 | + $this->_fields = array( |
|
42 | + 'WP_User' => array( |
|
43 | + 'ID' => new EE_Primary_Key_Int_Field('ID', __('WP_User ID', 'event_espresso')), |
|
44 | + 'user_login' => new EE_Plain_Text_Field( |
|
45 | + 'user_login', |
|
46 | + __('User Login', 'event_espresso'), |
|
47 | + false, |
|
48 | + '' |
|
49 | + ), |
|
50 | + 'user_pass' => new EE_Plain_Text_Field( |
|
51 | + 'user_pass', |
|
52 | + __('User Password', 'event_espresso'), |
|
53 | + false, |
|
54 | + '' |
|
55 | + ), |
|
56 | + 'user_nicename' => new EE_Plain_Text_Field( |
|
57 | + 'user_nicename', |
|
58 | + __(' User Nice Name', 'event_espresso'), |
|
59 | + false, |
|
60 | + '' |
|
61 | + ), |
|
62 | + 'user_email' => new EE_Email_Field( |
|
63 | + 'user_email', |
|
64 | + __('User Email', 'event_espresso'), |
|
65 | + false |
|
66 | + ), |
|
67 | + 'user_registered' => new EE_Datetime_Field( |
|
68 | + 'user_registered', |
|
69 | + __('Date User Registered', 'event_espresso'), |
|
70 | + false, |
|
71 | + EE_Datetime_Field::now, |
|
72 | + $timezone |
|
73 | + ), |
|
74 | + 'user_activation_key' => new EE_Plain_Text_Field( |
|
75 | + 'user_activation_key', |
|
76 | + __('User Activation Key', 'event_espresso'), |
|
77 | + false, |
|
78 | + '' |
|
79 | + ), |
|
80 | + 'user_status' => new EE_Integer_Field( |
|
81 | + 'user_status', |
|
82 | + __('User Status', 'event_espresso'), |
|
83 | + false, |
|
84 | + 0 |
|
85 | + ), |
|
86 | + 'display_name' => new EE_Plain_Text_Field( |
|
87 | + 'display_name', |
|
88 | + __('Display Name', 'event_espresso'), |
|
89 | + false, |
|
90 | + '' |
|
91 | + ), |
|
92 | + ), |
|
93 | + ); |
|
94 | + $this->_model_relations = array( |
|
95 | + 'Attendee' => new EE_Has_Many_Relation(), |
|
96 | + 'Change_Log' => new EE_Has_Many_Relation(), |
|
97 | + 'Event' => new EE_Has_Many_Relation(), |
|
98 | + 'Payment_Method' => new EE_Has_Many_Relation(), |
|
99 | + 'Price' => new EE_Has_Many_Relation(), |
|
100 | + 'Price_Type' => new EE_Has_Many_Relation(), |
|
101 | + 'Question' => new EE_Has_Many_Relation(), |
|
102 | + 'Question_Group' => new EE_Has_Many_Relation(), |
|
103 | + 'Ticket' => new EE_Has_Many_Relation(), |
|
104 | + 'Venue' => new EE_Has_Many_Relation(), |
|
105 | + 'Message' => new EE_Has_Many_Relation(), |
|
106 | + ); |
|
107 | + $this->_wp_core_model = true; |
|
108 | + $this->_caps_slug = 'users'; |
|
109 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list'; |
|
110 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list'; |
|
111 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
112 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User(); |
|
113 | + } |
|
114 | + //@todo: account for create_users controls whether they can create users at all |
|
115 | + parent::__construct($timezone); |
|
116 | + } |
|
117 | 117 | |
118 | 118 | |
119 | 119 | |
120 | - /** |
|
121 | - * We don't need a foreign key to the WP_User model, we just need its primary key |
|
122 | - * |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public function wp_user_field_name() |
|
126 | - { |
|
127 | - return $this->primary_key_name(); |
|
128 | - } |
|
120 | + /** |
|
121 | + * We don't need a foreign key to the WP_User model, we just need its primary key |
|
122 | + * |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public function wp_user_field_name() |
|
126 | + { |
|
127 | + return $this->primary_key_name(); |
|
128 | + } |
|
129 | 129 | |
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
134 | - * |
|
135 | - * @return boolean |
|
136 | - */ |
|
137 | - public function is_owned() |
|
138 | - { |
|
139 | - return true; |
|
140 | - } |
|
132 | + /** |
|
133 | + * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
134 | + * |
|
135 | + * @return boolean |
|
136 | + */ |
|
137 | + public function is_owned() |
|
138 | + { |
|
139 | + return true; |
|
140 | + } |
|
141 | 141 | } |
142 | 142 | // End of file EEM_WP_User.model.php |
143 | 143 | // Location: /core/db_models/EEM_WP_User.model.php |
@@ -1,4 +1,4 @@ |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -25,127 +25,127 @@ discard block |
||
25 | 25 | class EEM_Term_Taxonomy extends EEM_Base |
26 | 26 | { |
27 | 27 | |
28 | - // private instance of the Attendee object |
|
29 | - protected static $_instance = null; |
|
28 | + // private instance of the Attendee object |
|
29 | + protected static $_instance = null; |
|
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - protected function __construct($timezone = null) |
|
34 | - { |
|
35 | - $this->singular_item = __('Term Taxonomy', 'event_espresso'); |
|
36 | - $this->plural_item = __('Term Taxonomy', 'event_espresso'); |
|
37 | - $this->_tables = array( |
|
38 | - 'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'), |
|
39 | - ); |
|
40 | - $this->_fields = array( |
|
41 | - 'Term_Taxonomy' => array( |
|
42 | - 'term_taxonomy_id' => new EE_Primary_Key_Int_Field( |
|
43 | - 'term_taxonomy_id', |
|
44 | - __('Term-Taxonomy ID', 'event_espresso') |
|
45 | - ), |
|
46 | - 'term_id' => new EE_Foreign_Key_Int_Field( |
|
47 | - 'term_id', |
|
48 | - __("Term Id", "event_espresso"), |
|
49 | - false, |
|
50 | - 0, |
|
51 | - 'Term' |
|
52 | - ), |
|
53 | - 'taxonomy' => new EE_Plain_Text_Field( |
|
54 | - 'taxonomy', |
|
55 | - __('Taxonomy Name', 'event_espresso'), |
|
56 | - false, |
|
57 | - 'category' |
|
58 | - ), |
|
59 | - 'description' => new EE_Post_Content_Field( |
|
60 | - 'description', |
|
61 | - __("Description of Term", "event_espresso"), |
|
62 | - false, |
|
63 | - '' |
|
64 | - ), |
|
65 | - 'parent' => new EE_Integer_Field('parent', __("Parent Term ID", "event_espresso"), false, 0), |
|
66 | - 'term_count' => new EE_Integer_Field( |
|
67 | - 'count', |
|
68 | - __("Count of Objects attached", 'event_espresso'), |
|
69 | - false, |
|
70 | - 0 |
|
71 | - ), |
|
72 | - ), |
|
73 | - ); |
|
74 | - $this->_model_relations = array( |
|
75 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
76 | - 'Term' => new EE_Belongs_To_Relation(), |
|
77 | - ); |
|
78 | - $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
|
79 | - foreach ($cpt_models as $model_name) { |
|
80 | - $this->_model_relations[$model_name] = new EE_HABTM_Relation('Term_Relationship'); |
|
81 | - } |
|
82 | - $this->_indexes = array( |
|
83 | - 'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')), |
|
84 | - ); |
|
85 | - $path_to_tax_model = ''; |
|
86 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
87 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
88 | - $path_to_tax_model |
|
89 | - ); |
|
90 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
91 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
92 | - //add cap restrictions for editing relating to the "ee_edit_*" |
|
93 | - $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
94 | - array( |
|
95 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
96 | - ) |
|
97 | - ); |
|
98 | - $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
99 | - array( |
|
100 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
101 | - ) |
|
102 | - ); |
|
103 | - $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
104 | - array( |
|
105 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
106 | - ) |
|
107 | - ); |
|
108 | - //add cap restrictions for deleting relating to the "ee_deleting_*" |
|
109 | - $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
110 | - array( |
|
111 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
112 | - ) |
|
113 | - ); |
|
114 | - $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
115 | - array( |
|
116 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
117 | - ) |
|
118 | - ); |
|
119 | - $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
120 | - array( |
|
121 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
122 | - ) |
|
123 | - ); |
|
124 | - parent::__construct($timezone); |
|
125 | - add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3); |
|
126 | - } |
|
33 | + protected function __construct($timezone = null) |
|
34 | + { |
|
35 | + $this->singular_item = __('Term Taxonomy', 'event_espresso'); |
|
36 | + $this->plural_item = __('Term Taxonomy', 'event_espresso'); |
|
37 | + $this->_tables = array( |
|
38 | + 'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'), |
|
39 | + ); |
|
40 | + $this->_fields = array( |
|
41 | + 'Term_Taxonomy' => array( |
|
42 | + 'term_taxonomy_id' => new EE_Primary_Key_Int_Field( |
|
43 | + 'term_taxonomy_id', |
|
44 | + __('Term-Taxonomy ID', 'event_espresso') |
|
45 | + ), |
|
46 | + 'term_id' => new EE_Foreign_Key_Int_Field( |
|
47 | + 'term_id', |
|
48 | + __("Term Id", "event_espresso"), |
|
49 | + false, |
|
50 | + 0, |
|
51 | + 'Term' |
|
52 | + ), |
|
53 | + 'taxonomy' => new EE_Plain_Text_Field( |
|
54 | + 'taxonomy', |
|
55 | + __('Taxonomy Name', 'event_espresso'), |
|
56 | + false, |
|
57 | + 'category' |
|
58 | + ), |
|
59 | + 'description' => new EE_Post_Content_Field( |
|
60 | + 'description', |
|
61 | + __("Description of Term", "event_espresso"), |
|
62 | + false, |
|
63 | + '' |
|
64 | + ), |
|
65 | + 'parent' => new EE_Integer_Field('parent', __("Parent Term ID", "event_espresso"), false, 0), |
|
66 | + 'term_count' => new EE_Integer_Field( |
|
67 | + 'count', |
|
68 | + __("Count of Objects attached", 'event_espresso'), |
|
69 | + false, |
|
70 | + 0 |
|
71 | + ), |
|
72 | + ), |
|
73 | + ); |
|
74 | + $this->_model_relations = array( |
|
75 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
76 | + 'Term' => new EE_Belongs_To_Relation(), |
|
77 | + ); |
|
78 | + $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
|
79 | + foreach ($cpt_models as $model_name) { |
|
80 | + $this->_model_relations[$model_name] = new EE_HABTM_Relation('Term_Relationship'); |
|
81 | + } |
|
82 | + $this->_indexes = array( |
|
83 | + 'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')), |
|
84 | + ); |
|
85 | + $path_to_tax_model = ''; |
|
86 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
87 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
88 | + $path_to_tax_model |
|
89 | + ); |
|
90 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
91 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
92 | + //add cap restrictions for editing relating to the "ee_edit_*" |
|
93 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
94 | + array( |
|
95 | + $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
96 | + ) |
|
97 | + ); |
|
98 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
99 | + array( |
|
100 | + $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
101 | + ) |
|
102 | + ); |
|
103 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
104 | + array( |
|
105 | + $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
106 | + ) |
|
107 | + ); |
|
108 | + //add cap restrictions for deleting relating to the "ee_deleting_*" |
|
109 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
110 | + array( |
|
111 | + $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
112 | + ) |
|
113 | + ); |
|
114 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
115 | + array( |
|
116 | + $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
117 | + ) |
|
118 | + ); |
|
119 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
120 | + array( |
|
121 | + $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
122 | + ) |
|
123 | + ); |
|
124 | + parent::__construct($timezone); |
|
125 | + add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3); |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | 129 | |
130 | - /** |
|
131 | - * Makes sure that during REST API queries, we only return term-taxonomies |
|
132 | - * for term taxonomies which should be shown in the rest api |
|
133 | - * |
|
134 | - * @param array $model_query_params |
|
135 | - * @param array $querystring_query_params |
|
136 | - * @param EEM_Base $model |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
140 | - { |
|
141 | - if ($model === EEM_Term_Taxonomy::instance()) { |
|
142 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
143 | - if (! empty($taxonomies)) { |
|
144 | - $model_query_params[0]['taxonomy'] = array('IN', $taxonomies); |
|
145 | - } |
|
146 | - } |
|
147 | - return $model_query_params; |
|
148 | - } |
|
130 | + /** |
|
131 | + * Makes sure that during REST API queries, we only return term-taxonomies |
|
132 | + * for term taxonomies which should be shown in the rest api |
|
133 | + * |
|
134 | + * @param array $model_query_params |
|
135 | + * @param array $querystring_query_params |
|
136 | + * @param EEM_Base $model |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
140 | + { |
|
141 | + if ($model === EEM_Term_Taxonomy::instance()) { |
|
142 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
143 | + if (! empty($taxonomies)) { |
|
144 | + $model_query_params[0]['taxonomy'] = array('IN', $taxonomies); |
|
145 | + } |
|
146 | + } |
|
147 | + return $model_query_params; |
|
148 | + } |
|
149 | 149 | } |
150 | 150 | // End of file EEM_Term_Taxonomy.model.php |
151 | 151 | // Location: /includes/models/EEM_Term_Taxonomy.model.php |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | /** |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @author Michael Nelson |
19 | 19 | * ------------------------------------------------------------------------ |
20 | 20 | */ |
21 | -require_once(EE_MODELS . 'EEM_Base.model.php'); |
|
21 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
22 | 22 | |
23 | 23 | |
24 | 24 | |
@@ -92,33 +92,33 @@ discard block |
||
92 | 92 | //add cap restrictions for editing relating to the "ee_edit_*" |
93 | 93 | $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
94 | 94 | array( |
95 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
95 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
96 | 96 | ) |
97 | 97 | ); |
98 | 98 | $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
99 | 99 | array( |
100 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
100 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
101 | 101 | ) |
102 | 102 | ); |
103 | 103 | $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
104 | 104 | array( |
105 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
105 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
106 | 106 | ) |
107 | 107 | ); |
108 | 108 | //add cap restrictions for deleting relating to the "ee_deleting_*" |
109 | 109 | $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
110 | 110 | array( |
111 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
111 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
112 | 112 | ) |
113 | 113 | ); |
114 | 114 | $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
115 | 115 | array( |
116 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
116 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
117 | 117 | ) |
118 | 118 | ); |
119 | 119 | $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
120 | 120 | array( |
121 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
121 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
122 | 122 | ) |
123 | 123 | ); |
124 | 124 | parent::__construct($timezone); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | { |
141 | 141 | if ($model === EEM_Term_Taxonomy::instance()) { |
142 | 142 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
143 | - if (! empty($taxonomies)) { |
|
143 | + if ( ! empty($taxonomies)) { |
|
144 | 144 | $model_query_params[0]['taxonomy'] = array('IN', $taxonomies); |
145 | 145 | } |
146 | 146 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -15,206 +15,206 @@ discard block |
||
15 | 15 | class EEM_Term extends EEM_Base |
16 | 16 | { |
17 | 17 | |
18 | - // private instance of the Attendee object |
|
19 | - protected static $_instance = null; |
|
20 | - |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - *__construct |
|
25 | - * |
|
26 | - * @param string $timezone |
|
27 | - */ |
|
28 | - protected function __construct($timezone = null) |
|
29 | - { |
|
30 | - $this->singular_item = __('Term', 'event_espresso'); |
|
31 | - $this->plural_item = __('Terms', 'event_espresso'); |
|
32 | - $this->_tables = array( |
|
33 | - 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
34 | - ); |
|
35 | - $this->_fields = array( |
|
36 | - 'Term' => array( |
|
37 | - 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
38 | - 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
39 | - 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
40 | - 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
41 | - ), |
|
42 | - ); |
|
43 | - $this->_model_relations = array( |
|
44 | - 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
|
45 | - ); |
|
46 | - $path_to_tax_model = 'Term_Taxonomy'; |
|
47 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
48 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
49 | - $path_to_tax_model |
|
50 | - ); |
|
51 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
52 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
53 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
54 | - //add cap restrictions for editing relating to the "ee_edit_*" |
|
55 | - $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
56 | - array( |
|
57 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
58 | - ) |
|
59 | - ); |
|
60 | - $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
61 | - array( |
|
62 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
63 | - ) |
|
64 | - ); |
|
65 | - $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
66 | - array( |
|
67 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
68 | - ) |
|
69 | - ); |
|
70 | - //add cap restrictions for deleting relating to the "ee_deleting_*" |
|
71 | - $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
72 | - array( |
|
73 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
74 | - ) |
|
75 | - ); |
|
76 | - $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
77 | - array( |
|
78 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
79 | - ) |
|
80 | - ); |
|
81 | - $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
82 | - array( |
|
83 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
84 | - ) |
|
85 | - ); |
|
86 | - parent::__construct($timezone); |
|
87 | - add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * retrieves a list of all EE event categories |
|
94 | - * |
|
95 | - * @access public |
|
96 | - * @param bool $show_uncategorized |
|
97 | - * @return \EE_Base_Class[] |
|
98 | - */ |
|
99 | - public function get_all_ee_categories($show_uncategorized = false) |
|
100 | - { |
|
101 | - $where_params = array( |
|
102 | - 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
|
103 | - 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
104 | - ); |
|
105 | - if ($show_uncategorized) { |
|
106 | - unset($where_params['NOT']); |
|
107 | - } |
|
108 | - return EEM_Term::instance()->get_all( |
|
109 | - array( |
|
110 | - $where_params, |
|
111 | - 'order_by' => array('name' => 'ASC'), |
|
112 | - ) |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * retrieves a list of all post_tags associated with an EE CPT |
|
120 | - * |
|
121 | - * @access public |
|
122 | - * @param string $post_type |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function get_all_CPT_post_tags($post_type = '') |
|
126 | - { |
|
127 | - switch ($post_type) { |
|
128 | - case 'espresso_events': |
|
129 | - return $this->get_all_event_post_tags(); |
|
130 | - break; |
|
131 | - case 'espresso_venues': |
|
132 | - return $this->get_all_venue_post_tags(); |
|
133 | - break; |
|
134 | - default: |
|
135 | - $event_tags = $this->get_all_event_post_tags(); |
|
136 | - $venue_tags = $this->get_all_venue_post_tags(); |
|
137 | - return array_merge($event_tags, $venue_tags); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * get_all_event_post_tags |
|
145 | - * |
|
146 | - * @return EE_Base_Class[] |
|
147 | - */ |
|
148 | - public function get_all_event_post_tags() |
|
149 | - { |
|
150 | - $post_tags = EEM_Term::instance()->get_all( |
|
151 | - array( |
|
152 | - array( |
|
153 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
154 | - 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
155 | - ), |
|
156 | - 'order_by' => array('name' => 'ASC'), |
|
157 | - 'force_join' => array('Term_Taxonomy.Event'), |
|
158 | - ) |
|
159 | - ); |
|
160 | - foreach ($post_tags as $key => $post_tag) { |
|
161 | - if (! isset($post_tags[$key]->post_type)) { |
|
162 | - $post_tags[$key]->post_type = array(); |
|
163 | - } |
|
164 | - $post_tags[$key]->post_type[] = 'espresso_events'; |
|
165 | - } |
|
166 | - return $post_tags; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * get_all_venue_post_tags |
|
173 | - * |
|
174 | - * @return EE_Base_Class[] |
|
175 | - */ |
|
176 | - public function get_all_venue_post_tags() |
|
177 | - { |
|
178 | - $post_tags = EEM_Term::instance()->get_all( |
|
179 | - array( |
|
180 | - array( |
|
181 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
182 | - 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
183 | - ), |
|
184 | - 'order_by' => array('name' => 'ASC'), |
|
185 | - 'force_join' => array('Term_Taxonomy'), |
|
186 | - ) |
|
187 | - ); |
|
188 | - foreach ($post_tags as $key => $post_tag) { |
|
189 | - if (! isset($post_tags[$key]->post_type)) { |
|
190 | - $post_tags[$key]->post_type = array(); |
|
191 | - } |
|
192 | - $post_tags[$key]->post_type[] = 'espresso_venues'; |
|
193 | - } |
|
194 | - return $post_tags; |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Makes sure that during REST API queries, we only return terms |
|
201 | - * for term taxonomies which should be shown in the rest api |
|
202 | - * |
|
203 | - * @param array $model_query_params |
|
204 | - * @param array $querystring_query_params |
|
205 | - * @param EEM_Base $model |
|
206 | - * @return array |
|
207 | - */ |
|
208 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
209 | - { |
|
210 | - if ($model === EEM_Term::instance()) { |
|
211 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
212 | - if (! empty($taxonomies)) { |
|
213 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
214 | - } |
|
215 | - } |
|
216 | - return $model_query_params; |
|
217 | - } |
|
18 | + // private instance of the Attendee object |
|
19 | + protected static $_instance = null; |
|
20 | + |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + *__construct |
|
25 | + * |
|
26 | + * @param string $timezone |
|
27 | + */ |
|
28 | + protected function __construct($timezone = null) |
|
29 | + { |
|
30 | + $this->singular_item = __('Term', 'event_espresso'); |
|
31 | + $this->plural_item = __('Terms', 'event_espresso'); |
|
32 | + $this->_tables = array( |
|
33 | + 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
34 | + ); |
|
35 | + $this->_fields = array( |
|
36 | + 'Term' => array( |
|
37 | + 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
38 | + 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
39 | + 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
40 | + 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
41 | + ), |
|
42 | + ); |
|
43 | + $this->_model_relations = array( |
|
44 | + 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
|
45 | + ); |
|
46 | + $path_to_tax_model = 'Term_Taxonomy'; |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
49 | + $path_to_tax_model |
|
50 | + ); |
|
51 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
52 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
53 | + $path_to_tax_model = $path_to_tax_model . '.'; |
|
54 | + //add cap restrictions for editing relating to the "ee_edit_*" |
|
55 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
56 | + array( |
|
57 | + $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
58 | + ) |
|
59 | + ); |
|
60 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
61 | + array( |
|
62 | + $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
63 | + ) |
|
64 | + ); |
|
65 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
66 | + array( |
|
67 | + $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
68 | + ) |
|
69 | + ); |
|
70 | + //add cap restrictions for deleting relating to the "ee_deleting_*" |
|
71 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
72 | + array( |
|
73 | + $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
74 | + ) |
|
75 | + ); |
|
76 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
77 | + array( |
|
78 | + $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
79 | + ) |
|
80 | + ); |
|
81 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
82 | + array( |
|
83 | + $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
84 | + ) |
|
85 | + ); |
|
86 | + parent::__construct($timezone); |
|
87 | + add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * retrieves a list of all EE event categories |
|
94 | + * |
|
95 | + * @access public |
|
96 | + * @param bool $show_uncategorized |
|
97 | + * @return \EE_Base_Class[] |
|
98 | + */ |
|
99 | + public function get_all_ee_categories($show_uncategorized = false) |
|
100 | + { |
|
101 | + $where_params = array( |
|
102 | + 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
|
103 | + 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
104 | + ); |
|
105 | + if ($show_uncategorized) { |
|
106 | + unset($where_params['NOT']); |
|
107 | + } |
|
108 | + return EEM_Term::instance()->get_all( |
|
109 | + array( |
|
110 | + $where_params, |
|
111 | + 'order_by' => array('name' => 'ASC'), |
|
112 | + ) |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * retrieves a list of all post_tags associated with an EE CPT |
|
120 | + * |
|
121 | + * @access public |
|
122 | + * @param string $post_type |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function get_all_CPT_post_tags($post_type = '') |
|
126 | + { |
|
127 | + switch ($post_type) { |
|
128 | + case 'espresso_events': |
|
129 | + return $this->get_all_event_post_tags(); |
|
130 | + break; |
|
131 | + case 'espresso_venues': |
|
132 | + return $this->get_all_venue_post_tags(); |
|
133 | + break; |
|
134 | + default: |
|
135 | + $event_tags = $this->get_all_event_post_tags(); |
|
136 | + $venue_tags = $this->get_all_venue_post_tags(); |
|
137 | + return array_merge($event_tags, $venue_tags); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * get_all_event_post_tags |
|
145 | + * |
|
146 | + * @return EE_Base_Class[] |
|
147 | + */ |
|
148 | + public function get_all_event_post_tags() |
|
149 | + { |
|
150 | + $post_tags = EEM_Term::instance()->get_all( |
|
151 | + array( |
|
152 | + array( |
|
153 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
154 | + 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
155 | + ), |
|
156 | + 'order_by' => array('name' => 'ASC'), |
|
157 | + 'force_join' => array('Term_Taxonomy.Event'), |
|
158 | + ) |
|
159 | + ); |
|
160 | + foreach ($post_tags as $key => $post_tag) { |
|
161 | + if (! isset($post_tags[$key]->post_type)) { |
|
162 | + $post_tags[$key]->post_type = array(); |
|
163 | + } |
|
164 | + $post_tags[$key]->post_type[] = 'espresso_events'; |
|
165 | + } |
|
166 | + return $post_tags; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * get_all_venue_post_tags |
|
173 | + * |
|
174 | + * @return EE_Base_Class[] |
|
175 | + */ |
|
176 | + public function get_all_venue_post_tags() |
|
177 | + { |
|
178 | + $post_tags = EEM_Term::instance()->get_all( |
|
179 | + array( |
|
180 | + array( |
|
181 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
182 | + 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
183 | + ), |
|
184 | + 'order_by' => array('name' => 'ASC'), |
|
185 | + 'force_join' => array('Term_Taxonomy'), |
|
186 | + ) |
|
187 | + ); |
|
188 | + foreach ($post_tags as $key => $post_tag) { |
|
189 | + if (! isset($post_tags[$key]->post_type)) { |
|
190 | + $post_tags[$key]->post_type = array(); |
|
191 | + } |
|
192 | + $post_tags[$key]->post_type[] = 'espresso_venues'; |
|
193 | + } |
|
194 | + return $post_tags; |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Makes sure that during REST API queries, we only return terms |
|
201 | + * for term taxonomies which should be shown in the rest api |
|
202 | + * |
|
203 | + * @param array $model_query_params |
|
204 | + * @param array $querystring_query_params |
|
205 | + * @param EEM_Base $model |
|
206 | + * @return array |
|
207 | + */ |
|
208 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
209 | + { |
|
210 | + if ($model === EEM_Term::instance()) { |
|
211 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
212 | + if (! empty($taxonomies)) { |
|
213 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
214 | + } |
|
215 | + } |
|
216 | + return $model_query_params; |
|
217 | + } |
|
218 | 218 | |
219 | 219 | |
220 | 220 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -50,37 +50,37 @@ discard block |
||
50 | 50 | ); |
51 | 51 | $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
52 | 52 | $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
53 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
53 | + $path_to_tax_model = $path_to_tax_model.'.'; |
|
54 | 54 | //add cap restrictions for editing relating to the "ee_edit_*" |
55 | 55 | $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
56 | 56 | array( |
57 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
57 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
58 | 58 | ) |
59 | 59 | ); |
60 | 60 | $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
61 | 61 | array( |
62 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
62 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
63 | 63 | ) |
64 | 64 | ); |
65 | 65 | $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
66 | 66 | array( |
67 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
67 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
68 | 68 | ) |
69 | 69 | ); |
70 | 70 | //add cap restrictions for deleting relating to the "ee_deleting_*" |
71 | 71 | $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
72 | 72 | array( |
73 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
73 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
74 | 74 | ) |
75 | 75 | ); |
76 | 76 | $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
77 | 77 | array( |
78 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
78 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
79 | 79 | ) |
80 | 80 | ); |
81 | 81 | $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
82 | 82 | array( |
83 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
83 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
84 | 84 | ) |
85 | 85 | ); |
86 | 86 | parent::__construct($timezone); |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | ) |
159 | 159 | ); |
160 | 160 | foreach ($post_tags as $key => $post_tag) { |
161 | - if (! isset($post_tags[$key]->post_type)) { |
|
161 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
162 | 162 | $post_tags[$key]->post_type = array(); |
163 | 163 | } |
164 | 164 | $post_tags[$key]->post_type[] = 'espresso_events'; |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | ) |
187 | 187 | ); |
188 | 188 | foreach ($post_tags as $key => $post_tag) { |
189 | - if (! isset($post_tags[$key]->post_type)) { |
|
189 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
190 | 190 | $post_tags[$key]->post_type = array(); |
191 | 191 | } |
192 | 192 | $post_tags[$key]->post_type[] = 'espresso_venues'; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | { |
210 | 210 | if ($model === EEM_Term::instance()) { |
211 | 211 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
212 | - if (! empty($taxonomies)) { |
|
212 | + if ( ! empty($taxonomies)) { |
|
213 | 213 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
214 | 214 | } |
215 | 215 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -33,57 +33,57 @@ discard block |
||
33 | 33 | class EEM_Post_Meta extends EEM_Base |
34 | 34 | { |
35 | 35 | |
36 | - // private instance of the EE_Post_Meta object |
|
37 | - protected static $_instance = null; |
|
36 | + // private instance of the EE_Post_Meta object |
|
37 | + protected static $_instance = null; |
|
38 | 38 | |
39 | 39 | |
40 | 40 | |
41 | - protected function __construct($timezone = null) |
|
42 | - { |
|
43 | - $this->singular_item = __('Post Meta', 'event_espresso'); |
|
44 | - $this->plural_item = __('Post Metas', 'event_espresso'); |
|
45 | - $this->_tables = array( |
|
46 | - 'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'), |
|
47 | - ); |
|
48 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
49 | - $this->_fields = array( |
|
50 | - 'Post_Meta' => array( |
|
51 | - 'meta_id' => new EE_Primary_Key_Int_Field( |
|
52 | - 'meta_id', |
|
53 | - __("Meta ID", "event_espresso") |
|
54 | - ), |
|
55 | - 'post_id' => new EE_Foreign_Key_Int_Field( |
|
56 | - 'post_id', |
|
57 | - __("Primary Key of Post", "event_espresso"), |
|
58 | - false, |
|
59 | - 0, |
|
60 | - $models_this_can_attach_to |
|
61 | - ), |
|
62 | - 'meta_key' => new EE_Plain_Text_Field( |
|
63 | - 'meta_key', |
|
64 | - __("Meta Key", "event_espresso"), |
|
65 | - false, |
|
66 | - '' |
|
67 | - ), |
|
68 | - 'meta_value' => new EE_Maybe_Serialized_Text_Field( |
|
69 | - 'meta_value', |
|
70 | - __("Meta Value", "event_espresso"), |
|
71 | - true |
|
72 | - ), |
|
73 | - ), |
|
74 | - ); |
|
75 | - $this->_model_relations = array(); |
|
76 | - foreach ($models_this_can_attach_to as $model) { |
|
77 | - $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
|
78 | - } |
|
79 | - foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
80 | - $this->_cap_restriction_generators[$cap_context] = new EE_Restriction_Generator_Meta( |
|
81 | - 'meta_key', |
|
82 | - 'meta_value' |
|
83 | - ); |
|
84 | - } |
|
85 | - parent::__construct($timezone); |
|
86 | - } |
|
41 | + protected function __construct($timezone = null) |
|
42 | + { |
|
43 | + $this->singular_item = __('Post Meta', 'event_espresso'); |
|
44 | + $this->plural_item = __('Post Metas', 'event_espresso'); |
|
45 | + $this->_tables = array( |
|
46 | + 'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'), |
|
47 | + ); |
|
48 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
49 | + $this->_fields = array( |
|
50 | + 'Post_Meta' => array( |
|
51 | + 'meta_id' => new EE_Primary_Key_Int_Field( |
|
52 | + 'meta_id', |
|
53 | + __("Meta ID", "event_espresso") |
|
54 | + ), |
|
55 | + 'post_id' => new EE_Foreign_Key_Int_Field( |
|
56 | + 'post_id', |
|
57 | + __("Primary Key of Post", "event_espresso"), |
|
58 | + false, |
|
59 | + 0, |
|
60 | + $models_this_can_attach_to |
|
61 | + ), |
|
62 | + 'meta_key' => new EE_Plain_Text_Field( |
|
63 | + 'meta_key', |
|
64 | + __("Meta Key", "event_espresso"), |
|
65 | + false, |
|
66 | + '' |
|
67 | + ), |
|
68 | + 'meta_value' => new EE_Maybe_Serialized_Text_Field( |
|
69 | + 'meta_value', |
|
70 | + __("Meta Value", "event_espresso"), |
|
71 | + true |
|
72 | + ), |
|
73 | + ), |
|
74 | + ); |
|
75 | + $this->_model_relations = array(); |
|
76 | + foreach ($models_this_can_attach_to as $model) { |
|
77 | + $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
|
78 | + } |
|
79 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
80 | + $this->_cap_restriction_generators[$cap_context] = new EE_Restriction_Generator_Meta( |
|
81 | + 'meta_key', |
|
82 | + 'meta_value' |
|
83 | + ); |
|
84 | + } |
|
85 | + parent::__construct($timezone); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | 89 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | /** |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @author Michael Nelson |
27 | 27 | * ------------------------------------------------------------------------ |
28 | 28 | */ |
29 | -require_once(EE_MODELS . 'EEM_Base.model.php'); |
|
29 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
30 | 30 | |
31 | 31 | |
32 | 32 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | require_once(EE_MODELS . 'EEM_Base.model.php'); |
5 | 5 | |
@@ -15,229 +15,229 @@ discard block |
||
15 | 15 | class EEM_Term_Relationship extends EEM_Base |
16 | 16 | { |
17 | 17 | |
18 | - // private instance of the Attendee object |
|
19 | - protected static $_instance = null; |
|
20 | - |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * EEM_Term_Relationship constructor. |
|
25 | - * |
|
26 | - * @param string $timezone |
|
27 | - */ |
|
28 | - protected function __construct($timezone = null) |
|
29 | - { |
|
30 | - $this->singular_item = __('Term Relationship', 'event_espresso'); |
|
31 | - $this->plural_item = __('Term Relationships', 'event_espresso'); |
|
32 | - $this->_tables = array( |
|
33 | - 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
34 | - ); |
|
35 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
36 | - $this->_fields = array( |
|
37 | - 'Term_Relationship' => array( |
|
38 | - 'object_id' => new EE_Foreign_Key_Int_Field( |
|
39 | - 'object_id', |
|
40 | - __('Object(Post) ID', 'event_espresso'), |
|
41 | - false, |
|
42 | - 0, |
|
43 | - $models_this_can_attach_to |
|
44 | - ), |
|
45 | - 'term_taxonomy_id' => new EE_Foreign_Key_Int_Field( |
|
46 | - 'term_taxonomy_id', |
|
47 | - __( |
|
48 | - 'Term (in context of a taxonomy) ID', |
|
49 | - 'event_espresso' |
|
50 | - ), |
|
51 | - false, |
|
52 | - 0, |
|
53 | - 'Term_Taxonomy' |
|
54 | - ), |
|
55 | - 'term_order' => new EE_Integer_Field( |
|
56 | - 'term_order', |
|
57 | - __('Term Order', 'event_espresso'), |
|
58 | - false, |
|
59 | - 0 |
|
60 | - ), |
|
61 | - ), |
|
62 | - ); |
|
63 | - $this->_model_relations = array( |
|
64 | - 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
|
65 | - ); |
|
66 | - foreach ($models_this_can_attach_to as $model_name) { |
|
67 | - $this->_model_relations[$model_name] = new EE_Belongs_To_Relation(); |
|
68 | - } |
|
69 | - $this->_indexes = array( |
|
70 | - 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
|
71 | - ); |
|
72 | - $path_to_event_model = 'Event.'; |
|
73 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
74 | - $path_to_event_model |
|
75 | - ); |
|
76 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
77 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
78 | - $path_to_event_model |
|
79 | - ); |
|
80 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
81 | - $path_to_event_model |
|
82 | - ); |
|
83 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
84 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
85 | - $path_to_event_model, |
|
86 | - EEM_Base::caps_edit |
|
87 | - ); |
|
88 | - $path_to_tax_model = 'Term_Taxonomy.'; |
|
89 | - //add cap restrictions for editing term relations to the "ee_assign_*" |
|
90 | - //and for deleting term relations too |
|
91 | - $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
|
92 | - foreach ($cap_contexts_affected as $cap_context_affected) { |
|
93 | - $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] = |
|
94 | - new EE_Default_Where_Conditions( |
|
95 | - array( |
|
96 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
97 | - '!=', |
|
98 | - 'espresso_event_categories', |
|
99 | - ), |
|
100 | - ) |
|
101 | - ); |
|
102 | - $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] = |
|
103 | - new EE_Default_Where_Conditions( |
|
104 | - array( |
|
105 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
106 | - '!=', |
|
107 | - 'espresso_venue_categories', |
|
108 | - ), |
|
109 | - ) |
|
110 | - ); |
|
111 | - $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
112 | - array( |
|
113 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
114 | - ) |
|
115 | - ); |
|
116 | - } |
|
117 | - parent::__construct($timezone); |
|
118 | - add_filter( |
|
119 | - 'FHEE__Read__create_model_query_params', |
|
120 | - array('EEM_Term_Relationship', 'rest_api_query_params'), |
|
121 | - 10, |
|
122 | - 3 |
|
123 | - ); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * Makes sure all term-taxonomy counts are correct |
|
130 | - * |
|
131 | - * @param int $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL |
|
132 | - * @global wpdb $wpdb |
|
133 | - * @return int the number of rows affected |
|
134 | - */ |
|
135 | - public function update_term_taxonomy_counts($term_taxonomy_id = null) |
|
136 | - { |
|
137 | - //because this uses a subquery and sometimes assigning to column to be another column's |
|
138 | - //value, we just write the SQL directly. |
|
139 | - global $wpdb; |
|
140 | - if ($term_taxonomy_id) { |
|
141 | - $second_operand = $wpdb->prepare('%d', $term_taxonomy_id); |
|
142 | - } else { |
|
143 | - $second_operand = 'tr.term_taxonomy_id'; |
|
144 | - } |
|
145 | - $rows_affected = $this->_do_wpdb_query( |
|
146 | - 'query', |
|
147 | - array( |
|
148 | - " |
|
18 | + // private instance of the Attendee object |
|
19 | + protected static $_instance = null; |
|
20 | + |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * EEM_Term_Relationship constructor. |
|
25 | + * |
|
26 | + * @param string $timezone |
|
27 | + */ |
|
28 | + protected function __construct($timezone = null) |
|
29 | + { |
|
30 | + $this->singular_item = __('Term Relationship', 'event_espresso'); |
|
31 | + $this->plural_item = __('Term Relationships', 'event_espresso'); |
|
32 | + $this->_tables = array( |
|
33 | + 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
34 | + ); |
|
35 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
36 | + $this->_fields = array( |
|
37 | + 'Term_Relationship' => array( |
|
38 | + 'object_id' => new EE_Foreign_Key_Int_Field( |
|
39 | + 'object_id', |
|
40 | + __('Object(Post) ID', 'event_espresso'), |
|
41 | + false, |
|
42 | + 0, |
|
43 | + $models_this_can_attach_to |
|
44 | + ), |
|
45 | + 'term_taxonomy_id' => new EE_Foreign_Key_Int_Field( |
|
46 | + 'term_taxonomy_id', |
|
47 | + __( |
|
48 | + 'Term (in context of a taxonomy) ID', |
|
49 | + 'event_espresso' |
|
50 | + ), |
|
51 | + false, |
|
52 | + 0, |
|
53 | + 'Term_Taxonomy' |
|
54 | + ), |
|
55 | + 'term_order' => new EE_Integer_Field( |
|
56 | + 'term_order', |
|
57 | + __('Term Order', 'event_espresso'), |
|
58 | + false, |
|
59 | + 0 |
|
60 | + ), |
|
61 | + ), |
|
62 | + ); |
|
63 | + $this->_model_relations = array( |
|
64 | + 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
|
65 | + ); |
|
66 | + foreach ($models_this_can_attach_to as $model_name) { |
|
67 | + $this->_model_relations[$model_name] = new EE_Belongs_To_Relation(); |
|
68 | + } |
|
69 | + $this->_indexes = array( |
|
70 | + 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
|
71 | + ); |
|
72 | + $path_to_event_model = 'Event.'; |
|
73 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
74 | + $path_to_event_model |
|
75 | + ); |
|
76 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
77 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
78 | + $path_to_event_model |
|
79 | + ); |
|
80 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
81 | + $path_to_event_model |
|
82 | + ); |
|
83 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
84 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
85 | + $path_to_event_model, |
|
86 | + EEM_Base::caps_edit |
|
87 | + ); |
|
88 | + $path_to_tax_model = 'Term_Taxonomy.'; |
|
89 | + //add cap restrictions for editing term relations to the "ee_assign_*" |
|
90 | + //and for deleting term relations too |
|
91 | + $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
|
92 | + foreach ($cap_contexts_affected as $cap_context_affected) { |
|
93 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] = |
|
94 | + new EE_Default_Where_Conditions( |
|
95 | + array( |
|
96 | + $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
97 | + '!=', |
|
98 | + 'espresso_event_categories', |
|
99 | + ), |
|
100 | + ) |
|
101 | + ); |
|
102 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] = |
|
103 | + new EE_Default_Where_Conditions( |
|
104 | + array( |
|
105 | + $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
106 | + '!=', |
|
107 | + 'espresso_venue_categories', |
|
108 | + ), |
|
109 | + ) |
|
110 | + ); |
|
111 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
112 | + array( |
|
113 | + $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
114 | + ) |
|
115 | + ); |
|
116 | + } |
|
117 | + parent::__construct($timezone); |
|
118 | + add_filter( |
|
119 | + 'FHEE__Read__create_model_query_params', |
|
120 | + array('EEM_Term_Relationship', 'rest_api_query_params'), |
|
121 | + 10, |
|
122 | + 3 |
|
123 | + ); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * Makes sure all term-taxonomy counts are correct |
|
130 | + * |
|
131 | + * @param int $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL |
|
132 | + * @global wpdb $wpdb |
|
133 | + * @return int the number of rows affected |
|
134 | + */ |
|
135 | + public function update_term_taxonomy_counts($term_taxonomy_id = null) |
|
136 | + { |
|
137 | + //because this uses a subquery and sometimes assigning to column to be another column's |
|
138 | + //value, we just write the SQL directly. |
|
139 | + global $wpdb; |
|
140 | + if ($term_taxonomy_id) { |
|
141 | + $second_operand = $wpdb->prepare('%d', $term_taxonomy_id); |
|
142 | + } else { |
|
143 | + $second_operand = 'tr.term_taxonomy_id'; |
|
144 | + } |
|
145 | + $rows_affected = $this->_do_wpdb_query( |
|
146 | + 'query', |
|
147 | + array( |
|
148 | + " |
|
149 | 149 | UPDATE {$wpdb->term_taxonomy} AS tt |
150 | 150 | SET count = ( |
151 | 151 | select count(*) as proper_count from {$wpdb->term_relationships} AS tr |
152 | 152 | WHERE tt.term_taxonomy_id = $second_operand |
153 | 153 | )", |
154 | - ) |
|
155 | - ); |
|
156 | - return $rows_affected; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Overrides the parent to also make sure term-taxonomy counts are up-to-date after |
|
163 | - * inserting |
|
164 | - * |
|
165 | - * @param array $field_n_values @see EEM_Base::insert |
|
166 | - * @return boolean |
|
167 | - */ |
|
168 | - public function insert($field_n_values) |
|
169 | - { |
|
170 | - $return = parent::insert($field_n_values); |
|
171 | - if (isset($field_n_values['term_taxonomy_id'])) { |
|
172 | - $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
173 | - } |
|
174 | - return $return; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Overrides parent so that after an update, we also check the term_taxonomy_counts are |
|
181 | - * all ok |
|
182 | - * |
|
183 | - * @param array $fields_n_values see EEM_Base::update |
|
184 | - * @param array $query_params @see EEM_Base::get_all |
|
185 | - * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
186 | - * in this model's entity map according to $fields_n_values that match |
|
187 | - * $query_params. This obviously has some overhead, so you can disable it |
|
188 | - * by setting this to FALSE, but be aware that model objects being used |
|
189 | - * could get out-of-sync with the database |
|
190 | - * @return int |
|
191 | - */ |
|
192 | - public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
193 | - { |
|
194 | - $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
195 | - if ($count) { |
|
196 | - $this->update_term_taxonomy_counts(); |
|
197 | - } |
|
198 | - return $count; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Overrides parent so that after running this, we also double-check |
|
205 | - * the term taxonomy counts are up-to-date |
|
206 | - * |
|
207 | - * @param array $query_params @see EEM_Base::get_all |
|
208 | - * @param boolean $allow_blocking |
|
209 | - * @return int @see EEM_Base::delete |
|
210 | - */ |
|
211 | - public function delete($query_params, $allow_blocking = true) |
|
212 | - { |
|
213 | - $count = parent::delete($query_params, $allow_blocking); |
|
214 | - if ($count) { |
|
215 | - $this->update_term_taxonomy_counts(); |
|
216 | - } |
|
217 | - return $count; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * Makes sure that during REST API queries, we only return term relationships |
|
224 | - * for term taxonomies which should be shown in the rest api |
|
225 | - * |
|
226 | - * @param array $model_query_params |
|
227 | - * @param array $querystring_query_params |
|
228 | - * @param EEM_Base $model |
|
229 | - * @return array |
|
230 | - */ |
|
231 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
232 | - { |
|
233 | - if ($model === EEM_Term_Relationship::instance()) { |
|
234 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
235 | - if (! empty($taxonomies)) { |
|
236 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
237 | - } |
|
238 | - } |
|
239 | - return $model_query_params; |
|
240 | - } |
|
154 | + ) |
|
155 | + ); |
|
156 | + return $rows_affected; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Overrides the parent to also make sure term-taxonomy counts are up-to-date after |
|
163 | + * inserting |
|
164 | + * |
|
165 | + * @param array $field_n_values @see EEM_Base::insert |
|
166 | + * @return boolean |
|
167 | + */ |
|
168 | + public function insert($field_n_values) |
|
169 | + { |
|
170 | + $return = parent::insert($field_n_values); |
|
171 | + if (isset($field_n_values['term_taxonomy_id'])) { |
|
172 | + $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
173 | + } |
|
174 | + return $return; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Overrides parent so that after an update, we also check the term_taxonomy_counts are |
|
181 | + * all ok |
|
182 | + * |
|
183 | + * @param array $fields_n_values see EEM_Base::update |
|
184 | + * @param array $query_params @see EEM_Base::get_all |
|
185 | + * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
186 | + * in this model's entity map according to $fields_n_values that match |
|
187 | + * $query_params. This obviously has some overhead, so you can disable it |
|
188 | + * by setting this to FALSE, but be aware that model objects being used |
|
189 | + * could get out-of-sync with the database |
|
190 | + * @return int |
|
191 | + */ |
|
192 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
193 | + { |
|
194 | + $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
195 | + if ($count) { |
|
196 | + $this->update_term_taxonomy_counts(); |
|
197 | + } |
|
198 | + return $count; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Overrides parent so that after running this, we also double-check |
|
205 | + * the term taxonomy counts are up-to-date |
|
206 | + * |
|
207 | + * @param array $query_params @see EEM_Base::get_all |
|
208 | + * @param boolean $allow_blocking |
|
209 | + * @return int @see EEM_Base::delete |
|
210 | + */ |
|
211 | + public function delete($query_params, $allow_blocking = true) |
|
212 | + { |
|
213 | + $count = parent::delete($query_params, $allow_blocking); |
|
214 | + if ($count) { |
|
215 | + $this->update_term_taxonomy_counts(); |
|
216 | + } |
|
217 | + return $count; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * Makes sure that during REST API queries, we only return term relationships |
|
224 | + * for term taxonomies which should be shown in the rest api |
|
225 | + * |
|
226 | + * @param array $model_query_params |
|
227 | + * @param array $querystring_query_params |
|
228 | + * @param EEM_Base $model |
|
229 | + * @return array |
|
230 | + */ |
|
231 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
232 | + { |
|
233 | + if ($model === EEM_Term_Relationship::instance()) { |
|
234 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
235 | + if (! empty($taxonomies)) { |
|
236 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
237 | + } |
|
238 | + } |
|
239 | + return $model_query_params; |
|
240 | + } |
|
241 | 241 | |
242 | 242 | |
243 | 243 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | -require_once(EE_MODELS . 'EEM_Base.model.php'); |
|
4 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
5 | 5 | |
6 | 6 | |
7 | 7 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] = |
94 | 94 | new EE_Default_Where_Conditions( |
95 | 95 | array( |
96 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
96 | + $path_to_tax_model.'taxonomy*ee_assign_event_category' => array( |
|
97 | 97 | '!=', |
98 | 98 | 'espresso_event_categories', |
99 | 99 | ), |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] = |
103 | 103 | new EE_Default_Where_Conditions( |
104 | 104 | array( |
105 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
105 | + $path_to_tax_model.'taxonomy*ee_assign_venue_category' => array( |
|
106 | 106 | '!=', |
107 | 107 | 'espresso_venue_categories', |
108 | 108 | ), |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | ); |
111 | 111 | $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
112 | 112 | array( |
113 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
113 | + $path_to_tax_model.'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
114 | 114 | ) |
115 | 115 | ); |
116 | 116 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | { |
233 | 233 | if ($model === EEM_Term_Relationship::instance()) { |
234 | 234 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
235 | - if (! empty($taxonomies)) { |
|
235 | + if ( ! empty($taxonomies)) { |
|
236 | 236 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
237 | 237 | } |
238 | 238 | } |
@@ -11,14 +11,14 @@ discard block |
||
11 | 11 | <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/> |
12 | 12 | <?php |
13 | 13 | if ( $ticket instanceof EE_Ticket ) { |
14 | - do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event ); |
|
15 | - $ticket_description = $ticket->description(); |
|
16 | - $ticket_description .= ! empty( $ticket_description ) |
|
17 | - ? '<br />' . $ticket_status_display |
|
18 | - : $ticket_status_display; |
|
19 | - if (strpos( $ticket_description, '<div' ) === false) { |
|
20 | - $ticket_description = "<p>{$ticket_description}</p>"; |
|
21 | - } |
|
14 | + do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event ); |
|
15 | + $ticket_description = $ticket->description(); |
|
16 | + $ticket_description .= ! empty( $ticket_description ) |
|
17 | + ? '<br />' . $ticket_status_display |
|
18 | + : $ticket_status_display; |
|
19 | + if (strpos( $ticket_description, '<div' ) === false) { |
|
20 | + $ticket_description = "<p>{$ticket_description}</p>"; |
|
21 | + } |
|
22 | 22 | ?> |
23 | 23 | <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv"> |
24 | 24 | <div class="no-tkt-slctr-ticket-content-dv"> |
@@ -28,6 +28,6 @@ discard block |
||
28 | 28 | <?php } ?> |
29 | 29 | </div><!-- .no-tkt-slctr-ticket-content-dv --> |
30 | 30 | <?php |
31 | - do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event ); |
|
31 | + do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event ); |
|
32 | 32 | } |
33 | 33 | ?> |
@@ -10,24 +10,24 @@ |
||
10 | 10 | <input type="hidden" name="tkt-slctr-qty-<?php echo $EVT_ID; ?>[]" value="1"/> |
11 | 11 | <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/> |
12 | 12 | <?php |
13 | -if ( $ticket instanceof EE_Ticket ) { |
|
14 | - do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event ); |
|
13 | +if ($ticket instanceof EE_Ticket) { |
|
14 | + do_action('AHEE__ticket_selector_chart__template__before_ticket_selector', $event); |
|
15 | 15 | $ticket_description = $ticket->description(); |
16 | - $ticket_description .= ! empty( $ticket_description ) |
|
17 | - ? '<br />' . $ticket_status_display |
|
16 | + $ticket_description .= ! empty($ticket_description) |
|
17 | + ? '<br />'.$ticket_status_display |
|
18 | 18 | : $ticket_status_display; |
19 | - if (strpos( $ticket_description, '<div' ) === false) { |
|
19 | + if (strpos($ticket_description, '<div') === false) { |
|
20 | 20 | $ticket_description = "<p>{$ticket_description}</p>"; |
21 | 21 | } |
22 | 22 | ?> |
23 | 23 | <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv"> |
24 | 24 | <div class="no-tkt-slctr-ticket-content-dv"> |
25 | 25 | <h5><?php echo $ticket->name(); ?></h5> |
26 | - <?php if ( ! empty( $ticket_description ) ) { ?> |
|
26 | + <?php if ( ! empty($ticket_description)) { ?> |
|
27 | 27 | <?php echo $ticket_description; ?> |
28 | 28 | <?php } ?> |
29 | 29 | </div><!-- .no-tkt-slctr-ticket-content-dv --> |
30 | 30 | <?php |
31 | - do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event ); |
|
31 | + do_action('AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event); |
|
32 | 32 | } |
33 | 33 | ?> |