@@ -19,692 +19,692 @@ |
||
| 19 | 19 | class EE_Encryption implements InterminableInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * key used for saving the encryption key to the wp_options table |
|
| 24 | - */ |
|
| 25 | - const ENCRYPTION_OPTION_KEY = 'ee_encryption_key'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * the OPENSSL cipher method used |
|
| 29 | - */ |
|
| 30 | - const OPENSSL_CIPHER_METHOD = 'AES-128-CBC'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * WP "options_name" used to store a verified available cipher method |
|
| 34 | - */ |
|
| 35 | - const OPENSSL_CIPHER_METHOD_OPTION_NAME = 'ee_openssl_cipher_method'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * the OPENSSL digest method used |
|
| 39 | - */ |
|
| 40 | - const OPENSSL_DIGEST_METHOD = 'sha512'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * separates the encrypted text from the initialization vector |
|
| 44 | - */ |
|
| 45 | - const OPENSSL_IV_DELIMITER = ':iv:'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * appended to text encrypted using the acme encryption |
|
| 49 | - */ |
|
| 50 | - const ACME_ENCRYPTION_FLAG = '::ae'; |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * instance of the EE_Encryption object |
|
| 56 | - */ |
|
| 57 | - protected static $_instance; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var string $_encryption_key |
|
| 61 | - */ |
|
| 62 | - protected $_encryption_key; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @var string $cipher_method |
|
| 66 | - */ |
|
| 67 | - private $cipher_method = ''; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @var array $cipher_methods |
|
| 71 | - */ |
|
| 72 | - private $cipher_methods = array(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @var array $digest_methods |
|
| 76 | - */ |
|
| 77 | - private $digest_methods = array(); |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @var boolean $_use_openssl_encrypt |
|
| 81 | - */ |
|
| 82 | - protected $_use_openssl_encrypt = false; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @var boolean $_use_mcrypt |
|
| 86 | - */ |
|
| 87 | - protected $_use_mcrypt = false; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @var boolean $_use_base64_encode |
|
| 91 | - */ |
|
| 92 | - protected $_use_base64_encode = false; |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * protected constructor to prevent direct creation |
|
| 98 | - */ |
|
| 99 | - protected function __construct() |
|
| 100 | - { |
|
| 101 | - if (! defined('ESPRESSO_ENCRYPT')) { |
|
| 102 | - define('ESPRESSO_ENCRYPT', true); |
|
| 103 | - } |
|
| 104 | - if (extension_loaded('openssl')) { |
|
| 105 | - $this->_use_openssl_encrypt = true; |
|
| 106 | - } else if (extension_loaded('mcrypt')) { |
|
| 107 | - $this->_use_mcrypt = true; |
|
| 108 | - } |
|
| 109 | - if (function_exists('base64_encode')) { |
|
| 110 | - $this->_use_base64_encode = true; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * singleton method used to instantiate class object |
|
| 118 | - * |
|
| 119 | - * @return EE_Encryption |
|
| 120 | - */ |
|
| 121 | - public static function instance() |
|
| 122 | - { |
|
| 123 | - // check if class object is instantiated |
|
| 124 | - if (! EE_Encryption::$_instance instanceof EE_Encryption) { |
|
| 125 | - EE_Encryption::$_instance = new self(); |
|
| 126 | - } |
|
| 127 | - return EE_Encryption::$_instance; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * get encryption key |
|
| 134 | - * |
|
| 135 | - * @return string |
|
| 136 | - */ |
|
| 137 | - public function get_encryption_key() |
|
| 138 | - { |
|
| 139 | - // if encryption key has not been set |
|
| 140 | - if (empty($this->_encryption_key)) { |
|
| 141 | - // retrieve encryption_key from db |
|
| 142 | - $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, ''); |
|
| 143 | - // WHAT?? No encryption_key in the db ?? |
|
| 144 | - if ($this->_encryption_key === '') { |
|
| 145 | - // let's make one. And md5 it to make it just the right size for a key |
|
| 146 | - $new_key = md5($this->generate_random_string()); |
|
| 147 | - // now save it to the db for later |
|
| 148 | - add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key); |
|
| 149 | - // here's the key - FINALLY ! |
|
| 150 | - $this->_encryption_key = $new_key; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - return $this->_encryption_key; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * encrypts data |
|
| 160 | - * |
|
| 161 | - * @param string $text_string - the text to be encrypted |
|
| 162 | - * @return string |
|
| 163 | - * @throws RuntimeException |
|
| 164 | - */ |
|
| 165 | - public function encrypt($text_string = '') |
|
| 166 | - { |
|
| 167 | - // you give me nothing??? GET OUT ! |
|
| 168 | - if (empty($text_string)) { |
|
| 169 | - return $text_string; |
|
| 170 | - } |
|
| 171 | - if ($this->_use_openssl_encrypt) { |
|
| 172 | - $encrypted_text = $this->openssl_encrypt($text_string); |
|
| 173 | - } else { |
|
| 174 | - $encrypted_text = $this->acme_encrypt($text_string); |
|
| 175 | - } |
|
| 176 | - return $encrypted_text; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * decrypts data |
|
| 183 | - * |
|
| 184 | - * @param string $encrypted_text - the text to be decrypted |
|
| 185 | - * @return string |
|
| 186 | - * @throws RuntimeException |
|
| 187 | - */ |
|
| 188 | - public function decrypt($encrypted_text = '') |
|
| 189 | - { |
|
| 190 | - // you give me nothing??? GET OUT ! |
|
| 191 | - if (empty($encrypted_text)) { |
|
| 192 | - return $encrypted_text; |
|
| 193 | - } |
|
| 194 | - // if PHP's mcrypt functions are installed then we'll use them |
|
| 195 | - if ($this->_use_openssl_encrypt) { |
|
| 196 | - $decrypted_text = $this->openssl_decrypt($encrypted_text); |
|
| 197 | - } else { |
|
| 198 | - $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
| 199 | - } |
|
| 200 | - return $decrypted_text; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * encodes string with PHP's base64 encoding |
|
| 207 | - * |
|
| 208 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
| 209 | - * @param string $text_string the text to be encoded |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 212 | - public function base64_string_encode($text_string = '') |
|
| 213 | - { |
|
| 214 | - // you give me nothing??? GET OUT ! |
|
| 215 | - if (empty($text_string) || ! $this->_use_base64_encode) { |
|
| 216 | - return $text_string; |
|
| 217 | - } |
|
| 218 | - // encode |
|
| 219 | - return base64_encode($text_string); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * decodes string that has been encoded with PHP's base64 encoding |
|
| 225 | - * |
|
| 226 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
| 227 | - * @param string $encoded_string the text to be decoded |
|
| 228 | - * @return string |
|
| 229 | - * @throws RuntimeException |
|
| 230 | - */ |
|
| 231 | - public function base64_string_decode($encoded_string = '') |
|
| 232 | - { |
|
| 233 | - // you give me nothing??? GET OUT ! |
|
| 234 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 235 | - return $encoded_string; |
|
| 236 | - } |
|
| 237 | - // decode |
|
| 238 | - $decoded_string = base64_decode($encoded_string); |
|
| 239 | - if ($decoded_string === false) { |
|
| 240 | - throw new RuntimeException( |
|
| 241 | - esc_html__('Base 64 decoding failed.', 'event_espresso') |
|
| 242 | - ); |
|
| 243 | - } |
|
| 244 | - return $decoded_string; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * encodes url string with PHP's base64 encoding |
|
| 251 | - * |
|
| 252 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
| 253 | - * @param string $text_string the text to be encoded |
|
| 254 | - * @return string |
|
| 255 | - */ |
|
| 256 | - public function base64_url_encode($text_string = '') |
|
| 257 | - { |
|
| 258 | - // you give me nothing??? GET OUT ! |
|
| 259 | - if (empty($text_string) || ! $this->_use_base64_encode) { |
|
| 260 | - return $text_string; |
|
| 261 | - } |
|
| 262 | - // encode |
|
| 263 | - $encoded_string = base64_encode($text_string); |
|
| 264 | - // remove chars to make encoding more URL friendly |
|
| 265 | - return strtr($encoded_string, '+/=', '-_,'); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * decodes url string that has been encoded with PHP's base64 encoding |
|
| 271 | - * |
|
| 272 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
| 273 | - * @param string $encoded_string the text to be decoded |
|
| 274 | - * @return string |
|
| 275 | - * @throws RuntimeException |
|
| 276 | - */ |
|
| 277 | - public function base64_url_decode($encoded_string = '') |
|
| 278 | - { |
|
| 279 | - // you give me nothing??? GET OUT ! |
|
| 280 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 281 | - return $encoded_string; |
|
| 282 | - } |
|
| 283 | - // replace previously removed characters |
|
| 284 | - $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
| 285 | - // decode |
|
| 286 | - $decoded_string = base64_decode($encoded_string); |
|
| 287 | - if ($decoded_string === false) { |
|
| 288 | - throw new RuntimeException( |
|
| 289 | - esc_html__('Base 64 decoding failed.', 'event_espresso') |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - return $decoded_string; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * encrypts data using PHP's openssl functions |
|
| 298 | - * |
|
| 299 | - * @param string $text_string the text to be encrypted |
|
| 300 | - * @param string $cipher_method |
|
| 301 | - * @param string $encryption_key |
|
| 302 | - * @return string |
|
| 303 | - * @throws RuntimeException |
|
| 304 | - */ |
|
| 305 | - protected function openssl_encrypt( |
|
| 306 | - $text_string = '', |
|
| 307 | - $cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
| 308 | - $encryption_key = '' |
|
| 309 | - ) { |
|
| 310 | - // you give me nothing??? GET OUT ! |
|
| 311 | - if (empty($text_string)) { |
|
| 312 | - return $text_string; |
|
| 313 | - } |
|
| 314 | - $this->cipher_method = $this->getCipherMethod($cipher_method); |
|
| 315 | - // get initialization vector size |
|
| 316 | - $iv_size = openssl_cipher_iv_length($this->cipher_method); |
|
| 317 | - // generate initialization vector. |
|
| 318 | - // The second parameter ("crypto_strong") is passed by reference, |
|
| 319 | - // and is used to determines if the algorithm used was "cryptographically strong" |
|
| 320 | - // openssl_random_pseudo_bytes() will toggle it to either true or false |
|
| 321 | - $iv = openssl_random_pseudo_bytes($iv_size, $is_strong); |
|
| 322 | - if ($iv === false || $is_strong === false) { |
|
| 323 | - throw new RuntimeException( |
|
| 324 | - esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso') |
|
| 325 | - ); |
|
| 326 | - } |
|
| 327 | - // encrypt it |
|
| 328 | - $encrypted_text = openssl_encrypt( |
|
| 329 | - $text_string, |
|
| 330 | - $this->cipher_method, |
|
| 331 | - $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key), |
|
| 332 | - 0, |
|
| 333 | - $iv |
|
| 334 | - ); |
|
| 335 | - // append the initialization vector |
|
| 336 | - $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
| 337 | - // trim and maybe encode |
|
| 338 | - return $this->_use_base64_encode |
|
| 339 | - ? trim(base64_encode($encrypted_text)) |
|
| 340 | - : trim($encrypted_text); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Returns a cipher method that has been verified to work. |
|
| 347 | - * First checks if the cached cipher has been set already and if so, returns that. |
|
| 348 | - * Then tests the incoming default and returns that if it's good. |
|
| 349 | - * If not, then it retrieves the previously tested and saved cipher method. |
|
| 350 | - * But if that doesn't exist, then calls getAvailableCipherMethod() |
|
| 351 | - * to see what is available on the server, and returns the results. |
|
| 352 | - * |
|
| 353 | - * @param string $cipher_method |
|
| 354 | - * @return string |
|
| 355 | - * @throws RuntimeException |
|
| 356 | - */ |
|
| 357 | - protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD) |
|
| 358 | - { |
|
| 359 | - if($this->cipher_method !== ''){ |
|
| 360 | - return $this->cipher_method; |
|
| 361 | - } |
|
| 362 | - // verify that the default cipher method can produce an initialization vector |
|
| 363 | - if (openssl_cipher_iv_length($cipher_method) === false) { |
|
| 364 | - // nope? okay let's get what we found in the past to work |
|
| 365 | - $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, ''); |
|
| 366 | - // oops... haven't tested available cipher methods yet |
|
| 367 | - if($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) { |
|
| 368 | - $cipher_method = $this->getAvailableCipherMethod($cipher_method); |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - return $cipher_method; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * @param string $cipher_method |
|
| 378 | - * @return string |
|
| 379 | - * @throws \RuntimeException |
|
| 380 | - */ |
|
| 381 | - protected function getAvailableCipherMethod($cipher_method) |
|
| 382 | - { |
|
| 383 | - // verify that the incoming cipher method can produce an initialization vector |
|
| 384 | - if (openssl_cipher_iv_length($cipher_method) === false) { |
|
| 385 | - // nope? then check the next cipher in the list of available cipher methods |
|
| 386 | - $cipher_method = next($this->cipher_methods); |
|
| 387 | - // what? there's no list? then generate that list and cache it, |
|
| 388 | - if (empty($this->cipher_methods)) { |
|
| 389 | - $this->cipher_methods = openssl_get_cipher_methods(); |
|
| 390 | - // then grab the first item from the list |
|
| 391 | - $cipher_method = reset($this->cipher_methods); |
|
| 392 | - } |
|
| 393 | - if($cipher_method === false){ |
|
| 394 | - throw new RuntimeException( |
|
| 395 | - esc_html__( |
|
| 396 | - 'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.', |
|
| 397 | - 'event_espresso' |
|
| 398 | - ) |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - // verify that the next cipher method works |
|
| 402 | - return $this->getAvailableCipherMethod($cipher_method); |
|
| 403 | - } |
|
| 404 | - // if we've gotten this far, then we found an available cipher method that works |
|
| 405 | - // so save that for next time |
|
| 406 | - update_option( |
|
| 407 | - EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, |
|
| 408 | - $cipher_method |
|
| 409 | - ); |
|
| 410 | - return $cipher_method; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * decrypts data that has been encrypted with PHP's openssl functions |
|
| 416 | - * |
|
| 417 | - * @param string $encrypted_text the text to be decrypted |
|
| 418 | - * @param string $cipher_method |
|
| 419 | - * @param string $encryption_key |
|
| 420 | - * @return string |
|
| 421 | - * @throws RuntimeException |
|
| 422 | - */ |
|
| 423 | - protected function openssl_decrypt( |
|
| 424 | - $encrypted_text = '', |
|
| 425 | - $cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
| 426 | - $encryption_key = '' |
|
| 427 | - ) { |
|
| 428 | - // you give me nothing??? GET OUT ! |
|
| 429 | - if (empty($encrypted_text)) { |
|
| 430 | - return $encrypted_text; |
|
| 431 | - } |
|
| 432 | - // decode |
|
| 433 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 434 | - ? $this->base64_url_decode($encrypted_text) |
|
| 435 | - : $encrypted_text; |
|
| 436 | - $encrypted_components = explode( |
|
| 437 | - EE_Encryption::OPENSSL_IV_DELIMITER, |
|
| 438 | - $encrypted_text, |
|
| 439 | - 2 |
|
| 440 | - ); |
|
| 441 | - // check that iv exists, and if not, maybe text was encoded using mcrypt? |
|
| 442 | - if ($this->_use_mcrypt && ! isset($encrypted_components[1])) { |
|
| 443 | - return $this->m_decrypt($encrypted_text); |
|
| 444 | - } |
|
| 445 | - // decrypt it |
|
| 446 | - $decrypted_text = openssl_decrypt( |
|
| 447 | - $encrypted_components[0], |
|
| 448 | - $this->getCipherMethod($cipher_method), |
|
| 449 | - $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD,$encryption_key), |
|
| 450 | - 0, |
|
| 451 | - $encrypted_components[1] |
|
| 452 | - ); |
|
| 453 | - $decrypted_text = trim($decrypted_text); |
|
| 454 | - return $decrypted_text; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Computes the digest hash value using the specified digest method. |
|
| 460 | - * If that digest method fails to produce a valid hash value, |
|
| 461 | - * then we'll grab the next digest method and recursively try again until something works. |
|
| 462 | - * |
|
| 463 | - * @param string $digest_method |
|
| 464 | - * @param string $encryption_key |
|
| 465 | - * @return string |
|
| 466 | - * @throws RuntimeException |
|
| 467 | - */ |
|
| 468 | - protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key = ''){ |
|
| 469 | - $encryption_key = $encryption_key !== '' |
|
| 470 | - ? $encryption_key |
|
| 471 | - : $this->get_encryption_key(); |
|
| 472 | - $digest_hash_value = openssl_digest($encryption_key, $digest_method); |
|
| 473 | - if ($digest_hash_value === false) { |
|
| 474 | - return $this->getDigestHashValue($this->getDigestMethod()); |
|
| 475 | - } |
|
| 476 | - return $digest_hash_value; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * Returns the NEXT element in the $digest_methods array. |
|
| 483 | - * If the $digest_methods array is empty, then we populate it |
|
| 484 | - * with the available values returned from openssl_get_md_methods(). |
|
| 485 | - * |
|
| 486 | - * @return string |
|
| 487 | - * @throws \RuntimeException |
|
| 488 | - */ |
|
| 489 | - protected function getDigestMethod(){ |
|
| 490 | - $digest_method = prev($this->digest_methods); |
|
| 491 | - if (empty($this->digest_methods)) { |
|
| 492 | - $this->digest_methods = openssl_get_md_methods(); |
|
| 493 | - $digest_method = end($this->digest_methods); |
|
| 494 | - } |
|
| 495 | - if ($digest_method === false) { |
|
| 496 | - throw new RuntimeException( |
|
| 497 | - esc_html__( |
|
| 498 | - 'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.', |
|
| 499 | - 'event_espresso' |
|
| 500 | - ) |
|
| 501 | - ); |
|
| 502 | - } |
|
| 503 | - return $digest_method; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
| 509 | - * |
|
| 510 | - * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
| 511 | - * @param string $text_string the text to be decrypted |
|
| 512 | - * @return string |
|
| 513 | - */ |
|
| 514 | - protected function acme_encrypt($text_string = '') |
|
| 515 | - { |
|
| 516 | - // you give me nothing??? GET OUT ! |
|
| 517 | - if (empty($text_string)) { |
|
| 518 | - return $text_string; |
|
| 519 | - } |
|
| 520 | - $key_bits = str_split( |
|
| 521 | - str_pad( |
|
| 522 | - '', |
|
| 523 | - strlen($text_string), |
|
| 524 | - $this->get_encryption_key(), |
|
| 525 | - STR_PAD_RIGHT |
|
| 526 | - ) |
|
| 527 | - ); |
|
| 528 | - $string_bits = str_split($text_string); |
|
| 529 | - foreach ($string_bits as $k => $v) { |
|
| 530 | - $temp = ord($v) + ord($key_bits[$k]); |
|
| 531 | - $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
| 532 | - } |
|
| 533 | - $encrypted_text = implode('', $string_bits); |
|
| 534 | - $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
|
| 535 | - return $this->_use_base64_encode |
|
| 536 | - ? base64_encode($encrypted_text) |
|
| 537 | - : $encrypted_text; |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
| 544 | - * |
|
| 545 | - * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
| 546 | - * @param string $encrypted_text the text to be decrypted |
|
| 547 | - * @return string |
|
| 548 | - * @throws RuntimeException |
|
| 549 | - */ |
|
| 550 | - protected function acme_decrypt($encrypted_text = '') |
|
| 551 | - { |
|
| 552 | - // you give me nothing??? GET OUT ! |
|
| 553 | - if (empty($encrypted_text)) { |
|
| 554 | - return $encrypted_text; |
|
| 555 | - } |
|
| 556 | - // decode the data ? |
|
| 557 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 558 | - ? $this->base64_url_decode($encrypted_text) |
|
| 559 | - : $encrypted_text; |
|
| 560 | - if ( |
|
| 561 | - $this->_use_mcrypt |
|
| 562 | - && strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false |
|
| 563 | - ){ |
|
| 564 | - return $this->m_decrypt($encrypted_text); |
|
| 565 | - } |
|
| 566 | - $encrypted_text = substr($encrypted_text, 0, -4); |
|
| 567 | - $key_bits = str_split( |
|
| 568 | - str_pad( |
|
| 569 | - '', |
|
| 570 | - strlen($encrypted_text), |
|
| 571 | - $this->get_encryption_key(), |
|
| 572 | - STR_PAD_RIGHT |
|
| 573 | - ) |
|
| 574 | - ); |
|
| 575 | - $string_bits = str_split($encrypted_text); |
|
| 576 | - foreach ($string_bits as $k => $v) { |
|
| 577 | - $temp = ord($v) - ord($key_bits[$k]); |
|
| 578 | - $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
| 579 | - } |
|
| 580 | - return implode('', $string_bits); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
| 587 | - * @param $string |
|
| 588 | - * @return bool |
|
| 589 | - */ |
|
| 590 | - protected function valid_base_64($string) |
|
| 591 | - { |
|
| 592 | - // ensure data is a string |
|
| 593 | - if (! is_string($string) || ! $this->_use_base64_encode) { |
|
| 594 | - return false; |
|
| 595 | - } |
|
| 596 | - $decoded = base64_decode($string, true); |
|
| 597 | - // Check if there is no invalid character in string |
|
| 598 | - if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
| 599 | - return false; |
|
| 600 | - } |
|
| 601 | - // Decode the string in strict mode and send the response |
|
| 602 | - if (! base64_decode($string, true)) { |
|
| 603 | - return false; |
|
| 604 | - } |
|
| 605 | - // Encode and compare it to original one |
|
| 606 | - return base64_encode($decoded) === $string; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * generate random string |
|
| 613 | - * |
|
| 614 | - * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
| 615 | - * @param int $length number of characters for random string |
|
| 616 | - * @return string |
|
| 617 | - */ |
|
| 618 | - public function generate_random_string($length = 40) |
|
| 619 | - { |
|
| 620 | - $iterations = ceil($length / 40); |
|
| 621 | - $random_string = ''; |
|
| 622 | - for ($i = 0; $i < $iterations; $i++) { |
|
| 623 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
| 624 | - } |
|
| 625 | - $random_string = substr($random_string, 0, $length); |
|
| 626 | - return $random_string; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * encrypts data using PHP's mcrypt functions |
|
| 633 | - * |
|
| 634 | - * @deprecated 4.9.39 |
|
| 635 | - * @param string $text_string |
|
| 636 | - * @internal param $string - the text to be encrypted |
|
| 637 | - * @return string |
|
| 638 | - * @throws RuntimeException |
|
| 639 | - */ |
|
| 640 | - protected function m_encrypt($text_string = '') |
|
| 641 | - { |
|
| 642 | - // you give me nothing??? GET OUT ! |
|
| 643 | - if (empty($text_string)) { |
|
| 644 | - return $text_string; |
|
| 645 | - } |
|
| 646 | - // get the initialization vector size |
|
| 647 | - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
| 648 | - // initialization vector |
|
| 649 | - $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
| 650 | - if ($iv === false) { |
|
| 651 | - throw new RuntimeException( |
|
| 652 | - esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
| 653 | - ); |
|
| 654 | - } |
|
| 655 | - // encrypt it |
|
| 656 | - $encrypted_text = mcrypt_encrypt( |
|
| 657 | - MCRYPT_RIJNDAEL_256, |
|
| 658 | - $this->get_encryption_key(), |
|
| 659 | - $text_string, |
|
| 660 | - MCRYPT_MODE_ECB, |
|
| 661 | - $iv |
|
| 662 | - ); |
|
| 663 | - // trim and maybe encode |
|
| 664 | - return $this->_use_base64_encode |
|
| 665 | - ? trim(base64_encode($encrypted_text)) |
|
| 666 | - : trim($encrypted_text); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * decrypts data that has been encrypted with PHP's mcrypt functions |
|
| 673 | - * |
|
| 674 | - * @deprecated 4.9.39 |
|
| 675 | - * @param string $encrypted_text the text to be decrypted |
|
| 676 | - * @return string |
|
| 677 | - * @throws RuntimeException |
|
| 678 | - */ |
|
| 679 | - protected function m_decrypt($encrypted_text = '') |
|
| 680 | - { |
|
| 681 | - // you give me nothing??? GET OUT ! |
|
| 682 | - if (empty($encrypted_text)) { |
|
| 683 | - return $encrypted_text; |
|
| 684 | - } |
|
| 685 | - // decode |
|
| 686 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 687 | - ? $this->base64_url_decode($encrypted_text) |
|
| 688 | - : $encrypted_text; |
|
| 689 | - // get the initialization vector size |
|
| 690 | - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
| 691 | - $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
| 692 | - if ($iv === false) { |
|
| 693 | - throw new RuntimeException( |
|
| 694 | - esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
| 695 | - ); |
|
| 696 | - } |
|
| 697 | - // decrypt it |
|
| 698 | - $decrypted_text = mcrypt_decrypt( |
|
| 699 | - MCRYPT_RIJNDAEL_256, |
|
| 700 | - $this->get_encryption_key(), |
|
| 701 | - $encrypted_text, |
|
| 702 | - MCRYPT_MODE_ECB, |
|
| 703 | - $iv |
|
| 704 | - ); |
|
| 705 | - $decrypted_text = trim($decrypted_text); |
|
| 706 | - return $decrypted_text; |
|
| 707 | - } |
|
| 22 | + /** |
|
| 23 | + * key used for saving the encryption key to the wp_options table |
|
| 24 | + */ |
|
| 25 | + const ENCRYPTION_OPTION_KEY = 'ee_encryption_key'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * the OPENSSL cipher method used |
|
| 29 | + */ |
|
| 30 | + const OPENSSL_CIPHER_METHOD = 'AES-128-CBC'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * WP "options_name" used to store a verified available cipher method |
|
| 34 | + */ |
|
| 35 | + const OPENSSL_CIPHER_METHOD_OPTION_NAME = 'ee_openssl_cipher_method'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * the OPENSSL digest method used |
|
| 39 | + */ |
|
| 40 | + const OPENSSL_DIGEST_METHOD = 'sha512'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * separates the encrypted text from the initialization vector |
|
| 44 | + */ |
|
| 45 | + const OPENSSL_IV_DELIMITER = ':iv:'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * appended to text encrypted using the acme encryption |
|
| 49 | + */ |
|
| 50 | + const ACME_ENCRYPTION_FLAG = '::ae'; |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * instance of the EE_Encryption object |
|
| 56 | + */ |
|
| 57 | + protected static $_instance; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @var string $_encryption_key |
|
| 61 | + */ |
|
| 62 | + protected $_encryption_key; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @var string $cipher_method |
|
| 66 | + */ |
|
| 67 | + private $cipher_method = ''; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @var array $cipher_methods |
|
| 71 | + */ |
|
| 72 | + private $cipher_methods = array(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @var array $digest_methods |
|
| 76 | + */ |
|
| 77 | + private $digest_methods = array(); |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @var boolean $_use_openssl_encrypt |
|
| 81 | + */ |
|
| 82 | + protected $_use_openssl_encrypt = false; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @var boolean $_use_mcrypt |
|
| 86 | + */ |
|
| 87 | + protected $_use_mcrypt = false; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @var boolean $_use_base64_encode |
|
| 91 | + */ |
|
| 92 | + protected $_use_base64_encode = false; |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * protected constructor to prevent direct creation |
|
| 98 | + */ |
|
| 99 | + protected function __construct() |
|
| 100 | + { |
|
| 101 | + if (! defined('ESPRESSO_ENCRYPT')) { |
|
| 102 | + define('ESPRESSO_ENCRYPT', true); |
|
| 103 | + } |
|
| 104 | + if (extension_loaded('openssl')) { |
|
| 105 | + $this->_use_openssl_encrypt = true; |
|
| 106 | + } else if (extension_loaded('mcrypt')) { |
|
| 107 | + $this->_use_mcrypt = true; |
|
| 108 | + } |
|
| 109 | + if (function_exists('base64_encode')) { |
|
| 110 | + $this->_use_base64_encode = true; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * singleton method used to instantiate class object |
|
| 118 | + * |
|
| 119 | + * @return EE_Encryption |
|
| 120 | + */ |
|
| 121 | + public static function instance() |
|
| 122 | + { |
|
| 123 | + // check if class object is instantiated |
|
| 124 | + if (! EE_Encryption::$_instance instanceof EE_Encryption) { |
|
| 125 | + EE_Encryption::$_instance = new self(); |
|
| 126 | + } |
|
| 127 | + return EE_Encryption::$_instance; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * get encryption key |
|
| 134 | + * |
|
| 135 | + * @return string |
|
| 136 | + */ |
|
| 137 | + public function get_encryption_key() |
|
| 138 | + { |
|
| 139 | + // if encryption key has not been set |
|
| 140 | + if (empty($this->_encryption_key)) { |
|
| 141 | + // retrieve encryption_key from db |
|
| 142 | + $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, ''); |
|
| 143 | + // WHAT?? No encryption_key in the db ?? |
|
| 144 | + if ($this->_encryption_key === '') { |
|
| 145 | + // let's make one. And md5 it to make it just the right size for a key |
|
| 146 | + $new_key = md5($this->generate_random_string()); |
|
| 147 | + // now save it to the db for later |
|
| 148 | + add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key); |
|
| 149 | + // here's the key - FINALLY ! |
|
| 150 | + $this->_encryption_key = $new_key; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + return $this->_encryption_key; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * encrypts data |
|
| 160 | + * |
|
| 161 | + * @param string $text_string - the text to be encrypted |
|
| 162 | + * @return string |
|
| 163 | + * @throws RuntimeException |
|
| 164 | + */ |
|
| 165 | + public function encrypt($text_string = '') |
|
| 166 | + { |
|
| 167 | + // you give me nothing??? GET OUT ! |
|
| 168 | + if (empty($text_string)) { |
|
| 169 | + return $text_string; |
|
| 170 | + } |
|
| 171 | + if ($this->_use_openssl_encrypt) { |
|
| 172 | + $encrypted_text = $this->openssl_encrypt($text_string); |
|
| 173 | + } else { |
|
| 174 | + $encrypted_text = $this->acme_encrypt($text_string); |
|
| 175 | + } |
|
| 176 | + return $encrypted_text; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * decrypts data |
|
| 183 | + * |
|
| 184 | + * @param string $encrypted_text - the text to be decrypted |
|
| 185 | + * @return string |
|
| 186 | + * @throws RuntimeException |
|
| 187 | + */ |
|
| 188 | + public function decrypt($encrypted_text = '') |
|
| 189 | + { |
|
| 190 | + // you give me nothing??? GET OUT ! |
|
| 191 | + if (empty($encrypted_text)) { |
|
| 192 | + return $encrypted_text; |
|
| 193 | + } |
|
| 194 | + // if PHP's mcrypt functions are installed then we'll use them |
|
| 195 | + if ($this->_use_openssl_encrypt) { |
|
| 196 | + $decrypted_text = $this->openssl_decrypt($encrypted_text); |
|
| 197 | + } else { |
|
| 198 | + $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
| 199 | + } |
|
| 200 | + return $decrypted_text; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * encodes string with PHP's base64 encoding |
|
| 207 | + * |
|
| 208 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
| 209 | + * @param string $text_string the text to be encoded |
|
| 210 | + * @return string |
|
| 211 | + */ |
|
| 212 | + public function base64_string_encode($text_string = '') |
|
| 213 | + { |
|
| 214 | + // you give me nothing??? GET OUT ! |
|
| 215 | + if (empty($text_string) || ! $this->_use_base64_encode) { |
|
| 216 | + return $text_string; |
|
| 217 | + } |
|
| 218 | + // encode |
|
| 219 | + return base64_encode($text_string); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * decodes string that has been encoded with PHP's base64 encoding |
|
| 225 | + * |
|
| 226 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
| 227 | + * @param string $encoded_string the text to be decoded |
|
| 228 | + * @return string |
|
| 229 | + * @throws RuntimeException |
|
| 230 | + */ |
|
| 231 | + public function base64_string_decode($encoded_string = '') |
|
| 232 | + { |
|
| 233 | + // you give me nothing??? GET OUT ! |
|
| 234 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 235 | + return $encoded_string; |
|
| 236 | + } |
|
| 237 | + // decode |
|
| 238 | + $decoded_string = base64_decode($encoded_string); |
|
| 239 | + if ($decoded_string === false) { |
|
| 240 | + throw new RuntimeException( |
|
| 241 | + esc_html__('Base 64 decoding failed.', 'event_espresso') |
|
| 242 | + ); |
|
| 243 | + } |
|
| 244 | + return $decoded_string; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * encodes url string with PHP's base64 encoding |
|
| 251 | + * |
|
| 252 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
| 253 | + * @param string $text_string the text to be encoded |
|
| 254 | + * @return string |
|
| 255 | + */ |
|
| 256 | + public function base64_url_encode($text_string = '') |
|
| 257 | + { |
|
| 258 | + // you give me nothing??? GET OUT ! |
|
| 259 | + if (empty($text_string) || ! $this->_use_base64_encode) { |
|
| 260 | + return $text_string; |
|
| 261 | + } |
|
| 262 | + // encode |
|
| 263 | + $encoded_string = base64_encode($text_string); |
|
| 264 | + // remove chars to make encoding more URL friendly |
|
| 265 | + return strtr($encoded_string, '+/=', '-_,'); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * decodes url string that has been encoded with PHP's base64 encoding |
|
| 271 | + * |
|
| 272 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
| 273 | + * @param string $encoded_string the text to be decoded |
|
| 274 | + * @return string |
|
| 275 | + * @throws RuntimeException |
|
| 276 | + */ |
|
| 277 | + public function base64_url_decode($encoded_string = '') |
|
| 278 | + { |
|
| 279 | + // you give me nothing??? GET OUT ! |
|
| 280 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 281 | + return $encoded_string; |
|
| 282 | + } |
|
| 283 | + // replace previously removed characters |
|
| 284 | + $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
| 285 | + // decode |
|
| 286 | + $decoded_string = base64_decode($encoded_string); |
|
| 287 | + if ($decoded_string === false) { |
|
| 288 | + throw new RuntimeException( |
|
| 289 | + esc_html__('Base 64 decoding failed.', 'event_espresso') |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + return $decoded_string; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * encrypts data using PHP's openssl functions |
|
| 298 | + * |
|
| 299 | + * @param string $text_string the text to be encrypted |
|
| 300 | + * @param string $cipher_method |
|
| 301 | + * @param string $encryption_key |
|
| 302 | + * @return string |
|
| 303 | + * @throws RuntimeException |
|
| 304 | + */ |
|
| 305 | + protected function openssl_encrypt( |
|
| 306 | + $text_string = '', |
|
| 307 | + $cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
| 308 | + $encryption_key = '' |
|
| 309 | + ) { |
|
| 310 | + // you give me nothing??? GET OUT ! |
|
| 311 | + if (empty($text_string)) { |
|
| 312 | + return $text_string; |
|
| 313 | + } |
|
| 314 | + $this->cipher_method = $this->getCipherMethod($cipher_method); |
|
| 315 | + // get initialization vector size |
|
| 316 | + $iv_size = openssl_cipher_iv_length($this->cipher_method); |
|
| 317 | + // generate initialization vector. |
|
| 318 | + // The second parameter ("crypto_strong") is passed by reference, |
|
| 319 | + // and is used to determines if the algorithm used was "cryptographically strong" |
|
| 320 | + // openssl_random_pseudo_bytes() will toggle it to either true or false |
|
| 321 | + $iv = openssl_random_pseudo_bytes($iv_size, $is_strong); |
|
| 322 | + if ($iv === false || $is_strong === false) { |
|
| 323 | + throw new RuntimeException( |
|
| 324 | + esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso') |
|
| 325 | + ); |
|
| 326 | + } |
|
| 327 | + // encrypt it |
|
| 328 | + $encrypted_text = openssl_encrypt( |
|
| 329 | + $text_string, |
|
| 330 | + $this->cipher_method, |
|
| 331 | + $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key), |
|
| 332 | + 0, |
|
| 333 | + $iv |
|
| 334 | + ); |
|
| 335 | + // append the initialization vector |
|
| 336 | + $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
| 337 | + // trim and maybe encode |
|
| 338 | + return $this->_use_base64_encode |
|
| 339 | + ? trim(base64_encode($encrypted_text)) |
|
| 340 | + : trim($encrypted_text); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Returns a cipher method that has been verified to work. |
|
| 347 | + * First checks if the cached cipher has been set already and if so, returns that. |
|
| 348 | + * Then tests the incoming default and returns that if it's good. |
|
| 349 | + * If not, then it retrieves the previously tested and saved cipher method. |
|
| 350 | + * But if that doesn't exist, then calls getAvailableCipherMethod() |
|
| 351 | + * to see what is available on the server, and returns the results. |
|
| 352 | + * |
|
| 353 | + * @param string $cipher_method |
|
| 354 | + * @return string |
|
| 355 | + * @throws RuntimeException |
|
| 356 | + */ |
|
| 357 | + protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD) |
|
| 358 | + { |
|
| 359 | + if($this->cipher_method !== ''){ |
|
| 360 | + return $this->cipher_method; |
|
| 361 | + } |
|
| 362 | + // verify that the default cipher method can produce an initialization vector |
|
| 363 | + if (openssl_cipher_iv_length($cipher_method) === false) { |
|
| 364 | + // nope? okay let's get what we found in the past to work |
|
| 365 | + $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, ''); |
|
| 366 | + // oops... haven't tested available cipher methods yet |
|
| 367 | + if($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) { |
|
| 368 | + $cipher_method = $this->getAvailableCipherMethod($cipher_method); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + return $cipher_method; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * @param string $cipher_method |
|
| 378 | + * @return string |
|
| 379 | + * @throws \RuntimeException |
|
| 380 | + */ |
|
| 381 | + protected function getAvailableCipherMethod($cipher_method) |
|
| 382 | + { |
|
| 383 | + // verify that the incoming cipher method can produce an initialization vector |
|
| 384 | + if (openssl_cipher_iv_length($cipher_method) === false) { |
|
| 385 | + // nope? then check the next cipher in the list of available cipher methods |
|
| 386 | + $cipher_method = next($this->cipher_methods); |
|
| 387 | + // what? there's no list? then generate that list and cache it, |
|
| 388 | + if (empty($this->cipher_methods)) { |
|
| 389 | + $this->cipher_methods = openssl_get_cipher_methods(); |
|
| 390 | + // then grab the first item from the list |
|
| 391 | + $cipher_method = reset($this->cipher_methods); |
|
| 392 | + } |
|
| 393 | + if($cipher_method === false){ |
|
| 394 | + throw new RuntimeException( |
|
| 395 | + esc_html__( |
|
| 396 | + 'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.', |
|
| 397 | + 'event_espresso' |
|
| 398 | + ) |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + // verify that the next cipher method works |
|
| 402 | + return $this->getAvailableCipherMethod($cipher_method); |
|
| 403 | + } |
|
| 404 | + // if we've gotten this far, then we found an available cipher method that works |
|
| 405 | + // so save that for next time |
|
| 406 | + update_option( |
|
| 407 | + EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, |
|
| 408 | + $cipher_method |
|
| 409 | + ); |
|
| 410 | + return $cipher_method; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * decrypts data that has been encrypted with PHP's openssl functions |
|
| 416 | + * |
|
| 417 | + * @param string $encrypted_text the text to be decrypted |
|
| 418 | + * @param string $cipher_method |
|
| 419 | + * @param string $encryption_key |
|
| 420 | + * @return string |
|
| 421 | + * @throws RuntimeException |
|
| 422 | + */ |
|
| 423 | + protected function openssl_decrypt( |
|
| 424 | + $encrypted_text = '', |
|
| 425 | + $cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
| 426 | + $encryption_key = '' |
|
| 427 | + ) { |
|
| 428 | + // you give me nothing??? GET OUT ! |
|
| 429 | + if (empty($encrypted_text)) { |
|
| 430 | + return $encrypted_text; |
|
| 431 | + } |
|
| 432 | + // decode |
|
| 433 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 434 | + ? $this->base64_url_decode($encrypted_text) |
|
| 435 | + : $encrypted_text; |
|
| 436 | + $encrypted_components = explode( |
|
| 437 | + EE_Encryption::OPENSSL_IV_DELIMITER, |
|
| 438 | + $encrypted_text, |
|
| 439 | + 2 |
|
| 440 | + ); |
|
| 441 | + // check that iv exists, and if not, maybe text was encoded using mcrypt? |
|
| 442 | + if ($this->_use_mcrypt && ! isset($encrypted_components[1])) { |
|
| 443 | + return $this->m_decrypt($encrypted_text); |
|
| 444 | + } |
|
| 445 | + // decrypt it |
|
| 446 | + $decrypted_text = openssl_decrypt( |
|
| 447 | + $encrypted_components[0], |
|
| 448 | + $this->getCipherMethod($cipher_method), |
|
| 449 | + $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD,$encryption_key), |
|
| 450 | + 0, |
|
| 451 | + $encrypted_components[1] |
|
| 452 | + ); |
|
| 453 | + $decrypted_text = trim($decrypted_text); |
|
| 454 | + return $decrypted_text; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Computes the digest hash value using the specified digest method. |
|
| 460 | + * If that digest method fails to produce a valid hash value, |
|
| 461 | + * then we'll grab the next digest method and recursively try again until something works. |
|
| 462 | + * |
|
| 463 | + * @param string $digest_method |
|
| 464 | + * @param string $encryption_key |
|
| 465 | + * @return string |
|
| 466 | + * @throws RuntimeException |
|
| 467 | + */ |
|
| 468 | + protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key = ''){ |
|
| 469 | + $encryption_key = $encryption_key !== '' |
|
| 470 | + ? $encryption_key |
|
| 471 | + : $this->get_encryption_key(); |
|
| 472 | + $digest_hash_value = openssl_digest($encryption_key, $digest_method); |
|
| 473 | + if ($digest_hash_value === false) { |
|
| 474 | + return $this->getDigestHashValue($this->getDigestMethod()); |
|
| 475 | + } |
|
| 476 | + return $digest_hash_value; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * Returns the NEXT element in the $digest_methods array. |
|
| 483 | + * If the $digest_methods array is empty, then we populate it |
|
| 484 | + * with the available values returned from openssl_get_md_methods(). |
|
| 485 | + * |
|
| 486 | + * @return string |
|
| 487 | + * @throws \RuntimeException |
|
| 488 | + */ |
|
| 489 | + protected function getDigestMethod(){ |
|
| 490 | + $digest_method = prev($this->digest_methods); |
|
| 491 | + if (empty($this->digest_methods)) { |
|
| 492 | + $this->digest_methods = openssl_get_md_methods(); |
|
| 493 | + $digest_method = end($this->digest_methods); |
|
| 494 | + } |
|
| 495 | + if ($digest_method === false) { |
|
| 496 | + throw new RuntimeException( |
|
| 497 | + esc_html__( |
|
| 498 | + 'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.', |
|
| 499 | + 'event_espresso' |
|
| 500 | + ) |
|
| 501 | + ); |
|
| 502 | + } |
|
| 503 | + return $digest_method; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
| 509 | + * |
|
| 510 | + * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
| 511 | + * @param string $text_string the text to be decrypted |
|
| 512 | + * @return string |
|
| 513 | + */ |
|
| 514 | + protected function acme_encrypt($text_string = '') |
|
| 515 | + { |
|
| 516 | + // you give me nothing??? GET OUT ! |
|
| 517 | + if (empty($text_string)) { |
|
| 518 | + return $text_string; |
|
| 519 | + } |
|
| 520 | + $key_bits = str_split( |
|
| 521 | + str_pad( |
|
| 522 | + '', |
|
| 523 | + strlen($text_string), |
|
| 524 | + $this->get_encryption_key(), |
|
| 525 | + STR_PAD_RIGHT |
|
| 526 | + ) |
|
| 527 | + ); |
|
| 528 | + $string_bits = str_split($text_string); |
|
| 529 | + foreach ($string_bits as $k => $v) { |
|
| 530 | + $temp = ord($v) + ord($key_bits[$k]); |
|
| 531 | + $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
| 532 | + } |
|
| 533 | + $encrypted_text = implode('', $string_bits); |
|
| 534 | + $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
|
| 535 | + return $this->_use_base64_encode |
|
| 536 | + ? base64_encode($encrypted_text) |
|
| 537 | + : $encrypted_text; |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
| 544 | + * |
|
| 545 | + * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
| 546 | + * @param string $encrypted_text the text to be decrypted |
|
| 547 | + * @return string |
|
| 548 | + * @throws RuntimeException |
|
| 549 | + */ |
|
| 550 | + protected function acme_decrypt($encrypted_text = '') |
|
| 551 | + { |
|
| 552 | + // you give me nothing??? GET OUT ! |
|
| 553 | + if (empty($encrypted_text)) { |
|
| 554 | + return $encrypted_text; |
|
| 555 | + } |
|
| 556 | + // decode the data ? |
|
| 557 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 558 | + ? $this->base64_url_decode($encrypted_text) |
|
| 559 | + : $encrypted_text; |
|
| 560 | + if ( |
|
| 561 | + $this->_use_mcrypt |
|
| 562 | + && strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false |
|
| 563 | + ){ |
|
| 564 | + return $this->m_decrypt($encrypted_text); |
|
| 565 | + } |
|
| 566 | + $encrypted_text = substr($encrypted_text, 0, -4); |
|
| 567 | + $key_bits = str_split( |
|
| 568 | + str_pad( |
|
| 569 | + '', |
|
| 570 | + strlen($encrypted_text), |
|
| 571 | + $this->get_encryption_key(), |
|
| 572 | + STR_PAD_RIGHT |
|
| 573 | + ) |
|
| 574 | + ); |
|
| 575 | + $string_bits = str_split($encrypted_text); |
|
| 576 | + foreach ($string_bits as $k => $v) { |
|
| 577 | + $temp = ord($v) - ord($key_bits[$k]); |
|
| 578 | + $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
| 579 | + } |
|
| 580 | + return implode('', $string_bits); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
| 587 | + * @param $string |
|
| 588 | + * @return bool |
|
| 589 | + */ |
|
| 590 | + protected function valid_base_64($string) |
|
| 591 | + { |
|
| 592 | + // ensure data is a string |
|
| 593 | + if (! is_string($string) || ! $this->_use_base64_encode) { |
|
| 594 | + return false; |
|
| 595 | + } |
|
| 596 | + $decoded = base64_decode($string, true); |
|
| 597 | + // Check if there is no invalid character in string |
|
| 598 | + if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
| 599 | + return false; |
|
| 600 | + } |
|
| 601 | + // Decode the string in strict mode and send the response |
|
| 602 | + if (! base64_decode($string, true)) { |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 605 | + // Encode and compare it to original one |
|
| 606 | + return base64_encode($decoded) === $string; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * generate random string |
|
| 613 | + * |
|
| 614 | + * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
| 615 | + * @param int $length number of characters for random string |
|
| 616 | + * @return string |
|
| 617 | + */ |
|
| 618 | + public function generate_random_string($length = 40) |
|
| 619 | + { |
|
| 620 | + $iterations = ceil($length / 40); |
|
| 621 | + $random_string = ''; |
|
| 622 | + for ($i = 0; $i < $iterations; $i++) { |
|
| 623 | + $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
| 624 | + } |
|
| 625 | + $random_string = substr($random_string, 0, $length); |
|
| 626 | + return $random_string; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * encrypts data using PHP's mcrypt functions |
|
| 633 | + * |
|
| 634 | + * @deprecated 4.9.39 |
|
| 635 | + * @param string $text_string |
|
| 636 | + * @internal param $string - the text to be encrypted |
|
| 637 | + * @return string |
|
| 638 | + * @throws RuntimeException |
|
| 639 | + */ |
|
| 640 | + protected function m_encrypt($text_string = '') |
|
| 641 | + { |
|
| 642 | + // you give me nothing??? GET OUT ! |
|
| 643 | + if (empty($text_string)) { |
|
| 644 | + return $text_string; |
|
| 645 | + } |
|
| 646 | + // get the initialization vector size |
|
| 647 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
| 648 | + // initialization vector |
|
| 649 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
| 650 | + if ($iv === false) { |
|
| 651 | + throw new RuntimeException( |
|
| 652 | + esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
| 653 | + ); |
|
| 654 | + } |
|
| 655 | + // encrypt it |
|
| 656 | + $encrypted_text = mcrypt_encrypt( |
|
| 657 | + MCRYPT_RIJNDAEL_256, |
|
| 658 | + $this->get_encryption_key(), |
|
| 659 | + $text_string, |
|
| 660 | + MCRYPT_MODE_ECB, |
|
| 661 | + $iv |
|
| 662 | + ); |
|
| 663 | + // trim and maybe encode |
|
| 664 | + return $this->_use_base64_encode |
|
| 665 | + ? trim(base64_encode($encrypted_text)) |
|
| 666 | + : trim($encrypted_text); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * decrypts data that has been encrypted with PHP's mcrypt functions |
|
| 673 | + * |
|
| 674 | + * @deprecated 4.9.39 |
|
| 675 | + * @param string $encrypted_text the text to be decrypted |
|
| 676 | + * @return string |
|
| 677 | + * @throws RuntimeException |
|
| 678 | + */ |
|
| 679 | + protected function m_decrypt($encrypted_text = '') |
|
| 680 | + { |
|
| 681 | + // you give me nothing??? GET OUT ! |
|
| 682 | + if (empty($encrypted_text)) { |
|
| 683 | + return $encrypted_text; |
|
| 684 | + } |
|
| 685 | + // decode |
|
| 686 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 687 | + ? $this->base64_url_decode($encrypted_text) |
|
| 688 | + : $encrypted_text; |
|
| 689 | + // get the initialization vector size |
|
| 690 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
| 691 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
| 692 | + if ($iv === false) { |
|
| 693 | + throw new RuntimeException( |
|
| 694 | + esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
| 695 | + ); |
|
| 696 | + } |
|
| 697 | + // decrypt it |
|
| 698 | + $decrypted_text = mcrypt_decrypt( |
|
| 699 | + MCRYPT_RIJNDAEL_256, |
|
| 700 | + $this->get_encryption_key(), |
|
| 701 | + $encrypted_text, |
|
| 702 | + MCRYPT_MODE_ECB, |
|
| 703 | + $iv |
|
| 704 | + ); |
|
| 705 | + $decrypted_text = trim($decrypted_text); |
|
| 706 | + return $decrypted_text; |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | 709 | } |
| 710 | 710 | /* End of file EE_Encryption.class.php */ |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | protected function __construct() |
| 100 | 100 | { |
| 101 | - if (! defined('ESPRESSO_ENCRYPT')) { |
|
| 101 | + if ( ! defined('ESPRESSO_ENCRYPT')) { |
|
| 102 | 102 | define('ESPRESSO_ENCRYPT', true); |
| 103 | 103 | } |
| 104 | 104 | if (extension_loaded('openssl')) { |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | public static function instance() |
| 122 | 122 | { |
| 123 | 123 | // check if class object is instantiated |
| 124 | - if (! EE_Encryption::$_instance instanceof EE_Encryption) { |
|
| 124 | + if ( ! EE_Encryption::$_instance instanceof EE_Encryption) { |
|
| 125 | 125 | EE_Encryption::$_instance = new self(); |
| 126 | 126 | } |
| 127 | 127 | return EE_Encryption::$_instance; |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $iv |
| 334 | 334 | ); |
| 335 | 335 | // append the initialization vector |
| 336 | - $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
| 336 | + $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER.$iv; |
|
| 337 | 337 | // trim and maybe encode |
| 338 | 338 | return $this->_use_base64_encode |
| 339 | 339 | ? trim(base64_encode($encrypted_text)) |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD) |
| 358 | 358 | { |
| 359 | - if($this->cipher_method !== ''){ |
|
| 359 | + if ($this->cipher_method !== '') { |
|
| 360 | 360 | return $this->cipher_method; |
| 361 | 361 | } |
| 362 | 362 | // verify that the default cipher method can produce an initialization vector |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | // nope? okay let's get what we found in the past to work |
| 365 | 365 | $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, ''); |
| 366 | 366 | // oops... haven't tested available cipher methods yet |
| 367 | - if($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) { |
|
| 367 | + if ($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) { |
|
| 368 | 368 | $cipher_method = $this->getAvailableCipherMethod($cipher_method); |
| 369 | 369 | } |
| 370 | 370 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | // then grab the first item from the list |
| 391 | 391 | $cipher_method = reset($this->cipher_methods); |
| 392 | 392 | } |
| 393 | - if($cipher_method === false){ |
|
| 393 | + if ($cipher_method === false) { |
|
| 394 | 394 | throw new RuntimeException( |
| 395 | 395 | esc_html__( |
| 396 | 396 | 'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.', |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | $decrypted_text = openssl_decrypt( |
| 447 | 447 | $encrypted_components[0], |
| 448 | 448 | $this->getCipherMethod($cipher_method), |
| 449 | - $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD,$encryption_key), |
|
| 449 | + $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key), |
|
| 450 | 450 | 0, |
| 451 | 451 | $encrypted_components[1] |
| 452 | 452 | ); |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | * @return string |
| 466 | 466 | * @throws RuntimeException |
| 467 | 467 | */ |
| 468 | - protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key = ''){ |
|
| 468 | + protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key = '') { |
|
| 469 | 469 | $encryption_key = $encryption_key !== '' |
| 470 | 470 | ? $encryption_key |
| 471 | 471 | : $this->get_encryption_key(); |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | * @return string |
| 487 | 487 | * @throws \RuntimeException |
| 488 | 488 | */ |
| 489 | - protected function getDigestMethod(){ |
|
| 489 | + protected function getDigestMethod() { |
|
| 490 | 490 | $digest_method = prev($this->digest_methods); |
| 491 | 491 | if (empty($this->digest_methods)) { |
| 492 | 492 | $this->digest_methods = openssl_get_md_methods(); |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | if ( |
| 561 | 561 | $this->_use_mcrypt |
| 562 | 562 | && strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false |
| 563 | - ){ |
|
| 563 | + ) { |
|
| 564 | 564 | return $this->m_decrypt($encrypted_text); |
| 565 | 565 | } |
| 566 | 566 | $encrypted_text = substr($encrypted_text, 0, -4); |
@@ -590,16 +590,16 @@ discard block |
||
| 590 | 590 | protected function valid_base_64($string) |
| 591 | 591 | { |
| 592 | 592 | // ensure data is a string |
| 593 | - if (! is_string($string) || ! $this->_use_base64_encode) { |
|
| 593 | + if ( ! is_string($string) || ! $this->_use_base64_encode) { |
|
| 594 | 594 | return false; |
| 595 | 595 | } |
| 596 | 596 | $decoded = base64_decode($string, true); |
| 597 | 597 | // Check if there is no invalid character in string |
| 598 | - if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
| 598 | + if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
| 599 | 599 | return false; |
| 600 | 600 | } |
| 601 | 601 | // Decode the string in strict mode and send the response |
| 602 | - if (! base64_decode($string, true)) { |
|
| 602 | + if ( ! base64_decode($string, true)) { |
|
| 603 | 603 | return false; |
| 604 | 604 | } |
| 605 | 605 | // Encode and compare it to original one |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | $iterations = ceil($length / 40); |
| 621 | 621 | $random_string = ''; |
| 622 | 622 | for ($i = 0; $i < $iterations; $i++) { |
| 623 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
| 623 | + $random_string .= sha1(microtime(true).mt_rand(10000, 90000)); |
|
| 624 | 624 | } |
| 625 | 625 | $random_string = substr($random_string, 0, $length); |
| 626 | 626 | return $random_string; |
@@ -24,1073 +24,1073 @@ |
||
| 24 | 24 | class EED_Ticket_Sales_Monitor extends EED_Module |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - const debug = false; // true false |
|
| 28 | - |
|
| 29 | - private static $nl = ''; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * an array of raw ticket data from EED_Ticket_Selector |
|
| 33 | - * |
|
| 34 | - * @var array $ticket_selections |
|
| 35 | - */ |
|
| 36 | - protected $ticket_selections = array(); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
| 40 | - * according to how they are displayed in the actual Ticket_Selector |
|
| 41 | - * this tracks the current row being processed |
|
| 42 | - * |
|
| 43 | - * @var int $current_row |
|
| 44 | - */ |
|
| 45 | - protected $current_row = 0; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * an array for tracking names of tickets that have sold out |
|
| 49 | - * |
|
| 50 | - * @var array $sold_out_tickets |
|
| 51 | - */ |
|
| 52 | - protected $sold_out_tickets = array(); |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * an array for tracking names of tickets that have had their quantities reduced |
|
| 56 | - * |
|
| 57 | - * @var array $decremented_tickets |
|
| 58 | - */ |
|
| 59 | - protected $decremented_tickets = array(); |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public static function set_hooks() |
|
| 69 | - { |
|
| 70 | - self::$nl = defined('EE_TESTS_DIR')? "\n" : '<br />'; |
|
| 71 | - // release tickets for expired carts |
|
| 72 | - add_action( |
|
| 73 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 74 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
| 75 | - 1 |
|
| 76 | - ); |
|
| 77 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
| 78 | - add_filter( |
|
| 79 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
| 80 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
| 81 | - 20, |
|
| 82 | - 3 |
|
| 83 | - ); |
|
| 84 | - // add notices for sold out tickets |
|
| 85 | - add_action( |
|
| 86 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 87 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
| 88 | - 10 |
|
| 89 | - ); |
|
| 90 | - // handle ticket quantities adjusted in cart |
|
| 91 | - //add_action( |
|
| 92 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
| 93 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
| 94 | - // 10, 2 |
|
| 95 | - //); |
|
| 96 | - // handle tickets deleted from cart |
|
| 97 | - add_action( |
|
| 98 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
| 99 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
| 100 | - 10, |
|
| 101 | - 2 |
|
| 102 | - ); |
|
| 103 | - // handle emptied carts |
|
| 104 | - add_action( |
|
| 105 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
| 106 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 107 | - 10, |
|
| 108 | - 1 |
|
| 109 | - ); |
|
| 110 | - add_action( |
|
| 111 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
| 112 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 113 | - 10, |
|
| 114 | - 1 |
|
| 115 | - ); |
|
| 116 | - // handle cancelled registrations |
|
| 117 | - add_action( |
|
| 118 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
| 119 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
| 120 | - 10, |
|
| 121 | - 1 |
|
| 122 | - ); |
|
| 123 | - // cron tasks |
|
| 124 | - add_action( |
|
| 125 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 126 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 127 | - 10, |
|
| 128 | - 1 |
|
| 129 | - ); |
|
| 130 | - add_action( |
|
| 131 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 132 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 133 | - 10, |
|
| 134 | - 1 |
|
| 135 | - ); |
|
| 136 | - add_action( |
|
| 137 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 138 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
| 139 | - 10, |
|
| 140 | - 1 |
|
| 141 | - ); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 148 | - * |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - public static function set_hooks_admin() |
|
| 152 | - { |
|
| 153 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
| 160 | - */ |
|
| 161 | - public static function instance() |
|
| 162 | - { |
|
| 163 | - return parent::get_instance(__CLASS__); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @param WP_Query $WP_Query |
|
| 170 | - * @return void |
|
| 171 | - */ |
|
| 172 | - public function run($WP_Query) |
|
| 173 | - { |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Retrieves grand totals from the line items that have no TXN ID |
|
| 184 | - * and timestamps less than the current time minus the session lifespan. |
|
| 185 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
| 186 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
| 187 | - * |
|
| 188 | - * @return void |
|
| 189 | - * @throws DomainException |
|
| 190 | - * @throws EE_Error |
|
| 191 | - * @throws InvalidArgumentException |
|
| 192 | - * @throws InvalidDataTypeException |
|
| 193 | - * @throws InvalidInterfaceException |
|
| 194 | - * @throws UnexpectedEntityException |
|
| 195 | - */ |
|
| 196 | - public static function release_tickets_for_expired_carts() |
|
| 197 | - { |
|
| 198 | - if (self::debug) { |
|
| 199 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 200 | - } |
|
| 201 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
| 202 | - $expired_ticket_IDs = array(); |
|
| 203 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 204 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 205 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 206 | - ); |
|
| 207 | - $timestamp = $session_lifespan->expiration(); |
|
| 208 | - $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
| 209 | - if (self::debug) { |
|
| 210 | - echo self::$nl . ' . time(): ' . time(); |
|
| 211 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
| 212 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
| 213 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
| 214 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
| 215 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
| 216 | - } |
|
| 217 | - if (! empty($expired_ticket_line_items)) { |
|
| 218 | - foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
| 219 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
| 220 | - continue; |
|
| 221 | - } |
|
| 222 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
| 223 | - if (self::debug) { |
|
| 224 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
| 225 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' . date('Y-m-d h:i a', |
|
| 226 | - $expired_ticket_line_item->timestamp(true)); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - if (! empty($expired_ticket_IDs)) { |
|
| 230 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 231 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
| 232 | - array(), |
|
| 233 | - __FUNCTION__ |
|
| 234 | - ); |
|
| 235 | - // now let's get rid of expired line items so that they can't interfere with tracking |
|
| 236 | - EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - do_action( |
|
| 240 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 241 | - $expired_ticket_IDs, |
|
| 242 | - $expired_ticket_line_items |
|
| 243 | - ); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
| 254 | - * |
|
| 255 | - * @param int $qty |
|
| 256 | - * @param EE_Ticket $ticket |
|
| 257 | - * @return bool |
|
| 258 | - * @throws UnexpectedEntityException |
|
| 259 | - * @throws EE_Error |
|
| 260 | - */ |
|
| 261 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
| 262 | - { |
|
| 263 | - $qty = absint($qty); |
|
| 264 | - if ($qty > 0) { |
|
| 265 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
| 266 | - } |
|
| 267 | - if (self::debug) { |
|
| 268 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 269 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 270 | - } |
|
| 271 | - return $qty; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
| 278 | - * |
|
| 279 | - * @param EE_Ticket $ticket |
|
| 280 | - * @param int $qty |
|
| 281 | - * @return int |
|
| 282 | - * @throws UnexpectedEntityException |
|
| 283 | - * @throws EE_Error |
|
| 284 | - */ |
|
| 285 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
| 286 | - { |
|
| 287 | - if (self::debug) { |
|
| 288 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 289 | - } |
|
| 290 | - if (! $ticket instanceof EE_Ticket) { |
|
| 291 | - return 0; |
|
| 292 | - } |
|
| 293 | - if (self::debug) { |
|
| 294 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 295 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
| 296 | - } |
|
| 297 | - $ticket->refresh_from_db(); |
|
| 298 | - // first let's determine the ticket availability based on sales |
|
| 299 | - $available = $ticket->qty('saleable'); |
|
| 300 | - if (self::debug) { |
|
| 301 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
| 302 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
| 303 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 304 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 305 | - echo self::$nl . ' . . . available: ' . $available; |
|
| 306 | - } |
|
| 307 | - if ($available < 1) { |
|
| 308 | - $this->_ticket_sold_out($ticket); |
|
| 309 | - return 0; |
|
| 310 | - } |
|
| 311 | - if (self::debug) { |
|
| 312 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
| 313 | - } |
|
| 314 | - if ($available < $qty) { |
|
| 315 | - $qty = $available; |
|
| 316 | - if (self::debug) { |
|
| 317 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
| 318 | - } |
|
| 319 | - $this->_ticket_quantity_decremented($ticket); |
|
| 320 | - } |
|
| 321 | - $this->_reserve_ticket($ticket, $qty); |
|
| 322 | - return $qty; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * increments ticket reserved based on quantity passed |
|
| 329 | - * |
|
| 330 | - * @param EE_Ticket $ticket |
|
| 331 | - * @param int $quantity |
|
| 332 | - * @return bool |
|
| 333 | - * @throws EE_Error |
|
| 334 | - */ |
|
| 335 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 336 | - { |
|
| 337 | - if (self::debug) { |
|
| 338 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
| 339 | - } |
|
| 340 | - $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
| 341 | - return $ticket->save(); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @param EE_Ticket $ticket |
|
| 348 | - * @param int $quantity |
|
| 349 | - * @return bool |
|
| 350 | - * @throws EE_Error |
|
| 351 | - */ |
|
| 352 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 353 | - { |
|
| 354 | - if (self::debug) { |
|
| 355 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
| 356 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 357 | - } |
|
| 358 | - $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 359 | - if (self::debug) { |
|
| 360 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 361 | - } |
|
| 362 | - return $ticket->save() ? 1 : 0; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * removes quantities within the ticket selector based on zero ticket availability |
|
| 369 | - * |
|
| 370 | - * @param EE_Ticket $ticket |
|
| 371 | - * @return void |
|
| 372 | - * @throws UnexpectedEntityException |
|
| 373 | - * @throws EE_Error |
|
| 374 | - */ |
|
| 375 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
| 376 | - { |
|
| 377 | - if (self::debug) { |
|
| 378 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 379 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 380 | - } |
|
| 381 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
| 388 | - * |
|
| 389 | - * @param EE_Ticket $ticket |
|
| 390 | - * @return void |
|
| 391 | - * @throws UnexpectedEntityException |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
| 395 | - { |
|
| 396 | - if (self::debug) { |
|
| 397 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 398 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 399 | - } |
|
| 400 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * builds string out of ticket and event name |
|
| 407 | - * |
|
| 408 | - * @param EE_Ticket $ticket |
|
| 409 | - * @return string |
|
| 410 | - * @throws UnexpectedEntityException |
|
| 411 | - * @throws EE_Error |
|
| 412 | - */ |
|
| 413 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
| 414 | - { |
|
| 415 | - $event = $ticket->get_related_event(); |
|
| 416 | - if ($event instanceof EE_Event) { |
|
| 417 | - $ticket_name = sprintf( |
|
| 418 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
| 419 | - $ticket->name(), |
|
| 420 | - $event->name() |
|
| 421 | - ); |
|
| 422 | - } else { |
|
| 423 | - $ticket_name = $ticket->name(); |
|
| 424 | - } |
|
| 425 | - return $ticket_name; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /********************************** EVENT CART **********************************/ |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * releases or reserves ticket(s) based on quantity passed |
|
| 436 | - * |
|
| 437 | - * @param EE_Line_Item $line_item |
|
| 438 | - * @param int $quantity |
|
| 439 | - * @return void |
|
| 440 | - * @throws EE_Error |
|
| 441 | - * @throws InvalidArgumentException |
|
| 442 | - * @throws InvalidDataTypeException |
|
| 443 | - * @throws InvalidInterfaceException |
|
| 444 | - */ |
|
| 445 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
| 446 | - { |
|
| 447 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
| 448 | - if ($ticket instanceof EE_Ticket) { |
|
| 449 | - $ticket->add_extra_meta( |
|
| 450 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 451 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 452 | - ); |
|
| 453 | - if ($quantity > 0) { |
|
| 454 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
| 455 | - } else { |
|
| 456 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * releases reserved ticket(s) based on quantity passed |
|
| 465 | - * |
|
| 466 | - * @param EE_Ticket $ticket |
|
| 467 | - * @param int $quantity |
|
| 468 | - * @return void |
|
| 469 | - * @throws EE_Error |
|
| 470 | - */ |
|
| 471 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
| 472 | - { |
|
| 473 | - $ticket->add_extra_meta( |
|
| 474 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 475 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 476 | - ); |
|
| 477 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /********************************** POST_NOTICES **********************************/ |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @return void |
|
| 488 | - * @throws EE_Error |
|
| 489 | - * @throws InvalidArgumentException |
|
| 490 | - * @throws ReflectionException |
|
| 491 | - * @throws InvalidDataTypeException |
|
| 492 | - * @throws InvalidInterfaceException |
|
| 493 | - */ |
|
| 494 | - public static function post_notices() |
|
| 495 | - { |
|
| 496 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @return void |
|
| 503 | - * @throws EE_Error |
|
| 504 | - * @throws InvalidArgumentException |
|
| 505 | - * @throws ReflectionException |
|
| 506 | - * @throws InvalidDataTypeException |
|
| 507 | - * @throws InvalidInterfaceException |
|
| 508 | - */ |
|
| 509 | - protected function _post_notices() |
|
| 510 | - { |
|
| 511 | - if (self::debug) { |
|
| 512 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 513 | - } |
|
| 514 | - $refresh_msg = ''; |
|
| 515 | - $none_added_msg = ''; |
|
| 516 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 517 | - $refresh_msg = __( |
|
| 518 | - 'Please refresh the page to view updated ticket quantities.', |
|
| 519 | - 'event_espresso' |
|
| 520 | - ); |
|
| 521 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
| 522 | - } |
|
| 523 | - if (! empty($this->sold_out_tickets)) { |
|
| 524 | - EE_Error::add_attention( |
|
| 525 | - sprintf( |
|
| 526 | - apply_filters( |
|
| 527 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
| 528 | - __( |
|
| 529 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 530 | - 'event_espresso' |
|
| 531 | - ) |
|
| 532 | - ), |
|
| 533 | - '<br />', |
|
| 534 | - implode('<br />', $this->sold_out_tickets), |
|
| 535 | - $none_added_msg, |
|
| 536 | - $refresh_msg |
|
| 537 | - ) |
|
| 538 | - ); |
|
| 539 | - // alter code flow in the Ticket Selector for better UX |
|
| 540 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
| 541 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
| 542 | - $this->sold_out_tickets = array(); |
|
| 543 | - // and reset the cart |
|
| 544 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
| 545 | - } |
|
| 546 | - if (! empty($this->decremented_tickets)) { |
|
| 547 | - EE_Error::add_attention( |
|
| 548 | - sprintf( |
|
| 549 | - apply_filters( |
|
| 550 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
| 551 | - __( |
|
| 552 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 553 | - 'event_espresso' |
|
| 554 | - ) |
|
| 555 | - ), |
|
| 556 | - '<br />', |
|
| 557 | - implode('<br />', $this->decremented_tickets), |
|
| 558 | - $none_added_msg, |
|
| 559 | - $refresh_msg |
|
| 560 | - ) |
|
| 561 | - ); |
|
| 562 | - $this->decremented_tickets = array(); |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
| 574 | - * by default, will NOT release tickets for finalized transactions |
|
| 575 | - * |
|
| 576 | - * @param EE_Transaction $transaction |
|
| 577 | - * @return int |
|
| 578 | - * @throws EE_Error |
|
| 579 | - * @throws InvalidSessionDataException |
|
| 580 | - */ |
|
| 581 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
| 582 | - { |
|
| 583 | - if (self::debug) { |
|
| 584 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 585 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
| 586 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
| 587 | - } |
|
| 588 | - // check if 'finalize_registration' step has been completed... |
|
| 589 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 590 | - if (self::debug) { |
|
| 591 | - // DEBUG LOG |
|
| 592 | - EEH_Debug_Tools::log( |
|
| 593 | - __CLASS__, |
|
| 594 | - __FUNCTION__, |
|
| 595 | - __LINE__, |
|
| 596 | - array('finalized' => $finalized), |
|
| 597 | - false, |
|
| 598 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - // how many tickets were released |
|
| 602 | - $count = 0; |
|
| 603 | - if (self::debug) { |
|
| 604 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
| 605 | - } |
|
| 606 | - $release_tickets_with_TXN_status = array( |
|
| 607 | - EEM_Transaction::failed_status_code, |
|
| 608 | - EEM_Transaction::abandoned_status_code, |
|
| 609 | - EEM_Transaction::incomplete_status_code, |
|
| 610 | - ); |
|
| 611 | - $events = array(); |
|
| 612 | - // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
| 613 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 614 | - // cancel any reserved tickets for registrations that were not approved |
|
| 615 | - $registrations = $transaction->registrations(); |
|
| 616 | - if (self::debug) { |
|
| 617 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
| 618 | - $reg = reset($registrations); |
|
| 619 | - $ticket = $reg->ticket(); |
|
| 620 | - if ($ticket instanceof EE_Ticket) { |
|
| 621 | - $ticket->add_extra_meta( |
|
| 622 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 623 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 624 | - ); |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - if (! empty($registrations)) { |
|
| 628 | - foreach ($registrations as $registration) { |
|
| 629 | - if ( |
|
| 630 | - $registration instanceof EE_Registration |
|
| 631 | - && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
| 632 | - ) { |
|
| 633 | - $count++; |
|
| 634 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - if ($events !== array()) { |
|
| 640 | - foreach ($events as $event) { |
|
| 641 | - /** @var EE_Event $event */ |
|
| 642 | - $event->perform_sold_out_status_check(); |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - return $count; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * releases reserved tickets for an EE_Registration |
|
| 652 | - * by default, will NOT release tickets for APPROVED registrations |
|
| 653 | - * |
|
| 654 | - * @param EE_Registration $registration |
|
| 655 | - * @param EE_Transaction $transaction |
|
| 656 | - * @return int |
|
| 657 | - * @throws EE_Error |
|
| 658 | - */ |
|
| 659 | - protected function _release_reserved_ticket_for_registration( |
|
| 660 | - EE_Registration $registration, |
|
| 661 | - EE_Transaction $transaction |
|
| 662 | - ) { |
|
| 663 | - $STS_ID = $transaction->status_ID(); |
|
| 664 | - if (self::debug) { |
|
| 665 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 666 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
| 667 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
| 668 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
| 669 | - } |
|
| 670 | - if ( |
|
| 671 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
| 672 | - $STS_ID === EEM_Transaction::failed_status_code |
|
| 673 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
| 674 | - || ( |
|
| 675 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
| 676 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
| 677 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 678 | - ) |
|
| 679 | - ) { |
|
| 680 | - if (self::debug) { |
|
| 681 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
| 682 | - $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
| 683 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 684 | - var_dump($rsrvd); |
|
| 685 | - } |
|
| 686 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
| 687 | - return 1; |
|
| 688 | - } |
|
| 689 | - return 0; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /********************************** SESSION_CART_RESET **********************************/ |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
| 700 | - * |
|
| 701 | - * @param EE_Session $session |
|
| 702 | - * @return void |
|
| 703 | - * @throws EE_Error |
|
| 704 | - * @throws InvalidArgumentException |
|
| 705 | - * @throws ReflectionException |
|
| 706 | - * @throws InvalidDataTypeException |
|
| 707 | - * @throws InvalidInterfaceException |
|
| 708 | - */ |
|
| 709 | - public static function session_cart_reset(EE_Session $session) |
|
| 710 | - { |
|
| 711 | - if (self::debug) { |
|
| 712 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 713 | - } |
|
| 714 | - // first check of the session has a valid Checkout object |
|
| 715 | - $checkout = $session->checkout(); |
|
| 716 | - if ($checkout instanceof EE_Checkout) { |
|
| 717 | - // and use that to clear ticket reservations because it will update the associated registration meta data |
|
| 718 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 719 | - return; |
|
| 720 | - } |
|
| 721 | - $cart = $session->cart(); |
|
| 722 | - if ($cart instanceof EE_Cart) { |
|
| 723 | - if (self::debug) { |
|
| 724 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
| 725 | - } |
|
| 726 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
| 727 | - } else { |
|
| 728 | - if (self::debug) { |
|
| 729 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
| 730 | - var_export($cart, true); |
|
| 731 | - } |
|
| 732 | - } |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * releases reserved tickets in the EE_Cart |
|
| 739 | - * |
|
| 740 | - * @param EE_Cart $cart |
|
| 741 | - * @return void |
|
| 742 | - * @throws EE_Error |
|
| 743 | - * @throws InvalidArgumentException |
|
| 744 | - * @throws ReflectionException |
|
| 745 | - * @throws InvalidDataTypeException |
|
| 746 | - * @throws InvalidInterfaceException |
|
| 747 | - */ |
|
| 748 | - protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
| 749 | - { |
|
| 750 | - if (self::debug) { |
|
| 751 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 752 | - } |
|
| 753 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
| 754 | - $ticket_line_items = $cart->get_tickets(); |
|
| 755 | - if (empty($ticket_line_items)) { |
|
| 756 | - return; |
|
| 757 | - } |
|
| 758 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 759 | - if (self::debug) { |
|
| 760 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 761 | - } |
|
| 762 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
| 763 | - if (self::debug) { |
|
| 764 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 765 | - } |
|
| 766 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
| 767 | - if ($ticket instanceof EE_Ticket) { |
|
| 768 | - if (self::debug) { |
|
| 769 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
| 770 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 771 | - } |
|
| 772 | - $ticket->add_extra_meta( |
|
| 773 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 774 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 775 | - ); |
|
| 776 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - if (self::debug) { |
|
| 781 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
| 793 | - * |
|
| 794 | - * @param EE_Session $session |
|
| 795 | - * @return void |
|
| 796 | - * @throws EE_Error |
|
| 797 | - * @throws InvalidSessionDataException |
|
| 798 | - */ |
|
| 799 | - public static function session_checkout_reset(EE_Session $session) |
|
| 800 | - { |
|
| 801 | - $checkout = $session->checkout(); |
|
| 802 | - if ($checkout instanceof EE_Checkout) { |
|
| 803 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * releases reserved tickets for the EE_Checkout->transaction |
|
| 811 | - * |
|
| 812 | - * @param EE_Checkout $checkout |
|
| 813 | - * @return void |
|
| 814 | - * @throws EE_Error |
|
| 815 | - * @throws InvalidSessionDataException |
|
| 816 | - */ |
|
| 817 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
| 818 | - { |
|
| 819 | - if (self::debug) { |
|
| 820 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 821 | - } |
|
| 822 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
| 823 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
| 824 | - return; |
|
| 825 | - } |
|
| 826 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - |
|
| 830 | - |
|
| 831 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
| 832 | - |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * @param EE_Session $session |
|
| 837 | - * @return void |
|
| 838 | - */ |
|
| 839 | - public static function session_expired_reset(EE_Session $session) |
|
| 840 | - { |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
| 851 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
| 852 | - * |
|
| 853 | - * @param EE_Transaction $transaction |
|
| 854 | - * @return void |
|
| 855 | - * @throws EE_Error |
|
| 856 | - * @throws InvalidSessionDataException |
|
| 857 | - */ |
|
| 858 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
| 859 | - { |
|
| 860 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
| 861 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
| 862 | - if (self::debug) { |
|
| 863 | - // DEBUG LOG |
|
| 864 | - EEH_Debug_Tools::log( |
|
| 865 | - __CLASS__, |
|
| 866 | - __FUNCTION__, |
|
| 867 | - __LINE__, |
|
| 868 | - array($transaction), |
|
| 869 | - false, |
|
| 870 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 871 | - ); |
|
| 872 | - } |
|
| 873 | - return; |
|
| 874 | - } |
|
| 875 | - // have their been any successful payments made ? |
|
| 876 | - $payments = $transaction->payments(); |
|
| 877 | - foreach ($payments as $payment) { |
|
| 878 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
| 879 | - if (self::debug) { |
|
| 880 | - // DEBUG LOG |
|
| 881 | - EEH_Debug_Tools::log( |
|
| 882 | - __CLASS__, |
|
| 883 | - __FUNCTION__, |
|
| 884 | - __LINE__, |
|
| 885 | - array($payment), |
|
| 886 | - false, |
|
| 887 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 888 | - ); |
|
| 889 | - } |
|
| 890 | - return; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - // since you haven't even attempted to pay for your ticket... |
|
| 894 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
| 905 | - * |
|
| 906 | - * @param EE_Transaction $transaction |
|
| 907 | - * @return void |
|
| 908 | - * @throws EE_Error |
|
| 909 | - * @throws InvalidSessionDataException |
|
| 910 | - */ |
|
| 911 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
| 912 | - { |
|
| 913 | - // since you haven't even attempted to pay for your ticket... |
|
| 914 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - |
|
| 918 | - |
|
| 919 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
| 920 | - |
|
| 921 | - |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * Resets all ticket and datetime reserved counts to zero |
|
| 925 | - * Tickets that are currently associated with a Transaction that is in progress |
|
| 926 | - * |
|
| 927 | - * @throws EE_Error |
|
| 928 | - * @throws DomainException |
|
| 929 | - * @throws InvalidDataTypeException |
|
| 930 | - * @throws InvalidInterfaceException |
|
| 931 | - * @throws InvalidArgumentException |
|
| 932 | - * @throws UnexpectedEntityException |
|
| 933 | - */ |
|
| 934 | - public static function reset_reservation_counts() |
|
| 935 | - { |
|
| 936 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 937 | - $valid_reserved_tickets = array(); |
|
| 938 | - /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
| 939 | - $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
| 940 | - foreach ($transactions_not_in_progress as $transaction) { |
|
| 941 | - // if this TXN has been fully completed, then skip it |
|
| 942 | - if ($transaction->reg_step_completed('finalize_registration')) { |
|
| 943 | - continue; |
|
| 944 | - } |
|
| 945 | - $total_line_item = $transaction->total_line_item(); |
|
| 946 | - // $transaction_in_progress->line |
|
| 947 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
| 948 | - throw new DomainException( |
|
| 949 | - esc_html__( |
|
| 950 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
| 951 | - 'event_espresso' |
|
| 952 | - ) |
|
| 953 | - ); |
|
| 954 | - } |
|
| 955 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 956 | - $total_line_item |
|
| 957 | - ); |
|
| 958 | - } |
|
| 959 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
| 960 | - foreach ($total_line_items as $total_line_item) { |
|
| 961 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 962 | - $total_line_item |
|
| 963 | - ); |
|
| 964 | - } |
|
| 965 | - $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
| 966 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 967 | - $tickets_with_reservations, |
|
| 968 | - $valid_reserved_tickets, |
|
| 969 | - __FUNCTION__ |
|
| 970 | - ); |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - |
|
| 975 | - /** |
|
| 976 | - * @param EE_Line_Item $total_line_item |
|
| 977 | - * @return EE_Line_Item[] |
|
| 978 | - */ |
|
| 979 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
| 980 | - { |
|
| 981 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 982 | - $valid_reserved_tickets = array(); |
|
| 983 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 984 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 985 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
| 986 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - return $valid_reserved_tickets; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - |
|
| 994 | - /** |
|
| 995 | - * @param EE_Ticket[] $tickets_with_reservations |
|
| 996 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
| 997 | - * @return int |
|
| 998 | - * @throws UnexpectedEntityException |
|
| 999 | - * @throws DomainException |
|
| 1000 | - * @throws EE_Error |
|
| 1001 | - */ |
|
| 1002 | - private static function release_reservations_for_tickets( |
|
| 1003 | - array $tickets_with_reservations, |
|
| 1004 | - array $valid_reserved_ticket_line_items = array(), |
|
| 1005 | - $source |
|
| 1006 | - ) { |
|
| 1007 | - if (self::debug) { |
|
| 1008 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 1009 | - } |
|
| 1010 | - $total_tickets_released = 0; |
|
| 1011 | - $sold_out_events = array(); |
|
| 1012 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
| 1013 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1014 | - continue; |
|
| 1015 | - } |
|
| 1016 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
| 1017 | - if (self::debug) { |
|
| 1018 | - echo self::$nl . ' . $ticket_with_reservations->ID(): ' . $ticket_with_reservations->ID(); |
|
| 1019 | - echo self::$nl . ' . $reserved_qty: ' . $reserved_qty; |
|
| 1020 | - } |
|
| 1021 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
| 1022 | - if ( |
|
| 1023 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
| 1024 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
| 1025 | - ) { |
|
| 1026 | - if (self::debug) { |
|
| 1027 | - echo self::$nl . ' . $valid_reserved_ticket_line_item->quantity(): ' . $valid_reserved_ticket_line_item->quantity(); |
|
| 1028 | - } |
|
| 1029 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1032 | - if ($reserved_qty > 0) { |
|
| 1033 | - $ticket_with_reservations->add_extra_meta( |
|
| 1034 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 1035 | - __LINE__ . ') ' . $source . '()' |
|
| 1036 | - ); |
|
| 1037 | - $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 1038 | - $ticket_with_reservations->save(); |
|
| 1039 | - $total_tickets_released += $reserved_qty; |
|
| 1040 | - $event = $ticket_with_reservations->get_related_event(); |
|
| 1041 | - // track sold out events |
|
| 1042 | - if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
| 1043 | - $sold_out_events[] = $event; |
|
| 1044 | - } |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1047 | - if (self::debug) { |
|
| 1048 | - echo self::$nl . ' . $total_tickets_released: ' . $total_tickets_released; |
|
| 1049 | - } |
|
| 1050 | - // double check whether sold out events should remain sold out after releasing tickets |
|
| 1051 | - if($sold_out_events !== array()){ |
|
| 1052 | - foreach ($sold_out_events as $sold_out_event) { |
|
| 1053 | - /** @var EE_Event $sold_out_event */ |
|
| 1054 | - $sold_out_event->perform_sold_out_status_check(); |
|
| 1055 | - } |
|
| 1056 | - } |
|
| 1057 | - return $total_tickets_released; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - |
|
| 1062 | - /********************************** SHUTDOWN **********************************/ |
|
| 1063 | - |
|
| 1064 | - |
|
| 1065 | - |
|
| 1066 | - /** |
|
| 1067 | - * @param int $timestamp |
|
| 1068 | - * @return false|int |
|
| 1069 | - * @throws EE_Error |
|
| 1070 | - * @throws InvalidArgumentException |
|
| 1071 | - * @throws InvalidDataTypeException |
|
| 1072 | - * @throws InvalidInterfaceException |
|
| 1073 | - */ |
|
| 1074 | - public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
| 1075 | - { |
|
| 1076 | - /** @type WPDB $wpdb */ |
|
| 1077 | - global $wpdb; |
|
| 1078 | - if (! absint($timestamp)) { |
|
| 1079 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 1080 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 1081 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 1082 | - ); |
|
| 1083 | - $timestamp = $session_lifespan->expiration(); |
|
| 1084 | - } |
|
| 1085 | - return $wpdb->query( |
|
| 1086 | - $wpdb->prepare( |
|
| 1087 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 27 | + const debug = false; // true false |
|
| 28 | + |
|
| 29 | + private static $nl = ''; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * an array of raw ticket data from EED_Ticket_Selector |
|
| 33 | + * |
|
| 34 | + * @var array $ticket_selections |
|
| 35 | + */ |
|
| 36 | + protected $ticket_selections = array(); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
| 40 | + * according to how they are displayed in the actual Ticket_Selector |
|
| 41 | + * this tracks the current row being processed |
|
| 42 | + * |
|
| 43 | + * @var int $current_row |
|
| 44 | + */ |
|
| 45 | + protected $current_row = 0; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * an array for tracking names of tickets that have sold out |
|
| 49 | + * |
|
| 50 | + * @var array $sold_out_tickets |
|
| 51 | + */ |
|
| 52 | + protected $sold_out_tickets = array(); |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * an array for tracking names of tickets that have had their quantities reduced |
|
| 56 | + * |
|
| 57 | + * @var array $decremented_tickets |
|
| 58 | + */ |
|
| 59 | + protected $decremented_tickets = array(); |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public static function set_hooks() |
|
| 69 | + { |
|
| 70 | + self::$nl = defined('EE_TESTS_DIR')? "\n" : '<br />'; |
|
| 71 | + // release tickets for expired carts |
|
| 72 | + add_action( |
|
| 73 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 74 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
| 75 | + 1 |
|
| 76 | + ); |
|
| 77 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
| 78 | + add_filter( |
|
| 79 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
| 80 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
| 81 | + 20, |
|
| 82 | + 3 |
|
| 83 | + ); |
|
| 84 | + // add notices for sold out tickets |
|
| 85 | + add_action( |
|
| 86 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 87 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
| 88 | + 10 |
|
| 89 | + ); |
|
| 90 | + // handle ticket quantities adjusted in cart |
|
| 91 | + //add_action( |
|
| 92 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
| 93 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
| 94 | + // 10, 2 |
|
| 95 | + //); |
|
| 96 | + // handle tickets deleted from cart |
|
| 97 | + add_action( |
|
| 98 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
| 99 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
| 100 | + 10, |
|
| 101 | + 2 |
|
| 102 | + ); |
|
| 103 | + // handle emptied carts |
|
| 104 | + add_action( |
|
| 105 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
| 106 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 107 | + 10, |
|
| 108 | + 1 |
|
| 109 | + ); |
|
| 110 | + add_action( |
|
| 111 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
| 112 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 113 | + 10, |
|
| 114 | + 1 |
|
| 115 | + ); |
|
| 116 | + // handle cancelled registrations |
|
| 117 | + add_action( |
|
| 118 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
| 119 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
| 120 | + 10, |
|
| 121 | + 1 |
|
| 122 | + ); |
|
| 123 | + // cron tasks |
|
| 124 | + add_action( |
|
| 125 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 126 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 127 | + 10, |
|
| 128 | + 1 |
|
| 129 | + ); |
|
| 130 | + add_action( |
|
| 131 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 132 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 133 | + 10, |
|
| 134 | + 1 |
|
| 135 | + ); |
|
| 136 | + add_action( |
|
| 137 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 138 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
| 139 | + 10, |
|
| 140 | + 1 |
|
| 141 | + ); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 148 | + * |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + public static function set_hooks_admin() |
|
| 152 | + { |
|
| 153 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
| 160 | + */ |
|
| 161 | + public static function instance() |
|
| 162 | + { |
|
| 163 | + return parent::get_instance(__CLASS__); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @param WP_Query $WP_Query |
|
| 170 | + * @return void |
|
| 171 | + */ |
|
| 172 | + public function run($WP_Query) |
|
| 173 | + { |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Retrieves grand totals from the line items that have no TXN ID |
|
| 184 | + * and timestamps less than the current time minus the session lifespan. |
|
| 185 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
| 186 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
| 187 | + * |
|
| 188 | + * @return void |
|
| 189 | + * @throws DomainException |
|
| 190 | + * @throws EE_Error |
|
| 191 | + * @throws InvalidArgumentException |
|
| 192 | + * @throws InvalidDataTypeException |
|
| 193 | + * @throws InvalidInterfaceException |
|
| 194 | + * @throws UnexpectedEntityException |
|
| 195 | + */ |
|
| 196 | + public static function release_tickets_for_expired_carts() |
|
| 197 | + { |
|
| 198 | + if (self::debug) { |
|
| 199 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 200 | + } |
|
| 201 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
| 202 | + $expired_ticket_IDs = array(); |
|
| 203 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 204 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 205 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 206 | + ); |
|
| 207 | + $timestamp = $session_lifespan->expiration(); |
|
| 208 | + $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
| 209 | + if (self::debug) { |
|
| 210 | + echo self::$nl . ' . time(): ' . time(); |
|
| 211 | + echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
| 212 | + echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
| 213 | + echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
| 214 | + echo self::$nl . ' . timestamp: ' . $timestamp; |
|
| 215 | + echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
| 216 | + } |
|
| 217 | + if (! empty($expired_ticket_line_items)) { |
|
| 218 | + foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
| 219 | + if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
| 220 | + continue; |
|
| 221 | + } |
|
| 222 | + $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
| 223 | + if (self::debug) { |
|
| 224 | + echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
| 225 | + echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' . date('Y-m-d h:i a', |
|
| 226 | + $expired_ticket_line_item->timestamp(true)); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + if (! empty($expired_ticket_IDs)) { |
|
| 230 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 231 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
| 232 | + array(), |
|
| 233 | + __FUNCTION__ |
|
| 234 | + ); |
|
| 235 | + // now let's get rid of expired line items so that they can't interfere with tracking |
|
| 236 | + EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + do_action( |
|
| 240 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 241 | + $expired_ticket_IDs, |
|
| 242 | + $expired_ticket_line_items |
|
| 243 | + ); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
| 254 | + * |
|
| 255 | + * @param int $qty |
|
| 256 | + * @param EE_Ticket $ticket |
|
| 257 | + * @return bool |
|
| 258 | + * @throws UnexpectedEntityException |
|
| 259 | + * @throws EE_Error |
|
| 260 | + */ |
|
| 261 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
| 262 | + { |
|
| 263 | + $qty = absint($qty); |
|
| 264 | + if ($qty > 0) { |
|
| 265 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
| 266 | + } |
|
| 267 | + if (self::debug) { |
|
| 268 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 269 | + echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 270 | + } |
|
| 271 | + return $qty; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
| 278 | + * |
|
| 279 | + * @param EE_Ticket $ticket |
|
| 280 | + * @param int $qty |
|
| 281 | + * @return int |
|
| 282 | + * @throws UnexpectedEntityException |
|
| 283 | + * @throws EE_Error |
|
| 284 | + */ |
|
| 285 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
| 286 | + { |
|
| 287 | + if (self::debug) { |
|
| 288 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 289 | + } |
|
| 290 | + if (! $ticket instanceof EE_Ticket) { |
|
| 291 | + return 0; |
|
| 292 | + } |
|
| 293 | + if (self::debug) { |
|
| 294 | + echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 295 | + echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
| 296 | + } |
|
| 297 | + $ticket->refresh_from_db(); |
|
| 298 | + // first let's determine the ticket availability based on sales |
|
| 299 | + $available = $ticket->qty('saleable'); |
|
| 300 | + if (self::debug) { |
|
| 301 | + echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
| 302 | + echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
| 303 | + echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 304 | + echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 305 | + echo self::$nl . ' . . . available: ' . $available; |
|
| 306 | + } |
|
| 307 | + if ($available < 1) { |
|
| 308 | + $this->_ticket_sold_out($ticket); |
|
| 309 | + return 0; |
|
| 310 | + } |
|
| 311 | + if (self::debug) { |
|
| 312 | + echo self::$nl . ' . . . qty: ' . $qty; |
|
| 313 | + } |
|
| 314 | + if ($available < $qty) { |
|
| 315 | + $qty = $available; |
|
| 316 | + if (self::debug) { |
|
| 317 | + echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
| 318 | + } |
|
| 319 | + $this->_ticket_quantity_decremented($ticket); |
|
| 320 | + } |
|
| 321 | + $this->_reserve_ticket($ticket, $qty); |
|
| 322 | + return $qty; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * increments ticket reserved based on quantity passed |
|
| 329 | + * |
|
| 330 | + * @param EE_Ticket $ticket |
|
| 331 | + * @param int $quantity |
|
| 332 | + * @return bool |
|
| 333 | + * @throws EE_Error |
|
| 334 | + */ |
|
| 335 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 336 | + { |
|
| 337 | + if (self::debug) { |
|
| 338 | + echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
| 339 | + } |
|
| 340 | + $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
| 341 | + return $ticket->save(); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @param EE_Ticket $ticket |
|
| 348 | + * @param int $quantity |
|
| 349 | + * @return bool |
|
| 350 | + * @throws EE_Error |
|
| 351 | + */ |
|
| 352 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 353 | + { |
|
| 354 | + if (self::debug) { |
|
| 355 | + echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
| 356 | + echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 357 | + } |
|
| 358 | + $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 359 | + if (self::debug) { |
|
| 360 | + echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 361 | + } |
|
| 362 | + return $ticket->save() ? 1 : 0; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * removes quantities within the ticket selector based on zero ticket availability |
|
| 369 | + * |
|
| 370 | + * @param EE_Ticket $ticket |
|
| 371 | + * @return void |
|
| 372 | + * @throws UnexpectedEntityException |
|
| 373 | + * @throws EE_Error |
|
| 374 | + */ |
|
| 375 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
| 376 | + { |
|
| 377 | + if (self::debug) { |
|
| 378 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 379 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 380 | + } |
|
| 381 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
| 388 | + * |
|
| 389 | + * @param EE_Ticket $ticket |
|
| 390 | + * @return void |
|
| 391 | + * @throws UnexpectedEntityException |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
| 395 | + { |
|
| 396 | + if (self::debug) { |
|
| 397 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 398 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 399 | + } |
|
| 400 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * builds string out of ticket and event name |
|
| 407 | + * |
|
| 408 | + * @param EE_Ticket $ticket |
|
| 409 | + * @return string |
|
| 410 | + * @throws UnexpectedEntityException |
|
| 411 | + * @throws EE_Error |
|
| 412 | + */ |
|
| 413 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
| 414 | + { |
|
| 415 | + $event = $ticket->get_related_event(); |
|
| 416 | + if ($event instanceof EE_Event) { |
|
| 417 | + $ticket_name = sprintf( |
|
| 418 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
| 419 | + $ticket->name(), |
|
| 420 | + $event->name() |
|
| 421 | + ); |
|
| 422 | + } else { |
|
| 423 | + $ticket_name = $ticket->name(); |
|
| 424 | + } |
|
| 425 | + return $ticket_name; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /********************************** EVENT CART **********************************/ |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * releases or reserves ticket(s) based on quantity passed |
|
| 436 | + * |
|
| 437 | + * @param EE_Line_Item $line_item |
|
| 438 | + * @param int $quantity |
|
| 439 | + * @return void |
|
| 440 | + * @throws EE_Error |
|
| 441 | + * @throws InvalidArgumentException |
|
| 442 | + * @throws InvalidDataTypeException |
|
| 443 | + * @throws InvalidInterfaceException |
|
| 444 | + */ |
|
| 445 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
| 446 | + { |
|
| 447 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
| 448 | + if ($ticket instanceof EE_Ticket) { |
|
| 449 | + $ticket->add_extra_meta( |
|
| 450 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 451 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
| 452 | + ); |
|
| 453 | + if ($quantity > 0) { |
|
| 454 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
| 455 | + } else { |
|
| 456 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * releases reserved ticket(s) based on quantity passed |
|
| 465 | + * |
|
| 466 | + * @param EE_Ticket $ticket |
|
| 467 | + * @param int $quantity |
|
| 468 | + * @return void |
|
| 469 | + * @throws EE_Error |
|
| 470 | + */ |
|
| 471 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
| 472 | + { |
|
| 473 | + $ticket->add_extra_meta( |
|
| 474 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 475 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
| 476 | + ); |
|
| 477 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /********************************** POST_NOTICES **********************************/ |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * @return void |
|
| 488 | + * @throws EE_Error |
|
| 489 | + * @throws InvalidArgumentException |
|
| 490 | + * @throws ReflectionException |
|
| 491 | + * @throws InvalidDataTypeException |
|
| 492 | + * @throws InvalidInterfaceException |
|
| 493 | + */ |
|
| 494 | + public static function post_notices() |
|
| 495 | + { |
|
| 496 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @return void |
|
| 503 | + * @throws EE_Error |
|
| 504 | + * @throws InvalidArgumentException |
|
| 505 | + * @throws ReflectionException |
|
| 506 | + * @throws InvalidDataTypeException |
|
| 507 | + * @throws InvalidInterfaceException |
|
| 508 | + */ |
|
| 509 | + protected function _post_notices() |
|
| 510 | + { |
|
| 511 | + if (self::debug) { |
|
| 512 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 513 | + } |
|
| 514 | + $refresh_msg = ''; |
|
| 515 | + $none_added_msg = ''; |
|
| 516 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 517 | + $refresh_msg = __( |
|
| 518 | + 'Please refresh the page to view updated ticket quantities.', |
|
| 519 | + 'event_espresso' |
|
| 520 | + ); |
|
| 521 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
| 522 | + } |
|
| 523 | + if (! empty($this->sold_out_tickets)) { |
|
| 524 | + EE_Error::add_attention( |
|
| 525 | + sprintf( |
|
| 526 | + apply_filters( |
|
| 527 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
| 528 | + __( |
|
| 529 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 530 | + 'event_espresso' |
|
| 531 | + ) |
|
| 532 | + ), |
|
| 533 | + '<br />', |
|
| 534 | + implode('<br />', $this->sold_out_tickets), |
|
| 535 | + $none_added_msg, |
|
| 536 | + $refresh_msg |
|
| 537 | + ) |
|
| 538 | + ); |
|
| 539 | + // alter code flow in the Ticket Selector for better UX |
|
| 540 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
| 541 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
| 542 | + $this->sold_out_tickets = array(); |
|
| 543 | + // and reset the cart |
|
| 544 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
| 545 | + } |
|
| 546 | + if (! empty($this->decremented_tickets)) { |
|
| 547 | + EE_Error::add_attention( |
|
| 548 | + sprintf( |
|
| 549 | + apply_filters( |
|
| 550 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
| 551 | + __( |
|
| 552 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 553 | + 'event_espresso' |
|
| 554 | + ) |
|
| 555 | + ), |
|
| 556 | + '<br />', |
|
| 557 | + implode('<br />', $this->decremented_tickets), |
|
| 558 | + $none_added_msg, |
|
| 559 | + $refresh_msg |
|
| 560 | + ) |
|
| 561 | + ); |
|
| 562 | + $this->decremented_tickets = array(); |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
| 574 | + * by default, will NOT release tickets for finalized transactions |
|
| 575 | + * |
|
| 576 | + * @param EE_Transaction $transaction |
|
| 577 | + * @return int |
|
| 578 | + * @throws EE_Error |
|
| 579 | + * @throws InvalidSessionDataException |
|
| 580 | + */ |
|
| 581 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
| 582 | + { |
|
| 583 | + if (self::debug) { |
|
| 584 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 585 | + echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
| 586 | + echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
| 587 | + } |
|
| 588 | + // check if 'finalize_registration' step has been completed... |
|
| 589 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 590 | + if (self::debug) { |
|
| 591 | + // DEBUG LOG |
|
| 592 | + EEH_Debug_Tools::log( |
|
| 593 | + __CLASS__, |
|
| 594 | + __FUNCTION__, |
|
| 595 | + __LINE__, |
|
| 596 | + array('finalized' => $finalized), |
|
| 597 | + false, |
|
| 598 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + // how many tickets were released |
|
| 602 | + $count = 0; |
|
| 603 | + if (self::debug) { |
|
| 604 | + echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
| 605 | + } |
|
| 606 | + $release_tickets_with_TXN_status = array( |
|
| 607 | + EEM_Transaction::failed_status_code, |
|
| 608 | + EEM_Transaction::abandoned_status_code, |
|
| 609 | + EEM_Transaction::incomplete_status_code, |
|
| 610 | + ); |
|
| 611 | + $events = array(); |
|
| 612 | + // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
| 613 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 614 | + // cancel any reserved tickets for registrations that were not approved |
|
| 615 | + $registrations = $transaction->registrations(); |
|
| 616 | + if (self::debug) { |
|
| 617 | + echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
| 618 | + $reg = reset($registrations); |
|
| 619 | + $ticket = $reg->ticket(); |
|
| 620 | + if ($ticket instanceof EE_Ticket) { |
|
| 621 | + $ticket->add_extra_meta( |
|
| 622 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 623 | + __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 624 | + ); |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + if (! empty($registrations)) { |
|
| 628 | + foreach ($registrations as $registration) { |
|
| 629 | + if ( |
|
| 630 | + $registration instanceof EE_Registration |
|
| 631 | + && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
| 632 | + ) { |
|
| 633 | + $count++; |
|
| 634 | + $events[ $registration->event_ID() ] = $registration->event(); |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + if ($events !== array()) { |
|
| 640 | + foreach ($events as $event) { |
|
| 641 | + /** @var EE_Event $event */ |
|
| 642 | + $event->perform_sold_out_status_check(); |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + return $count; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * releases reserved tickets for an EE_Registration |
|
| 652 | + * by default, will NOT release tickets for APPROVED registrations |
|
| 653 | + * |
|
| 654 | + * @param EE_Registration $registration |
|
| 655 | + * @param EE_Transaction $transaction |
|
| 656 | + * @return int |
|
| 657 | + * @throws EE_Error |
|
| 658 | + */ |
|
| 659 | + protected function _release_reserved_ticket_for_registration( |
|
| 660 | + EE_Registration $registration, |
|
| 661 | + EE_Transaction $transaction |
|
| 662 | + ) { |
|
| 663 | + $STS_ID = $transaction->status_ID(); |
|
| 664 | + if (self::debug) { |
|
| 665 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 666 | + echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
| 667 | + echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
| 668 | + echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
| 669 | + } |
|
| 670 | + if ( |
|
| 671 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
| 672 | + $STS_ID === EEM_Transaction::failed_status_code |
|
| 673 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
| 674 | + || ( |
|
| 675 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
| 676 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
| 677 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 678 | + ) |
|
| 679 | + ) { |
|
| 680 | + if (self::debug) { |
|
| 681 | + echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
| 682 | + $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
| 683 | + echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 684 | + var_dump($rsrvd); |
|
| 685 | + } |
|
| 686 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
| 687 | + return 1; |
|
| 688 | + } |
|
| 689 | + return 0; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /********************************** SESSION_CART_RESET **********************************/ |
|
| 695 | + |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
| 700 | + * |
|
| 701 | + * @param EE_Session $session |
|
| 702 | + * @return void |
|
| 703 | + * @throws EE_Error |
|
| 704 | + * @throws InvalidArgumentException |
|
| 705 | + * @throws ReflectionException |
|
| 706 | + * @throws InvalidDataTypeException |
|
| 707 | + * @throws InvalidInterfaceException |
|
| 708 | + */ |
|
| 709 | + public static function session_cart_reset(EE_Session $session) |
|
| 710 | + { |
|
| 711 | + if (self::debug) { |
|
| 712 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 713 | + } |
|
| 714 | + // first check of the session has a valid Checkout object |
|
| 715 | + $checkout = $session->checkout(); |
|
| 716 | + if ($checkout instanceof EE_Checkout) { |
|
| 717 | + // and use that to clear ticket reservations because it will update the associated registration meta data |
|
| 718 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 719 | + return; |
|
| 720 | + } |
|
| 721 | + $cart = $session->cart(); |
|
| 722 | + if ($cart instanceof EE_Cart) { |
|
| 723 | + if (self::debug) { |
|
| 724 | + echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
| 725 | + } |
|
| 726 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
| 727 | + } else { |
|
| 728 | + if (self::debug) { |
|
| 729 | + echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
| 730 | + var_export($cart, true); |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * releases reserved tickets in the EE_Cart |
|
| 739 | + * |
|
| 740 | + * @param EE_Cart $cart |
|
| 741 | + * @return void |
|
| 742 | + * @throws EE_Error |
|
| 743 | + * @throws InvalidArgumentException |
|
| 744 | + * @throws ReflectionException |
|
| 745 | + * @throws InvalidDataTypeException |
|
| 746 | + * @throws InvalidInterfaceException |
|
| 747 | + */ |
|
| 748 | + protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
| 749 | + { |
|
| 750 | + if (self::debug) { |
|
| 751 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 752 | + } |
|
| 753 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
| 754 | + $ticket_line_items = $cart->get_tickets(); |
|
| 755 | + if (empty($ticket_line_items)) { |
|
| 756 | + return; |
|
| 757 | + } |
|
| 758 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 759 | + if (self::debug) { |
|
| 760 | + echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 761 | + } |
|
| 762 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
| 763 | + if (self::debug) { |
|
| 764 | + echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 765 | + } |
|
| 766 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
| 767 | + if ($ticket instanceof EE_Ticket) { |
|
| 768 | + if (self::debug) { |
|
| 769 | + echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
| 770 | + echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 771 | + } |
|
| 772 | + $ticket->add_extra_meta( |
|
| 773 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 774 | + __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 775 | + ); |
|
| 776 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + if (self::debug) { |
|
| 781 | + echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
| 793 | + * |
|
| 794 | + * @param EE_Session $session |
|
| 795 | + * @return void |
|
| 796 | + * @throws EE_Error |
|
| 797 | + * @throws InvalidSessionDataException |
|
| 798 | + */ |
|
| 799 | + public static function session_checkout_reset(EE_Session $session) |
|
| 800 | + { |
|
| 801 | + $checkout = $session->checkout(); |
|
| 802 | + if ($checkout instanceof EE_Checkout) { |
|
| 803 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * releases reserved tickets for the EE_Checkout->transaction |
|
| 811 | + * |
|
| 812 | + * @param EE_Checkout $checkout |
|
| 813 | + * @return void |
|
| 814 | + * @throws EE_Error |
|
| 815 | + * @throws InvalidSessionDataException |
|
| 816 | + */ |
|
| 817 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
| 818 | + { |
|
| 819 | + if (self::debug) { |
|
| 820 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 821 | + } |
|
| 822 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
| 823 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
| 824 | + return; |
|
| 825 | + } |
|
| 826 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + |
|
| 830 | + |
|
| 831 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
| 832 | + |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * @param EE_Session $session |
|
| 837 | + * @return void |
|
| 838 | + */ |
|
| 839 | + public static function session_expired_reset(EE_Session $session) |
|
| 840 | + { |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
| 851 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
| 852 | + * |
|
| 853 | + * @param EE_Transaction $transaction |
|
| 854 | + * @return void |
|
| 855 | + * @throws EE_Error |
|
| 856 | + * @throws InvalidSessionDataException |
|
| 857 | + */ |
|
| 858 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
| 859 | + { |
|
| 860 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
| 861 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
| 862 | + if (self::debug) { |
|
| 863 | + // DEBUG LOG |
|
| 864 | + EEH_Debug_Tools::log( |
|
| 865 | + __CLASS__, |
|
| 866 | + __FUNCTION__, |
|
| 867 | + __LINE__, |
|
| 868 | + array($transaction), |
|
| 869 | + false, |
|
| 870 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 871 | + ); |
|
| 872 | + } |
|
| 873 | + return; |
|
| 874 | + } |
|
| 875 | + // have their been any successful payments made ? |
|
| 876 | + $payments = $transaction->payments(); |
|
| 877 | + foreach ($payments as $payment) { |
|
| 878 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
| 879 | + if (self::debug) { |
|
| 880 | + // DEBUG LOG |
|
| 881 | + EEH_Debug_Tools::log( |
|
| 882 | + __CLASS__, |
|
| 883 | + __FUNCTION__, |
|
| 884 | + __LINE__, |
|
| 885 | + array($payment), |
|
| 886 | + false, |
|
| 887 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 888 | + ); |
|
| 889 | + } |
|
| 890 | + return; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + // since you haven't even attempted to pay for your ticket... |
|
| 894 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
| 905 | + * |
|
| 906 | + * @param EE_Transaction $transaction |
|
| 907 | + * @return void |
|
| 908 | + * @throws EE_Error |
|
| 909 | + * @throws InvalidSessionDataException |
|
| 910 | + */ |
|
| 911 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
| 912 | + { |
|
| 913 | + // since you haven't even attempted to pay for your ticket... |
|
| 914 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + |
|
| 918 | + |
|
| 919 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
| 920 | + |
|
| 921 | + |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * Resets all ticket and datetime reserved counts to zero |
|
| 925 | + * Tickets that are currently associated with a Transaction that is in progress |
|
| 926 | + * |
|
| 927 | + * @throws EE_Error |
|
| 928 | + * @throws DomainException |
|
| 929 | + * @throws InvalidDataTypeException |
|
| 930 | + * @throws InvalidInterfaceException |
|
| 931 | + * @throws InvalidArgumentException |
|
| 932 | + * @throws UnexpectedEntityException |
|
| 933 | + */ |
|
| 934 | + public static function reset_reservation_counts() |
|
| 935 | + { |
|
| 936 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 937 | + $valid_reserved_tickets = array(); |
|
| 938 | + /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
| 939 | + $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
| 940 | + foreach ($transactions_not_in_progress as $transaction) { |
|
| 941 | + // if this TXN has been fully completed, then skip it |
|
| 942 | + if ($transaction->reg_step_completed('finalize_registration')) { |
|
| 943 | + continue; |
|
| 944 | + } |
|
| 945 | + $total_line_item = $transaction->total_line_item(); |
|
| 946 | + // $transaction_in_progress->line |
|
| 947 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
| 948 | + throw new DomainException( |
|
| 949 | + esc_html__( |
|
| 950 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
| 951 | + 'event_espresso' |
|
| 952 | + ) |
|
| 953 | + ); |
|
| 954 | + } |
|
| 955 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 956 | + $total_line_item |
|
| 957 | + ); |
|
| 958 | + } |
|
| 959 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
| 960 | + foreach ($total_line_items as $total_line_item) { |
|
| 961 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 962 | + $total_line_item |
|
| 963 | + ); |
|
| 964 | + } |
|
| 965 | + $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
| 966 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 967 | + $tickets_with_reservations, |
|
| 968 | + $valid_reserved_tickets, |
|
| 969 | + __FUNCTION__ |
|
| 970 | + ); |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + |
|
| 975 | + /** |
|
| 976 | + * @param EE_Line_Item $total_line_item |
|
| 977 | + * @return EE_Line_Item[] |
|
| 978 | + */ |
|
| 979 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
| 980 | + { |
|
| 981 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 982 | + $valid_reserved_tickets = array(); |
|
| 983 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 984 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 985 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
| 986 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + return $valid_reserved_tickets; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + |
|
| 994 | + /** |
|
| 995 | + * @param EE_Ticket[] $tickets_with_reservations |
|
| 996 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
| 997 | + * @return int |
|
| 998 | + * @throws UnexpectedEntityException |
|
| 999 | + * @throws DomainException |
|
| 1000 | + * @throws EE_Error |
|
| 1001 | + */ |
|
| 1002 | + private static function release_reservations_for_tickets( |
|
| 1003 | + array $tickets_with_reservations, |
|
| 1004 | + array $valid_reserved_ticket_line_items = array(), |
|
| 1005 | + $source |
|
| 1006 | + ) { |
|
| 1007 | + if (self::debug) { |
|
| 1008 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 1009 | + } |
|
| 1010 | + $total_tickets_released = 0; |
|
| 1011 | + $sold_out_events = array(); |
|
| 1012 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
| 1013 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1014 | + continue; |
|
| 1015 | + } |
|
| 1016 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
| 1017 | + if (self::debug) { |
|
| 1018 | + echo self::$nl . ' . $ticket_with_reservations->ID(): ' . $ticket_with_reservations->ID(); |
|
| 1019 | + echo self::$nl . ' . $reserved_qty: ' . $reserved_qty; |
|
| 1020 | + } |
|
| 1021 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
| 1022 | + if ( |
|
| 1023 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
| 1024 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
| 1025 | + ) { |
|
| 1026 | + if (self::debug) { |
|
| 1027 | + echo self::$nl . ' . $valid_reserved_ticket_line_item->quantity(): ' . $valid_reserved_ticket_line_item->quantity(); |
|
| 1028 | + } |
|
| 1029 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | + if ($reserved_qty > 0) { |
|
| 1033 | + $ticket_with_reservations->add_extra_meta( |
|
| 1034 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 1035 | + __LINE__ . ') ' . $source . '()' |
|
| 1036 | + ); |
|
| 1037 | + $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 1038 | + $ticket_with_reservations->save(); |
|
| 1039 | + $total_tickets_released += $reserved_qty; |
|
| 1040 | + $event = $ticket_with_reservations->get_related_event(); |
|
| 1041 | + // track sold out events |
|
| 1042 | + if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
| 1043 | + $sold_out_events[] = $event; |
|
| 1044 | + } |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | + if (self::debug) { |
|
| 1048 | + echo self::$nl . ' . $total_tickets_released: ' . $total_tickets_released; |
|
| 1049 | + } |
|
| 1050 | + // double check whether sold out events should remain sold out after releasing tickets |
|
| 1051 | + if($sold_out_events !== array()){ |
|
| 1052 | + foreach ($sold_out_events as $sold_out_event) { |
|
| 1053 | + /** @var EE_Event $sold_out_event */ |
|
| 1054 | + $sold_out_event->perform_sold_out_status_check(); |
|
| 1055 | + } |
|
| 1056 | + } |
|
| 1057 | + return $total_tickets_released; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + |
|
| 1062 | + /********************************** SHUTDOWN **********************************/ |
|
| 1063 | + |
|
| 1064 | + |
|
| 1065 | + |
|
| 1066 | + /** |
|
| 1067 | + * @param int $timestamp |
|
| 1068 | + * @return false|int |
|
| 1069 | + * @throws EE_Error |
|
| 1070 | + * @throws InvalidArgumentException |
|
| 1071 | + * @throws InvalidDataTypeException |
|
| 1072 | + * @throws InvalidInterfaceException |
|
| 1073 | + */ |
|
| 1074 | + public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
| 1075 | + { |
|
| 1076 | + /** @type WPDB $wpdb */ |
|
| 1077 | + global $wpdb; |
|
| 1078 | + if (! absint($timestamp)) { |
|
| 1079 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 1080 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 1081 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 1082 | + ); |
|
| 1083 | + $timestamp = $session_lifespan->expiration(); |
|
| 1084 | + } |
|
| 1085 | + return $wpdb->query( |
|
| 1086 | + $wpdb->prepare( |
|
| 1087 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 1088 | 1088 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
| 1089 | - // use GMT time because that's what LIN_timestamps are in |
|
| 1090 | - date('Y-m-d H:i:s', $timestamp) |
|
| 1091 | - ) |
|
| 1092 | - ); |
|
| 1093 | - } |
|
| 1089 | + // use GMT time because that's what LIN_timestamps are in |
|
| 1090 | + date('Y-m-d H:i:s', $timestamp) |
|
| 1091 | + ) |
|
| 1092 | + ); |
|
| 1093 | + } |
|
| 1094 | 1094 | |
| 1095 | 1095 | } |
| 1096 | 1096 | // End of file EED_Ticket_Sales_Monitor.module.php |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | class EED_Ticket_Sales_Monitor extends EED_Module |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - const debug = false; // true false |
|
| 27 | + const debug = false; // true false |
|
| 28 | 28 | |
| 29 | 29 | private static $nl = ''; |
| 30 | 30 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public static function set_hooks() |
| 69 | 69 | { |
| 70 | - self::$nl = defined('EE_TESTS_DIR')? "\n" : '<br />'; |
|
| 70 | + self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
| 71 | 71 | // release tickets for expired carts |
| 72 | 72 | add_action( |
| 73 | 73 | 'EED_Ticket_Selector__process_ticket_selections__before', |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | public static function release_tickets_for_expired_carts() |
| 197 | 197 | { |
| 198 | 198 | if (self::debug) { |
| 199 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 199 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
| 200 | 200 | } |
| 201 | 201 | do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
| 202 | 202 | $expired_ticket_IDs = array(); |
@@ -207,26 +207,26 @@ discard block |
||
| 207 | 207 | $timestamp = $session_lifespan->expiration(); |
| 208 | 208 | $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
| 209 | 209 | if (self::debug) { |
| 210 | - echo self::$nl . ' . time(): ' . time(); |
|
| 211 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
| 212 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
| 213 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
| 214 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
| 215 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
| 210 | + echo self::$nl.' . time(): '.time(); |
|
| 211 | + echo self::$nl.' . time() as date: '.date('Y-m-d H:i a'); |
|
| 212 | + echo self::$nl.' . session expiration: '.$session_lifespan->expiration(); |
|
| 213 | + echo self::$nl.' . session expiration as date: '.date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
| 214 | + echo self::$nl.' . timestamp: '.$timestamp; |
|
| 215 | + echo self::$nl.' . $expired_ticket_line_items: '.count($expired_ticket_line_items); |
|
| 216 | 216 | } |
| 217 | - if (! empty($expired_ticket_line_items)) { |
|
| 217 | + if ( ! empty($expired_ticket_line_items)) { |
|
| 218 | 218 | foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
| 219 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
| 219 | + if ( ! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
| 220 | 220 | continue; |
| 221 | 221 | } |
| 222 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
| 222 | + $expired_ticket_IDs[$expired_ticket_line_item->OBJ_ID()] = $expired_ticket_line_item->OBJ_ID(); |
|
| 223 | 223 | if (self::debug) { |
| 224 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
| 225 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' . date('Y-m-d h:i a', |
|
| 224 | + echo self::$nl.' . $expired_ticket_line_item->OBJ_ID(): '.$expired_ticket_line_item->OBJ_ID(); |
|
| 225 | + echo self::$nl.' . $expired_ticket_line_item->timestamp(): '.date('Y-m-d h:i a', |
|
| 226 | 226 | $expired_ticket_line_item->timestamp(true)); |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | - if (! empty($expired_ticket_IDs)) { |
|
| 229 | + if ( ! empty($expired_ticket_IDs)) { |
|
| 230 | 230 | EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
| 231 | 231 | \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
| 232 | 232 | array(), |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
| 266 | 266 | } |
| 267 | 267 | if (self::debug) { |
| 268 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 269 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 268 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
| 269 | + echo self::$nl.self::$nl.'<b> RETURNED QTY: '.$qty.'</b>'; |
|
| 270 | 270 | } |
| 271 | 271 | return $qty; |
| 272 | 272 | } |
@@ -285,36 +285,36 @@ discard block |
||
| 285 | 285 | protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
| 286 | 286 | { |
| 287 | 287 | if (self::debug) { |
| 288 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 288 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 289 | 289 | } |
| 290 | - if (! $ticket instanceof EE_Ticket) { |
|
| 290 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 291 | 291 | return 0; |
| 292 | 292 | } |
| 293 | 293 | if (self::debug) { |
| 294 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 295 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
| 294 | + echo self::$nl.'<b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
| 295 | + echo self::$nl.' . original ticket->reserved: '.$ticket->reserved(); |
|
| 296 | 296 | } |
| 297 | 297 | $ticket->refresh_from_db(); |
| 298 | 298 | // first let's determine the ticket availability based on sales |
| 299 | 299 | $available = $ticket->qty('saleable'); |
| 300 | 300 | if (self::debug) { |
| 301 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
| 302 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
| 303 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 304 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 305 | - echo self::$nl . ' . . . available: ' . $available; |
|
| 301 | + echo self::$nl.' . . . ticket->qty: '.$ticket->qty(); |
|
| 302 | + echo self::$nl.' . . . ticket->sold: '.$ticket->sold(); |
|
| 303 | + echo self::$nl.' . . . ticket->reserved: '.$ticket->reserved(); |
|
| 304 | + echo self::$nl.' . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
| 305 | + echo self::$nl.' . . . available: '.$available; |
|
| 306 | 306 | } |
| 307 | 307 | if ($available < 1) { |
| 308 | 308 | $this->_ticket_sold_out($ticket); |
| 309 | 309 | return 0; |
| 310 | 310 | } |
| 311 | 311 | if (self::debug) { |
| 312 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
| 312 | + echo self::$nl.' . . . qty: '.$qty; |
|
| 313 | 313 | } |
| 314 | 314 | if ($available < $qty) { |
| 315 | 315 | $qty = $available; |
| 316 | 316 | if (self::debug) { |
| 317 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
| 317 | + echo self::$nl.' . . . QTY ADJUSTED: '.$qty; |
|
| 318 | 318 | } |
| 319 | 319 | $this->_ticket_quantity_decremented($ticket); |
| 320 | 320 | } |
@@ -335,9 +335,9 @@ discard block |
||
| 335 | 335 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
| 336 | 336 | { |
| 337 | 337 | if (self::debug) { |
| 338 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
| 338 | + echo self::$nl.self::$nl.' . . . INCREASE RESERVED: '.$quantity; |
|
| 339 | 339 | } |
| 340 | - $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
| 340 | + $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'.__LINE__); |
|
| 341 | 341 | return $ticket->save(); |
| 342 | 342 | } |
| 343 | 343 | |
@@ -352,12 +352,12 @@ discard block |
||
| 352 | 352 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
| 353 | 353 | { |
| 354 | 354 | if (self::debug) { |
| 355 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
| 356 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 355 | + echo self::$nl.' . . . ticket->ID: '.$ticket->ID(); |
|
| 356 | + echo self::$nl.' . . . ticket->reserved: '.$ticket->reserved(); |
|
| 357 | 357 | } |
| 358 | - $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 358 | + $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'.__LINE__); |
|
| 359 | 359 | if (self::debug) { |
| 360 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 360 | + echo self::$nl.' . . . ticket->reserved: '.$ticket->reserved(); |
|
| 361 | 361 | } |
| 362 | 362 | return $ticket->save() ? 1 : 0; |
| 363 | 363 | } |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | protected function _ticket_sold_out(EE_Ticket $ticket) |
| 376 | 376 | { |
| 377 | 377 | if (self::debug) { |
| 378 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 379 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 378 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 379 | + echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
| 380 | 380 | } |
| 381 | 381 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
| 382 | 382 | } |
@@ -394,8 +394,8 @@ discard block |
||
| 394 | 394 | protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
| 395 | 395 | { |
| 396 | 396 | if (self::debug) { |
| 397 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 398 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 397 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 398 | + echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
| 399 | 399 | } |
| 400 | 400 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
| 401 | 401 | } |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | if ($ticket instanceof EE_Ticket) { |
| 449 | 449 | $ticket->add_extra_meta( |
| 450 | 450 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 451 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 451 | + __LINE__.') '.__METHOD__.'()' |
|
| 452 | 452 | ); |
| 453 | 453 | if ($quantity > 0) { |
| 454 | 454 | EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | { |
| 473 | 473 | $ticket->add_extra_meta( |
| 474 | 474 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 475 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 475 | + __LINE__.') '.__METHOD__.'()' |
|
| 476 | 476 | ); |
| 477 | 477 | EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
| 478 | 478 | } |
@@ -509,18 +509,18 @@ discard block |
||
| 509 | 509 | protected function _post_notices() |
| 510 | 510 | { |
| 511 | 511 | if (self::debug) { |
| 512 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 512 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 513 | 513 | } |
| 514 | 514 | $refresh_msg = ''; |
| 515 | 515 | $none_added_msg = ''; |
| 516 | 516 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 517 | - $refresh_msg = __( |
|
| 517 | + $refresh_msg = __( |
|
| 518 | 518 | 'Please refresh the page to view updated ticket quantities.', |
| 519 | 519 | 'event_espresso' |
| 520 | 520 | ); |
| 521 | 521 | $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
| 522 | 522 | } |
| 523 | - if (! empty($this->sold_out_tickets)) { |
|
| 523 | + if ( ! empty($this->sold_out_tickets)) { |
|
| 524 | 524 | EE_Error::add_attention( |
| 525 | 525 | sprintf( |
| 526 | 526 | apply_filters( |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | // and reset the cart |
| 544 | 544 | EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
| 545 | 545 | } |
| 546 | - if (! empty($this->decremented_tickets)) { |
|
| 546 | + if ( ! empty($this->decremented_tickets)) { |
|
| 547 | 547 | EE_Error::add_attention( |
| 548 | 548 | sprintf( |
| 549 | 549 | apply_filters( |
@@ -581,9 +581,9 @@ discard block |
||
| 581 | 581 | protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
| 582 | 582 | { |
| 583 | 583 | if (self::debug) { |
| 584 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 585 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
| 586 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
| 584 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 585 | + echo self::$nl.' . transaction->ID: '.$transaction->ID(); |
|
| 586 | + echo self::$nl.' . TXN status_ID: '.$transaction->status_ID(); |
|
| 587 | 587 | } |
| 588 | 588 | // check if 'finalize_registration' step has been completed... |
| 589 | 589 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -595,13 +595,13 @@ discard block |
||
| 595 | 595 | __LINE__, |
| 596 | 596 | array('finalized' => $finalized), |
| 597 | 597 | false, |
| 598 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 598 | + 'EE_Transaction: '.$transaction->ID() |
|
| 599 | 599 | ); |
| 600 | 600 | } |
| 601 | 601 | // how many tickets were released |
| 602 | 602 | $count = 0; |
| 603 | 603 | if (self::debug) { |
| 604 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
| 604 | + echo self::$nl.' . . . TXN finalized: '.$finalized; |
|
| 605 | 605 | } |
| 606 | 606 | $release_tickets_with_TXN_status = array( |
| 607 | 607 | EEM_Transaction::failed_status_code, |
@@ -610,28 +610,28 @@ discard block |
||
| 610 | 610 | ); |
| 611 | 611 | $events = array(); |
| 612 | 612 | // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
| 613 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 613 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 614 | 614 | // cancel any reserved tickets for registrations that were not approved |
| 615 | 615 | $registrations = $transaction->registrations(); |
| 616 | 616 | if (self::debug) { |
| 617 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
| 617 | + echo self::$nl.' . . . # registrations: '.count($registrations); |
|
| 618 | 618 | $reg = reset($registrations); |
| 619 | 619 | $ticket = $reg->ticket(); |
| 620 | 620 | if ($ticket instanceof EE_Ticket) { |
| 621 | 621 | $ticket->add_extra_meta( |
| 622 | 622 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 623 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 623 | + __LINE__.') Release All Tickets TXN:'.$transaction->ID() |
|
| 624 | 624 | ); |
| 625 | 625 | } |
| 626 | 626 | } |
| 627 | - if (! empty($registrations)) { |
|
| 627 | + if ( ! empty($registrations)) { |
|
| 628 | 628 | foreach ($registrations as $registration) { |
| 629 | 629 | if ( |
| 630 | 630 | $registration instanceof EE_Registration |
| 631 | 631 | && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
| 632 | 632 | ) { |
| 633 | 633 | $count++; |
| 634 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
| 634 | + $events[$registration->event_ID()] = $registration->event(); |
|
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | 637 | } |
@@ -662,10 +662,10 @@ discard block |
||
| 662 | 662 | ) { |
| 663 | 663 | $STS_ID = $transaction->status_ID(); |
| 664 | 664 | if (self::debug) { |
| 665 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 666 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
| 667 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
| 668 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
| 665 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 666 | + echo self::$nl.' . . registration->ID: '.$registration->ID(); |
|
| 667 | + echo self::$nl.' . . registration->status_ID: '.$registration->status_ID(); |
|
| 668 | + echo self::$nl.' . . transaction->status_ID(): '.$STS_ID; |
|
| 669 | 669 | } |
| 670 | 670 | if ( |
| 671 | 671 | // release Tickets for Failed Transactions and Abandoned Transactions |
@@ -678,12 +678,12 @@ discard block |
||
| 678 | 678 | ) |
| 679 | 679 | ) { |
| 680 | 680 | if (self::debug) { |
| 681 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
| 681 | + echo self::$nl.self::$nl.' . . RELEASE RESERVED TICKET'; |
|
| 682 | 682 | $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
| 683 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 683 | + echo self::$nl.' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 684 | 684 | var_dump($rsrvd); |
| 685 | 685 | } |
| 686 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
| 686 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'.__LINE__); |
|
| 687 | 687 | return 1; |
| 688 | 688 | } |
| 689 | 689 | return 0; |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | public static function session_cart_reset(EE_Session $session) |
| 710 | 710 | { |
| 711 | 711 | if (self::debug) { |
| 712 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 712 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 713 | 713 | } |
| 714 | 714 | // first check of the session has a valid Checkout object |
| 715 | 715 | $checkout = $session->checkout(); |
@@ -721,12 +721,12 @@ discard block |
||
| 721 | 721 | $cart = $session->cart(); |
| 722 | 722 | if ($cart instanceof EE_Cart) { |
| 723 | 723 | if (self::debug) { |
| 724 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
| 724 | + echo self::$nl.self::$nl.' cart instance of EE_Cart: '; |
|
| 725 | 725 | } |
| 726 | 726 | EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
| 727 | 727 | } else { |
| 728 | 728 | if (self::debug) { |
| 729 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
| 729 | + echo self::$nl.self::$nl.' invalid EE_Cart: '; |
|
| 730 | 730 | var_export($cart, true); |
| 731 | 731 | } |
| 732 | 732 | } |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
| 749 | 749 | { |
| 750 | 750 | if (self::debug) { |
| 751 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 751 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 752 | 752 | } |
| 753 | 753 | EE_Registry::instance()->load_helper('Line_Item'); |
| 754 | 754 | $ticket_line_items = $cart->get_tickets(); |
@@ -757,28 +757,28 @@ discard block |
||
| 757 | 757 | } |
| 758 | 758 | foreach ($ticket_line_items as $ticket_line_item) { |
| 759 | 759 | if (self::debug) { |
| 760 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 760 | + echo self::$nl.' . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
| 761 | 761 | } |
| 762 | 762 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
| 763 | 763 | if (self::debug) { |
| 764 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 764 | + echo self::$nl.' . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
| 765 | 765 | } |
| 766 | 766 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
| 767 | 767 | if ($ticket instanceof EE_Ticket) { |
| 768 | 768 | if (self::debug) { |
| 769 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
| 770 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 769 | + echo self::$nl.' . . ticket->ID(): '.$ticket->ID(); |
|
| 770 | + echo self::$nl.' . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
| 771 | 771 | } |
| 772 | 772 | $ticket->add_extra_meta( |
| 773 | 773 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 774 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 774 | + __LINE__.') '.__METHOD__.'() SID = '.$session->id() |
|
| 775 | 775 | ); |
| 776 | 776 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
| 777 | 777 | } |
| 778 | 778 | } |
| 779 | 779 | } |
| 780 | 780 | if (self::debug) { |
| 781 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
| 781 | + echo self::$nl.self::$nl.' RESET COMPLETED '; |
|
| 782 | 782 | } |
| 783 | 783 | } |
| 784 | 784 | |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | protected function _session_checkout_reset(EE_Checkout $checkout) |
| 818 | 818 | { |
| 819 | 819 | if (self::debug) { |
| 820 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 820 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 821 | 821 | } |
| 822 | 822 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
| 823 | 823 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | __LINE__, |
| 868 | 868 | array($transaction), |
| 869 | 869 | false, |
| 870 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 870 | + 'EE_Transaction: '.$transaction->ID() |
|
| 871 | 871 | ); |
| 872 | 872 | } |
| 873 | 873 | return; |
@@ -884,7 +884,7 @@ discard block |
||
| 884 | 884 | __LINE__, |
| 885 | 885 | array($payment), |
| 886 | 886 | false, |
| 887 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 887 | + 'EE_Transaction: '.$transaction->ID() |
|
| 888 | 888 | ); |
| 889 | 889 | } |
| 890 | 890 | return; |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | } |
| 945 | 945 | $total_line_item = $transaction->total_line_item(); |
| 946 | 946 | // $transaction_in_progress->line |
| 947 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
| 947 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
| 948 | 948 | throw new DomainException( |
| 949 | 949 | esc_html__( |
| 950 | 950 | 'Transaction does not have a valid Total Line Item associated with it.', |
@@ -1005,18 +1005,18 @@ discard block |
||
| 1005 | 1005 | $source |
| 1006 | 1006 | ) { |
| 1007 | 1007 | if (self::debug) { |
| 1008 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 1008 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
| 1009 | 1009 | } |
| 1010 | 1010 | $total_tickets_released = 0; |
| 1011 | 1011 | $sold_out_events = array(); |
| 1012 | 1012 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
| 1013 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1013 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1014 | 1014 | continue; |
| 1015 | 1015 | } |
| 1016 | 1016 | $reserved_qty = $ticket_with_reservations->reserved(); |
| 1017 | 1017 | if (self::debug) { |
| 1018 | - echo self::$nl . ' . $ticket_with_reservations->ID(): ' . $ticket_with_reservations->ID(); |
|
| 1019 | - echo self::$nl . ' . $reserved_qty: ' . $reserved_qty; |
|
| 1018 | + echo self::$nl.' . $ticket_with_reservations->ID(): '.$ticket_with_reservations->ID(); |
|
| 1019 | + echo self::$nl.' . $reserved_qty: '.$reserved_qty; |
|
| 1020 | 1020 | } |
| 1021 | 1021 | foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
| 1022 | 1022 | if ( |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
| 1025 | 1025 | ) { |
| 1026 | 1026 | if (self::debug) { |
| 1027 | - echo self::$nl . ' . $valid_reserved_ticket_line_item->quantity(): ' . $valid_reserved_ticket_line_item->quantity(); |
|
| 1027 | + echo self::$nl.' . $valid_reserved_ticket_line_item->quantity(): '.$valid_reserved_ticket_line_item->quantity(); |
|
| 1028 | 1028 | } |
| 1029 | 1029 | $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
| 1030 | 1030 | } |
@@ -1032,9 +1032,9 @@ discard block |
||
| 1032 | 1032 | if ($reserved_qty > 0) { |
| 1033 | 1033 | $ticket_with_reservations->add_extra_meta( |
| 1034 | 1034 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 1035 | - __LINE__ . ') ' . $source . '()' |
|
| 1035 | + __LINE__.') '.$source.'()' |
|
| 1036 | 1036 | ); |
| 1037 | - $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 1037 | + $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'.__LINE__); |
|
| 1038 | 1038 | $ticket_with_reservations->save(); |
| 1039 | 1039 | $total_tickets_released += $reserved_qty; |
| 1040 | 1040 | $event = $ticket_with_reservations->get_related_event(); |
@@ -1045,10 +1045,10 @@ discard block |
||
| 1045 | 1045 | } |
| 1046 | 1046 | } |
| 1047 | 1047 | if (self::debug) { |
| 1048 | - echo self::$nl . ' . $total_tickets_released: ' . $total_tickets_released; |
|
| 1048 | + echo self::$nl.' . $total_tickets_released: '.$total_tickets_released; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | // double check whether sold out events should remain sold out after releasing tickets |
| 1051 | - if($sold_out_events !== array()){ |
|
| 1051 | + if ($sold_out_events !== array()) { |
|
| 1052 | 1052 | foreach ($sold_out_events as $sold_out_event) { |
| 1053 | 1053 | /** @var EE_Event $sold_out_event */ |
| 1054 | 1054 | $sold_out_event->perform_sold_out_status_check(); |
@@ -1075,7 +1075,7 @@ discard block |
||
| 1075 | 1075 | { |
| 1076 | 1076 | /** @type WPDB $wpdb */ |
| 1077 | 1077 | global $wpdb; |
| 1078 | - if (! absint($timestamp)) { |
|
| 1078 | + if ( ! absint($timestamp)) { |
|
| 1079 | 1079 | /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
| 1080 | 1080 | $session_lifespan = LoaderFactory::getLoader()->getShared( |
| 1081 | 1081 | 'EventEspresso\core\domain\values\session\SessionLifespan' |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | } |
| 1085 | 1085 | return $wpdb->query( |
| 1086 | 1086 | $wpdb->prepare( |
| 1087 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 1087 | + 'DELETE FROM '.EEM_Line_Item::instance()->table().' |
|
| 1088 | 1088 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
| 1089 | 1089 | // use GMT time because that's what LIN_timestamps are in |
| 1090 | 1090 | date('Y-m-d H:i:s', $timestamp) |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
| 2 | 2 | |
| 3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -17,637 +17,637 @@ discard block |
||
| 17 | 17 | class EEH_Debug_Tools |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * instance of the EEH_Autoloader object |
|
| 22 | - * |
|
| 23 | - * @var $_instance |
|
| 24 | - * @access private |
|
| 25 | - */ |
|
| 26 | - private static $_instance; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $_memory_usage_points = array(); |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @singleton method used to instantiate class object |
|
| 37 | - * @access public |
|
| 38 | - * @return EEH_Debug_Tools |
|
| 39 | - */ |
|
| 40 | - public static function instance() |
|
| 41 | - { |
|
| 42 | - // check if class object is instantiated, and instantiated properly |
|
| 43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | - self::$_instance = new self(); |
|
| 45 | - } |
|
| 46 | - return self::$_instance; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * private class constructor |
|
| 53 | - */ |
|
| 54 | - private function __construct() |
|
| 55 | - { |
|
| 56 | - // load Kint PHP debugging library |
|
| 57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 58 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 59 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 60 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 61 | - // so we've moved it to our test folder so that it is not included with production releases |
|
| 62 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 64 | - } |
|
| 65 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 66 | - //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 67 | - // } |
|
| 68 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 69 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 70 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 71 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * show_db_name |
|
| 78 | - * |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public static function show_db_name() |
|
| 82 | - { |
|
| 83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 85 | - . DB_NAME |
|
| 86 | - . '</p>'; |
|
| 87 | - } |
|
| 88 | - if (EE_DEBUG) { |
|
| 89 | - Benchmark::displayResults(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * dump EE_Session object at bottom of page after everything else has happened |
|
| 97 | - * |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public function espresso_session_footer_dump() |
|
| 101 | - { |
|
| 102 | - if ( |
|
| 103 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
| 104 | - && ! defined('DOING_AJAX') |
|
| 105 | - && class_exists('Kint') |
|
| 106 | - && function_exists('wp_get_current_user') |
|
| 107 | - && current_user_can('update_core') |
|
| 108 | - && class_exists('EE_Registry') |
|
| 109 | - ) { |
|
| 110 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 111 | - Kint::dump(EE_Registry::instance()->SSN); |
|
| 112 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 113 | - $this->espresso_list_hooked_functions(); |
|
| 114 | - Benchmark::displayResults(); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * List All Hooked Functions |
|
| 122 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 123 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 124 | - * |
|
| 125 | - * @param string $tag |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function espresso_list_hooked_functions($tag = '') |
|
| 129 | - { |
|
| 130 | - global $wp_filter; |
|
| 131 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 132 | - if ($tag) { |
|
| 133 | - $hook[$tag] = $wp_filter[$tag]; |
|
| 134 | - if (! is_array($hook[$tag])) { |
|
| 135 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 136 | - return; |
|
| 137 | - } |
|
| 138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 139 | - } else { |
|
| 140 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 141 | - ksort($hook); |
|
| 142 | - } |
|
| 143 | - foreach ($hook as $tag_name => $priorities) { |
|
| 144 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 145 | - ksort($priorities); |
|
| 146 | - foreach ($priorities as $priority => $function) { |
|
| 147 | - echo $priority; |
|
| 148 | - foreach ($function as $name => $properties) { |
|
| 149 | - echo "\t$name<br />"; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * registered_filter_callbacks |
|
| 159 | - * |
|
| 160 | - * @param string $hook_name |
|
| 161 | - * @return array |
|
| 162 | - */ |
|
| 163 | - public static function registered_filter_callbacks($hook_name = '') |
|
| 164 | - { |
|
| 165 | - $filters = array(); |
|
| 166 | - global $wp_filter; |
|
| 167 | - if (isset($wp_filter[$hook_name])) { |
|
| 168 | - $filters[$hook_name] = array(); |
|
| 169 | - foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
| 170 | - $filters[$hook_name][$priority] = array(); |
|
| 171 | - foreach ($callbacks as $callback) { |
|
| 172 | - $filters[$hook_name][$priority][] = $callback['function']; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - return $filters; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * captures plugin activation errors for debugging |
|
| 183 | - * |
|
| 184 | - * @return void |
|
| 185 | - * @throws EE_Error |
|
| 186 | - */ |
|
| 187 | - public static function ee_plugin_activation_errors() |
|
| 188 | - { |
|
| 189 | - if (WP_DEBUG) { |
|
| 190 | - $activation_errors = ob_get_contents(); |
|
| 191 | - if (! empty($activation_errors)) { |
|
| 192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 193 | - } |
|
| 194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 195 | - if (class_exists('EEH_File')) { |
|
| 196 | - try { |
|
| 197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
| 198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 199 | - ); |
|
| 200 | - EEH_File::write_to_file( |
|
| 201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 202 | - $activation_errors |
|
| 203 | - ); |
|
| 204 | - } catch (EE_Error $e) { |
|
| 205 | - EE_Error::add_error( |
|
| 206 | - sprintf( |
|
| 207 | - __( |
|
| 208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 209 | - 'event_espresso' |
|
| 210 | - ), |
|
| 211 | - $e->getMessage() |
|
| 212 | - ), |
|
| 213 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 214 | - ); |
|
| 215 | - } |
|
| 216 | - } else { |
|
| 217 | - // old school attempt |
|
| 218 | - file_put_contents( |
|
| 219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 220 | - $activation_errors |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 224 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 232 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 233 | - * or we want to make sure they use something the right way. |
|
| 234 | - * |
|
| 235 | - * @access public |
|
| 236 | - * @param string $function The function that was called |
|
| 237 | - * @param string $message A message explaining what has been done incorrectly |
|
| 238 | - * @param string $version The version of Event Espresso where the error was added |
|
| 239 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 240 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
| 241 | - * but not have any notices appear until a later version. This allows developers |
|
| 242 | - * extra time to update their code before notices appear. |
|
| 243 | - * @param int $error_type |
|
| 244 | - * @uses trigger_error() |
|
| 245 | - */ |
|
| 246 | - public function doing_it_wrong( |
|
| 247 | - $function, |
|
| 248 | - $message, |
|
| 249 | - $version, |
|
| 250 | - $applies_when = '', |
|
| 251 | - $error_type = null |
|
| 252 | - ) { |
|
| 253 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 254 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 255 | - // because we swapped the parameter order around for the last two params, |
|
| 256 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
| 257 | - if (is_int($applies_when)) { |
|
| 258 | - $error_type = $applies_when; |
|
| 259 | - $applies_when = espresso_version(); |
|
| 260 | - } |
|
| 261 | - // if not displaying notices yet, then just leave |
|
| 262 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 263 | - return; |
|
| 264 | - } |
|
| 265 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 266 | - $version = $version === null |
|
| 267 | - ? '' |
|
| 268 | - : sprintf( |
|
| 269 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 270 | - $version |
|
| 271 | - ); |
|
| 272 | - $error_message = sprintf( |
|
| 273 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 274 | - $function, |
|
| 275 | - '<strong>', |
|
| 276 | - '</strong>', |
|
| 277 | - $message, |
|
| 278 | - $version |
|
| 279 | - ); |
|
| 280 | - // don't trigger error if doing ajax, |
|
| 281 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 282 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 283 | - $error_message .= ' ' . esc_html__( |
|
| 284 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 285 | - 'event_espresso' |
|
| 286 | - ); |
|
| 287 | - $error_message .= '<ul><li>'; |
|
| 288 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 289 | - $error_message .= '</ul>'; |
|
| 290 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 291 | - //now we set this on the transient so it shows up on the next request. |
|
| 292 | - EE_Error::get_notices(false, true); |
|
| 293 | - } else { |
|
| 294 | - trigger_error($error_message, $error_type); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Logger helpers |
|
| 303 | - */ |
|
| 304 | - /** |
|
| 305 | - * debug |
|
| 306 | - * |
|
| 307 | - * @param string $class |
|
| 308 | - * @param string $func |
|
| 309 | - * @param string $line |
|
| 310 | - * @param array $info |
|
| 311 | - * @param bool $display_request |
|
| 312 | - * @param string $debug_index |
|
| 313 | - * @param string $debug_key |
|
| 314 | - * @throws EE_Error |
|
| 315 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 316 | - */ |
|
| 317 | - public static function log( |
|
| 318 | - $class = '', |
|
| 319 | - $func = '', |
|
| 320 | - $line = '', |
|
| 321 | - $info = array(), |
|
| 322 | - $display_request = false, |
|
| 323 | - $debug_index = '', |
|
| 324 | - $debug_key = 'EE_DEBUG_SPCO' |
|
| 325 | - ) { |
|
| 326 | - if (WP_DEBUG) { |
|
| 327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 328 | - $debug_data = get_option($debug_key, array()); |
|
| 329 | - $default_data = array( |
|
| 330 | - $class => $func . '() : ' . $line, |
|
| 331 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
| 332 | - ); |
|
| 333 | - // don't serialize objects |
|
| 334 | - $info = self::strip_objects($info); |
|
| 335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 336 | - if (! isset($debug_data[$index])) { |
|
| 337 | - $debug_data[$index] = array(); |
|
| 338 | - } |
|
| 339 | - $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
| 340 | - update_option($debug_key, $debug_data); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * strip_objects |
|
| 348 | - * |
|
| 349 | - * @param array $info |
|
| 350 | - * @return array |
|
| 351 | - */ |
|
| 352 | - public static function strip_objects($info = array()) |
|
| 353 | - { |
|
| 354 | - foreach ($info as $key => $value) { |
|
| 355 | - if (is_array($value)) { |
|
| 356 | - $info[$key] = self::strip_objects($value); |
|
| 357 | - } else if (is_object($value)) { |
|
| 358 | - $object_class = get_class($value); |
|
| 359 | - $info[$object_class] = array(); |
|
| 360 | - $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 361 | - if (method_exists($value, 'ID')) { |
|
| 362 | - $info[$object_class]['ID'] = $value->ID(); |
|
| 363 | - } |
|
| 364 | - if (method_exists($value, 'status')) { |
|
| 365 | - $info[$object_class]['status'] = $value->status(); |
|
| 366 | - } else if (method_exists($value, 'status_ID')) { |
|
| 367 | - $info[$object_class]['status'] = $value->status_ID(); |
|
| 368 | - } |
|
| 369 | - unset($info[$key]); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - return (array)$info; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @param mixed $var |
|
| 379 | - * @param string $var_name |
|
| 380 | - * @param string $file |
|
| 381 | - * @param int|string $line |
|
| 382 | - * @param int $heading_tag |
|
| 383 | - * @param bool $die |
|
| 384 | - * @param string $margin |
|
| 385 | - */ |
|
| 386 | - public static function printv( |
|
| 387 | - $var, |
|
| 388 | - $var_name = '', |
|
| 389 | - $file = '', |
|
| 390 | - $line = '', |
|
| 391 | - $heading_tag = 5, |
|
| 392 | - $die = false, |
|
| 393 | - $margin = '' |
|
| 394 | - ) { |
|
| 395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
| 396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 397 | - $is_method = method_exists($var_name, $var); |
|
| 398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 399 | - $heading_tag = absint($heading_tag); |
|
| 400 | - $result = $heading_tag < 3 ? "\n" : ''; |
|
| 401 | - $heading_tag = $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
| 402 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 403 | - $result .= $is_method |
|
| 404 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 405 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 406 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 407 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 408 | - if ($die) { |
|
| 409 | - die($result); |
|
| 410 | - } |
|
| 411 | - echo $result; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - protected static function plainOutput() |
|
| 416 | - { |
|
| 417 | - return defined('EE_TESTS_DIR') || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * @param string $var_name |
|
| 423 | - * @param string $heading_tag |
|
| 424 | - * @param string $margin |
|
| 425 | - * @param int $line |
|
| 426 | - * @return string |
|
| 427 | - */ |
|
| 428 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
| 429 | - { |
|
| 430 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 431 | - return "\n{$line}) {$var_name}"; |
|
| 432 | - } |
|
| 433 | - $margin = "25px 0 0 {$margin}"; |
|
| 434 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * @param string $heading_tag |
|
| 441 | - * @return string |
|
| 442 | - */ |
|
| 443 | - protected static function headingX($heading_tag = 'h5') |
|
| 444 | - { |
|
| 445 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 446 | - return ''; |
|
| 447 | - } |
|
| 448 | - return '</' . $heading_tag . '>'; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * @param string $content |
|
| 455 | - * @return string |
|
| 456 | - */ |
|
| 457 | - protected static function grey_span($content = '') |
|
| 458 | - { |
|
| 459 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 460 | - return $content; |
|
| 461 | - } |
|
| 462 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * @param string $file |
|
| 469 | - * @param int $line |
|
| 470 | - * @return string |
|
| 471 | - */ |
|
| 472 | - protected static function file_and_line($file, $line) |
|
| 473 | - { |
|
| 474 | - if ($file === '' || $line === '' || EEH_Debug_Tools::plainOutput()) { |
|
| 475 | - return ''; |
|
| 476 | - } |
|
| 477 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
| 478 | - . $file |
|
| 479 | - . '<br />line no: ' |
|
| 480 | - . $line |
|
| 481 | - . '</span>'; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @param string $content |
|
| 488 | - * @return string |
|
| 489 | - */ |
|
| 490 | - protected static function orange_span($content = '') |
|
| 491 | - { |
|
| 492 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 493 | - return $content; |
|
| 494 | - } |
|
| 495 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * @param mixed $var |
|
| 502 | - * @return string |
|
| 503 | - */ |
|
| 504 | - protected static function pre_span($var) |
|
| 505 | - { |
|
| 506 | - ob_start(); |
|
| 507 | - var_dump($var); |
|
| 508 | - $var = ob_get_clean(); |
|
| 509 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 510 | - return "\n" . $var; |
|
| 511 | - } |
|
| 512 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * @param mixed $var |
|
| 519 | - * @param string $var_name |
|
| 520 | - * @param string $file |
|
| 521 | - * @param int|string $line |
|
| 522 | - * @param int $heading_tag |
|
| 523 | - * @param bool $die |
|
| 524 | - */ |
|
| 525 | - public static function printr( |
|
| 526 | - $var, |
|
| 527 | - $var_name = '', |
|
| 528 | - $file = '', |
|
| 529 | - $line = '', |
|
| 530 | - $heading_tag = 5, |
|
| 531 | - $die = false |
|
| 532 | - ) { |
|
| 533 | - // return; |
|
| 534 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 535 | - $margin = is_admin() ? ' 180px' : '0'; |
|
| 536 | - //$print_r = false; |
|
| 537 | - if (is_string($var)) { |
|
| 538 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 539 | - return; |
|
| 540 | - } |
|
| 541 | - if (is_object($var)) { |
|
| 542 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
| 543 | - //$print_r = true; |
|
| 544 | - } else if (is_array($var)) { |
|
| 545 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
| 546 | - //$print_r = true; |
|
| 547 | - } else if (is_numeric($var)) { |
|
| 548 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 549 | - } else if ($var === null) { |
|
| 550 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
| 551 | - } |
|
| 552 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 553 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 554 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 555 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 556 | - EEH_Debug_Tools::pre_span($var) |
|
| 557 | - ); |
|
| 558 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 559 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 560 | - if ($die) { |
|
| 561 | - die($result); |
|
| 562 | - } |
|
| 563 | - echo $result; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /******************** deprecated ********************/ |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * @deprecated 4.9.39.rc.034 |
|
| 574 | - */ |
|
| 575 | - public function reset_times() |
|
| 576 | - { |
|
| 577 | - Benchmark::resetTimes(); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * @deprecated 4.9.39.rc.034 |
|
| 584 | - * @param null $timer_name |
|
| 585 | - */ |
|
| 586 | - public function start_timer($timer_name = null) |
|
| 587 | - { |
|
| 588 | - Benchmark::startTimer($timer_name); |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * @deprecated 4.9.39.rc.034 |
|
| 595 | - * @param string $timer_name |
|
| 596 | - */ |
|
| 597 | - public function stop_timer($timer_name = '') |
|
| 598 | - { |
|
| 599 | - Benchmark::stopTimer($timer_name); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * @deprecated 4.9.39.rc.034 |
|
| 606 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 607 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 608 | - * @return void |
|
| 609 | - */ |
|
| 610 | - public function measure_memory($label, $output_now = false) |
|
| 611 | - { |
|
| 612 | - Benchmark::measureMemory($label, $output_now); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * @deprecated 4.9.39.rc.034 |
|
| 619 | - * @param int $size |
|
| 620 | - * @return string |
|
| 621 | - */ |
|
| 622 | - public function convert($size) |
|
| 623 | - { |
|
| 624 | - return Benchmark::convert($size); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * @deprecated 4.9.39.rc.034 |
|
| 631 | - * @param bool $output_now |
|
| 632 | - * @return string |
|
| 633 | - */ |
|
| 634 | - public function show_times($output_now = true) |
|
| 635 | - { |
|
| 636 | - return Benchmark::displayResults($output_now); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * @deprecated 4.9.39.rc.034 |
|
| 643 | - * @param string $timer_name |
|
| 644 | - * @param float $total_time |
|
| 645 | - * @return string |
|
| 646 | - */ |
|
| 647 | - public function format_time($timer_name, $total_time) |
|
| 648 | - { |
|
| 649 | - return Benchmark::formatTime($timer_name, $total_time); |
|
| 650 | - } |
|
| 20 | + /** |
|
| 21 | + * instance of the EEH_Autoloader object |
|
| 22 | + * |
|
| 23 | + * @var $_instance |
|
| 24 | + * @access private |
|
| 25 | + */ |
|
| 26 | + private static $_instance; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $_memory_usage_points = array(); |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @singleton method used to instantiate class object |
|
| 37 | + * @access public |
|
| 38 | + * @return EEH_Debug_Tools |
|
| 39 | + */ |
|
| 40 | + public static function instance() |
|
| 41 | + { |
|
| 42 | + // check if class object is instantiated, and instantiated properly |
|
| 43 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | + self::$_instance = new self(); |
|
| 45 | + } |
|
| 46 | + return self::$_instance; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * private class constructor |
|
| 53 | + */ |
|
| 54 | + private function __construct() |
|
| 55 | + { |
|
| 56 | + // load Kint PHP debugging library |
|
| 57 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 58 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 59 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 60 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 61 | + // so we've moved it to our test folder so that it is not included with production releases |
|
| 62 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 63 | + require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 64 | + } |
|
| 65 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 66 | + //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 67 | + // } |
|
| 68 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 69 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 70 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 71 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * show_db_name |
|
| 78 | + * |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public static function show_db_name() |
|
| 82 | + { |
|
| 83 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 85 | + . DB_NAME |
|
| 86 | + . '</p>'; |
|
| 87 | + } |
|
| 88 | + if (EE_DEBUG) { |
|
| 89 | + Benchmark::displayResults(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * dump EE_Session object at bottom of page after everything else has happened |
|
| 97 | + * |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public function espresso_session_footer_dump() |
|
| 101 | + { |
|
| 102 | + if ( |
|
| 103 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
| 104 | + && ! defined('DOING_AJAX') |
|
| 105 | + && class_exists('Kint') |
|
| 106 | + && function_exists('wp_get_current_user') |
|
| 107 | + && current_user_can('update_core') |
|
| 108 | + && class_exists('EE_Registry') |
|
| 109 | + ) { |
|
| 110 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 111 | + Kint::dump(EE_Registry::instance()->SSN); |
|
| 112 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 113 | + $this->espresso_list_hooked_functions(); |
|
| 114 | + Benchmark::displayResults(); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * List All Hooked Functions |
|
| 122 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 123 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 124 | + * |
|
| 125 | + * @param string $tag |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function espresso_list_hooked_functions($tag = '') |
|
| 129 | + { |
|
| 130 | + global $wp_filter; |
|
| 131 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 132 | + if ($tag) { |
|
| 133 | + $hook[$tag] = $wp_filter[$tag]; |
|
| 134 | + if (! is_array($hook[$tag])) { |
|
| 135 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 136 | + return; |
|
| 137 | + } |
|
| 138 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 139 | + } else { |
|
| 140 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 141 | + ksort($hook); |
|
| 142 | + } |
|
| 143 | + foreach ($hook as $tag_name => $priorities) { |
|
| 144 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 145 | + ksort($priorities); |
|
| 146 | + foreach ($priorities as $priority => $function) { |
|
| 147 | + echo $priority; |
|
| 148 | + foreach ($function as $name => $properties) { |
|
| 149 | + echo "\t$name<br />"; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * registered_filter_callbacks |
|
| 159 | + * |
|
| 160 | + * @param string $hook_name |
|
| 161 | + * @return array |
|
| 162 | + */ |
|
| 163 | + public static function registered_filter_callbacks($hook_name = '') |
|
| 164 | + { |
|
| 165 | + $filters = array(); |
|
| 166 | + global $wp_filter; |
|
| 167 | + if (isset($wp_filter[$hook_name])) { |
|
| 168 | + $filters[$hook_name] = array(); |
|
| 169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
| 170 | + $filters[$hook_name][$priority] = array(); |
|
| 171 | + foreach ($callbacks as $callback) { |
|
| 172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + return $filters; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * captures plugin activation errors for debugging |
|
| 183 | + * |
|
| 184 | + * @return void |
|
| 185 | + * @throws EE_Error |
|
| 186 | + */ |
|
| 187 | + public static function ee_plugin_activation_errors() |
|
| 188 | + { |
|
| 189 | + if (WP_DEBUG) { |
|
| 190 | + $activation_errors = ob_get_contents(); |
|
| 191 | + if (! empty($activation_errors)) { |
|
| 192 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 193 | + } |
|
| 194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 195 | + if (class_exists('EEH_File')) { |
|
| 196 | + try { |
|
| 197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
| 198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 199 | + ); |
|
| 200 | + EEH_File::write_to_file( |
|
| 201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 202 | + $activation_errors |
|
| 203 | + ); |
|
| 204 | + } catch (EE_Error $e) { |
|
| 205 | + EE_Error::add_error( |
|
| 206 | + sprintf( |
|
| 207 | + __( |
|
| 208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 209 | + 'event_espresso' |
|
| 210 | + ), |
|
| 211 | + $e->getMessage() |
|
| 212 | + ), |
|
| 213 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 214 | + ); |
|
| 215 | + } |
|
| 216 | + } else { |
|
| 217 | + // old school attempt |
|
| 218 | + file_put_contents( |
|
| 219 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 220 | + $activation_errors |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 224 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 232 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 233 | + * or we want to make sure they use something the right way. |
|
| 234 | + * |
|
| 235 | + * @access public |
|
| 236 | + * @param string $function The function that was called |
|
| 237 | + * @param string $message A message explaining what has been done incorrectly |
|
| 238 | + * @param string $version The version of Event Espresso where the error was added |
|
| 239 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 240 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
| 241 | + * but not have any notices appear until a later version. This allows developers |
|
| 242 | + * extra time to update their code before notices appear. |
|
| 243 | + * @param int $error_type |
|
| 244 | + * @uses trigger_error() |
|
| 245 | + */ |
|
| 246 | + public function doing_it_wrong( |
|
| 247 | + $function, |
|
| 248 | + $message, |
|
| 249 | + $version, |
|
| 250 | + $applies_when = '', |
|
| 251 | + $error_type = null |
|
| 252 | + ) { |
|
| 253 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 254 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 255 | + // because we swapped the parameter order around for the last two params, |
|
| 256 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
| 257 | + if (is_int($applies_when)) { |
|
| 258 | + $error_type = $applies_when; |
|
| 259 | + $applies_when = espresso_version(); |
|
| 260 | + } |
|
| 261 | + // if not displaying notices yet, then just leave |
|
| 262 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 266 | + $version = $version === null |
|
| 267 | + ? '' |
|
| 268 | + : sprintf( |
|
| 269 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 270 | + $version |
|
| 271 | + ); |
|
| 272 | + $error_message = sprintf( |
|
| 273 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 274 | + $function, |
|
| 275 | + '<strong>', |
|
| 276 | + '</strong>', |
|
| 277 | + $message, |
|
| 278 | + $version |
|
| 279 | + ); |
|
| 280 | + // don't trigger error if doing ajax, |
|
| 281 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 282 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 283 | + $error_message .= ' ' . esc_html__( |
|
| 284 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 285 | + 'event_espresso' |
|
| 286 | + ); |
|
| 287 | + $error_message .= '<ul><li>'; |
|
| 288 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 289 | + $error_message .= '</ul>'; |
|
| 290 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 291 | + //now we set this on the transient so it shows up on the next request. |
|
| 292 | + EE_Error::get_notices(false, true); |
|
| 293 | + } else { |
|
| 294 | + trigger_error($error_message, $error_type); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Logger helpers |
|
| 303 | + */ |
|
| 304 | + /** |
|
| 305 | + * debug |
|
| 306 | + * |
|
| 307 | + * @param string $class |
|
| 308 | + * @param string $func |
|
| 309 | + * @param string $line |
|
| 310 | + * @param array $info |
|
| 311 | + * @param bool $display_request |
|
| 312 | + * @param string $debug_index |
|
| 313 | + * @param string $debug_key |
|
| 314 | + * @throws EE_Error |
|
| 315 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 316 | + */ |
|
| 317 | + public static function log( |
|
| 318 | + $class = '', |
|
| 319 | + $func = '', |
|
| 320 | + $line = '', |
|
| 321 | + $info = array(), |
|
| 322 | + $display_request = false, |
|
| 323 | + $debug_index = '', |
|
| 324 | + $debug_key = 'EE_DEBUG_SPCO' |
|
| 325 | + ) { |
|
| 326 | + if (WP_DEBUG) { |
|
| 327 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 328 | + $debug_data = get_option($debug_key, array()); |
|
| 329 | + $default_data = array( |
|
| 330 | + $class => $func . '() : ' . $line, |
|
| 331 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
| 332 | + ); |
|
| 333 | + // don't serialize objects |
|
| 334 | + $info = self::strip_objects($info); |
|
| 335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 336 | + if (! isset($debug_data[$index])) { |
|
| 337 | + $debug_data[$index] = array(); |
|
| 338 | + } |
|
| 339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
| 340 | + update_option($debug_key, $debug_data); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * strip_objects |
|
| 348 | + * |
|
| 349 | + * @param array $info |
|
| 350 | + * @return array |
|
| 351 | + */ |
|
| 352 | + public static function strip_objects($info = array()) |
|
| 353 | + { |
|
| 354 | + foreach ($info as $key => $value) { |
|
| 355 | + if (is_array($value)) { |
|
| 356 | + $info[$key] = self::strip_objects($value); |
|
| 357 | + } else if (is_object($value)) { |
|
| 358 | + $object_class = get_class($value); |
|
| 359 | + $info[$object_class] = array(); |
|
| 360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 361 | + if (method_exists($value, 'ID')) { |
|
| 362 | + $info[$object_class]['ID'] = $value->ID(); |
|
| 363 | + } |
|
| 364 | + if (method_exists($value, 'status')) { |
|
| 365 | + $info[$object_class]['status'] = $value->status(); |
|
| 366 | + } else if (method_exists($value, 'status_ID')) { |
|
| 367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
| 368 | + } |
|
| 369 | + unset($info[$key]); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + return (array)$info; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @param mixed $var |
|
| 379 | + * @param string $var_name |
|
| 380 | + * @param string $file |
|
| 381 | + * @param int|string $line |
|
| 382 | + * @param int $heading_tag |
|
| 383 | + * @param bool $die |
|
| 384 | + * @param string $margin |
|
| 385 | + */ |
|
| 386 | + public static function printv( |
|
| 387 | + $var, |
|
| 388 | + $var_name = '', |
|
| 389 | + $file = '', |
|
| 390 | + $line = '', |
|
| 391 | + $heading_tag = 5, |
|
| 392 | + $die = false, |
|
| 393 | + $margin = '' |
|
| 394 | + ) { |
|
| 395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
| 396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 397 | + $is_method = method_exists($var_name, $var); |
|
| 398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 399 | + $heading_tag = absint($heading_tag); |
|
| 400 | + $result = $heading_tag < 3 ? "\n" : ''; |
|
| 401 | + $heading_tag = $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
| 402 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 403 | + $result .= $is_method |
|
| 404 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 405 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 406 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 407 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 408 | + if ($die) { |
|
| 409 | + die($result); |
|
| 410 | + } |
|
| 411 | + echo $result; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + protected static function plainOutput() |
|
| 416 | + { |
|
| 417 | + return defined('EE_TESTS_DIR') || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * @param string $var_name |
|
| 423 | + * @param string $heading_tag |
|
| 424 | + * @param string $margin |
|
| 425 | + * @param int $line |
|
| 426 | + * @return string |
|
| 427 | + */ |
|
| 428 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
| 429 | + { |
|
| 430 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 431 | + return "\n{$line}) {$var_name}"; |
|
| 432 | + } |
|
| 433 | + $margin = "25px 0 0 {$margin}"; |
|
| 434 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * @param string $heading_tag |
|
| 441 | + * @return string |
|
| 442 | + */ |
|
| 443 | + protected static function headingX($heading_tag = 'h5') |
|
| 444 | + { |
|
| 445 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 446 | + return ''; |
|
| 447 | + } |
|
| 448 | + return '</' . $heading_tag . '>'; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * @param string $content |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + protected static function grey_span($content = '') |
|
| 458 | + { |
|
| 459 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 460 | + return $content; |
|
| 461 | + } |
|
| 462 | + return '<span style="color:#999">' . $content . '</span>'; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * @param string $file |
|
| 469 | + * @param int $line |
|
| 470 | + * @return string |
|
| 471 | + */ |
|
| 472 | + protected static function file_and_line($file, $line) |
|
| 473 | + { |
|
| 474 | + if ($file === '' || $line === '' || EEH_Debug_Tools::plainOutput()) { |
|
| 475 | + return ''; |
|
| 476 | + } |
|
| 477 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
| 478 | + . $file |
|
| 479 | + . '<br />line no: ' |
|
| 480 | + . $line |
|
| 481 | + . '</span>'; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * @param string $content |
|
| 488 | + * @return string |
|
| 489 | + */ |
|
| 490 | + protected static function orange_span($content = '') |
|
| 491 | + { |
|
| 492 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 493 | + return $content; |
|
| 494 | + } |
|
| 495 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * @param mixed $var |
|
| 502 | + * @return string |
|
| 503 | + */ |
|
| 504 | + protected static function pre_span($var) |
|
| 505 | + { |
|
| 506 | + ob_start(); |
|
| 507 | + var_dump($var); |
|
| 508 | + $var = ob_get_clean(); |
|
| 509 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 510 | + return "\n" . $var; |
|
| 511 | + } |
|
| 512 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * @param mixed $var |
|
| 519 | + * @param string $var_name |
|
| 520 | + * @param string $file |
|
| 521 | + * @param int|string $line |
|
| 522 | + * @param int $heading_tag |
|
| 523 | + * @param bool $die |
|
| 524 | + */ |
|
| 525 | + public static function printr( |
|
| 526 | + $var, |
|
| 527 | + $var_name = '', |
|
| 528 | + $file = '', |
|
| 529 | + $line = '', |
|
| 530 | + $heading_tag = 5, |
|
| 531 | + $die = false |
|
| 532 | + ) { |
|
| 533 | + // return; |
|
| 534 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 535 | + $margin = is_admin() ? ' 180px' : '0'; |
|
| 536 | + //$print_r = false; |
|
| 537 | + if (is_string($var)) { |
|
| 538 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 539 | + return; |
|
| 540 | + } |
|
| 541 | + if (is_object($var)) { |
|
| 542 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
| 543 | + //$print_r = true; |
|
| 544 | + } else if (is_array($var)) { |
|
| 545 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
| 546 | + //$print_r = true; |
|
| 547 | + } else if (is_numeric($var)) { |
|
| 548 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 549 | + } else if ($var === null) { |
|
| 550 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
| 551 | + } |
|
| 552 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 553 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 554 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 555 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 556 | + EEH_Debug_Tools::pre_span($var) |
|
| 557 | + ); |
|
| 558 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 559 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 560 | + if ($die) { |
|
| 561 | + die($result); |
|
| 562 | + } |
|
| 563 | + echo $result; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /******************** deprecated ********************/ |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * @deprecated 4.9.39.rc.034 |
|
| 574 | + */ |
|
| 575 | + public function reset_times() |
|
| 576 | + { |
|
| 577 | + Benchmark::resetTimes(); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * @deprecated 4.9.39.rc.034 |
|
| 584 | + * @param null $timer_name |
|
| 585 | + */ |
|
| 586 | + public function start_timer($timer_name = null) |
|
| 587 | + { |
|
| 588 | + Benchmark::startTimer($timer_name); |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * @deprecated 4.9.39.rc.034 |
|
| 595 | + * @param string $timer_name |
|
| 596 | + */ |
|
| 597 | + public function stop_timer($timer_name = '') |
|
| 598 | + { |
|
| 599 | + Benchmark::stopTimer($timer_name); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * @deprecated 4.9.39.rc.034 |
|
| 606 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 607 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 608 | + * @return void |
|
| 609 | + */ |
|
| 610 | + public function measure_memory($label, $output_now = false) |
|
| 611 | + { |
|
| 612 | + Benchmark::measureMemory($label, $output_now); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * @deprecated 4.9.39.rc.034 |
|
| 619 | + * @param int $size |
|
| 620 | + * @return string |
|
| 621 | + */ |
|
| 622 | + public function convert($size) |
|
| 623 | + { |
|
| 624 | + return Benchmark::convert($size); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * @deprecated 4.9.39.rc.034 |
|
| 631 | + * @param bool $output_now |
|
| 632 | + * @return string |
|
| 633 | + */ |
|
| 634 | + public function show_times($output_now = true) |
|
| 635 | + { |
|
| 636 | + return Benchmark::displayResults($output_now); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * @deprecated 4.9.39.rc.034 |
|
| 643 | + * @param string $timer_name |
|
| 644 | + * @param float $total_time |
|
| 645 | + * @return string |
|
| 646 | + */ |
|
| 647 | + public function format_time($timer_name, $total_time) |
|
| 648 | + { |
|
| 649 | + return Benchmark::formatTime($timer_name, $total_time); |
|
| 650 | + } |
|
| 651 | 651 | |
| 652 | 652 | |
| 653 | 653 | |
@@ -660,31 +660,31 @@ discard block |
||
| 660 | 660 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 661 | 661 | */ |
| 662 | 662 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
| 663 | - function dump_wp_query() |
|
| 664 | - { |
|
| 665 | - global $wp_query; |
|
| 666 | - d($wp_query); |
|
| 667 | - } |
|
| 663 | + function dump_wp_query() |
|
| 664 | + { |
|
| 665 | + global $wp_query; |
|
| 666 | + d($wp_query); |
|
| 667 | + } |
|
| 668 | 668 | } |
| 669 | 669 | /** |
| 670 | 670 | * borrowed from Kint Debugger |
| 671 | 671 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 672 | 672 | */ |
| 673 | 673 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
| 674 | - function dump_wp() |
|
| 675 | - { |
|
| 676 | - global $wp; |
|
| 677 | - d($wp); |
|
| 678 | - } |
|
| 674 | + function dump_wp() |
|
| 675 | + { |
|
| 676 | + global $wp; |
|
| 677 | + d($wp); |
|
| 678 | + } |
|
| 679 | 679 | } |
| 680 | 680 | /** |
| 681 | 681 | * borrowed from Kint Debugger |
| 682 | 682 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 683 | 683 | */ |
| 684 | 684 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
| 685 | - function dump_post() |
|
| 686 | - { |
|
| 687 | - global $post; |
|
| 688 | - d($post); |
|
| 689 | - } |
|
| 685 | + function dump_post() |
|
| 686 | + { |
|
| 687 | + global $post; |
|
| 688 | + d($post); |
|
| 689 | + } |
|
| 690 | 690 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
| 2 | 2 | |
| 3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | } |
| 6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | public static function instance() |
| 41 | 41 | { |
| 42 | 42 | // check if class object is instantiated, and instantiated properly |
| 43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 43 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | 44 | self::$_instance = new self(); |
| 45 | 45 | } |
| 46 | 46 | return self::$_instance; |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | private function __construct() |
| 55 | 55 | { |
| 56 | 56 | // load Kint PHP debugging library |
| 57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 57 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
| 58 | 58 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
| 59 | 59 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
| 60 | 60 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
| 61 | 61 | // so we've moved it to our test folder so that it is not included with production releases |
| 62 | 62 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
| 63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 63 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
| 64 | 64 | } |
| 65 | 65 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
| 66 | 66 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public static function show_db_name() |
| 82 | 82 | { |
| 83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 83 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | 84 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
| 85 | 85 | . DB_NAME |
| 86 | 86 | . '</p>'; |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
| 132 | 132 | if ($tag) { |
| 133 | 133 | $hook[$tag] = $wp_filter[$tag]; |
| 134 | - if (! is_array($hook[$tag])) { |
|
| 134 | + if ( ! is_array($hook[$tag])) { |
|
| 135 | 135 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
| 136 | 136 | return; |
| 137 | 137 | } |
| 138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 138 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
| 139 | 139 | } else { |
| 140 | 140 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
| 141 | 141 | ksort($hook); |
@@ -188,17 +188,17 @@ discard block |
||
| 188 | 188 | { |
| 189 | 189 | if (WP_DEBUG) { |
| 190 | 190 | $activation_errors = ob_get_contents(); |
| 191 | - if (! empty($activation_errors)) { |
|
| 192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 191 | + if ( ! empty($activation_errors)) { |
|
| 192 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
| 193 | 193 | } |
| 194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
| 195 | 195 | if (class_exists('EEH_File')) { |
| 196 | 196 | try { |
| 197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
| 198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html' |
|
| 199 | 199 | ); |
| 200 | 200 | EEH_File::write_to_file( |
| 201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
| 202 | 202 | $activation_errors |
| 203 | 203 | ); |
| 204 | 204 | } catch (EE_Error $e) { |
@@ -216,11 +216,11 @@ discard block |
||
| 216 | 216 | } else { |
| 217 | 217 | // old school attempt |
| 218 | 218 | file_put_contents( |
| 219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 219 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
| 220 | 220 | $activation_errors |
| 221 | 221 | ); |
| 222 | 222 | } |
| 223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 223 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
| 224 | 224 | update_option('ee_plugin_activation_errors', $activation_errors); |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | // don't trigger error if doing ajax, |
| 281 | 281 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
| 282 | 282 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 283 | - $error_message .= ' ' . esc_html__( |
|
| 283 | + $error_message .= ' '.esc_html__( |
|
| 284 | 284 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
| 285 | 285 | 'event_espresso' |
| 286 | 286 | ); |
@@ -324,16 +324,16 @@ discard block |
||
| 324 | 324 | $debug_key = 'EE_DEBUG_SPCO' |
| 325 | 325 | ) { |
| 326 | 326 | if (WP_DEBUG) { |
| 327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 327 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
| 328 | 328 | $debug_data = get_option($debug_key, array()); |
| 329 | 329 | $default_data = array( |
| 330 | - $class => $func . '() : ' . $line, |
|
| 330 | + $class => $func.'() : '.$line, |
|
| 331 | 331 | 'REQ' => $display_request ? $_REQUEST : '', |
| 332 | 332 | ); |
| 333 | 333 | // don't serialize objects |
| 334 | 334 | $info = self::strip_objects($info); |
| 335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
| 336 | - if (! isset($debug_data[$index])) { |
|
| 336 | + if ( ! isset($debug_data[$index])) { |
|
| 337 | 337 | $debug_data[$index] = array(); |
| 338 | 338 | } |
| 339 | 339 | $debug_data[$index][microtime()] = array_merge($default_data, $info); |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | unset($info[$key]); |
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | - return (array)$info; |
|
| 372 | + return (array) $info; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
@@ -401,8 +401,8 @@ discard block |
||
| 401 | 401 | $heading_tag = $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
| 402 | 402 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
| 403 | 403 | $result .= $is_method |
| 404 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 405 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 404 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
| 405 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
| 406 | 406 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
| 407 | 407 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
| 408 | 408 | if ($die) { |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | return "\n{$line}) {$var_name}"; |
| 432 | 432 | } |
| 433 | 433 | $margin = "25px 0 0 {$margin}"; |
| 434 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 434 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | if (EEH_Debug_Tools::plainOutput()) { |
| 446 | 446 | return ''; |
| 447 | 447 | } |
| 448 | - return '</' . $heading_tag . '>'; |
|
| 448 | + return '</'.$heading_tag.'>'; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | if (EEH_Debug_Tools::plainOutput()) { |
| 460 | 460 | return $content; |
| 461 | 461 | } |
| 462 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 462 | + return '<span style="color:#999">'.$content.'</span>'; |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | if (EEH_Debug_Tools::plainOutput()) { |
| 493 | 493 | return $content; |
| 494 | 494 | } |
| 495 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 495 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | |
@@ -507,9 +507,9 @@ discard block |
||
| 507 | 507 | var_dump($var); |
| 508 | 508 | $var = ob_get_clean(); |
| 509 | 509 | if (EEH_Debug_Tools::plainOutput()) { |
| 510 | - return "\n" . $var; |
|
| 510 | + return "\n".$var; |
|
| 511 | 511 | } |
| 512 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 512 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
| 553 | 553 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
| 554 | 554 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
| 555 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 555 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
| 556 | 556 | EEH_Debug_Tools::pre_span($var) |
| 557 | 557 | ); |
| 558 | 558 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
@@ -17,122 +17,122 @@ |
||
| 17 | 17 | class GatewayDataFormatter implements GatewayDataFormatterInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Gets the text to use for a gateway's line item name when this is a partial payment |
|
| 22 | - * |
|
| 23 | - * @param \EEI_Payment $payment |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function formatPartialPaymentLineItemName(\EEI_Payment $payment) |
|
| 27 | - { |
|
| 28 | - return apply_filters( |
|
| 29 | - 'EEG_Paypal_Pro__do_direct_payment__partial_amount_line_item_name', |
|
| 30 | - $payment->get_first_event_name(), |
|
| 31 | - $this, |
|
| 32 | - $payment |
|
| 33 | - ); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Gets the text to use for a gateway's line item description when this is a partial payment |
|
| 40 | - * |
|
| 41 | - * @param \EEI_Payment $payment |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment) |
|
| 45 | - { |
|
| 46 | - return apply_filters( |
|
| 47 | - 'FHEE__EE_Gateway___partial_payment_desc', |
|
| 48 | - sprintf( |
|
| 49 | - __("Payment of %s for %s", "event_espresso"), |
|
| 50 | - $payment->get_pretty('PAY_amount', 'no_currency_code'), |
|
| 51 | - $payment->get_first_event_name() |
|
| 52 | - ), |
|
| 53 | - $this, |
|
| 54 | - $payment |
|
| 55 | - ); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Gets the name to use for a line item when sending line items to the gateway |
|
| 62 | - * |
|
| 63 | - * @param \EEI_Line_Item $line_item |
|
| 64 | - * @param \EEI_Payment $payment |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
| 68 | - { |
|
| 69 | - return apply_filters( |
|
| 70 | - 'FHEE__EE_gateway___line_item_name', |
|
| 71 | - sprintf( |
|
| 72 | - _x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'), |
|
| 73 | - $line_item->name(), |
|
| 74 | - $line_item->ticket_event_name() |
|
| 75 | - ), |
|
| 76 | - $this, |
|
| 77 | - $line_item, |
|
| 78 | - $payment |
|
| 79 | - ); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Gets the description to use for a line item when sending line items to the gateway |
|
| 86 | - * |
|
| 87 | - * @param \EEI_Line_Item $line_item |
|
| 88 | - * @param \EEI_Payment $payment |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
| 92 | - { |
|
| 93 | - return apply_filters( |
|
| 94 | - 'FHEE__EE_Gateway___line_item_desc', |
|
| 95 | - $line_item->desc(), |
|
| 96 | - $this, |
|
| 97 | - $line_item, |
|
| 98 | - $payment |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Gets the order description that should generally be sent to gateways |
|
| 106 | - * |
|
| 107 | - * @param \EEI_Payment $payment |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public function formatOrderDescription(\EEI_Payment $payment) |
|
| 111 | - { |
|
| 112 | - return apply_filters( |
|
| 113 | - 'FHEE__EE_Gateway___order_description', |
|
| 114 | - sprintf( |
|
| 115 | - __('Event Registrations from %1$s for %2$s', "event_espresso"), |
|
| 116 | - wp_specialchars_decode(get_bloginfo(), ENT_QUOTES), |
|
| 117 | - $payment->get_first_event_name() |
|
| 118 | - ), |
|
| 119 | - $this, |
|
| 120 | - $payment |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Formats the amount so it can generally be sent to gateways |
|
| 128 | - * |
|
| 129 | - * @param float $amount |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public function formatCurrency($amount) |
|
| 133 | - { |
|
| 134 | - return number_format($amount, 2, '.', ''); |
|
| 135 | - } |
|
| 20 | + /** |
|
| 21 | + * Gets the text to use for a gateway's line item name when this is a partial payment |
|
| 22 | + * |
|
| 23 | + * @param \EEI_Payment $payment |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function formatPartialPaymentLineItemName(\EEI_Payment $payment) |
|
| 27 | + { |
|
| 28 | + return apply_filters( |
|
| 29 | + 'EEG_Paypal_Pro__do_direct_payment__partial_amount_line_item_name', |
|
| 30 | + $payment->get_first_event_name(), |
|
| 31 | + $this, |
|
| 32 | + $payment |
|
| 33 | + ); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Gets the text to use for a gateway's line item description when this is a partial payment |
|
| 40 | + * |
|
| 41 | + * @param \EEI_Payment $payment |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment) |
|
| 45 | + { |
|
| 46 | + return apply_filters( |
|
| 47 | + 'FHEE__EE_Gateway___partial_payment_desc', |
|
| 48 | + sprintf( |
|
| 49 | + __("Payment of %s for %s", "event_espresso"), |
|
| 50 | + $payment->get_pretty('PAY_amount', 'no_currency_code'), |
|
| 51 | + $payment->get_first_event_name() |
|
| 52 | + ), |
|
| 53 | + $this, |
|
| 54 | + $payment |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Gets the name to use for a line item when sending line items to the gateway |
|
| 62 | + * |
|
| 63 | + * @param \EEI_Line_Item $line_item |
|
| 64 | + * @param \EEI_Payment $payment |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
| 68 | + { |
|
| 69 | + return apply_filters( |
|
| 70 | + 'FHEE__EE_gateway___line_item_name', |
|
| 71 | + sprintf( |
|
| 72 | + _x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'), |
|
| 73 | + $line_item->name(), |
|
| 74 | + $line_item->ticket_event_name() |
|
| 75 | + ), |
|
| 76 | + $this, |
|
| 77 | + $line_item, |
|
| 78 | + $payment |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Gets the description to use for a line item when sending line items to the gateway |
|
| 86 | + * |
|
| 87 | + * @param \EEI_Line_Item $line_item |
|
| 88 | + * @param \EEI_Payment $payment |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
| 92 | + { |
|
| 93 | + return apply_filters( |
|
| 94 | + 'FHEE__EE_Gateway___line_item_desc', |
|
| 95 | + $line_item->desc(), |
|
| 96 | + $this, |
|
| 97 | + $line_item, |
|
| 98 | + $payment |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Gets the order description that should generally be sent to gateways |
|
| 106 | + * |
|
| 107 | + * @param \EEI_Payment $payment |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public function formatOrderDescription(\EEI_Payment $payment) |
|
| 111 | + { |
|
| 112 | + return apply_filters( |
|
| 113 | + 'FHEE__EE_Gateway___order_description', |
|
| 114 | + sprintf( |
|
| 115 | + __('Event Registrations from %1$s for %2$s', "event_espresso"), |
|
| 116 | + wp_specialchars_decode(get_bloginfo(), ENT_QUOTES), |
|
| 117 | + $payment->get_first_event_name() |
|
| 118 | + ), |
|
| 119 | + $this, |
|
| 120 | + $payment |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Formats the amount so it can generally be sent to gateways |
|
| 128 | + * |
|
| 129 | + * @param float $amount |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public function formatCurrency($amount) |
|
| 133 | + { |
|
| 134 | + return number_format($amount, 2, '.', ''); |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | // End of file GatewayDataFormatter.php |
| 138 | 138 | // Location: core\services\gateways/GatewayDataFormatter.php |
| 139 | 139 | \ No newline at end of file |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | use EEH_Template; |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
| 10 | - exit( 'No direct script access allowed' ); |
|
| 10 | + exit( 'No direct script access allowed' ); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | |
@@ -23,387 +23,387 @@ discard block |
||
| 23 | 23 | class Iframe |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /* |
|
| 26 | + /* |
|
| 27 | 27 | * HTML for notices and ajax gif |
| 28 | 28 | * @var string $title |
| 29 | 29 | */ |
| 30 | - protected $title = ''; |
|
| 30 | + protected $title = ''; |
|
| 31 | 31 | |
| 32 | - /* |
|
| 32 | + /* |
|
| 33 | 33 | * HTML for the content being displayed |
| 34 | 34 | * @var string $content |
| 35 | 35 | */ |
| 36 | - protected $content = ''; |
|
| 36 | + protected $content = ''; |
|
| 37 | 37 | |
| 38 | - /* |
|
| 38 | + /* |
|
| 39 | 39 | * whether or not to call wp_head() and wp_footer() |
| 40 | 40 | * @var boolean $enqueue_wp_assets |
| 41 | 41 | */ |
| 42 | - protected $enqueue_wp_assets = false; |
|
| 42 | + protected $enqueue_wp_assets = false; |
|
| 43 | 43 | |
| 44 | - /* |
|
| 44 | + /* |
|
| 45 | 45 | * an array of CSS URLs |
| 46 | 46 | * @var array $css |
| 47 | 47 | */ |
| 48 | - protected $css = array(); |
|
| 48 | + protected $css = array(); |
|
| 49 | 49 | |
| 50 | - /* |
|
| 50 | + /* |
|
| 51 | 51 | * an array of JS URLs to be set in the HTML header. |
| 52 | 52 | * @var array $header_js |
| 53 | 53 | */ |
| 54 | - protected $header_js = array(); |
|
| 54 | + protected $header_js = array(); |
|
| 55 | 55 | |
| 56 | - /* |
|
| 56 | + /* |
|
| 57 | 57 | * an array of additional attributes to be added to <script> tags for header JS |
| 58 | 58 | * @var array $footer_js |
| 59 | 59 | */ |
| 60 | - protected $header_js_attributes = array(); |
|
| 60 | + protected $header_js_attributes = array(); |
|
| 61 | 61 | |
| 62 | - /* |
|
| 62 | + /* |
|
| 63 | 63 | * an array of JS URLs to be displayed before the HTML </body> tag |
| 64 | 64 | * @var array $footer_js |
| 65 | 65 | */ |
| 66 | - protected $footer_js = array(); |
|
| 66 | + protected $footer_js = array(); |
|
| 67 | 67 | |
| 68 | - /* |
|
| 68 | + /* |
|
| 69 | 69 | * an array of additional attributes to be added to <script> tags for footer JS |
| 70 | 70 | * @var array $footer_js_attributes |
| 71 | 71 | */ |
| 72 | - protected $footer_js_attributes = array(); |
|
| 72 | + protected $footer_js_attributes = array(); |
|
| 73 | 73 | |
| 74 | - /* |
|
| 74 | + /* |
|
| 75 | 75 | * an array of JSON vars to be set in the HTML header. |
| 76 | 76 | * @var array $localized_vars |
| 77 | 77 | */ |
| 78 | - protected $localized_vars = array(); |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Iframe constructor |
|
| 84 | - * |
|
| 85 | - * @param string $title |
|
| 86 | - * @param string $content |
|
| 87 | - * @throws DomainException |
|
| 88 | - */ |
|
| 89 | - public function __construct( $title, $content ) |
|
| 90 | - { |
|
| 91 | - global $wp_version; |
|
| 92 | - if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
| 93 | - define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
| 94 | - } |
|
| 95 | - $this->setContent( $content ); |
|
| 96 | - $this->setTitle( $title ); |
|
| 97 | - $this->addStylesheets( |
|
| 98 | - apply_filters( |
|
| 99 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
| 100 | - array( |
|
| 101 | - 'site_theme' => get_stylesheet_directory_uri() . DS |
|
| 102 | - . 'style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 103 | - 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
| 104 | - 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
| 105 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 106 | - ), |
|
| 107 | - $this |
|
| 108 | - ) |
|
| 109 | - ); |
|
| 110 | - $this->addScripts( |
|
| 111 | - apply_filters( |
|
| 112 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
| 113 | - array( |
|
| 114 | - 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
| 115 | - 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
| 116 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 117 | - ), |
|
| 118 | - $this |
|
| 119 | - ) |
|
| 120 | - ); |
|
| 121 | - if ( |
|
| 122 | - apply_filters( |
|
| 123 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
| 124 | - false |
|
| 125 | - ) |
|
| 126 | - ) { |
|
| 127 | - $this->addStylesheets( |
|
| 128 | - apply_filters( |
|
| 129 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
| 130 | - array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
| 131 | - $this |
|
| 132 | - ) |
|
| 133 | - ); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $title |
|
| 141 | - * @throws DomainException |
|
| 142 | - */ |
|
| 143 | - public function setTitle( $title ) |
|
| 144 | - { |
|
| 145 | - if ( empty( $title ) ) { |
|
| 146 | - throw new DomainException( |
|
| 147 | - esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
| 148 | - ); |
|
| 149 | - } |
|
| 150 | - $this->title = $title; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param string $content |
|
| 157 | - * @throws DomainException |
|
| 158 | - */ |
|
| 159 | - public function setContent( $content ) |
|
| 160 | - { |
|
| 161 | - if ( empty( $content ) ) { |
|
| 162 | - throw new DomainException( |
|
| 163 | - esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
| 164 | - ); |
|
| 165 | - } |
|
| 166 | - $this->content = $content; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param boolean $enqueue_wp_assets |
|
| 173 | - */ |
|
| 174 | - public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
| 175 | - { |
|
| 176 | - $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @param array $stylesheets |
|
| 183 | - * @throws DomainException |
|
| 184 | - */ |
|
| 185 | - public function addStylesheets( array $stylesheets ) |
|
| 186 | - { |
|
| 187 | - if ( empty( $stylesheets ) ) { |
|
| 188 | - throw new DomainException( |
|
| 189 | - esc_html__( |
|
| 190 | - 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
| 191 | - 'event_espresso' |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - } |
|
| 195 | - foreach ( $stylesheets as $handle => $stylesheet ) { |
|
| 196 | - $this->css[ $handle ] = $stylesheet; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @param array $scripts |
|
| 204 | - * @param bool $add_to_header |
|
| 205 | - * @throws DomainException |
|
| 206 | - */ |
|
| 207 | - public function addScripts( array $scripts, $add_to_header = false ) |
|
| 208 | - { |
|
| 209 | - if ( empty( $scripts ) ) { |
|
| 210 | - throw new DomainException( |
|
| 211 | - esc_html__( |
|
| 212 | - 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
| 213 | - 'event_espresso' |
|
| 214 | - ) |
|
| 215 | - ); |
|
| 216 | - } |
|
| 217 | - foreach ( $scripts as $handle => $script ) { |
|
| 218 | - if ( $add_to_header ) { |
|
| 219 | - $this->header_js[ $handle ] = $script; |
|
| 220 | - } else { |
|
| 221 | - $this->footer_js[ $handle ] = $script; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @param array $script_attributes |
|
| 230 | - * @param bool $add_to_header |
|
| 231 | - * @throws DomainException |
|
| 232 | - */ |
|
| 233 | - public function addScriptAttributes( array $script_attributes, $add_to_header = false ) |
|
| 234 | - { |
|
| 235 | - if ( empty($script_attributes ) ) { |
|
| 236 | - throw new DomainException( |
|
| 237 | - esc_html__( |
|
| 238 | - 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
| 239 | - 'event_espresso' |
|
| 240 | - ) |
|
| 241 | - ); |
|
| 242 | - } |
|
| 243 | - foreach ($script_attributes as $handle => $script_attribute ) { |
|
| 244 | - if ( $add_to_header ) { |
|
| 245 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
| 246 | - } else { |
|
| 247 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param array $vars |
|
| 256 | - * @param string $var_name |
|
| 257 | - * @throws DomainException |
|
| 258 | - */ |
|
| 259 | - public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
| 260 | - { |
|
| 261 | - if ( empty( $vars ) ) { |
|
| 262 | - throw new DomainException( |
|
| 263 | - esc_html__( |
|
| 264 | - 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
| 265 | - 'event_espresso' |
|
| 266 | - ) |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - foreach ( $vars as $handle => $var ) { |
|
| 270 | - if ( $var_name === 'eei18n' ) { |
|
| 271 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
| 272 | - } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
| 273 | - $this->localized_vars[ $var_name ] = $var; |
|
| 274 | - } else { |
|
| 275 | - if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
| 276 | - $this->localized_vars[ $var_name ] = array(); |
|
| 277 | - } |
|
| 278 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * @param string $utm_content |
|
| 287 | - * @throws DomainException |
|
| 288 | - */ |
|
| 289 | - public function display($utm_content = '') |
|
| 290 | - { |
|
| 291 | - $this->content .= EEH_Template::powered_by_event_espresso( |
|
| 292 | - '', |
|
| 293 | - '', |
|
| 294 | - ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
| 295 | - ); |
|
| 296 | - EE_System::do_not_cache(); |
|
| 297 | - echo $this->getTemplate(); |
|
| 298 | - exit; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * @return string |
|
| 305 | - * @throws DomainException |
|
| 306 | - */ |
|
| 307 | - public function getTemplate() |
|
| 308 | - { |
|
| 309 | - return EEH_Template::display_template( |
|
| 310 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
| 311 | - array( |
|
| 312 | - 'title' => apply_filters( |
|
| 313 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
| 314 | - $this->title, |
|
| 315 | - $this |
|
| 316 | - ), |
|
| 317 | - 'content' => apply_filters( |
|
| 318 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
| 319 | - $this->content, |
|
| 320 | - $this |
|
| 321 | - ), |
|
| 322 | - 'enqueue_wp_assets' => apply_filters( |
|
| 323 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
| 324 | - $this->enqueue_wp_assets, |
|
| 325 | - $this |
|
| 326 | - ), |
|
| 327 | - 'css' => (array)apply_filters( |
|
| 328 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
| 329 | - $this->css, |
|
| 330 | - $this |
|
| 331 | - ), |
|
| 332 | - 'header_js' => (array)apply_filters( |
|
| 333 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
| 334 | - $this->header_js, |
|
| 335 | - $this |
|
| 336 | - ), |
|
| 337 | - 'header_js_attributes' => (array) apply_filters( |
|
| 338 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
| 339 | - $this->header_js_attributes, |
|
| 340 | - $this |
|
| 341 | - ), |
|
| 342 | - 'footer_js' => (array)apply_filters( |
|
| 343 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
| 344 | - $this->footer_js, |
|
| 345 | - $this |
|
| 346 | - ), |
|
| 347 | - 'footer_js_attributes' => (array)apply_filters( |
|
| 348 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
| 349 | - $this->footer_js_attributes, |
|
| 350 | - $this |
|
| 351 | - ), |
|
| 352 | - 'eei18n' => apply_filters( |
|
| 353 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
| 354 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
| 355 | - $this |
|
| 356 | - ), |
|
| 357 | - 'notices' => EEH_Template::display_template( |
|
| 358 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
| 359 | - array(), |
|
| 360 | - true |
|
| 361 | - ), |
|
| 362 | - ), |
|
| 363 | - true, |
|
| 364 | - true |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * localizeJsonVars |
|
| 372 | - * |
|
| 373 | - * @return string |
|
| 374 | - */ |
|
| 375 | - public function localizeJsonVars() |
|
| 376 | - { |
|
| 377 | - $JSON = ''; |
|
| 378 | - foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
| 379 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars ); |
|
| 380 | - $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
| 381 | - $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
| 382 | - $JSON .= '; /* ]]> */'; |
|
| 383 | - } |
|
| 384 | - return $JSON; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * @param bool|int|float|string|array $var |
|
| 391 | - * @return array |
|
| 392 | - */ |
|
| 393 | - public function encodeJsonVars( $var ) |
|
| 394 | - { |
|
| 395 | - if ( is_array( $var ) ) { |
|
| 396 | - $localized_vars = array(); |
|
| 397 | - foreach ( (array)$var as $key => $value ) { |
|
| 398 | - $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
| 399 | - } |
|
| 400 | - return $localized_vars; |
|
| 401 | - } |
|
| 402 | - if ( is_scalar( $var ) ) { |
|
| 403 | - return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
| 404 | - } |
|
| 405 | - return null; |
|
| 406 | - } |
|
| 78 | + protected $localized_vars = array(); |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Iframe constructor |
|
| 84 | + * |
|
| 85 | + * @param string $title |
|
| 86 | + * @param string $content |
|
| 87 | + * @throws DomainException |
|
| 88 | + */ |
|
| 89 | + public function __construct( $title, $content ) |
|
| 90 | + { |
|
| 91 | + global $wp_version; |
|
| 92 | + if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
| 93 | + define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
| 94 | + } |
|
| 95 | + $this->setContent( $content ); |
|
| 96 | + $this->setTitle( $title ); |
|
| 97 | + $this->addStylesheets( |
|
| 98 | + apply_filters( |
|
| 99 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
| 100 | + array( |
|
| 101 | + 'site_theme' => get_stylesheet_directory_uri() . DS |
|
| 102 | + . 'style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 103 | + 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
| 104 | + 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
| 105 | + . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 106 | + ), |
|
| 107 | + $this |
|
| 108 | + ) |
|
| 109 | + ); |
|
| 110 | + $this->addScripts( |
|
| 111 | + apply_filters( |
|
| 112 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
| 113 | + array( |
|
| 114 | + 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
| 115 | + 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
| 116 | + . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 117 | + ), |
|
| 118 | + $this |
|
| 119 | + ) |
|
| 120 | + ); |
|
| 121 | + if ( |
|
| 122 | + apply_filters( |
|
| 123 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
| 124 | + false |
|
| 125 | + ) |
|
| 126 | + ) { |
|
| 127 | + $this->addStylesheets( |
|
| 128 | + apply_filters( |
|
| 129 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
| 130 | + array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
| 131 | + $this |
|
| 132 | + ) |
|
| 133 | + ); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $title |
|
| 141 | + * @throws DomainException |
|
| 142 | + */ |
|
| 143 | + public function setTitle( $title ) |
|
| 144 | + { |
|
| 145 | + if ( empty( $title ) ) { |
|
| 146 | + throw new DomainException( |
|
| 147 | + esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
| 148 | + ); |
|
| 149 | + } |
|
| 150 | + $this->title = $title; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param string $content |
|
| 157 | + * @throws DomainException |
|
| 158 | + */ |
|
| 159 | + public function setContent( $content ) |
|
| 160 | + { |
|
| 161 | + if ( empty( $content ) ) { |
|
| 162 | + throw new DomainException( |
|
| 163 | + esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
| 164 | + ); |
|
| 165 | + } |
|
| 166 | + $this->content = $content; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param boolean $enqueue_wp_assets |
|
| 173 | + */ |
|
| 174 | + public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
| 175 | + { |
|
| 176 | + $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @param array $stylesheets |
|
| 183 | + * @throws DomainException |
|
| 184 | + */ |
|
| 185 | + public function addStylesheets( array $stylesheets ) |
|
| 186 | + { |
|
| 187 | + if ( empty( $stylesheets ) ) { |
|
| 188 | + throw new DomainException( |
|
| 189 | + esc_html__( |
|
| 190 | + 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
| 191 | + 'event_espresso' |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | + foreach ( $stylesheets as $handle => $stylesheet ) { |
|
| 196 | + $this->css[ $handle ] = $stylesheet; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @param array $scripts |
|
| 204 | + * @param bool $add_to_header |
|
| 205 | + * @throws DomainException |
|
| 206 | + */ |
|
| 207 | + public function addScripts( array $scripts, $add_to_header = false ) |
|
| 208 | + { |
|
| 209 | + if ( empty( $scripts ) ) { |
|
| 210 | + throw new DomainException( |
|
| 211 | + esc_html__( |
|
| 212 | + 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
| 213 | + 'event_espresso' |
|
| 214 | + ) |
|
| 215 | + ); |
|
| 216 | + } |
|
| 217 | + foreach ( $scripts as $handle => $script ) { |
|
| 218 | + if ( $add_to_header ) { |
|
| 219 | + $this->header_js[ $handle ] = $script; |
|
| 220 | + } else { |
|
| 221 | + $this->footer_js[ $handle ] = $script; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @param array $script_attributes |
|
| 230 | + * @param bool $add_to_header |
|
| 231 | + * @throws DomainException |
|
| 232 | + */ |
|
| 233 | + public function addScriptAttributes( array $script_attributes, $add_to_header = false ) |
|
| 234 | + { |
|
| 235 | + if ( empty($script_attributes ) ) { |
|
| 236 | + throw new DomainException( |
|
| 237 | + esc_html__( |
|
| 238 | + 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
| 239 | + 'event_espresso' |
|
| 240 | + ) |
|
| 241 | + ); |
|
| 242 | + } |
|
| 243 | + foreach ($script_attributes as $handle => $script_attribute ) { |
|
| 244 | + if ( $add_to_header ) { |
|
| 245 | + $this->header_js_attributes[ $handle ] = $script_attribute; |
|
| 246 | + } else { |
|
| 247 | + $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param array $vars |
|
| 256 | + * @param string $var_name |
|
| 257 | + * @throws DomainException |
|
| 258 | + */ |
|
| 259 | + public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
| 260 | + { |
|
| 261 | + if ( empty( $vars ) ) { |
|
| 262 | + throw new DomainException( |
|
| 263 | + esc_html__( |
|
| 264 | + 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
| 265 | + 'event_espresso' |
|
| 266 | + ) |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + foreach ( $vars as $handle => $var ) { |
|
| 270 | + if ( $var_name === 'eei18n' ) { |
|
| 271 | + EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
| 272 | + } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
| 273 | + $this->localized_vars[ $var_name ] = $var; |
|
| 274 | + } else { |
|
| 275 | + if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
| 276 | + $this->localized_vars[ $var_name ] = array(); |
|
| 277 | + } |
|
| 278 | + $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * @param string $utm_content |
|
| 287 | + * @throws DomainException |
|
| 288 | + */ |
|
| 289 | + public function display($utm_content = '') |
|
| 290 | + { |
|
| 291 | + $this->content .= EEH_Template::powered_by_event_espresso( |
|
| 292 | + '', |
|
| 293 | + '', |
|
| 294 | + ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
| 295 | + ); |
|
| 296 | + EE_System::do_not_cache(); |
|
| 297 | + echo $this->getTemplate(); |
|
| 298 | + exit; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * @return string |
|
| 305 | + * @throws DomainException |
|
| 306 | + */ |
|
| 307 | + public function getTemplate() |
|
| 308 | + { |
|
| 309 | + return EEH_Template::display_template( |
|
| 310 | + __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
| 311 | + array( |
|
| 312 | + 'title' => apply_filters( |
|
| 313 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
| 314 | + $this->title, |
|
| 315 | + $this |
|
| 316 | + ), |
|
| 317 | + 'content' => apply_filters( |
|
| 318 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
| 319 | + $this->content, |
|
| 320 | + $this |
|
| 321 | + ), |
|
| 322 | + 'enqueue_wp_assets' => apply_filters( |
|
| 323 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
| 324 | + $this->enqueue_wp_assets, |
|
| 325 | + $this |
|
| 326 | + ), |
|
| 327 | + 'css' => (array)apply_filters( |
|
| 328 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
| 329 | + $this->css, |
|
| 330 | + $this |
|
| 331 | + ), |
|
| 332 | + 'header_js' => (array)apply_filters( |
|
| 333 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
| 334 | + $this->header_js, |
|
| 335 | + $this |
|
| 336 | + ), |
|
| 337 | + 'header_js_attributes' => (array) apply_filters( |
|
| 338 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
| 339 | + $this->header_js_attributes, |
|
| 340 | + $this |
|
| 341 | + ), |
|
| 342 | + 'footer_js' => (array)apply_filters( |
|
| 343 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
| 344 | + $this->footer_js, |
|
| 345 | + $this |
|
| 346 | + ), |
|
| 347 | + 'footer_js_attributes' => (array)apply_filters( |
|
| 348 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
| 349 | + $this->footer_js_attributes, |
|
| 350 | + $this |
|
| 351 | + ), |
|
| 352 | + 'eei18n' => apply_filters( |
|
| 353 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
| 354 | + EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
| 355 | + $this |
|
| 356 | + ), |
|
| 357 | + 'notices' => EEH_Template::display_template( |
|
| 358 | + EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
| 359 | + array(), |
|
| 360 | + true |
|
| 361 | + ), |
|
| 362 | + ), |
|
| 363 | + true, |
|
| 364 | + true |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * localizeJsonVars |
|
| 372 | + * |
|
| 373 | + * @return string |
|
| 374 | + */ |
|
| 375 | + public function localizeJsonVars() |
|
| 376 | + { |
|
| 377 | + $JSON = ''; |
|
| 378 | + foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
| 379 | + $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars ); |
|
| 380 | + $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
| 381 | + $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
| 382 | + $JSON .= '; /* ]]> */'; |
|
| 383 | + } |
|
| 384 | + return $JSON; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * @param bool|int|float|string|array $var |
|
| 391 | + * @return array |
|
| 392 | + */ |
|
| 393 | + public function encodeJsonVars( $var ) |
|
| 394 | + { |
|
| 395 | + if ( is_array( $var ) ) { |
|
| 396 | + $localized_vars = array(); |
|
| 397 | + foreach ( (array)$var as $key => $value ) { |
|
| 398 | + $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
| 399 | + } |
|
| 400 | + return $localized_vars; |
|
| 401 | + } |
|
| 402 | + if ( is_scalar( $var ) ) { |
|
| 403 | + return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
| 404 | + } |
|
| 405 | + return null; |
|
| 406 | + } |
|
| 407 | 407 | |
| 408 | 408 | |
| 409 | 409 | |
@@ -6,8 +6,8 @@ discard block |
||
| 6 | 6 | use EE_System; |
| 7 | 7 | use EEH_Template; |
| 8 | 8 | |
| 9 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 10 | - exit( 'No direct script access allowed' ); |
|
| 9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 10 | + exit('No direct script access allowed'); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | |
@@ -86,23 +86,23 @@ discard block |
||
| 86 | 86 | * @param string $content |
| 87 | 87 | * @throws DomainException |
| 88 | 88 | */ |
| 89 | - public function __construct( $title, $content ) |
|
| 89 | + public function __construct($title, $content) |
|
| 90 | 90 | { |
| 91 | 91 | global $wp_version; |
| 92 | - if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
| 93 | - define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
| 92 | + if ( ! defined('EE_IFRAME_DIR_URL')) { |
|
| 93 | + define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
| 94 | 94 | } |
| 95 | - $this->setContent( $content ); |
|
| 96 | - $this->setTitle( $title ); |
|
| 95 | + $this->setContent($content); |
|
| 96 | + $this->setTitle($title); |
|
| 97 | 97 | $this->addStylesheets( |
| 98 | 98 | apply_filters( |
| 99 | 99 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
| 100 | 100 | array( |
| 101 | - 'site_theme' => get_stylesheet_directory_uri() . DS |
|
| 102 | - . 'style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 103 | - 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
| 101 | + 'site_theme' => get_stylesheet_directory_uri().DS |
|
| 102 | + . 'style.css?ver='.EVENT_ESPRESSO_VERSION, |
|
| 103 | + 'dashicons' => includes_url('css/dashicons.min.css?ver='.$wp_version), |
|
| 104 | 104 | 'espresso_default' => EE_GLOBAL_ASSETS_URL |
| 105 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 105 | + . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
| 106 | 106 | ), |
| 107 | 107 | $this |
| 108 | 108 | ) |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | apply_filters( |
| 112 | 112 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
| 113 | 113 | array( |
| 114 | - 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
| 114 | + 'jquery' => includes_url('js/jquery/jquery.js?ver='.$wp_version), |
|
| 115 | 115 | 'espresso_core' => EE_GLOBAL_ASSETS_URL |
| 116 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 116 | + . 'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION, |
|
| 117 | 117 | ), |
| 118 | 118 | $this |
| 119 | 119 | ) |
@@ -140,11 +140,11 @@ discard block |
||
| 140 | 140 | * @param string $title |
| 141 | 141 | * @throws DomainException |
| 142 | 142 | */ |
| 143 | - public function setTitle( $title ) |
|
| 143 | + public function setTitle($title) |
|
| 144 | 144 | { |
| 145 | - if ( empty( $title ) ) { |
|
| 145 | + if (empty($title)) { |
|
| 146 | 146 | throw new DomainException( |
| 147 | - esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
| 147 | + esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
| 148 | 148 | ); |
| 149 | 149 | } |
| 150 | 150 | $this->title = $title; |
@@ -156,11 +156,11 @@ discard block |
||
| 156 | 156 | * @param string $content |
| 157 | 157 | * @throws DomainException |
| 158 | 158 | */ |
| 159 | - public function setContent( $content ) |
|
| 159 | + public function setContent($content) |
|
| 160 | 160 | { |
| 161 | - if ( empty( $content ) ) { |
|
| 161 | + if (empty($content)) { |
|
| 162 | 162 | throw new DomainException( |
| 163 | - esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
| 163 | + esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
| 164 | 164 | ); |
| 165 | 165 | } |
| 166 | 166 | $this->content = $content; |
@@ -171,9 +171,9 @@ discard block |
||
| 171 | 171 | /** |
| 172 | 172 | * @param boolean $enqueue_wp_assets |
| 173 | 173 | */ |
| 174 | - public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
| 174 | + public function setEnqueueWpAssets($enqueue_wp_assets) |
|
| 175 | 175 | { |
| 176 | - $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
| 176 | + $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -182,9 +182,9 @@ discard block |
||
| 182 | 182 | * @param array $stylesheets |
| 183 | 183 | * @throws DomainException |
| 184 | 184 | */ |
| 185 | - public function addStylesheets( array $stylesheets ) |
|
| 185 | + public function addStylesheets(array $stylesheets) |
|
| 186 | 186 | { |
| 187 | - if ( empty( $stylesheets ) ) { |
|
| 187 | + if (empty($stylesheets)) { |
|
| 188 | 188 | throw new DomainException( |
| 189 | 189 | esc_html__( |
| 190 | 190 | 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
@@ -192,8 +192,8 @@ discard block |
||
| 192 | 192 | ) |
| 193 | 193 | ); |
| 194 | 194 | } |
| 195 | - foreach ( $stylesheets as $handle => $stylesheet ) { |
|
| 196 | - $this->css[ $handle ] = $stylesheet; |
|
| 195 | + foreach ($stylesheets as $handle => $stylesheet) { |
|
| 196 | + $this->css[$handle] = $stylesheet; |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | * @param bool $add_to_header |
| 205 | 205 | * @throws DomainException |
| 206 | 206 | */ |
| 207 | - public function addScripts( array $scripts, $add_to_header = false ) |
|
| 207 | + public function addScripts(array $scripts, $add_to_header = false) |
|
| 208 | 208 | { |
| 209 | - if ( empty( $scripts ) ) { |
|
| 209 | + if (empty($scripts)) { |
|
| 210 | 210 | throw new DomainException( |
| 211 | 211 | esc_html__( |
| 212 | 212 | 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
@@ -214,11 +214,11 @@ discard block |
||
| 214 | 214 | ) |
| 215 | 215 | ); |
| 216 | 216 | } |
| 217 | - foreach ( $scripts as $handle => $script ) { |
|
| 218 | - if ( $add_to_header ) { |
|
| 219 | - $this->header_js[ $handle ] = $script; |
|
| 217 | + foreach ($scripts as $handle => $script) { |
|
| 218 | + if ($add_to_header) { |
|
| 219 | + $this->header_js[$handle] = $script; |
|
| 220 | 220 | } else { |
| 221 | - $this->footer_js[ $handle ] = $script; |
|
| 221 | + $this->footer_js[$handle] = $script; |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | } |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | * @param bool $add_to_header |
| 231 | 231 | * @throws DomainException |
| 232 | 232 | */ |
| 233 | - public function addScriptAttributes( array $script_attributes, $add_to_header = false ) |
|
| 233 | + public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
| 234 | 234 | { |
| 235 | - if ( empty($script_attributes ) ) { |
|
| 235 | + if (empty($script_attributes)) { |
|
| 236 | 236 | throw new DomainException( |
| 237 | 237 | esc_html__( |
| 238 | 238 | 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | ) |
| 241 | 241 | ); |
| 242 | 242 | } |
| 243 | - foreach ($script_attributes as $handle => $script_attribute ) { |
|
| 244 | - if ( $add_to_header ) { |
|
| 245 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
| 243 | + foreach ($script_attributes as $handle => $script_attribute) { |
|
| 244 | + if ($add_to_header) { |
|
| 245 | + $this->header_js_attributes[$handle] = $script_attribute; |
|
| 246 | 246 | } else { |
| 247 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
| 247 | + $this->footer_js_attributes[$handle] = $script_attribute; |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | } |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | * @param string $var_name |
| 257 | 257 | * @throws DomainException |
| 258 | 258 | */ |
| 259 | - public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
| 259 | + public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
| 260 | 260 | { |
| 261 | - if ( empty( $vars ) ) { |
|
| 261 | + if (empty($vars)) { |
|
| 262 | 262 | throw new DomainException( |
| 263 | 263 | esc_html__( |
| 264 | 264 | 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
@@ -266,16 +266,16 @@ discard block |
||
| 266 | 266 | ) |
| 267 | 267 | ); |
| 268 | 268 | } |
| 269 | - foreach ( $vars as $handle => $var ) { |
|
| 270 | - if ( $var_name === 'eei18n' ) { |
|
| 271 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
| 269 | + foreach ($vars as $handle => $var) { |
|
| 270 | + if ($var_name === 'eei18n') { |
|
| 271 | + EE_Registry::$i18n_js_strings[$handle] = $var; |
|
| 272 | 272 | } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
| 273 | - $this->localized_vars[ $var_name ] = $var; |
|
| 273 | + $this->localized_vars[$var_name] = $var; |
|
| 274 | 274 | } else { |
| 275 | - if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
| 276 | - $this->localized_vars[ $var_name ] = array(); |
|
| 275 | + if ( ! isset($this->localized_vars[$var_name])) { |
|
| 276 | + $this->localized_vars[$var_name] = array(); |
|
| 277 | 277 | } |
| 278 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
| 278 | + $this->localized_vars[$var_name][$handle] = $var; |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | } |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | public function getTemplate() |
| 308 | 308 | { |
| 309 | 309 | return EEH_Template::display_template( |
| 310 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
| 310 | + __DIR__.DIRECTORY_SEPARATOR.'iframe_wrapper.template.php', |
|
| 311 | 311 | array( |
| 312 | 312 | 'title' => apply_filters( |
| 313 | 313 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
@@ -324,12 +324,12 @@ discard block |
||
| 324 | 324 | $this->enqueue_wp_assets, |
| 325 | 325 | $this |
| 326 | 326 | ), |
| 327 | - 'css' => (array)apply_filters( |
|
| 327 | + 'css' => (array) apply_filters( |
|
| 328 | 328 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
| 329 | 329 | $this->css, |
| 330 | 330 | $this |
| 331 | 331 | ), |
| 332 | - 'header_js' => (array)apply_filters( |
|
| 332 | + 'header_js' => (array) apply_filters( |
|
| 333 | 333 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
| 334 | 334 | $this->header_js, |
| 335 | 335 | $this |
@@ -339,23 +339,23 @@ discard block |
||
| 339 | 339 | $this->header_js_attributes, |
| 340 | 340 | $this |
| 341 | 341 | ), |
| 342 | - 'footer_js' => (array)apply_filters( |
|
| 342 | + 'footer_js' => (array) apply_filters( |
|
| 343 | 343 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
| 344 | 344 | $this->footer_js, |
| 345 | 345 | $this |
| 346 | 346 | ), |
| 347 | - 'footer_js_attributes' => (array)apply_filters( |
|
| 347 | + 'footer_js_attributes' => (array) apply_filters( |
|
| 348 | 348 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
| 349 | 349 | $this->footer_js_attributes, |
| 350 | 350 | $this |
| 351 | 351 | ), |
| 352 | 352 | 'eei18n' => apply_filters( |
| 353 | 353 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
| 354 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
| 354 | + EE_Registry::localize_i18n_js_strings().$this->localizeJsonVars(), |
|
| 355 | 355 | $this |
| 356 | 356 | ), |
| 357 | 357 | 'notices' => EEH_Template::display_template( |
| 358 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
| 358 | + EE_TEMPLATES.'espresso-ajax-notices.template.php', |
|
| 359 | 359 | array(), |
| 360 | 360 | true |
| 361 | 361 | ), |
@@ -375,10 +375,10 @@ discard block |
||
| 375 | 375 | public function localizeJsonVars() |
| 376 | 376 | { |
| 377 | 377 | $JSON = ''; |
| 378 | - foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
| 379 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars ); |
|
| 378 | + foreach ((array) $this->localized_vars as $var_name => $vars) { |
|
| 379 | + $this->localized_vars[$var_name] = $this->encodeJsonVars($vars); |
|
| 380 | 380 | $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
| 381 | - $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
| 381 | + $JSON .= wp_json_encode($this->localized_vars[$var_name]); |
|
| 382 | 382 | $JSON .= '; /* ]]> */'; |
| 383 | 383 | } |
| 384 | 384 | return $JSON; |
@@ -390,17 +390,17 @@ discard block |
||
| 390 | 390 | * @param bool|int|float|string|array $var |
| 391 | 391 | * @return array |
| 392 | 392 | */ |
| 393 | - public function encodeJsonVars( $var ) |
|
| 393 | + public function encodeJsonVars($var) |
|
| 394 | 394 | { |
| 395 | - if ( is_array( $var ) ) { |
|
| 395 | + if (is_array($var)) { |
|
| 396 | 396 | $localized_vars = array(); |
| 397 | - foreach ( (array)$var as $key => $value ) { |
|
| 398 | - $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
| 397 | + foreach ((array) $var as $key => $value) { |
|
| 398 | + $localized_vars[$key] = $this->encodeJsonVars($value); |
|
| 399 | 399 | } |
| 400 | 400 | return $localized_vars; |
| 401 | 401 | } |
| 402 | - if ( is_scalar( $var ) ) { |
|
| 403 | - return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
| 402 | + if (is_scalar($var)) { |
|
| 403 | + return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
| 404 | 404 | } |
| 405 | 405 | return null; |
| 406 | 406 | } |
@@ -21,4209 +21,4209 @@ |
||
| 21 | 21 | { |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - //set in _init_page_props() |
|
| 25 | - public $page_slug; |
|
| 24 | + //set in _init_page_props() |
|
| 25 | + public $page_slug; |
|
| 26 | 26 | |
| 27 | - public $page_label; |
|
| 27 | + public $page_label; |
|
| 28 | 28 | |
| 29 | - public $page_folder; |
|
| 29 | + public $page_folder; |
|
| 30 | 30 | |
| 31 | - //set in define_page_props() |
|
| 32 | - protected $_admin_base_url; |
|
| 31 | + //set in define_page_props() |
|
| 32 | + protected $_admin_base_url; |
|
| 33 | 33 | |
| 34 | - protected $_admin_base_path; |
|
| 34 | + protected $_admin_base_path; |
|
| 35 | 35 | |
| 36 | - protected $_admin_page_title; |
|
| 36 | + protected $_admin_page_title; |
|
| 37 | 37 | |
| 38 | - protected $_labels; |
|
| 38 | + protected $_labels; |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - //set early within EE_Admin_Init |
|
| 42 | - protected $_wp_page_slug; |
|
| 41 | + //set early within EE_Admin_Init |
|
| 42 | + protected $_wp_page_slug; |
|
| 43 | 43 | |
| 44 | - //navtabs |
|
| 45 | - protected $_nav_tabs; |
|
| 44 | + //navtabs |
|
| 45 | + protected $_nav_tabs; |
|
| 46 | 46 | |
| 47 | - protected $_default_nav_tab_name; |
|
| 47 | + protected $_default_nav_tab_name; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var array $_help_tour |
|
| 51 | - */ |
|
| 52 | - protected $_help_tour = array(); |
|
| 49 | + /** |
|
| 50 | + * @var array $_help_tour |
|
| 51 | + */ |
|
| 52 | + protected $_help_tour = array(); |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - //template variables (used by templates) |
|
| 56 | - protected $_template_path; |
|
| 55 | + //template variables (used by templates) |
|
| 56 | + protected $_template_path; |
|
| 57 | 57 | |
| 58 | - protected $_column_template_path; |
|
| 58 | + protected $_column_template_path; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var array $_template_args |
|
| 62 | - */ |
|
| 63 | - protected $_template_args = array(); |
|
| 60 | + /** |
|
| 61 | + * @var array $_template_args |
|
| 62 | + */ |
|
| 63 | + protected $_template_args = array(); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * this will hold the list table object for a given view. |
|
| 67 | - * |
|
| 68 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 69 | - */ |
|
| 70 | - protected $_list_table_object; |
|
| 65 | + /** |
|
| 66 | + * this will hold the list table object for a given view. |
|
| 67 | + * |
|
| 68 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 69 | + */ |
|
| 70 | + protected $_list_table_object; |
|
| 71 | 71 | |
| 72 | - //bools |
|
| 73 | - protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 72 | + //bools |
|
| 73 | + protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 74 | 74 | |
| 75 | - protected $_routing; |
|
| 75 | + protected $_routing; |
|
| 76 | 76 | |
| 77 | - //list table args |
|
| 78 | - protected $_view; |
|
| 77 | + //list table args |
|
| 78 | + protected $_view; |
|
| 79 | 79 | |
| 80 | - protected $_views; |
|
| 80 | + protected $_views; |
|
| 81 | 81 | |
| 82 | 82 | |
| 83 | - //action => method pairs used for routing incoming requests |
|
| 84 | - protected $_page_routes; |
|
| 83 | + //action => method pairs used for routing incoming requests |
|
| 84 | + protected $_page_routes; |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @var array $_page_config |
|
| 88 | - */ |
|
| 89 | - protected $_page_config; |
|
| 86 | + /** |
|
| 87 | + * @var array $_page_config |
|
| 88 | + */ |
|
| 89 | + protected $_page_config; |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * the current page route and route config |
|
| 93 | - * |
|
| 94 | - * @var string $_route |
|
| 95 | - */ |
|
| 96 | - protected $_route; |
|
| 91 | + /** |
|
| 92 | + * the current page route and route config |
|
| 93 | + * |
|
| 94 | + * @var string $_route |
|
| 95 | + */ |
|
| 96 | + protected $_route; |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @var string $_cpt_route |
|
| 100 | - */ |
|
| 101 | - protected $_cpt_route; |
|
| 98 | + /** |
|
| 99 | + * @var string $_cpt_route |
|
| 100 | + */ |
|
| 101 | + protected $_cpt_route; |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * @var array $_route_config |
|
| 105 | - */ |
|
| 106 | - protected $_route_config; |
|
| 103 | + /** |
|
| 104 | + * @var array $_route_config |
|
| 105 | + */ |
|
| 106 | + protected $_route_config; |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 110 | - * actions. |
|
| 111 | - * |
|
| 112 | - * @since 4.6.x |
|
| 113 | - * @var array. |
|
| 114 | - */ |
|
| 115 | - protected $_default_route_query_args; |
|
| 116 | - |
|
| 117 | - //set via request page and action args. |
|
| 118 | - protected $_current_page; |
|
| 108 | + /** |
|
| 109 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 110 | + * actions. |
|
| 111 | + * |
|
| 112 | + * @since 4.6.x |
|
| 113 | + * @var array. |
|
| 114 | + */ |
|
| 115 | + protected $_default_route_query_args; |
|
| 116 | + |
|
| 117 | + //set via request page and action args. |
|
| 118 | + protected $_current_page; |
|
| 119 | 119 | |
| 120 | - protected $_current_view; |
|
| 120 | + protected $_current_view; |
|
| 121 | 121 | |
| 122 | - protected $_current_page_view_url; |
|
| 122 | + protected $_current_page_view_url; |
|
| 123 | 123 | |
| 124 | - //sanitized request action (and nonce) |
|
| 124 | + //sanitized request action (and nonce) |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * @var string $_req_action |
|
| 128 | - */ |
|
| 129 | - protected $_req_action; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @var string $_req_nonce |
|
| 133 | - */ |
|
| 134 | - protected $_req_nonce; |
|
| 135 | - |
|
| 136 | - //search related |
|
| 137 | - protected $_search_btn_label; |
|
| 138 | - |
|
| 139 | - protected $_search_box_callback; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * WP Current Screen object |
|
| 143 | - * |
|
| 144 | - * @var WP_Screen |
|
| 145 | - */ |
|
| 146 | - protected $_current_screen; |
|
| 147 | - |
|
| 148 | - //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 149 | - protected $_hook_obj; |
|
| 150 | - |
|
| 151 | - //for holding incoming request data |
|
| 152 | - protected $_req_data; |
|
| 153 | - |
|
| 154 | - // yes / no array for admin form fields |
|
| 155 | - protected $_yes_no_values = array(); |
|
| 156 | - |
|
| 157 | - //some default things shared by all child classes |
|
| 158 | - protected $_default_espresso_metaboxes; |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * EE_Registry Object |
|
| 162 | - * |
|
| 163 | - * @var EE_Registry |
|
| 164 | - */ |
|
| 165 | - protected $EE = null; |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 171 | - * |
|
| 172 | - * @var boolean |
|
| 173 | - */ |
|
| 174 | - protected $_is_caf = false; |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @Constructor |
|
| 180 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 181 | - * @throws EE_Error |
|
| 182 | - * @throws InvalidArgumentException |
|
| 183 | - * @throws ReflectionException |
|
| 184 | - * @throws InvalidDataTypeException |
|
| 185 | - * @throws InvalidInterfaceException |
|
| 186 | - */ |
|
| 187 | - public function __construct($routing = true) |
|
| 188 | - { |
|
| 189 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 190 | - $this->_is_caf = true; |
|
| 191 | - } |
|
| 192 | - $this->_yes_no_values = array( |
|
| 193 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 194 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 195 | - ); |
|
| 196 | - //set the _req_data property. |
|
| 197 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 198 | - //routing enabled? |
|
| 199 | - $this->_routing = $routing; |
|
| 200 | - //set initial page props (child method) |
|
| 201 | - $this->_init_page_props(); |
|
| 202 | - //set global defaults |
|
| 203 | - $this->_set_defaults(); |
|
| 204 | - //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 205 | - $this->_global_ajax_hooks(); |
|
| 206 | - $this->_ajax_hooks(); |
|
| 207 | - //other_page_hooks have to be early too. |
|
| 208 | - $this->_do_other_page_hooks(); |
|
| 209 | - //This just allows us to have extending classes do something specific |
|
| 210 | - // before the parent constructor runs _page_setup(). |
|
| 211 | - if (method_exists($this, '_before_page_setup')) { |
|
| 212 | - $this->_before_page_setup(); |
|
| 213 | - } |
|
| 214 | - //set up page dependencies |
|
| 215 | - $this->_page_setup(); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * _init_page_props |
|
| 222 | - * Child classes use to set at least the following properties: |
|
| 223 | - * $page_slug. |
|
| 224 | - * $page_label. |
|
| 225 | - * |
|
| 226 | - * @abstract |
|
| 227 | - * @return void |
|
| 228 | - */ |
|
| 229 | - abstract protected function _init_page_props(); |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * _ajax_hooks |
|
| 235 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 236 | - * Note: within the ajax callback methods. |
|
| 237 | - * |
|
| 238 | - * @abstract |
|
| 239 | - * @return void |
|
| 240 | - */ |
|
| 241 | - abstract protected function _ajax_hooks(); |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * _define_page_props |
|
| 247 | - * child classes define page properties in here. Must include at least: |
|
| 248 | - * $_admin_base_url = base_url for all admin pages |
|
| 249 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 250 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 251 | - * array( |
|
| 252 | - * 'buttons' => array( |
|
| 253 | - * 'add' => esc_html__('label for add new button'), |
|
| 254 | - * 'edit' => esc_html__('label for edit button'), |
|
| 255 | - * 'delete' => esc_html__('label for delete button') |
|
| 256 | - * ) |
|
| 257 | - * ) |
|
| 258 | - * |
|
| 259 | - * @abstract |
|
| 260 | - * @return void |
|
| 261 | - */ |
|
| 262 | - abstract protected function _define_page_props(); |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * _set_page_routes |
|
| 268 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 269 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 270 | - * have a 'default' route. Here's the format |
|
| 271 | - * $this->_page_routes = array( |
|
| 272 | - * 'default' => array( |
|
| 273 | - * 'func' => '_default_method_handling_route', |
|
| 274 | - * 'args' => array('array','of','args'), |
|
| 275 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 276 | - * ajax request, backend processing) |
|
| 277 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 278 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 279 | - * headers sent route. |
|
| 280 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 281 | - * this route. |
|
| 282 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 283 | - * checks). |
|
| 284 | - * ), |
|
| 285 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 286 | - * handling method. |
|
| 287 | - * ) |
|
| 288 | - * ) |
|
| 289 | - * |
|
| 290 | - * @abstract |
|
| 291 | - * @return void |
|
| 292 | - */ |
|
| 293 | - abstract protected function _set_page_routes(); |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * _set_page_config |
|
| 299 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 300 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 301 | - * $this->_page_config = array( |
|
| 302 | - * 'default' => array( |
|
| 303 | - * 'labels' => array( |
|
| 304 | - * 'buttons' => array( |
|
| 305 | - * 'add' => esc_html__('label for adding item'), |
|
| 306 | - * 'edit' => esc_html__('label for editing item'), |
|
| 307 | - * 'delete' => esc_html__('label for deleting item') |
|
| 308 | - * ), |
|
| 309 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 310 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 311 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 312 | - * _define_page_props() method |
|
| 313 | - * 'nav' => array( |
|
| 314 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 315 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 316 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 317 | - * 'order' => 10, //required to indicate tab position. |
|
| 318 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 319 | - * displayed then add this parameter. |
|
| 320 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 321 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 322 | - * metaboxes set for eventespresso admin pages. |
|
| 323 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 324 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 325 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 326 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 327 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 328 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 329 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 330 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 331 | - * want to display. |
|
| 332 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 333 | - * 'tab_id' => array( |
|
| 334 | - * 'title' => 'tab_title', |
|
| 335 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 336 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 337 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 338 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 339 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 340 | - * attempt to use the callback which should match the name of a method in the class |
|
| 341 | - * ), |
|
| 342 | - * 'tab2_id' => array( |
|
| 343 | - * 'title' => 'tab2 title', |
|
| 344 | - * 'filename' => 'file_name_2' |
|
| 345 | - * 'callback' => 'callback_method_for_content', |
|
| 346 | - * ), |
|
| 347 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 348 | - * help tab area on an admin page. @link |
|
| 349 | - * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 350 | - * 'help_tour' => array( |
|
| 351 | - * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 352 | - * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 353 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 354 | - * ), |
|
| 355 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 356 | - * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 357 | - * just set |
|
| 358 | - * 'require_nonce' to FALSE |
|
| 359 | - * ) |
|
| 360 | - * ) |
|
| 361 | - * |
|
| 362 | - * @abstract |
|
| 363 | - * @return void |
|
| 364 | - */ |
|
| 365 | - abstract protected function _set_page_config(); |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** end sample help_tour methods **/ |
|
| 372 | - /** |
|
| 373 | - * _add_screen_options |
|
| 374 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 375 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 376 | - * to a particular view. |
|
| 377 | - * |
|
| 378 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 379 | - * see also WP_Screen object documents... |
|
| 380 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 381 | - * @abstract |
|
| 382 | - * @return void |
|
| 383 | - */ |
|
| 384 | - abstract protected function _add_screen_options(); |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * _add_feature_pointers |
|
| 390 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 391 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 392 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 393 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 394 | - * extended) also see: |
|
| 395 | - * |
|
| 396 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 397 | - * @abstract |
|
| 398 | - * @return void |
|
| 399 | - */ |
|
| 400 | - abstract protected function _add_feature_pointers(); |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * load_scripts_styles |
|
| 406 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 407 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 408 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 409 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 410 | - * |
|
| 411 | - * @abstract |
|
| 412 | - * @return void |
|
| 413 | - */ |
|
| 414 | - abstract public function load_scripts_styles(); |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * admin_init |
|
| 420 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 421 | - * all pages/views loaded by child class. |
|
| 422 | - * |
|
| 423 | - * @abstract |
|
| 424 | - * @return void |
|
| 425 | - */ |
|
| 426 | - abstract public function admin_init(); |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * admin_notices |
|
| 432 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 433 | - * all pages/views loaded by child class. |
|
| 434 | - * |
|
| 435 | - * @abstract |
|
| 436 | - * @return void |
|
| 437 | - */ |
|
| 438 | - abstract public function admin_notices(); |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * admin_footer_scripts |
|
| 444 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 445 | - * will apply to all pages/views loaded by child class. |
|
| 446 | - * |
|
| 447 | - * @return void |
|
| 448 | - */ |
|
| 449 | - abstract public function admin_footer_scripts(); |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * admin_footer |
|
| 455 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 456 | - * apply to all pages/views loaded by child class. |
|
| 457 | - * |
|
| 458 | - * @return void |
|
| 459 | - */ |
|
| 460 | - public function admin_footer() |
|
| 461 | - { |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * _global_ajax_hooks |
|
| 468 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 469 | - * Note: within the ajax callback methods. |
|
| 470 | - * |
|
| 471 | - * @abstract |
|
| 472 | - * @return void |
|
| 473 | - */ |
|
| 474 | - protected function _global_ajax_hooks() |
|
| 475 | - { |
|
| 476 | - //for lazy loading of metabox content |
|
| 477 | - add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - public function ajax_metabox_content() |
|
| 483 | - { |
|
| 484 | - $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 485 | - $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 486 | - self::cached_rss_display($contentid, $url); |
|
| 487 | - wp_die(); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * _page_setup |
|
| 494 | - * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 495 | - * doesn't match the object. |
|
| 496 | - * |
|
| 497 | - * @final |
|
| 498 | - * @return void |
|
| 499 | - * @throws EE_Error |
|
| 500 | - * @throws InvalidArgumentException |
|
| 501 | - * @throws ReflectionException |
|
| 502 | - * @throws InvalidDataTypeException |
|
| 503 | - * @throws InvalidInterfaceException |
|
| 504 | - */ |
|
| 505 | - final protected function _page_setup() |
|
| 506 | - { |
|
| 507 | - //requires? |
|
| 508 | - //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 509 | - add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 510 | - //next verify if we need to load anything... |
|
| 511 | - $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 512 | - $this->page_folder = strtolower( |
|
| 513 | - str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 514 | - ); |
|
| 515 | - global $ee_menu_slugs; |
|
| 516 | - $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 517 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 518 | - return; |
|
| 519 | - } |
|
| 520 | - // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 521 | - if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 522 | - $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 523 | - ? $this->_req_data['action2'] |
|
| 524 | - : $this->_req_data['action']; |
|
| 525 | - } |
|
| 526 | - // then set blank or -1 action values to 'default' |
|
| 527 | - $this->_req_action = isset($this->_req_data['action']) |
|
| 528 | - && ! empty($this->_req_data['action']) |
|
| 529 | - && $this->_req_data['action'] !== '-1' |
|
| 530 | - ? sanitize_key($this->_req_data['action']) |
|
| 531 | - : 'default'; |
|
| 532 | - // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 533 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 534 | - $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 535 | - ? $this->_req_data['route'] : $this->_req_action; |
|
| 536 | - //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 537 | - $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 538 | - ? $this->_req_data['route'] |
|
| 539 | - : $this->_req_action; |
|
| 540 | - $this->_current_view = $this->_req_action; |
|
| 541 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 542 | - $this->_define_page_props(); |
|
| 543 | - $this->_current_page_view_url = add_query_arg( |
|
| 544 | - array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 545 | - $this->_admin_base_url |
|
| 546 | - ); |
|
| 547 | - //default things |
|
| 548 | - $this->_default_espresso_metaboxes = array( |
|
| 549 | - '_espresso_news_post_box', |
|
| 550 | - '_espresso_links_post_box', |
|
| 551 | - '_espresso_ratings_request', |
|
| 552 | - '_espresso_sponsors_post_box', |
|
| 553 | - ); |
|
| 554 | - //set page configs |
|
| 555 | - $this->_set_page_routes(); |
|
| 556 | - $this->_set_page_config(); |
|
| 557 | - //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 558 | - if (isset($this->_req_data['wp_referer'])) { |
|
| 559 | - $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 560 | - } |
|
| 561 | - //for caffeinated and other extended functionality. |
|
| 562 | - // If there is a _extend_page_config method |
|
| 563 | - // then let's run that to modify the all the various page configuration arrays |
|
| 564 | - if (method_exists($this, '_extend_page_config')) { |
|
| 565 | - $this->_extend_page_config(); |
|
| 566 | - } |
|
| 567 | - //for CPT and other extended functionality. |
|
| 568 | - // If there is an _extend_page_config_for_cpt |
|
| 569 | - // then let's run that to modify all the various page configuration arrays. |
|
| 570 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 571 | - $this->_extend_page_config_for_cpt(); |
|
| 572 | - } |
|
| 573 | - //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 574 | - $this->_page_routes = apply_filters( |
|
| 575 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 576 | - $this->_page_routes, |
|
| 577 | - $this |
|
| 578 | - ); |
|
| 579 | - $this->_page_config = apply_filters( |
|
| 580 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 581 | - $this->_page_config, |
|
| 582 | - $this |
|
| 583 | - ); |
|
| 584 | - //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 585 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 586 | - if ( |
|
| 587 | - method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view) |
|
| 588 | - ) { |
|
| 589 | - add_action( |
|
| 590 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 591 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 592 | - 10, |
|
| 593 | - 2 |
|
| 594 | - ); |
|
| 595 | - } |
|
| 596 | - //next route only if routing enabled |
|
| 597 | - if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 598 | - $this->_verify_routes(); |
|
| 599 | - //next let's just check user_access and kill if no access |
|
| 600 | - $this->check_user_access(); |
|
| 601 | - if ($this->_is_UI_request) { |
|
| 602 | - //admin_init stuff - global, all views for this page class, specific view |
|
| 603 | - add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 604 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 605 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 606 | - } |
|
| 607 | - } else { |
|
| 608 | - //hijack regular WP loading and route admin request immediately |
|
| 609 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 610 | - $this->route_admin_request(); |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 619 | - * |
|
| 620 | - * @return void |
|
| 621 | - * @throws ReflectionException |
|
| 622 | - * @throws EE_Error |
|
| 623 | - */ |
|
| 624 | - private function _do_other_page_hooks() |
|
| 625 | - { |
|
| 626 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 627 | - foreach ($registered_pages as $page) { |
|
| 628 | - //now let's setup the file name and class that should be present |
|
| 629 | - $classname = str_replace('.class.php', '', $page); |
|
| 630 | - //autoloaders should take care of loading file |
|
| 631 | - if (! class_exists($classname)) { |
|
| 632 | - $error_msg[] = sprintf( |
|
| 633 | - esc_html__( |
|
| 634 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 635 | - 'event_espresso' |
|
| 636 | - ), |
|
| 637 | - $page |
|
| 638 | - ); |
|
| 639 | - $error_msg[] = $error_msg[0] |
|
| 640 | - . "\r\n" |
|
| 641 | - . sprintf( |
|
| 642 | - esc_html__( |
|
| 643 | - 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 644 | - 'event_espresso' |
|
| 645 | - ), |
|
| 646 | - $page, |
|
| 647 | - '<br />', |
|
| 648 | - '<strong>' . $classname . '</strong>' |
|
| 649 | - ); |
|
| 650 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 651 | - } |
|
| 652 | - $a = new ReflectionClass($classname); |
|
| 653 | - //notice we are passing the instance of this class to the hook object. |
|
| 654 | - $hookobj[] = $a->newInstance($this); |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - public function load_page_dependencies() |
|
| 661 | - { |
|
| 662 | - try { |
|
| 663 | - $this->_load_page_dependencies(); |
|
| 664 | - } catch (EE_Error $e) { |
|
| 665 | - $e->get_error(); |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * load_page_dependencies |
|
| 673 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 674 | - * |
|
| 675 | - * @return void |
|
| 676 | - * @throws DomainException |
|
| 677 | - * @throws EE_Error |
|
| 678 | - * @throws InvalidArgumentException |
|
| 679 | - * @throws InvalidDataTypeException |
|
| 680 | - * @throws InvalidInterfaceException |
|
| 681 | - * @throws ReflectionException |
|
| 682 | - */ |
|
| 683 | - protected function _load_page_dependencies() |
|
| 684 | - { |
|
| 685 | - //let's set the current_screen and screen options to override what WP set |
|
| 686 | - $this->_current_screen = get_current_screen(); |
|
| 687 | - //load admin_notices - global, page class, and view specific |
|
| 688 | - add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 689 | - add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 690 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 691 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 692 | - } |
|
| 693 | - //load network admin_notices - global, page class, and view specific |
|
| 694 | - add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 695 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 696 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 697 | - } |
|
| 698 | - //this will save any per_page screen options if they are present |
|
| 699 | - $this->_set_per_page_screen_options(); |
|
| 700 | - //setup list table properties |
|
| 701 | - $this->_set_list_table(); |
|
| 702 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 703 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 704 | - $this->_add_registered_meta_boxes(); |
|
| 705 | - $this->_add_screen_columns(); |
|
| 706 | - //add screen options - global, page child class, and view specific |
|
| 707 | - $this->_add_global_screen_options(); |
|
| 708 | - $this->_add_screen_options(); |
|
| 709 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 710 | - if (method_exists($this, $add_screen_options )) { |
|
| 711 | - $this->{$add_screen_options}(); |
|
| 712 | - } |
|
| 713 | - //add help tab(s) and tours- set via page_config and qtips. |
|
| 714 | - $this->_add_help_tour(); |
|
| 715 | - $this->_add_help_tabs(); |
|
| 716 | - $this->_add_qtips(); |
|
| 717 | - //add feature_pointers - global, page child class, and view specific |
|
| 718 | - $this->_add_feature_pointers(); |
|
| 719 | - $this->_add_global_feature_pointers(); |
|
| 720 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 721 | - if (method_exists($this, $add_feature_pointer )) { |
|
| 722 | - $this->{$add_feature_pointer}(); |
|
| 723 | - } |
|
| 724 | - //enqueue scripts/styles - global, page class, and view specific |
|
| 725 | - add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 726 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 727 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 728 | - add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 729 | - } |
|
| 730 | - add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 731 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 732 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 733 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 734 | - // is a good use case. Notice the late priority we're giving these |
|
| 735 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 736 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 737 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 738 | - add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 739 | - } |
|
| 740 | - //admin footer scripts |
|
| 741 | - add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 742 | - add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 743 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 744 | - add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 745 | - } |
|
| 746 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 747 | - //targeted hook |
|
| 748 | - do_action( |
|
| 749 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 750 | - |
|
| 751 | - ); |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * _set_defaults |
|
| 758 | - * This sets some global defaults for class properties. |
|
| 759 | - */ |
|
| 760 | - private function _set_defaults() |
|
| 761 | - { |
|
| 762 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 763 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 764 | - $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 765 | - $this->_page_config = $this->_default_route_query_args = array(); |
|
| 766 | - $this->_default_nav_tab_name = 'overview'; |
|
| 767 | - //init template args |
|
| 768 | - $this->_template_args = array( |
|
| 769 | - 'admin_page_header' => '', |
|
| 770 | - 'admin_page_content' => '', |
|
| 771 | - 'post_body_content' => '', |
|
| 772 | - 'before_list_table' => '', |
|
| 773 | - 'after_list_table' => '', |
|
| 774 | - ); |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * route_admin_request |
|
| 781 | - * |
|
| 782 | - * @see _route_admin_request() |
|
| 783 | - * @return exception|void error |
|
| 784 | - * @throws InvalidArgumentException |
|
| 785 | - * @throws InvalidInterfaceException |
|
| 786 | - * @throws InvalidDataTypeException |
|
| 787 | - * @throws EE_Error |
|
| 788 | - * @throws ReflectionException |
|
| 789 | - */ |
|
| 790 | - public function route_admin_request() |
|
| 791 | - { |
|
| 792 | - try { |
|
| 793 | - $this->_route_admin_request(); |
|
| 794 | - } catch (EE_Error $e) { |
|
| 795 | - $e->get_error(); |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - |
|
| 801 | - public function set_wp_page_slug($wp_page_slug) |
|
| 802 | - { |
|
| 803 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 804 | - //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 805 | - if (is_network_admin()) { |
|
| 806 | - $this->_wp_page_slug .= '-network'; |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - |
|
| 812 | - /** |
|
| 813 | - * _verify_routes |
|
| 814 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 815 | - * we know if we need to drop out. |
|
| 816 | - * |
|
| 817 | - * @return bool |
|
| 818 | - * @throws EE_Error |
|
| 819 | - */ |
|
| 820 | - protected function _verify_routes() |
|
| 821 | - { |
|
| 822 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 823 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 826 | - $this->_route = false; |
|
| 827 | - // check that the page_routes array is not empty |
|
| 828 | - if (empty($this->_page_routes)) { |
|
| 829 | - // user error msg |
|
| 830 | - $error_msg = sprintf( |
|
| 831 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 832 | - $this->_admin_page_title |
|
| 833 | - ); |
|
| 834 | - // developer error msg |
|
| 835 | - $error_msg .= '||' . $error_msg . esc_html__( |
|
| 836 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 837 | - 'event_espresso' |
|
| 838 | - ); |
|
| 839 | - throw new EE_Error($error_msg); |
|
| 840 | - } |
|
| 841 | - // and that the requested page route exists |
|
| 842 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 843 | - $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 844 | - $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 845 | - ? $this->_page_config[$this->_req_action] : array(); |
|
| 846 | - } else { |
|
| 847 | - // user error msg |
|
| 848 | - $error_msg = sprintf( |
|
| 849 | - esc_html__( |
|
| 850 | - 'The requested page route does not exist for the %s admin page.', |
|
| 851 | - 'event_espresso' |
|
| 852 | - ), |
|
| 853 | - $this->_admin_page_title |
|
| 854 | - ); |
|
| 855 | - // developer error msg |
|
| 856 | - $error_msg .= '||' . $error_msg . sprintf( |
|
| 857 | - esc_html__( |
|
| 858 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 859 | - 'event_espresso' |
|
| 860 | - ), |
|
| 861 | - $this->_req_action |
|
| 862 | - ); |
|
| 863 | - throw new EE_Error($error_msg); |
|
| 864 | - } |
|
| 865 | - // and that a default route exists |
|
| 866 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 867 | - // user error msg |
|
| 868 | - $error_msg = sprintf( |
|
| 869 | - esc_html__( |
|
| 870 | - 'A default page route has not been set for the % admin page.', |
|
| 871 | - 'event_espresso' |
|
| 872 | - ), |
|
| 873 | - $this->_admin_page_title |
|
| 874 | - ); |
|
| 875 | - // developer error msg |
|
| 876 | - $error_msg .= '||' . $error_msg . esc_html__( |
|
| 877 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 878 | - 'event_espresso' |
|
| 879 | - ); |
|
| 880 | - throw new EE_Error($error_msg); |
|
| 881 | - } |
|
| 882 | - //first lets' catch if the UI request has EVER been set. |
|
| 883 | - if ($this->_is_UI_request === null) { |
|
| 884 | - //lets set if this is a UI request or not. |
|
| 885 | - $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 886 | - //wait a minute... we might have a noheader in the route array |
|
| 887 | - $this->_is_UI_request = is_array($this->_route) |
|
| 888 | - && isset($this->_route['noheader']) |
|
| 889 | - && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 890 | - } |
|
| 891 | - $this->_set_current_labels(); |
|
| 892 | - return true; |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 899 | - * |
|
| 900 | - * @param string $route the route name we're verifying |
|
| 901 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 902 | - * @throws EE_Error |
|
| 903 | - */ |
|
| 904 | - protected function _verify_route($route) |
|
| 905 | - { |
|
| 906 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 907 | - return true; |
|
| 908 | - } |
|
| 909 | - // user error msg |
|
| 910 | - $error_msg = sprintf( |
|
| 911 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 912 | - $this->_admin_page_title |
|
| 913 | - ); |
|
| 914 | - // developer error msg |
|
| 915 | - $error_msg .= '||' . $error_msg . sprintf( |
|
| 916 | - esc_html__( |
|
| 917 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 918 | - 'event_espresso' |
|
| 919 | - ), |
|
| 920 | - $route |
|
| 921 | - ); |
|
| 922 | - throw new EE_Error($error_msg); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * perform nonce verification |
|
| 929 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 930 | - * using this method (and save retyping!) |
|
| 931 | - * |
|
| 932 | - * @param string $nonce The nonce sent |
|
| 933 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 934 | - * @return void |
|
| 935 | - * @throws EE_Error |
|
| 936 | - */ |
|
| 937 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 938 | - { |
|
| 939 | - // verify nonce against expected value |
|
| 940 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 941 | - // these are not the droids you are looking for !!! |
|
| 942 | - $msg = sprintf( |
|
| 943 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 944 | - '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 945 | - '</a>' |
|
| 946 | - ); |
|
| 947 | - if (WP_DEBUG) { |
|
| 948 | - $msg .= "\n " . sprintf( |
|
| 949 | - esc_html__( |
|
| 950 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 951 | - 'event_espresso' |
|
| 952 | - ), |
|
| 953 | - __CLASS__ |
|
| 954 | - ); |
|
| 955 | - } |
|
| 956 | - if (! defined('DOING_AJAX')) { |
|
| 957 | - wp_die($msg); |
|
| 958 | - } else { |
|
| 959 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 960 | - $this->_return_json(); |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - |
|
| 967 | - /** |
|
| 968 | - * _route_admin_request() |
|
| 969 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 970 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 971 | - * in the page routes and then will try to load the corresponding method. |
|
| 972 | - * |
|
| 973 | - * @return void |
|
| 974 | - * @throws EE_Error |
|
| 975 | - * @throws InvalidArgumentException |
|
| 976 | - * @throws InvalidDataTypeException |
|
| 977 | - * @throws InvalidInterfaceException |
|
| 978 | - * @throws ReflectionException |
|
| 979 | - */ |
|
| 980 | - protected function _route_admin_request() |
|
| 981 | - { |
|
| 982 | - if (! $this->_is_UI_request) { |
|
| 983 | - $this->_verify_routes(); |
|
| 984 | - } |
|
| 985 | - $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 986 | - ? $this->_route_config['require_nonce'] |
|
| 987 | - : true; |
|
| 988 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 989 | - // set nonce from post data |
|
| 990 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 991 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 992 | - : ''; |
|
| 993 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 994 | - } |
|
| 995 | - //set the nav_tabs array but ONLY if this is UI_request |
|
| 996 | - if ($this->_is_UI_request) { |
|
| 997 | - $this->_set_nav_tabs(); |
|
| 998 | - } |
|
| 999 | - // grab callback function |
|
| 1000 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 1001 | - // check if callback has args |
|
| 1002 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 1003 | - $error_msg = ''; |
|
| 1004 | - // action right before calling route |
|
| 1005 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1006 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1007 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1008 | - } |
|
| 1009 | - // right before calling the route, let's remove _wp_http_referer from the |
|
| 1010 | - // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 1011 | - $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 1012 | - '_wp_http_referer', |
|
| 1013 | - wp_unslash($_SERVER['REQUEST_URI']) |
|
| 1014 | - ); |
|
| 1015 | - if (! empty($func)) { |
|
| 1016 | - if (is_array($func)) { |
|
| 1017 | - list($class, $method) = $func; |
|
| 1018 | - } elseif (strpos($func, '::') !== false) { |
|
| 1019 | - list($class, $method) = explode('::', $func); |
|
| 1020 | - } else { |
|
| 1021 | - $class = $this; |
|
| 1022 | - $method = $func; |
|
| 1023 | - } |
|
| 1024 | - if (! (is_object($class) && $class === $this)) { |
|
| 1025 | - // send along this admin page object for access by addons. |
|
| 1026 | - $args['admin_page_object'] = $this; |
|
| 1027 | - } |
|
| 1028 | - if ( |
|
| 1029 | - //is it a method on a class that doesn't work? |
|
| 1030 | - ( |
|
| 1031 | - ( |
|
| 1032 | - method_exists($class, $method) |
|
| 1033 | - && call_user_func_array(array($class, $method), $args) === false |
|
| 1034 | - ) |
|
| 1035 | - && ( |
|
| 1036 | - //is it a standalone function that doesn't work? |
|
| 1037 | - function_exists($method) |
|
| 1038 | - && call_user_func_array( |
|
| 1039 | - $func, |
|
| 1040 | - array_merge(array('admin_page_object' => $this), $args) |
|
| 1041 | - ) === false |
|
| 1042 | - ) |
|
| 1043 | - ) |
|
| 1044 | - || ( |
|
| 1045 | - //is it neither a class method NOR a standalone function? |
|
| 1046 | - ! method_exists($class, $method) |
|
| 1047 | - && ! function_exists($method) |
|
| 1048 | - ) |
|
| 1049 | - ) { |
|
| 1050 | - // user error msg |
|
| 1051 | - $error_msg = esc_html__( |
|
| 1052 | - 'An error occurred. The requested page route could not be found.', |
|
| 1053 | - 'event_espresso' |
|
| 1054 | - ); |
|
| 1055 | - // developer error msg |
|
| 1056 | - $error_msg .= '||'; |
|
| 1057 | - $error_msg .= sprintf( |
|
| 1058 | - esc_html__( |
|
| 1059 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1060 | - 'event_espresso' |
|
| 1061 | - ), |
|
| 1062 | - $method |
|
| 1063 | - ); |
|
| 1064 | - } |
|
| 1065 | - if (! empty($error_msg)) { |
|
| 1066 | - throw new EE_Error($error_msg); |
|
| 1067 | - } |
|
| 1068 | - } |
|
| 1069 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1070 | - // then we need to reset the routing properties to the new route. |
|
| 1071 | - //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1072 | - if ($this->_is_UI_request === false |
|
| 1073 | - && is_array($this->_route) |
|
| 1074 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1075 | - ) { |
|
| 1076 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1077 | - } |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - |
|
| 1081 | - |
|
| 1082 | - /** |
|
| 1083 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1084 | - * route redirects to a headers route in its route config. |
|
| 1085 | - * |
|
| 1086 | - * @since 4.3.0 |
|
| 1087 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1088 | - * @return void |
|
| 1089 | - * @throws ReflectionException |
|
| 1090 | - * @throws InvalidArgumentException |
|
| 1091 | - * @throws InvalidInterfaceException |
|
| 1092 | - * @throws InvalidDataTypeException |
|
| 1093 | - * @throws EE_Error |
|
| 1094 | - */ |
|
| 1095 | - protected function _reset_routing_properties($new_route) |
|
| 1096 | - { |
|
| 1097 | - $this->_is_UI_request = true; |
|
| 1098 | - //now we set the current route to whatever the headers_sent_route is set at |
|
| 1099 | - $this->_req_data['action'] = $new_route; |
|
| 1100 | - //rerun page setup |
|
| 1101 | - $this->_page_setup(); |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - |
|
| 1106 | - /** |
|
| 1107 | - * _add_query_arg |
|
| 1108 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1109 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1110 | - * |
|
| 1111 | - * @param array $args |
|
| 1112 | - * @param string $url |
|
| 1113 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1114 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1115 | - * Example usage: If the current page is: |
|
| 1116 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1117 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1118 | - * &_wpnonce=5467821 |
|
| 1119 | - * and you call: |
|
| 1120 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1121 | - * array( |
|
| 1122 | - * 'action' => 'resend_something', |
|
| 1123 | - * 'page=>espresso_registrations' |
|
| 1124 | - * ), |
|
| 1125 | - * $some_url, |
|
| 1126 | - * true |
|
| 1127 | - * ); |
|
| 1128 | - * It will produce a url in this structure: |
|
| 1129 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1130 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1131 | - * month_range]=March%202015 |
|
| 1132 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1133 | - * @return string |
|
| 1134 | - */ |
|
| 1135 | - public static function add_query_args_and_nonce( |
|
| 1136 | - $args = array(), |
|
| 1137 | - $url = false, |
|
| 1138 | - $sticky = false, |
|
| 1139 | - $exclude_nonce = false |
|
| 1140 | - ) { |
|
| 1141 | - //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1142 | - if ($sticky) { |
|
| 1143 | - $request = $_REQUEST; |
|
| 1144 | - unset($request['_wp_http_referer']); |
|
| 1145 | - unset($request['wp_referer']); |
|
| 1146 | - foreach ($request as $key => $value) { |
|
| 1147 | - //do not add nonces |
|
| 1148 | - if (strpos($key, 'nonce') !== false) { |
|
| 1149 | - continue; |
|
| 1150 | - } |
|
| 1151 | - $args['wp_referer[' . $key . ']'] = $value; |
|
| 1152 | - } |
|
| 1153 | - } |
|
| 1154 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - |
|
| 1158 | - |
|
| 1159 | - /** |
|
| 1160 | - * This returns a generated link that will load the related help tab. |
|
| 1161 | - * |
|
| 1162 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1163 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1164 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1165 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1166 | - * @return string generated link |
|
| 1167 | - */ |
|
| 1168 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1169 | - { |
|
| 1170 | - return EEH_Template::get_help_tab_link( |
|
| 1171 | - $help_tab_id, |
|
| 1172 | - $this->page_slug, |
|
| 1173 | - $this->_req_action, |
|
| 1174 | - $icon_style, |
|
| 1175 | - $help_text |
|
| 1176 | - ); |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * _add_help_tabs |
|
| 1183 | - * Note child classes define their help tabs within the page_config array. |
|
| 1184 | - * |
|
| 1185 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1186 | - * @return void |
|
| 1187 | - * @throws DomainException |
|
| 1188 | - * @throws EE_Error |
|
| 1189 | - */ |
|
| 1190 | - protected function _add_help_tabs() |
|
| 1191 | - { |
|
| 1192 | - $tour_buttons = ''; |
|
| 1193 | - if (isset($this->_page_config[$this->_req_action])) { |
|
| 1194 | - $config = $this->_page_config[$this->_req_action]; |
|
| 1195 | - //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1196 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1197 | - $tb = array(); |
|
| 1198 | - $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1199 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1200 | - //if this is the end tour then we don't need to setup a button |
|
| 1201 | - if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1202 | - continue; |
|
| 1203 | - } |
|
| 1204 | - $tb[] = '<button id="trigger-tour-' |
|
| 1205 | - . $tour->get_slug() |
|
| 1206 | - . '" class="button-primary trigger-ee-help-tour">' |
|
| 1207 | - . $tour->get_label() |
|
| 1208 | - . '</button>'; |
|
| 1209 | - } |
|
| 1210 | - $tour_buttons .= implode('<br />', $tb); |
|
| 1211 | - $tour_buttons .= '</div></div>'; |
|
| 1212 | - } |
|
| 1213 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1214 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1215 | - //check that the callback given is valid |
|
| 1216 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1217 | - throw new EE_Error( |
|
| 1218 | - sprintf( |
|
| 1219 | - esc_html__( |
|
| 1220 | - 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1221 | - 'event_espresso' |
|
| 1222 | - ), |
|
| 1223 | - $config['help_sidebar'], |
|
| 1224 | - get_class($this) |
|
| 1225 | - ) |
|
| 1226 | - ); |
|
| 1227 | - } |
|
| 1228 | - $content = apply_filters( |
|
| 1229 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1230 | - $this->{$config['help_sidebar']}() |
|
| 1231 | - ); |
|
| 1232 | - $content .= $tour_buttons; //add help tour buttons. |
|
| 1233 | - //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1234 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1235 | - } |
|
| 1236 | - //if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1237 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1238 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1239 | - } |
|
| 1240 | - //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1241 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1242 | - $_ht['id'] = $this->page_slug; |
|
| 1243 | - $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1244 | - $_ht['content'] = '<p>' . esc_html__( |
|
| 1245 | - 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1246 | - 'event_espresso' |
|
| 1247 | - ) . '</p>'; |
|
| 1248 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1249 | - } |
|
| 1250 | - if (! isset($config['help_tabs'])) { |
|
| 1251 | - return; |
|
| 1252 | - } //no help tabs for this route |
|
| 1253 | - foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1254 | - //we're here so there ARE help tabs! |
|
| 1255 | - //make sure we've got what we need |
|
| 1256 | - if (! isset($cfg['title'])) { |
|
| 1257 | - throw new EE_Error( |
|
| 1258 | - esc_html__( |
|
| 1259 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1260 | - 'event_espresso' |
|
| 1261 | - ) |
|
| 1262 | - ); |
|
| 1263 | - } |
|
| 1264 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1265 | - throw new EE_Error( |
|
| 1266 | - esc_html__( |
|
| 1267 | - 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1268 | - 'event_espresso' |
|
| 1269 | - ) |
|
| 1270 | - ); |
|
| 1271 | - } |
|
| 1272 | - //first priority goes to content. |
|
| 1273 | - if (! empty($cfg['content'])) { |
|
| 1274 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1275 | - //second priority goes to filename |
|
| 1276 | - } elseif (! empty($cfg['filename'])) { |
|
| 1277 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1278 | - //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1279 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1280 | - . basename($this->_get_dir()) |
|
| 1281 | - . '/help_tabs/' |
|
| 1282 | - . $cfg['filename'] |
|
| 1283 | - . '.help_tab.php' : $file_path; |
|
| 1284 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1285 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1286 | - EE_Error::add_error( |
|
| 1287 | - sprintf( |
|
| 1288 | - esc_html__( |
|
| 1289 | - 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1290 | - 'event_espresso' |
|
| 1291 | - ), |
|
| 1292 | - $tab_id, |
|
| 1293 | - key($config), |
|
| 1294 | - $file_path |
|
| 1295 | - ), |
|
| 1296 | - __FILE__, |
|
| 1297 | - __FUNCTION__, |
|
| 1298 | - __LINE__ |
|
| 1299 | - ); |
|
| 1300 | - return; |
|
| 1301 | - } |
|
| 1302 | - $template_args['admin_page_obj'] = $this; |
|
| 1303 | - $content = EEH_Template::display_template( |
|
| 1304 | - $file_path, |
|
| 1305 | - $template_args, |
|
| 1306 | - true |
|
| 1307 | - ); |
|
| 1308 | - } else { |
|
| 1309 | - $content = ''; |
|
| 1310 | - } |
|
| 1311 | - //check if callback is valid |
|
| 1312 | - if ( |
|
| 1313 | - empty($content) && ( |
|
| 1314 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1315 | - ) |
|
| 1316 | - ) { |
|
| 1317 | - EE_Error::add_error( |
|
| 1318 | - sprintf( |
|
| 1319 | - esc_html__( |
|
| 1320 | - 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1321 | - 'event_espresso' |
|
| 1322 | - ), |
|
| 1323 | - $cfg['title'] |
|
| 1324 | - ), |
|
| 1325 | - __FILE__, |
|
| 1326 | - __FUNCTION__, |
|
| 1327 | - __LINE__ |
|
| 1328 | - ); |
|
| 1329 | - return; |
|
| 1330 | - } |
|
| 1331 | - //setup config array for help tab method |
|
| 1332 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1333 | - $_ht = array( |
|
| 1334 | - 'id' => $id, |
|
| 1335 | - 'title' => $cfg['title'], |
|
| 1336 | - 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1337 | - 'content' => $content, |
|
| 1338 | - ); |
|
| 1339 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1340 | - } |
|
| 1341 | - } |
|
| 1342 | - } |
|
| 1343 | - |
|
| 1344 | - |
|
| 1345 | - |
|
| 1346 | - /** |
|
| 1347 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1348 | - * an array with properties for setting up usage of the joyride plugin |
|
| 1349 | - * |
|
| 1350 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1351 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1352 | - * _set_page_config() comments |
|
| 1353 | - * @return void |
|
| 1354 | - * @throws EE_Error |
|
| 1355 | - * @throws InvalidArgumentException |
|
| 1356 | - * @throws InvalidDataTypeException |
|
| 1357 | - * @throws InvalidInterfaceException |
|
| 1358 | - */ |
|
| 1359 | - protected function _add_help_tour() |
|
| 1360 | - { |
|
| 1361 | - $tours = array(); |
|
| 1362 | - $this->_help_tour = array(); |
|
| 1363 | - //exit early if help tours are turned off globally |
|
| 1364 | - if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1365 | - || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1366 | - ) { |
|
| 1367 | - return; |
|
| 1368 | - } |
|
| 1369 | - //loop through _page_config to find any help_tour defined |
|
| 1370 | - foreach ($this->_page_config as $route => $config) { |
|
| 1371 | - //we're only going to set things up for this route |
|
| 1372 | - if ($route !== $this->_req_action) { |
|
| 1373 | - continue; |
|
| 1374 | - } |
|
| 1375 | - if (isset($config['help_tour'])) { |
|
| 1376 | - foreach ($config['help_tour'] as $tour) { |
|
| 1377 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1378 | - // let's see if we can get that file... |
|
| 1379 | - // if not its possible this is a decaf route not set in caffeinated |
|
| 1380 | - // so lets try and get the caffeinated equivalent |
|
| 1381 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1382 | - . basename($this->_get_dir()) |
|
| 1383 | - . '/help_tours/' |
|
| 1384 | - . $tour |
|
| 1385 | - . '.class.php' : $file_path; |
|
| 1386 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1387 | - if (! is_readable($file_path)) { |
|
| 1388 | - EE_Error::add_error( |
|
| 1389 | - sprintf( |
|
| 1390 | - esc_html__( |
|
| 1391 | - 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1392 | - 'event_espresso' |
|
| 1393 | - ), |
|
| 1394 | - $file_path, |
|
| 1395 | - $tour |
|
| 1396 | - ), |
|
| 1397 | - __FILE__, |
|
| 1398 | - __FUNCTION__, |
|
| 1399 | - __LINE__ |
|
| 1400 | - ); |
|
| 1401 | - return; |
|
| 1402 | - } |
|
| 1403 | - require_once $file_path; |
|
| 1404 | - if (! class_exists($tour)) { |
|
| 1405 | - $error_msg[] = sprintf( |
|
| 1406 | - esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1407 | - $tour |
|
| 1408 | - ); |
|
| 1409 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
| 1410 | - esc_html__( |
|
| 1411 | - 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1412 | - 'event_espresso' |
|
| 1413 | - ), |
|
| 1414 | - $tour, |
|
| 1415 | - '<br />', |
|
| 1416 | - $tour, |
|
| 1417 | - $this->_req_action, |
|
| 1418 | - get_class($this) |
|
| 1419 | - ); |
|
| 1420 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 1421 | - } |
|
| 1422 | - $tour_obj = new $tour($this->_is_caf); |
|
| 1423 | - $tours[] = $tour_obj; |
|
| 1424 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1425 | - } |
|
| 1426 | - //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1427 | - $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1428 | - $tours[] = $end_stop_tour; |
|
| 1429 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1430 | - } |
|
| 1431 | - } |
|
| 1432 | - if (! empty($tours)) { |
|
| 1433 | - $this->_help_tour['tours'] = $tours; |
|
| 1434 | - } |
|
| 1435 | - // that's it! Now that the $_help_tours property is set (or not) |
|
| 1436 | - // the scripts and html should be taken care of automatically. |
|
| 1437 | - } |
|
| 1438 | - |
|
| 1439 | - |
|
| 1440 | - |
|
| 1441 | - /** |
|
| 1442 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1443 | - * |
|
| 1444 | - * @return void |
|
| 1445 | - */ |
|
| 1446 | - protected function _add_qtips() |
|
| 1447 | - { |
|
| 1448 | - if (isset($this->_route_config['qtips'])) { |
|
| 1449 | - $qtips = (array)$this->_route_config['qtips']; |
|
| 1450 | - //load qtip loader |
|
| 1451 | - $path = array( |
|
| 1452 | - $this->_get_dir() . '/qtips/', |
|
| 1453 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1454 | - ); |
|
| 1455 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1456 | - } |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - |
|
| 1460 | - |
|
| 1461 | - /** |
|
| 1462 | - * _set_nav_tabs |
|
| 1463 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1464 | - * wish to add additional tabs or modify accordingly. |
|
| 1465 | - * |
|
| 1466 | - * @return void |
|
| 1467 | - * @throws InvalidArgumentException |
|
| 1468 | - * @throws InvalidInterfaceException |
|
| 1469 | - * @throws InvalidDataTypeException |
|
| 1470 | - */ |
|
| 1471 | - protected function _set_nav_tabs() |
|
| 1472 | - { |
|
| 1473 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1474 | - $i = 0; |
|
| 1475 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1476 | - if ( |
|
| 1477 | - ! is_array($config) |
|
| 1478 | - || ( |
|
| 1479 | - is_array($config) |
|
| 1480 | - && ( |
|
| 1481 | - (isset($config['nav']) && ! $config['nav']) |
|
| 1482 | - || ! isset($config['nav']) |
|
| 1483 | - ) |
|
| 1484 | - ) |
|
| 1485 | - ) { |
|
| 1486 | - continue; |
|
| 1487 | - } |
|
| 1488 | - //no nav tab for this config |
|
| 1489 | - //check for persistent flag |
|
| 1490 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1491 | - // nav tab is only to appear when route requested. |
|
| 1492 | - continue; |
|
| 1493 | - } |
|
| 1494 | - if (! $this->check_user_access($slug, true)) { |
|
| 1495 | - // no nav tab because current user does not have access. |
|
| 1496 | - continue; |
|
| 1497 | - } |
|
| 1498 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1499 | - $this->_nav_tabs[$slug] = array( |
|
| 1500 | - 'url' => isset($config['nav']['url']) |
|
| 1501 | - ? $config['nav']['url'] |
|
| 1502 | - : self::add_query_args_and_nonce( |
|
| 1503 | - array('action' => $slug), |
|
| 1504 | - $this->_admin_base_url |
|
| 1505 | - ), |
|
| 1506 | - 'link_text' => isset($config['nav']['label']) |
|
| 1507 | - ? $config['nav']['label'] |
|
| 1508 | - : ucwords( |
|
| 1509 | - str_replace('_', ' ', $slug) |
|
| 1510 | - ), |
|
| 1511 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1512 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1513 | - ); |
|
| 1514 | - $i++; |
|
| 1515 | - } |
|
| 1516 | - //if $this->_nav_tabs is empty then lets set the default |
|
| 1517 | - if (empty($this->_nav_tabs)) { |
|
| 1518 | - $this->_nav_tabs[$this->_default_nav_tab_name] = array( |
|
| 1519 | - 'url' => $this->_admin_base_url, |
|
| 1520 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1521 | - 'css_class' => 'nav-tab-active', |
|
| 1522 | - 'order' => 10, |
|
| 1523 | - ); |
|
| 1524 | - } |
|
| 1525 | - //now let's sort the tabs according to order |
|
| 1526 | - usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - |
|
| 1530 | - |
|
| 1531 | - /** |
|
| 1532 | - * _set_current_labels |
|
| 1533 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1534 | - * property array |
|
| 1535 | - * |
|
| 1536 | - * @return void |
|
| 1537 | - */ |
|
| 1538 | - private function _set_current_labels() |
|
| 1539 | - { |
|
| 1540 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1541 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1542 | - if (is_array($text)) { |
|
| 1543 | - foreach ($text as $sublabel => $subtext) { |
|
| 1544 | - $this->_labels[$label][$sublabel] = $subtext; |
|
| 1545 | - } |
|
| 1546 | - } else { |
|
| 1547 | - $this->_labels[$label] = $text; |
|
| 1548 | - } |
|
| 1549 | - } |
|
| 1550 | - } |
|
| 1551 | - } |
|
| 1552 | - |
|
| 1553 | - |
|
| 1554 | - |
|
| 1555 | - /** |
|
| 1556 | - * verifies user access for this admin page |
|
| 1557 | - * |
|
| 1558 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1559 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1560 | - * return false if verify fail. |
|
| 1561 | - * @return bool |
|
| 1562 | - * @throws InvalidArgumentException |
|
| 1563 | - * @throws InvalidDataTypeException |
|
| 1564 | - * @throws InvalidInterfaceException |
|
| 1565 | - */ |
|
| 1566 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1567 | - { |
|
| 1568 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1569 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1570 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1571 | - && is_array( |
|
| 1572 | - $this->_page_routes[$route_to_check] |
|
| 1573 | - ) |
|
| 1574 | - && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1575 | - ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1576 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1577 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1578 | - : $this->_route['capability']; |
|
| 1579 | - } else { |
|
| 1580 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1581 | - } |
|
| 1582 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1583 | - if ( |
|
| 1584 | - ! defined('DOING_AJAX') |
|
| 1585 | - && ( |
|
| 1586 | - ! function_exists('is_admin') |
|
| 1587 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1588 | - $capability, |
|
| 1589 | - $this->page_slug |
|
| 1590 | - . '_' |
|
| 1591 | - . $route_to_check, |
|
| 1592 | - $id |
|
| 1593 | - ) |
|
| 1594 | - ) |
|
| 1595 | - ) { |
|
| 1596 | - if ($verify_only) { |
|
| 1597 | - return false; |
|
| 1598 | - } |
|
| 1599 | - if (is_user_logged_in()) { |
|
| 1600 | - wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1601 | - } else { |
|
| 1602 | - return false; |
|
| 1603 | - } |
|
| 1604 | - } |
|
| 1605 | - return true; |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - |
|
| 1609 | - |
|
| 1610 | - /** |
|
| 1611 | - * admin_init_global |
|
| 1612 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1613 | - * This method executes for ALL EE Admin pages. |
|
| 1614 | - * |
|
| 1615 | - * @return void |
|
| 1616 | - */ |
|
| 1617 | - public function admin_init_global() |
|
| 1618 | - { |
|
| 1619 | - } |
|
| 1620 | - |
|
| 1621 | - |
|
| 1622 | - |
|
| 1623 | - /** |
|
| 1624 | - * wp_loaded_global |
|
| 1625 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1626 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1627 | - * |
|
| 1628 | - * @return void |
|
| 1629 | - */ |
|
| 1630 | - public function wp_loaded() |
|
| 1631 | - { |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - |
|
| 1635 | - |
|
| 1636 | - /** |
|
| 1637 | - * admin_notices |
|
| 1638 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1639 | - * ALL EE_Admin pages. |
|
| 1640 | - * |
|
| 1641 | - * @return void |
|
| 1642 | - */ |
|
| 1643 | - public function admin_notices_global() |
|
| 1644 | - { |
|
| 1645 | - $this->_display_no_javascript_warning(); |
|
| 1646 | - $this->_display_espresso_notices(); |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - |
|
| 1650 | - |
|
| 1651 | - public function network_admin_notices_global() |
|
| 1652 | - { |
|
| 1653 | - $this->_display_no_javascript_warning(); |
|
| 1654 | - $this->_display_espresso_notices(); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - |
|
| 1658 | - |
|
| 1659 | - /** |
|
| 1660 | - * admin_footer_scripts_global |
|
| 1661 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1662 | - * will apply on ALL EE_Admin pages. |
|
| 1663 | - * |
|
| 1664 | - * @return void |
|
| 1665 | - */ |
|
| 1666 | - public function admin_footer_scripts_global() |
|
| 1667 | - { |
|
| 1668 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1669 | - $this->_add_admin_page_overlay(); |
|
| 1670 | - //if metaboxes are present we need to add the nonce field |
|
| 1671 | - if ( |
|
| 1672 | - isset($this->_route_config['metaboxes']) |
|
| 1673 | - || isset($this->_route_config['list_table']) |
|
| 1674 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1675 | - ) { |
|
| 1676 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1677 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1678 | - } |
|
| 1679 | - } |
|
| 1680 | - |
|
| 1681 | - |
|
| 1682 | - |
|
| 1683 | - /** |
|
| 1684 | - * admin_footer_global |
|
| 1685 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1686 | - * ALL EE_Admin Pages. |
|
| 1687 | - * |
|
| 1688 | - * @return void |
|
| 1689 | - * @throws EE_Error |
|
| 1690 | - */ |
|
| 1691 | - public function admin_footer_global() |
|
| 1692 | - { |
|
| 1693 | - //dialog container for dialog helper |
|
| 1694 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1695 | - $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1696 | - $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1697 | - $d_cont .= '</div>'; |
|
| 1698 | - echo $d_cont; |
|
| 1699 | - //help tour stuff? |
|
| 1700 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1701 | - echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1702 | - } |
|
| 1703 | - //current set timezone for timezone js |
|
| 1704 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - |
|
| 1708 | - |
|
| 1709 | - /** |
|
| 1710 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1711 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1712 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1713 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1714 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1715 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1716 | - * for the |
|
| 1717 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1718 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1719 | - * 'help_trigger_id' => array( |
|
| 1720 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1721 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1722 | - * ) |
|
| 1723 | - * ); |
|
| 1724 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1725 | - * |
|
| 1726 | - * @param array $help_array |
|
| 1727 | - * @param bool $display |
|
| 1728 | - * @return string content |
|
| 1729 | - * @throws DomainException |
|
| 1730 | - * @throws EE_Error |
|
| 1731 | - */ |
|
| 1732 | - protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1733 | - { |
|
| 1734 | - $content = ''; |
|
| 1735 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1736 | - //loop through the array and setup content |
|
| 1737 | - foreach ($help_array as $trigger => $help) { |
|
| 1738 | - //make sure the array is setup properly |
|
| 1739 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1740 | - throw new EE_Error( |
|
| 1741 | - esc_html__( |
|
| 1742 | - 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1743 | - 'event_espresso' |
|
| 1744 | - ) |
|
| 1745 | - ); |
|
| 1746 | - } |
|
| 1747 | - //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1748 | - $template_args = array( |
|
| 1749 | - 'help_popup_id' => $trigger, |
|
| 1750 | - 'help_popup_title' => $help['title'], |
|
| 1751 | - 'help_popup_content' => $help['content'], |
|
| 1752 | - ); |
|
| 1753 | - $content .= EEH_Template::display_template( |
|
| 1754 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1755 | - $template_args, |
|
| 1756 | - true |
|
| 1757 | - ); |
|
| 1758 | - } |
|
| 1759 | - if ($display) { |
|
| 1760 | - echo $content; |
|
| 1761 | - return ''; |
|
| 1762 | - } |
|
| 1763 | - return $content; |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - |
|
| 1767 | - |
|
| 1768 | - /** |
|
| 1769 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1770 | - * |
|
| 1771 | - * @return array properly formatted array for help popup content |
|
| 1772 | - * @throws EE_Error |
|
| 1773 | - */ |
|
| 1774 | - private function _get_help_content() |
|
| 1775 | - { |
|
| 1776 | - //what is the method we're looking for? |
|
| 1777 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1778 | - //if method doesn't exist let's get out. |
|
| 1779 | - if (! method_exists($this, $method_name)) { |
|
| 1780 | - return array(); |
|
| 1781 | - } |
|
| 1782 | - //k we're good to go let's retrieve the help array |
|
| 1783 | - $help_array = call_user_func(array($this, $method_name)); |
|
| 1784 | - //make sure we've got an array! |
|
| 1785 | - if (! is_array($help_array)) { |
|
| 1786 | - throw new EE_Error( |
|
| 1787 | - esc_html__( |
|
| 1788 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1789 | - 'event_espresso' |
|
| 1790 | - ) |
|
| 1791 | - ); |
|
| 1792 | - } |
|
| 1793 | - return $help_array; |
|
| 1794 | - } |
|
| 1795 | - |
|
| 1796 | - |
|
| 1797 | - |
|
| 1798 | - /** |
|
| 1799 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1800 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1801 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1802 | - * |
|
| 1803 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1804 | - * @param boolean $display if false then we return the trigger string |
|
| 1805 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1806 | - * @return string |
|
| 1807 | - * @throws DomainException |
|
| 1808 | - * @throws EE_Error |
|
| 1809 | - */ |
|
| 1810 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1811 | - { |
|
| 1812 | - if (defined('DOING_AJAX')) { |
|
| 1813 | - return ''; |
|
| 1814 | - } |
|
| 1815 | - //let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1816 | - $help_array = $this->_get_help_content(); |
|
| 1817 | - $help_content = ''; |
|
| 1818 | - if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1819 | - $help_array[$trigger_id] = array( |
|
| 1820 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1821 | - 'content' => esc_html__( |
|
| 1822 | - 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1823 | - 'event_espresso' |
|
| 1824 | - ), |
|
| 1825 | - ); |
|
| 1826 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1827 | - } |
|
| 1828 | - //let's setup the trigger |
|
| 1829 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1830 | - . $dimensions[0] |
|
| 1831 | - . '&width=' |
|
| 1832 | - . $dimensions[1] |
|
| 1833 | - . '&inlineId=' |
|
| 1834 | - . $trigger_id |
|
| 1835 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1836 | - $content .= $help_content; |
|
| 1837 | - if ($display) { |
|
| 1838 | - echo $content; |
|
| 1839 | - return ''; |
|
| 1840 | - } |
|
| 1841 | - return $content; |
|
| 1842 | - } |
|
| 1843 | - |
|
| 1844 | - |
|
| 1845 | - |
|
| 1846 | - /** |
|
| 1847 | - * _add_global_screen_options |
|
| 1848 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1849 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1850 | - * |
|
| 1851 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1852 | - * see also WP_Screen object documents... |
|
| 1853 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1854 | - * @abstract |
|
| 1855 | - * @return void |
|
| 1856 | - */ |
|
| 1857 | - private function _add_global_screen_options() |
|
| 1858 | - { |
|
| 1859 | - } |
|
| 1860 | - |
|
| 1861 | - |
|
| 1862 | - |
|
| 1863 | - /** |
|
| 1864 | - * _add_global_feature_pointers |
|
| 1865 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1866 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1867 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1868 | - * |
|
| 1869 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1870 | - * extended) also see: |
|
| 1871 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1872 | - * @abstract |
|
| 1873 | - * @return void |
|
| 1874 | - */ |
|
| 1875 | - private function _add_global_feature_pointers() |
|
| 1876 | - { |
|
| 1877 | - } |
|
| 1878 | - |
|
| 1879 | - |
|
| 1880 | - |
|
| 1881 | - /** |
|
| 1882 | - * load_global_scripts_styles |
|
| 1883 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1884 | - * |
|
| 1885 | - * @return void |
|
| 1886 | - * @throws EE_Error |
|
| 1887 | - */ |
|
| 1888 | - public function load_global_scripts_styles() |
|
| 1889 | - { |
|
| 1890 | - /** STYLES **/ |
|
| 1891 | - // add debugging styles |
|
| 1892 | - if (WP_DEBUG) { |
|
| 1893 | - add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1894 | - } |
|
| 1895 | - // register all styles |
|
| 1896 | - wp_register_style( |
|
| 1897 | - 'espresso-ui-theme', |
|
| 1898 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1899 | - array(), |
|
| 1900 | - EVENT_ESPRESSO_VERSION |
|
| 1901 | - ); |
|
| 1902 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1903 | - //helpers styles |
|
| 1904 | - wp_register_style( |
|
| 1905 | - 'ee-text-links', |
|
| 1906 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1907 | - array(), |
|
| 1908 | - EVENT_ESPRESSO_VERSION |
|
| 1909 | - ); |
|
| 1910 | - /** SCRIPTS **/ |
|
| 1911 | - //register all scripts |
|
| 1912 | - wp_register_script( |
|
| 1913 | - 'ee-dialog', |
|
| 1914 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1915 | - array('jquery', 'jquery-ui-draggable'), |
|
| 1916 | - EVENT_ESPRESSO_VERSION, |
|
| 1917 | - true |
|
| 1918 | - ); |
|
| 1919 | - wp_register_script( |
|
| 1920 | - 'ee_admin_js', |
|
| 1921 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1922 | - array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
| 1923 | - EVENT_ESPRESSO_VERSION, |
|
| 1924 | - true |
|
| 1925 | - ); |
|
| 1926 | - wp_register_script( |
|
| 1927 | - 'jquery-ui-timepicker-addon', |
|
| 1928 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1929 | - array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
| 1930 | - EVENT_ESPRESSO_VERSION, |
|
| 1931 | - true |
|
| 1932 | - ); |
|
| 1933 | - add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1934 | - //script for sorting tables |
|
| 1935 | - wp_register_script( |
|
| 1936 | - 'espresso_ajax_table_sorting', |
|
| 1937 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1938 | - array('ee_admin_js', 'jquery-ui-sortable'), |
|
| 1939 | - EVENT_ESPRESSO_VERSION, |
|
| 1940 | - true |
|
| 1941 | - ); |
|
| 1942 | - //script for parsing uri's |
|
| 1943 | - wp_register_script( |
|
| 1944 | - 'ee-parse-uri', |
|
| 1945 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1946 | - array(), |
|
| 1947 | - EVENT_ESPRESSO_VERSION, |
|
| 1948 | - true |
|
| 1949 | - ); |
|
| 1950 | - //and parsing associative serialized form elements |
|
| 1951 | - wp_register_script( |
|
| 1952 | - 'ee-serialize-full-array', |
|
| 1953 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1954 | - array('jquery'), |
|
| 1955 | - EVENT_ESPRESSO_VERSION, |
|
| 1956 | - true |
|
| 1957 | - ); |
|
| 1958 | - //helpers scripts |
|
| 1959 | - wp_register_script( |
|
| 1960 | - 'ee-text-links', |
|
| 1961 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1962 | - array('jquery'), |
|
| 1963 | - EVENT_ESPRESSO_VERSION, |
|
| 1964 | - true |
|
| 1965 | - ); |
|
| 1966 | - wp_register_script( |
|
| 1967 | - 'ee-moment-core', |
|
| 1968 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1969 | - array(), |
|
| 1970 | - EVENT_ESPRESSO_VERSION, |
|
| 1971 | - true |
|
| 1972 | - ); |
|
| 1973 | - wp_register_script( |
|
| 1974 | - 'ee-moment', |
|
| 1975 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1976 | - array('ee-moment-core'), |
|
| 1977 | - EVENT_ESPRESSO_VERSION, |
|
| 1978 | - true |
|
| 1979 | - ); |
|
| 1980 | - wp_register_script( |
|
| 1981 | - 'ee-datepicker', |
|
| 1982 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1983 | - array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
| 1984 | - EVENT_ESPRESSO_VERSION, |
|
| 1985 | - true |
|
| 1986 | - ); |
|
| 1987 | - //google charts |
|
| 1988 | - wp_register_script( |
|
| 1989 | - 'google-charts', |
|
| 1990 | - 'https://www.gstatic.com/charts/loader.js', |
|
| 1991 | - array(), |
|
| 1992 | - EVENT_ESPRESSO_VERSION, |
|
| 1993 | - false |
|
| 1994 | - ); |
|
| 1995 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1996 | - wp_enqueue_style('ee-admin-css'); |
|
| 1997 | - wp_enqueue_script('ee_admin_js'); |
|
| 1998 | - wp_enqueue_script('ee-accounting'); |
|
| 1999 | - wp_enqueue_script('jquery-validate'); |
|
| 2000 | - //taking care of metaboxes |
|
| 2001 | - if ( |
|
| 2002 | - empty($this->_cpt_route) |
|
| 2003 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 2004 | - ) { |
|
| 2005 | - wp_enqueue_script('dashboard'); |
|
| 2006 | - } |
|
| 2007 | - // LOCALIZED DATA |
|
| 2008 | - //localize script for ajax lazy loading |
|
| 2009 | - $lazy_loader_container_ids = apply_filters( |
|
| 2010 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 2011 | - array('espresso_news_post_box_content') |
|
| 2012 | - ); |
|
| 2013 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 2014 | - /** |
|
| 2015 | - * help tour stuff |
|
| 2016 | - */ |
|
| 2017 | - if (! empty($this->_help_tour)) { |
|
| 2018 | - //register the js for kicking things off |
|
| 2019 | - wp_enqueue_script( |
|
| 2020 | - 'ee-help-tour', |
|
| 2021 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2022 | - array('jquery-joyride'), |
|
| 2023 | - EVENT_ESPRESSO_VERSION, |
|
| 2024 | - true |
|
| 2025 | - ); |
|
| 2026 | - $tours = array(); |
|
| 2027 | - //setup tours for the js tour object |
|
| 2028 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 2029 | - if ($tour instanceof EE_Help_Tour) { |
|
| 2030 | - $tours[] = array( |
|
| 2031 | - 'id' => $tour->get_slug(), |
|
| 2032 | - 'options' => $tour->get_options(), |
|
| 2033 | - ); |
|
| 2034 | - } |
|
| 2035 | - } |
|
| 2036 | - wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2037 | - //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2038 | - } |
|
| 2039 | - } |
|
| 2040 | - |
|
| 2041 | - |
|
| 2042 | - |
|
| 2043 | - /** |
|
| 2044 | - * admin_footer_scripts_eei18n_js_strings |
|
| 2045 | - * |
|
| 2046 | - * @return void |
|
| 2047 | - */ |
|
| 2048 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 2049 | - { |
|
| 2050 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2051 | - EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 2052 | - 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 2053 | - 'event_espresso' |
|
| 2054 | - ); |
|
| 2055 | - EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2056 | - EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2057 | - EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2058 | - EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2059 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2060 | - EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2061 | - EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2062 | - EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2063 | - EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2064 | - EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2065 | - EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2066 | - EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2067 | - EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2068 | - EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2069 | - EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2070 | - EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2071 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2072 | - EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2073 | - EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2074 | - EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2075 | - EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2076 | - EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2077 | - EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2078 | - EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2079 | - EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2080 | - EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2081 | - EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2082 | - EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2083 | - EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2084 | - EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2085 | - EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2086 | - EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2087 | - EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2088 | - EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2089 | - EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2090 | - EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2091 | - EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2092 | - EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2093 | - } |
|
| 2094 | - |
|
| 2095 | - |
|
| 2096 | - |
|
| 2097 | - /** |
|
| 2098 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2099 | - * |
|
| 2100 | - * @return void |
|
| 2101 | - */ |
|
| 2102 | - public function add_xdebug_style() |
|
| 2103 | - { |
|
| 2104 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2105 | - } |
|
| 2106 | - |
|
| 2107 | - |
|
| 2108 | - /************************/ |
|
| 2109 | - /** LIST TABLE METHODS **/ |
|
| 2110 | - /************************/ |
|
| 2111 | - /** |
|
| 2112 | - * this sets up the list table if the current view requires it. |
|
| 2113 | - * |
|
| 2114 | - * @return void |
|
| 2115 | - * @throws EE_Error |
|
| 2116 | - */ |
|
| 2117 | - protected function _set_list_table() |
|
| 2118 | - { |
|
| 2119 | - //first is this a list_table view? |
|
| 2120 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2121 | - return; |
|
| 2122 | - } //not a list_table view so get out. |
|
| 2123 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2124 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2125 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2126 | - //user error msg |
|
| 2127 | - $error_msg = esc_html__( |
|
| 2128 | - 'An error occurred. The requested list table views could not be found.', |
|
| 2129 | - 'event_espresso' |
|
| 2130 | - ); |
|
| 2131 | - //developer error msg |
|
| 2132 | - $error_msg .= '||' . sprintf( |
|
| 2133 | - esc_html__( |
|
| 2134 | - 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2135 | - 'event_espresso' |
|
| 2136 | - ), |
|
| 2137 | - $this->_req_action, |
|
| 2138 | - $list_table_view |
|
| 2139 | - ); |
|
| 2140 | - throw new EE_Error($error_msg); |
|
| 2141 | - } |
|
| 2142 | - //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2143 | - $this->_views = apply_filters( |
|
| 2144 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2145 | - $this->_views |
|
| 2146 | - ); |
|
| 2147 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2148 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2149 | - $this->_set_list_table_view(); |
|
| 2150 | - $this->_set_list_table_object(); |
|
| 2151 | - } |
|
| 2152 | - |
|
| 2153 | - |
|
| 2154 | - |
|
| 2155 | - /** |
|
| 2156 | - * set current view for List Table |
|
| 2157 | - * |
|
| 2158 | - * @return void |
|
| 2159 | - */ |
|
| 2160 | - protected function _set_list_table_view() |
|
| 2161 | - { |
|
| 2162 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2163 | - // looking at active items or dumpster diving ? |
|
| 2164 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2165 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2166 | - } else { |
|
| 2167 | - $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2168 | - } |
|
| 2169 | - } |
|
| 2170 | - |
|
| 2171 | - |
|
| 2172 | - /** |
|
| 2173 | - * _set_list_table_object |
|
| 2174 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2175 | - * |
|
| 2176 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2177 | - * @throws \InvalidArgumentException |
|
| 2178 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2179 | - * @throws EE_Error |
|
| 2180 | - * @throws InvalidInterfaceException |
|
| 2181 | - */ |
|
| 2182 | - protected function _set_list_table_object() |
|
| 2183 | - { |
|
| 2184 | - if (isset($this->_route_config['list_table'])) { |
|
| 2185 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2186 | - throw new EE_Error( |
|
| 2187 | - sprintf( |
|
| 2188 | - esc_html__( |
|
| 2189 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2190 | - 'event_espresso' |
|
| 2191 | - ), |
|
| 2192 | - $this->_route_config['list_table'], |
|
| 2193 | - get_class($this) |
|
| 2194 | - ) |
|
| 2195 | - ); |
|
| 2196 | - } |
|
| 2197 | - $this->_list_table_object = LoaderFactory::getLoader()->getShared( |
|
| 2198 | - $this->_route_config['list_table'], |
|
| 2199 | - array($this) |
|
| 2200 | - ); |
|
| 2201 | - } |
|
| 2202 | - } |
|
| 2203 | - |
|
| 2204 | - |
|
| 2205 | - |
|
| 2206 | - /** |
|
| 2207 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2208 | - * |
|
| 2209 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2210 | - * urls. The array should be indexed by the view it is being |
|
| 2211 | - * added to. |
|
| 2212 | - * @return array |
|
| 2213 | - */ |
|
| 2214 | - public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2215 | - { |
|
| 2216 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2217 | - if (empty($this->_views)) { |
|
| 2218 | - $this->_views = array(); |
|
| 2219 | - } |
|
| 2220 | - // cycle thru views |
|
| 2221 | - foreach ($this->_views as $key => $view) { |
|
| 2222 | - $query_args = array(); |
|
| 2223 | - // check for current view |
|
| 2224 | - $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2225 | - $query_args['action'] = $this->_req_action; |
|
| 2226 | - $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2227 | - $query_args['status'] = $view['slug']; |
|
| 2228 | - //merge any other arguments sent in. |
|
| 2229 | - if (isset($extra_query_args[$view['slug']])) { |
|
| 2230 | - $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2231 | - } |
|
| 2232 | - $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2233 | - } |
|
| 2234 | - return $this->_views; |
|
| 2235 | - } |
|
| 2236 | - |
|
| 2237 | - |
|
| 2238 | - |
|
| 2239 | - /** |
|
| 2240 | - * _entries_per_page_dropdown |
|
| 2241 | - * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2242 | - * |
|
| 2243 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2244 | - * WP does it. |
|
| 2245 | - * @param int $max_entries total number of rows in the table |
|
| 2246 | - * @return string |
|
| 2247 | - */ |
|
| 2248 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2249 | - { |
|
| 2250 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2251 | - $values = array(10, 25, 50, 100); |
|
| 2252 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2253 | - if ($max_entries) { |
|
| 2254 | - $values[] = $max_entries; |
|
| 2255 | - sort($values); |
|
| 2256 | - } |
|
| 2257 | - $entries_per_page_dropdown = ' |
|
| 126 | + /** |
|
| 127 | + * @var string $_req_action |
|
| 128 | + */ |
|
| 129 | + protected $_req_action; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @var string $_req_nonce |
|
| 133 | + */ |
|
| 134 | + protected $_req_nonce; |
|
| 135 | + |
|
| 136 | + //search related |
|
| 137 | + protected $_search_btn_label; |
|
| 138 | + |
|
| 139 | + protected $_search_box_callback; |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * WP Current Screen object |
|
| 143 | + * |
|
| 144 | + * @var WP_Screen |
|
| 145 | + */ |
|
| 146 | + protected $_current_screen; |
|
| 147 | + |
|
| 148 | + //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 149 | + protected $_hook_obj; |
|
| 150 | + |
|
| 151 | + //for holding incoming request data |
|
| 152 | + protected $_req_data; |
|
| 153 | + |
|
| 154 | + // yes / no array for admin form fields |
|
| 155 | + protected $_yes_no_values = array(); |
|
| 156 | + |
|
| 157 | + //some default things shared by all child classes |
|
| 158 | + protected $_default_espresso_metaboxes; |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * EE_Registry Object |
|
| 162 | + * |
|
| 163 | + * @var EE_Registry |
|
| 164 | + */ |
|
| 165 | + protected $EE = null; |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 171 | + * |
|
| 172 | + * @var boolean |
|
| 173 | + */ |
|
| 174 | + protected $_is_caf = false; |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @Constructor |
|
| 180 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 181 | + * @throws EE_Error |
|
| 182 | + * @throws InvalidArgumentException |
|
| 183 | + * @throws ReflectionException |
|
| 184 | + * @throws InvalidDataTypeException |
|
| 185 | + * @throws InvalidInterfaceException |
|
| 186 | + */ |
|
| 187 | + public function __construct($routing = true) |
|
| 188 | + { |
|
| 189 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 190 | + $this->_is_caf = true; |
|
| 191 | + } |
|
| 192 | + $this->_yes_no_values = array( |
|
| 193 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 194 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 195 | + ); |
|
| 196 | + //set the _req_data property. |
|
| 197 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 198 | + //routing enabled? |
|
| 199 | + $this->_routing = $routing; |
|
| 200 | + //set initial page props (child method) |
|
| 201 | + $this->_init_page_props(); |
|
| 202 | + //set global defaults |
|
| 203 | + $this->_set_defaults(); |
|
| 204 | + //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 205 | + $this->_global_ajax_hooks(); |
|
| 206 | + $this->_ajax_hooks(); |
|
| 207 | + //other_page_hooks have to be early too. |
|
| 208 | + $this->_do_other_page_hooks(); |
|
| 209 | + //This just allows us to have extending classes do something specific |
|
| 210 | + // before the parent constructor runs _page_setup(). |
|
| 211 | + if (method_exists($this, '_before_page_setup')) { |
|
| 212 | + $this->_before_page_setup(); |
|
| 213 | + } |
|
| 214 | + //set up page dependencies |
|
| 215 | + $this->_page_setup(); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * _init_page_props |
|
| 222 | + * Child classes use to set at least the following properties: |
|
| 223 | + * $page_slug. |
|
| 224 | + * $page_label. |
|
| 225 | + * |
|
| 226 | + * @abstract |
|
| 227 | + * @return void |
|
| 228 | + */ |
|
| 229 | + abstract protected function _init_page_props(); |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * _ajax_hooks |
|
| 235 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 236 | + * Note: within the ajax callback methods. |
|
| 237 | + * |
|
| 238 | + * @abstract |
|
| 239 | + * @return void |
|
| 240 | + */ |
|
| 241 | + abstract protected function _ajax_hooks(); |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * _define_page_props |
|
| 247 | + * child classes define page properties in here. Must include at least: |
|
| 248 | + * $_admin_base_url = base_url for all admin pages |
|
| 249 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 250 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 251 | + * array( |
|
| 252 | + * 'buttons' => array( |
|
| 253 | + * 'add' => esc_html__('label for add new button'), |
|
| 254 | + * 'edit' => esc_html__('label for edit button'), |
|
| 255 | + * 'delete' => esc_html__('label for delete button') |
|
| 256 | + * ) |
|
| 257 | + * ) |
|
| 258 | + * |
|
| 259 | + * @abstract |
|
| 260 | + * @return void |
|
| 261 | + */ |
|
| 262 | + abstract protected function _define_page_props(); |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * _set_page_routes |
|
| 268 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 269 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 270 | + * have a 'default' route. Here's the format |
|
| 271 | + * $this->_page_routes = array( |
|
| 272 | + * 'default' => array( |
|
| 273 | + * 'func' => '_default_method_handling_route', |
|
| 274 | + * 'args' => array('array','of','args'), |
|
| 275 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 276 | + * ajax request, backend processing) |
|
| 277 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 278 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 279 | + * headers sent route. |
|
| 280 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 281 | + * this route. |
|
| 282 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 283 | + * checks). |
|
| 284 | + * ), |
|
| 285 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 286 | + * handling method. |
|
| 287 | + * ) |
|
| 288 | + * ) |
|
| 289 | + * |
|
| 290 | + * @abstract |
|
| 291 | + * @return void |
|
| 292 | + */ |
|
| 293 | + abstract protected function _set_page_routes(); |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * _set_page_config |
|
| 299 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 300 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 301 | + * $this->_page_config = array( |
|
| 302 | + * 'default' => array( |
|
| 303 | + * 'labels' => array( |
|
| 304 | + * 'buttons' => array( |
|
| 305 | + * 'add' => esc_html__('label for adding item'), |
|
| 306 | + * 'edit' => esc_html__('label for editing item'), |
|
| 307 | + * 'delete' => esc_html__('label for deleting item') |
|
| 308 | + * ), |
|
| 309 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 310 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 311 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 312 | + * _define_page_props() method |
|
| 313 | + * 'nav' => array( |
|
| 314 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 315 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 316 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 317 | + * 'order' => 10, //required to indicate tab position. |
|
| 318 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 319 | + * displayed then add this parameter. |
|
| 320 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 321 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 322 | + * metaboxes set for eventespresso admin pages. |
|
| 323 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 324 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 325 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 326 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 327 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 328 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 329 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 330 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 331 | + * want to display. |
|
| 332 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 333 | + * 'tab_id' => array( |
|
| 334 | + * 'title' => 'tab_title', |
|
| 335 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 336 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 337 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 338 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 339 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 340 | + * attempt to use the callback which should match the name of a method in the class |
|
| 341 | + * ), |
|
| 342 | + * 'tab2_id' => array( |
|
| 343 | + * 'title' => 'tab2 title', |
|
| 344 | + * 'filename' => 'file_name_2' |
|
| 345 | + * 'callback' => 'callback_method_for_content', |
|
| 346 | + * ), |
|
| 347 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 348 | + * help tab area on an admin page. @link |
|
| 349 | + * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 350 | + * 'help_tour' => array( |
|
| 351 | + * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 352 | + * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 353 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 354 | + * ), |
|
| 355 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 356 | + * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 357 | + * just set |
|
| 358 | + * 'require_nonce' to FALSE |
|
| 359 | + * ) |
|
| 360 | + * ) |
|
| 361 | + * |
|
| 362 | + * @abstract |
|
| 363 | + * @return void |
|
| 364 | + */ |
|
| 365 | + abstract protected function _set_page_config(); |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** end sample help_tour methods **/ |
|
| 372 | + /** |
|
| 373 | + * _add_screen_options |
|
| 374 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 375 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 376 | + * to a particular view. |
|
| 377 | + * |
|
| 378 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 379 | + * see also WP_Screen object documents... |
|
| 380 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 381 | + * @abstract |
|
| 382 | + * @return void |
|
| 383 | + */ |
|
| 384 | + abstract protected function _add_screen_options(); |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * _add_feature_pointers |
|
| 390 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 391 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 392 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 393 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 394 | + * extended) also see: |
|
| 395 | + * |
|
| 396 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 397 | + * @abstract |
|
| 398 | + * @return void |
|
| 399 | + */ |
|
| 400 | + abstract protected function _add_feature_pointers(); |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * load_scripts_styles |
|
| 406 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 407 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 408 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 409 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 410 | + * |
|
| 411 | + * @abstract |
|
| 412 | + * @return void |
|
| 413 | + */ |
|
| 414 | + abstract public function load_scripts_styles(); |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * admin_init |
|
| 420 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 421 | + * all pages/views loaded by child class. |
|
| 422 | + * |
|
| 423 | + * @abstract |
|
| 424 | + * @return void |
|
| 425 | + */ |
|
| 426 | + abstract public function admin_init(); |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * admin_notices |
|
| 432 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 433 | + * all pages/views loaded by child class. |
|
| 434 | + * |
|
| 435 | + * @abstract |
|
| 436 | + * @return void |
|
| 437 | + */ |
|
| 438 | + abstract public function admin_notices(); |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * admin_footer_scripts |
|
| 444 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 445 | + * will apply to all pages/views loaded by child class. |
|
| 446 | + * |
|
| 447 | + * @return void |
|
| 448 | + */ |
|
| 449 | + abstract public function admin_footer_scripts(); |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * admin_footer |
|
| 455 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 456 | + * apply to all pages/views loaded by child class. |
|
| 457 | + * |
|
| 458 | + * @return void |
|
| 459 | + */ |
|
| 460 | + public function admin_footer() |
|
| 461 | + { |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * _global_ajax_hooks |
|
| 468 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 469 | + * Note: within the ajax callback methods. |
|
| 470 | + * |
|
| 471 | + * @abstract |
|
| 472 | + * @return void |
|
| 473 | + */ |
|
| 474 | + protected function _global_ajax_hooks() |
|
| 475 | + { |
|
| 476 | + //for lazy loading of metabox content |
|
| 477 | + add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + public function ajax_metabox_content() |
|
| 483 | + { |
|
| 484 | + $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 485 | + $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 486 | + self::cached_rss_display($contentid, $url); |
|
| 487 | + wp_die(); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * _page_setup |
|
| 494 | + * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 495 | + * doesn't match the object. |
|
| 496 | + * |
|
| 497 | + * @final |
|
| 498 | + * @return void |
|
| 499 | + * @throws EE_Error |
|
| 500 | + * @throws InvalidArgumentException |
|
| 501 | + * @throws ReflectionException |
|
| 502 | + * @throws InvalidDataTypeException |
|
| 503 | + * @throws InvalidInterfaceException |
|
| 504 | + */ |
|
| 505 | + final protected function _page_setup() |
|
| 506 | + { |
|
| 507 | + //requires? |
|
| 508 | + //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 509 | + add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 510 | + //next verify if we need to load anything... |
|
| 511 | + $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 512 | + $this->page_folder = strtolower( |
|
| 513 | + str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 514 | + ); |
|
| 515 | + global $ee_menu_slugs; |
|
| 516 | + $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 517 | + if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 518 | + return; |
|
| 519 | + } |
|
| 520 | + // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 521 | + if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 522 | + $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 523 | + ? $this->_req_data['action2'] |
|
| 524 | + : $this->_req_data['action']; |
|
| 525 | + } |
|
| 526 | + // then set blank or -1 action values to 'default' |
|
| 527 | + $this->_req_action = isset($this->_req_data['action']) |
|
| 528 | + && ! empty($this->_req_data['action']) |
|
| 529 | + && $this->_req_data['action'] !== '-1' |
|
| 530 | + ? sanitize_key($this->_req_data['action']) |
|
| 531 | + : 'default'; |
|
| 532 | + // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 533 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 534 | + $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 535 | + ? $this->_req_data['route'] : $this->_req_action; |
|
| 536 | + //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 537 | + $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 538 | + ? $this->_req_data['route'] |
|
| 539 | + : $this->_req_action; |
|
| 540 | + $this->_current_view = $this->_req_action; |
|
| 541 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 542 | + $this->_define_page_props(); |
|
| 543 | + $this->_current_page_view_url = add_query_arg( |
|
| 544 | + array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 545 | + $this->_admin_base_url |
|
| 546 | + ); |
|
| 547 | + //default things |
|
| 548 | + $this->_default_espresso_metaboxes = array( |
|
| 549 | + '_espresso_news_post_box', |
|
| 550 | + '_espresso_links_post_box', |
|
| 551 | + '_espresso_ratings_request', |
|
| 552 | + '_espresso_sponsors_post_box', |
|
| 553 | + ); |
|
| 554 | + //set page configs |
|
| 555 | + $this->_set_page_routes(); |
|
| 556 | + $this->_set_page_config(); |
|
| 557 | + //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 558 | + if (isset($this->_req_data['wp_referer'])) { |
|
| 559 | + $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 560 | + } |
|
| 561 | + //for caffeinated and other extended functionality. |
|
| 562 | + // If there is a _extend_page_config method |
|
| 563 | + // then let's run that to modify the all the various page configuration arrays |
|
| 564 | + if (method_exists($this, '_extend_page_config')) { |
|
| 565 | + $this->_extend_page_config(); |
|
| 566 | + } |
|
| 567 | + //for CPT and other extended functionality. |
|
| 568 | + // If there is an _extend_page_config_for_cpt |
|
| 569 | + // then let's run that to modify all the various page configuration arrays. |
|
| 570 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 571 | + $this->_extend_page_config_for_cpt(); |
|
| 572 | + } |
|
| 573 | + //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 574 | + $this->_page_routes = apply_filters( |
|
| 575 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 576 | + $this->_page_routes, |
|
| 577 | + $this |
|
| 578 | + ); |
|
| 579 | + $this->_page_config = apply_filters( |
|
| 580 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 581 | + $this->_page_config, |
|
| 582 | + $this |
|
| 583 | + ); |
|
| 584 | + //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 585 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 586 | + if ( |
|
| 587 | + method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view) |
|
| 588 | + ) { |
|
| 589 | + add_action( |
|
| 590 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 591 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 592 | + 10, |
|
| 593 | + 2 |
|
| 594 | + ); |
|
| 595 | + } |
|
| 596 | + //next route only if routing enabled |
|
| 597 | + if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 598 | + $this->_verify_routes(); |
|
| 599 | + //next let's just check user_access and kill if no access |
|
| 600 | + $this->check_user_access(); |
|
| 601 | + if ($this->_is_UI_request) { |
|
| 602 | + //admin_init stuff - global, all views for this page class, specific view |
|
| 603 | + add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 604 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 605 | + add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 606 | + } |
|
| 607 | + } else { |
|
| 608 | + //hijack regular WP loading and route admin request immediately |
|
| 609 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 610 | + $this->route_admin_request(); |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 619 | + * |
|
| 620 | + * @return void |
|
| 621 | + * @throws ReflectionException |
|
| 622 | + * @throws EE_Error |
|
| 623 | + */ |
|
| 624 | + private function _do_other_page_hooks() |
|
| 625 | + { |
|
| 626 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 627 | + foreach ($registered_pages as $page) { |
|
| 628 | + //now let's setup the file name and class that should be present |
|
| 629 | + $classname = str_replace('.class.php', '', $page); |
|
| 630 | + //autoloaders should take care of loading file |
|
| 631 | + if (! class_exists($classname)) { |
|
| 632 | + $error_msg[] = sprintf( |
|
| 633 | + esc_html__( |
|
| 634 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 635 | + 'event_espresso' |
|
| 636 | + ), |
|
| 637 | + $page |
|
| 638 | + ); |
|
| 639 | + $error_msg[] = $error_msg[0] |
|
| 640 | + . "\r\n" |
|
| 641 | + . sprintf( |
|
| 642 | + esc_html__( |
|
| 643 | + 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 644 | + 'event_espresso' |
|
| 645 | + ), |
|
| 646 | + $page, |
|
| 647 | + '<br />', |
|
| 648 | + '<strong>' . $classname . '</strong>' |
|
| 649 | + ); |
|
| 650 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 651 | + } |
|
| 652 | + $a = new ReflectionClass($classname); |
|
| 653 | + //notice we are passing the instance of this class to the hook object. |
|
| 654 | + $hookobj[] = $a->newInstance($this); |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + public function load_page_dependencies() |
|
| 661 | + { |
|
| 662 | + try { |
|
| 663 | + $this->_load_page_dependencies(); |
|
| 664 | + } catch (EE_Error $e) { |
|
| 665 | + $e->get_error(); |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * load_page_dependencies |
|
| 673 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 674 | + * |
|
| 675 | + * @return void |
|
| 676 | + * @throws DomainException |
|
| 677 | + * @throws EE_Error |
|
| 678 | + * @throws InvalidArgumentException |
|
| 679 | + * @throws InvalidDataTypeException |
|
| 680 | + * @throws InvalidInterfaceException |
|
| 681 | + * @throws ReflectionException |
|
| 682 | + */ |
|
| 683 | + protected function _load_page_dependencies() |
|
| 684 | + { |
|
| 685 | + //let's set the current_screen and screen options to override what WP set |
|
| 686 | + $this->_current_screen = get_current_screen(); |
|
| 687 | + //load admin_notices - global, page class, and view specific |
|
| 688 | + add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 689 | + add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 690 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 691 | + add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 692 | + } |
|
| 693 | + //load network admin_notices - global, page class, and view specific |
|
| 694 | + add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 695 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 696 | + add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 697 | + } |
|
| 698 | + //this will save any per_page screen options if they are present |
|
| 699 | + $this->_set_per_page_screen_options(); |
|
| 700 | + //setup list table properties |
|
| 701 | + $this->_set_list_table(); |
|
| 702 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 703 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 704 | + $this->_add_registered_meta_boxes(); |
|
| 705 | + $this->_add_screen_columns(); |
|
| 706 | + //add screen options - global, page child class, and view specific |
|
| 707 | + $this->_add_global_screen_options(); |
|
| 708 | + $this->_add_screen_options(); |
|
| 709 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 710 | + if (method_exists($this, $add_screen_options )) { |
|
| 711 | + $this->{$add_screen_options}(); |
|
| 712 | + } |
|
| 713 | + //add help tab(s) and tours- set via page_config and qtips. |
|
| 714 | + $this->_add_help_tour(); |
|
| 715 | + $this->_add_help_tabs(); |
|
| 716 | + $this->_add_qtips(); |
|
| 717 | + //add feature_pointers - global, page child class, and view specific |
|
| 718 | + $this->_add_feature_pointers(); |
|
| 719 | + $this->_add_global_feature_pointers(); |
|
| 720 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 721 | + if (method_exists($this, $add_feature_pointer )) { |
|
| 722 | + $this->{$add_feature_pointer}(); |
|
| 723 | + } |
|
| 724 | + //enqueue scripts/styles - global, page class, and view specific |
|
| 725 | + add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 726 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 727 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 728 | + add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 729 | + } |
|
| 730 | + add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 731 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 732 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 733 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 734 | + // is a good use case. Notice the late priority we're giving these |
|
| 735 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 736 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 737 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 738 | + add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 739 | + } |
|
| 740 | + //admin footer scripts |
|
| 741 | + add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 742 | + add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 743 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 744 | + add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 745 | + } |
|
| 746 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 747 | + //targeted hook |
|
| 748 | + do_action( |
|
| 749 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 750 | + |
|
| 751 | + ); |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * _set_defaults |
|
| 758 | + * This sets some global defaults for class properties. |
|
| 759 | + */ |
|
| 760 | + private function _set_defaults() |
|
| 761 | + { |
|
| 762 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 763 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 764 | + $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 765 | + $this->_page_config = $this->_default_route_query_args = array(); |
|
| 766 | + $this->_default_nav_tab_name = 'overview'; |
|
| 767 | + //init template args |
|
| 768 | + $this->_template_args = array( |
|
| 769 | + 'admin_page_header' => '', |
|
| 770 | + 'admin_page_content' => '', |
|
| 771 | + 'post_body_content' => '', |
|
| 772 | + 'before_list_table' => '', |
|
| 773 | + 'after_list_table' => '', |
|
| 774 | + ); |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * route_admin_request |
|
| 781 | + * |
|
| 782 | + * @see _route_admin_request() |
|
| 783 | + * @return exception|void error |
|
| 784 | + * @throws InvalidArgumentException |
|
| 785 | + * @throws InvalidInterfaceException |
|
| 786 | + * @throws InvalidDataTypeException |
|
| 787 | + * @throws EE_Error |
|
| 788 | + * @throws ReflectionException |
|
| 789 | + */ |
|
| 790 | + public function route_admin_request() |
|
| 791 | + { |
|
| 792 | + try { |
|
| 793 | + $this->_route_admin_request(); |
|
| 794 | + } catch (EE_Error $e) { |
|
| 795 | + $e->get_error(); |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + |
|
| 801 | + public function set_wp_page_slug($wp_page_slug) |
|
| 802 | + { |
|
| 803 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 804 | + //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 805 | + if (is_network_admin()) { |
|
| 806 | + $this->_wp_page_slug .= '-network'; |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + |
|
| 812 | + /** |
|
| 813 | + * _verify_routes |
|
| 814 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 815 | + * we know if we need to drop out. |
|
| 816 | + * |
|
| 817 | + * @return bool |
|
| 818 | + * @throws EE_Error |
|
| 819 | + */ |
|
| 820 | + protected function _verify_routes() |
|
| 821 | + { |
|
| 822 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 823 | + if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | + $this->_route = false; |
|
| 827 | + // check that the page_routes array is not empty |
|
| 828 | + if (empty($this->_page_routes)) { |
|
| 829 | + // user error msg |
|
| 830 | + $error_msg = sprintf( |
|
| 831 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 832 | + $this->_admin_page_title |
|
| 833 | + ); |
|
| 834 | + // developer error msg |
|
| 835 | + $error_msg .= '||' . $error_msg . esc_html__( |
|
| 836 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 837 | + 'event_espresso' |
|
| 838 | + ); |
|
| 839 | + throw new EE_Error($error_msg); |
|
| 840 | + } |
|
| 841 | + // and that the requested page route exists |
|
| 842 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 843 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 844 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 845 | + ? $this->_page_config[$this->_req_action] : array(); |
|
| 846 | + } else { |
|
| 847 | + // user error msg |
|
| 848 | + $error_msg = sprintf( |
|
| 849 | + esc_html__( |
|
| 850 | + 'The requested page route does not exist for the %s admin page.', |
|
| 851 | + 'event_espresso' |
|
| 852 | + ), |
|
| 853 | + $this->_admin_page_title |
|
| 854 | + ); |
|
| 855 | + // developer error msg |
|
| 856 | + $error_msg .= '||' . $error_msg . sprintf( |
|
| 857 | + esc_html__( |
|
| 858 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 859 | + 'event_espresso' |
|
| 860 | + ), |
|
| 861 | + $this->_req_action |
|
| 862 | + ); |
|
| 863 | + throw new EE_Error($error_msg); |
|
| 864 | + } |
|
| 865 | + // and that a default route exists |
|
| 866 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 867 | + // user error msg |
|
| 868 | + $error_msg = sprintf( |
|
| 869 | + esc_html__( |
|
| 870 | + 'A default page route has not been set for the % admin page.', |
|
| 871 | + 'event_espresso' |
|
| 872 | + ), |
|
| 873 | + $this->_admin_page_title |
|
| 874 | + ); |
|
| 875 | + // developer error msg |
|
| 876 | + $error_msg .= '||' . $error_msg . esc_html__( |
|
| 877 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 878 | + 'event_espresso' |
|
| 879 | + ); |
|
| 880 | + throw new EE_Error($error_msg); |
|
| 881 | + } |
|
| 882 | + //first lets' catch if the UI request has EVER been set. |
|
| 883 | + if ($this->_is_UI_request === null) { |
|
| 884 | + //lets set if this is a UI request or not. |
|
| 885 | + $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 886 | + //wait a minute... we might have a noheader in the route array |
|
| 887 | + $this->_is_UI_request = is_array($this->_route) |
|
| 888 | + && isset($this->_route['noheader']) |
|
| 889 | + && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 890 | + } |
|
| 891 | + $this->_set_current_labels(); |
|
| 892 | + return true; |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 899 | + * |
|
| 900 | + * @param string $route the route name we're verifying |
|
| 901 | + * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 902 | + * @throws EE_Error |
|
| 903 | + */ |
|
| 904 | + protected function _verify_route($route) |
|
| 905 | + { |
|
| 906 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 907 | + return true; |
|
| 908 | + } |
|
| 909 | + // user error msg |
|
| 910 | + $error_msg = sprintf( |
|
| 911 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 912 | + $this->_admin_page_title |
|
| 913 | + ); |
|
| 914 | + // developer error msg |
|
| 915 | + $error_msg .= '||' . $error_msg . sprintf( |
|
| 916 | + esc_html__( |
|
| 917 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 918 | + 'event_espresso' |
|
| 919 | + ), |
|
| 920 | + $route |
|
| 921 | + ); |
|
| 922 | + throw new EE_Error($error_msg); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * perform nonce verification |
|
| 929 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 930 | + * using this method (and save retyping!) |
|
| 931 | + * |
|
| 932 | + * @param string $nonce The nonce sent |
|
| 933 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 934 | + * @return void |
|
| 935 | + * @throws EE_Error |
|
| 936 | + */ |
|
| 937 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 938 | + { |
|
| 939 | + // verify nonce against expected value |
|
| 940 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 941 | + // these are not the droids you are looking for !!! |
|
| 942 | + $msg = sprintf( |
|
| 943 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 944 | + '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 945 | + '</a>' |
|
| 946 | + ); |
|
| 947 | + if (WP_DEBUG) { |
|
| 948 | + $msg .= "\n " . sprintf( |
|
| 949 | + esc_html__( |
|
| 950 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 951 | + 'event_espresso' |
|
| 952 | + ), |
|
| 953 | + __CLASS__ |
|
| 954 | + ); |
|
| 955 | + } |
|
| 956 | + if (! defined('DOING_AJAX')) { |
|
| 957 | + wp_die($msg); |
|
| 958 | + } else { |
|
| 959 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 960 | + $this->_return_json(); |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + |
|
| 967 | + /** |
|
| 968 | + * _route_admin_request() |
|
| 969 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 970 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 971 | + * in the page routes and then will try to load the corresponding method. |
|
| 972 | + * |
|
| 973 | + * @return void |
|
| 974 | + * @throws EE_Error |
|
| 975 | + * @throws InvalidArgumentException |
|
| 976 | + * @throws InvalidDataTypeException |
|
| 977 | + * @throws InvalidInterfaceException |
|
| 978 | + * @throws ReflectionException |
|
| 979 | + */ |
|
| 980 | + protected function _route_admin_request() |
|
| 981 | + { |
|
| 982 | + if (! $this->_is_UI_request) { |
|
| 983 | + $this->_verify_routes(); |
|
| 984 | + } |
|
| 985 | + $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 986 | + ? $this->_route_config['require_nonce'] |
|
| 987 | + : true; |
|
| 988 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 989 | + // set nonce from post data |
|
| 990 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 991 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 992 | + : ''; |
|
| 993 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 994 | + } |
|
| 995 | + //set the nav_tabs array but ONLY if this is UI_request |
|
| 996 | + if ($this->_is_UI_request) { |
|
| 997 | + $this->_set_nav_tabs(); |
|
| 998 | + } |
|
| 999 | + // grab callback function |
|
| 1000 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 1001 | + // check if callback has args |
|
| 1002 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 1003 | + $error_msg = ''; |
|
| 1004 | + // action right before calling route |
|
| 1005 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1006 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1007 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1008 | + } |
|
| 1009 | + // right before calling the route, let's remove _wp_http_referer from the |
|
| 1010 | + // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 1011 | + $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 1012 | + '_wp_http_referer', |
|
| 1013 | + wp_unslash($_SERVER['REQUEST_URI']) |
|
| 1014 | + ); |
|
| 1015 | + if (! empty($func)) { |
|
| 1016 | + if (is_array($func)) { |
|
| 1017 | + list($class, $method) = $func; |
|
| 1018 | + } elseif (strpos($func, '::') !== false) { |
|
| 1019 | + list($class, $method) = explode('::', $func); |
|
| 1020 | + } else { |
|
| 1021 | + $class = $this; |
|
| 1022 | + $method = $func; |
|
| 1023 | + } |
|
| 1024 | + if (! (is_object($class) && $class === $this)) { |
|
| 1025 | + // send along this admin page object for access by addons. |
|
| 1026 | + $args['admin_page_object'] = $this; |
|
| 1027 | + } |
|
| 1028 | + if ( |
|
| 1029 | + //is it a method on a class that doesn't work? |
|
| 1030 | + ( |
|
| 1031 | + ( |
|
| 1032 | + method_exists($class, $method) |
|
| 1033 | + && call_user_func_array(array($class, $method), $args) === false |
|
| 1034 | + ) |
|
| 1035 | + && ( |
|
| 1036 | + //is it a standalone function that doesn't work? |
|
| 1037 | + function_exists($method) |
|
| 1038 | + && call_user_func_array( |
|
| 1039 | + $func, |
|
| 1040 | + array_merge(array('admin_page_object' => $this), $args) |
|
| 1041 | + ) === false |
|
| 1042 | + ) |
|
| 1043 | + ) |
|
| 1044 | + || ( |
|
| 1045 | + //is it neither a class method NOR a standalone function? |
|
| 1046 | + ! method_exists($class, $method) |
|
| 1047 | + && ! function_exists($method) |
|
| 1048 | + ) |
|
| 1049 | + ) { |
|
| 1050 | + // user error msg |
|
| 1051 | + $error_msg = esc_html__( |
|
| 1052 | + 'An error occurred. The requested page route could not be found.', |
|
| 1053 | + 'event_espresso' |
|
| 1054 | + ); |
|
| 1055 | + // developer error msg |
|
| 1056 | + $error_msg .= '||'; |
|
| 1057 | + $error_msg .= sprintf( |
|
| 1058 | + esc_html__( |
|
| 1059 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1060 | + 'event_espresso' |
|
| 1061 | + ), |
|
| 1062 | + $method |
|
| 1063 | + ); |
|
| 1064 | + } |
|
| 1065 | + if (! empty($error_msg)) { |
|
| 1066 | + throw new EE_Error($error_msg); |
|
| 1067 | + } |
|
| 1068 | + } |
|
| 1069 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1070 | + // then we need to reset the routing properties to the new route. |
|
| 1071 | + //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1072 | + if ($this->_is_UI_request === false |
|
| 1073 | + && is_array($this->_route) |
|
| 1074 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1075 | + ) { |
|
| 1076 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1077 | + } |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + |
|
| 1081 | + |
|
| 1082 | + /** |
|
| 1083 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1084 | + * route redirects to a headers route in its route config. |
|
| 1085 | + * |
|
| 1086 | + * @since 4.3.0 |
|
| 1087 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1088 | + * @return void |
|
| 1089 | + * @throws ReflectionException |
|
| 1090 | + * @throws InvalidArgumentException |
|
| 1091 | + * @throws InvalidInterfaceException |
|
| 1092 | + * @throws InvalidDataTypeException |
|
| 1093 | + * @throws EE_Error |
|
| 1094 | + */ |
|
| 1095 | + protected function _reset_routing_properties($new_route) |
|
| 1096 | + { |
|
| 1097 | + $this->_is_UI_request = true; |
|
| 1098 | + //now we set the current route to whatever the headers_sent_route is set at |
|
| 1099 | + $this->_req_data['action'] = $new_route; |
|
| 1100 | + //rerun page setup |
|
| 1101 | + $this->_page_setup(); |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + |
|
| 1106 | + /** |
|
| 1107 | + * _add_query_arg |
|
| 1108 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1109 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1110 | + * |
|
| 1111 | + * @param array $args |
|
| 1112 | + * @param string $url |
|
| 1113 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1114 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1115 | + * Example usage: If the current page is: |
|
| 1116 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1117 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1118 | + * &_wpnonce=5467821 |
|
| 1119 | + * and you call: |
|
| 1120 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1121 | + * array( |
|
| 1122 | + * 'action' => 'resend_something', |
|
| 1123 | + * 'page=>espresso_registrations' |
|
| 1124 | + * ), |
|
| 1125 | + * $some_url, |
|
| 1126 | + * true |
|
| 1127 | + * ); |
|
| 1128 | + * It will produce a url in this structure: |
|
| 1129 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1130 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1131 | + * month_range]=March%202015 |
|
| 1132 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1133 | + * @return string |
|
| 1134 | + */ |
|
| 1135 | + public static function add_query_args_and_nonce( |
|
| 1136 | + $args = array(), |
|
| 1137 | + $url = false, |
|
| 1138 | + $sticky = false, |
|
| 1139 | + $exclude_nonce = false |
|
| 1140 | + ) { |
|
| 1141 | + //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1142 | + if ($sticky) { |
|
| 1143 | + $request = $_REQUEST; |
|
| 1144 | + unset($request['_wp_http_referer']); |
|
| 1145 | + unset($request['wp_referer']); |
|
| 1146 | + foreach ($request as $key => $value) { |
|
| 1147 | + //do not add nonces |
|
| 1148 | + if (strpos($key, 'nonce') !== false) { |
|
| 1149 | + continue; |
|
| 1150 | + } |
|
| 1151 | + $args['wp_referer[' . $key . ']'] = $value; |
|
| 1152 | + } |
|
| 1153 | + } |
|
| 1154 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + |
|
| 1158 | + |
|
| 1159 | + /** |
|
| 1160 | + * This returns a generated link that will load the related help tab. |
|
| 1161 | + * |
|
| 1162 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1163 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1164 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1165 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1166 | + * @return string generated link |
|
| 1167 | + */ |
|
| 1168 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1169 | + { |
|
| 1170 | + return EEH_Template::get_help_tab_link( |
|
| 1171 | + $help_tab_id, |
|
| 1172 | + $this->page_slug, |
|
| 1173 | + $this->_req_action, |
|
| 1174 | + $icon_style, |
|
| 1175 | + $help_text |
|
| 1176 | + ); |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * _add_help_tabs |
|
| 1183 | + * Note child classes define their help tabs within the page_config array. |
|
| 1184 | + * |
|
| 1185 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1186 | + * @return void |
|
| 1187 | + * @throws DomainException |
|
| 1188 | + * @throws EE_Error |
|
| 1189 | + */ |
|
| 1190 | + protected function _add_help_tabs() |
|
| 1191 | + { |
|
| 1192 | + $tour_buttons = ''; |
|
| 1193 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1194 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1195 | + //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1196 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1197 | + $tb = array(); |
|
| 1198 | + $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1199 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1200 | + //if this is the end tour then we don't need to setup a button |
|
| 1201 | + if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1202 | + continue; |
|
| 1203 | + } |
|
| 1204 | + $tb[] = '<button id="trigger-tour-' |
|
| 1205 | + . $tour->get_slug() |
|
| 1206 | + . '" class="button-primary trigger-ee-help-tour">' |
|
| 1207 | + . $tour->get_label() |
|
| 1208 | + . '</button>'; |
|
| 1209 | + } |
|
| 1210 | + $tour_buttons .= implode('<br />', $tb); |
|
| 1211 | + $tour_buttons .= '</div></div>'; |
|
| 1212 | + } |
|
| 1213 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1214 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1215 | + //check that the callback given is valid |
|
| 1216 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1217 | + throw new EE_Error( |
|
| 1218 | + sprintf( |
|
| 1219 | + esc_html__( |
|
| 1220 | + 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1221 | + 'event_espresso' |
|
| 1222 | + ), |
|
| 1223 | + $config['help_sidebar'], |
|
| 1224 | + get_class($this) |
|
| 1225 | + ) |
|
| 1226 | + ); |
|
| 1227 | + } |
|
| 1228 | + $content = apply_filters( |
|
| 1229 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1230 | + $this->{$config['help_sidebar']}() |
|
| 1231 | + ); |
|
| 1232 | + $content .= $tour_buttons; //add help tour buttons. |
|
| 1233 | + //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1234 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1235 | + } |
|
| 1236 | + //if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1237 | + if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1238 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1239 | + } |
|
| 1240 | + //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1241 | + if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1242 | + $_ht['id'] = $this->page_slug; |
|
| 1243 | + $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1244 | + $_ht['content'] = '<p>' . esc_html__( |
|
| 1245 | + 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1246 | + 'event_espresso' |
|
| 1247 | + ) . '</p>'; |
|
| 1248 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1249 | + } |
|
| 1250 | + if (! isset($config['help_tabs'])) { |
|
| 1251 | + return; |
|
| 1252 | + } //no help tabs for this route |
|
| 1253 | + foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1254 | + //we're here so there ARE help tabs! |
|
| 1255 | + //make sure we've got what we need |
|
| 1256 | + if (! isset($cfg['title'])) { |
|
| 1257 | + throw new EE_Error( |
|
| 1258 | + esc_html__( |
|
| 1259 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1260 | + 'event_espresso' |
|
| 1261 | + ) |
|
| 1262 | + ); |
|
| 1263 | + } |
|
| 1264 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1265 | + throw new EE_Error( |
|
| 1266 | + esc_html__( |
|
| 1267 | + 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1268 | + 'event_espresso' |
|
| 1269 | + ) |
|
| 1270 | + ); |
|
| 1271 | + } |
|
| 1272 | + //first priority goes to content. |
|
| 1273 | + if (! empty($cfg['content'])) { |
|
| 1274 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1275 | + //second priority goes to filename |
|
| 1276 | + } elseif (! empty($cfg['filename'])) { |
|
| 1277 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1278 | + //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1279 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1280 | + . basename($this->_get_dir()) |
|
| 1281 | + . '/help_tabs/' |
|
| 1282 | + . $cfg['filename'] |
|
| 1283 | + . '.help_tab.php' : $file_path; |
|
| 1284 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1285 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1286 | + EE_Error::add_error( |
|
| 1287 | + sprintf( |
|
| 1288 | + esc_html__( |
|
| 1289 | + 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1290 | + 'event_espresso' |
|
| 1291 | + ), |
|
| 1292 | + $tab_id, |
|
| 1293 | + key($config), |
|
| 1294 | + $file_path |
|
| 1295 | + ), |
|
| 1296 | + __FILE__, |
|
| 1297 | + __FUNCTION__, |
|
| 1298 | + __LINE__ |
|
| 1299 | + ); |
|
| 1300 | + return; |
|
| 1301 | + } |
|
| 1302 | + $template_args['admin_page_obj'] = $this; |
|
| 1303 | + $content = EEH_Template::display_template( |
|
| 1304 | + $file_path, |
|
| 1305 | + $template_args, |
|
| 1306 | + true |
|
| 1307 | + ); |
|
| 1308 | + } else { |
|
| 1309 | + $content = ''; |
|
| 1310 | + } |
|
| 1311 | + //check if callback is valid |
|
| 1312 | + if ( |
|
| 1313 | + empty($content) && ( |
|
| 1314 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1315 | + ) |
|
| 1316 | + ) { |
|
| 1317 | + EE_Error::add_error( |
|
| 1318 | + sprintf( |
|
| 1319 | + esc_html__( |
|
| 1320 | + 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1321 | + 'event_espresso' |
|
| 1322 | + ), |
|
| 1323 | + $cfg['title'] |
|
| 1324 | + ), |
|
| 1325 | + __FILE__, |
|
| 1326 | + __FUNCTION__, |
|
| 1327 | + __LINE__ |
|
| 1328 | + ); |
|
| 1329 | + return; |
|
| 1330 | + } |
|
| 1331 | + //setup config array for help tab method |
|
| 1332 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1333 | + $_ht = array( |
|
| 1334 | + 'id' => $id, |
|
| 1335 | + 'title' => $cfg['title'], |
|
| 1336 | + 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1337 | + 'content' => $content, |
|
| 1338 | + ); |
|
| 1339 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1340 | + } |
|
| 1341 | + } |
|
| 1342 | + } |
|
| 1343 | + |
|
| 1344 | + |
|
| 1345 | + |
|
| 1346 | + /** |
|
| 1347 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1348 | + * an array with properties for setting up usage of the joyride plugin |
|
| 1349 | + * |
|
| 1350 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1351 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1352 | + * _set_page_config() comments |
|
| 1353 | + * @return void |
|
| 1354 | + * @throws EE_Error |
|
| 1355 | + * @throws InvalidArgumentException |
|
| 1356 | + * @throws InvalidDataTypeException |
|
| 1357 | + * @throws InvalidInterfaceException |
|
| 1358 | + */ |
|
| 1359 | + protected function _add_help_tour() |
|
| 1360 | + { |
|
| 1361 | + $tours = array(); |
|
| 1362 | + $this->_help_tour = array(); |
|
| 1363 | + //exit early if help tours are turned off globally |
|
| 1364 | + if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1365 | + || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1366 | + ) { |
|
| 1367 | + return; |
|
| 1368 | + } |
|
| 1369 | + //loop through _page_config to find any help_tour defined |
|
| 1370 | + foreach ($this->_page_config as $route => $config) { |
|
| 1371 | + //we're only going to set things up for this route |
|
| 1372 | + if ($route !== $this->_req_action) { |
|
| 1373 | + continue; |
|
| 1374 | + } |
|
| 1375 | + if (isset($config['help_tour'])) { |
|
| 1376 | + foreach ($config['help_tour'] as $tour) { |
|
| 1377 | + $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1378 | + // let's see if we can get that file... |
|
| 1379 | + // if not its possible this is a decaf route not set in caffeinated |
|
| 1380 | + // so lets try and get the caffeinated equivalent |
|
| 1381 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1382 | + . basename($this->_get_dir()) |
|
| 1383 | + . '/help_tours/' |
|
| 1384 | + . $tour |
|
| 1385 | + . '.class.php' : $file_path; |
|
| 1386 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1387 | + if (! is_readable($file_path)) { |
|
| 1388 | + EE_Error::add_error( |
|
| 1389 | + sprintf( |
|
| 1390 | + esc_html__( |
|
| 1391 | + 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1392 | + 'event_espresso' |
|
| 1393 | + ), |
|
| 1394 | + $file_path, |
|
| 1395 | + $tour |
|
| 1396 | + ), |
|
| 1397 | + __FILE__, |
|
| 1398 | + __FUNCTION__, |
|
| 1399 | + __LINE__ |
|
| 1400 | + ); |
|
| 1401 | + return; |
|
| 1402 | + } |
|
| 1403 | + require_once $file_path; |
|
| 1404 | + if (! class_exists($tour)) { |
|
| 1405 | + $error_msg[] = sprintf( |
|
| 1406 | + esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1407 | + $tour |
|
| 1408 | + ); |
|
| 1409 | + $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
| 1410 | + esc_html__( |
|
| 1411 | + 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1412 | + 'event_espresso' |
|
| 1413 | + ), |
|
| 1414 | + $tour, |
|
| 1415 | + '<br />', |
|
| 1416 | + $tour, |
|
| 1417 | + $this->_req_action, |
|
| 1418 | + get_class($this) |
|
| 1419 | + ); |
|
| 1420 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 1421 | + } |
|
| 1422 | + $tour_obj = new $tour($this->_is_caf); |
|
| 1423 | + $tours[] = $tour_obj; |
|
| 1424 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1425 | + } |
|
| 1426 | + //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1427 | + $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1428 | + $tours[] = $end_stop_tour; |
|
| 1429 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1430 | + } |
|
| 1431 | + } |
|
| 1432 | + if (! empty($tours)) { |
|
| 1433 | + $this->_help_tour['tours'] = $tours; |
|
| 1434 | + } |
|
| 1435 | + // that's it! Now that the $_help_tours property is set (or not) |
|
| 1436 | + // the scripts and html should be taken care of automatically. |
|
| 1437 | + } |
|
| 1438 | + |
|
| 1439 | + |
|
| 1440 | + |
|
| 1441 | + /** |
|
| 1442 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1443 | + * |
|
| 1444 | + * @return void |
|
| 1445 | + */ |
|
| 1446 | + protected function _add_qtips() |
|
| 1447 | + { |
|
| 1448 | + if (isset($this->_route_config['qtips'])) { |
|
| 1449 | + $qtips = (array)$this->_route_config['qtips']; |
|
| 1450 | + //load qtip loader |
|
| 1451 | + $path = array( |
|
| 1452 | + $this->_get_dir() . '/qtips/', |
|
| 1453 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1454 | + ); |
|
| 1455 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1456 | + } |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + |
|
| 1460 | + |
|
| 1461 | + /** |
|
| 1462 | + * _set_nav_tabs |
|
| 1463 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1464 | + * wish to add additional tabs or modify accordingly. |
|
| 1465 | + * |
|
| 1466 | + * @return void |
|
| 1467 | + * @throws InvalidArgumentException |
|
| 1468 | + * @throws InvalidInterfaceException |
|
| 1469 | + * @throws InvalidDataTypeException |
|
| 1470 | + */ |
|
| 1471 | + protected function _set_nav_tabs() |
|
| 1472 | + { |
|
| 1473 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1474 | + $i = 0; |
|
| 1475 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1476 | + if ( |
|
| 1477 | + ! is_array($config) |
|
| 1478 | + || ( |
|
| 1479 | + is_array($config) |
|
| 1480 | + && ( |
|
| 1481 | + (isset($config['nav']) && ! $config['nav']) |
|
| 1482 | + || ! isset($config['nav']) |
|
| 1483 | + ) |
|
| 1484 | + ) |
|
| 1485 | + ) { |
|
| 1486 | + continue; |
|
| 1487 | + } |
|
| 1488 | + //no nav tab for this config |
|
| 1489 | + //check for persistent flag |
|
| 1490 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1491 | + // nav tab is only to appear when route requested. |
|
| 1492 | + continue; |
|
| 1493 | + } |
|
| 1494 | + if (! $this->check_user_access($slug, true)) { |
|
| 1495 | + // no nav tab because current user does not have access. |
|
| 1496 | + continue; |
|
| 1497 | + } |
|
| 1498 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1499 | + $this->_nav_tabs[$slug] = array( |
|
| 1500 | + 'url' => isset($config['nav']['url']) |
|
| 1501 | + ? $config['nav']['url'] |
|
| 1502 | + : self::add_query_args_and_nonce( |
|
| 1503 | + array('action' => $slug), |
|
| 1504 | + $this->_admin_base_url |
|
| 1505 | + ), |
|
| 1506 | + 'link_text' => isset($config['nav']['label']) |
|
| 1507 | + ? $config['nav']['label'] |
|
| 1508 | + : ucwords( |
|
| 1509 | + str_replace('_', ' ', $slug) |
|
| 1510 | + ), |
|
| 1511 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1512 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1513 | + ); |
|
| 1514 | + $i++; |
|
| 1515 | + } |
|
| 1516 | + //if $this->_nav_tabs is empty then lets set the default |
|
| 1517 | + if (empty($this->_nav_tabs)) { |
|
| 1518 | + $this->_nav_tabs[$this->_default_nav_tab_name] = array( |
|
| 1519 | + 'url' => $this->_admin_base_url, |
|
| 1520 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1521 | + 'css_class' => 'nav-tab-active', |
|
| 1522 | + 'order' => 10, |
|
| 1523 | + ); |
|
| 1524 | + } |
|
| 1525 | + //now let's sort the tabs according to order |
|
| 1526 | + usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + |
|
| 1531 | + /** |
|
| 1532 | + * _set_current_labels |
|
| 1533 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1534 | + * property array |
|
| 1535 | + * |
|
| 1536 | + * @return void |
|
| 1537 | + */ |
|
| 1538 | + private function _set_current_labels() |
|
| 1539 | + { |
|
| 1540 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1541 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1542 | + if (is_array($text)) { |
|
| 1543 | + foreach ($text as $sublabel => $subtext) { |
|
| 1544 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1545 | + } |
|
| 1546 | + } else { |
|
| 1547 | + $this->_labels[$label] = $text; |
|
| 1548 | + } |
|
| 1549 | + } |
|
| 1550 | + } |
|
| 1551 | + } |
|
| 1552 | + |
|
| 1553 | + |
|
| 1554 | + |
|
| 1555 | + /** |
|
| 1556 | + * verifies user access for this admin page |
|
| 1557 | + * |
|
| 1558 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1559 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1560 | + * return false if verify fail. |
|
| 1561 | + * @return bool |
|
| 1562 | + * @throws InvalidArgumentException |
|
| 1563 | + * @throws InvalidDataTypeException |
|
| 1564 | + * @throws InvalidInterfaceException |
|
| 1565 | + */ |
|
| 1566 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1567 | + { |
|
| 1568 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1569 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1570 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1571 | + && is_array( |
|
| 1572 | + $this->_page_routes[$route_to_check] |
|
| 1573 | + ) |
|
| 1574 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1575 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1576 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1577 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1578 | + : $this->_route['capability']; |
|
| 1579 | + } else { |
|
| 1580 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1581 | + } |
|
| 1582 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1583 | + if ( |
|
| 1584 | + ! defined('DOING_AJAX') |
|
| 1585 | + && ( |
|
| 1586 | + ! function_exists('is_admin') |
|
| 1587 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1588 | + $capability, |
|
| 1589 | + $this->page_slug |
|
| 1590 | + . '_' |
|
| 1591 | + . $route_to_check, |
|
| 1592 | + $id |
|
| 1593 | + ) |
|
| 1594 | + ) |
|
| 1595 | + ) { |
|
| 1596 | + if ($verify_only) { |
|
| 1597 | + return false; |
|
| 1598 | + } |
|
| 1599 | + if (is_user_logged_in()) { |
|
| 1600 | + wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1601 | + } else { |
|
| 1602 | + return false; |
|
| 1603 | + } |
|
| 1604 | + } |
|
| 1605 | + return true; |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + |
|
| 1609 | + |
|
| 1610 | + /** |
|
| 1611 | + * admin_init_global |
|
| 1612 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1613 | + * This method executes for ALL EE Admin pages. |
|
| 1614 | + * |
|
| 1615 | + * @return void |
|
| 1616 | + */ |
|
| 1617 | + public function admin_init_global() |
|
| 1618 | + { |
|
| 1619 | + } |
|
| 1620 | + |
|
| 1621 | + |
|
| 1622 | + |
|
| 1623 | + /** |
|
| 1624 | + * wp_loaded_global |
|
| 1625 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1626 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1627 | + * |
|
| 1628 | + * @return void |
|
| 1629 | + */ |
|
| 1630 | + public function wp_loaded() |
|
| 1631 | + { |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + |
|
| 1635 | + |
|
| 1636 | + /** |
|
| 1637 | + * admin_notices |
|
| 1638 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1639 | + * ALL EE_Admin pages. |
|
| 1640 | + * |
|
| 1641 | + * @return void |
|
| 1642 | + */ |
|
| 1643 | + public function admin_notices_global() |
|
| 1644 | + { |
|
| 1645 | + $this->_display_no_javascript_warning(); |
|
| 1646 | + $this->_display_espresso_notices(); |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + |
|
| 1650 | + |
|
| 1651 | + public function network_admin_notices_global() |
|
| 1652 | + { |
|
| 1653 | + $this->_display_no_javascript_warning(); |
|
| 1654 | + $this->_display_espresso_notices(); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + |
|
| 1658 | + |
|
| 1659 | + /** |
|
| 1660 | + * admin_footer_scripts_global |
|
| 1661 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1662 | + * will apply on ALL EE_Admin pages. |
|
| 1663 | + * |
|
| 1664 | + * @return void |
|
| 1665 | + */ |
|
| 1666 | + public function admin_footer_scripts_global() |
|
| 1667 | + { |
|
| 1668 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1669 | + $this->_add_admin_page_overlay(); |
|
| 1670 | + //if metaboxes are present we need to add the nonce field |
|
| 1671 | + if ( |
|
| 1672 | + isset($this->_route_config['metaboxes']) |
|
| 1673 | + || isset($this->_route_config['list_table']) |
|
| 1674 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1675 | + ) { |
|
| 1676 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1677 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1678 | + } |
|
| 1679 | + } |
|
| 1680 | + |
|
| 1681 | + |
|
| 1682 | + |
|
| 1683 | + /** |
|
| 1684 | + * admin_footer_global |
|
| 1685 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1686 | + * ALL EE_Admin Pages. |
|
| 1687 | + * |
|
| 1688 | + * @return void |
|
| 1689 | + * @throws EE_Error |
|
| 1690 | + */ |
|
| 1691 | + public function admin_footer_global() |
|
| 1692 | + { |
|
| 1693 | + //dialog container for dialog helper |
|
| 1694 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1695 | + $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1696 | + $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1697 | + $d_cont .= '</div>'; |
|
| 1698 | + echo $d_cont; |
|
| 1699 | + //help tour stuff? |
|
| 1700 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1701 | + echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1702 | + } |
|
| 1703 | + //current set timezone for timezone js |
|
| 1704 | + echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + |
|
| 1708 | + |
|
| 1709 | + /** |
|
| 1710 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1711 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1712 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1713 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1714 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1715 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1716 | + * for the |
|
| 1717 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1718 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1719 | + * 'help_trigger_id' => array( |
|
| 1720 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1721 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1722 | + * ) |
|
| 1723 | + * ); |
|
| 1724 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1725 | + * |
|
| 1726 | + * @param array $help_array |
|
| 1727 | + * @param bool $display |
|
| 1728 | + * @return string content |
|
| 1729 | + * @throws DomainException |
|
| 1730 | + * @throws EE_Error |
|
| 1731 | + */ |
|
| 1732 | + protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1733 | + { |
|
| 1734 | + $content = ''; |
|
| 1735 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1736 | + //loop through the array and setup content |
|
| 1737 | + foreach ($help_array as $trigger => $help) { |
|
| 1738 | + //make sure the array is setup properly |
|
| 1739 | + if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1740 | + throw new EE_Error( |
|
| 1741 | + esc_html__( |
|
| 1742 | + 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1743 | + 'event_espresso' |
|
| 1744 | + ) |
|
| 1745 | + ); |
|
| 1746 | + } |
|
| 1747 | + //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1748 | + $template_args = array( |
|
| 1749 | + 'help_popup_id' => $trigger, |
|
| 1750 | + 'help_popup_title' => $help['title'], |
|
| 1751 | + 'help_popup_content' => $help['content'], |
|
| 1752 | + ); |
|
| 1753 | + $content .= EEH_Template::display_template( |
|
| 1754 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1755 | + $template_args, |
|
| 1756 | + true |
|
| 1757 | + ); |
|
| 1758 | + } |
|
| 1759 | + if ($display) { |
|
| 1760 | + echo $content; |
|
| 1761 | + return ''; |
|
| 1762 | + } |
|
| 1763 | + return $content; |
|
| 1764 | + } |
|
| 1765 | + |
|
| 1766 | + |
|
| 1767 | + |
|
| 1768 | + /** |
|
| 1769 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1770 | + * |
|
| 1771 | + * @return array properly formatted array for help popup content |
|
| 1772 | + * @throws EE_Error |
|
| 1773 | + */ |
|
| 1774 | + private function _get_help_content() |
|
| 1775 | + { |
|
| 1776 | + //what is the method we're looking for? |
|
| 1777 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1778 | + //if method doesn't exist let's get out. |
|
| 1779 | + if (! method_exists($this, $method_name)) { |
|
| 1780 | + return array(); |
|
| 1781 | + } |
|
| 1782 | + //k we're good to go let's retrieve the help array |
|
| 1783 | + $help_array = call_user_func(array($this, $method_name)); |
|
| 1784 | + //make sure we've got an array! |
|
| 1785 | + if (! is_array($help_array)) { |
|
| 1786 | + throw new EE_Error( |
|
| 1787 | + esc_html__( |
|
| 1788 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1789 | + 'event_espresso' |
|
| 1790 | + ) |
|
| 1791 | + ); |
|
| 1792 | + } |
|
| 1793 | + return $help_array; |
|
| 1794 | + } |
|
| 1795 | + |
|
| 1796 | + |
|
| 1797 | + |
|
| 1798 | + /** |
|
| 1799 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1800 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1801 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1802 | + * |
|
| 1803 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1804 | + * @param boolean $display if false then we return the trigger string |
|
| 1805 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1806 | + * @return string |
|
| 1807 | + * @throws DomainException |
|
| 1808 | + * @throws EE_Error |
|
| 1809 | + */ |
|
| 1810 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1811 | + { |
|
| 1812 | + if (defined('DOING_AJAX')) { |
|
| 1813 | + return ''; |
|
| 1814 | + } |
|
| 1815 | + //let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1816 | + $help_array = $this->_get_help_content(); |
|
| 1817 | + $help_content = ''; |
|
| 1818 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1819 | + $help_array[$trigger_id] = array( |
|
| 1820 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1821 | + 'content' => esc_html__( |
|
| 1822 | + 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1823 | + 'event_espresso' |
|
| 1824 | + ), |
|
| 1825 | + ); |
|
| 1826 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1827 | + } |
|
| 1828 | + //let's setup the trigger |
|
| 1829 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1830 | + . $dimensions[0] |
|
| 1831 | + . '&width=' |
|
| 1832 | + . $dimensions[1] |
|
| 1833 | + . '&inlineId=' |
|
| 1834 | + . $trigger_id |
|
| 1835 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1836 | + $content .= $help_content; |
|
| 1837 | + if ($display) { |
|
| 1838 | + echo $content; |
|
| 1839 | + return ''; |
|
| 1840 | + } |
|
| 1841 | + return $content; |
|
| 1842 | + } |
|
| 1843 | + |
|
| 1844 | + |
|
| 1845 | + |
|
| 1846 | + /** |
|
| 1847 | + * _add_global_screen_options |
|
| 1848 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1849 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1850 | + * |
|
| 1851 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1852 | + * see also WP_Screen object documents... |
|
| 1853 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1854 | + * @abstract |
|
| 1855 | + * @return void |
|
| 1856 | + */ |
|
| 1857 | + private function _add_global_screen_options() |
|
| 1858 | + { |
|
| 1859 | + } |
|
| 1860 | + |
|
| 1861 | + |
|
| 1862 | + |
|
| 1863 | + /** |
|
| 1864 | + * _add_global_feature_pointers |
|
| 1865 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1866 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1867 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1868 | + * |
|
| 1869 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1870 | + * extended) also see: |
|
| 1871 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1872 | + * @abstract |
|
| 1873 | + * @return void |
|
| 1874 | + */ |
|
| 1875 | + private function _add_global_feature_pointers() |
|
| 1876 | + { |
|
| 1877 | + } |
|
| 1878 | + |
|
| 1879 | + |
|
| 1880 | + |
|
| 1881 | + /** |
|
| 1882 | + * load_global_scripts_styles |
|
| 1883 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1884 | + * |
|
| 1885 | + * @return void |
|
| 1886 | + * @throws EE_Error |
|
| 1887 | + */ |
|
| 1888 | + public function load_global_scripts_styles() |
|
| 1889 | + { |
|
| 1890 | + /** STYLES **/ |
|
| 1891 | + // add debugging styles |
|
| 1892 | + if (WP_DEBUG) { |
|
| 1893 | + add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1894 | + } |
|
| 1895 | + // register all styles |
|
| 1896 | + wp_register_style( |
|
| 1897 | + 'espresso-ui-theme', |
|
| 1898 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1899 | + array(), |
|
| 1900 | + EVENT_ESPRESSO_VERSION |
|
| 1901 | + ); |
|
| 1902 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1903 | + //helpers styles |
|
| 1904 | + wp_register_style( |
|
| 1905 | + 'ee-text-links', |
|
| 1906 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1907 | + array(), |
|
| 1908 | + EVENT_ESPRESSO_VERSION |
|
| 1909 | + ); |
|
| 1910 | + /** SCRIPTS **/ |
|
| 1911 | + //register all scripts |
|
| 1912 | + wp_register_script( |
|
| 1913 | + 'ee-dialog', |
|
| 1914 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1915 | + array('jquery', 'jquery-ui-draggable'), |
|
| 1916 | + EVENT_ESPRESSO_VERSION, |
|
| 1917 | + true |
|
| 1918 | + ); |
|
| 1919 | + wp_register_script( |
|
| 1920 | + 'ee_admin_js', |
|
| 1921 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1922 | + array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
| 1923 | + EVENT_ESPRESSO_VERSION, |
|
| 1924 | + true |
|
| 1925 | + ); |
|
| 1926 | + wp_register_script( |
|
| 1927 | + 'jquery-ui-timepicker-addon', |
|
| 1928 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1929 | + array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
| 1930 | + EVENT_ESPRESSO_VERSION, |
|
| 1931 | + true |
|
| 1932 | + ); |
|
| 1933 | + add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1934 | + //script for sorting tables |
|
| 1935 | + wp_register_script( |
|
| 1936 | + 'espresso_ajax_table_sorting', |
|
| 1937 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1938 | + array('ee_admin_js', 'jquery-ui-sortable'), |
|
| 1939 | + EVENT_ESPRESSO_VERSION, |
|
| 1940 | + true |
|
| 1941 | + ); |
|
| 1942 | + //script for parsing uri's |
|
| 1943 | + wp_register_script( |
|
| 1944 | + 'ee-parse-uri', |
|
| 1945 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1946 | + array(), |
|
| 1947 | + EVENT_ESPRESSO_VERSION, |
|
| 1948 | + true |
|
| 1949 | + ); |
|
| 1950 | + //and parsing associative serialized form elements |
|
| 1951 | + wp_register_script( |
|
| 1952 | + 'ee-serialize-full-array', |
|
| 1953 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1954 | + array('jquery'), |
|
| 1955 | + EVENT_ESPRESSO_VERSION, |
|
| 1956 | + true |
|
| 1957 | + ); |
|
| 1958 | + //helpers scripts |
|
| 1959 | + wp_register_script( |
|
| 1960 | + 'ee-text-links', |
|
| 1961 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1962 | + array('jquery'), |
|
| 1963 | + EVENT_ESPRESSO_VERSION, |
|
| 1964 | + true |
|
| 1965 | + ); |
|
| 1966 | + wp_register_script( |
|
| 1967 | + 'ee-moment-core', |
|
| 1968 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1969 | + array(), |
|
| 1970 | + EVENT_ESPRESSO_VERSION, |
|
| 1971 | + true |
|
| 1972 | + ); |
|
| 1973 | + wp_register_script( |
|
| 1974 | + 'ee-moment', |
|
| 1975 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1976 | + array('ee-moment-core'), |
|
| 1977 | + EVENT_ESPRESSO_VERSION, |
|
| 1978 | + true |
|
| 1979 | + ); |
|
| 1980 | + wp_register_script( |
|
| 1981 | + 'ee-datepicker', |
|
| 1982 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1983 | + array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
| 1984 | + EVENT_ESPRESSO_VERSION, |
|
| 1985 | + true |
|
| 1986 | + ); |
|
| 1987 | + //google charts |
|
| 1988 | + wp_register_script( |
|
| 1989 | + 'google-charts', |
|
| 1990 | + 'https://www.gstatic.com/charts/loader.js', |
|
| 1991 | + array(), |
|
| 1992 | + EVENT_ESPRESSO_VERSION, |
|
| 1993 | + false |
|
| 1994 | + ); |
|
| 1995 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1996 | + wp_enqueue_style('ee-admin-css'); |
|
| 1997 | + wp_enqueue_script('ee_admin_js'); |
|
| 1998 | + wp_enqueue_script('ee-accounting'); |
|
| 1999 | + wp_enqueue_script('jquery-validate'); |
|
| 2000 | + //taking care of metaboxes |
|
| 2001 | + if ( |
|
| 2002 | + empty($this->_cpt_route) |
|
| 2003 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 2004 | + ) { |
|
| 2005 | + wp_enqueue_script('dashboard'); |
|
| 2006 | + } |
|
| 2007 | + // LOCALIZED DATA |
|
| 2008 | + //localize script for ajax lazy loading |
|
| 2009 | + $lazy_loader_container_ids = apply_filters( |
|
| 2010 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 2011 | + array('espresso_news_post_box_content') |
|
| 2012 | + ); |
|
| 2013 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 2014 | + /** |
|
| 2015 | + * help tour stuff |
|
| 2016 | + */ |
|
| 2017 | + if (! empty($this->_help_tour)) { |
|
| 2018 | + //register the js for kicking things off |
|
| 2019 | + wp_enqueue_script( |
|
| 2020 | + 'ee-help-tour', |
|
| 2021 | + EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2022 | + array('jquery-joyride'), |
|
| 2023 | + EVENT_ESPRESSO_VERSION, |
|
| 2024 | + true |
|
| 2025 | + ); |
|
| 2026 | + $tours = array(); |
|
| 2027 | + //setup tours for the js tour object |
|
| 2028 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 2029 | + if ($tour instanceof EE_Help_Tour) { |
|
| 2030 | + $tours[] = array( |
|
| 2031 | + 'id' => $tour->get_slug(), |
|
| 2032 | + 'options' => $tour->get_options(), |
|
| 2033 | + ); |
|
| 2034 | + } |
|
| 2035 | + } |
|
| 2036 | + wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2037 | + //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2038 | + } |
|
| 2039 | + } |
|
| 2040 | + |
|
| 2041 | + |
|
| 2042 | + |
|
| 2043 | + /** |
|
| 2044 | + * admin_footer_scripts_eei18n_js_strings |
|
| 2045 | + * |
|
| 2046 | + * @return void |
|
| 2047 | + */ |
|
| 2048 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 2049 | + { |
|
| 2050 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2051 | + EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 2052 | + 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 2053 | + 'event_espresso' |
|
| 2054 | + ); |
|
| 2055 | + EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2056 | + EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2057 | + EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2058 | + EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2059 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2060 | + EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2061 | + EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2062 | + EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2063 | + EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2064 | + EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2065 | + EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2066 | + EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2067 | + EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2068 | + EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2069 | + EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2070 | + EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2071 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2072 | + EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2073 | + EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2074 | + EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2075 | + EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2076 | + EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2077 | + EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2078 | + EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2079 | + EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2080 | + EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2081 | + EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2082 | + EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2083 | + EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2084 | + EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2085 | + EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2086 | + EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2087 | + EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2088 | + EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2089 | + EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2090 | + EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2091 | + EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2092 | + EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2093 | + } |
|
| 2094 | + |
|
| 2095 | + |
|
| 2096 | + |
|
| 2097 | + /** |
|
| 2098 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2099 | + * |
|
| 2100 | + * @return void |
|
| 2101 | + */ |
|
| 2102 | + public function add_xdebug_style() |
|
| 2103 | + { |
|
| 2104 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2105 | + } |
|
| 2106 | + |
|
| 2107 | + |
|
| 2108 | + /************************/ |
|
| 2109 | + /** LIST TABLE METHODS **/ |
|
| 2110 | + /************************/ |
|
| 2111 | + /** |
|
| 2112 | + * this sets up the list table if the current view requires it. |
|
| 2113 | + * |
|
| 2114 | + * @return void |
|
| 2115 | + * @throws EE_Error |
|
| 2116 | + */ |
|
| 2117 | + protected function _set_list_table() |
|
| 2118 | + { |
|
| 2119 | + //first is this a list_table view? |
|
| 2120 | + if (! isset($this->_route_config['list_table'])) { |
|
| 2121 | + return; |
|
| 2122 | + } //not a list_table view so get out. |
|
| 2123 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2124 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2125 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2126 | + //user error msg |
|
| 2127 | + $error_msg = esc_html__( |
|
| 2128 | + 'An error occurred. The requested list table views could not be found.', |
|
| 2129 | + 'event_espresso' |
|
| 2130 | + ); |
|
| 2131 | + //developer error msg |
|
| 2132 | + $error_msg .= '||' . sprintf( |
|
| 2133 | + esc_html__( |
|
| 2134 | + 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2135 | + 'event_espresso' |
|
| 2136 | + ), |
|
| 2137 | + $this->_req_action, |
|
| 2138 | + $list_table_view |
|
| 2139 | + ); |
|
| 2140 | + throw new EE_Error($error_msg); |
|
| 2141 | + } |
|
| 2142 | + //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2143 | + $this->_views = apply_filters( |
|
| 2144 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2145 | + $this->_views |
|
| 2146 | + ); |
|
| 2147 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2148 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2149 | + $this->_set_list_table_view(); |
|
| 2150 | + $this->_set_list_table_object(); |
|
| 2151 | + } |
|
| 2152 | + |
|
| 2153 | + |
|
| 2154 | + |
|
| 2155 | + /** |
|
| 2156 | + * set current view for List Table |
|
| 2157 | + * |
|
| 2158 | + * @return void |
|
| 2159 | + */ |
|
| 2160 | + protected function _set_list_table_view() |
|
| 2161 | + { |
|
| 2162 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2163 | + // looking at active items or dumpster diving ? |
|
| 2164 | + if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2165 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2166 | + } else { |
|
| 2167 | + $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2168 | + } |
|
| 2169 | + } |
|
| 2170 | + |
|
| 2171 | + |
|
| 2172 | + /** |
|
| 2173 | + * _set_list_table_object |
|
| 2174 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2175 | + * |
|
| 2176 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2177 | + * @throws \InvalidArgumentException |
|
| 2178 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2179 | + * @throws EE_Error |
|
| 2180 | + * @throws InvalidInterfaceException |
|
| 2181 | + */ |
|
| 2182 | + protected function _set_list_table_object() |
|
| 2183 | + { |
|
| 2184 | + if (isset($this->_route_config['list_table'])) { |
|
| 2185 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 2186 | + throw new EE_Error( |
|
| 2187 | + sprintf( |
|
| 2188 | + esc_html__( |
|
| 2189 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2190 | + 'event_espresso' |
|
| 2191 | + ), |
|
| 2192 | + $this->_route_config['list_table'], |
|
| 2193 | + get_class($this) |
|
| 2194 | + ) |
|
| 2195 | + ); |
|
| 2196 | + } |
|
| 2197 | + $this->_list_table_object = LoaderFactory::getLoader()->getShared( |
|
| 2198 | + $this->_route_config['list_table'], |
|
| 2199 | + array($this) |
|
| 2200 | + ); |
|
| 2201 | + } |
|
| 2202 | + } |
|
| 2203 | + |
|
| 2204 | + |
|
| 2205 | + |
|
| 2206 | + /** |
|
| 2207 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2208 | + * |
|
| 2209 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2210 | + * urls. The array should be indexed by the view it is being |
|
| 2211 | + * added to. |
|
| 2212 | + * @return array |
|
| 2213 | + */ |
|
| 2214 | + public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2215 | + { |
|
| 2216 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2217 | + if (empty($this->_views)) { |
|
| 2218 | + $this->_views = array(); |
|
| 2219 | + } |
|
| 2220 | + // cycle thru views |
|
| 2221 | + foreach ($this->_views as $key => $view) { |
|
| 2222 | + $query_args = array(); |
|
| 2223 | + // check for current view |
|
| 2224 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2225 | + $query_args['action'] = $this->_req_action; |
|
| 2226 | + $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2227 | + $query_args['status'] = $view['slug']; |
|
| 2228 | + //merge any other arguments sent in. |
|
| 2229 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2230 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2231 | + } |
|
| 2232 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2233 | + } |
|
| 2234 | + return $this->_views; |
|
| 2235 | + } |
|
| 2236 | + |
|
| 2237 | + |
|
| 2238 | + |
|
| 2239 | + /** |
|
| 2240 | + * _entries_per_page_dropdown |
|
| 2241 | + * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2242 | + * |
|
| 2243 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2244 | + * WP does it. |
|
| 2245 | + * @param int $max_entries total number of rows in the table |
|
| 2246 | + * @return string |
|
| 2247 | + */ |
|
| 2248 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2249 | + { |
|
| 2250 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2251 | + $values = array(10, 25, 50, 100); |
|
| 2252 | + $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2253 | + if ($max_entries) { |
|
| 2254 | + $values[] = $max_entries; |
|
| 2255 | + sort($values); |
|
| 2256 | + } |
|
| 2257 | + $entries_per_page_dropdown = ' |
|
| 2258 | 2258 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2259 | 2259 | <label class="hide-if-no-js"> |
| 2260 | 2260 | Show |
| 2261 | 2261 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2262 | - foreach ($values as $value) { |
|
| 2263 | - if ($value < $max_entries) { |
|
| 2264 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2265 | - $entries_per_page_dropdown .= ' |
|
| 2262 | + foreach ($values as $value) { |
|
| 2263 | + if ($value < $max_entries) { |
|
| 2264 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2265 | + $entries_per_page_dropdown .= ' |
|
| 2266 | 2266 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2267 | - } |
|
| 2268 | - } |
|
| 2269 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2270 | - $entries_per_page_dropdown .= ' |
|
| 2267 | + } |
|
| 2268 | + } |
|
| 2269 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2270 | + $entries_per_page_dropdown .= ' |
|
| 2271 | 2271 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2272 | - $entries_per_page_dropdown .= ' |
|
| 2272 | + $entries_per_page_dropdown .= ' |
|
| 2273 | 2273 | </select> |
| 2274 | 2274 | entries |
| 2275 | 2275 | </label> |
| 2276 | 2276 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 2277 | 2277 | </div> |
| 2278 | 2278 | '; |
| 2279 | - return $entries_per_page_dropdown; |
|
| 2280 | - } |
|
| 2281 | - |
|
| 2282 | - |
|
| 2283 | - |
|
| 2284 | - /** |
|
| 2285 | - * _set_search_attributes |
|
| 2286 | - * |
|
| 2287 | - * @return void |
|
| 2288 | - */ |
|
| 2289 | - public function _set_search_attributes() |
|
| 2290 | - { |
|
| 2291 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2292 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2293 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2294 | - : $this->_search_btn_label |
|
| 2295 | - ); |
|
| 2296 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2297 | - } |
|
| 2298 | - |
|
| 2299 | - |
|
| 2300 | - |
|
| 2301 | - /*** END LIST TABLE METHODS **/ |
|
| 2302 | - |
|
| 2303 | - |
|
| 2304 | - |
|
| 2305 | - /** |
|
| 2306 | - * _add_registered_metaboxes |
|
| 2307 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2308 | - * |
|
| 2309 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2310 | - * @return void |
|
| 2311 | - * @throws EE_Error |
|
| 2312 | - */ |
|
| 2313 | - private function _add_registered_meta_boxes() |
|
| 2314 | - { |
|
| 2315 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2316 | - //we only add meta boxes if the page_route calls for it |
|
| 2317 | - if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2318 | - && is_array( |
|
| 2319 | - $this->_route_config['metaboxes'] |
|
| 2320 | - ) |
|
| 2321 | - ) { |
|
| 2322 | - // this simply loops through the callbacks provided |
|
| 2323 | - // and checks if there is a corresponding callback registered by the child |
|
| 2324 | - // if there is then we go ahead and process the metabox loader. |
|
| 2325 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2326 | - // first check for Closures |
|
| 2327 | - if ($metabox_callback instanceof Closure) { |
|
| 2328 | - $result = $metabox_callback(); |
|
| 2329 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2330 | - $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2331 | - } else { |
|
| 2332 | - $result = call_user_func(array($this, &$metabox_callback)); |
|
| 2333 | - } |
|
| 2334 | - if ($result === false) { |
|
| 2335 | - // user error msg |
|
| 2336 | - $error_msg = esc_html__( |
|
| 2337 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2338 | - 'event_espresso' |
|
| 2339 | - ); |
|
| 2340 | - // developer error msg |
|
| 2341 | - $error_msg .= '||' . sprintf( |
|
| 2342 | - esc_html__( |
|
| 2343 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2344 | - 'event_espresso' |
|
| 2345 | - ), |
|
| 2346 | - $metabox_callback |
|
| 2347 | - ); |
|
| 2348 | - throw new EE_Error($error_msg); |
|
| 2349 | - } |
|
| 2350 | - } |
|
| 2351 | - } |
|
| 2352 | - } |
|
| 2353 | - |
|
| 2354 | - |
|
| 2355 | - |
|
| 2356 | - /** |
|
| 2357 | - * _add_screen_columns |
|
| 2358 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2359 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2360 | - * |
|
| 2361 | - * @return void |
|
| 2362 | - */ |
|
| 2363 | - private function _add_screen_columns() |
|
| 2364 | - { |
|
| 2365 | - if ( |
|
| 2366 | - is_array($this->_route_config) |
|
| 2367 | - && isset($this->_route_config['columns']) |
|
| 2368 | - && is_array($this->_route_config['columns']) |
|
| 2369 | - && count($this->_route_config['columns']) === 2 |
|
| 2370 | - ) { |
|
| 2371 | - add_screen_option( |
|
| 2372 | - 'layout_columns', |
|
| 2373 | - array( |
|
| 2374 | - 'max' => (int)$this->_route_config['columns'][0], |
|
| 2375 | - 'default' => (int)$this->_route_config['columns'][1], |
|
| 2376 | - ) |
|
| 2377 | - ); |
|
| 2378 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2379 | - $screen_id = $this->_current_screen->id; |
|
| 2380 | - $screen_columns = (int)get_user_option("screen_layout_{$screen_id}"); |
|
| 2381 | - $total_columns = ! empty($screen_columns) |
|
| 2382 | - ? $screen_columns |
|
| 2383 | - : $this->_route_config['columns'][1]; |
|
| 2384 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2385 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2386 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2387 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2388 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2389 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2390 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2391 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2392 | - } |
|
| 2393 | - } |
|
| 2394 | - |
|
| 2395 | - |
|
| 2396 | - |
|
| 2397 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2398 | - |
|
| 2399 | - |
|
| 2400 | - /** |
|
| 2401 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2402 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2403 | - * these get loaded on. |
|
| 2404 | - */ |
|
| 2405 | - private function _espresso_news_post_box() |
|
| 2406 | - { |
|
| 2407 | - $news_box_title = apply_filters( |
|
| 2408 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2409 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2410 | - ); |
|
| 2411 | - add_meta_box( |
|
| 2412 | - 'espresso_news_post_box', |
|
| 2413 | - $news_box_title, |
|
| 2414 | - array( |
|
| 2415 | - $this, |
|
| 2416 | - 'espresso_news_post_box', |
|
| 2417 | - ), |
|
| 2418 | - $this->_wp_page_slug, |
|
| 2419 | - 'side' |
|
| 2420 | - ); |
|
| 2421 | - } |
|
| 2422 | - |
|
| 2423 | - |
|
| 2424 | - |
|
| 2425 | - /** |
|
| 2426 | - * Code for setting up espresso ratings request metabox. |
|
| 2427 | - */ |
|
| 2428 | - protected function _espresso_ratings_request() |
|
| 2429 | - { |
|
| 2430 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2431 | - return; |
|
| 2432 | - } |
|
| 2433 | - $ratings_box_title = apply_filters( |
|
| 2434 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2435 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2436 | - ); |
|
| 2437 | - add_meta_box( |
|
| 2438 | - 'espresso_ratings_request', |
|
| 2439 | - $ratings_box_title, |
|
| 2440 | - array( |
|
| 2441 | - $this, |
|
| 2442 | - 'espresso_ratings_request', |
|
| 2443 | - ), |
|
| 2444 | - $this->_wp_page_slug, |
|
| 2445 | - 'side' |
|
| 2446 | - ); |
|
| 2447 | - } |
|
| 2448 | - |
|
| 2449 | - |
|
| 2450 | - |
|
| 2451 | - /** |
|
| 2452 | - * Code for setting up espresso ratings request metabox content. |
|
| 2453 | - * |
|
| 2454 | - * @throws DomainException |
|
| 2455 | - */ |
|
| 2456 | - public function espresso_ratings_request() |
|
| 2457 | - { |
|
| 2458 | - EEH_Template::display_template( |
|
| 2459 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2460 | - array() |
|
| 2461 | - ); |
|
| 2462 | - } |
|
| 2463 | - |
|
| 2464 | - |
|
| 2465 | - |
|
| 2466 | - public static function cached_rss_display($rss_id, $url) |
|
| 2467 | - { |
|
| 2468 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2469 | - . __('Loading…') |
|
| 2470 | - . '</p><p class="hide-if-js">' |
|
| 2471 | - . esc_html__('This widget requires JavaScript.') |
|
| 2472 | - . '</p>'; |
|
| 2473 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2474 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2475 | - $post = '</div>' . "\n"; |
|
| 2476 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2477 | - $output = get_transient($cache_key); |
|
| 2478 | - if ($output !== false) { |
|
| 2479 | - echo $pre . $output . $post; |
|
| 2480 | - return true; |
|
| 2481 | - } |
|
| 2482 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2483 | - echo $pre . $loading . $post; |
|
| 2484 | - return false; |
|
| 2485 | - } |
|
| 2486 | - ob_start(); |
|
| 2487 | - wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2488 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2489 | - return true; |
|
| 2490 | - } |
|
| 2491 | - |
|
| 2492 | - |
|
| 2493 | - |
|
| 2494 | - public function espresso_news_post_box() |
|
| 2495 | - { |
|
| 2496 | - ?> |
|
| 2279 | + return $entries_per_page_dropdown; |
|
| 2280 | + } |
|
| 2281 | + |
|
| 2282 | + |
|
| 2283 | + |
|
| 2284 | + /** |
|
| 2285 | + * _set_search_attributes |
|
| 2286 | + * |
|
| 2287 | + * @return void |
|
| 2288 | + */ |
|
| 2289 | + public function _set_search_attributes() |
|
| 2290 | + { |
|
| 2291 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2292 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2293 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2294 | + : $this->_search_btn_label |
|
| 2295 | + ); |
|
| 2296 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2297 | + } |
|
| 2298 | + |
|
| 2299 | + |
|
| 2300 | + |
|
| 2301 | + /*** END LIST TABLE METHODS **/ |
|
| 2302 | + |
|
| 2303 | + |
|
| 2304 | + |
|
| 2305 | + /** |
|
| 2306 | + * _add_registered_metaboxes |
|
| 2307 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2308 | + * |
|
| 2309 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2310 | + * @return void |
|
| 2311 | + * @throws EE_Error |
|
| 2312 | + */ |
|
| 2313 | + private function _add_registered_meta_boxes() |
|
| 2314 | + { |
|
| 2315 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2316 | + //we only add meta boxes if the page_route calls for it |
|
| 2317 | + if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2318 | + && is_array( |
|
| 2319 | + $this->_route_config['metaboxes'] |
|
| 2320 | + ) |
|
| 2321 | + ) { |
|
| 2322 | + // this simply loops through the callbacks provided |
|
| 2323 | + // and checks if there is a corresponding callback registered by the child |
|
| 2324 | + // if there is then we go ahead and process the metabox loader. |
|
| 2325 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2326 | + // first check for Closures |
|
| 2327 | + if ($metabox_callback instanceof Closure) { |
|
| 2328 | + $result = $metabox_callback(); |
|
| 2329 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2330 | + $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2331 | + } else { |
|
| 2332 | + $result = call_user_func(array($this, &$metabox_callback)); |
|
| 2333 | + } |
|
| 2334 | + if ($result === false) { |
|
| 2335 | + // user error msg |
|
| 2336 | + $error_msg = esc_html__( |
|
| 2337 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2338 | + 'event_espresso' |
|
| 2339 | + ); |
|
| 2340 | + // developer error msg |
|
| 2341 | + $error_msg .= '||' . sprintf( |
|
| 2342 | + esc_html__( |
|
| 2343 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2344 | + 'event_espresso' |
|
| 2345 | + ), |
|
| 2346 | + $metabox_callback |
|
| 2347 | + ); |
|
| 2348 | + throw new EE_Error($error_msg); |
|
| 2349 | + } |
|
| 2350 | + } |
|
| 2351 | + } |
|
| 2352 | + } |
|
| 2353 | + |
|
| 2354 | + |
|
| 2355 | + |
|
| 2356 | + /** |
|
| 2357 | + * _add_screen_columns |
|
| 2358 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2359 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2360 | + * |
|
| 2361 | + * @return void |
|
| 2362 | + */ |
|
| 2363 | + private function _add_screen_columns() |
|
| 2364 | + { |
|
| 2365 | + if ( |
|
| 2366 | + is_array($this->_route_config) |
|
| 2367 | + && isset($this->_route_config['columns']) |
|
| 2368 | + && is_array($this->_route_config['columns']) |
|
| 2369 | + && count($this->_route_config['columns']) === 2 |
|
| 2370 | + ) { |
|
| 2371 | + add_screen_option( |
|
| 2372 | + 'layout_columns', |
|
| 2373 | + array( |
|
| 2374 | + 'max' => (int)$this->_route_config['columns'][0], |
|
| 2375 | + 'default' => (int)$this->_route_config['columns'][1], |
|
| 2376 | + ) |
|
| 2377 | + ); |
|
| 2378 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2379 | + $screen_id = $this->_current_screen->id; |
|
| 2380 | + $screen_columns = (int)get_user_option("screen_layout_{$screen_id}"); |
|
| 2381 | + $total_columns = ! empty($screen_columns) |
|
| 2382 | + ? $screen_columns |
|
| 2383 | + : $this->_route_config['columns'][1]; |
|
| 2384 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2385 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2386 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2387 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2388 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2389 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2390 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2391 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2392 | + } |
|
| 2393 | + } |
|
| 2394 | + |
|
| 2395 | + |
|
| 2396 | + |
|
| 2397 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2398 | + |
|
| 2399 | + |
|
| 2400 | + /** |
|
| 2401 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2402 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2403 | + * these get loaded on. |
|
| 2404 | + */ |
|
| 2405 | + private function _espresso_news_post_box() |
|
| 2406 | + { |
|
| 2407 | + $news_box_title = apply_filters( |
|
| 2408 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2409 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2410 | + ); |
|
| 2411 | + add_meta_box( |
|
| 2412 | + 'espresso_news_post_box', |
|
| 2413 | + $news_box_title, |
|
| 2414 | + array( |
|
| 2415 | + $this, |
|
| 2416 | + 'espresso_news_post_box', |
|
| 2417 | + ), |
|
| 2418 | + $this->_wp_page_slug, |
|
| 2419 | + 'side' |
|
| 2420 | + ); |
|
| 2421 | + } |
|
| 2422 | + |
|
| 2423 | + |
|
| 2424 | + |
|
| 2425 | + /** |
|
| 2426 | + * Code for setting up espresso ratings request metabox. |
|
| 2427 | + */ |
|
| 2428 | + protected function _espresso_ratings_request() |
|
| 2429 | + { |
|
| 2430 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2431 | + return; |
|
| 2432 | + } |
|
| 2433 | + $ratings_box_title = apply_filters( |
|
| 2434 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2435 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2436 | + ); |
|
| 2437 | + add_meta_box( |
|
| 2438 | + 'espresso_ratings_request', |
|
| 2439 | + $ratings_box_title, |
|
| 2440 | + array( |
|
| 2441 | + $this, |
|
| 2442 | + 'espresso_ratings_request', |
|
| 2443 | + ), |
|
| 2444 | + $this->_wp_page_slug, |
|
| 2445 | + 'side' |
|
| 2446 | + ); |
|
| 2447 | + } |
|
| 2448 | + |
|
| 2449 | + |
|
| 2450 | + |
|
| 2451 | + /** |
|
| 2452 | + * Code for setting up espresso ratings request metabox content. |
|
| 2453 | + * |
|
| 2454 | + * @throws DomainException |
|
| 2455 | + */ |
|
| 2456 | + public function espresso_ratings_request() |
|
| 2457 | + { |
|
| 2458 | + EEH_Template::display_template( |
|
| 2459 | + EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2460 | + array() |
|
| 2461 | + ); |
|
| 2462 | + } |
|
| 2463 | + |
|
| 2464 | + |
|
| 2465 | + |
|
| 2466 | + public static function cached_rss_display($rss_id, $url) |
|
| 2467 | + { |
|
| 2468 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2469 | + . __('Loading…') |
|
| 2470 | + . '</p><p class="hide-if-js">' |
|
| 2471 | + . esc_html__('This widget requires JavaScript.') |
|
| 2472 | + . '</p>'; |
|
| 2473 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2474 | + $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2475 | + $post = '</div>' . "\n"; |
|
| 2476 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2477 | + $output = get_transient($cache_key); |
|
| 2478 | + if ($output !== false) { |
|
| 2479 | + echo $pre . $output . $post; |
|
| 2480 | + return true; |
|
| 2481 | + } |
|
| 2482 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2483 | + echo $pre . $loading . $post; |
|
| 2484 | + return false; |
|
| 2485 | + } |
|
| 2486 | + ob_start(); |
|
| 2487 | + wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2488 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2489 | + return true; |
|
| 2490 | + } |
|
| 2491 | + |
|
| 2492 | + |
|
| 2493 | + |
|
| 2494 | + public function espresso_news_post_box() |
|
| 2495 | + { |
|
| 2496 | + ?> |
|
| 2497 | 2497 | <div class="padding"> |
| 2498 | 2498 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2499 | 2499 | <?php |
| 2500 | - // Get RSS Feed(s) |
|
| 2501 | - self::cached_rss_display( |
|
| 2502 | - 'espresso_news_post_box_content', |
|
| 2503 | - urlencode( |
|
| 2504 | - apply_filters( |
|
| 2505 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2506 | - 'http://eventespresso.com/feed/' |
|
| 2507 | - ) |
|
| 2508 | - ) |
|
| 2509 | - ); |
|
| 2510 | - ?> |
|
| 2500 | + // Get RSS Feed(s) |
|
| 2501 | + self::cached_rss_display( |
|
| 2502 | + 'espresso_news_post_box_content', |
|
| 2503 | + urlencode( |
|
| 2504 | + apply_filters( |
|
| 2505 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2506 | + 'http://eventespresso.com/feed/' |
|
| 2507 | + ) |
|
| 2508 | + ) |
|
| 2509 | + ); |
|
| 2510 | + ?> |
|
| 2511 | 2511 | </div> |
| 2512 | 2512 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2513 | 2513 | </div> |
| 2514 | 2514 | <?php |
| 2515 | - } |
|
| 2516 | - |
|
| 2517 | - |
|
| 2518 | - |
|
| 2519 | - private function _espresso_links_post_box() |
|
| 2520 | - { |
|
| 2521 | - //Hiding until we actually have content to put in here... |
|
| 2522 | - //add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2523 | - } |
|
| 2524 | - |
|
| 2525 | - |
|
| 2526 | - |
|
| 2527 | - public function espresso_links_post_box() |
|
| 2528 | - { |
|
| 2529 | - //Hiding until we actually have content to put in here... |
|
| 2530 | - // EEH_Template::display_template( |
|
| 2531 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2532 | - // ); |
|
| 2533 | - } |
|
| 2534 | - |
|
| 2535 | - |
|
| 2536 | - |
|
| 2537 | - protected function _espresso_sponsors_post_box() |
|
| 2538 | - { |
|
| 2539 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2540 | - add_meta_box( |
|
| 2541 | - 'espresso_sponsors_post_box', |
|
| 2542 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2543 | - array($this, 'espresso_sponsors_post_box'), |
|
| 2544 | - $this->_wp_page_slug, |
|
| 2545 | - 'side' |
|
| 2546 | - ); |
|
| 2547 | - } |
|
| 2548 | - } |
|
| 2549 | - |
|
| 2550 | - |
|
| 2551 | - |
|
| 2552 | - public function espresso_sponsors_post_box() |
|
| 2553 | - { |
|
| 2554 | - EEH_Template::display_template( |
|
| 2555 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2556 | - ); |
|
| 2557 | - } |
|
| 2558 | - |
|
| 2559 | - |
|
| 2560 | - |
|
| 2561 | - private function _publish_post_box() |
|
| 2562 | - { |
|
| 2563 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2564 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2565 | - // then we'll use that for the metabox label. |
|
| 2566 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2567 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2568 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2569 | - : $this->_labels['publishbox']; |
|
| 2570 | - } else { |
|
| 2571 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2572 | - } |
|
| 2573 | - $box_label = apply_filters( |
|
| 2574 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2575 | - $box_label, |
|
| 2576 | - $this->_req_action, |
|
| 2577 | - $this |
|
| 2578 | - ); |
|
| 2579 | - add_meta_box( |
|
| 2580 | - $meta_box_ref, |
|
| 2581 | - $box_label, |
|
| 2582 | - array($this, 'editor_overview'), |
|
| 2583 | - $this->_current_screen->id, |
|
| 2584 | - 'side', |
|
| 2585 | - 'high' |
|
| 2586 | - ); |
|
| 2587 | - } |
|
| 2588 | - |
|
| 2589 | - |
|
| 2590 | - |
|
| 2591 | - public function editor_overview() |
|
| 2592 | - { |
|
| 2593 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2594 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2595 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2596 | - : ''; |
|
| 2597 | - echo EEH_Template::display_template( |
|
| 2598 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2599 | - $this->_template_args, |
|
| 2600 | - true |
|
| 2601 | - ); |
|
| 2602 | - } |
|
| 2603 | - |
|
| 2604 | - |
|
| 2605 | - /** end of globally available metaboxes section **/ |
|
| 2606 | - |
|
| 2607 | - |
|
| 2608 | - |
|
| 2609 | - /** |
|
| 2610 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2611 | - * protected method. |
|
| 2612 | - * |
|
| 2613 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2614 | - * @since 4.6.0 |
|
| 2615 | - * @param string $name |
|
| 2616 | - * @param int $id |
|
| 2617 | - * @param bool $delete |
|
| 2618 | - * @param string $save_close_redirect_URL |
|
| 2619 | - * @param bool $both_btns |
|
| 2620 | - * @throws EE_Error |
|
| 2621 | - * @throws InvalidArgumentException |
|
| 2622 | - * @throws InvalidDataTypeException |
|
| 2623 | - * @throws InvalidInterfaceException |
|
| 2624 | - */ |
|
| 2625 | - public function set_publish_post_box_vars( |
|
| 2626 | - $name = '', |
|
| 2627 | - $id = 0, |
|
| 2628 | - $delete = false, |
|
| 2629 | - $save_close_redirect_URL = '', |
|
| 2630 | - $both_btns = true |
|
| 2631 | - ) { |
|
| 2632 | - $this->_set_publish_post_box_vars( |
|
| 2633 | - $name, |
|
| 2634 | - $id, |
|
| 2635 | - $delete, |
|
| 2636 | - $save_close_redirect_URL, |
|
| 2637 | - $both_btns |
|
| 2638 | - ); |
|
| 2639 | - } |
|
| 2640 | - |
|
| 2641 | - |
|
| 2642 | - |
|
| 2643 | - /** |
|
| 2644 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2645 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2646 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2647 | - * values for the name and id arguments. |
|
| 2648 | - * |
|
| 2649 | - * @todo Add in validation for name/id arguments. |
|
| 2650 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2651 | - * @param int $id id attached to the item published |
|
| 2652 | - * @param string $delete page route callback for the delete action |
|
| 2653 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2654 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2655 | - * the Save button |
|
| 2656 | - * @throws EE_Error |
|
| 2657 | - * @throws InvalidArgumentException |
|
| 2658 | - * @throws InvalidDataTypeException |
|
| 2659 | - * @throws InvalidInterfaceException |
|
| 2660 | - */ |
|
| 2661 | - protected function _set_publish_post_box_vars( |
|
| 2662 | - $name = '', |
|
| 2663 | - $id = 0, |
|
| 2664 | - $delete = '', |
|
| 2665 | - $save_close_redirect_URL = '', |
|
| 2666 | - $both_btns = true |
|
| 2667 | - ) { |
|
| 2668 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2669 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2670 | - ? $save_close_redirect_URL |
|
| 2671 | - : $this->_admin_base_url; |
|
| 2672 | - // create the Save & Close and Save buttons |
|
| 2673 | - $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2674 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2675 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2676 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2677 | - : ''; |
|
| 2678 | - if ($delete && ! empty($id)) { |
|
| 2679 | - //make sure we have a default if just true is sent. |
|
| 2680 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2681 | - $delete_link_args = array($name => $id); |
|
| 2682 | - $delete = $this->get_action_link_or_button( |
|
| 2683 | - $delete, |
|
| 2684 | - $delete, |
|
| 2685 | - $delete_link_args, |
|
| 2686 | - 'submitdelete deletion', |
|
| 2687 | - '', |
|
| 2688 | - false |
|
| 2689 | - ); |
|
| 2690 | - } |
|
| 2691 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2692 | - if (! empty($name) && ! empty($id)) { |
|
| 2693 | - $hidden_field_arr[$name] = array( |
|
| 2694 | - 'type' => 'hidden', |
|
| 2695 | - 'value' => $id, |
|
| 2696 | - ); |
|
| 2697 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2698 | - } else { |
|
| 2699 | - $hf = ''; |
|
| 2700 | - } |
|
| 2701 | - // add hidden field |
|
| 2702 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2703 | - ? $hf[$name]['field'] |
|
| 2704 | - : $hf; |
|
| 2705 | - } |
|
| 2706 | - |
|
| 2707 | - |
|
| 2708 | - |
|
| 2709 | - /** |
|
| 2710 | - * displays an error message to ppl who have javascript disabled |
|
| 2711 | - * |
|
| 2712 | - * @return void |
|
| 2713 | - */ |
|
| 2714 | - private function _display_no_javascript_warning() |
|
| 2715 | - { |
|
| 2716 | - ?> |
|
| 2515 | + } |
|
| 2516 | + |
|
| 2517 | + |
|
| 2518 | + |
|
| 2519 | + private function _espresso_links_post_box() |
|
| 2520 | + { |
|
| 2521 | + //Hiding until we actually have content to put in here... |
|
| 2522 | + //add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2523 | + } |
|
| 2524 | + |
|
| 2525 | + |
|
| 2526 | + |
|
| 2527 | + public function espresso_links_post_box() |
|
| 2528 | + { |
|
| 2529 | + //Hiding until we actually have content to put in here... |
|
| 2530 | + // EEH_Template::display_template( |
|
| 2531 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2532 | + // ); |
|
| 2533 | + } |
|
| 2534 | + |
|
| 2535 | + |
|
| 2536 | + |
|
| 2537 | + protected function _espresso_sponsors_post_box() |
|
| 2538 | + { |
|
| 2539 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2540 | + add_meta_box( |
|
| 2541 | + 'espresso_sponsors_post_box', |
|
| 2542 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2543 | + array($this, 'espresso_sponsors_post_box'), |
|
| 2544 | + $this->_wp_page_slug, |
|
| 2545 | + 'side' |
|
| 2546 | + ); |
|
| 2547 | + } |
|
| 2548 | + } |
|
| 2549 | + |
|
| 2550 | + |
|
| 2551 | + |
|
| 2552 | + public function espresso_sponsors_post_box() |
|
| 2553 | + { |
|
| 2554 | + EEH_Template::display_template( |
|
| 2555 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2556 | + ); |
|
| 2557 | + } |
|
| 2558 | + |
|
| 2559 | + |
|
| 2560 | + |
|
| 2561 | + private function _publish_post_box() |
|
| 2562 | + { |
|
| 2563 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2564 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2565 | + // then we'll use that for the metabox label. |
|
| 2566 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2567 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2568 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2569 | + : $this->_labels['publishbox']; |
|
| 2570 | + } else { |
|
| 2571 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2572 | + } |
|
| 2573 | + $box_label = apply_filters( |
|
| 2574 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2575 | + $box_label, |
|
| 2576 | + $this->_req_action, |
|
| 2577 | + $this |
|
| 2578 | + ); |
|
| 2579 | + add_meta_box( |
|
| 2580 | + $meta_box_ref, |
|
| 2581 | + $box_label, |
|
| 2582 | + array($this, 'editor_overview'), |
|
| 2583 | + $this->_current_screen->id, |
|
| 2584 | + 'side', |
|
| 2585 | + 'high' |
|
| 2586 | + ); |
|
| 2587 | + } |
|
| 2588 | + |
|
| 2589 | + |
|
| 2590 | + |
|
| 2591 | + public function editor_overview() |
|
| 2592 | + { |
|
| 2593 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2594 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2595 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2596 | + : ''; |
|
| 2597 | + echo EEH_Template::display_template( |
|
| 2598 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2599 | + $this->_template_args, |
|
| 2600 | + true |
|
| 2601 | + ); |
|
| 2602 | + } |
|
| 2603 | + |
|
| 2604 | + |
|
| 2605 | + /** end of globally available metaboxes section **/ |
|
| 2606 | + |
|
| 2607 | + |
|
| 2608 | + |
|
| 2609 | + /** |
|
| 2610 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2611 | + * protected method. |
|
| 2612 | + * |
|
| 2613 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2614 | + * @since 4.6.0 |
|
| 2615 | + * @param string $name |
|
| 2616 | + * @param int $id |
|
| 2617 | + * @param bool $delete |
|
| 2618 | + * @param string $save_close_redirect_URL |
|
| 2619 | + * @param bool $both_btns |
|
| 2620 | + * @throws EE_Error |
|
| 2621 | + * @throws InvalidArgumentException |
|
| 2622 | + * @throws InvalidDataTypeException |
|
| 2623 | + * @throws InvalidInterfaceException |
|
| 2624 | + */ |
|
| 2625 | + public function set_publish_post_box_vars( |
|
| 2626 | + $name = '', |
|
| 2627 | + $id = 0, |
|
| 2628 | + $delete = false, |
|
| 2629 | + $save_close_redirect_URL = '', |
|
| 2630 | + $both_btns = true |
|
| 2631 | + ) { |
|
| 2632 | + $this->_set_publish_post_box_vars( |
|
| 2633 | + $name, |
|
| 2634 | + $id, |
|
| 2635 | + $delete, |
|
| 2636 | + $save_close_redirect_URL, |
|
| 2637 | + $both_btns |
|
| 2638 | + ); |
|
| 2639 | + } |
|
| 2640 | + |
|
| 2641 | + |
|
| 2642 | + |
|
| 2643 | + /** |
|
| 2644 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2645 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2646 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2647 | + * values for the name and id arguments. |
|
| 2648 | + * |
|
| 2649 | + * @todo Add in validation for name/id arguments. |
|
| 2650 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2651 | + * @param int $id id attached to the item published |
|
| 2652 | + * @param string $delete page route callback for the delete action |
|
| 2653 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2654 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2655 | + * the Save button |
|
| 2656 | + * @throws EE_Error |
|
| 2657 | + * @throws InvalidArgumentException |
|
| 2658 | + * @throws InvalidDataTypeException |
|
| 2659 | + * @throws InvalidInterfaceException |
|
| 2660 | + */ |
|
| 2661 | + protected function _set_publish_post_box_vars( |
|
| 2662 | + $name = '', |
|
| 2663 | + $id = 0, |
|
| 2664 | + $delete = '', |
|
| 2665 | + $save_close_redirect_URL = '', |
|
| 2666 | + $both_btns = true |
|
| 2667 | + ) { |
|
| 2668 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2669 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2670 | + ? $save_close_redirect_URL |
|
| 2671 | + : $this->_admin_base_url; |
|
| 2672 | + // create the Save & Close and Save buttons |
|
| 2673 | + $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2674 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2675 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2676 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2677 | + : ''; |
|
| 2678 | + if ($delete && ! empty($id)) { |
|
| 2679 | + //make sure we have a default if just true is sent. |
|
| 2680 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2681 | + $delete_link_args = array($name => $id); |
|
| 2682 | + $delete = $this->get_action_link_or_button( |
|
| 2683 | + $delete, |
|
| 2684 | + $delete, |
|
| 2685 | + $delete_link_args, |
|
| 2686 | + 'submitdelete deletion', |
|
| 2687 | + '', |
|
| 2688 | + false |
|
| 2689 | + ); |
|
| 2690 | + } |
|
| 2691 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2692 | + if (! empty($name) && ! empty($id)) { |
|
| 2693 | + $hidden_field_arr[$name] = array( |
|
| 2694 | + 'type' => 'hidden', |
|
| 2695 | + 'value' => $id, |
|
| 2696 | + ); |
|
| 2697 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2698 | + } else { |
|
| 2699 | + $hf = ''; |
|
| 2700 | + } |
|
| 2701 | + // add hidden field |
|
| 2702 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2703 | + ? $hf[$name]['field'] |
|
| 2704 | + : $hf; |
|
| 2705 | + } |
|
| 2706 | + |
|
| 2707 | + |
|
| 2708 | + |
|
| 2709 | + /** |
|
| 2710 | + * displays an error message to ppl who have javascript disabled |
|
| 2711 | + * |
|
| 2712 | + * @return void |
|
| 2713 | + */ |
|
| 2714 | + private function _display_no_javascript_warning() |
|
| 2715 | + { |
|
| 2716 | + ?> |
|
| 2717 | 2717 | <noscript> |
| 2718 | 2718 | <div id="no-js-message" class="error"> |
| 2719 | 2719 | <p style="font-size:1.3em;"> |
| 2720 | 2720 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2721 | 2721 | <?php esc_html_e( |
| 2722 | - 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2723 | - 'event_espresso' |
|
| 2724 | - ); ?> |
|
| 2722 | + 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2723 | + 'event_espresso' |
|
| 2724 | + ); ?> |
|
| 2725 | 2725 | </p> |
| 2726 | 2726 | </div> |
| 2727 | 2727 | </noscript> |
| 2728 | 2728 | <?php |
| 2729 | - } |
|
| 2729 | + } |
|
| 2730 | 2730 | |
| 2731 | 2731 | |
| 2732 | 2732 | |
| 2733 | - /** |
|
| 2734 | - * displays espresso success and/or error notices |
|
| 2735 | - * |
|
| 2736 | - * @return void |
|
| 2737 | - */ |
|
| 2738 | - private function _display_espresso_notices() |
|
| 2739 | - { |
|
| 2740 | - $notices = $this->_get_transient(true); |
|
| 2741 | - echo stripslashes($notices); |
|
| 2742 | - } |
|
| 2733 | + /** |
|
| 2734 | + * displays espresso success and/or error notices |
|
| 2735 | + * |
|
| 2736 | + * @return void |
|
| 2737 | + */ |
|
| 2738 | + private function _display_espresso_notices() |
|
| 2739 | + { |
|
| 2740 | + $notices = $this->_get_transient(true); |
|
| 2741 | + echo stripslashes($notices); |
|
| 2742 | + } |
|
| 2743 | 2743 | |
| 2744 | 2744 | |
| 2745 | 2745 | |
| 2746 | - /** |
|
| 2747 | - * spinny things pacify the masses |
|
| 2748 | - * |
|
| 2749 | - * @return void |
|
| 2750 | - */ |
|
| 2751 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2752 | - { |
|
| 2753 | - ?> |
|
| 2746 | + /** |
|
| 2747 | + * spinny things pacify the masses |
|
| 2748 | + * |
|
| 2749 | + * @return void |
|
| 2750 | + */ |
|
| 2751 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2752 | + { |
|
| 2753 | + ?> |
|
| 2754 | 2754 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2755 | 2755 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e( |
| 2756 | - 'loading...', |
|
| 2757 | - 'event_espresso' |
|
| 2758 | - ); ?></span> |
|
| 2756 | + 'loading...', |
|
| 2757 | + 'event_espresso' |
|
| 2758 | + ); ?></span> |
|
| 2759 | 2759 | </div> |
| 2760 | 2760 | <?php |
| 2761 | - } |
|
| 2761 | + } |
|
| 2762 | 2762 | |
| 2763 | 2763 | |
| 2764 | 2764 | |
| 2765 | - /** |
|
| 2766 | - * add admin page overlay for modal boxes |
|
| 2767 | - * |
|
| 2768 | - * @return void |
|
| 2769 | - */ |
|
| 2770 | - protected function _add_admin_page_overlay() |
|
| 2771 | - { |
|
| 2772 | - ?> |
|
| 2765 | + /** |
|
| 2766 | + * add admin page overlay for modal boxes |
|
| 2767 | + * |
|
| 2768 | + * @return void |
|
| 2769 | + */ |
|
| 2770 | + protected function _add_admin_page_overlay() |
|
| 2771 | + { |
|
| 2772 | + ?> |
|
| 2773 | 2773 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2774 | 2774 | <?php |
| 2775 | - } |
|
| 2776 | - |
|
| 2777 | - |
|
| 2778 | - |
|
| 2779 | - /** |
|
| 2780 | - * facade for add_meta_box |
|
| 2781 | - * |
|
| 2782 | - * @param string $action where the metabox get's displayed |
|
| 2783 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2784 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2785 | - * instead of the one created in here. |
|
| 2786 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2787 | - * @param string $column what metabox column |
|
| 2788 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2789 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2790 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2791 | - * @throws \DomainException |
|
| 2792 | - */ |
|
| 2793 | - public function _add_admin_page_meta_box( |
|
| 2794 | - $action, |
|
| 2795 | - $title, |
|
| 2796 | - $callback, |
|
| 2797 | - $callback_args, |
|
| 2798 | - $column = 'normal', |
|
| 2799 | - $priority = 'high', |
|
| 2800 | - $create_func = true |
|
| 2801 | - ) { |
|
| 2802 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2803 | - //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2804 | - if (empty($callback_args) && $create_func) { |
|
| 2805 | - $callback_args = array( |
|
| 2806 | - 'template_path' => $this->_template_path, |
|
| 2807 | - 'template_args' => $this->_template_args, |
|
| 2808 | - ); |
|
| 2809 | - } |
|
| 2810 | - //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2811 | - $call_back_func = $create_func |
|
| 2812 | - ? function ($post, $metabox) |
|
| 2813 | - { |
|
| 2814 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2815 | - echo EEH_Template::display_template( |
|
| 2816 | - $metabox['args']['template_path'], |
|
| 2817 | - $metabox['args']['template_args'], |
|
| 2818 | - true |
|
| 2819 | - ); |
|
| 2820 | - } |
|
| 2821 | - : $callback; |
|
| 2822 | - add_meta_box( |
|
| 2823 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2824 | - $title, |
|
| 2825 | - $call_back_func, |
|
| 2826 | - $this->_wp_page_slug, |
|
| 2827 | - $column, |
|
| 2828 | - $priority, |
|
| 2829 | - $callback_args |
|
| 2830 | - ); |
|
| 2831 | - } |
|
| 2832 | - |
|
| 2833 | - |
|
| 2834 | - |
|
| 2835 | - /** |
|
| 2836 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2837 | - * |
|
| 2838 | - * @throws DomainException |
|
| 2839 | - * @throws EE_Error |
|
| 2840 | - */ |
|
| 2841 | - public function display_admin_page_with_metabox_columns() |
|
| 2842 | - { |
|
| 2843 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2844 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2845 | - $this->_column_template_path, |
|
| 2846 | - $this->_template_args, |
|
| 2847 | - true |
|
| 2848 | - ); |
|
| 2849 | - //the final wrapper |
|
| 2850 | - $this->admin_page_wrapper(); |
|
| 2851 | - } |
|
| 2852 | - |
|
| 2853 | - |
|
| 2854 | - |
|
| 2855 | - /** |
|
| 2856 | - * generates HTML wrapper for an admin details page |
|
| 2857 | - * |
|
| 2858 | - * @return void |
|
| 2859 | - * @throws EE_Error |
|
| 2860 | - * @throws DomainException |
|
| 2861 | - */ |
|
| 2862 | - public function display_admin_page_with_sidebar() |
|
| 2863 | - { |
|
| 2864 | - $this->_display_admin_page(true); |
|
| 2865 | - } |
|
| 2866 | - |
|
| 2867 | - |
|
| 2868 | - |
|
| 2869 | - /** |
|
| 2870 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2871 | - * |
|
| 2872 | - * @return void |
|
| 2873 | - * @throws EE_Error |
|
| 2874 | - * @throws DomainException |
|
| 2875 | - */ |
|
| 2876 | - public function display_admin_page_with_no_sidebar() |
|
| 2877 | - { |
|
| 2878 | - $this->_display_admin_page(); |
|
| 2879 | - } |
|
| 2880 | - |
|
| 2881 | - |
|
| 2882 | - |
|
| 2883 | - /** |
|
| 2884 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2885 | - * |
|
| 2886 | - * @return void |
|
| 2887 | - * @throws EE_Error |
|
| 2888 | - * @throws DomainException |
|
| 2889 | - */ |
|
| 2890 | - public function display_about_admin_page() |
|
| 2891 | - { |
|
| 2892 | - $this->_display_admin_page(false, true); |
|
| 2893 | - } |
|
| 2894 | - |
|
| 2895 | - |
|
| 2896 | - |
|
| 2897 | - /** |
|
| 2898 | - * display_admin_page |
|
| 2899 | - * contains the code for actually displaying an admin page |
|
| 2900 | - * |
|
| 2901 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2902 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2903 | - * @return void |
|
| 2904 | - * @throws DomainException |
|
| 2905 | - * @throws EE_Error |
|
| 2906 | - */ |
|
| 2907 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2908 | - { |
|
| 2909 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2910 | - //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2911 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2912 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2913 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2914 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2915 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2916 | - ? 'poststuff' |
|
| 2917 | - : 'espresso-default-admin'; |
|
| 2918 | - $template_path = $sidebar |
|
| 2919 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2920 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2921 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2922 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2923 | - } |
|
| 2924 | - $template_path = ! empty($this->_column_template_path) |
|
| 2925 | - ? $this->_column_template_path : $template_path; |
|
| 2926 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2927 | - ? $this->_template_args['admin_page_content'] |
|
| 2928 | - : ''; |
|
| 2929 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2930 | - ? $this->_template_args['before_admin_page_content'] |
|
| 2931 | - : ''; |
|
| 2932 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2933 | - ? $this->_template_args['after_admin_page_content'] |
|
| 2934 | - : ''; |
|
| 2935 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2936 | - $template_path, |
|
| 2937 | - $this->_template_args, |
|
| 2938 | - true |
|
| 2939 | - ); |
|
| 2940 | - // the final template wrapper |
|
| 2941 | - $this->admin_page_wrapper($about); |
|
| 2942 | - } |
|
| 2943 | - |
|
| 2944 | - |
|
| 2945 | - |
|
| 2946 | - /** |
|
| 2947 | - * This is used to display caf preview pages. |
|
| 2948 | - * |
|
| 2949 | - * @since 4.3.2 |
|
| 2950 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2951 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2952 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2953 | - * @return void |
|
| 2954 | - * @throws DomainException |
|
| 2955 | - * @throws EE_Error |
|
| 2956 | - * @throws InvalidArgumentException |
|
| 2957 | - * @throws InvalidDataTypeException |
|
| 2958 | - * @throws InvalidInterfaceException |
|
| 2959 | - */ |
|
| 2960 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2961 | - { |
|
| 2962 | - //let's generate a default preview action button if there isn't one already present. |
|
| 2963 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2964 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2965 | - 'event_espresso' |
|
| 2966 | - ); |
|
| 2967 | - $buy_now_url = add_query_arg( |
|
| 2968 | - array( |
|
| 2969 | - 'ee_ver' => 'ee4', |
|
| 2970 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2971 | - 'utm_medium' => 'link', |
|
| 2972 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2973 | - 'utm_content' => 'buy_now_button', |
|
| 2974 | - ), |
|
| 2975 | - 'http://eventespresso.com/pricing/' |
|
| 2976 | - ); |
|
| 2977 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2978 | - ? $this->get_action_link_or_button( |
|
| 2979 | - '', |
|
| 2980 | - 'buy_now', |
|
| 2981 | - array(), |
|
| 2982 | - 'button-primary button-large', |
|
| 2983 | - $buy_now_url, |
|
| 2984 | - true |
|
| 2985 | - ) |
|
| 2986 | - : $this->_template_args['preview_action_button']; |
|
| 2987 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2988 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2989 | - $this->_template_args, |
|
| 2990 | - true |
|
| 2991 | - ); |
|
| 2992 | - $this->_display_admin_page($display_sidebar); |
|
| 2993 | - } |
|
| 2994 | - |
|
| 2995 | - |
|
| 2996 | - |
|
| 2997 | - /** |
|
| 2998 | - * display_admin_list_table_page_with_sidebar |
|
| 2999 | - * generates HTML wrapper for an admin_page with list_table |
|
| 3000 | - * |
|
| 3001 | - * @return void |
|
| 3002 | - * @throws EE_Error |
|
| 3003 | - * @throws DomainException |
|
| 3004 | - */ |
|
| 3005 | - public function display_admin_list_table_page_with_sidebar() |
|
| 3006 | - { |
|
| 3007 | - $this->_display_admin_list_table_page(true); |
|
| 3008 | - } |
|
| 3009 | - |
|
| 3010 | - |
|
| 3011 | - |
|
| 3012 | - /** |
|
| 3013 | - * display_admin_list_table_page_with_no_sidebar |
|
| 3014 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 3015 | - * |
|
| 3016 | - * @return void |
|
| 3017 | - * @throws EE_Error |
|
| 3018 | - * @throws DomainException |
|
| 3019 | - */ |
|
| 3020 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 3021 | - { |
|
| 3022 | - $this->_display_admin_list_table_page(); |
|
| 3023 | - } |
|
| 3024 | - |
|
| 3025 | - |
|
| 3026 | - |
|
| 3027 | - /** |
|
| 3028 | - * generates html wrapper for an admin_list_table page |
|
| 3029 | - * |
|
| 3030 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 3031 | - * @return void |
|
| 3032 | - * @throws DomainException |
|
| 3033 | - * @throws EE_Error |
|
| 3034 | - */ |
|
| 3035 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 3036 | - { |
|
| 3037 | - //setup search attributes |
|
| 3038 | - $this->_set_search_attributes(); |
|
| 3039 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 3040 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3041 | - $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 3042 | - ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 3043 | - : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 3044 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 3045 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 3046 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 3047 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 3048 | - if (! empty($ajax_sorting_callback)) { |
|
| 3049 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 3050 | - $ajax_sorting_callback . '_nonce', |
|
| 3051 | - $ajax_sorting_callback . '_nonce', |
|
| 3052 | - false, |
|
| 3053 | - false |
|
| 3054 | - ); |
|
| 3055 | - // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 3056 | - // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 3057 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3058 | - . $this->page_slug |
|
| 3059 | - . '" />'; |
|
| 3060 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3061 | - . $ajax_sorting_callback |
|
| 3062 | - . '" />'; |
|
| 3063 | - } else { |
|
| 3064 | - $sortable_list_table_form_fields = ''; |
|
| 3065 | - } |
|
| 3066 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3067 | - $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 3068 | - ? $this->_template_args['list_table_hidden_fields'] |
|
| 3069 | - : ''; |
|
| 3070 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3071 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3072 | - . $nonce_ref |
|
| 3073 | - . '" value="' |
|
| 3074 | - . wp_create_nonce($nonce_ref) |
|
| 3075 | - . '">'; |
|
| 3076 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3077 | - //display message about search results? |
|
| 3078 | - $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 3079 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3080 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3081 | - trim($this->_req_data['s'], '%') |
|
| 3082 | - ) . '</p>' |
|
| 3083 | - : ''; |
|
| 3084 | - // filter before_list_table template arg |
|
| 3085 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 3086 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3087 | - $this->_template_args['before_list_table'], |
|
| 3088 | - $this->page_slug, |
|
| 3089 | - $this->_req_data, |
|
| 3090 | - $this->_req_action |
|
| 3091 | - ); |
|
| 3092 | - // convert to array and filter again |
|
| 3093 | - // arrays are easier to inject new items in a specific location, |
|
| 3094 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3095 | - $this->_template_args['before_list_table'] = implode( |
|
| 3096 | - " \n", |
|
| 3097 | - (array)apply_filters( |
|
| 3098 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3099 | - (array)$this->_template_args['before_list_table'], |
|
| 3100 | - $this->page_slug, |
|
| 3101 | - $this->_req_data, |
|
| 3102 | - $this->_req_action |
|
| 3103 | - ) |
|
| 3104 | - ); |
|
| 3105 | - // filter after_list_table template arg |
|
| 3106 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 3107 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3108 | - $this->_template_args['after_list_table'], |
|
| 3109 | - $this->page_slug, |
|
| 3110 | - $this->_req_data, |
|
| 3111 | - $this->_req_action |
|
| 3112 | - ); |
|
| 3113 | - // convert to array and filter again |
|
| 3114 | - // arrays are easier to inject new items in a specific location, |
|
| 3115 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3116 | - $this->_template_args['after_list_table'] = implode( |
|
| 3117 | - " \n", |
|
| 3118 | - (array)apply_filters( |
|
| 3119 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3120 | - (array)$this->_template_args['after_list_table'], |
|
| 3121 | - $this->page_slug, |
|
| 3122 | - $this->_req_data, |
|
| 3123 | - $this->_req_action |
|
| 3124 | - ) |
|
| 3125 | - ); |
|
| 3126 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3127 | - $template_path, |
|
| 3128 | - $this->_template_args, |
|
| 3129 | - true |
|
| 3130 | - ); |
|
| 3131 | - // the final template wrapper |
|
| 3132 | - if ($sidebar) { |
|
| 3133 | - $this->display_admin_page_with_sidebar(); |
|
| 3134 | - } else { |
|
| 3135 | - $this->display_admin_page_with_no_sidebar(); |
|
| 3136 | - } |
|
| 3137 | - } |
|
| 3138 | - |
|
| 3139 | - |
|
| 3140 | - |
|
| 3141 | - /** |
|
| 3142 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3143 | - * html string for the legend. |
|
| 3144 | - * $items are expected in an array in the following format: |
|
| 3145 | - * $legend_items = array( |
|
| 3146 | - * 'item_id' => array( |
|
| 3147 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3148 | - * 'desc' => esc_html__('localized description of item'); |
|
| 3149 | - * ) |
|
| 3150 | - * ); |
|
| 3151 | - * |
|
| 3152 | - * @param array $items see above for format of array |
|
| 3153 | - * @return string html string of legend |
|
| 3154 | - * @throws DomainException |
|
| 3155 | - */ |
|
| 3156 | - protected function _display_legend($items) |
|
| 3157 | - { |
|
| 3158 | - $this->_template_args['items'] = apply_filters( |
|
| 3159 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3160 | - (array)$items, |
|
| 3161 | - $this |
|
| 3162 | - ); |
|
| 3163 | - return EEH_Template::display_template( |
|
| 3164 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3165 | - $this->_template_args, |
|
| 3166 | - true |
|
| 3167 | - ); |
|
| 3168 | - } |
|
| 3169 | - |
|
| 3170 | - |
|
| 3171 | - /** |
|
| 3172 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3173 | - * The returned json object is created from an array in the following format: |
|
| 3174 | - * array( |
|
| 3175 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3176 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3177 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3178 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3179 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3180 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3181 | - * that might be included in here) |
|
| 3182 | - * ) |
|
| 3183 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 3184 | - * |
|
| 3185 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3186 | - * instead of displayed. |
|
| 3187 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3188 | - * @return void |
|
| 3189 | - * @throws EE_Error |
|
| 3190 | - */ |
|
| 3191 | - protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3192 | - { |
|
| 3193 | - //make sure any EE_Error notices have been handled. |
|
| 3194 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3195 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3196 | - unset($this->_template_args['data']); |
|
| 3197 | - $json = array( |
|
| 3198 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3199 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3200 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3201 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3202 | - 'notices' => EE_Error::get_notices(), |
|
| 3203 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3204 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 3205 | - 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3206 | - 'isEEajax' => true |
|
| 3207 | - //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3208 | - ); |
|
| 3209 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3210 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 3211 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 3212 | - } |
|
| 3213 | - echo wp_json_encode($json); |
|
| 3214 | - exit(); |
|
| 3215 | - } |
|
| 3216 | - |
|
| 3217 | - |
|
| 3218 | - |
|
| 3219 | - /** |
|
| 3220 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3221 | - * |
|
| 3222 | - * @return void |
|
| 3223 | - * @throws EE_Error |
|
| 3224 | - */ |
|
| 3225 | - public function return_json() |
|
| 3226 | - { |
|
| 3227 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3228 | - $this->_return_json(); |
|
| 3229 | - } else { |
|
| 3230 | - throw new EE_Error( |
|
| 3231 | - sprintf( |
|
| 3232 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3233 | - __FUNCTION__ |
|
| 3234 | - ) |
|
| 3235 | - ); |
|
| 3236 | - } |
|
| 3237 | - } |
|
| 3238 | - |
|
| 3239 | - |
|
| 3240 | - |
|
| 3241 | - /** |
|
| 3242 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3243 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3244 | - * |
|
| 3245 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3246 | - */ |
|
| 3247 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3248 | - { |
|
| 3249 | - $this->_hook_obj = $hook_obj; |
|
| 3250 | - } |
|
| 3251 | - |
|
| 3252 | - |
|
| 3253 | - |
|
| 3254 | - /** |
|
| 3255 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3256 | - * |
|
| 3257 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3258 | - * @return void |
|
| 3259 | - * @throws DomainException |
|
| 3260 | - * @throws EE_Error |
|
| 3261 | - */ |
|
| 3262 | - public function admin_page_wrapper($about = false) |
|
| 3263 | - { |
|
| 3264 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3265 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3266 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3267 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3268 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3269 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3270 | - isset($this->_template_args['before_admin_page_content']) |
|
| 3271 | - ? $this->_template_args['before_admin_page_content'] |
|
| 3272 | - : '' |
|
| 3273 | - ); |
|
| 3274 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3275 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3276 | - isset($this->_template_args['after_admin_page_content']) |
|
| 3277 | - ? $this->_template_args['after_admin_page_content'] |
|
| 3278 | - : '' |
|
| 3279 | - ); |
|
| 3280 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3281 | - // load settings page wrapper template |
|
| 3282 | - $template_path = ! defined('DOING_AJAX') |
|
| 3283 | - ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3284 | - : EE_ADMIN_TEMPLATE |
|
| 3285 | - . 'admin_wrapper_ajax.template.php'; |
|
| 3286 | - //about page? |
|
| 3287 | - $template_path = $about |
|
| 3288 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3289 | - : $template_path; |
|
| 3290 | - if (defined('DOING_AJAX')) { |
|
| 3291 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3292 | - $template_path, |
|
| 3293 | - $this->_template_args, |
|
| 3294 | - true |
|
| 3295 | - ); |
|
| 3296 | - $this->_return_json(); |
|
| 3297 | - } else { |
|
| 3298 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3299 | - } |
|
| 3300 | - } |
|
| 3301 | - |
|
| 3302 | - |
|
| 3303 | - |
|
| 3304 | - /** |
|
| 3305 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3306 | - * |
|
| 3307 | - * @return string html |
|
| 3308 | - * @throws EE_Error |
|
| 3309 | - */ |
|
| 3310 | - protected function _get_main_nav_tabs() |
|
| 3311 | - { |
|
| 3312 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3313 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3314 | - // (rather than setting in the page_routes array) |
|
| 3315 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3316 | - } |
|
| 3317 | - |
|
| 3318 | - |
|
| 3319 | - |
|
| 3320 | - /** |
|
| 3321 | - * sort nav tabs |
|
| 3322 | - * |
|
| 3323 | - * @param $a |
|
| 3324 | - * @param $b |
|
| 3325 | - * @return int |
|
| 3326 | - */ |
|
| 3327 | - private function _sort_nav_tabs($a, $b) |
|
| 3328 | - { |
|
| 3329 | - if ($a['order'] === $b['order']) { |
|
| 3330 | - return 0; |
|
| 3331 | - } |
|
| 3332 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3333 | - } |
|
| 3334 | - |
|
| 3335 | - |
|
| 3336 | - |
|
| 3337 | - /** |
|
| 3338 | - * generates HTML for the forms used on admin pages |
|
| 3339 | - * |
|
| 3340 | - * @param array $input_vars - array of input field details |
|
| 3341 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3342 | - * use) |
|
| 3343 | - * @param bool $id |
|
| 3344 | - * @return string |
|
| 3345 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3346 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3347 | - */ |
|
| 3348 | - protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 3349 | - { |
|
| 3350 | - $content = $generator === 'string' |
|
| 3351 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3352 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3353 | - return $content; |
|
| 3354 | - } |
|
| 3355 | - |
|
| 3356 | - |
|
| 3357 | - |
|
| 3358 | - /** |
|
| 3359 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3360 | - * |
|
| 3361 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3362 | - * Close" button. |
|
| 3363 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3364 | - * 'Save', [1] => 'save & close') |
|
| 3365 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3366 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3367 | - * default actions by submitting some other value. |
|
| 3368 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3369 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3370 | - * close (normal form handling). |
|
| 3371 | - */ |
|
| 3372 | - protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3373 | - { |
|
| 3374 | - //make sure $text and $actions are in an array |
|
| 3375 | - $text = (array)$text; |
|
| 3376 | - $actions = (array)$actions; |
|
| 3377 | - $referrer_url = empty($referrer) |
|
| 3378 | - ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3379 | - . $_SERVER['REQUEST_URI'] |
|
| 3380 | - . '" />' |
|
| 3381 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3382 | - . $referrer |
|
| 3383 | - . '" />'; |
|
| 3384 | - $button_text = ! empty($text) |
|
| 3385 | - ? $text |
|
| 3386 | - : array( |
|
| 3387 | - esc_html__('Save', 'event_espresso'), |
|
| 3388 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3389 | - ); |
|
| 3390 | - $default_names = array('save', 'save_and_close'); |
|
| 3391 | - //add in a hidden index for the current page (so save and close redirects properly) |
|
| 3392 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3393 | - foreach ($button_text as $key => $button) { |
|
| 3394 | - $ref = $default_names[$key]; |
|
| 3395 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3396 | - . $ref |
|
| 3397 | - . '" value="' |
|
| 3398 | - . $button |
|
| 3399 | - . '" name="' |
|
| 3400 | - . (! empty($actions) ? $actions[$key] : $ref) |
|
| 3401 | - . '" id="' |
|
| 3402 | - . $this->_current_view . '_' . $ref |
|
| 3403 | - . '" />'; |
|
| 3404 | - if (! $both) { |
|
| 3405 | - break; |
|
| 3406 | - } |
|
| 3407 | - } |
|
| 3408 | - } |
|
| 3409 | - |
|
| 3410 | - |
|
| 3411 | - |
|
| 3412 | - /** |
|
| 3413 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3414 | - * |
|
| 3415 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3416 | - * @since 4.6.0 |
|
| 3417 | - * @param string $route |
|
| 3418 | - * @param array $additional_hidden_fields |
|
| 3419 | - */ |
|
| 3420 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3421 | - { |
|
| 3422 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3423 | - } |
|
| 3424 | - |
|
| 3425 | - |
|
| 3426 | - |
|
| 3427 | - /** |
|
| 3428 | - * set form open and close tags on add/edit pages. |
|
| 3429 | - * |
|
| 3430 | - * @param string $route the route you want the form to direct to |
|
| 3431 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3432 | - * @return void |
|
| 3433 | - */ |
|
| 3434 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3435 | - { |
|
| 3436 | - if (empty($route)) { |
|
| 3437 | - $user_msg = esc_html__( |
|
| 3438 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3439 | - 'event_espresso' |
|
| 3440 | - ); |
|
| 3441 | - $dev_msg = $user_msg . "\n" . sprintf( |
|
| 3442 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3443 | - __FUNCTION__, |
|
| 3444 | - __CLASS__ |
|
| 3445 | - ); |
|
| 3446 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3447 | - } |
|
| 3448 | - // open form |
|
| 3449 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3450 | - . $this->_admin_base_url |
|
| 3451 | - . '" id="' |
|
| 3452 | - . $route |
|
| 3453 | - . '_event_form" >'; |
|
| 3454 | - // add nonce |
|
| 3455 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3456 | - // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 3457 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3458 | - // add REQUIRED form action |
|
| 3459 | - $hidden_fields = array( |
|
| 3460 | - 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3461 | - ); |
|
| 3462 | - // merge arrays |
|
| 3463 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3464 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3465 | - : $hidden_fields; |
|
| 3466 | - // generate form fields |
|
| 3467 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3468 | - // add fields to form |
|
| 3469 | - foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 3470 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3471 | - } |
|
| 3472 | - // close form |
|
| 3473 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3474 | - } |
|
| 3475 | - |
|
| 3476 | - |
|
| 3477 | - |
|
| 3478 | - /** |
|
| 3479 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3480 | - * discovered it would be useful for external code to have access. |
|
| 3481 | - * |
|
| 3482 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3483 | - * @since 4.5.0 |
|
| 3484 | - * @param bool $success |
|
| 3485 | - * @param string $what |
|
| 3486 | - * @param string $action_desc |
|
| 3487 | - * @param array $query_args |
|
| 3488 | - * @param bool $override_overwrite |
|
| 3489 | - * @throws EE_Error |
|
| 3490 | - */ |
|
| 3491 | - public function redirect_after_action( |
|
| 3492 | - $success = false, |
|
| 3493 | - $what = 'item', |
|
| 3494 | - $action_desc = 'processed', |
|
| 3495 | - $query_args = array(), |
|
| 3496 | - $override_overwrite = false |
|
| 3497 | - ) { |
|
| 3498 | - $this->_redirect_after_action( |
|
| 3499 | - $success, |
|
| 3500 | - $what, |
|
| 3501 | - $action_desc, |
|
| 3502 | - $query_args, |
|
| 3503 | - $override_overwrite |
|
| 3504 | - ); |
|
| 3505 | - } |
|
| 3506 | - |
|
| 3507 | - |
|
| 3508 | - |
|
| 3509 | - /** |
|
| 3510 | - * _redirect_after_action |
|
| 3511 | - * |
|
| 3512 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3513 | - * @param string $what - what the action was performed on |
|
| 3514 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3515 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3516 | - * action is completed |
|
| 3517 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3518 | - * override this so that they show. |
|
| 3519 | - * @return void |
|
| 3520 | - * @throws EE_Error |
|
| 3521 | - */ |
|
| 3522 | - protected function _redirect_after_action( |
|
| 3523 | - $success = 0, |
|
| 3524 | - $what = 'item', |
|
| 3525 | - $action_desc = 'processed', |
|
| 3526 | - $query_args = array(), |
|
| 3527 | - $override_overwrite = false |
|
| 3528 | - ) { |
|
| 3529 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3530 | - //class name for actions/filters. |
|
| 3531 | - $classname = get_class($this); |
|
| 3532 | - // set redirect url. |
|
| 3533 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3534 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3535 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3536 | - $notices = EE_Error::get_notices(false); |
|
| 3537 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3538 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3539 | - EE_Error::overwrite_success(); |
|
| 3540 | - } |
|
| 3541 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3542 | - // how many records affected ? more than one record ? or just one ? |
|
| 3543 | - if ($success > 1) { |
|
| 3544 | - // set plural msg |
|
| 3545 | - EE_Error::add_success( |
|
| 3546 | - sprintf( |
|
| 3547 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3548 | - $what, |
|
| 3549 | - $action_desc |
|
| 3550 | - ), |
|
| 3551 | - __FILE__, |
|
| 3552 | - __FUNCTION__, |
|
| 3553 | - __LINE__ |
|
| 3554 | - ); |
|
| 3555 | - } elseif ($success === 1) { |
|
| 3556 | - // set singular msg |
|
| 3557 | - EE_Error::add_success( |
|
| 3558 | - sprintf( |
|
| 3559 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3560 | - $what, |
|
| 3561 | - $action_desc |
|
| 3562 | - ), |
|
| 3563 | - __FILE__, |
|
| 3564 | - __FUNCTION__, |
|
| 3565 | - __LINE__ |
|
| 3566 | - ); |
|
| 3567 | - } |
|
| 3568 | - } |
|
| 3569 | - // check that $query_args isn't something crazy |
|
| 3570 | - if (! is_array($query_args)) { |
|
| 3571 | - $query_args = array(); |
|
| 3572 | - } |
|
| 3573 | - /** |
|
| 3574 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3575 | - * redirections on save and close actions |
|
| 3576 | - * |
|
| 3577 | - * @since 4.2.0 |
|
| 3578 | - * @param array $query_args The original query_args array coming into the |
|
| 3579 | - * method. |
|
| 3580 | - */ |
|
| 3581 | - do_action( |
|
| 3582 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3583 | - $query_args |
|
| 3584 | - ); |
|
| 3585 | - //calculate where we're going (if we have a "save and close" button pushed) |
|
| 3586 | - if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3587 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3588 | - $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3589 | - // regenerate query args array from referrer URL |
|
| 3590 | - parse_str($parsed_url['query'], $query_args); |
|
| 3591 | - // correct page and action will be in the query args now |
|
| 3592 | - $redirect_url = admin_url('admin.php'); |
|
| 3593 | - } |
|
| 3594 | - //merge any default query_args set in _default_route_query_args property |
|
| 3595 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3596 | - $args_to_merge = array(); |
|
| 3597 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3598 | - //is there a wp_referer array in our _default_route_query_args property? |
|
| 3599 | - if ($query_param === 'wp_referer') { |
|
| 3600 | - $query_value = (array)$query_value; |
|
| 3601 | - foreach ($query_value as $reference => $value) { |
|
| 3602 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3603 | - continue; |
|
| 3604 | - } |
|
| 3605 | - //finally we will override any arguments in the referer with |
|
| 3606 | - //what might be set on the _default_route_query_args array. |
|
| 3607 | - if (isset($this->_default_route_query_args[$reference])) { |
|
| 3608 | - $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3609 | - } else { |
|
| 3610 | - $args_to_merge[$reference] = urlencode($value); |
|
| 3611 | - } |
|
| 3612 | - } |
|
| 3613 | - continue; |
|
| 3614 | - } |
|
| 3615 | - $args_to_merge[$query_param] = $query_value; |
|
| 3616 | - } |
|
| 3617 | - //now let's merge these arguments but override with what was specifically sent in to the |
|
| 3618 | - //redirect. |
|
| 3619 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3620 | - } |
|
| 3621 | - $this->_process_notices($query_args); |
|
| 3622 | - // generate redirect url |
|
| 3623 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3624 | - if (isset($query_args['action'])) { |
|
| 3625 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3626 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3627 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3628 | - } |
|
| 3629 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3630 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3631 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3632 | - $redirect_url = apply_filters( |
|
| 3633 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3634 | - self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3635 | - $query_args |
|
| 3636 | - ); |
|
| 3637 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3638 | - if (defined('DOING_AJAX')) { |
|
| 3639 | - $default_data = array( |
|
| 3640 | - 'close' => true, |
|
| 3641 | - 'redirect_url' => $redirect_url, |
|
| 3642 | - 'where' => 'main', |
|
| 3643 | - 'what' => 'append', |
|
| 3644 | - ); |
|
| 3645 | - $this->_template_args['success'] = $success; |
|
| 3646 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3647 | - $default_data, |
|
| 3648 | - $this->_template_args['data'] |
|
| 3649 | - ) : $default_data; |
|
| 3650 | - $this->_return_json(); |
|
| 3651 | - } |
|
| 3652 | - wp_safe_redirect($redirect_url); |
|
| 3653 | - exit(); |
|
| 3654 | - } |
|
| 3655 | - |
|
| 3656 | - |
|
| 3657 | - |
|
| 3658 | - /** |
|
| 3659 | - * process any notices before redirecting (or returning ajax request) |
|
| 3660 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3661 | - * |
|
| 3662 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3663 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3664 | - * page_routes haven't been defined yet. |
|
| 3665 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3666 | - * still save a transient for the notice. |
|
| 3667 | - * @return void |
|
| 3668 | - * @throws EE_Error |
|
| 3669 | - */ |
|
| 3670 | - protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3671 | - { |
|
| 3672 | - //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3673 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3674 | - $notices = EE_Error::get_notices(false); |
|
| 3675 | - if (empty($this->_template_args['success'])) { |
|
| 3676 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3677 | - } |
|
| 3678 | - if (empty($this->_template_args['errors'])) { |
|
| 3679 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3680 | - } |
|
| 3681 | - if (empty($this->_template_args['attention'])) { |
|
| 3682 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3683 | - } |
|
| 3684 | - } |
|
| 3685 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3686 | - //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3687 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3688 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3689 | - $this->_add_transient( |
|
| 3690 | - $route, |
|
| 3691 | - $this->_template_args['notices'], |
|
| 3692 | - true, |
|
| 3693 | - $skip_route_verify |
|
| 3694 | - ); |
|
| 3695 | - } |
|
| 3696 | - } |
|
| 3697 | - |
|
| 3698 | - |
|
| 3699 | - |
|
| 3700 | - /** |
|
| 3701 | - * get_action_link_or_button |
|
| 3702 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3703 | - * |
|
| 3704 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3705 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3706 | - * property. |
|
| 3707 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3708 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3709 | - * @param string $base_url If this is not provided |
|
| 3710 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3711 | - * Otherwise this value will be used. |
|
| 3712 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3713 | - * @return string |
|
| 3714 | - * @throws InvalidArgumentException |
|
| 3715 | - * @throws InvalidInterfaceException |
|
| 3716 | - * @throws InvalidDataTypeException |
|
| 3717 | - * @throws EE_Error |
|
| 3718 | - */ |
|
| 3719 | - public function get_action_link_or_button( |
|
| 3720 | - $action, |
|
| 3721 | - $type = 'add', |
|
| 3722 | - $extra_request = array(), |
|
| 3723 | - $class = 'button-primary', |
|
| 3724 | - $base_url = '', |
|
| 3725 | - $exclude_nonce = false |
|
| 3726 | - ) { |
|
| 3727 | - //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3728 | - if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3729 | - throw new EE_Error( |
|
| 3730 | - sprintf( |
|
| 3731 | - esc_html__( |
|
| 3732 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3733 | - 'event_espresso' |
|
| 3734 | - ), |
|
| 3735 | - $action |
|
| 3736 | - ) |
|
| 3737 | - ); |
|
| 3738 | - } |
|
| 3739 | - if (! isset($this->_labels['buttons'][$type])) { |
|
| 3740 | - throw new EE_Error( |
|
| 3741 | - sprintf( |
|
| 3742 | - __( |
|
| 3743 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3744 | - 'event_espresso' |
|
| 3745 | - ), |
|
| 3746 | - $type |
|
| 3747 | - ) |
|
| 3748 | - ); |
|
| 3749 | - } |
|
| 3750 | - //finally check user access for this button. |
|
| 3751 | - $has_access = $this->check_user_access($action, true); |
|
| 3752 | - if (! $has_access) { |
|
| 3753 | - return ''; |
|
| 3754 | - } |
|
| 3755 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3756 | - $query_args = array( |
|
| 3757 | - 'action' => $action, |
|
| 3758 | - ); |
|
| 3759 | - //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3760 | - if (! empty($extra_request)) { |
|
| 3761 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3762 | - } |
|
| 3763 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3764 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3765 | - } |
|
| 3766 | - |
|
| 3767 | - |
|
| 3768 | - |
|
| 3769 | - /** |
|
| 3770 | - * _per_page_screen_option |
|
| 3771 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3772 | - * |
|
| 3773 | - * @return void |
|
| 3774 | - * @throws InvalidArgumentException |
|
| 3775 | - * @throws InvalidInterfaceException |
|
| 3776 | - * @throws InvalidDataTypeException |
|
| 3777 | - */ |
|
| 3778 | - protected function _per_page_screen_option() |
|
| 3779 | - { |
|
| 3780 | - $option = 'per_page'; |
|
| 3781 | - $args = array( |
|
| 3782 | - 'label' => esc_html__( |
|
| 3783 | - apply_filters( |
|
| 3784 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3785 | - $this->_admin_page_title, |
|
| 3786 | - $this |
|
| 3787 | - ) |
|
| 3788 | - ), |
|
| 3789 | - 'default' => (int) apply_filters( |
|
| 3790 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3791 | - 10 |
|
| 3792 | - ), |
|
| 3793 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3794 | - ); |
|
| 3795 | - //ONLY add the screen option if the user has access to it. |
|
| 3796 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3797 | - add_screen_option($option, $args); |
|
| 3798 | - } |
|
| 3799 | - } |
|
| 3800 | - |
|
| 3801 | - |
|
| 3802 | - |
|
| 3803 | - /** |
|
| 3804 | - * set_per_page_screen_option |
|
| 3805 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3806 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3807 | - * admin_menu. |
|
| 3808 | - * |
|
| 3809 | - * @return void |
|
| 3810 | - */ |
|
| 3811 | - private function _set_per_page_screen_options() |
|
| 3812 | - { |
|
| 3813 | - if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3814 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3815 | - if (! $user = wp_get_current_user()) { |
|
| 3816 | - return; |
|
| 3817 | - } |
|
| 3818 | - $option = $_POST['wp_screen_options']['option']; |
|
| 3819 | - $value = $_POST['wp_screen_options']['value']; |
|
| 3820 | - if ($option != sanitize_key($option)) { |
|
| 3821 | - return; |
|
| 3822 | - } |
|
| 3823 | - $map_option = $option; |
|
| 3824 | - $option = str_replace('-', '_', $option); |
|
| 3825 | - switch ($map_option) { |
|
| 3826 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3827 | - $value = (int)$value; |
|
| 3828 | - $max_value = apply_filters( |
|
| 3829 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3830 | - 999, |
|
| 3831 | - $this->_current_page, |
|
| 3832 | - $this->_current_view |
|
| 3833 | - ); |
|
| 3834 | - if ($value < 1) { |
|
| 3835 | - return; |
|
| 3836 | - } |
|
| 3837 | - $value = min($value, $max_value); |
|
| 3838 | - break; |
|
| 3839 | - default: |
|
| 3840 | - $value = apply_filters( |
|
| 3841 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3842 | - false, |
|
| 3843 | - $option, |
|
| 3844 | - $value |
|
| 3845 | - ); |
|
| 3846 | - if (false === $value) { |
|
| 3847 | - return; |
|
| 3848 | - } |
|
| 3849 | - break; |
|
| 3850 | - } |
|
| 3851 | - update_user_meta($user->ID, $option, $value); |
|
| 3852 | - wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3853 | - exit; |
|
| 3854 | - } |
|
| 3855 | - } |
|
| 3856 | - |
|
| 3857 | - |
|
| 3858 | - |
|
| 3859 | - /** |
|
| 3860 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3861 | - * |
|
| 3862 | - * @param array $data array that will be assigned to template args. |
|
| 3863 | - */ |
|
| 3864 | - public function set_template_args($data) |
|
| 3865 | - { |
|
| 3866 | - $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3867 | - } |
|
| 3868 | - |
|
| 3869 | - |
|
| 3870 | - |
|
| 3871 | - /** |
|
| 3872 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3873 | - * |
|
| 3874 | - * @param string $route the route that should receive the transient |
|
| 3875 | - * @param array $data the data that gets sent |
|
| 3876 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3877 | - * normal route transient. |
|
| 3878 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3879 | - * when we are adding a transient before page_routes have been defined. |
|
| 3880 | - * @return void |
|
| 3881 | - * @throws EE_Error |
|
| 3882 | - */ |
|
| 3883 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3884 | - { |
|
| 3885 | - $user_id = get_current_user_id(); |
|
| 3886 | - if (! $skip_route_verify) { |
|
| 3887 | - $this->_verify_route($route); |
|
| 3888 | - } |
|
| 3889 | - //now let's set the string for what kind of transient we're setting |
|
| 3890 | - $transient = $notices |
|
| 3891 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3892 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3893 | - $data = $notices ? array('notices' => $data) : $data; |
|
| 3894 | - //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3895 | - $existing = is_multisite() && is_network_admin() |
|
| 3896 | - ? get_site_transient($transient) |
|
| 3897 | - : get_transient($transient); |
|
| 3898 | - if ($existing) { |
|
| 3899 | - $data = array_merge((array)$data, (array)$existing); |
|
| 3900 | - } |
|
| 3901 | - if (is_multisite() && is_network_admin()) { |
|
| 3902 | - set_site_transient($transient, $data, 8); |
|
| 3903 | - } else { |
|
| 3904 | - set_transient($transient, $data, 8); |
|
| 3905 | - } |
|
| 3906 | - } |
|
| 3907 | - |
|
| 3908 | - |
|
| 3909 | - |
|
| 3910 | - /** |
|
| 3911 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3912 | - * |
|
| 3913 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3914 | - * @param string $route |
|
| 3915 | - * @return mixed data |
|
| 3916 | - */ |
|
| 3917 | - protected function _get_transient($notices = false, $route = '') |
|
| 3918 | - { |
|
| 3919 | - $user_id = get_current_user_id(); |
|
| 3920 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3921 | - $transient = $notices |
|
| 3922 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3923 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3924 | - $data = is_multisite() && is_network_admin() |
|
| 3925 | - ? get_site_transient($transient) |
|
| 3926 | - : get_transient($transient); |
|
| 3927 | - //delete transient after retrieval (just in case it hasn't expired); |
|
| 3928 | - if (is_multisite() && is_network_admin()) { |
|
| 3929 | - delete_site_transient($transient); |
|
| 3930 | - } else { |
|
| 3931 | - delete_transient($transient); |
|
| 3932 | - } |
|
| 3933 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3934 | - } |
|
| 3935 | - |
|
| 3936 | - |
|
| 3937 | - |
|
| 3938 | - /** |
|
| 3939 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3940 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3941 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3942 | - * |
|
| 3943 | - * @return void |
|
| 3944 | - */ |
|
| 3945 | - protected function _transient_garbage_collection() |
|
| 3946 | - { |
|
| 3947 | - global $wpdb; |
|
| 3948 | - //retrieve all existing transients |
|
| 3949 | - $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3950 | - if ($results = $wpdb->get_results($query)) { |
|
| 3951 | - foreach ($results as $result) { |
|
| 3952 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3953 | - get_transient($transient); |
|
| 3954 | - if (is_multisite() && is_network_admin()) { |
|
| 3955 | - get_site_transient($transient); |
|
| 3956 | - } |
|
| 3957 | - } |
|
| 3958 | - } |
|
| 3959 | - } |
|
| 3960 | - |
|
| 3961 | - |
|
| 3962 | - |
|
| 3963 | - /** |
|
| 3964 | - * get_view |
|
| 3965 | - * |
|
| 3966 | - * @return string content of _view property |
|
| 3967 | - */ |
|
| 3968 | - public function get_view() |
|
| 3969 | - { |
|
| 3970 | - return $this->_view; |
|
| 3971 | - } |
|
| 3972 | - |
|
| 3973 | - |
|
| 3974 | - |
|
| 3975 | - /** |
|
| 3976 | - * getter for the protected $_views property |
|
| 3977 | - * |
|
| 3978 | - * @return array |
|
| 3979 | - */ |
|
| 3980 | - public function get_views() |
|
| 3981 | - { |
|
| 3982 | - return $this->_views; |
|
| 3983 | - } |
|
| 3984 | - |
|
| 3985 | - |
|
| 3986 | - |
|
| 3987 | - /** |
|
| 3988 | - * get_current_page |
|
| 3989 | - * |
|
| 3990 | - * @return string _current_page property value |
|
| 3991 | - */ |
|
| 3992 | - public function get_current_page() |
|
| 3993 | - { |
|
| 3994 | - return $this->_current_page; |
|
| 3995 | - } |
|
| 3996 | - |
|
| 3997 | - |
|
| 3998 | - |
|
| 3999 | - /** |
|
| 4000 | - * get_current_view |
|
| 4001 | - * |
|
| 4002 | - * @return string _current_view property value |
|
| 4003 | - */ |
|
| 4004 | - public function get_current_view() |
|
| 4005 | - { |
|
| 4006 | - return $this->_current_view; |
|
| 4007 | - } |
|
| 4008 | - |
|
| 4009 | - |
|
| 4010 | - |
|
| 4011 | - /** |
|
| 4012 | - * get_current_screen |
|
| 4013 | - * |
|
| 4014 | - * @return object The current WP_Screen object |
|
| 4015 | - */ |
|
| 4016 | - public function get_current_screen() |
|
| 4017 | - { |
|
| 4018 | - return $this->_current_screen; |
|
| 4019 | - } |
|
| 4020 | - |
|
| 4021 | - |
|
| 4022 | - |
|
| 4023 | - /** |
|
| 4024 | - * get_current_page_view_url |
|
| 4025 | - * |
|
| 4026 | - * @return string This returns the url for the current_page_view. |
|
| 4027 | - */ |
|
| 4028 | - public function get_current_page_view_url() |
|
| 4029 | - { |
|
| 4030 | - return $this->_current_page_view_url; |
|
| 4031 | - } |
|
| 4032 | - |
|
| 4033 | - |
|
| 4034 | - |
|
| 4035 | - /** |
|
| 4036 | - * just returns the _req_data property |
|
| 4037 | - * |
|
| 4038 | - * @return array |
|
| 4039 | - */ |
|
| 4040 | - public function get_request_data() |
|
| 4041 | - { |
|
| 4042 | - return $this->_req_data; |
|
| 4043 | - } |
|
| 4044 | - |
|
| 4045 | - |
|
| 4046 | - |
|
| 4047 | - /** |
|
| 4048 | - * returns the _req_data protected property |
|
| 4049 | - * |
|
| 4050 | - * @return string |
|
| 4051 | - */ |
|
| 4052 | - public function get_req_action() |
|
| 4053 | - { |
|
| 4054 | - return $this->_req_action; |
|
| 4055 | - } |
|
| 4056 | - |
|
| 4057 | - |
|
| 4058 | - |
|
| 4059 | - /** |
|
| 4060 | - * @return bool value of $_is_caf property |
|
| 4061 | - */ |
|
| 4062 | - public function is_caf() |
|
| 4063 | - { |
|
| 4064 | - return $this->_is_caf; |
|
| 4065 | - } |
|
| 4066 | - |
|
| 4067 | - |
|
| 4068 | - |
|
| 4069 | - /** |
|
| 4070 | - * @return mixed |
|
| 4071 | - */ |
|
| 4072 | - public function default_espresso_metaboxes() |
|
| 4073 | - { |
|
| 4074 | - return $this->_default_espresso_metaboxes; |
|
| 4075 | - } |
|
| 4076 | - |
|
| 4077 | - |
|
| 4078 | - |
|
| 4079 | - /** |
|
| 4080 | - * @return mixed |
|
| 4081 | - */ |
|
| 4082 | - public function admin_base_url() |
|
| 4083 | - { |
|
| 4084 | - return $this->_admin_base_url; |
|
| 4085 | - } |
|
| 2775 | + } |
|
| 2776 | + |
|
| 2777 | + |
|
| 2778 | + |
|
| 2779 | + /** |
|
| 2780 | + * facade for add_meta_box |
|
| 2781 | + * |
|
| 2782 | + * @param string $action where the metabox get's displayed |
|
| 2783 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2784 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2785 | + * instead of the one created in here. |
|
| 2786 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2787 | + * @param string $column what metabox column |
|
| 2788 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2789 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2790 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2791 | + * @throws \DomainException |
|
| 2792 | + */ |
|
| 2793 | + public function _add_admin_page_meta_box( |
|
| 2794 | + $action, |
|
| 2795 | + $title, |
|
| 2796 | + $callback, |
|
| 2797 | + $callback_args, |
|
| 2798 | + $column = 'normal', |
|
| 2799 | + $priority = 'high', |
|
| 2800 | + $create_func = true |
|
| 2801 | + ) { |
|
| 2802 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2803 | + //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2804 | + if (empty($callback_args) && $create_func) { |
|
| 2805 | + $callback_args = array( |
|
| 2806 | + 'template_path' => $this->_template_path, |
|
| 2807 | + 'template_args' => $this->_template_args, |
|
| 2808 | + ); |
|
| 2809 | + } |
|
| 2810 | + //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2811 | + $call_back_func = $create_func |
|
| 2812 | + ? function ($post, $metabox) |
|
| 2813 | + { |
|
| 2814 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2815 | + echo EEH_Template::display_template( |
|
| 2816 | + $metabox['args']['template_path'], |
|
| 2817 | + $metabox['args']['template_args'], |
|
| 2818 | + true |
|
| 2819 | + ); |
|
| 2820 | + } |
|
| 2821 | + : $callback; |
|
| 2822 | + add_meta_box( |
|
| 2823 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2824 | + $title, |
|
| 2825 | + $call_back_func, |
|
| 2826 | + $this->_wp_page_slug, |
|
| 2827 | + $column, |
|
| 2828 | + $priority, |
|
| 2829 | + $callback_args |
|
| 2830 | + ); |
|
| 2831 | + } |
|
| 2832 | + |
|
| 2833 | + |
|
| 2834 | + |
|
| 2835 | + /** |
|
| 2836 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2837 | + * |
|
| 2838 | + * @throws DomainException |
|
| 2839 | + * @throws EE_Error |
|
| 2840 | + */ |
|
| 2841 | + public function display_admin_page_with_metabox_columns() |
|
| 2842 | + { |
|
| 2843 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2844 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2845 | + $this->_column_template_path, |
|
| 2846 | + $this->_template_args, |
|
| 2847 | + true |
|
| 2848 | + ); |
|
| 2849 | + //the final wrapper |
|
| 2850 | + $this->admin_page_wrapper(); |
|
| 2851 | + } |
|
| 2852 | + |
|
| 2853 | + |
|
| 2854 | + |
|
| 2855 | + /** |
|
| 2856 | + * generates HTML wrapper for an admin details page |
|
| 2857 | + * |
|
| 2858 | + * @return void |
|
| 2859 | + * @throws EE_Error |
|
| 2860 | + * @throws DomainException |
|
| 2861 | + */ |
|
| 2862 | + public function display_admin_page_with_sidebar() |
|
| 2863 | + { |
|
| 2864 | + $this->_display_admin_page(true); |
|
| 2865 | + } |
|
| 2866 | + |
|
| 2867 | + |
|
| 2868 | + |
|
| 2869 | + /** |
|
| 2870 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2871 | + * |
|
| 2872 | + * @return void |
|
| 2873 | + * @throws EE_Error |
|
| 2874 | + * @throws DomainException |
|
| 2875 | + */ |
|
| 2876 | + public function display_admin_page_with_no_sidebar() |
|
| 2877 | + { |
|
| 2878 | + $this->_display_admin_page(); |
|
| 2879 | + } |
|
| 2880 | + |
|
| 2881 | + |
|
| 2882 | + |
|
| 2883 | + /** |
|
| 2884 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2885 | + * |
|
| 2886 | + * @return void |
|
| 2887 | + * @throws EE_Error |
|
| 2888 | + * @throws DomainException |
|
| 2889 | + */ |
|
| 2890 | + public function display_about_admin_page() |
|
| 2891 | + { |
|
| 2892 | + $this->_display_admin_page(false, true); |
|
| 2893 | + } |
|
| 2894 | + |
|
| 2895 | + |
|
| 2896 | + |
|
| 2897 | + /** |
|
| 2898 | + * display_admin_page |
|
| 2899 | + * contains the code for actually displaying an admin page |
|
| 2900 | + * |
|
| 2901 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2902 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2903 | + * @return void |
|
| 2904 | + * @throws DomainException |
|
| 2905 | + * @throws EE_Error |
|
| 2906 | + */ |
|
| 2907 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2908 | + { |
|
| 2909 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2910 | + //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2911 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2912 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2913 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2914 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2915 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2916 | + ? 'poststuff' |
|
| 2917 | + : 'espresso-default-admin'; |
|
| 2918 | + $template_path = $sidebar |
|
| 2919 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2920 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2921 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2922 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2923 | + } |
|
| 2924 | + $template_path = ! empty($this->_column_template_path) |
|
| 2925 | + ? $this->_column_template_path : $template_path; |
|
| 2926 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2927 | + ? $this->_template_args['admin_page_content'] |
|
| 2928 | + : ''; |
|
| 2929 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2930 | + ? $this->_template_args['before_admin_page_content'] |
|
| 2931 | + : ''; |
|
| 2932 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2933 | + ? $this->_template_args['after_admin_page_content'] |
|
| 2934 | + : ''; |
|
| 2935 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2936 | + $template_path, |
|
| 2937 | + $this->_template_args, |
|
| 2938 | + true |
|
| 2939 | + ); |
|
| 2940 | + // the final template wrapper |
|
| 2941 | + $this->admin_page_wrapper($about); |
|
| 2942 | + } |
|
| 2943 | + |
|
| 2944 | + |
|
| 2945 | + |
|
| 2946 | + /** |
|
| 2947 | + * This is used to display caf preview pages. |
|
| 2948 | + * |
|
| 2949 | + * @since 4.3.2 |
|
| 2950 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2951 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2952 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2953 | + * @return void |
|
| 2954 | + * @throws DomainException |
|
| 2955 | + * @throws EE_Error |
|
| 2956 | + * @throws InvalidArgumentException |
|
| 2957 | + * @throws InvalidDataTypeException |
|
| 2958 | + * @throws InvalidInterfaceException |
|
| 2959 | + */ |
|
| 2960 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2961 | + { |
|
| 2962 | + //let's generate a default preview action button if there isn't one already present. |
|
| 2963 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2964 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2965 | + 'event_espresso' |
|
| 2966 | + ); |
|
| 2967 | + $buy_now_url = add_query_arg( |
|
| 2968 | + array( |
|
| 2969 | + 'ee_ver' => 'ee4', |
|
| 2970 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2971 | + 'utm_medium' => 'link', |
|
| 2972 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2973 | + 'utm_content' => 'buy_now_button', |
|
| 2974 | + ), |
|
| 2975 | + 'http://eventespresso.com/pricing/' |
|
| 2976 | + ); |
|
| 2977 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2978 | + ? $this->get_action_link_or_button( |
|
| 2979 | + '', |
|
| 2980 | + 'buy_now', |
|
| 2981 | + array(), |
|
| 2982 | + 'button-primary button-large', |
|
| 2983 | + $buy_now_url, |
|
| 2984 | + true |
|
| 2985 | + ) |
|
| 2986 | + : $this->_template_args['preview_action_button']; |
|
| 2987 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2988 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2989 | + $this->_template_args, |
|
| 2990 | + true |
|
| 2991 | + ); |
|
| 2992 | + $this->_display_admin_page($display_sidebar); |
|
| 2993 | + } |
|
| 2994 | + |
|
| 2995 | + |
|
| 2996 | + |
|
| 2997 | + /** |
|
| 2998 | + * display_admin_list_table_page_with_sidebar |
|
| 2999 | + * generates HTML wrapper for an admin_page with list_table |
|
| 3000 | + * |
|
| 3001 | + * @return void |
|
| 3002 | + * @throws EE_Error |
|
| 3003 | + * @throws DomainException |
|
| 3004 | + */ |
|
| 3005 | + public function display_admin_list_table_page_with_sidebar() |
|
| 3006 | + { |
|
| 3007 | + $this->_display_admin_list_table_page(true); |
|
| 3008 | + } |
|
| 3009 | + |
|
| 3010 | + |
|
| 3011 | + |
|
| 3012 | + /** |
|
| 3013 | + * display_admin_list_table_page_with_no_sidebar |
|
| 3014 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 3015 | + * |
|
| 3016 | + * @return void |
|
| 3017 | + * @throws EE_Error |
|
| 3018 | + * @throws DomainException |
|
| 3019 | + */ |
|
| 3020 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 3021 | + { |
|
| 3022 | + $this->_display_admin_list_table_page(); |
|
| 3023 | + } |
|
| 3024 | + |
|
| 3025 | + |
|
| 3026 | + |
|
| 3027 | + /** |
|
| 3028 | + * generates html wrapper for an admin_list_table page |
|
| 3029 | + * |
|
| 3030 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 3031 | + * @return void |
|
| 3032 | + * @throws DomainException |
|
| 3033 | + * @throws EE_Error |
|
| 3034 | + */ |
|
| 3035 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 3036 | + { |
|
| 3037 | + //setup search attributes |
|
| 3038 | + $this->_set_search_attributes(); |
|
| 3039 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 3040 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3041 | + $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 3042 | + ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 3043 | + : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 3044 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 3045 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 3046 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 3047 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 3048 | + if (! empty($ajax_sorting_callback)) { |
|
| 3049 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 3050 | + $ajax_sorting_callback . '_nonce', |
|
| 3051 | + $ajax_sorting_callback . '_nonce', |
|
| 3052 | + false, |
|
| 3053 | + false |
|
| 3054 | + ); |
|
| 3055 | + // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 3056 | + // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 3057 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3058 | + . $this->page_slug |
|
| 3059 | + . '" />'; |
|
| 3060 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3061 | + . $ajax_sorting_callback |
|
| 3062 | + . '" />'; |
|
| 3063 | + } else { |
|
| 3064 | + $sortable_list_table_form_fields = ''; |
|
| 3065 | + } |
|
| 3066 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3067 | + $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 3068 | + ? $this->_template_args['list_table_hidden_fields'] |
|
| 3069 | + : ''; |
|
| 3070 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3071 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3072 | + . $nonce_ref |
|
| 3073 | + . '" value="' |
|
| 3074 | + . wp_create_nonce($nonce_ref) |
|
| 3075 | + . '">'; |
|
| 3076 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3077 | + //display message about search results? |
|
| 3078 | + $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 3079 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 3080 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3081 | + trim($this->_req_data['s'], '%') |
|
| 3082 | + ) . '</p>' |
|
| 3083 | + : ''; |
|
| 3084 | + // filter before_list_table template arg |
|
| 3085 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 3086 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3087 | + $this->_template_args['before_list_table'], |
|
| 3088 | + $this->page_slug, |
|
| 3089 | + $this->_req_data, |
|
| 3090 | + $this->_req_action |
|
| 3091 | + ); |
|
| 3092 | + // convert to array and filter again |
|
| 3093 | + // arrays are easier to inject new items in a specific location, |
|
| 3094 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3095 | + $this->_template_args['before_list_table'] = implode( |
|
| 3096 | + " \n", |
|
| 3097 | + (array)apply_filters( |
|
| 3098 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3099 | + (array)$this->_template_args['before_list_table'], |
|
| 3100 | + $this->page_slug, |
|
| 3101 | + $this->_req_data, |
|
| 3102 | + $this->_req_action |
|
| 3103 | + ) |
|
| 3104 | + ); |
|
| 3105 | + // filter after_list_table template arg |
|
| 3106 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 3107 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3108 | + $this->_template_args['after_list_table'], |
|
| 3109 | + $this->page_slug, |
|
| 3110 | + $this->_req_data, |
|
| 3111 | + $this->_req_action |
|
| 3112 | + ); |
|
| 3113 | + // convert to array and filter again |
|
| 3114 | + // arrays are easier to inject new items in a specific location, |
|
| 3115 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3116 | + $this->_template_args['after_list_table'] = implode( |
|
| 3117 | + " \n", |
|
| 3118 | + (array)apply_filters( |
|
| 3119 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3120 | + (array)$this->_template_args['after_list_table'], |
|
| 3121 | + $this->page_slug, |
|
| 3122 | + $this->_req_data, |
|
| 3123 | + $this->_req_action |
|
| 3124 | + ) |
|
| 3125 | + ); |
|
| 3126 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3127 | + $template_path, |
|
| 3128 | + $this->_template_args, |
|
| 3129 | + true |
|
| 3130 | + ); |
|
| 3131 | + // the final template wrapper |
|
| 3132 | + if ($sidebar) { |
|
| 3133 | + $this->display_admin_page_with_sidebar(); |
|
| 3134 | + } else { |
|
| 3135 | + $this->display_admin_page_with_no_sidebar(); |
|
| 3136 | + } |
|
| 3137 | + } |
|
| 3138 | + |
|
| 3139 | + |
|
| 3140 | + |
|
| 3141 | + /** |
|
| 3142 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3143 | + * html string for the legend. |
|
| 3144 | + * $items are expected in an array in the following format: |
|
| 3145 | + * $legend_items = array( |
|
| 3146 | + * 'item_id' => array( |
|
| 3147 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3148 | + * 'desc' => esc_html__('localized description of item'); |
|
| 3149 | + * ) |
|
| 3150 | + * ); |
|
| 3151 | + * |
|
| 3152 | + * @param array $items see above for format of array |
|
| 3153 | + * @return string html string of legend |
|
| 3154 | + * @throws DomainException |
|
| 3155 | + */ |
|
| 3156 | + protected function _display_legend($items) |
|
| 3157 | + { |
|
| 3158 | + $this->_template_args['items'] = apply_filters( |
|
| 3159 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3160 | + (array)$items, |
|
| 3161 | + $this |
|
| 3162 | + ); |
|
| 3163 | + return EEH_Template::display_template( |
|
| 3164 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3165 | + $this->_template_args, |
|
| 3166 | + true |
|
| 3167 | + ); |
|
| 3168 | + } |
|
| 3169 | + |
|
| 3170 | + |
|
| 3171 | + /** |
|
| 3172 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3173 | + * The returned json object is created from an array in the following format: |
|
| 3174 | + * array( |
|
| 3175 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3176 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3177 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3178 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3179 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3180 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3181 | + * that might be included in here) |
|
| 3182 | + * ) |
|
| 3183 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 3184 | + * |
|
| 3185 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3186 | + * instead of displayed. |
|
| 3187 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3188 | + * @return void |
|
| 3189 | + * @throws EE_Error |
|
| 3190 | + */ |
|
| 3191 | + protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3192 | + { |
|
| 3193 | + //make sure any EE_Error notices have been handled. |
|
| 3194 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3195 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3196 | + unset($this->_template_args['data']); |
|
| 3197 | + $json = array( |
|
| 3198 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3199 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3200 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3201 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3202 | + 'notices' => EE_Error::get_notices(), |
|
| 3203 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3204 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 3205 | + 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3206 | + 'isEEajax' => true |
|
| 3207 | + //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3208 | + ); |
|
| 3209 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3210 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 3211 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 3212 | + } |
|
| 3213 | + echo wp_json_encode($json); |
|
| 3214 | + exit(); |
|
| 3215 | + } |
|
| 3216 | + |
|
| 3217 | + |
|
| 3218 | + |
|
| 3219 | + /** |
|
| 3220 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3221 | + * |
|
| 3222 | + * @return void |
|
| 3223 | + * @throws EE_Error |
|
| 3224 | + */ |
|
| 3225 | + public function return_json() |
|
| 3226 | + { |
|
| 3227 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3228 | + $this->_return_json(); |
|
| 3229 | + } else { |
|
| 3230 | + throw new EE_Error( |
|
| 3231 | + sprintf( |
|
| 3232 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3233 | + __FUNCTION__ |
|
| 3234 | + ) |
|
| 3235 | + ); |
|
| 3236 | + } |
|
| 3237 | + } |
|
| 3238 | + |
|
| 3239 | + |
|
| 3240 | + |
|
| 3241 | + /** |
|
| 3242 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3243 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3244 | + * |
|
| 3245 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3246 | + */ |
|
| 3247 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3248 | + { |
|
| 3249 | + $this->_hook_obj = $hook_obj; |
|
| 3250 | + } |
|
| 3251 | + |
|
| 3252 | + |
|
| 3253 | + |
|
| 3254 | + /** |
|
| 3255 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3256 | + * |
|
| 3257 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3258 | + * @return void |
|
| 3259 | + * @throws DomainException |
|
| 3260 | + * @throws EE_Error |
|
| 3261 | + */ |
|
| 3262 | + public function admin_page_wrapper($about = false) |
|
| 3263 | + { |
|
| 3264 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3265 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3266 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3267 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3268 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3269 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3270 | + isset($this->_template_args['before_admin_page_content']) |
|
| 3271 | + ? $this->_template_args['before_admin_page_content'] |
|
| 3272 | + : '' |
|
| 3273 | + ); |
|
| 3274 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3275 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3276 | + isset($this->_template_args['after_admin_page_content']) |
|
| 3277 | + ? $this->_template_args['after_admin_page_content'] |
|
| 3278 | + : '' |
|
| 3279 | + ); |
|
| 3280 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3281 | + // load settings page wrapper template |
|
| 3282 | + $template_path = ! defined('DOING_AJAX') |
|
| 3283 | + ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3284 | + : EE_ADMIN_TEMPLATE |
|
| 3285 | + . 'admin_wrapper_ajax.template.php'; |
|
| 3286 | + //about page? |
|
| 3287 | + $template_path = $about |
|
| 3288 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3289 | + : $template_path; |
|
| 3290 | + if (defined('DOING_AJAX')) { |
|
| 3291 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3292 | + $template_path, |
|
| 3293 | + $this->_template_args, |
|
| 3294 | + true |
|
| 3295 | + ); |
|
| 3296 | + $this->_return_json(); |
|
| 3297 | + } else { |
|
| 3298 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3299 | + } |
|
| 3300 | + } |
|
| 3301 | + |
|
| 3302 | + |
|
| 3303 | + |
|
| 3304 | + /** |
|
| 3305 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3306 | + * |
|
| 3307 | + * @return string html |
|
| 3308 | + * @throws EE_Error |
|
| 3309 | + */ |
|
| 3310 | + protected function _get_main_nav_tabs() |
|
| 3311 | + { |
|
| 3312 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3313 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3314 | + // (rather than setting in the page_routes array) |
|
| 3315 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3316 | + } |
|
| 3317 | + |
|
| 3318 | + |
|
| 3319 | + |
|
| 3320 | + /** |
|
| 3321 | + * sort nav tabs |
|
| 3322 | + * |
|
| 3323 | + * @param $a |
|
| 3324 | + * @param $b |
|
| 3325 | + * @return int |
|
| 3326 | + */ |
|
| 3327 | + private function _sort_nav_tabs($a, $b) |
|
| 3328 | + { |
|
| 3329 | + if ($a['order'] === $b['order']) { |
|
| 3330 | + return 0; |
|
| 3331 | + } |
|
| 3332 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3333 | + } |
|
| 3334 | + |
|
| 3335 | + |
|
| 3336 | + |
|
| 3337 | + /** |
|
| 3338 | + * generates HTML for the forms used on admin pages |
|
| 3339 | + * |
|
| 3340 | + * @param array $input_vars - array of input field details |
|
| 3341 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3342 | + * use) |
|
| 3343 | + * @param bool $id |
|
| 3344 | + * @return string |
|
| 3345 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3346 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3347 | + */ |
|
| 3348 | + protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 3349 | + { |
|
| 3350 | + $content = $generator === 'string' |
|
| 3351 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3352 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3353 | + return $content; |
|
| 3354 | + } |
|
| 3355 | + |
|
| 3356 | + |
|
| 3357 | + |
|
| 3358 | + /** |
|
| 3359 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3360 | + * |
|
| 3361 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3362 | + * Close" button. |
|
| 3363 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3364 | + * 'Save', [1] => 'save & close') |
|
| 3365 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3366 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3367 | + * default actions by submitting some other value. |
|
| 3368 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3369 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3370 | + * close (normal form handling). |
|
| 3371 | + */ |
|
| 3372 | + protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3373 | + { |
|
| 3374 | + //make sure $text and $actions are in an array |
|
| 3375 | + $text = (array)$text; |
|
| 3376 | + $actions = (array)$actions; |
|
| 3377 | + $referrer_url = empty($referrer) |
|
| 3378 | + ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3379 | + . $_SERVER['REQUEST_URI'] |
|
| 3380 | + . '" />' |
|
| 3381 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3382 | + . $referrer |
|
| 3383 | + . '" />'; |
|
| 3384 | + $button_text = ! empty($text) |
|
| 3385 | + ? $text |
|
| 3386 | + : array( |
|
| 3387 | + esc_html__('Save', 'event_espresso'), |
|
| 3388 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3389 | + ); |
|
| 3390 | + $default_names = array('save', 'save_and_close'); |
|
| 3391 | + //add in a hidden index for the current page (so save and close redirects properly) |
|
| 3392 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3393 | + foreach ($button_text as $key => $button) { |
|
| 3394 | + $ref = $default_names[$key]; |
|
| 3395 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3396 | + . $ref |
|
| 3397 | + . '" value="' |
|
| 3398 | + . $button |
|
| 3399 | + . '" name="' |
|
| 3400 | + . (! empty($actions) ? $actions[$key] : $ref) |
|
| 3401 | + . '" id="' |
|
| 3402 | + . $this->_current_view . '_' . $ref |
|
| 3403 | + . '" />'; |
|
| 3404 | + if (! $both) { |
|
| 3405 | + break; |
|
| 3406 | + } |
|
| 3407 | + } |
|
| 3408 | + } |
|
| 3409 | + |
|
| 3410 | + |
|
| 3411 | + |
|
| 3412 | + /** |
|
| 3413 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3414 | + * |
|
| 3415 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3416 | + * @since 4.6.0 |
|
| 3417 | + * @param string $route |
|
| 3418 | + * @param array $additional_hidden_fields |
|
| 3419 | + */ |
|
| 3420 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3421 | + { |
|
| 3422 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3423 | + } |
|
| 3424 | + |
|
| 3425 | + |
|
| 3426 | + |
|
| 3427 | + /** |
|
| 3428 | + * set form open and close tags on add/edit pages. |
|
| 3429 | + * |
|
| 3430 | + * @param string $route the route you want the form to direct to |
|
| 3431 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3432 | + * @return void |
|
| 3433 | + */ |
|
| 3434 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3435 | + { |
|
| 3436 | + if (empty($route)) { |
|
| 3437 | + $user_msg = esc_html__( |
|
| 3438 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3439 | + 'event_espresso' |
|
| 3440 | + ); |
|
| 3441 | + $dev_msg = $user_msg . "\n" . sprintf( |
|
| 3442 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3443 | + __FUNCTION__, |
|
| 3444 | + __CLASS__ |
|
| 3445 | + ); |
|
| 3446 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3447 | + } |
|
| 3448 | + // open form |
|
| 3449 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3450 | + . $this->_admin_base_url |
|
| 3451 | + . '" id="' |
|
| 3452 | + . $route |
|
| 3453 | + . '_event_form" >'; |
|
| 3454 | + // add nonce |
|
| 3455 | + $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3456 | + // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 3457 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3458 | + // add REQUIRED form action |
|
| 3459 | + $hidden_fields = array( |
|
| 3460 | + 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3461 | + ); |
|
| 3462 | + // merge arrays |
|
| 3463 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3464 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3465 | + : $hidden_fields; |
|
| 3466 | + // generate form fields |
|
| 3467 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3468 | + // add fields to form |
|
| 3469 | + foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 3470 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3471 | + } |
|
| 3472 | + // close form |
|
| 3473 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3474 | + } |
|
| 3475 | + |
|
| 3476 | + |
|
| 3477 | + |
|
| 3478 | + /** |
|
| 3479 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3480 | + * discovered it would be useful for external code to have access. |
|
| 3481 | + * |
|
| 3482 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3483 | + * @since 4.5.0 |
|
| 3484 | + * @param bool $success |
|
| 3485 | + * @param string $what |
|
| 3486 | + * @param string $action_desc |
|
| 3487 | + * @param array $query_args |
|
| 3488 | + * @param bool $override_overwrite |
|
| 3489 | + * @throws EE_Error |
|
| 3490 | + */ |
|
| 3491 | + public function redirect_after_action( |
|
| 3492 | + $success = false, |
|
| 3493 | + $what = 'item', |
|
| 3494 | + $action_desc = 'processed', |
|
| 3495 | + $query_args = array(), |
|
| 3496 | + $override_overwrite = false |
|
| 3497 | + ) { |
|
| 3498 | + $this->_redirect_after_action( |
|
| 3499 | + $success, |
|
| 3500 | + $what, |
|
| 3501 | + $action_desc, |
|
| 3502 | + $query_args, |
|
| 3503 | + $override_overwrite |
|
| 3504 | + ); |
|
| 3505 | + } |
|
| 3506 | + |
|
| 3507 | + |
|
| 3508 | + |
|
| 3509 | + /** |
|
| 3510 | + * _redirect_after_action |
|
| 3511 | + * |
|
| 3512 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3513 | + * @param string $what - what the action was performed on |
|
| 3514 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3515 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3516 | + * action is completed |
|
| 3517 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3518 | + * override this so that they show. |
|
| 3519 | + * @return void |
|
| 3520 | + * @throws EE_Error |
|
| 3521 | + */ |
|
| 3522 | + protected function _redirect_after_action( |
|
| 3523 | + $success = 0, |
|
| 3524 | + $what = 'item', |
|
| 3525 | + $action_desc = 'processed', |
|
| 3526 | + $query_args = array(), |
|
| 3527 | + $override_overwrite = false |
|
| 3528 | + ) { |
|
| 3529 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3530 | + //class name for actions/filters. |
|
| 3531 | + $classname = get_class($this); |
|
| 3532 | + // set redirect url. |
|
| 3533 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3534 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3535 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3536 | + $notices = EE_Error::get_notices(false); |
|
| 3537 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3538 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3539 | + EE_Error::overwrite_success(); |
|
| 3540 | + } |
|
| 3541 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3542 | + // how many records affected ? more than one record ? or just one ? |
|
| 3543 | + if ($success > 1) { |
|
| 3544 | + // set plural msg |
|
| 3545 | + EE_Error::add_success( |
|
| 3546 | + sprintf( |
|
| 3547 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3548 | + $what, |
|
| 3549 | + $action_desc |
|
| 3550 | + ), |
|
| 3551 | + __FILE__, |
|
| 3552 | + __FUNCTION__, |
|
| 3553 | + __LINE__ |
|
| 3554 | + ); |
|
| 3555 | + } elseif ($success === 1) { |
|
| 3556 | + // set singular msg |
|
| 3557 | + EE_Error::add_success( |
|
| 3558 | + sprintf( |
|
| 3559 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3560 | + $what, |
|
| 3561 | + $action_desc |
|
| 3562 | + ), |
|
| 3563 | + __FILE__, |
|
| 3564 | + __FUNCTION__, |
|
| 3565 | + __LINE__ |
|
| 3566 | + ); |
|
| 3567 | + } |
|
| 3568 | + } |
|
| 3569 | + // check that $query_args isn't something crazy |
|
| 3570 | + if (! is_array($query_args)) { |
|
| 3571 | + $query_args = array(); |
|
| 3572 | + } |
|
| 3573 | + /** |
|
| 3574 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3575 | + * redirections on save and close actions |
|
| 3576 | + * |
|
| 3577 | + * @since 4.2.0 |
|
| 3578 | + * @param array $query_args The original query_args array coming into the |
|
| 3579 | + * method. |
|
| 3580 | + */ |
|
| 3581 | + do_action( |
|
| 3582 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3583 | + $query_args |
|
| 3584 | + ); |
|
| 3585 | + //calculate where we're going (if we have a "save and close" button pushed) |
|
| 3586 | + if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3587 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3588 | + $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3589 | + // regenerate query args array from referrer URL |
|
| 3590 | + parse_str($parsed_url['query'], $query_args); |
|
| 3591 | + // correct page and action will be in the query args now |
|
| 3592 | + $redirect_url = admin_url('admin.php'); |
|
| 3593 | + } |
|
| 3594 | + //merge any default query_args set in _default_route_query_args property |
|
| 3595 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3596 | + $args_to_merge = array(); |
|
| 3597 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3598 | + //is there a wp_referer array in our _default_route_query_args property? |
|
| 3599 | + if ($query_param === 'wp_referer') { |
|
| 3600 | + $query_value = (array)$query_value; |
|
| 3601 | + foreach ($query_value as $reference => $value) { |
|
| 3602 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3603 | + continue; |
|
| 3604 | + } |
|
| 3605 | + //finally we will override any arguments in the referer with |
|
| 3606 | + //what might be set on the _default_route_query_args array. |
|
| 3607 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3608 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3609 | + } else { |
|
| 3610 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3611 | + } |
|
| 3612 | + } |
|
| 3613 | + continue; |
|
| 3614 | + } |
|
| 3615 | + $args_to_merge[$query_param] = $query_value; |
|
| 3616 | + } |
|
| 3617 | + //now let's merge these arguments but override with what was specifically sent in to the |
|
| 3618 | + //redirect. |
|
| 3619 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3620 | + } |
|
| 3621 | + $this->_process_notices($query_args); |
|
| 3622 | + // generate redirect url |
|
| 3623 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3624 | + if (isset($query_args['action'])) { |
|
| 3625 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3626 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3627 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3628 | + } |
|
| 3629 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3630 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3631 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3632 | + $redirect_url = apply_filters( |
|
| 3633 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3634 | + self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3635 | + $query_args |
|
| 3636 | + ); |
|
| 3637 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3638 | + if (defined('DOING_AJAX')) { |
|
| 3639 | + $default_data = array( |
|
| 3640 | + 'close' => true, |
|
| 3641 | + 'redirect_url' => $redirect_url, |
|
| 3642 | + 'where' => 'main', |
|
| 3643 | + 'what' => 'append', |
|
| 3644 | + ); |
|
| 3645 | + $this->_template_args['success'] = $success; |
|
| 3646 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3647 | + $default_data, |
|
| 3648 | + $this->_template_args['data'] |
|
| 3649 | + ) : $default_data; |
|
| 3650 | + $this->_return_json(); |
|
| 3651 | + } |
|
| 3652 | + wp_safe_redirect($redirect_url); |
|
| 3653 | + exit(); |
|
| 3654 | + } |
|
| 3655 | + |
|
| 3656 | + |
|
| 3657 | + |
|
| 3658 | + /** |
|
| 3659 | + * process any notices before redirecting (or returning ajax request) |
|
| 3660 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3661 | + * |
|
| 3662 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3663 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3664 | + * page_routes haven't been defined yet. |
|
| 3665 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3666 | + * still save a transient for the notice. |
|
| 3667 | + * @return void |
|
| 3668 | + * @throws EE_Error |
|
| 3669 | + */ |
|
| 3670 | + protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3671 | + { |
|
| 3672 | + //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3673 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3674 | + $notices = EE_Error::get_notices(false); |
|
| 3675 | + if (empty($this->_template_args['success'])) { |
|
| 3676 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3677 | + } |
|
| 3678 | + if (empty($this->_template_args['errors'])) { |
|
| 3679 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3680 | + } |
|
| 3681 | + if (empty($this->_template_args['attention'])) { |
|
| 3682 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3683 | + } |
|
| 3684 | + } |
|
| 3685 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3686 | + //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3687 | + if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3688 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3689 | + $this->_add_transient( |
|
| 3690 | + $route, |
|
| 3691 | + $this->_template_args['notices'], |
|
| 3692 | + true, |
|
| 3693 | + $skip_route_verify |
|
| 3694 | + ); |
|
| 3695 | + } |
|
| 3696 | + } |
|
| 3697 | + |
|
| 3698 | + |
|
| 3699 | + |
|
| 3700 | + /** |
|
| 3701 | + * get_action_link_or_button |
|
| 3702 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3703 | + * |
|
| 3704 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3705 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3706 | + * property. |
|
| 3707 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3708 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3709 | + * @param string $base_url If this is not provided |
|
| 3710 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3711 | + * Otherwise this value will be used. |
|
| 3712 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3713 | + * @return string |
|
| 3714 | + * @throws InvalidArgumentException |
|
| 3715 | + * @throws InvalidInterfaceException |
|
| 3716 | + * @throws InvalidDataTypeException |
|
| 3717 | + * @throws EE_Error |
|
| 3718 | + */ |
|
| 3719 | + public function get_action_link_or_button( |
|
| 3720 | + $action, |
|
| 3721 | + $type = 'add', |
|
| 3722 | + $extra_request = array(), |
|
| 3723 | + $class = 'button-primary', |
|
| 3724 | + $base_url = '', |
|
| 3725 | + $exclude_nonce = false |
|
| 3726 | + ) { |
|
| 3727 | + //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3728 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3729 | + throw new EE_Error( |
|
| 3730 | + sprintf( |
|
| 3731 | + esc_html__( |
|
| 3732 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3733 | + 'event_espresso' |
|
| 3734 | + ), |
|
| 3735 | + $action |
|
| 3736 | + ) |
|
| 3737 | + ); |
|
| 3738 | + } |
|
| 3739 | + if (! isset($this->_labels['buttons'][$type])) { |
|
| 3740 | + throw new EE_Error( |
|
| 3741 | + sprintf( |
|
| 3742 | + __( |
|
| 3743 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3744 | + 'event_espresso' |
|
| 3745 | + ), |
|
| 3746 | + $type |
|
| 3747 | + ) |
|
| 3748 | + ); |
|
| 3749 | + } |
|
| 3750 | + //finally check user access for this button. |
|
| 3751 | + $has_access = $this->check_user_access($action, true); |
|
| 3752 | + if (! $has_access) { |
|
| 3753 | + return ''; |
|
| 3754 | + } |
|
| 3755 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3756 | + $query_args = array( |
|
| 3757 | + 'action' => $action, |
|
| 3758 | + ); |
|
| 3759 | + //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3760 | + if (! empty($extra_request)) { |
|
| 3761 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3762 | + } |
|
| 3763 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3764 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3765 | + } |
|
| 3766 | + |
|
| 3767 | + |
|
| 3768 | + |
|
| 3769 | + /** |
|
| 3770 | + * _per_page_screen_option |
|
| 3771 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3772 | + * |
|
| 3773 | + * @return void |
|
| 3774 | + * @throws InvalidArgumentException |
|
| 3775 | + * @throws InvalidInterfaceException |
|
| 3776 | + * @throws InvalidDataTypeException |
|
| 3777 | + */ |
|
| 3778 | + protected function _per_page_screen_option() |
|
| 3779 | + { |
|
| 3780 | + $option = 'per_page'; |
|
| 3781 | + $args = array( |
|
| 3782 | + 'label' => esc_html__( |
|
| 3783 | + apply_filters( |
|
| 3784 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3785 | + $this->_admin_page_title, |
|
| 3786 | + $this |
|
| 3787 | + ) |
|
| 3788 | + ), |
|
| 3789 | + 'default' => (int) apply_filters( |
|
| 3790 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3791 | + 10 |
|
| 3792 | + ), |
|
| 3793 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3794 | + ); |
|
| 3795 | + //ONLY add the screen option if the user has access to it. |
|
| 3796 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3797 | + add_screen_option($option, $args); |
|
| 3798 | + } |
|
| 3799 | + } |
|
| 3800 | + |
|
| 3801 | + |
|
| 3802 | + |
|
| 3803 | + /** |
|
| 3804 | + * set_per_page_screen_option |
|
| 3805 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3806 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3807 | + * admin_menu. |
|
| 3808 | + * |
|
| 3809 | + * @return void |
|
| 3810 | + */ |
|
| 3811 | + private function _set_per_page_screen_options() |
|
| 3812 | + { |
|
| 3813 | + if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3814 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3815 | + if (! $user = wp_get_current_user()) { |
|
| 3816 | + return; |
|
| 3817 | + } |
|
| 3818 | + $option = $_POST['wp_screen_options']['option']; |
|
| 3819 | + $value = $_POST['wp_screen_options']['value']; |
|
| 3820 | + if ($option != sanitize_key($option)) { |
|
| 3821 | + return; |
|
| 3822 | + } |
|
| 3823 | + $map_option = $option; |
|
| 3824 | + $option = str_replace('-', '_', $option); |
|
| 3825 | + switch ($map_option) { |
|
| 3826 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3827 | + $value = (int)$value; |
|
| 3828 | + $max_value = apply_filters( |
|
| 3829 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3830 | + 999, |
|
| 3831 | + $this->_current_page, |
|
| 3832 | + $this->_current_view |
|
| 3833 | + ); |
|
| 3834 | + if ($value < 1) { |
|
| 3835 | + return; |
|
| 3836 | + } |
|
| 3837 | + $value = min($value, $max_value); |
|
| 3838 | + break; |
|
| 3839 | + default: |
|
| 3840 | + $value = apply_filters( |
|
| 3841 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3842 | + false, |
|
| 3843 | + $option, |
|
| 3844 | + $value |
|
| 3845 | + ); |
|
| 3846 | + if (false === $value) { |
|
| 3847 | + return; |
|
| 3848 | + } |
|
| 3849 | + break; |
|
| 3850 | + } |
|
| 3851 | + update_user_meta($user->ID, $option, $value); |
|
| 3852 | + wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3853 | + exit; |
|
| 3854 | + } |
|
| 3855 | + } |
|
| 3856 | + |
|
| 3857 | + |
|
| 3858 | + |
|
| 3859 | + /** |
|
| 3860 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3861 | + * |
|
| 3862 | + * @param array $data array that will be assigned to template args. |
|
| 3863 | + */ |
|
| 3864 | + public function set_template_args($data) |
|
| 3865 | + { |
|
| 3866 | + $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3867 | + } |
|
| 3868 | + |
|
| 3869 | + |
|
| 3870 | + |
|
| 3871 | + /** |
|
| 3872 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3873 | + * |
|
| 3874 | + * @param string $route the route that should receive the transient |
|
| 3875 | + * @param array $data the data that gets sent |
|
| 3876 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3877 | + * normal route transient. |
|
| 3878 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3879 | + * when we are adding a transient before page_routes have been defined. |
|
| 3880 | + * @return void |
|
| 3881 | + * @throws EE_Error |
|
| 3882 | + */ |
|
| 3883 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3884 | + { |
|
| 3885 | + $user_id = get_current_user_id(); |
|
| 3886 | + if (! $skip_route_verify) { |
|
| 3887 | + $this->_verify_route($route); |
|
| 3888 | + } |
|
| 3889 | + //now let's set the string for what kind of transient we're setting |
|
| 3890 | + $transient = $notices |
|
| 3891 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3892 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3893 | + $data = $notices ? array('notices' => $data) : $data; |
|
| 3894 | + //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3895 | + $existing = is_multisite() && is_network_admin() |
|
| 3896 | + ? get_site_transient($transient) |
|
| 3897 | + : get_transient($transient); |
|
| 3898 | + if ($existing) { |
|
| 3899 | + $data = array_merge((array)$data, (array)$existing); |
|
| 3900 | + } |
|
| 3901 | + if (is_multisite() && is_network_admin()) { |
|
| 3902 | + set_site_transient($transient, $data, 8); |
|
| 3903 | + } else { |
|
| 3904 | + set_transient($transient, $data, 8); |
|
| 3905 | + } |
|
| 3906 | + } |
|
| 3907 | + |
|
| 3908 | + |
|
| 3909 | + |
|
| 3910 | + /** |
|
| 3911 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3912 | + * |
|
| 3913 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3914 | + * @param string $route |
|
| 3915 | + * @return mixed data |
|
| 3916 | + */ |
|
| 3917 | + protected function _get_transient($notices = false, $route = '') |
|
| 3918 | + { |
|
| 3919 | + $user_id = get_current_user_id(); |
|
| 3920 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3921 | + $transient = $notices |
|
| 3922 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3923 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3924 | + $data = is_multisite() && is_network_admin() |
|
| 3925 | + ? get_site_transient($transient) |
|
| 3926 | + : get_transient($transient); |
|
| 3927 | + //delete transient after retrieval (just in case it hasn't expired); |
|
| 3928 | + if (is_multisite() && is_network_admin()) { |
|
| 3929 | + delete_site_transient($transient); |
|
| 3930 | + } else { |
|
| 3931 | + delete_transient($transient); |
|
| 3932 | + } |
|
| 3933 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3934 | + } |
|
| 3935 | + |
|
| 3936 | + |
|
| 3937 | + |
|
| 3938 | + /** |
|
| 3939 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3940 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3941 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3942 | + * |
|
| 3943 | + * @return void |
|
| 3944 | + */ |
|
| 3945 | + protected function _transient_garbage_collection() |
|
| 3946 | + { |
|
| 3947 | + global $wpdb; |
|
| 3948 | + //retrieve all existing transients |
|
| 3949 | + $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3950 | + if ($results = $wpdb->get_results($query)) { |
|
| 3951 | + foreach ($results as $result) { |
|
| 3952 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3953 | + get_transient($transient); |
|
| 3954 | + if (is_multisite() && is_network_admin()) { |
|
| 3955 | + get_site_transient($transient); |
|
| 3956 | + } |
|
| 3957 | + } |
|
| 3958 | + } |
|
| 3959 | + } |
|
| 3960 | + |
|
| 3961 | + |
|
| 3962 | + |
|
| 3963 | + /** |
|
| 3964 | + * get_view |
|
| 3965 | + * |
|
| 3966 | + * @return string content of _view property |
|
| 3967 | + */ |
|
| 3968 | + public function get_view() |
|
| 3969 | + { |
|
| 3970 | + return $this->_view; |
|
| 3971 | + } |
|
| 3972 | + |
|
| 3973 | + |
|
| 3974 | + |
|
| 3975 | + /** |
|
| 3976 | + * getter for the protected $_views property |
|
| 3977 | + * |
|
| 3978 | + * @return array |
|
| 3979 | + */ |
|
| 3980 | + public function get_views() |
|
| 3981 | + { |
|
| 3982 | + return $this->_views; |
|
| 3983 | + } |
|
| 3984 | + |
|
| 3985 | + |
|
| 3986 | + |
|
| 3987 | + /** |
|
| 3988 | + * get_current_page |
|
| 3989 | + * |
|
| 3990 | + * @return string _current_page property value |
|
| 3991 | + */ |
|
| 3992 | + public function get_current_page() |
|
| 3993 | + { |
|
| 3994 | + return $this->_current_page; |
|
| 3995 | + } |
|
| 3996 | + |
|
| 3997 | + |
|
| 3998 | + |
|
| 3999 | + /** |
|
| 4000 | + * get_current_view |
|
| 4001 | + * |
|
| 4002 | + * @return string _current_view property value |
|
| 4003 | + */ |
|
| 4004 | + public function get_current_view() |
|
| 4005 | + { |
|
| 4006 | + return $this->_current_view; |
|
| 4007 | + } |
|
| 4008 | + |
|
| 4009 | + |
|
| 4010 | + |
|
| 4011 | + /** |
|
| 4012 | + * get_current_screen |
|
| 4013 | + * |
|
| 4014 | + * @return object The current WP_Screen object |
|
| 4015 | + */ |
|
| 4016 | + public function get_current_screen() |
|
| 4017 | + { |
|
| 4018 | + return $this->_current_screen; |
|
| 4019 | + } |
|
| 4020 | + |
|
| 4021 | + |
|
| 4022 | + |
|
| 4023 | + /** |
|
| 4024 | + * get_current_page_view_url |
|
| 4025 | + * |
|
| 4026 | + * @return string This returns the url for the current_page_view. |
|
| 4027 | + */ |
|
| 4028 | + public function get_current_page_view_url() |
|
| 4029 | + { |
|
| 4030 | + return $this->_current_page_view_url; |
|
| 4031 | + } |
|
| 4032 | + |
|
| 4033 | + |
|
| 4034 | + |
|
| 4035 | + /** |
|
| 4036 | + * just returns the _req_data property |
|
| 4037 | + * |
|
| 4038 | + * @return array |
|
| 4039 | + */ |
|
| 4040 | + public function get_request_data() |
|
| 4041 | + { |
|
| 4042 | + return $this->_req_data; |
|
| 4043 | + } |
|
| 4044 | + |
|
| 4045 | + |
|
| 4046 | + |
|
| 4047 | + /** |
|
| 4048 | + * returns the _req_data protected property |
|
| 4049 | + * |
|
| 4050 | + * @return string |
|
| 4051 | + */ |
|
| 4052 | + public function get_req_action() |
|
| 4053 | + { |
|
| 4054 | + return $this->_req_action; |
|
| 4055 | + } |
|
| 4056 | + |
|
| 4057 | + |
|
| 4058 | + |
|
| 4059 | + /** |
|
| 4060 | + * @return bool value of $_is_caf property |
|
| 4061 | + */ |
|
| 4062 | + public function is_caf() |
|
| 4063 | + { |
|
| 4064 | + return $this->_is_caf; |
|
| 4065 | + } |
|
| 4066 | + |
|
| 4067 | + |
|
| 4068 | + |
|
| 4069 | + /** |
|
| 4070 | + * @return mixed |
|
| 4071 | + */ |
|
| 4072 | + public function default_espresso_metaboxes() |
|
| 4073 | + { |
|
| 4074 | + return $this->_default_espresso_metaboxes; |
|
| 4075 | + } |
|
| 4076 | + |
|
| 4077 | + |
|
| 4078 | + |
|
| 4079 | + /** |
|
| 4080 | + * @return mixed |
|
| 4081 | + */ |
|
| 4082 | + public function admin_base_url() |
|
| 4083 | + { |
|
| 4084 | + return $this->_admin_base_url; |
|
| 4085 | + } |
|
| 4086 | 4086 | |
| 4087 | 4087 | |
| 4088 | 4088 | |
| 4089 | - /** |
|
| 4090 | - * @return mixed |
|
| 4091 | - */ |
|
| 4092 | - public function wp_page_slug() |
|
| 4093 | - { |
|
| 4094 | - return $this->_wp_page_slug; |
|
| 4095 | - } |
|
| 4089 | + /** |
|
| 4090 | + * @return mixed |
|
| 4091 | + */ |
|
| 4092 | + public function wp_page_slug() |
|
| 4093 | + { |
|
| 4094 | + return $this->_wp_page_slug; |
|
| 4095 | + } |
|
| 4096 | 4096 | |
| 4097 | 4097 | |
| 4098 | - |
|
| 4099 | - /** |
|
| 4100 | - * updates espresso configuration settings |
|
| 4101 | - * |
|
| 4102 | - * @param string $tab |
|
| 4103 | - * @param EE_Config_Base|EE_Config $config |
|
| 4104 | - * @param string $file file where error occurred |
|
| 4105 | - * @param string $func function where error occurred |
|
| 4106 | - * @param string $line line no where error occurred |
|
| 4107 | - * @return boolean |
|
| 4108 | - */ |
|
| 4109 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4110 | - { |
|
| 4111 | - //remove any options that are NOT going to be saved with the config settings. |
|
| 4112 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 4113 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4114 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4115 | - update_option('ee_ueip_has_notified', true); |
|
| 4116 | - } |
|
| 4117 | - // and save it (note we're also doing the network save here) |
|
| 4118 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4119 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4120 | - if ($config_saved && $net_saved) { |
|
| 4121 | - EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4122 | - return true; |
|
| 4123 | - } |
|
| 4124 | - EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4125 | - return false; |
|
| 4126 | - } |
|
| 4127 | - |
|
| 4128 | - |
|
| 4129 | - |
|
| 4130 | - /** |
|
| 4131 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4132 | - * |
|
| 4133 | - * @return array |
|
| 4134 | - */ |
|
| 4135 | - public function get_yes_no_values() |
|
| 4136 | - { |
|
| 4137 | - return $this->_yes_no_values; |
|
| 4138 | - } |
|
| 4139 | - |
|
| 4140 | - |
|
| 4141 | - |
|
| 4142 | - protected function _get_dir() |
|
| 4143 | - { |
|
| 4144 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 4145 | - return dirname($reflector->getFileName()); |
|
| 4146 | - } |
|
| 4147 | - |
|
| 4148 | - |
|
| 4149 | - |
|
| 4150 | - /** |
|
| 4151 | - * A helper for getting a "next link". |
|
| 4152 | - * |
|
| 4153 | - * @param string $url The url to link to |
|
| 4154 | - * @param string $class The class to use. |
|
| 4155 | - * @return string |
|
| 4156 | - */ |
|
| 4157 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4158 | - { |
|
| 4159 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4160 | - } |
|
| 4161 | - |
|
| 4162 | - |
|
| 4163 | - |
|
| 4164 | - /** |
|
| 4165 | - * A helper for getting a "previous link". |
|
| 4166 | - * |
|
| 4167 | - * @param string $url The url to link to |
|
| 4168 | - * @param string $class The class to use. |
|
| 4169 | - * @return string |
|
| 4170 | - */ |
|
| 4171 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4172 | - { |
|
| 4173 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4174 | - } |
|
| 4175 | - |
|
| 4176 | - |
|
| 4177 | - |
|
| 4178 | - |
|
| 4179 | - |
|
| 4180 | - |
|
| 4181 | - |
|
| 4182 | - //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4183 | - |
|
| 4184 | - |
|
| 4185 | - /** |
|
| 4186 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4187 | - * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4188 | - * _req_data array. |
|
| 4189 | - * |
|
| 4190 | - * @return bool success/fail |
|
| 4191 | - * @throws EE_Error |
|
| 4192 | - * @throws InvalidArgumentException |
|
| 4193 | - * @throws ReflectionException |
|
| 4194 | - * @throws InvalidDataTypeException |
|
| 4195 | - * @throws InvalidInterfaceException |
|
| 4196 | - */ |
|
| 4197 | - protected function _process_resend_registration() |
|
| 4198 | - { |
|
| 4199 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4200 | - do_action( |
|
| 4201 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4202 | - $this->_template_args['success'], |
|
| 4203 | - $this->_req_data |
|
| 4204 | - ); |
|
| 4205 | - return $this->_template_args['success']; |
|
| 4206 | - } |
|
| 4207 | - |
|
| 4208 | - |
|
| 4209 | - |
|
| 4210 | - /** |
|
| 4211 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4212 | - * |
|
| 4213 | - * @param \EE_Payment $payment |
|
| 4214 | - * @return bool success/fail |
|
| 4215 | - */ |
|
| 4216 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 4217 | - { |
|
| 4218 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4219 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4220 | - $this->_template_args['success'] = apply_filters( |
|
| 4221 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4222 | - false, |
|
| 4223 | - $payment |
|
| 4224 | - ); |
|
| 4225 | - return $this->_template_args['success']; |
|
| 4226 | - } |
|
| 4098 | + |
|
| 4099 | + /** |
|
| 4100 | + * updates espresso configuration settings |
|
| 4101 | + * |
|
| 4102 | + * @param string $tab |
|
| 4103 | + * @param EE_Config_Base|EE_Config $config |
|
| 4104 | + * @param string $file file where error occurred |
|
| 4105 | + * @param string $func function where error occurred |
|
| 4106 | + * @param string $line line no where error occurred |
|
| 4107 | + * @return boolean |
|
| 4108 | + */ |
|
| 4109 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4110 | + { |
|
| 4111 | + //remove any options that are NOT going to be saved with the config settings. |
|
| 4112 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 4113 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4114 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4115 | + update_option('ee_ueip_has_notified', true); |
|
| 4116 | + } |
|
| 4117 | + // and save it (note we're also doing the network save here) |
|
| 4118 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4119 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4120 | + if ($config_saved && $net_saved) { |
|
| 4121 | + EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4122 | + return true; |
|
| 4123 | + } |
|
| 4124 | + EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4125 | + return false; |
|
| 4126 | + } |
|
| 4127 | + |
|
| 4128 | + |
|
| 4129 | + |
|
| 4130 | + /** |
|
| 4131 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4132 | + * |
|
| 4133 | + * @return array |
|
| 4134 | + */ |
|
| 4135 | + public function get_yes_no_values() |
|
| 4136 | + { |
|
| 4137 | + return $this->_yes_no_values; |
|
| 4138 | + } |
|
| 4139 | + |
|
| 4140 | + |
|
| 4141 | + |
|
| 4142 | + protected function _get_dir() |
|
| 4143 | + { |
|
| 4144 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 4145 | + return dirname($reflector->getFileName()); |
|
| 4146 | + } |
|
| 4147 | + |
|
| 4148 | + |
|
| 4149 | + |
|
| 4150 | + /** |
|
| 4151 | + * A helper for getting a "next link". |
|
| 4152 | + * |
|
| 4153 | + * @param string $url The url to link to |
|
| 4154 | + * @param string $class The class to use. |
|
| 4155 | + * @return string |
|
| 4156 | + */ |
|
| 4157 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4158 | + { |
|
| 4159 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4160 | + } |
|
| 4161 | + |
|
| 4162 | + |
|
| 4163 | + |
|
| 4164 | + /** |
|
| 4165 | + * A helper for getting a "previous link". |
|
| 4166 | + * |
|
| 4167 | + * @param string $url The url to link to |
|
| 4168 | + * @param string $class The class to use. |
|
| 4169 | + * @return string |
|
| 4170 | + */ |
|
| 4171 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4172 | + { |
|
| 4173 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4174 | + } |
|
| 4175 | + |
|
| 4176 | + |
|
| 4177 | + |
|
| 4178 | + |
|
| 4179 | + |
|
| 4180 | + |
|
| 4181 | + |
|
| 4182 | + //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4183 | + |
|
| 4184 | + |
|
| 4185 | + /** |
|
| 4186 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4187 | + * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4188 | + * _req_data array. |
|
| 4189 | + * |
|
| 4190 | + * @return bool success/fail |
|
| 4191 | + * @throws EE_Error |
|
| 4192 | + * @throws InvalidArgumentException |
|
| 4193 | + * @throws ReflectionException |
|
| 4194 | + * @throws InvalidDataTypeException |
|
| 4195 | + * @throws InvalidInterfaceException |
|
| 4196 | + */ |
|
| 4197 | + protected function _process_resend_registration() |
|
| 4198 | + { |
|
| 4199 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4200 | + do_action( |
|
| 4201 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4202 | + $this->_template_args['success'], |
|
| 4203 | + $this->_req_data |
|
| 4204 | + ); |
|
| 4205 | + return $this->_template_args['success']; |
|
| 4206 | + } |
|
| 4207 | + |
|
| 4208 | + |
|
| 4209 | + |
|
| 4210 | + /** |
|
| 4211 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4212 | + * |
|
| 4213 | + * @param \EE_Payment $payment |
|
| 4214 | + * @return bool success/fail |
|
| 4215 | + */ |
|
| 4216 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 4217 | + { |
|
| 4218 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4219 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4220 | + $this->_template_args['success'] = apply_filters( |
|
| 4221 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4222 | + false, |
|
| 4223 | + $payment |
|
| 4224 | + ); |
|
| 4225 | + return $this->_template_args['success']; |
|
| 4226 | + } |
|
| 4227 | 4227 | |
| 4228 | 4228 | |
| 4229 | 4229 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $this->registerManifestFile( |
| 105 | 105 | self::ASSET_NAMESPACE, |
| 106 | 106 | $this->domain->distributionAssetsUrl(), |
| 107 | - $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
| 107 | + $this->domain->distributionAssetsPath().'build-manifest.json' |
|
| 108 | 108 | ); |
| 109 | 109 | add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
| 110 | 110 | add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | //js.api |
| 150 | 150 | wp_register_script( |
| 151 | 151 | 'eejs-api', |
| 152 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 152 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
| 153 | 153 | array('underscore', 'eejs-core'), |
| 154 | 154 | EVENT_ESPRESSO_VERSION, |
| 155 | 155 | true |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
| 158 | 158 | $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
| 159 | 159 | } |
| 160 | - if (! is_admin()) { |
|
| 160 | + if ( ! is_admin()) { |
|
| 161 | 161 | $this->loadCoreCss(); |
| 162 | 162 | } |
| 163 | 163 | $this->loadCoreJs(); |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | public function addTemplate($template_reference, $template_content) |
| 256 | 256 | { |
| 257 | - if (! isset($this->jsdata['templates'])) { |
|
| 257 | + if ( ! isset($this->jsdata['templates'])) { |
|
| 258 | 258 | $this->jsdata['templates'] = array(); |
| 259 | 259 | } |
| 260 | 260 | //no overrides allowed. |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | ); |
| 369 | 369 | } |
| 370 | 370 | $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
| 371 | - if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
| 371 | + if ( ! isset($this->manifest_data[$namespace]['url_base'])) { |
|
| 372 | 372 | $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
| 373 | 373 | } |
| 374 | 374 | } |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | private function decodeManifestFile($manifest_file) |
| 387 | 387 | { |
| 388 | - if (! file_exists($manifest_file)) { |
|
| 388 | + if ( ! file_exists($manifest_file)) { |
|
| 389 | 389 | throw new InvalidFilePathException($manifest_file); |
| 390 | 390 | } |
| 391 | 391 | return json_decode(file_get_contents($manifest_file), true); |
@@ -440,9 +440,9 @@ discard block |
||
| 440 | 440 | private function loadCoreCss() |
| 441 | 441 | { |
| 442 | 442 | if ($this->template_config->enable_default_style) { |
| 443 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 443 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
| 444 | 444 | ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
| 445 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 445 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css'; |
|
| 446 | 446 | wp_register_style( |
| 447 | 447 | 'espresso_default', |
| 448 | 448 | $default_stylesheet_path, |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | if ($this->template_config->custom_style_sheet !== null) { |
| 454 | 454 | wp_register_style( |
| 455 | 455 | 'espresso_custom_css', |
| 456 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 456 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
| 457 | 457 | array('espresso_default'), |
| 458 | 458 | EVENT_ESPRESSO_VERSION |
| 459 | 459 | ); |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | // load core js |
| 472 | 472 | wp_register_script( |
| 473 | 473 | 'espresso_core', |
| 474 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 474 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 475 | 475 | array('jquery'), |
| 476 | 476 | EVENT_ESPRESSO_VERSION, |
| 477 | 477 | true |
@@ -488,14 +488,14 @@ discard block |
||
| 488 | 488 | // register jQuery Validate and additional methods |
| 489 | 489 | wp_register_script( |
| 490 | 490 | 'jquery-validate', |
| 491 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 491 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
| 492 | 492 | array('jquery'), |
| 493 | 493 | '1.15.0', |
| 494 | 494 | true |
| 495 | 495 | ); |
| 496 | 496 | wp_register_script( |
| 497 | 497 | 'jquery-validate-extra-methods', |
| 498 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 498 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
| 499 | 499 | array('jquery', 'jquery-validate'), |
| 500 | 500 | '1.15.0', |
| 501 | 501 | true |
@@ -513,14 +513,14 @@ discard block |
||
| 513 | 513 | // @link http://josscrowcroft.github.io/accounting.js/ |
| 514 | 514 | wp_register_script( |
| 515 | 515 | 'ee-accounting-core', |
| 516 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 516 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
| 517 | 517 | array('underscore'), |
| 518 | 518 | '0.3.2', |
| 519 | 519 | true |
| 520 | 520 | ); |
| 521 | 521 | wp_register_script( |
| 522 | 522 | 'ee-accounting', |
| 523 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 523 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
| 524 | 524 | array('ee-accounting-core'), |
| 525 | 525 | EVENT_ESPRESSO_VERSION, |
| 526 | 526 | true |
@@ -25,642 +25,642 @@ |
||
| 25 | 25 | class Registry |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - const ASSET_TYPE_CSS = 'css'; |
|
| 29 | - const ASSET_TYPE_JS = 'js'; |
|
| 30 | - const ASSET_NAMESPACE = 'core'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var EE_Template_Config $template_config |
|
| 34 | - */ |
|
| 35 | - protected $template_config; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var EE_Currency_Config $currency_config |
|
| 39 | - */ |
|
| 40 | - protected $currency_config; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - protected $jsdata = array(); |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
| 52 | - * page source. |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - protected $script_handles_with_data = array(); |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var DomainInterface |
|
| 60 | - */ |
|
| 61 | - protected $domain; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Holds the manifest data obtained from registered manifest files. |
|
| 67 | - * Manifests are maps of asset chunk name to actual built asset file names. |
|
| 68 | - * Shape of this array is: |
|
| 69 | - * |
|
| 70 | - * array( |
|
| 71 | - * 'some_namespace_slug' => array( |
|
| 72 | - * 'some_chunk_name' => array( |
|
| 73 | - * 'js' => 'filename.js' |
|
| 74 | - * 'css' => 'filename.js' |
|
| 75 | - * ), |
|
| 76 | - * 'url_base' => 'https://baseurl.com/to/assets |
|
| 77 | - * ) |
|
| 78 | - * ) |
|
| 79 | - * |
|
| 80 | - * @var array |
|
| 81 | - */ |
|
| 82 | - private $manifest_data = array(); |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Registry constructor. |
|
| 87 | - * Hooking into WP actions for script registry. |
|
| 88 | - * |
|
| 89 | - * @param EE_Template_Config $template_config |
|
| 90 | - * @param EE_Currency_Config $currency_config |
|
| 91 | - * @param DomainInterface $domain |
|
| 92 | - * @throws InvalidArgumentException |
|
| 93 | - * @throws InvalidFilePathException |
|
| 94 | - */ |
|
| 95 | - public function __construct( |
|
| 96 | - EE_Template_Config $template_config, |
|
| 97 | - EE_Currency_Config $currency_config, |
|
| 98 | - DomainInterface $domain |
|
| 99 | - ) { |
|
| 100 | - $this->template_config = $template_config; |
|
| 101 | - $this->currency_config = $currency_config; |
|
| 102 | - $this->domain = $domain; |
|
| 103 | - $this->registerManifestFile( |
|
| 104 | - self::ASSET_NAMESPACE, |
|
| 105 | - $this->domain->distributionAssetsUrl(), |
|
| 106 | - $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
| 107 | - ); |
|
| 108 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 109 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 110 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 111 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 112 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 113 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Callback for the WP script actions. |
|
| 118 | - * Used to register globally accessible core scripts. |
|
| 119 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 120 | - * |
|
| 121 | - */ |
|
| 122 | - public function scripts() |
|
| 123 | - { |
|
| 124 | - global $wp_version; |
|
| 125 | - wp_register_script( |
|
| 126 | - 'ee-manifest', |
|
| 127 | - $this->getJsUrl(self::ASSET_NAMESPACE, 'manifest'), |
|
| 128 | - array(), |
|
| 129 | - null, |
|
| 130 | - true |
|
| 131 | - ); |
|
| 132 | - wp_register_script( |
|
| 133 | - 'eejs-core', |
|
| 134 | - $this->getJsUrl(self::ASSET_NAMESPACE, 'eejs'), |
|
| 135 | - array('ee-manifest'), |
|
| 136 | - null, |
|
| 137 | - true |
|
| 138 | - ); |
|
| 139 | - wp_register_script( |
|
| 140 | - 'ee-vendor-react', |
|
| 141 | - $this->getJsUrl(self::ASSET_NAMESPACE, 'reactVendor'), |
|
| 142 | - array('eejs-core'), |
|
| 143 | - null, |
|
| 144 | - true |
|
| 145 | - ); |
|
| 146 | - //only run this if WordPress 4.4.0 > is in use. |
|
| 147 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 148 | - //js.api |
|
| 149 | - wp_register_script( |
|
| 150 | - 'eejs-api', |
|
| 151 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 152 | - array('underscore', 'eejs-core'), |
|
| 153 | - EVENT_ESPRESSO_VERSION, |
|
| 154 | - true |
|
| 155 | - ); |
|
| 156 | - $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 157 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 158 | - } |
|
| 159 | - if (! is_admin()) { |
|
| 160 | - $this->loadCoreCss(); |
|
| 161 | - } |
|
| 162 | - $this->loadCoreJs(); |
|
| 163 | - $this->loadJqueryValidate(); |
|
| 164 | - $this->loadAccountingJs(); |
|
| 165 | - $this->loadQtipJs(); |
|
| 166 | - $this->registerAdminAssets(); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Call back for the script print in frontend and backend. |
|
| 173 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 174 | - * |
|
| 175 | - * @since 4.9.31.rc.015 |
|
| 176 | - */ |
|
| 177 | - public function enqueueData() |
|
| 178 | - { |
|
| 179 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
| 180 | - wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata)); |
|
| 181 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 182 | - $this->localizeAccountingJs(); |
|
| 183 | - $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
| 184 | - $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Used to add data to eejs.data object. |
|
| 191 | - * Note: Overriding existing data is not allowed. |
|
| 192 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 193 | - * If the data you add is something like this: |
|
| 194 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 195 | - * It will be exposed in the page source as: |
|
| 196 | - * eejs.data.my_plugin_data.foo == gar |
|
| 197 | - * |
|
| 198 | - * @param string $key Key used to access your data |
|
| 199 | - * @param string|array $value Value to attach to key |
|
| 200 | - * @throws InvalidArgumentException |
|
| 201 | - */ |
|
| 202 | - public function addData($key, $value) |
|
| 203 | - { |
|
| 204 | - if ($this->verifyDataNotExisting($key)) { |
|
| 205 | - $this->jsdata[$key] = $value; |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 213 | - * elements in an array. |
|
| 214 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 215 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 216 | - * object like this, eejs.data.test = [ my_data, |
|
| 217 | - * ] |
|
| 218 | - * If there has already been a scalar value attached to the data object given key, then |
|
| 219 | - * this will throw an exception. |
|
| 220 | - * |
|
| 221 | - * @param string $key Key to attach data to. |
|
| 222 | - * @param string|array $value Value being registered. |
|
| 223 | - * @throws InvalidArgumentException |
|
| 224 | - */ |
|
| 225 | - public function pushData($key, $value) |
|
| 226 | - { |
|
| 227 | - if (isset($this->jsdata[$key]) |
|
| 228 | - && ! is_array($this->jsdata[$key]) |
|
| 229 | - ) { |
|
| 230 | - throw new invalidArgumentException( |
|
| 231 | - sprintf( |
|
| 232 | - __( |
|
| 233 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 28 | + const ASSET_TYPE_CSS = 'css'; |
|
| 29 | + const ASSET_TYPE_JS = 'js'; |
|
| 30 | + const ASSET_NAMESPACE = 'core'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var EE_Template_Config $template_config |
|
| 34 | + */ |
|
| 35 | + protected $template_config; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var EE_Currency_Config $currency_config |
|
| 39 | + */ |
|
| 40 | + protected $currency_config; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + protected $jsdata = array(); |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
| 52 | + * page source. |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + protected $script_handles_with_data = array(); |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var DomainInterface |
|
| 60 | + */ |
|
| 61 | + protected $domain; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Holds the manifest data obtained from registered manifest files. |
|
| 67 | + * Manifests are maps of asset chunk name to actual built asset file names. |
|
| 68 | + * Shape of this array is: |
|
| 69 | + * |
|
| 70 | + * array( |
|
| 71 | + * 'some_namespace_slug' => array( |
|
| 72 | + * 'some_chunk_name' => array( |
|
| 73 | + * 'js' => 'filename.js' |
|
| 74 | + * 'css' => 'filename.js' |
|
| 75 | + * ), |
|
| 76 | + * 'url_base' => 'https://baseurl.com/to/assets |
|
| 77 | + * ) |
|
| 78 | + * ) |
|
| 79 | + * |
|
| 80 | + * @var array |
|
| 81 | + */ |
|
| 82 | + private $manifest_data = array(); |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Registry constructor. |
|
| 87 | + * Hooking into WP actions for script registry. |
|
| 88 | + * |
|
| 89 | + * @param EE_Template_Config $template_config |
|
| 90 | + * @param EE_Currency_Config $currency_config |
|
| 91 | + * @param DomainInterface $domain |
|
| 92 | + * @throws InvalidArgumentException |
|
| 93 | + * @throws InvalidFilePathException |
|
| 94 | + */ |
|
| 95 | + public function __construct( |
|
| 96 | + EE_Template_Config $template_config, |
|
| 97 | + EE_Currency_Config $currency_config, |
|
| 98 | + DomainInterface $domain |
|
| 99 | + ) { |
|
| 100 | + $this->template_config = $template_config; |
|
| 101 | + $this->currency_config = $currency_config; |
|
| 102 | + $this->domain = $domain; |
|
| 103 | + $this->registerManifestFile( |
|
| 104 | + self::ASSET_NAMESPACE, |
|
| 105 | + $this->domain->distributionAssetsUrl(), |
|
| 106 | + $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
| 107 | + ); |
|
| 108 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 109 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 110 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 111 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 112 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 113 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Callback for the WP script actions. |
|
| 118 | + * Used to register globally accessible core scripts. |
|
| 119 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 120 | + * |
|
| 121 | + */ |
|
| 122 | + public function scripts() |
|
| 123 | + { |
|
| 124 | + global $wp_version; |
|
| 125 | + wp_register_script( |
|
| 126 | + 'ee-manifest', |
|
| 127 | + $this->getJsUrl(self::ASSET_NAMESPACE, 'manifest'), |
|
| 128 | + array(), |
|
| 129 | + null, |
|
| 130 | + true |
|
| 131 | + ); |
|
| 132 | + wp_register_script( |
|
| 133 | + 'eejs-core', |
|
| 134 | + $this->getJsUrl(self::ASSET_NAMESPACE, 'eejs'), |
|
| 135 | + array('ee-manifest'), |
|
| 136 | + null, |
|
| 137 | + true |
|
| 138 | + ); |
|
| 139 | + wp_register_script( |
|
| 140 | + 'ee-vendor-react', |
|
| 141 | + $this->getJsUrl(self::ASSET_NAMESPACE, 'reactVendor'), |
|
| 142 | + array('eejs-core'), |
|
| 143 | + null, |
|
| 144 | + true |
|
| 145 | + ); |
|
| 146 | + //only run this if WordPress 4.4.0 > is in use. |
|
| 147 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 148 | + //js.api |
|
| 149 | + wp_register_script( |
|
| 150 | + 'eejs-api', |
|
| 151 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 152 | + array('underscore', 'eejs-core'), |
|
| 153 | + EVENT_ESPRESSO_VERSION, |
|
| 154 | + true |
|
| 155 | + ); |
|
| 156 | + $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 157 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 158 | + } |
|
| 159 | + if (! is_admin()) { |
|
| 160 | + $this->loadCoreCss(); |
|
| 161 | + } |
|
| 162 | + $this->loadCoreJs(); |
|
| 163 | + $this->loadJqueryValidate(); |
|
| 164 | + $this->loadAccountingJs(); |
|
| 165 | + $this->loadQtipJs(); |
|
| 166 | + $this->registerAdminAssets(); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Call back for the script print in frontend and backend. |
|
| 173 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 174 | + * |
|
| 175 | + * @since 4.9.31.rc.015 |
|
| 176 | + */ |
|
| 177 | + public function enqueueData() |
|
| 178 | + { |
|
| 179 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
| 180 | + wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata)); |
|
| 181 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 182 | + $this->localizeAccountingJs(); |
|
| 183 | + $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
| 184 | + $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Used to add data to eejs.data object. |
|
| 191 | + * Note: Overriding existing data is not allowed. |
|
| 192 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 193 | + * If the data you add is something like this: |
|
| 194 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 195 | + * It will be exposed in the page source as: |
|
| 196 | + * eejs.data.my_plugin_data.foo == gar |
|
| 197 | + * |
|
| 198 | + * @param string $key Key used to access your data |
|
| 199 | + * @param string|array $value Value to attach to key |
|
| 200 | + * @throws InvalidArgumentException |
|
| 201 | + */ |
|
| 202 | + public function addData($key, $value) |
|
| 203 | + { |
|
| 204 | + if ($this->verifyDataNotExisting($key)) { |
|
| 205 | + $this->jsdata[$key] = $value; |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 213 | + * elements in an array. |
|
| 214 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 215 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 216 | + * object like this, eejs.data.test = [ my_data, |
|
| 217 | + * ] |
|
| 218 | + * If there has already been a scalar value attached to the data object given key, then |
|
| 219 | + * this will throw an exception. |
|
| 220 | + * |
|
| 221 | + * @param string $key Key to attach data to. |
|
| 222 | + * @param string|array $value Value being registered. |
|
| 223 | + * @throws InvalidArgumentException |
|
| 224 | + */ |
|
| 225 | + public function pushData($key, $value) |
|
| 226 | + { |
|
| 227 | + if (isset($this->jsdata[$key]) |
|
| 228 | + && ! is_array($this->jsdata[$key]) |
|
| 229 | + ) { |
|
| 230 | + throw new invalidArgumentException( |
|
| 231 | + sprintf( |
|
| 232 | + __( |
|
| 233 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 234 | 234 | push values to this data element when it is an array.', |
| 235 | - 'event_espresso' |
|
| 236 | - ), |
|
| 237 | - $key, |
|
| 238 | - __METHOD__ |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - $this->jsdata[$key][] = $value; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Used to set content used by javascript for a template. |
|
| 249 | - * Note: Overrides of existing registered templates are not allowed. |
|
| 250 | - * |
|
| 251 | - * @param string $template_reference |
|
| 252 | - * @param string $template_content |
|
| 253 | - * @throws InvalidArgumentException |
|
| 254 | - */ |
|
| 255 | - public function addTemplate($template_reference, $template_content) |
|
| 256 | - { |
|
| 257 | - if (! isset($this->jsdata['templates'])) { |
|
| 258 | - $this->jsdata['templates'] = array(); |
|
| 259 | - } |
|
| 260 | - //no overrides allowed. |
|
| 261 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 262 | - throw new invalidArgumentException( |
|
| 263 | - sprintf( |
|
| 264 | - __( |
|
| 265 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 266 | - 'event_espresso' |
|
| 267 | - ), |
|
| 268 | - $template_reference |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Retrieve the template content already registered for the given reference. |
|
| 279 | - * |
|
| 280 | - * @param string $template_reference |
|
| 281 | - * @return string |
|
| 282 | - */ |
|
| 283 | - public function getTemplate($template_reference) |
|
| 284 | - { |
|
| 285 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 286 | - ? $this->jsdata['templates'][$template_reference] |
|
| 287 | - : ''; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Retrieve registered data. |
|
| 294 | - * |
|
| 295 | - * @param string $key Name of key to attach data to. |
|
| 296 | - * @return mixed If there is no for the given key, then false is returned. |
|
| 297 | - */ |
|
| 298 | - public function getData($key) |
|
| 299 | - { |
|
| 300 | - return isset($this->jsdata[$key]) |
|
| 301 | - ? $this->jsdata[$key] |
|
| 302 | - : false; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Get the actual asset path for asset manifests. |
|
| 308 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
| 309 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
| 310 | - * asset file location. |
|
| 311 | - * @param string $chunk_name |
|
| 312 | - * @param string $asset_type |
|
| 313 | - * @return string |
|
| 314 | - * @since 4.9.59.p |
|
| 315 | - */ |
|
| 316 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
| 317 | - { |
|
| 318 | - $url = isset( |
|
| 319 | - $this->manifest_data[$namespace][$chunk_name][$asset_type], |
|
| 320 | - $this->manifest_data[$namespace]['url_base'] |
|
| 321 | - ) |
|
| 322 | - ? $this->manifest_data[$namespace]['url_base'] |
|
| 323 | - . $this->manifest_data[$namespace][$chunk_name][$asset_type] |
|
| 324 | - : $chunk_name; |
|
| 325 | - return apply_filters( |
|
| 326 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
| 327 | - $url, |
|
| 328 | - $namespace, |
|
| 329 | - $chunk_name, |
|
| 330 | - $asset_type |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Return the url to a js file for the given namespace and chunk name. |
|
| 337 | - * |
|
| 338 | - * @param string $namespace |
|
| 339 | - * @param string $chunk_name |
|
| 340 | - * @return string |
|
| 341 | - */ |
|
| 342 | - public function getJsUrl($namespace, $chunk_name) |
|
| 343 | - { |
|
| 344 | - return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Return the url to a css file for the given namespace and chunk name. |
|
| 350 | - * |
|
| 351 | - * @param string $namespace |
|
| 352 | - * @param string $chunk_name |
|
| 353 | - * @return string |
|
| 354 | - */ |
|
| 355 | - public function getCssUrl($namespace, $chunk_name) |
|
| 356 | - { |
|
| 357 | - return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
| 363 | - * |
|
| 364 | - * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
| 365 | - * @param string $url_base The url base for the manifest file location. |
|
| 366 | - * @param string $manifest_file The absolute path to the manifest file. |
|
| 367 | - * @throws InvalidArgumentException |
|
| 368 | - * @throws InvalidFilePathException |
|
| 369 | - * @since 4.9.59.p |
|
| 370 | - */ |
|
| 371 | - public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
| 372 | - { |
|
| 373 | - if (isset($this->manifest_data[$namespace])) { |
|
| 374 | - throw new InvalidArgumentException( |
|
| 375 | - sprintf( |
|
| 376 | - esc_html__( |
|
| 377 | - 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
| 378 | - 'event_espresso' |
|
| 379 | - ), |
|
| 380 | - $namespace |
|
| 381 | - ) |
|
| 382 | - ); |
|
| 383 | - } |
|
| 384 | - if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
| 385 | - throw new InvalidArgumentException( |
|
| 386 | - sprintf( |
|
| 387 | - esc_html__( |
|
| 388 | - 'The provided value for %1$s is not a valid url. The url provided was: %2$s', |
|
| 389 | - 'event_espresso' |
|
| 390 | - ), |
|
| 391 | - '$url_base', |
|
| 392 | - $url_base |
|
| 393 | - ) |
|
| 394 | - ); |
|
| 395 | - } |
|
| 396 | - $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
| 397 | - if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
| 398 | - $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Decodes json from the provided manifest file. |
|
| 406 | - * |
|
| 407 | - * @since 4.9.59.p |
|
| 408 | - * @param string $manifest_file Path to manifest file. |
|
| 409 | - * @return array |
|
| 410 | - * @throws InvalidFilePathException |
|
| 411 | - */ |
|
| 412 | - private function decodeManifestFile($manifest_file) |
|
| 413 | - { |
|
| 414 | - if (! file_exists($manifest_file)) { |
|
| 415 | - throw new InvalidFilePathException($manifest_file); |
|
| 416 | - } |
|
| 417 | - return json_decode(file_get_contents($manifest_file), true); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Verifies whether the given data exists already on the jsdata array. |
|
| 424 | - * Overriding data is not allowed. |
|
| 425 | - * |
|
| 426 | - * @param string $key Index for data. |
|
| 427 | - * @return bool If valid then return true. |
|
| 428 | - * @throws InvalidArgumentException if data already exists. |
|
| 429 | - */ |
|
| 430 | - protected function verifyDataNotExisting($key) |
|
| 431 | - { |
|
| 432 | - if (isset($this->jsdata[$key])) { |
|
| 433 | - if (is_array($this->jsdata[$key])) { |
|
| 434 | - throw new InvalidArgumentException( |
|
| 435 | - sprintf( |
|
| 436 | - __( |
|
| 437 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
| 235 | + 'event_espresso' |
|
| 236 | + ), |
|
| 237 | + $key, |
|
| 238 | + __METHOD__ |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + $this->jsdata[$key][] = $value; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Used to set content used by javascript for a template. |
|
| 249 | + * Note: Overrides of existing registered templates are not allowed. |
|
| 250 | + * |
|
| 251 | + * @param string $template_reference |
|
| 252 | + * @param string $template_content |
|
| 253 | + * @throws InvalidArgumentException |
|
| 254 | + */ |
|
| 255 | + public function addTemplate($template_reference, $template_content) |
|
| 256 | + { |
|
| 257 | + if (! isset($this->jsdata['templates'])) { |
|
| 258 | + $this->jsdata['templates'] = array(); |
|
| 259 | + } |
|
| 260 | + //no overrides allowed. |
|
| 261 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 262 | + throw new invalidArgumentException( |
|
| 263 | + sprintf( |
|
| 264 | + __( |
|
| 265 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 266 | + 'event_espresso' |
|
| 267 | + ), |
|
| 268 | + $template_reference |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Retrieve the template content already registered for the given reference. |
|
| 279 | + * |
|
| 280 | + * @param string $template_reference |
|
| 281 | + * @return string |
|
| 282 | + */ |
|
| 283 | + public function getTemplate($template_reference) |
|
| 284 | + { |
|
| 285 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 286 | + ? $this->jsdata['templates'][$template_reference] |
|
| 287 | + : ''; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Retrieve registered data. |
|
| 294 | + * |
|
| 295 | + * @param string $key Name of key to attach data to. |
|
| 296 | + * @return mixed If there is no for the given key, then false is returned. |
|
| 297 | + */ |
|
| 298 | + public function getData($key) |
|
| 299 | + { |
|
| 300 | + return isset($this->jsdata[$key]) |
|
| 301 | + ? $this->jsdata[$key] |
|
| 302 | + : false; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Get the actual asset path for asset manifests. |
|
| 308 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
| 309 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
| 310 | + * asset file location. |
|
| 311 | + * @param string $chunk_name |
|
| 312 | + * @param string $asset_type |
|
| 313 | + * @return string |
|
| 314 | + * @since 4.9.59.p |
|
| 315 | + */ |
|
| 316 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
| 317 | + { |
|
| 318 | + $url = isset( |
|
| 319 | + $this->manifest_data[$namespace][$chunk_name][$asset_type], |
|
| 320 | + $this->manifest_data[$namespace]['url_base'] |
|
| 321 | + ) |
|
| 322 | + ? $this->manifest_data[$namespace]['url_base'] |
|
| 323 | + . $this->manifest_data[$namespace][$chunk_name][$asset_type] |
|
| 324 | + : $chunk_name; |
|
| 325 | + return apply_filters( |
|
| 326 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
| 327 | + $url, |
|
| 328 | + $namespace, |
|
| 329 | + $chunk_name, |
|
| 330 | + $asset_type |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Return the url to a js file for the given namespace and chunk name. |
|
| 337 | + * |
|
| 338 | + * @param string $namespace |
|
| 339 | + * @param string $chunk_name |
|
| 340 | + * @return string |
|
| 341 | + */ |
|
| 342 | + public function getJsUrl($namespace, $chunk_name) |
|
| 343 | + { |
|
| 344 | + return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Return the url to a css file for the given namespace and chunk name. |
|
| 350 | + * |
|
| 351 | + * @param string $namespace |
|
| 352 | + * @param string $chunk_name |
|
| 353 | + * @return string |
|
| 354 | + */ |
|
| 355 | + public function getCssUrl($namespace, $chunk_name) |
|
| 356 | + { |
|
| 357 | + return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
| 363 | + * |
|
| 364 | + * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
| 365 | + * @param string $url_base The url base for the manifest file location. |
|
| 366 | + * @param string $manifest_file The absolute path to the manifest file. |
|
| 367 | + * @throws InvalidArgumentException |
|
| 368 | + * @throws InvalidFilePathException |
|
| 369 | + * @since 4.9.59.p |
|
| 370 | + */ |
|
| 371 | + public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
| 372 | + { |
|
| 373 | + if (isset($this->manifest_data[$namespace])) { |
|
| 374 | + throw new InvalidArgumentException( |
|
| 375 | + sprintf( |
|
| 376 | + esc_html__( |
|
| 377 | + 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
| 378 | + 'event_espresso' |
|
| 379 | + ), |
|
| 380 | + $namespace |
|
| 381 | + ) |
|
| 382 | + ); |
|
| 383 | + } |
|
| 384 | + if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
| 385 | + throw new InvalidArgumentException( |
|
| 386 | + sprintf( |
|
| 387 | + esc_html__( |
|
| 388 | + 'The provided value for %1$s is not a valid url. The url provided was: %2$s', |
|
| 389 | + 'event_espresso' |
|
| 390 | + ), |
|
| 391 | + '$url_base', |
|
| 392 | + $url_base |
|
| 393 | + ) |
|
| 394 | + ); |
|
| 395 | + } |
|
| 396 | + $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
| 397 | + if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
| 398 | + $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Decodes json from the provided manifest file. |
|
| 406 | + * |
|
| 407 | + * @since 4.9.59.p |
|
| 408 | + * @param string $manifest_file Path to manifest file. |
|
| 409 | + * @return array |
|
| 410 | + * @throws InvalidFilePathException |
|
| 411 | + */ |
|
| 412 | + private function decodeManifestFile($manifest_file) |
|
| 413 | + { |
|
| 414 | + if (! file_exists($manifest_file)) { |
|
| 415 | + throw new InvalidFilePathException($manifest_file); |
|
| 416 | + } |
|
| 417 | + return json_decode(file_get_contents($manifest_file), true); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Verifies whether the given data exists already on the jsdata array. |
|
| 424 | + * Overriding data is not allowed. |
|
| 425 | + * |
|
| 426 | + * @param string $key Index for data. |
|
| 427 | + * @return bool If valid then return true. |
|
| 428 | + * @throws InvalidArgumentException if data already exists. |
|
| 429 | + */ |
|
| 430 | + protected function verifyDataNotExisting($key) |
|
| 431 | + { |
|
| 432 | + if (isset($this->jsdata[$key])) { |
|
| 433 | + if (is_array($this->jsdata[$key])) { |
|
| 434 | + throw new InvalidArgumentException( |
|
| 435 | + sprintf( |
|
| 436 | + __( |
|
| 437 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
| 438 | 438 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
| 439 | 439 | %2$s method to push your value to the array.', |
| 440 | - 'event_espresso' |
|
| 441 | - ), |
|
| 442 | - $key, |
|
| 443 | - 'pushData()' |
|
| 444 | - ) |
|
| 445 | - ); |
|
| 446 | - } |
|
| 447 | - throw new InvalidArgumentException( |
|
| 448 | - sprintf( |
|
| 449 | - __( |
|
| 450 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 440 | + 'event_espresso' |
|
| 441 | + ), |
|
| 442 | + $key, |
|
| 443 | + 'pushData()' |
|
| 444 | + ) |
|
| 445 | + ); |
|
| 446 | + } |
|
| 447 | + throw new InvalidArgumentException( |
|
| 448 | + sprintf( |
|
| 449 | + __( |
|
| 450 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 451 | 451 | allowed. Consider attaching your value to a different key', |
| 452 | - 'event_espresso' |
|
| 453 | - ), |
|
| 454 | - $key |
|
| 455 | - ) |
|
| 456 | - ); |
|
| 457 | - } |
|
| 458 | - return true; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * registers core default stylesheets |
|
| 465 | - */ |
|
| 466 | - private function loadCoreCss() |
|
| 467 | - { |
|
| 468 | - if ($this->template_config->enable_default_style) { |
|
| 469 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 470 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 471 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 472 | - wp_register_style( |
|
| 473 | - 'espresso_default', |
|
| 474 | - $default_stylesheet_path, |
|
| 475 | - array('dashicons'), |
|
| 476 | - EVENT_ESPRESSO_VERSION |
|
| 477 | - ); |
|
| 478 | - //Load custom style sheet if available |
|
| 479 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 480 | - wp_register_style( |
|
| 481 | - 'espresso_custom_css', |
|
| 482 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 483 | - array('espresso_default'), |
|
| 484 | - EVENT_ESPRESSO_VERSION |
|
| 485 | - ); |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * registers core default javascript |
|
| 494 | - */ |
|
| 495 | - private function loadCoreJs() |
|
| 496 | - { |
|
| 497 | - // load core js |
|
| 498 | - wp_register_script( |
|
| 499 | - 'espresso_core', |
|
| 500 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 501 | - array('jquery'), |
|
| 502 | - EVENT_ESPRESSO_VERSION, |
|
| 503 | - true |
|
| 504 | - ); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * registers jQuery Validate for form validation |
|
| 511 | - */ |
|
| 512 | - private function loadJqueryValidate() |
|
| 513 | - { |
|
| 514 | - // register jQuery Validate and additional methods |
|
| 515 | - wp_register_script( |
|
| 516 | - 'jquery-validate', |
|
| 517 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 518 | - array('jquery'), |
|
| 519 | - '1.15.0', |
|
| 520 | - true |
|
| 521 | - ); |
|
| 522 | - wp_register_script( |
|
| 523 | - 'jquery-validate-extra-methods', |
|
| 524 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 525 | - array('jquery', 'jquery-validate'), |
|
| 526 | - '1.15.0', |
|
| 527 | - true |
|
| 528 | - ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * registers accounting.js for performing client-side calculations |
|
| 535 | - */ |
|
| 536 | - private function loadAccountingJs() |
|
| 537 | - { |
|
| 538 | - //accounting.js library |
|
| 539 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 540 | - wp_register_script( |
|
| 541 | - 'ee-accounting-core', |
|
| 542 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 543 | - array('underscore'), |
|
| 544 | - '0.3.2', |
|
| 545 | - true |
|
| 546 | - ); |
|
| 547 | - wp_register_script( |
|
| 548 | - 'ee-accounting', |
|
| 549 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 550 | - array('ee-accounting-core'), |
|
| 551 | - EVENT_ESPRESSO_VERSION, |
|
| 552 | - true |
|
| 553 | - ); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * registers accounting.js for performing client-side calculations |
|
| 560 | - */ |
|
| 561 | - private function localizeAccountingJs() |
|
| 562 | - { |
|
| 563 | - wp_localize_script( |
|
| 564 | - 'ee-accounting', |
|
| 565 | - 'EE_ACCOUNTING_CFG', |
|
| 566 | - array( |
|
| 567 | - 'currency' => array( |
|
| 568 | - 'symbol' => $this->currency_config->sign, |
|
| 569 | - 'format' => array( |
|
| 570 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 571 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 572 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 573 | - ), |
|
| 574 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 575 | - 'thousand' => $this->currency_config->thsnds, |
|
| 576 | - 'precision' => $this->currency_config->dec_plc, |
|
| 577 | - ), |
|
| 578 | - 'number' => array( |
|
| 579 | - 'precision' => $this->currency_config->dec_plc, |
|
| 580 | - 'thousand' => $this->currency_config->thsnds, |
|
| 581 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 582 | - ), |
|
| 583 | - ) |
|
| 584 | - ); |
|
| 585 | - $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * registers assets for cleaning your ears |
|
| 592 | - */ |
|
| 593 | - private function loadQtipJs() |
|
| 594 | - { |
|
| 595 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 596 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 597 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 598 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * This is used to set registered script handles that have data. |
|
| 605 | - * @param string $script_handle |
|
| 606 | - */ |
|
| 607 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
| 608 | - { |
|
| 609 | - $this->script_handles_with_data[$script_handle] = $script_handle; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
| 615 | - * Dependency stored in WP_Scripts if its set. |
|
| 616 | - */ |
|
| 617 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
| 618 | - { |
|
| 619 | - if (empty($this->script_handles_with_data)) { |
|
| 620 | - return; |
|
| 621 | - } |
|
| 622 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
| 623 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
| 630 | - * @param string $script_handle |
|
| 631 | - */ |
|
| 632 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
| 633 | - { |
|
| 634 | - if (isset($this->script_handles_with_data[$script_handle])) { |
|
| 635 | - global $wp_scripts; |
|
| 636 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
| 637 | - unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
| 638 | - unset($this->script_handles_with_data[$script_handle]); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * Registers assets that are used in the WordPress admin. |
|
| 646 | - */ |
|
| 647 | - private function registerAdminAssets() |
|
| 648 | - { |
|
| 649 | - wp_register_script( |
|
| 650 | - 'ee-wp-plugins-page', |
|
| 651 | - $this->getJsUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'), |
|
| 652 | - array( |
|
| 653 | - 'jquery', |
|
| 654 | - 'ee-vendor-react' |
|
| 655 | - ), |
|
| 656 | - null, |
|
| 657 | - true |
|
| 658 | - ); |
|
| 659 | - wp_register_style( |
|
| 660 | - 'ee-wp-plugins-page', |
|
| 661 | - $this->getCssUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'), |
|
| 662 | - array(), |
|
| 663 | - null |
|
| 664 | - ); |
|
| 665 | - } |
|
| 452 | + 'event_espresso' |
|
| 453 | + ), |
|
| 454 | + $key |
|
| 455 | + ) |
|
| 456 | + ); |
|
| 457 | + } |
|
| 458 | + return true; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * registers core default stylesheets |
|
| 465 | + */ |
|
| 466 | + private function loadCoreCss() |
|
| 467 | + { |
|
| 468 | + if ($this->template_config->enable_default_style) { |
|
| 469 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 470 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 471 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 472 | + wp_register_style( |
|
| 473 | + 'espresso_default', |
|
| 474 | + $default_stylesheet_path, |
|
| 475 | + array('dashicons'), |
|
| 476 | + EVENT_ESPRESSO_VERSION |
|
| 477 | + ); |
|
| 478 | + //Load custom style sheet if available |
|
| 479 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 480 | + wp_register_style( |
|
| 481 | + 'espresso_custom_css', |
|
| 482 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 483 | + array('espresso_default'), |
|
| 484 | + EVENT_ESPRESSO_VERSION |
|
| 485 | + ); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * registers core default javascript |
|
| 494 | + */ |
|
| 495 | + private function loadCoreJs() |
|
| 496 | + { |
|
| 497 | + // load core js |
|
| 498 | + wp_register_script( |
|
| 499 | + 'espresso_core', |
|
| 500 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 501 | + array('jquery'), |
|
| 502 | + EVENT_ESPRESSO_VERSION, |
|
| 503 | + true |
|
| 504 | + ); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * registers jQuery Validate for form validation |
|
| 511 | + */ |
|
| 512 | + private function loadJqueryValidate() |
|
| 513 | + { |
|
| 514 | + // register jQuery Validate and additional methods |
|
| 515 | + wp_register_script( |
|
| 516 | + 'jquery-validate', |
|
| 517 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 518 | + array('jquery'), |
|
| 519 | + '1.15.0', |
|
| 520 | + true |
|
| 521 | + ); |
|
| 522 | + wp_register_script( |
|
| 523 | + 'jquery-validate-extra-methods', |
|
| 524 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 525 | + array('jquery', 'jquery-validate'), |
|
| 526 | + '1.15.0', |
|
| 527 | + true |
|
| 528 | + ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * registers accounting.js for performing client-side calculations |
|
| 535 | + */ |
|
| 536 | + private function loadAccountingJs() |
|
| 537 | + { |
|
| 538 | + //accounting.js library |
|
| 539 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 540 | + wp_register_script( |
|
| 541 | + 'ee-accounting-core', |
|
| 542 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 543 | + array('underscore'), |
|
| 544 | + '0.3.2', |
|
| 545 | + true |
|
| 546 | + ); |
|
| 547 | + wp_register_script( |
|
| 548 | + 'ee-accounting', |
|
| 549 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 550 | + array('ee-accounting-core'), |
|
| 551 | + EVENT_ESPRESSO_VERSION, |
|
| 552 | + true |
|
| 553 | + ); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * registers accounting.js for performing client-side calculations |
|
| 560 | + */ |
|
| 561 | + private function localizeAccountingJs() |
|
| 562 | + { |
|
| 563 | + wp_localize_script( |
|
| 564 | + 'ee-accounting', |
|
| 565 | + 'EE_ACCOUNTING_CFG', |
|
| 566 | + array( |
|
| 567 | + 'currency' => array( |
|
| 568 | + 'symbol' => $this->currency_config->sign, |
|
| 569 | + 'format' => array( |
|
| 570 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 571 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 572 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 573 | + ), |
|
| 574 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 575 | + 'thousand' => $this->currency_config->thsnds, |
|
| 576 | + 'precision' => $this->currency_config->dec_plc, |
|
| 577 | + ), |
|
| 578 | + 'number' => array( |
|
| 579 | + 'precision' => $this->currency_config->dec_plc, |
|
| 580 | + 'thousand' => $this->currency_config->thsnds, |
|
| 581 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 582 | + ), |
|
| 583 | + ) |
|
| 584 | + ); |
|
| 585 | + $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * registers assets for cleaning your ears |
|
| 592 | + */ |
|
| 593 | + private function loadQtipJs() |
|
| 594 | + { |
|
| 595 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 596 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 597 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 598 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * This is used to set registered script handles that have data. |
|
| 605 | + * @param string $script_handle |
|
| 606 | + */ |
|
| 607 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
| 608 | + { |
|
| 609 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
| 615 | + * Dependency stored in WP_Scripts if its set. |
|
| 616 | + */ |
|
| 617 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
| 618 | + { |
|
| 619 | + if (empty($this->script_handles_with_data)) { |
|
| 620 | + return; |
|
| 621 | + } |
|
| 622 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
| 623 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
| 630 | + * @param string $script_handle |
|
| 631 | + */ |
|
| 632 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
| 633 | + { |
|
| 634 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
| 635 | + global $wp_scripts; |
|
| 636 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
| 637 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
| 638 | + unset($this->script_handles_with_data[$script_handle]); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * Registers assets that are used in the WordPress admin. |
|
| 646 | + */ |
|
| 647 | + private function registerAdminAssets() |
|
| 648 | + { |
|
| 649 | + wp_register_script( |
|
| 650 | + 'ee-wp-plugins-page', |
|
| 651 | + $this->getJsUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'), |
|
| 652 | + array( |
|
| 653 | + 'jquery', |
|
| 654 | + 'ee-vendor-react' |
|
| 655 | + ), |
|
| 656 | + null, |
|
| 657 | + true |
|
| 658 | + ); |
|
| 659 | + wp_register_style( |
|
| 660 | + 'ee-wp-plugins-page', |
|
| 661 | + $this->getCssUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'), |
|
| 662 | + array(), |
|
| 663 | + null |
|
| 664 | + ); |
|
| 665 | + } |
|
| 666 | 666 | } |
@@ -19,94 +19,94 @@ |
||
| 19 | 19 | class ExitModal |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var Registry |
|
| 24 | - */ |
|
| 25 | - private $assets_registry; |
|
| 22 | + /** |
|
| 23 | + * @var Registry |
|
| 24 | + */ |
|
| 25 | + private $assets_registry; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * ExitModal constructor. |
|
| 29 | - * |
|
| 30 | - * @param Registry $assets_registry |
|
| 31 | - */ |
|
| 32 | - public function __construct(Registry $assets_registry) |
|
| 33 | - { |
|
| 34 | - $this->assets_registry = $assets_registry; |
|
| 35 | - add_action('in_admin_footer', array($this, 'modalContainer')); |
|
| 36 | - add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
| 37 | - } |
|
| 27 | + /** |
|
| 28 | + * ExitModal constructor. |
|
| 29 | + * |
|
| 30 | + * @param Registry $assets_registry |
|
| 31 | + */ |
|
| 32 | + public function __construct(Registry $assets_registry) |
|
| 33 | + { |
|
| 34 | + $this->assets_registry = $assets_registry; |
|
| 35 | + add_action('in_admin_footer', array($this, 'modalContainer')); |
|
| 36 | + add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Callback on in_admin_footer that is used to output the exit modal container. |
|
| 42 | - */ |
|
| 43 | - public function modalContainer() |
|
| 44 | - { |
|
| 45 | - echo '<div id="ee-exit-survey-modal"></div>'; |
|
| 46 | - } |
|
| 40 | + /** |
|
| 41 | + * Callback on in_admin_footer that is used to output the exit modal container. |
|
| 42 | + */ |
|
| 43 | + public function modalContainer() |
|
| 44 | + { |
|
| 45 | + echo '<div id="ee-exit-survey-modal"></div>'; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
| 51 | - * |
|
| 52 | - * @throws InvalidArgumentException |
|
| 53 | - */ |
|
| 54 | - public function enqueues() |
|
| 55 | - { |
|
| 56 | - $current_user = new WP_User(get_current_user_id()); |
|
| 57 | - $this->assets_registry->addData( |
|
| 58 | - 'exitModali18n', |
|
| 59 | - array( |
|
| 60 | - 'introText' => htmlspecialchars( |
|
| 61 | - __( |
|
| 62 | - 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
| 63 | - 'event_espresso' |
|
| 64 | - ), |
|
| 65 | - ENT_NOQUOTES |
|
| 66 | - ), |
|
| 67 | - 'doSurveyButtonText' => htmlspecialchars( |
|
| 68 | - __( |
|
| 69 | - 'Sure I\'ll help', |
|
| 70 | - 'event_espresso' |
|
| 71 | - ), |
|
| 72 | - ENT_NOQUOTES |
|
| 73 | - ), |
|
| 74 | - 'skipButtonText' => htmlspecialchars( |
|
| 75 | - __( |
|
| 76 | - 'Skip', |
|
| 77 | - 'event_espresso' |
|
| 78 | - ), |
|
| 79 | - ENT_NOQUOTES |
|
| 80 | - ) |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - $this->assets_registry->addData( |
|
| 84 | - 'exitModalInfo', |
|
| 85 | - array( |
|
| 86 | - 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
| 87 | - 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
| 88 | - 'website' => htmlspecialchars(site_url()), |
|
| 89 | - 'isModalActive' => $this->isModalActive() |
|
| 90 | - ) |
|
| 91 | - ); |
|
| 49 | + /** |
|
| 50 | + * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
| 51 | + * |
|
| 52 | + * @throws InvalidArgumentException |
|
| 53 | + */ |
|
| 54 | + public function enqueues() |
|
| 55 | + { |
|
| 56 | + $current_user = new WP_User(get_current_user_id()); |
|
| 57 | + $this->assets_registry->addData( |
|
| 58 | + 'exitModali18n', |
|
| 59 | + array( |
|
| 60 | + 'introText' => htmlspecialchars( |
|
| 61 | + __( |
|
| 62 | + 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
| 63 | + 'event_espresso' |
|
| 64 | + ), |
|
| 65 | + ENT_NOQUOTES |
|
| 66 | + ), |
|
| 67 | + 'doSurveyButtonText' => htmlspecialchars( |
|
| 68 | + __( |
|
| 69 | + 'Sure I\'ll help', |
|
| 70 | + 'event_espresso' |
|
| 71 | + ), |
|
| 72 | + ENT_NOQUOTES |
|
| 73 | + ), |
|
| 74 | + 'skipButtonText' => htmlspecialchars( |
|
| 75 | + __( |
|
| 76 | + 'Skip', |
|
| 77 | + 'event_espresso' |
|
| 78 | + ), |
|
| 79 | + ENT_NOQUOTES |
|
| 80 | + ) |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + $this->assets_registry->addData( |
|
| 84 | + 'exitModalInfo', |
|
| 85 | + array( |
|
| 86 | + 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
| 87 | + 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
| 88 | + 'website' => htmlspecialchars(site_url()), |
|
| 89 | + 'isModalActive' => $this->isModalActive() |
|
| 90 | + ) |
|
| 91 | + ); |
|
| 92 | 92 | |
| 93 | - wp_enqueue_script('ee-wp-plugins-page'); |
|
| 94 | - wp_enqueue_style('ee-wp-plugins-page'); |
|
| 95 | - } |
|
| 93 | + wp_enqueue_script('ee-wp-plugins-page'); |
|
| 94 | + wp_enqueue_style('ee-wp-plugins-page'); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - private function isModalActive() |
|
| 103 | - { |
|
| 104 | - return filter_var( |
|
| 105 | - apply_filters( |
|
| 106 | - 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
| 107 | - true |
|
| 108 | - ), |
|
| 109 | - FILTER_VALIDATE_BOOLEAN |
|
| 110 | - ); |
|
| 111 | - } |
|
| 98 | + /** |
|
| 99 | + * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + private function isModalActive() |
|
| 103 | + { |
|
| 104 | + return filter_var( |
|
| 105 | + apply_filters( |
|
| 106 | + 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
| 107 | + true |
|
| 108 | + ), |
|
| 109 | + FILTER_VALIDATE_BOOLEAN |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | \ No newline at end of file |
@@ -473,7 +473,7 @@ |
||
| 473 | 473 | * |
| 474 | 474 | * @param EE_Ticket $ticket |
| 475 | 475 | * @param int $qty |
| 476 | - * @return TRUE on success, FALSE on fail |
|
| 476 | + * @return boolean on success, FALSE on fail |
|
| 477 | 477 | * @throws InvalidArgumentException |
| 478 | 478 | * @throws InvalidInterfaceException |
| 479 | 479 | * @throws InvalidDataTypeException |
@@ -34,526 +34,526 @@ |
||
| 34 | 34 | class ProcessTicketSelector |
| 35 | 35 | { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var EE_Cart $cart |
|
| 39 | - */ |
|
| 40 | - private $cart; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var EE_Core_Config $core_config |
|
| 44 | - */ |
|
| 45 | - private $core_config; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var Request $request |
|
| 49 | - */ |
|
| 50 | - private $request; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var EE_Session $session |
|
| 54 | - */ |
|
| 55 | - private $session; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var EEM_Ticket $ticket_model |
|
| 59 | - */ |
|
| 60 | - private $ticket_model; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var TicketDatetimeAvailabilityTracker $tracker |
|
| 64 | - */ |
|
| 65 | - private $tracker; |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * ProcessTicketSelector constructor. |
|
| 70 | - * NOTE: PLZ use the Loader to instantiate this class if need be |
|
| 71 | - * so that all dependencies get injected correctly (which will happen automatically) |
|
| 72 | - * Null values for parameters are only for backwards compatibility but will be removed later on. |
|
| 73 | - * |
|
| 74 | - * @param EE_Core_Config $core_config |
|
| 75 | - * @param Request $request |
|
| 76 | - * @param EE_Session $session |
|
| 77 | - * @param EEM_Ticket $ticket_model |
|
| 78 | - * @param TicketDatetimeAvailabilityTracker $tracker |
|
| 79 | - * @throws InvalidArgumentException |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - * @throws InvalidInterfaceException |
|
| 82 | - */ |
|
| 83 | - public function __construct( |
|
| 84 | - EE_Core_Config $core_config = null, |
|
| 85 | - Request $request = null, |
|
| 86 | - EE_Session $session = null, |
|
| 87 | - EEM_Ticket $ticket_model = null, |
|
| 88 | - TicketDatetimeAvailabilityTracker $tracker = null |
|
| 89 | - ) { |
|
| 90 | - /** @var LoaderInterface $loader */ |
|
| 91 | - $loader = LoaderFactory::getLoader(); |
|
| 92 | - $this->core_config = $core_config instanceof EE_Core_Config |
|
| 93 | - ? $core_config |
|
| 94 | - : $loader->getShared('EE_Core_Config'); |
|
| 95 | - $this->request = $request instanceof Request |
|
| 96 | - ? $request |
|
| 97 | - : $loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 98 | - $this->session = $session instanceof EE_Session |
|
| 99 | - ? $session |
|
| 100 | - : $loader->getShared('EE_Session'); |
|
| 101 | - $this->ticket_model = $ticket_model instanceof EEM_Ticket |
|
| 102 | - ? $ticket_model |
|
| 103 | - : $loader->getShared('EEM_Ticket'); |
|
| 104 | - $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker |
|
| 105 | - ? $tracker |
|
| 106 | - : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * cancelTicketSelections |
|
| 112 | - * |
|
| 113 | - * @return bool |
|
| 114 | - * @throws EE_Error |
|
| 115 | - * @throws InvalidArgumentException |
|
| 116 | - * @throws InvalidInterfaceException |
|
| 117 | - * @throws InvalidDataTypeException |
|
| 118 | - */ |
|
| 119 | - public function cancelTicketSelections() |
|
| 120 | - { |
|
| 121 | - // check nonce |
|
| 122 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 123 | - return false; |
|
| 124 | - } |
|
| 125 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 126 | - if ($this->request->requestParamIsSet('event_id')) { |
|
| 127 | - EEH_URL::safeRedirectAndExit( |
|
| 128 | - EEH_Event_View::event_link_url( |
|
| 129 | - $this->request->getRequestParam('event_id') |
|
| 130 | - ) |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - EEH_URL::safeRedirectAndExit( |
|
| 134 | - site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
| 135 | - ); |
|
| 136 | - return true; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * processTicketSelectorNonce |
|
| 142 | - * |
|
| 143 | - * @param string $nonce_name |
|
| 144 | - * @param string $id |
|
| 145 | - * @return bool |
|
| 146 | - */ |
|
| 147 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
| 148 | - { |
|
| 149 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
| 150 | - if ( |
|
| 151 | - ! $this->request->isAdmin() |
|
| 152 | - && ( |
|
| 153 | - ! $this->request->is_set($nonce_name_with_id) |
|
| 154 | - || ! wp_verify_nonce( |
|
| 155 | - $this->request->get($nonce_name_with_id), |
|
| 156 | - $nonce_name |
|
| 157 | - ) |
|
| 158 | - ) |
|
| 159 | - ) { |
|
| 160 | - EE_Error::add_error( |
|
| 161 | - sprintf( |
|
| 162 | - esc_html__( |
|
| 163 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 164 | - 'event_espresso' |
|
| 165 | - ), |
|
| 166 | - '<br/>' |
|
| 167 | - ), |
|
| 168 | - __FILE__, |
|
| 169 | - __FUNCTION__, |
|
| 170 | - __LINE__ |
|
| 171 | - ); |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - return true; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * process_ticket_selections |
|
| 180 | - * |
|
| 181 | - * @return array|bool |
|
| 182 | - * @throws EE_Error |
|
| 183 | - * @throws InvalidArgumentException |
|
| 184 | - * @throws InvalidDataTypeException |
|
| 185 | - * @throws InvalidInterfaceException |
|
| 186 | - */ |
|
| 187 | - public function processTicketSelections() |
|
| 188 | - { |
|
| 189 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 190 | - if($this->request->isBot()) { |
|
| 191 | - EEH_URL::safeRedirectAndExit( |
|
| 192 | - apply_filters( |
|
| 193 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
| 194 | - site_url() |
|
| 195 | - ) |
|
| 196 | - ); |
|
| 197 | - } |
|
| 198 | - // do we have an event id? |
|
| 199 | - $id = $this->getEventId(); |
|
| 200 | - // we should really only have 1 registration in the works now |
|
| 201 | - // (ie, no MER) so unless otherwise requested, clear the session |
|
| 202 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 203 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 204 | - } |
|
| 205 | - // validate/sanitize/filter data |
|
| 206 | - $valid = apply_filters( |
|
| 207 | - 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
| 208 | - $this->validatePostData($id) |
|
| 209 | - ); |
|
| 210 | - //check total tickets ordered vs max number of attendees that can register |
|
| 211 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
| 212 | - $this->maxAttendeesViolation($valid); |
|
| 213 | - } else { |
|
| 214 | - // all data appears to be valid |
|
| 215 | - if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
| 216 | - return true; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 220 | - // at this point, just return if registration is being made from admin |
|
| 221 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 222 | - return false; |
|
| 223 | - } |
|
| 224 | - if ($valid['return_url']) { |
|
| 225 | - EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
| 226 | - } |
|
| 227 | - if ($id) { |
|
| 228 | - EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
| 229 | - } |
|
| 230 | - echo EE_Error::get_notices(); |
|
| 231 | - return false; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @return int |
|
| 237 | - */ |
|
| 238 | - private function getEventId() |
|
| 239 | - { |
|
| 240 | - // do we have an event id? |
|
| 241 | - if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
| 242 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
| 243 | - EE_Error::add_error( |
|
| 244 | - sprintf( |
|
| 245 | - esc_html__( |
|
| 246 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
| 247 | - 'event_espresso' |
|
| 248 | - ), |
|
| 249 | - '<br/>' |
|
| 250 | - ), |
|
| 251 | - __FILE__, |
|
| 252 | - __FUNCTION__, |
|
| 253 | - __LINE__ |
|
| 254 | - ); |
|
| 255 | - } |
|
| 256 | - //if event id is valid |
|
| 257 | - return absint($this->request->getRequestParam('tkt-slctr-event-id')); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * validate_post_data |
|
| 263 | - * |
|
| 264 | - * @param int $id |
|
| 265 | - * @return array|FALSE |
|
| 266 | - */ |
|
| 267 | - private function validatePostData($id = 0) |
|
| 268 | - { |
|
| 269 | - if (! $id) { |
|
| 270 | - EE_Error::add_error( |
|
| 271 | - esc_html__('The event id provided was not valid.', 'event_espresso'), |
|
| 272 | - __FILE__, |
|
| 273 | - __FUNCTION__, |
|
| 274 | - __LINE__ |
|
| 275 | - ); |
|
| 276 | - return false; |
|
| 277 | - } |
|
| 278 | - // start with an empty array() |
|
| 279 | - $valid_data = array(); |
|
| 280 | - // grab valid id |
|
| 281 | - $valid_data['id'] = $id; |
|
| 282 | - // array of other form names |
|
| 283 | - $inputs_to_clean = array( |
|
| 284 | - 'event_id' => 'tkt-slctr-event-id', |
|
| 285 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
| 286 | - 'rows' => 'tkt-slctr-rows-', |
|
| 287 | - 'qty' => 'tkt-slctr-qty-', |
|
| 288 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
| 289 | - 'return_url' => 'tkt-slctr-return-url-', |
|
| 290 | - ); |
|
| 291 | - // let's track the total number of tickets ordered.' |
|
| 292 | - $valid_data['total_tickets'] = 0; |
|
| 293 | - // cycle through $inputs_to_clean array |
|
| 294 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
| 295 | - // check for POST data |
|
| 296 | - if ($this->request->requestParamIsSet($input_to_clean . $id)) { |
|
| 297 | - // grab value |
|
| 298 | - $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
| 299 | - switch ($what) { |
|
| 300 | - // integers |
|
| 301 | - case 'event_id': |
|
| 302 | - $valid_data[ $what ] = absint($input_value); |
|
| 303 | - // get event via the event id we put in the form |
|
| 304 | - break; |
|
| 305 | - case 'rows': |
|
| 306 | - case 'max_atndz': |
|
| 307 | - $valid_data[ $what ] = absint($input_value); |
|
| 308 | - break; |
|
| 309 | - // arrays of integers |
|
| 310 | - case 'qty': |
|
| 311 | - /** @var array $row_qty */ |
|
| 312 | - $row_qty = $input_value; |
|
| 313 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
| 314 | - if (! is_array($row_qty)) { |
|
| 315 | - /** @var string $row_qty */ |
|
| 316 | - // get number of rows |
|
| 317 | - $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
| 318 | - ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
| 319 | - : 1; |
|
| 320 | - // explode integers by the dash |
|
| 321 | - $row_qty = explode('-', $row_qty); |
|
| 322 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
| 323 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
| 324 | - $row_qty = array($row => $qty); |
|
| 325 | - for ($x = 1; $x <= $rows; $x++) { |
|
| 326 | - if (! isset($row_qty[ $x ])) { |
|
| 327 | - $row_qty[ $x ] = 0; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - ksort($row_qty); |
|
| 332 | - // cycle thru values |
|
| 333 | - foreach ($row_qty as $qty) { |
|
| 334 | - $qty = absint($qty); |
|
| 335 | - // sanitize as integers |
|
| 336 | - $valid_data[ $what ][] = $qty; |
|
| 337 | - $valid_data['total_tickets'] += $qty; |
|
| 338 | - } |
|
| 339 | - break; |
|
| 340 | - // array of integers |
|
| 341 | - case 'ticket_id': |
|
| 342 | - // cycle thru values |
|
| 343 | - foreach ((array) $input_value as $key => $value) { |
|
| 344 | - // allow only integers |
|
| 345 | - $valid_data[ $what ][ $key ] = absint($value); |
|
| 346 | - } |
|
| 347 | - break; |
|
| 348 | - case 'return_url' : |
|
| 349 | - // grab and sanitize return-url |
|
| 350 | - $input_value = esc_url_raw($input_value); |
|
| 351 | - // was the request coming from an iframe ? if so, then: |
|
| 352 | - if (strpos($input_value, 'event_list=iframe')) { |
|
| 353 | - // get anchor fragment |
|
| 354 | - $input_value = explode('#', $input_value); |
|
| 355 | - $input_value = end($input_value); |
|
| 356 | - // use event list url instead, but append anchor |
|
| 357 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
| 358 | - } |
|
| 359 | - $valid_data[ $what ] = $input_value; |
|
| 360 | - break; |
|
| 361 | - } // end switch $what |
|
| 362 | - } |
|
| 363 | - } // end foreach $inputs_to_clean |
|
| 364 | - return $valid_data; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * @param array $valid |
|
| 370 | - */ |
|
| 371 | - private function maxAttendeesViolation(array $valid) |
|
| 372 | - { |
|
| 373 | - // ordering too many tickets !!! |
|
| 374 | - $total_tickets_string = esc_html( |
|
| 375 | - _n( |
|
| 376 | - 'You have attempted to purchase %s ticket.', |
|
| 377 | - 'You have attempted to purchase %s tickets.', |
|
| 378 | - $valid['total_tickets'], |
|
| 379 | - 'event_espresso' |
|
| 380 | - ) |
|
| 381 | - ); |
|
| 382 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 383 | - // dev only message |
|
| 384 | - $max_attendees_string = esc_html( |
|
| 385 | - _n( |
|
| 386 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 387 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 388 | - $valid['max_atndz'], |
|
| 389 | - 'event_espresso' |
|
| 390 | - ) |
|
| 391 | - ); |
|
| 392 | - $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 393 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * @param array $valid |
|
| 399 | - * @return int|TRUE |
|
| 400 | - * @throws EE_Error |
|
| 401 | - * @throws InvalidArgumentException |
|
| 402 | - * @throws InvalidDataTypeException |
|
| 403 | - * @throws InvalidInterfaceException |
|
| 404 | - */ |
|
| 405 | - private function addTicketsToCart(array $valid) |
|
| 406 | - { |
|
| 407 | - $tickets_added = 0; |
|
| 408 | - $tickets_selected = false; |
|
| 409 | - if($valid['total_tickets'] > 0){ |
|
| 410 | - // load cart using factory because we don't want to do so until actually needed |
|
| 411 | - $this->cart = CartFactory::getCart(); |
|
| 412 | - // cycle thru the number of data rows sent from the event listing |
|
| 413 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
| 414 | - // does this row actually contain a ticket quantity? |
|
| 415 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
| 416 | - // YES we have a ticket quantity |
|
| 417 | - $tickets_selected = true; |
|
| 418 | - $valid_ticket = false; |
|
| 419 | - // \EEH_Debug_Tools::printr( |
|
| 420 | - // $valid['ticket_id'][ $x ], |
|
| 421 | - // '$valid[\'ticket_id\'][ $x ]', |
|
| 422 | - // __FILE__, __LINE__ |
|
| 423 | - // ); |
|
| 424 | - if (isset($valid['ticket_id'][ $x ])) { |
|
| 425 | - // get ticket via the ticket id we put in the form |
|
| 426 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
| 427 | - if ($ticket instanceof EE_Ticket) { |
|
| 428 | - $valid_ticket = true; |
|
| 429 | - $tickets_added += $this->addTicketToCart( |
|
| 430 | - $ticket, |
|
| 431 | - $valid['qty'][ $x ] |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - if ($valid_ticket !== true) { |
|
| 436 | - // nothing added to cart retrieved |
|
| 437 | - EE_Error::add_error( |
|
| 438 | - sprintf( |
|
| 439 | - esc_html__( |
|
| 440 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 441 | - 'event_espresso' |
|
| 442 | - ), |
|
| 443 | - '<br/>' |
|
| 444 | - ), |
|
| 445 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 446 | - ); |
|
| 447 | - } |
|
| 448 | - if (EE_Error::has_error()) { |
|
| 449 | - break; |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - do_action( |
|
| 455 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 456 | - $this->cart, |
|
| 457 | - $this |
|
| 458 | - ); |
|
| 459 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 460 | - // no ticket quantities were selected |
|
| 461 | - EE_Error::add_error( |
|
| 462 | - esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
| 463 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 464 | - ); |
|
| 465 | - } |
|
| 466 | - return $tickets_added; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * adds a ticket to the cart |
|
| 473 | - * |
|
| 474 | - * @param EE_Ticket $ticket |
|
| 475 | - * @param int $qty |
|
| 476 | - * @return TRUE on success, FALSE on fail |
|
| 477 | - * @throws InvalidArgumentException |
|
| 478 | - * @throws InvalidInterfaceException |
|
| 479 | - * @throws InvalidDataTypeException |
|
| 480 | - * @throws EE_Error |
|
| 481 | - */ |
|
| 482 | - private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
| 483 | - { |
|
| 484 | - // get the number of spaces left for this datetime ticket |
|
| 485 | - $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
| 486 | - // compare available spaces against the number of tickets being purchased |
|
| 487 | - if ($available_spaces >= $qty) { |
|
| 488 | - // allow addons to prevent a ticket from being added to cart |
|
| 489 | - if ( |
|
| 490 | - ! apply_filters( |
|
| 491 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 492 | - true, |
|
| 493 | - $ticket, |
|
| 494 | - $qty, |
|
| 495 | - $available_spaces |
|
| 496 | - ) |
|
| 497 | - ) { |
|
| 498 | - return false; |
|
| 499 | - } |
|
| 500 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
| 501 | - // add event to cart |
|
| 502 | - if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
| 503 | - $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 504 | - return true; |
|
| 505 | - } |
|
| 506 | - return false; |
|
| 507 | - } |
|
| 508 | - $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
| 509 | - return false; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * @param $tickets_added |
|
| 515 | - * @return bool |
|
| 516 | - * @throws InvalidInterfaceException |
|
| 517 | - * @throws InvalidDataTypeException |
|
| 518 | - * @throws EE_Error |
|
| 519 | - * @throws InvalidArgumentException |
|
| 520 | - */ |
|
| 521 | - private function processSuccessfulCart($tickets_added) |
|
| 522 | - { |
|
| 523 | - // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 524 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
| 525 | - // make sure cart is loaded |
|
| 526 | - if(! $this->cart instanceof EE_Cart){ |
|
| 527 | - $this->cart = CartFactory::getCart(); |
|
| 528 | - } |
|
| 529 | - do_action( |
|
| 530 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 531 | - $this->cart, |
|
| 532 | - $this |
|
| 533 | - ); |
|
| 534 | - $this->cart->recalculate_all_cart_totals(); |
|
| 535 | - $this->cart->save_cart(false); |
|
| 536 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 537 | - // just return TRUE for registrations being made from admin |
|
| 538 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 539 | - return true; |
|
| 540 | - } |
|
| 541 | - EEH_URL::safeRedirectAndExit( |
|
| 542 | - apply_filters( |
|
| 543 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 544 | - $this->core_config->reg_page_url() |
|
| 545 | - ) |
|
| 546 | - ); |
|
| 547 | - } |
|
| 548 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 549 | - // nothing added to cart |
|
| 550 | - EE_Error::add_attention( |
|
| 551 | - esc_html__('No tickets were added for the event', 'event_espresso'), |
|
| 552 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 553 | - ); |
|
| 554 | - } |
|
| 555 | - return false; |
|
| 556 | - } |
|
| 37 | + /** |
|
| 38 | + * @var EE_Cart $cart |
|
| 39 | + */ |
|
| 40 | + private $cart; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var EE_Core_Config $core_config |
|
| 44 | + */ |
|
| 45 | + private $core_config; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var Request $request |
|
| 49 | + */ |
|
| 50 | + private $request; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var EE_Session $session |
|
| 54 | + */ |
|
| 55 | + private $session; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var EEM_Ticket $ticket_model |
|
| 59 | + */ |
|
| 60 | + private $ticket_model; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var TicketDatetimeAvailabilityTracker $tracker |
|
| 64 | + */ |
|
| 65 | + private $tracker; |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * ProcessTicketSelector constructor. |
|
| 70 | + * NOTE: PLZ use the Loader to instantiate this class if need be |
|
| 71 | + * so that all dependencies get injected correctly (which will happen automatically) |
|
| 72 | + * Null values for parameters are only for backwards compatibility but will be removed later on. |
|
| 73 | + * |
|
| 74 | + * @param EE_Core_Config $core_config |
|
| 75 | + * @param Request $request |
|
| 76 | + * @param EE_Session $session |
|
| 77 | + * @param EEM_Ticket $ticket_model |
|
| 78 | + * @param TicketDatetimeAvailabilityTracker $tracker |
|
| 79 | + * @throws InvalidArgumentException |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + * @throws InvalidInterfaceException |
|
| 82 | + */ |
|
| 83 | + public function __construct( |
|
| 84 | + EE_Core_Config $core_config = null, |
|
| 85 | + Request $request = null, |
|
| 86 | + EE_Session $session = null, |
|
| 87 | + EEM_Ticket $ticket_model = null, |
|
| 88 | + TicketDatetimeAvailabilityTracker $tracker = null |
|
| 89 | + ) { |
|
| 90 | + /** @var LoaderInterface $loader */ |
|
| 91 | + $loader = LoaderFactory::getLoader(); |
|
| 92 | + $this->core_config = $core_config instanceof EE_Core_Config |
|
| 93 | + ? $core_config |
|
| 94 | + : $loader->getShared('EE_Core_Config'); |
|
| 95 | + $this->request = $request instanceof Request |
|
| 96 | + ? $request |
|
| 97 | + : $loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 98 | + $this->session = $session instanceof EE_Session |
|
| 99 | + ? $session |
|
| 100 | + : $loader->getShared('EE_Session'); |
|
| 101 | + $this->ticket_model = $ticket_model instanceof EEM_Ticket |
|
| 102 | + ? $ticket_model |
|
| 103 | + : $loader->getShared('EEM_Ticket'); |
|
| 104 | + $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker |
|
| 105 | + ? $tracker |
|
| 106 | + : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * cancelTicketSelections |
|
| 112 | + * |
|
| 113 | + * @return bool |
|
| 114 | + * @throws EE_Error |
|
| 115 | + * @throws InvalidArgumentException |
|
| 116 | + * @throws InvalidInterfaceException |
|
| 117 | + * @throws InvalidDataTypeException |
|
| 118 | + */ |
|
| 119 | + public function cancelTicketSelections() |
|
| 120 | + { |
|
| 121 | + // check nonce |
|
| 122 | + if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 123 | + return false; |
|
| 124 | + } |
|
| 125 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 126 | + if ($this->request->requestParamIsSet('event_id')) { |
|
| 127 | + EEH_URL::safeRedirectAndExit( |
|
| 128 | + EEH_Event_View::event_link_url( |
|
| 129 | + $this->request->getRequestParam('event_id') |
|
| 130 | + ) |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + EEH_URL::safeRedirectAndExit( |
|
| 134 | + site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
| 135 | + ); |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * processTicketSelectorNonce |
|
| 142 | + * |
|
| 143 | + * @param string $nonce_name |
|
| 144 | + * @param string $id |
|
| 145 | + * @return bool |
|
| 146 | + */ |
|
| 147 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
| 148 | + { |
|
| 149 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
| 150 | + if ( |
|
| 151 | + ! $this->request->isAdmin() |
|
| 152 | + && ( |
|
| 153 | + ! $this->request->is_set($nonce_name_with_id) |
|
| 154 | + || ! wp_verify_nonce( |
|
| 155 | + $this->request->get($nonce_name_with_id), |
|
| 156 | + $nonce_name |
|
| 157 | + ) |
|
| 158 | + ) |
|
| 159 | + ) { |
|
| 160 | + EE_Error::add_error( |
|
| 161 | + sprintf( |
|
| 162 | + esc_html__( |
|
| 163 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 164 | + 'event_espresso' |
|
| 165 | + ), |
|
| 166 | + '<br/>' |
|
| 167 | + ), |
|
| 168 | + __FILE__, |
|
| 169 | + __FUNCTION__, |
|
| 170 | + __LINE__ |
|
| 171 | + ); |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + return true; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * process_ticket_selections |
|
| 180 | + * |
|
| 181 | + * @return array|bool |
|
| 182 | + * @throws EE_Error |
|
| 183 | + * @throws InvalidArgumentException |
|
| 184 | + * @throws InvalidDataTypeException |
|
| 185 | + * @throws InvalidInterfaceException |
|
| 186 | + */ |
|
| 187 | + public function processTicketSelections() |
|
| 188 | + { |
|
| 189 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 190 | + if($this->request->isBot()) { |
|
| 191 | + EEH_URL::safeRedirectAndExit( |
|
| 192 | + apply_filters( |
|
| 193 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
| 194 | + site_url() |
|
| 195 | + ) |
|
| 196 | + ); |
|
| 197 | + } |
|
| 198 | + // do we have an event id? |
|
| 199 | + $id = $this->getEventId(); |
|
| 200 | + // we should really only have 1 registration in the works now |
|
| 201 | + // (ie, no MER) so unless otherwise requested, clear the session |
|
| 202 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 203 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 204 | + } |
|
| 205 | + // validate/sanitize/filter data |
|
| 206 | + $valid = apply_filters( |
|
| 207 | + 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
| 208 | + $this->validatePostData($id) |
|
| 209 | + ); |
|
| 210 | + //check total tickets ordered vs max number of attendees that can register |
|
| 211 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
| 212 | + $this->maxAttendeesViolation($valid); |
|
| 213 | + } else { |
|
| 214 | + // all data appears to be valid |
|
| 215 | + if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
| 216 | + return true; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 220 | + // at this point, just return if registration is being made from admin |
|
| 221 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 224 | + if ($valid['return_url']) { |
|
| 225 | + EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
| 226 | + } |
|
| 227 | + if ($id) { |
|
| 228 | + EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
| 229 | + } |
|
| 230 | + echo EE_Error::get_notices(); |
|
| 231 | + return false; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @return int |
|
| 237 | + */ |
|
| 238 | + private function getEventId() |
|
| 239 | + { |
|
| 240 | + // do we have an event id? |
|
| 241 | + if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
| 242 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
| 243 | + EE_Error::add_error( |
|
| 244 | + sprintf( |
|
| 245 | + esc_html__( |
|
| 246 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
| 247 | + 'event_espresso' |
|
| 248 | + ), |
|
| 249 | + '<br/>' |
|
| 250 | + ), |
|
| 251 | + __FILE__, |
|
| 252 | + __FUNCTION__, |
|
| 253 | + __LINE__ |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | + //if event id is valid |
|
| 257 | + return absint($this->request->getRequestParam('tkt-slctr-event-id')); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * validate_post_data |
|
| 263 | + * |
|
| 264 | + * @param int $id |
|
| 265 | + * @return array|FALSE |
|
| 266 | + */ |
|
| 267 | + private function validatePostData($id = 0) |
|
| 268 | + { |
|
| 269 | + if (! $id) { |
|
| 270 | + EE_Error::add_error( |
|
| 271 | + esc_html__('The event id provided was not valid.', 'event_espresso'), |
|
| 272 | + __FILE__, |
|
| 273 | + __FUNCTION__, |
|
| 274 | + __LINE__ |
|
| 275 | + ); |
|
| 276 | + return false; |
|
| 277 | + } |
|
| 278 | + // start with an empty array() |
|
| 279 | + $valid_data = array(); |
|
| 280 | + // grab valid id |
|
| 281 | + $valid_data['id'] = $id; |
|
| 282 | + // array of other form names |
|
| 283 | + $inputs_to_clean = array( |
|
| 284 | + 'event_id' => 'tkt-slctr-event-id', |
|
| 285 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
| 286 | + 'rows' => 'tkt-slctr-rows-', |
|
| 287 | + 'qty' => 'tkt-slctr-qty-', |
|
| 288 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
| 289 | + 'return_url' => 'tkt-slctr-return-url-', |
|
| 290 | + ); |
|
| 291 | + // let's track the total number of tickets ordered.' |
|
| 292 | + $valid_data['total_tickets'] = 0; |
|
| 293 | + // cycle through $inputs_to_clean array |
|
| 294 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
| 295 | + // check for POST data |
|
| 296 | + if ($this->request->requestParamIsSet($input_to_clean . $id)) { |
|
| 297 | + // grab value |
|
| 298 | + $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
| 299 | + switch ($what) { |
|
| 300 | + // integers |
|
| 301 | + case 'event_id': |
|
| 302 | + $valid_data[ $what ] = absint($input_value); |
|
| 303 | + // get event via the event id we put in the form |
|
| 304 | + break; |
|
| 305 | + case 'rows': |
|
| 306 | + case 'max_atndz': |
|
| 307 | + $valid_data[ $what ] = absint($input_value); |
|
| 308 | + break; |
|
| 309 | + // arrays of integers |
|
| 310 | + case 'qty': |
|
| 311 | + /** @var array $row_qty */ |
|
| 312 | + $row_qty = $input_value; |
|
| 313 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
| 314 | + if (! is_array($row_qty)) { |
|
| 315 | + /** @var string $row_qty */ |
|
| 316 | + // get number of rows |
|
| 317 | + $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
| 318 | + ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
| 319 | + : 1; |
|
| 320 | + // explode integers by the dash |
|
| 321 | + $row_qty = explode('-', $row_qty); |
|
| 322 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
| 323 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
| 324 | + $row_qty = array($row => $qty); |
|
| 325 | + for ($x = 1; $x <= $rows; $x++) { |
|
| 326 | + if (! isset($row_qty[ $x ])) { |
|
| 327 | + $row_qty[ $x ] = 0; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + ksort($row_qty); |
|
| 332 | + // cycle thru values |
|
| 333 | + foreach ($row_qty as $qty) { |
|
| 334 | + $qty = absint($qty); |
|
| 335 | + // sanitize as integers |
|
| 336 | + $valid_data[ $what ][] = $qty; |
|
| 337 | + $valid_data['total_tickets'] += $qty; |
|
| 338 | + } |
|
| 339 | + break; |
|
| 340 | + // array of integers |
|
| 341 | + case 'ticket_id': |
|
| 342 | + // cycle thru values |
|
| 343 | + foreach ((array) $input_value as $key => $value) { |
|
| 344 | + // allow only integers |
|
| 345 | + $valid_data[ $what ][ $key ] = absint($value); |
|
| 346 | + } |
|
| 347 | + break; |
|
| 348 | + case 'return_url' : |
|
| 349 | + // grab and sanitize return-url |
|
| 350 | + $input_value = esc_url_raw($input_value); |
|
| 351 | + // was the request coming from an iframe ? if so, then: |
|
| 352 | + if (strpos($input_value, 'event_list=iframe')) { |
|
| 353 | + // get anchor fragment |
|
| 354 | + $input_value = explode('#', $input_value); |
|
| 355 | + $input_value = end($input_value); |
|
| 356 | + // use event list url instead, but append anchor |
|
| 357 | + $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
| 358 | + } |
|
| 359 | + $valid_data[ $what ] = $input_value; |
|
| 360 | + break; |
|
| 361 | + } // end switch $what |
|
| 362 | + } |
|
| 363 | + } // end foreach $inputs_to_clean |
|
| 364 | + return $valid_data; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * @param array $valid |
|
| 370 | + */ |
|
| 371 | + private function maxAttendeesViolation(array $valid) |
|
| 372 | + { |
|
| 373 | + // ordering too many tickets !!! |
|
| 374 | + $total_tickets_string = esc_html( |
|
| 375 | + _n( |
|
| 376 | + 'You have attempted to purchase %s ticket.', |
|
| 377 | + 'You have attempted to purchase %s tickets.', |
|
| 378 | + $valid['total_tickets'], |
|
| 379 | + 'event_espresso' |
|
| 380 | + ) |
|
| 381 | + ); |
|
| 382 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 383 | + // dev only message |
|
| 384 | + $max_attendees_string = esc_html( |
|
| 385 | + _n( |
|
| 386 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 387 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 388 | + $valid['max_atndz'], |
|
| 389 | + 'event_espresso' |
|
| 390 | + ) |
|
| 391 | + ); |
|
| 392 | + $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 393 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * @param array $valid |
|
| 399 | + * @return int|TRUE |
|
| 400 | + * @throws EE_Error |
|
| 401 | + * @throws InvalidArgumentException |
|
| 402 | + * @throws InvalidDataTypeException |
|
| 403 | + * @throws InvalidInterfaceException |
|
| 404 | + */ |
|
| 405 | + private function addTicketsToCart(array $valid) |
|
| 406 | + { |
|
| 407 | + $tickets_added = 0; |
|
| 408 | + $tickets_selected = false; |
|
| 409 | + if($valid['total_tickets'] > 0){ |
|
| 410 | + // load cart using factory because we don't want to do so until actually needed |
|
| 411 | + $this->cart = CartFactory::getCart(); |
|
| 412 | + // cycle thru the number of data rows sent from the event listing |
|
| 413 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
| 414 | + // does this row actually contain a ticket quantity? |
|
| 415 | + if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
| 416 | + // YES we have a ticket quantity |
|
| 417 | + $tickets_selected = true; |
|
| 418 | + $valid_ticket = false; |
|
| 419 | + // \EEH_Debug_Tools::printr( |
|
| 420 | + // $valid['ticket_id'][ $x ], |
|
| 421 | + // '$valid[\'ticket_id\'][ $x ]', |
|
| 422 | + // __FILE__, __LINE__ |
|
| 423 | + // ); |
|
| 424 | + if (isset($valid['ticket_id'][ $x ])) { |
|
| 425 | + // get ticket via the ticket id we put in the form |
|
| 426 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
| 427 | + if ($ticket instanceof EE_Ticket) { |
|
| 428 | + $valid_ticket = true; |
|
| 429 | + $tickets_added += $this->addTicketToCart( |
|
| 430 | + $ticket, |
|
| 431 | + $valid['qty'][ $x ] |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + if ($valid_ticket !== true) { |
|
| 436 | + // nothing added to cart retrieved |
|
| 437 | + EE_Error::add_error( |
|
| 438 | + sprintf( |
|
| 439 | + esc_html__( |
|
| 440 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 441 | + 'event_espresso' |
|
| 442 | + ), |
|
| 443 | + '<br/>' |
|
| 444 | + ), |
|
| 445 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 446 | + ); |
|
| 447 | + } |
|
| 448 | + if (EE_Error::has_error()) { |
|
| 449 | + break; |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + do_action( |
|
| 455 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 456 | + $this->cart, |
|
| 457 | + $this |
|
| 458 | + ); |
|
| 459 | + if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 460 | + // no ticket quantities were selected |
|
| 461 | + EE_Error::add_error( |
|
| 462 | + esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
| 463 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 464 | + ); |
|
| 465 | + } |
|
| 466 | + return $tickets_added; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * adds a ticket to the cart |
|
| 473 | + * |
|
| 474 | + * @param EE_Ticket $ticket |
|
| 475 | + * @param int $qty |
|
| 476 | + * @return TRUE on success, FALSE on fail |
|
| 477 | + * @throws InvalidArgumentException |
|
| 478 | + * @throws InvalidInterfaceException |
|
| 479 | + * @throws InvalidDataTypeException |
|
| 480 | + * @throws EE_Error |
|
| 481 | + */ |
|
| 482 | + private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
| 483 | + { |
|
| 484 | + // get the number of spaces left for this datetime ticket |
|
| 485 | + $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
| 486 | + // compare available spaces against the number of tickets being purchased |
|
| 487 | + if ($available_spaces >= $qty) { |
|
| 488 | + // allow addons to prevent a ticket from being added to cart |
|
| 489 | + if ( |
|
| 490 | + ! apply_filters( |
|
| 491 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 492 | + true, |
|
| 493 | + $ticket, |
|
| 494 | + $qty, |
|
| 495 | + $available_spaces |
|
| 496 | + ) |
|
| 497 | + ) { |
|
| 498 | + return false; |
|
| 499 | + } |
|
| 500 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
| 501 | + // add event to cart |
|
| 502 | + if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
| 503 | + $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 504 | + return true; |
|
| 505 | + } |
|
| 506 | + return false; |
|
| 507 | + } |
|
| 508 | + $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
| 509 | + return false; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * @param $tickets_added |
|
| 515 | + * @return bool |
|
| 516 | + * @throws InvalidInterfaceException |
|
| 517 | + * @throws InvalidDataTypeException |
|
| 518 | + * @throws EE_Error |
|
| 519 | + * @throws InvalidArgumentException |
|
| 520 | + */ |
|
| 521 | + private function processSuccessfulCart($tickets_added) |
|
| 522 | + { |
|
| 523 | + // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 524 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
| 525 | + // make sure cart is loaded |
|
| 526 | + if(! $this->cart instanceof EE_Cart){ |
|
| 527 | + $this->cart = CartFactory::getCart(); |
|
| 528 | + } |
|
| 529 | + do_action( |
|
| 530 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 531 | + $this->cart, |
|
| 532 | + $this |
|
| 533 | + ); |
|
| 534 | + $this->cart->recalculate_all_cart_totals(); |
|
| 535 | + $this->cart->save_cart(false); |
|
| 536 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 537 | + // just return TRUE for registrations being made from admin |
|
| 538 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 539 | + return true; |
|
| 540 | + } |
|
| 541 | + EEH_URL::safeRedirectAndExit( |
|
| 542 | + apply_filters( |
|
| 543 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 544 | + $this->core_config->reg_page_url() |
|
| 545 | + ) |
|
| 546 | + ); |
|
| 547 | + } |
|
| 548 | + if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 549 | + // nothing added to cart |
|
| 550 | + EE_Error::add_attention( |
|
| 551 | + esc_html__('No tickets were added for the event', 'event_espresso'), |
|
| 552 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 553 | + ); |
|
| 554 | + } |
|
| 555 | + return false; |
|
| 556 | + } |
|
| 557 | 557 | } |
| 558 | 558 | // End of file ProcessTicketSelector.php |
| 559 | 559 | // Location: /ProcessTicketSelector.php |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public function cancelTicketSelections() |
| 120 | 120 | { |
| 121 | 121 | // check nonce |
| 122 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 122 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 123 | 123 | return false; |
| 124 | 124 | } |
| 125 | 125 | $this->session->clear_session(__CLASS__, __FUNCTION__); |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | ); |
| 132 | 132 | } |
| 133 | 133 | EEH_URL::safeRedirectAndExit( |
| 134 | - site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
| 134 | + site_url('/'.$this->core_config->event_cpt_slug.'/') |
|
| 135 | 135 | ); |
| 136 | 136 | return true; |
| 137 | 137 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | public function processTicketSelections() |
| 188 | 188 | { |
| 189 | 189 | do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
| 190 | - if($this->request->isBot()) { |
|
| 190 | + if ($this->request->isBot()) { |
|
| 191 | 191 | EEH_URL::safeRedirectAndExit( |
| 192 | 192 | apply_filters( |
| 193 | 193 | 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | private function getEventId() |
| 239 | 239 | { |
| 240 | 240 | // do we have an event id? |
| 241 | - if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
| 241 | + if ( ! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
| 242 | 242 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
| 243 | 243 | EE_Error::add_error( |
| 244 | 244 | sprintf( |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | private function validatePostData($id = 0) |
| 268 | 268 | { |
| 269 | - if (! $id) { |
|
| 269 | + if ( ! $id) { |
|
| 270 | 270 | EE_Error::add_error( |
| 271 | 271 | esc_html__('The event id provided was not valid.', 'event_espresso'), |
| 272 | 272 | __FILE__, |
@@ -293,29 +293,29 @@ discard block |
||
| 293 | 293 | // cycle through $inputs_to_clean array |
| 294 | 294 | foreach ($inputs_to_clean as $what => $input_to_clean) { |
| 295 | 295 | // check for POST data |
| 296 | - if ($this->request->requestParamIsSet($input_to_clean . $id)) { |
|
| 296 | + if ($this->request->requestParamIsSet($input_to_clean.$id)) { |
|
| 297 | 297 | // grab value |
| 298 | - $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
| 298 | + $input_value = $this->request->getRequestParam($input_to_clean.$id); |
|
| 299 | 299 | switch ($what) { |
| 300 | 300 | // integers |
| 301 | 301 | case 'event_id': |
| 302 | - $valid_data[ $what ] = absint($input_value); |
|
| 302 | + $valid_data[$what] = absint($input_value); |
|
| 303 | 303 | // get event via the event id we put in the form |
| 304 | 304 | break; |
| 305 | 305 | case 'rows': |
| 306 | 306 | case 'max_atndz': |
| 307 | - $valid_data[ $what ] = absint($input_value); |
|
| 307 | + $valid_data[$what] = absint($input_value); |
|
| 308 | 308 | break; |
| 309 | 309 | // arrays of integers |
| 310 | 310 | case 'qty': |
| 311 | 311 | /** @var array $row_qty */ |
| 312 | 312 | $row_qty = $input_value; |
| 313 | 313 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
| 314 | - if (! is_array($row_qty)) { |
|
| 314 | + if ( ! is_array($row_qty)) { |
|
| 315 | 315 | /** @var string $row_qty */ |
| 316 | 316 | // get number of rows |
| 317 | - $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
| 318 | - ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
| 317 | + $rows = $this->request->requestParamIsSet('tkt-slctr-rows-'.$id) |
|
| 318 | + ? absint($this->request->getRequestParam('tkt-slctr-rows-'.$id)) |
|
| 319 | 319 | : 1; |
| 320 | 320 | // explode integers by the dash |
| 321 | 321 | $row_qty = explode('-', $row_qty); |
@@ -323,8 +323,8 @@ discard block |
||
| 323 | 323 | $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
| 324 | 324 | $row_qty = array($row => $qty); |
| 325 | 325 | for ($x = 1; $x <= $rows; $x++) { |
| 326 | - if (! isset($row_qty[ $x ])) { |
|
| 327 | - $row_qty[ $x ] = 0; |
|
| 326 | + if ( ! isset($row_qty[$x])) { |
|
| 327 | + $row_qty[$x] = 0; |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | } |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | foreach ($row_qty as $qty) { |
| 334 | 334 | $qty = absint($qty); |
| 335 | 335 | // sanitize as integers |
| 336 | - $valid_data[ $what ][] = $qty; |
|
| 336 | + $valid_data[$what][] = $qty; |
|
| 337 | 337 | $valid_data['total_tickets'] += $qty; |
| 338 | 338 | } |
| 339 | 339 | break; |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | // cycle thru values |
| 343 | 343 | foreach ((array) $input_value as $key => $value) { |
| 344 | 344 | // allow only integers |
| 345 | - $valid_data[ $what ][ $key ] = absint($value); |
|
| 345 | + $valid_data[$what][$key] = absint($value); |
|
| 346 | 346 | } |
| 347 | 347 | break; |
| 348 | 348 | case 'return_url' : |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | $input_value = explode('#', $input_value); |
| 355 | 355 | $input_value = end($input_value); |
| 356 | 356 | // use event list url instead, but append anchor |
| 357 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
| 357 | + $input_value = EEH_Event_View::event_archive_url().'#'.$input_value; |
|
| 358 | 358 | } |
| 359 | - $valid_data[ $what ] = $input_value; |
|
| 359 | + $valid_data[$what] = $input_value; |
|
| 360 | 360 | break; |
| 361 | 361 | } // end switch $what |
| 362 | 362 | } |
@@ -389,8 +389,8 @@ discard block |
||
| 389 | 389 | 'event_espresso' |
| 390 | 390 | ) |
| 391 | 391 | ); |
| 392 | - $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 393 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 392 | + $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 393 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | |
@@ -406,13 +406,13 @@ discard block |
||
| 406 | 406 | { |
| 407 | 407 | $tickets_added = 0; |
| 408 | 408 | $tickets_selected = false; |
| 409 | - if($valid['total_tickets'] > 0){ |
|
| 409 | + if ($valid['total_tickets'] > 0) { |
|
| 410 | 410 | // load cart using factory because we don't want to do so until actually needed |
| 411 | 411 | $this->cart = CartFactory::getCart(); |
| 412 | 412 | // cycle thru the number of data rows sent from the event listing |
| 413 | 413 | for ($x = 0; $x < $valid['rows']; $x++) { |
| 414 | 414 | // does this row actually contain a ticket quantity? |
| 415 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
| 415 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
| 416 | 416 | // YES we have a ticket quantity |
| 417 | 417 | $tickets_selected = true; |
| 418 | 418 | $valid_ticket = false; |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | // '$valid[\'ticket_id\'][ $x ]', |
| 422 | 422 | // __FILE__, __LINE__ |
| 423 | 423 | // ); |
| 424 | - if (isset($valid['ticket_id'][ $x ])) { |
|
| 424 | + if (isset($valid['ticket_id'][$x])) { |
|
| 425 | 425 | // get ticket via the ticket id we put in the form |
| 426 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
| 426 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]); |
|
| 427 | 427 | if ($ticket instanceof EE_Ticket) { |
| 428 | - $valid_ticket = true; |
|
| 428 | + $valid_ticket = true; |
|
| 429 | 429 | $tickets_added += $this->addTicketToCart( |
| 430 | 430 | $ticket, |
| 431 | - $valid['qty'][ $x ] |
|
| 431 | + $valid['qty'][$x] |
|
| 432 | 432 | ); |
| 433 | 433 | } |
| 434 | 434 | } |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | $this->cart, |
| 457 | 457 | $this |
| 458 | 458 | ); |
| 459 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 459 | + if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 460 | 460 | // no ticket quantities were selected |
| 461 | 461 | EE_Error::add_error( |
| 462 | 462 | esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
| 524 | 524 | if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
| 525 | 525 | // make sure cart is loaded |
| 526 | - if(! $this->cart instanceof EE_Cart){ |
|
| 526 | + if ( ! $this->cart instanceof EE_Cart) { |
|
| 527 | 527 | $this->cart = CartFactory::getCart(); |
| 528 | 528 | } |
| 529 | 529 | do_action( |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | ) |
| 546 | 546 | ); |
| 547 | 547 | } |
| 548 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 548 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 549 | 549 | // nothing added to cart |
| 550 | 550 | EE_Error::add_attention( |
| 551 | 551 | esc_html__('No tickets were added for the event', 'event_espresso'), |