@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | default : |
| 99 | 99 | $to = get_option('admin_email'); |
| 100 | 100 | } |
| 101 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 101 | + $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url(); |
|
| 102 | 102 | $msg = EE_Error::_format_error($type, $message, $file, $line); |
| 103 | 103 | if (function_exists('wp_mail')) { |
| 104 | 104 | add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
| 105 | 105 | wp_mail($to, $subject, $msg); |
| 106 | 106 | } |
| 107 | 107 | echo '<div id="message" class="espresso-notices error"><p>'; |
| 108 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 108 | + echo $type.': '.$message.'<br />'.$file.' line '.$line; |
|
| 109 | 109 | echo '<br /></p></div>'; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | ? true |
| 255 | 255 | : false; |
| 256 | 256 | if ($check_stored && ! $has_error) { |
| 257 | - $notices = (array)get_option('ee_notices', array()); |
|
| 257 | + $notices = (array) get_option('ee_notices', array()); |
|
| 258 | 258 | foreach ($notices as $type => $notice) { |
| 259 | 259 | if ($type === $type_to_check && $notice) { |
| 260 | 260 | return true; |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | } |
| 332 | 332 | </style> |
| 333 | 333 | <div id="ee-error-message" class="error">'; |
| 334 | - if (! WP_DEBUG) { |
|
| 334 | + if ( ! WP_DEBUG) { |
|
| 335 | 335 | $output .= ' |
| 336 | 336 | <p>'; |
| 337 | 337 | } |
@@ -383,14 +383,14 @@ discard block |
||
| 383 | 383 | $class_dsply = ! empty($class) ? $class : ' '; |
| 384 | 384 | $type_dsply = ! empty($type) ? $type : ' '; |
| 385 | 385 | $function_dsply = ! empty($function) ? $function : ' '; |
| 386 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 386 | + $args_dsply = ! empty($args) ? '( '.$args.' )' : ''; |
|
| 387 | 387 | $trace_details .= ' |
| 388 | 388 | <tr> |
| 389 | - <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
|
| 390 | - <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
|
| 391 | - <td align="left" class="' . $zebra . '">' . $file_dsply . '</td> |
|
| 392 | - <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
|
| 393 | - <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
|
| 389 | + <td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td> |
|
| 390 | + <td align="right" class="' . $zebra.'">'.$line_dsply.'</td> |
|
| 391 | + <td align="left" class="' . $zebra.'">'.$file_dsply.'</td> |
|
| 392 | + <td align="left" class="' . $zebra.'">'.$class_dsply.'</td> |
|
| 393 | + <td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td> |
|
| 394 | 394 | </tr>'; |
| 395 | 395 | } |
| 396 | 396 | $trace_details .= ' |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | } |
| 400 | 400 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
| 401 | 401 | // add generic non-identifying messages for non-privileged users |
| 402 | - if (! WP_DEBUG) { |
|
| 402 | + if ( ! WP_DEBUG) { |
|
| 403 | 403 | $output .= '<span class="ee-error-user-msg-spn">' |
| 404 | 404 | . trim($ex['msg']) |
| 405 | 405 | . '</span> <sup>' |
@@ -441,14 +441,14 @@ discard block |
||
| 441 | 441 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
| 442 | 442 | ' |
| 443 | 443 | . $trace_details; |
| 444 | - if (! empty($class)) { |
|
| 444 | + if ( ! empty($class)) { |
|
| 445 | 445 | $output .= ' |
| 446 | 446 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
| 447 | 447 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
| 448 | 448 | <h3>Class Details</h3>'; |
| 449 | 449 | $a = new ReflectionClass($class); |
| 450 | 450 | $output .= ' |
| 451 | - <pre>' . $a . '</pre> |
|
| 451 | + <pre>' . $a.'</pre> |
|
| 452 | 452 | </div> |
| 453 | 453 | </div>'; |
| 454 | 454 | } |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | } |
| 462 | 462 | // remove last linebreak |
| 463 | 463 | $output = substr($output, 0, -6); |
| 464 | - if (! WP_DEBUG) { |
|
| 464 | + if ( ! WP_DEBUG) { |
|
| 465 | 465 | $output .= ' |
| 466 | 466 | </p>'; |
| 467 | 467 | } |
@@ -488,20 +488,20 @@ discard block |
||
| 488 | 488 | private function _convert_args_to_string($arguments = array(), $array = false) |
| 489 | 489 | { |
| 490 | 490 | $arg_string = ''; |
| 491 | - if (! empty($arguments)) { |
|
| 491 | + if ( ! empty($arguments)) { |
|
| 492 | 492 | $args = array(); |
| 493 | 493 | foreach ($arguments as $arg) { |
| 494 | - if (! empty($arg)) { |
|
| 494 | + if ( ! empty($arg)) { |
|
| 495 | 495 | if (is_string($arg)) { |
| 496 | - $args[] = " '" . $arg . "'"; |
|
| 496 | + $args[] = " '".$arg."'"; |
|
| 497 | 497 | } elseif (is_array($arg)) { |
| 498 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 498 | + $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true); |
|
| 499 | 499 | } elseif ($arg === null) { |
| 500 | 500 | $args[] = ' NULL'; |
| 501 | 501 | } elseif (is_bool($arg)) { |
| 502 | 502 | $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
| 503 | 503 | } elseif (is_object($arg)) { |
| 504 | - $args[] = ' OBJECT ' . get_class($arg); |
|
| 504 | + $args[] = ' OBJECT '.get_class($arg); |
|
| 505 | 505 | } elseif (is_resource($arg)) { |
| 506 | 506 | $args[] = get_resource_type($arg); |
| 507 | 507 | } else { |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | { |
| 607 | 607 | if (empty($msg)) { |
| 608 | 608 | EE_Error::doing_it_wrong( |
| 609 | - 'EE_Error::add_' . $type . '()', |
|
| 609 | + 'EE_Error::add_'.$type.'()', |
|
| 610 | 610 | sprintf( |
| 611 | 611 | __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
| 612 | 612 | 'event_espresso'), |
@@ -642,11 +642,11 @@ discard block |
||
| 642 | 642 | do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
| 643 | 643 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
| 644 | 644 | // add notice if message exists |
| 645 | - if (! empty($msg)) { |
|
| 645 | + if ( ! empty($msg)) { |
|
| 646 | 646 | // get error code |
| 647 | 647 | $notice_code = EE_Error::generate_error_code($file, $func, $line); |
| 648 | 648 | if (WP_DEBUG && $type === 'errors') { |
| 649 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 649 | + $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>'; |
|
| 650 | 650 | } |
| 651 | 651 | // add notice. Index by code if it's not blank |
| 652 | 652 | if ($notice_code) { |
@@ -890,14 +890,14 @@ discard block |
||
| 890 | 890 | */ |
| 891 | 891 | public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
| 892 | 892 | { |
| 893 | - if (! empty($pan_name) && ! empty($pan_message)) { |
|
| 893 | + if ( ! empty($pan_name) && ! empty($pan_message)) { |
|
| 894 | 894 | $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
| 895 | 895 | //maybe initialize persistent_admin_notices |
| 896 | 896 | if (empty($persistent_admin_notices)) { |
| 897 | 897 | add_option('ee_pers_admin_notices', array(), '', 'no'); |
| 898 | 898 | } |
| 899 | 899 | $pan_name = sanitize_key($pan_name); |
| 900 | - if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) { |
|
| 900 | + if ( ! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) { |
|
| 901 | 901 | $persistent_admin_notices[$pan_name] = $pan_message; |
| 902 | 902 | update_option('ee_pers_admin_notices', $persistent_admin_notices); |
| 903 | 903 | } |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | { |
| 919 | 919 | $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice') |
| 920 | 920 | ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name; |
| 921 | - if (! empty($pan_name)) { |
|
| 921 | + if ( ! empty($pan_name)) { |
|
| 922 | 922 | $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
| 923 | 923 | // check if notice we wish to dismiss is actually in the $persistent_admin_notices array |
| 924 | 924 | if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) { |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | */ |
| 962 | 962 | public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
| 963 | 963 | { |
| 964 | - if (! empty($pan_name) && ! empty($pan_message)) { |
|
| 964 | + if ( ! empty($pan_name) && ! empty($pan_message)) { |
|
| 965 | 965 | $args = array( |
| 966 | 966 | 'nag_notice' => $pan_name, |
| 967 | 967 | 'return_url' => urlencode($return_url), |
@@ -1013,14 +1013,14 @@ discard block |
||
| 1013 | 1013 | // load scripts |
| 1014 | 1014 | wp_register_script( |
| 1015 | 1015 | 'espresso_core', |
| 1016 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1016 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 1017 | 1017 | array('jquery'), |
| 1018 | 1018 | EVENT_ESPRESSO_VERSION, |
| 1019 | 1019 | true |
| 1020 | 1020 | ); |
| 1021 | 1021 | wp_register_script( |
| 1022 | 1022 | 'ee_error_js', |
| 1023 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1023 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
| 1024 | 1024 | array('espresso_core'), |
| 1025 | 1025 | EVENT_ESPRESSO_VERSION, |
| 1026 | 1026 | true |
@@ -1044,7 +1044,7 @@ discard block |
||
| 1044 | 1044 | */ |
| 1045 | 1045 | private static function _print_scripts($force_print = false) |
| 1046 | 1046 | { |
| 1047 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1047 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1048 | 1048 | if (wp_script_is('ee_error_js', 'enqueued')) { |
| 1049 | 1049 | return ''; |
| 1050 | 1050 | } |
@@ -1058,12 +1058,12 @@ discard block |
||
| 1058 | 1058 | return ' |
| 1059 | 1059 | <script> |
| 1060 | 1060 | /* <![CDATA[ */ |
| 1061 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
| 1061 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
| 1062 | 1062 | /* ]]> */ |
| 1063 | 1063 | </script> |
| 1064 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
| 1065 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
| 1066 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
| 1064 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
| 1065 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
| 1066 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
| 1067 | 1067 | '; |
| 1068 | 1068 | } |
| 1069 | 1069 | return ''; |
@@ -1096,8 +1096,8 @@ discard block |
||
| 1096 | 1096 | { |
| 1097 | 1097 | $file = explode('.', basename($file)); |
| 1098 | 1098 | $error_code = ! empty($file[0]) ? $file[0] : ''; |
| 1099 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1100 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1099 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
| 1100 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
| 1101 | 1101 | return $error_code; |
| 1102 | 1102 | } |
| 1103 | 1103 | |
@@ -1116,33 +1116,33 @@ discard block |
||
| 1116 | 1116 | if (empty($ex)) { |
| 1117 | 1117 | return; |
| 1118 | 1118 | } |
| 1119 | - if (! $time) { |
|
| 1119 | + if ( ! $time) { |
|
| 1120 | 1120 | $time = time(); |
| 1121 | 1121 | } |
| 1122 | 1122 | $exception_log = '----------------------------------------------------------------------------------------' |
| 1123 | 1123 | . PHP_EOL; |
| 1124 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1125 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1126 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1127 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1128 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1129 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1130 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1124 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
| 1125 | + $exception_log .= 'Message: '.$ex['msg'].PHP_EOL; |
|
| 1126 | + $exception_log .= 'Code: '.$ex['code'].PHP_EOL; |
|
| 1127 | + $exception_log .= 'File: '.$ex['file'].PHP_EOL; |
|
| 1128 | + $exception_log .= 'Line No: '.$ex['line'].PHP_EOL; |
|
| 1129 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
| 1130 | + $exception_log .= $ex['string'].PHP_EOL; |
|
| 1131 | 1131 | $exception_log .= '----------------------------------------------------------------------------------------' |
| 1132 | 1132 | . PHP_EOL; |
| 1133 | 1133 | try { |
| 1134 | 1134 | EEH_File::ensure_file_exists_and_is_writable( |
| 1135 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file |
|
| 1135 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file |
|
| 1136 | 1136 | ); |
| 1137 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs'); |
|
| 1138 | - if (! $clear) { |
|
| 1137 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs'); |
|
| 1138 | + if ( ! $clear) { |
|
| 1139 | 1139 | //get existing log file and append new log info |
| 1140 | 1140 | $exception_log = EEH_File::get_file_contents( |
| 1141 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file |
|
| 1142 | - ) . $exception_log; |
|
| 1141 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file |
|
| 1142 | + ).$exception_log; |
|
| 1143 | 1143 | } |
| 1144 | 1144 | EEH_File::write_to_file( |
| 1145 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, |
|
| 1145 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file, |
|
| 1146 | 1146 | $exception_log |
| 1147 | 1147 | ); |
| 1148 | 1148 | } catch (EE_Error $e) { |
@@ -1220,14 +1220,14 @@ discard block |
||
| 1220 | 1220 | // js for error handling |
| 1221 | 1221 | wp_register_script( |
| 1222 | 1222 | 'espresso_core', |
| 1223 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1223 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 1224 | 1224 | array('jquery'), |
| 1225 | 1225 | EVENT_ESPRESSO_VERSION, |
| 1226 | 1226 | false |
| 1227 | 1227 | ); |
| 1228 | 1228 | wp_register_script( |
| 1229 | 1229 | 'ee_error_js', |
| 1230 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1230 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
| 1231 | 1231 | array('espresso_core'), |
| 1232 | 1232 | EVENT_ESPRESSO_VERSION, |
| 1233 | 1233 | false |
@@ -5,8 +5,8 @@ discard block |
||
| 5 | 5 | // if you're a dev and want to receive all errors via email |
| 6 | 6 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
| 7 | 7 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
| 8 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
| 9 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
| 8 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
| 9 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | |
@@ -23,259 +23,259 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * name of the file to log exceptions to |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * stores details for all exception |
|
| 35 | - * |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - private static $_all_exceptions = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * tracks number of errors |
|
| 42 | - * |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - private static $_error_count = 0; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * has shutdown action been added ? |
|
| 49 | - * |
|
| 50 | - * @var array $_espresso_notices |
|
| 51 | - */ |
|
| 52 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @override default exception handling |
|
| 58 | - * @param string $message |
|
| 59 | - * @param int $code |
|
| 60 | - * @param Exception|null $previous |
|
| 61 | - */ |
|
| 62 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
| 63 | - { |
|
| 64 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
| 65 | - parent::__construct($message, $code); |
|
| 66 | - } else { |
|
| 67 | - parent::__construct($message, $code, $previous); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * error_handler |
|
| 75 | - * |
|
| 76 | - * @param $code |
|
| 77 | - * @param $message |
|
| 78 | - * @param $file |
|
| 79 | - * @param $line |
|
| 80 | - * @return void |
|
| 81 | - */ |
|
| 82 | - public static function error_handler($code, $message, $file, $line) |
|
| 83 | - { |
|
| 84 | - $type = EE_Error::error_type($code); |
|
| 85 | - $site = site_url(); |
|
| 86 | - switch ($site) { |
|
| 87 | - case 'http://ee4.eventespresso.com/' : |
|
| 88 | - case 'http://ee4decaf.eventespresso.com/' : |
|
| 89 | - case 'http://ee4hf.eventespresso.com/' : |
|
| 90 | - case 'http://ee4a.eventespresso.com/' : |
|
| 91 | - case 'http://ee4ad.eventespresso.com/' : |
|
| 92 | - case 'http://ee4b.eventespresso.com/' : |
|
| 93 | - case 'http://ee4bd.eventespresso.com/' : |
|
| 94 | - case 'http://ee4d.eventespresso.com/' : |
|
| 95 | - case 'http://ee4dd.eventespresso.com/' : |
|
| 96 | - $to = '[email protected]'; |
|
| 97 | - break; |
|
| 98 | - default : |
|
| 99 | - $to = get_option('admin_email'); |
|
| 100 | - } |
|
| 101 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 102 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
| 103 | - if (function_exists('wp_mail')) { |
|
| 104 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 105 | - wp_mail($to, $subject, $msg); |
|
| 106 | - } |
|
| 107 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
| 108 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 109 | - echo '<br /></p></div>'; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * error_type |
|
| 116 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
| 117 | - * |
|
| 118 | - * @param $code |
|
| 119 | - * @return string |
|
| 120 | - */ |
|
| 121 | - public static function error_type($code) |
|
| 122 | - { |
|
| 123 | - switch ($code) { |
|
| 124 | - case E_ERROR: // 1 // |
|
| 125 | - return 'E_ERROR'; |
|
| 126 | - case E_WARNING: // 2 // |
|
| 127 | - return 'E_WARNING'; |
|
| 128 | - case E_PARSE: // 4 // |
|
| 129 | - return 'E_PARSE'; |
|
| 130 | - case E_NOTICE: // 8 // |
|
| 131 | - return 'E_NOTICE'; |
|
| 132 | - case E_CORE_ERROR: // 16 // |
|
| 133 | - return 'E_CORE_ERROR'; |
|
| 134 | - case E_CORE_WARNING: // 32 // |
|
| 135 | - return 'E_CORE_WARNING'; |
|
| 136 | - case E_COMPILE_ERROR: // 64 // |
|
| 137 | - return 'E_COMPILE_ERROR'; |
|
| 138 | - case E_COMPILE_WARNING: // 128 // |
|
| 139 | - return 'E_COMPILE_WARNING'; |
|
| 140 | - case E_USER_ERROR: // 256 // |
|
| 141 | - return 'E_USER_ERROR'; |
|
| 142 | - case E_USER_WARNING: // 512 // |
|
| 143 | - return 'E_USER_WARNING'; |
|
| 144 | - case E_USER_NOTICE: // 1024 // |
|
| 145 | - return 'E_USER_NOTICE'; |
|
| 146 | - case E_STRICT: // 2048 // |
|
| 147 | - return 'E_STRICT'; |
|
| 148 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
| 149 | - return 'E_RECOVERABLE_ERROR'; |
|
| 150 | - case E_DEPRECATED: // 8192 // |
|
| 151 | - return 'E_DEPRECATED'; |
|
| 152 | - case E_USER_DEPRECATED: // 16384 // |
|
| 153 | - return 'E_USER_DEPRECATED'; |
|
| 154 | - case E_ALL: // 16384 // |
|
| 155 | - return 'E_ALL'; |
|
| 156 | - } |
|
| 157 | - return ''; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * fatal_error_handler |
|
| 164 | - * |
|
| 165 | - * @return void |
|
| 166 | - */ |
|
| 167 | - public static function fatal_error_handler() |
|
| 168 | - { |
|
| 169 | - $last_error = error_get_last(); |
|
| 170 | - if ($last_error['type'] === E_ERROR) { |
|
| 171 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * _format_error |
|
| 179 | - * |
|
| 180 | - * @param $code |
|
| 181 | - * @param $message |
|
| 182 | - * @param $file |
|
| 183 | - * @param $line |
|
| 184 | - * @return string |
|
| 185 | - */ |
|
| 186 | - private static function _format_error($code, $message, $file, $line) |
|
| 187 | - { |
|
| 188 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
| 189 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
| 190 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
| 191 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
| 192 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
| 193 | - $html .= '</tbody></table>'; |
|
| 194 | - return $html; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * set_content_type |
|
| 201 | - * |
|
| 202 | - * @param $content_type |
|
| 203 | - * @return string |
|
| 204 | - */ |
|
| 205 | - public static function set_content_type($content_type) |
|
| 206 | - { |
|
| 207 | - return 'text/html'; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @return void |
|
| 214 | - * @throws EE_Error |
|
| 215 | - * @throws ReflectionException |
|
| 216 | - */ |
|
| 217 | - public function get_error() |
|
| 218 | - { |
|
| 219 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
| 220 | - throw $this; |
|
| 221 | - } |
|
| 222 | - // get separate user and developer messages if they exist |
|
| 223 | - $msg = explode('||', $this->getMessage()); |
|
| 224 | - $user_msg = $msg[0]; |
|
| 225 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 226 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 227 | - // add details to _all_exceptions array |
|
| 228 | - $x_time = time(); |
|
| 229 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
| 230 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
| 231 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
| 232 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
| 233 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
| 234 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
| 235 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
| 236 | - self::$_error_count++; |
|
| 237 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
| 238 | - $this->display_errors(); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * has_error |
|
| 245 | - * |
|
| 246 | - * @param bool $check_stored |
|
| 247 | - * @param string $type_to_check |
|
| 248 | - * @return bool |
|
| 249 | - */ |
|
| 250 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
| 251 | - { |
|
| 252 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
| 253 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
| 254 | - ? true |
|
| 255 | - : false; |
|
| 256 | - if ($check_stored && ! $has_error) { |
|
| 257 | - $notices = (array)get_option('ee_notices', array()); |
|
| 258 | - foreach ($notices as $type => $notice) { |
|
| 259 | - if ($type === $type_to_check && $notice) { |
|
| 260 | - return true; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - return $has_error; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * display_errors |
|
| 271 | - * |
|
| 272 | - * @echo string |
|
| 273 | - * @throws \ReflectionException |
|
| 274 | - */ |
|
| 275 | - public function display_errors() |
|
| 276 | - { |
|
| 277 | - $trace_details = ''; |
|
| 278 | - $output = ' |
|
| 26 | + /** |
|
| 27 | + * name of the file to log exceptions to |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * stores details for all exception |
|
| 35 | + * |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + private static $_all_exceptions = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * tracks number of errors |
|
| 42 | + * |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + private static $_error_count = 0; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * has shutdown action been added ? |
|
| 49 | + * |
|
| 50 | + * @var array $_espresso_notices |
|
| 51 | + */ |
|
| 52 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @override default exception handling |
|
| 58 | + * @param string $message |
|
| 59 | + * @param int $code |
|
| 60 | + * @param Exception|null $previous |
|
| 61 | + */ |
|
| 62 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
| 63 | + { |
|
| 64 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
| 65 | + parent::__construct($message, $code); |
|
| 66 | + } else { |
|
| 67 | + parent::__construct($message, $code, $previous); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * error_handler |
|
| 75 | + * |
|
| 76 | + * @param $code |
|
| 77 | + * @param $message |
|
| 78 | + * @param $file |
|
| 79 | + * @param $line |
|
| 80 | + * @return void |
|
| 81 | + */ |
|
| 82 | + public static function error_handler($code, $message, $file, $line) |
|
| 83 | + { |
|
| 84 | + $type = EE_Error::error_type($code); |
|
| 85 | + $site = site_url(); |
|
| 86 | + switch ($site) { |
|
| 87 | + case 'http://ee4.eventespresso.com/' : |
|
| 88 | + case 'http://ee4decaf.eventespresso.com/' : |
|
| 89 | + case 'http://ee4hf.eventespresso.com/' : |
|
| 90 | + case 'http://ee4a.eventespresso.com/' : |
|
| 91 | + case 'http://ee4ad.eventespresso.com/' : |
|
| 92 | + case 'http://ee4b.eventespresso.com/' : |
|
| 93 | + case 'http://ee4bd.eventespresso.com/' : |
|
| 94 | + case 'http://ee4d.eventespresso.com/' : |
|
| 95 | + case 'http://ee4dd.eventespresso.com/' : |
|
| 96 | + $to = '[email protected]'; |
|
| 97 | + break; |
|
| 98 | + default : |
|
| 99 | + $to = get_option('admin_email'); |
|
| 100 | + } |
|
| 101 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 102 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
| 103 | + if (function_exists('wp_mail')) { |
|
| 104 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 105 | + wp_mail($to, $subject, $msg); |
|
| 106 | + } |
|
| 107 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
| 108 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 109 | + echo '<br /></p></div>'; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * error_type |
|
| 116 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
| 117 | + * |
|
| 118 | + * @param $code |
|
| 119 | + * @return string |
|
| 120 | + */ |
|
| 121 | + public static function error_type($code) |
|
| 122 | + { |
|
| 123 | + switch ($code) { |
|
| 124 | + case E_ERROR: // 1 // |
|
| 125 | + return 'E_ERROR'; |
|
| 126 | + case E_WARNING: // 2 // |
|
| 127 | + return 'E_WARNING'; |
|
| 128 | + case E_PARSE: // 4 // |
|
| 129 | + return 'E_PARSE'; |
|
| 130 | + case E_NOTICE: // 8 // |
|
| 131 | + return 'E_NOTICE'; |
|
| 132 | + case E_CORE_ERROR: // 16 // |
|
| 133 | + return 'E_CORE_ERROR'; |
|
| 134 | + case E_CORE_WARNING: // 32 // |
|
| 135 | + return 'E_CORE_WARNING'; |
|
| 136 | + case E_COMPILE_ERROR: // 64 // |
|
| 137 | + return 'E_COMPILE_ERROR'; |
|
| 138 | + case E_COMPILE_WARNING: // 128 // |
|
| 139 | + return 'E_COMPILE_WARNING'; |
|
| 140 | + case E_USER_ERROR: // 256 // |
|
| 141 | + return 'E_USER_ERROR'; |
|
| 142 | + case E_USER_WARNING: // 512 // |
|
| 143 | + return 'E_USER_WARNING'; |
|
| 144 | + case E_USER_NOTICE: // 1024 // |
|
| 145 | + return 'E_USER_NOTICE'; |
|
| 146 | + case E_STRICT: // 2048 // |
|
| 147 | + return 'E_STRICT'; |
|
| 148 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
| 149 | + return 'E_RECOVERABLE_ERROR'; |
|
| 150 | + case E_DEPRECATED: // 8192 // |
|
| 151 | + return 'E_DEPRECATED'; |
|
| 152 | + case E_USER_DEPRECATED: // 16384 // |
|
| 153 | + return 'E_USER_DEPRECATED'; |
|
| 154 | + case E_ALL: // 16384 // |
|
| 155 | + return 'E_ALL'; |
|
| 156 | + } |
|
| 157 | + return ''; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * fatal_error_handler |
|
| 164 | + * |
|
| 165 | + * @return void |
|
| 166 | + */ |
|
| 167 | + public static function fatal_error_handler() |
|
| 168 | + { |
|
| 169 | + $last_error = error_get_last(); |
|
| 170 | + if ($last_error['type'] === E_ERROR) { |
|
| 171 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * _format_error |
|
| 179 | + * |
|
| 180 | + * @param $code |
|
| 181 | + * @param $message |
|
| 182 | + * @param $file |
|
| 183 | + * @param $line |
|
| 184 | + * @return string |
|
| 185 | + */ |
|
| 186 | + private static function _format_error($code, $message, $file, $line) |
|
| 187 | + { |
|
| 188 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
| 189 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
| 190 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
| 191 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
| 192 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
| 193 | + $html .= '</tbody></table>'; |
|
| 194 | + return $html; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * set_content_type |
|
| 201 | + * |
|
| 202 | + * @param $content_type |
|
| 203 | + * @return string |
|
| 204 | + */ |
|
| 205 | + public static function set_content_type($content_type) |
|
| 206 | + { |
|
| 207 | + return 'text/html'; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @return void |
|
| 214 | + * @throws EE_Error |
|
| 215 | + * @throws ReflectionException |
|
| 216 | + */ |
|
| 217 | + public function get_error() |
|
| 218 | + { |
|
| 219 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
| 220 | + throw $this; |
|
| 221 | + } |
|
| 222 | + // get separate user and developer messages if they exist |
|
| 223 | + $msg = explode('||', $this->getMessage()); |
|
| 224 | + $user_msg = $msg[0]; |
|
| 225 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 226 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 227 | + // add details to _all_exceptions array |
|
| 228 | + $x_time = time(); |
|
| 229 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
| 230 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
| 231 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
| 232 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
| 233 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
| 234 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
| 235 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
| 236 | + self::$_error_count++; |
|
| 237 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
| 238 | + $this->display_errors(); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * has_error |
|
| 245 | + * |
|
| 246 | + * @param bool $check_stored |
|
| 247 | + * @param string $type_to_check |
|
| 248 | + * @return bool |
|
| 249 | + */ |
|
| 250 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
| 251 | + { |
|
| 252 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
| 253 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
| 254 | + ? true |
|
| 255 | + : false; |
|
| 256 | + if ($check_stored && ! $has_error) { |
|
| 257 | + $notices = (array)get_option('ee_notices', array()); |
|
| 258 | + foreach ($notices as $type => $notice) { |
|
| 259 | + if ($type === $type_to_check && $notice) { |
|
| 260 | + return true; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + return $has_error; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * display_errors |
|
| 271 | + * |
|
| 272 | + * @echo string |
|
| 273 | + * @throws \ReflectionException |
|
| 274 | + */ |
|
| 275 | + public function display_errors() |
|
| 276 | + { |
|
| 277 | + $trace_details = ''; |
|
| 278 | + $output = ' |
|
| 279 | 279 | <style type="text/css"> |
| 280 | 280 | #ee-error-message { |
| 281 | 281 | max-width:90% !important; |
@@ -331,19 +331,19 @@ discard block |
||
| 331 | 331 | } |
| 332 | 332 | </style> |
| 333 | 333 | <div id="ee-error-message" class="error">'; |
| 334 | - if (! WP_DEBUG) { |
|
| 335 | - $output .= ' |
|
| 334 | + if (! WP_DEBUG) { |
|
| 335 | + $output .= ' |
|
| 336 | 336 | <p>'; |
| 337 | - } |
|
| 338 | - // cycle thru errors |
|
| 339 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
| 340 | - $error_code = ''; |
|
| 341 | - // process trace info |
|
| 342 | - if (empty($ex['trace'])) { |
|
| 343 | - $trace_details .= __('Sorry, but no trace information was available for this exception.', |
|
| 344 | - 'event_espresso'); |
|
| 345 | - } else { |
|
| 346 | - $trace_details .= ' |
|
| 337 | + } |
|
| 338 | + // cycle thru errors |
|
| 339 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
| 340 | + $error_code = ''; |
|
| 341 | + // process trace info |
|
| 342 | + if (empty($ex['trace'])) { |
|
| 343 | + $trace_details .= __('Sorry, but no trace information was available for this exception.', |
|
| 344 | + 'event_espresso'); |
|
| 345 | + } else { |
|
| 346 | + $trace_details .= ' |
|
| 347 | 347 | <div id="ee-trace-details"> |
| 348 | 348 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
| 349 | 349 | <tr> |
@@ -353,43 +353,43 @@ discard block |
||
| 353 | 353 | <th scope="col" align="left">Class</th> |
| 354 | 354 | <th scope="col" align="left">Method( arguments )</th> |
| 355 | 355 | </tr>'; |
| 356 | - $last_on_stack = count($ex['trace']) - 1; |
|
| 357 | - // reverse array so that stack is in proper chronological order |
|
| 358 | - $sorted_trace = array_reverse($ex['trace']); |
|
| 359 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
| 360 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
| 361 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
| 362 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
| 363 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
| 364 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
| 365 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
| 366 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
| 367 | - if (empty($file) && ! empty($class)) { |
|
| 368 | - $a = new ReflectionClass($class); |
|
| 369 | - $file = $a->getFileName(); |
|
| 370 | - if (empty($line) && ! empty($function)) { |
|
| 371 | - try { |
|
| 372 | - //if $function is a closure, this throws an exception |
|
| 373 | - $b = new ReflectionMethod($class, $function); |
|
| 374 | - $line = $b->getStartLine(); |
|
| 375 | - } catch (Exception $closure_exception) { |
|
| 376 | - $line = 'unknown'; |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - if ($nmbr === $last_on_stack) { |
|
| 381 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
| 382 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
| 383 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
| 384 | - } |
|
| 385 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
| 386 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
| 387 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
| 388 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
| 389 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
| 390 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
| 391 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 392 | - $trace_details .= ' |
|
| 356 | + $last_on_stack = count($ex['trace']) - 1; |
|
| 357 | + // reverse array so that stack is in proper chronological order |
|
| 358 | + $sorted_trace = array_reverse($ex['trace']); |
|
| 359 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
| 360 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
| 361 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
| 362 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
| 363 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
| 364 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
| 365 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
| 366 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
| 367 | + if (empty($file) && ! empty($class)) { |
|
| 368 | + $a = new ReflectionClass($class); |
|
| 369 | + $file = $a->getFileName(); |
|
| 370 | + if (empty($line) && ! empty($function)) { |
|
| 371 | + try { |
|
| 372 | + //if $function is a closure, this throws an exception |
|
| 373 | + $b = new ReflectionMethod($class, $function); |
|
| 374 | + $line = $b->getStartLine(); |
|
| 375 | + } catch (Exception $closure_exception) { |
|
| 376 | + $line = 'unknown'; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + if ($nmbr === $last_on_stack) { |
|
| 381 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
| 382 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
| 383 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
| 384 | + } |
|
| 385 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
| 386 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
| 387 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
| 388 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
| 389 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
| 390 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
| 391 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 392 | + $trace_details .= ' |
|
| 393 | 393 | <tr> |
| 394 | 394 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
| 395 | 395 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -397,674 +397,674 @@ discard block |
||
| 397 | 397 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
| 398 | 398 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
| 399 | 399 | </tr>'; |
| 400 | - } |
|
| 401 | - $trace_details .= ' |
|
| 400 | + } |
|
| 401 | + $trace_details .= ' |
|
| 402 | 402 | </table> |
| 403 | 403 | </div>'; |
| 404 | - } |
|
| 405 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
| 406 | - // add generic non-identifying messages for non-privileged users |
|
| 407 | - if (! WP_DEBUG) { |
|
| 408 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
| 409 | - . trim($ex['msg']) |
|
| 410 | - . '</span> <sup>' |
|
| 411 | - . $ex['code'] |
|
| 412 | - . '</sup><br />'; |
|
| 413 | - } else { |
|
| 414 | - // or helpful developer messages if debugging is on |
|
| 415 | - $output .= ' |
|
| 404 | + } |
|
| 405 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
| 406 | + // add generic non-identifying messages for non-privileged users |
|
| 407 | + if (! WP_DEBUG) { |
|
| 408 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
| 409 | + . trim($ex['msg']) |
|
| 410 | + . '</span> <sup>' |
|
| 411 | + . $ex['code'] |
|
| 412 | + . '</sup><br />'; |
|
| 413 | + } else { |
|
| 414 | + // or helpful developer messages if debugging is on |
|
| 415 | + $output .= ' |
|
| 416 | 416 | <div class="ee-error-dev-msg-dv"> |
| 417 | 417 | <p class="ee-error-dev-msg-pg"> |
| 418 | 418 | <strong class="ee-error-dev-msg-str">An ' |
| 419 | - . $ex['name'] |
|
| 420 | - . ' exception was thrown!</strong> <span>code: ' |
|
| 421 | - . $ex['code'] |
|
| 422 | - . '</span><br /> |
|
| 419 | + . $ex['name'] |
|
| 420 | + . ' exception was thrown!</strong> <span>code: ' |
|
| 421 | + . $ex['code'] |
|
| 422 | + . '</span><br /> |
|
| 423 | 423 | <span class="big-text">"' |
| 424 | - . trim($ex['msg']) |
|
| 425 | - . '"</span><br/> |
|
| 424 | + . trim($ex['msg']) |
|
| 425 | + . '"</span><br/> |
|
| 426 | 426 | <a id="display-ee-error-trace-' |
| 427 | - . self::$_error_count |
|
| 428 | - . $time |
|
| 429 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
| 430 | - . self::$_error_count |
|
| 431 | - . $time |
|
| 432 | - . '"> |
|
| 427 | + . self::$_error_count |
|
| 428 | + . $time |
|
| 429 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
| 430 | + . self::$_error_count |
|
| 431 | + . $time |
|
| 432 | + . '"> |
|
| 433 | 433 | ' |
| 434 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
| 435 | - . ' |
|
| 434 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
| 435 | + . ' |
|
| 436 | 436 | </a><br /> |
| 437 | 437 | <span class="small-text lt-grey-text">' |
| 438 | - . $ex['file'] |
|
| 439 | - . ' ( line no: ' |
|
| 440 | - . $ex['line'] |
|
| 441 | - . ' )</span> |
|
| 438 | + . $ex['file'] |
|
| 439 | + . ' ( line no: ' |
|
| 440 | + . $ex['line'] |
|
| 441 | + . ' )</span> |
|
| 442 | 442 | </p> |
| 443 | 443 | <div id="ee-error-trace-' |
| 444 | - . self::$_error_count |
|
| 445 | - . $time |
|
| 446 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
| 444 | + . self::$_error_count |
|
| 445 | + . $time |
|
| 446 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
| 447 | 447 | ' |
| 448 | - . $trace_details; |
|
| 449 | - if (! empty($class)) { |
|
| 450 | - $output .= ' |
|
| 448 | + . $trace_details; |
|
| 449 | + if (! empty($class)) { |
|
| 450 | + $output .= ' |
|
| 451 | 451 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
| 452 | 452 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
| 453 | 453 | <h3>Class Details</h3>'; |
| 454 | - $a = new ReflectionClass($class); |
|
| 455 | - $output .= ' |
|
| 454 | + $a = new ReflectionClass($class); |
|
| 455 | + $output .= ' |
|
| 456 | 456 | <pre>' . $a . '</pre> |
| 457 | 457 | </div> |
| 458 | 458 | </div>'; |
| 459 | - } |
|
| 460 | - $output .= ' |
|
| 459 | + } |
|
| 460 | + $output .= ' |
|
| 461 | 461 | </div> |
| 462 | 462 | </div> |
| 463 | 463 | <br />'; |
| 464 | - } |
|
| 465 | - $this->write_to_error_log($time, $ex); |
|
| 466 | - } |
|
| 467 | - // remove last linebreak |
|
| 468 | - $output = substr($output, 0, -6); |
|
| 469 | - if (! WP_DEBUG) { |
|
| 470 | - $output .= ' |
|
| 464 | + } |
|
| 465 | + $this->write_to_error_log($time, $ex); |
|
| 466 | + } |
|
| 467 | + // remove last linebreak |
|
| 468 | + $output = substr($output, 0, -6); |
|
| 469 | + if (! WP_DEBUG) { |
|
| 470 | + $output .= ' |
|
| 471 | 471 | </p>'; |
| 472 | - } |
|
| 473 | - $output .= ' |
|
| 472 | + } |
|
| 473 | + $output .= ' |
|
| 474 | 474 | </div>'; |
| 475 | - $output .= self::_print_scripts(true); |
|
| 476 | - if (defined('DOING_AJAX')) { |
|
| 477 | - echo wp_json_encode(array('error' => $output)); |
|
| 478 | - exit(); |
|
| 479 | - } |
|
| 480 | - echo $output; |
|
| 481 | - die(); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * generate string from exception trace args |
|
| 488 | - * |
|
| 489 | - * @param array $arguments |
|
| 490 | - * @param bool $array |
|
| 491 | - * @return string |
|
| 492 | - */ |
|
| 493 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
| 494 | - { |
|
| 495 | - $arg_string = ''; |
|
| 496 | - if (! empty($arguments)) { |
|
| 497 | - $args = array(); |
|
| 498 | - foreach ($arguments as $arg) { |
|
| 499 | - if (! empty($arg)) { |
|
| 500 | - if (is_string($arg)) { |
|
| 501 | - $args[] = " '" . $arg . "'"; |
|
| 502 | - } elseif (is_array($arg)) { |
|
| 503 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 504 | - } elseif ($arg === null) { |
|
| 505 | - $args[] = ' NULL'; |
|
| 506 | - } elseif (is_bool($arg)) { |
|
| 507 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
| 508 | - } elseif (is_object($arg)) { |
|
| 509 | - $args[] = ' OBJECT ' . get_class($arg); |
|
| 510 | - } elseif (is_resource($arg)) { |
|
| 511 | - $args[] = get_resource_type($arg); |
|
| 512 | - } else { |
|
| 513 | - $args[] = $arg; |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - } |
|
| 517 | - $arg_string = implode(', ', $args); |
|
| 518 | - } |
|
| 519 | - if ($array) { |
|
| 520 | - $arg_string .= ' )'; |
|
| 521 | - } |
|
| 522 | - return $arg_string; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * add error message |
|
| 529 | - * |
|
| 530 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 531 | - * separate messages for user || dev |
|
| 532 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 533 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 534 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 535 | - * @return void |
|
| 536 | - */ |
|
| 537 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
| 538 | - { |
|
| 539 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
| 540 | - self::$_error_count++; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
| 547 | - * adds an error |
|
| 548 | - * |
|
| 549 | - * @param string $msg |
|
| 550 | - * @param string $file |
|
| 551 | - * @param string $func |
|
| 552 | - * @param string $line |
|
| 553 | - * @throws EE_Error |
|
| 554 | - */ |
|
| 555 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
| 556 | - { |
|
| 557 | - if (WP_DEBUG) { |
|
| 558 | - throw new EE_Error($msg); |
|
| 559 | - } |
|
| 560 | - EE_Error::add_error($msg, $file, $func, $line); |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * add success message |
|
| 567 | - * |
|
| 568 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 569 | - * separate messages for user || dev |
|
| 570 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 571 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 572 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 573 | - * @return void |
|
| 574 | - */ |
|
| 575 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
| 576 | - { |
|
| 577 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * add attention message |
|
| 584 | - * |
|
| 585 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 586 | - * separate messages for user || dev |
|
| 587 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 588 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 589 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 590 | - * @return void |
|
| 591 | - */ |
|
| 592 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
| 593 | - { |
|
| 594 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * add success message |
|
| 601 | - * |
|
| 602 | - * @param string $type whether the message is for a success or error notification |
|
| 603 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 604 | - * separate messages for user || dev |
|
| 605 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 606 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 607 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 608 | - * @return void |
|
| 609 | - */ |
|
| 610 | - private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null) |
|
| 611 | - { |
|
| 612 | - if (empty($msg)) { |
|
| 613 | - EE_Error::doing_it_wrong( |
|
| 614 | - 'EE_Error::add_' . $type . '()', |
|
| 615 | - sprintf( |
|
| 616 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
| 617 | - 'event_espresso'), |
|
| 618 | - $type, |
|
| 619 | - $file, |
|
| 620 | - $line |
|
| 621 | - ), |
|
| 622 | - EVENT_ESPRESSO_VERSION |
|
| 623 | - ); |
|
| 624 | - } |
|
| 625 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
| 626 | - EE_Error::doing_it_wrong( |
|
| 627 | - 'EE_Error::add_error()', |
|
| 628 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
| 629 | - 'event_espresso'), |
|
| 630 | - EVENT_ESPRESSO_VERSION |
|
| 631 | - ); |
|
| 632 | - } |
|
| 633 | - // get separate user and developer messages if they exist |
|
| 634 | - $msg = explode('||', $msg); |
|
| 635 | - $user_msg = $msg[0]; |
|
| 636 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 637 | - /** |
|
| 638 | - * Do an action so other code can be triggered when a notice is created |
|
| 639 | - * |
|
| 640 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
| 641 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
| 642 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
| 643 | - * @param string $file file where error was generated |
|
| 644 | - * @param string $func function where error was generated |
|
| 645 | - * @param string $line line where error was generated |
|
| 646 | - */ |
|
| 647 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
| 648 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 649 | - // add notice if message exists |
|
| 650 | - if (! empty($msg)) { |
|
| 651 | - // get error code |
|
| 652 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
| 653 | - if (WP_DEBUG && $type === 'errors') { |
|
| 654 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 655 | - } |
|
| 656 | - // add notice. Index by code if it's not blank |
|
| 657 | - if ($notice_code) { |
|
| 658 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
| 659 | - } else { |
|
| 660 | - self::$_espresso_notices[$type][] = $msg; |
|
| 661 | - } |
|
| 662 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * in some case it may be necessary to overwrite the existing success messages |
|
| 670 | - * |
|
| 671 | - * @return void |
|
| 672 | - */ |
|
| 673 | - public static function overwrite_success() |
|
| 674 | - { |
|
| 675 | - self::$_espresso_notices['success'] = false; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * in some case it may be necessary to overwrite the existing attention messages |
|
| 682 | - * |
|
| 683 | - * @return void |
|
| 684 | - */ |
|
| 685 | - public static function overwrite_attention() |
|
| 686 | - { |
|
| 687 | - self::$_espresso_notices['attention'] = false; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - /** |
|
| 693 | - * in some case it may be necessary to overwrite the existing error messages |
|
| 694 | - * |
|
| 695 | - * @return void |
|
| 696 | - */ |
|
| 697 | - public static function overwrite_errors() |
|
| 698 | - { |
|
| 699 | - self::$_espresso_notices['errors'] = false; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * reset_notices |
|
| 706 | - * |
|
| 707 | - * @return void |
|
| 708 | - */ |
|
| 709 | - public static function reset_notices() |
|
| 710 | - { |
|
| 711 | - self::$_espresso_notices['success'] = false; |
|
| 712 | - self::$_espresso_notices['attention'] = false; |
|
| 713 | - self::$_espresso_notices['errors'] = false; |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * has_errors |
|
| 720 | - * |
|
| 721 | - * @return int |
|
| 722 | - */ |
|
| 723 | - public static function has_notices() |
|
| 724 | - { |
|
| 725 | - $has_notices = 0; |
|
| 726 | - // check for success messages |
|
| 727 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3 |
|
| 728 | - : $has_notices; |
|
| 729 | - // check for attention messages |
|
| 730 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2 |
|
| 731 | - : $has_notices; |
|
| 732 | - // check for error messages |
|
| 733 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1 |
|
| 734 | - : $has_notices; |
|
| 735 | - return $has_notices; |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
| 742 | - * |
|
| 743 | - * @since 4.9.0 |
|
| 744 | - * @return array |
|
| 745 | - */ |
|
| 746 | - public static function get_vanilla_notices() |
|
| 747 | - { |
|
| 748 | - return array( |
|
| 749 | - 'success' => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(), |
|
| 750 | - 'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention'] |
|
| 751 | - : array(), |
|
| 752 | - 'errors' => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(), |
|
| 753 | - ); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * compile all error or success messages into one string |
|
| 760 | - * |
|
| 761 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
| 762 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
| 763 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
| 764 | - * - ONLY do this just before redirecting |
|
| 765 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
| 766 | - * @return array |
|
| 767 | - */ |
|
| 768 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
| 769 | - { |
|
| 770 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 771 | - $success_messages = ''; |
|
| 772 | - $attention_messages = ''; |
|
| 773 | - $error_messages = ''; |
|
| 774 | - $print_scripts = false; |
|
| 775 | - // either save notices to the db |
|
| 776 | - if ($save_to_transient) { |
|
| 777 | - update_option('ee_notices', self::$_espresso_notices); |
|
| 778 | - return array(); |
|
| 779 | - } |
|
| 780 | - // grab any notices that have been previously saved |
|
| 781 | - if ($notices = get_option('ee_notices', false)) { |
|
| 782 | - foreach ($notices as $type => $notice) { |
|
| 783 | - if (is_array($notice) && ! empty($notice)) { |
|
| 784 | - // make sure that existing notice type is an array |
|
| 785 | - self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
| 786 | - && ! empty(self::$_espresso_notices[$type]) |
|
| 787 | - ? self::$_espresso_notices[$type] : array(); |
|
| 788 | - // merge stored notices with any newly created ones |
|
| 789 | - self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
| 790 | - $print_scripts = true; |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - // now clear any stored notices |
|
| 794 | - update_option('ee_notices', false); |
|
| 795 | - } |
|
| 796 | - // check for success messages |
|
| 797 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
| 798 | - // combine messages |
|
| 799 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />'); |
|
| 800 | - $print_scripts = true; |
|
| 801 | - } |
|
| 802 | - // check for attention messages |
|
| 803 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
| 804 | - // combine messages |
|
| 805 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />'); |
|
| 806 | - $print_scripts = true; |
|
| 807 | - } |
|
| 808 | - // check for error messages |
|
| 809 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
| 810 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
| 811 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
| 812 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
| 813 | - // combine messages |
|
| 814 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />'); |
|
| 815 | - $print_scripts = true; |
|
| 816 | - } |
|
| 817 | - if ($format_output) { |
|
| 818 | - $notices = '<div id="espresso-notices">'; |
|
| 819 | - $close = is_admin() ? '' |
|
| 820 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
| 821 | - if ($success_messages !== '') { |
|
| 822 | - $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
| 823 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
| 824 | - //showMessage( $success_messages ); |
|
| 825 | - $notices .= '<div id="' |
|
| 826 | - . $css_id |
|
| 827 | - . '" class="espresso-notices ' |
|
| 828 | - . $css_class |
|
| 829 | - . '" style="display:none;"><p>' |
|
| 830 | - . $success_messages |
|
| 831 | - . '</p>' |
|
| 832 | - . $close |
|
| 833 | - . '</div>'; |
|
| 834 | - } |
|
| 835 | - if ($attention_messages !== '') { |
|
| 836 | - $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
| 837 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
| 838 | - //showMessage( $error_messages, TRUE ); |
|
| 839 | - $notices .= '<div id="' |
|
| 840 | - . $css_id |
|
| 841 | - . '" class="espresso-notices ' |
|
| 842 | - . $css_class |
|
| 843 | - . '" style="display:none;"><p>' |
|
| 844 | - . $attention_messages |
|
| 845 | - . '</p>' |
|
| 846 | - . $close |
|
| 847 | - . '</div>'; |
|
| 848 | - } |
|
| 849 | - if ($error_messages !== '') { |
|
| 850 | - $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
| 851 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
| 852 | - //showMessage( $error_messages, TRUE ); |
|
| 853 | - $notices .= '<div id="' |
|
| 854 | - . $css_id |
|
| 855 | - . '" class="espresso-notices ' |
|
| 856 | - . $css_class |
|
| 857 | - . '" style="display:none;"><p>' |
|
| 858 | - . $error_messages |
|
| 859 | - . '</p>' |
|
| 860 | - . $close |
|
| 861 | - . '</div>'; |
|
| 862 | - } |
|
| 863 | - $notices .= '</div>'; |
|
| 864 | - } else { |
|
| 865 | - $notices = array( |
|
| 866 | - 'success' => $success_messages, |
|
| 867 | - 'attention' => $attention_messages, |
|
| 868 | - 'errors' => $error_messages, |
|
| 869 | - ); |
|
| 870 | - if ($remove_empty) { |
|
| 871 | - // remove empty notices |
|
| 872 | - foreach ($notices as $type => $notice) { |
|
| 873 | - if (empty($notice)) { |
|
| 874 | - unset($notices[$type]); |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - } |
|
| 879 | - if ($print_scripts) { |
|
| 880 | - self::_print_scripts(); |
|
| 881 | - } |
|
| 882 | - return $notices; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - /** |
|
| 888 | - * add_persistent_admin_notice |
|
| 889 | - * |
|
| 890 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 891 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
| 892 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
| 893 | - * @return void |
|
| 894 | - */ |
|
| 895 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
| 896 | - { |
|
| 897 | - if (! empty($pan_name) && ! empty($pan_message)) { |
|
| 898 | - $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
| 899 | - //maybe initialize persistent_admin_notices |
|
| 900 | - if (empty($persistent_admin_notices)) { |
|
| 901 | - add_option('ee_pers_admin_notices', array(), '', 'no'); |
|
| 902 | - } |
|
| 903 | - $pan_name = sanitize_key($pan_name); |
|
| 904 | - if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) { |
|
| 905 | - $persistent_admin_notices[$pan_name] = $pan_message; |
|
| 906 | - update_option('ee_pers_admin_notices', $persistent_admin_notices); |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * dismiss_persistent_admin_notice |
|
| 915 | - * |
|
| 916 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
| 917 | - * @param bool $purge |
|
| 918 | - * @param bool $return_immediately |
|
| 919 | - * @return void |
|
| 920 | - */ |
|
| 921 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false) |
|
| 922 | - { |
|
| 923 | - $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice') |
|
| 924 | - ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name; |
|
| 925 | - if (! empty($pan_name)) { |
|
| 926 | - $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
| 927 | - // check if notice we wish to dismiss is actually in the $persistent_admin_notices array |
|
| 928 | - if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) { |
|
| 929 | - // completely delete nag notice, or just NULL message so that it can NOT be added again ? |
|
| 930 | - if ($purge) { |
|
| 931 | - unset($persistent_admin_notices[$pan_name]); |
|
| 932 | - } else { |
|
| 933 | - $persistent_admin_notices[$pan_name] = null; |
|
| 934 | - } |
|
| 935 | - if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) { |
|
| 936 | - EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.', |
|
| 937 | - 'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__); |
|
| 938 | - } |
|
| 939 | - } |
|
| 940 | - } |
|
| 941 | - if ($return_immediately) { |
|
| 942 | - return; |
|
| 943 | - } |
|
| 944 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 945 | - // grab any notices and concatenate into string |
|
| 946 | - echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false)))); |
|
| 947 | - exit(); |
|
| 948 | - } |
|
| 949 | - // save errors to a transient to be displayed on next request (after redirect) |
|
| 950 | - EE_Error::get_notices(false, true); |
|
| 951 | - $return_url = EE_Registry::instance()->REQ->is_set('return_url') |
|
| 952 | - ? EE_Registry::instance()->REQ->get('return_url') : ''; |
|
| 953 | - wp_safe_redirect(urldecode($return_url)); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - |
|
| 958 | - /** |
|
| 959 | - * display_persistent_admin_notices |
|
| 960 | - * |
|
| 961 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 962 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
| 963 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
| 964 | - * @return string |
|
| 965 | - */ |
|
| 966 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
| 967 | - { |
|
| 968 | - if (! empty($pan_name) && ! empty($pan_message)) { |
|
| 969 | - $args = array( |
|
| 970 | - 'nag_notice' => $pan_name, |
|
| 971 | - 'return_url' => urlencode($return_url), |
|
| 972 | - 'ajax_url' => WP_AJAX_URL, |
|
| 973 | - 'unknown_error' => esc_html__( |
|
| 974 | - 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
| 975 | - 'event_espresso' |
|
| 976 | - ), |
|
| 977 | - ); |
|
| 978 | - EE_Registry::$i18n_js_strings = array_merge( |
|
| 979 | - EE_Registry::$i18n_js_strings, |
|
| 980 | - array('ee_dismiss' => $args) |
|
| 981 | - ); |
|
| 982 | - return ' |
|
| 475 | + $output .= self::_print_scripts(true); |
|
| 476 | + if (defined('DOING_AJAX')) { |
|
| 477 | + echo wp_json_encode(array('error' => $output)); |
|
| 478 | + exit(); |
|
| 479 | + } |
|
| 480 | + echo $output; |
|
| 481 | + die(); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * generate string from exception trace args |
|
| 488 | + * |
|
| 489 | + * @param array $arguments |
|
| 490 | + * @param bool $array |
|
| 491 | + * @return string |
|
| 492 | + */ |
|
| 493 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
| 494 | + { |
|
| 495 | + $arg_string = ''; |
|
| 496 | + if (! empty($arguments)) { |
|
| 497 | + $args = array(); |
|
| 498 | + foreach ($arguments as $arg) { |
|
| 499 | + if (! empty($arg)) { |
|
| 500 | + if (is_string($arg)) { |
|
| 501 | + $args[] = " '" . $arg . "'"; |
|
| 502 | + } elseif (is_array($arg)) { |
|
| 503 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 504 | + } elseif ($arg === null) { |
|
| 505 | + $args[] = ' NULL'; |
|
| 506 | + } elseif (is_bool($arg)) { |
|
| 507 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
| 508 | + } elseif (is_object($arg)) { |
|
| 509 | + $args[] = ' OBJECT ' . get_class($arg); |
|
| 510 | + } elseif (is_resource($arg)) { |
|
| 511 | + $args[] = get_resource_type($arg); |
|
| 512 | + } else { |
|
| 513 | + $args[] = $arg; |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + } |
|
| 517 | + $arg_string = implode(', ', $args); |
|
| 518 | + } |
|
| 519 | + if ($array) { |
|
| 520 | + $arg_string .= ' )'; |
|
| 521 | + } |
|
| 522 | + return $arg_string; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * add error message |
|
| 529 | + * |
|
| 530 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 531 | + * separate messages for user || dev |
|
| 532 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 533 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 534 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 535 | + * @return void |
|
| 536 | + */ |
|
| 537 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
| 538 | + { |
|
| 539 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
| 540 | + self::$_error_count++; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
| 547 | + * adds an error |
|
| 548 | + * |
|
| 549 | + * @param string $msg |
|
| 550 | + * @param string $file |
|
| 551 | + * @param string $func |
|
| 552 | + * @param string $line |
|
| 553 | + * @throws EE_Error |
|
| 554 | + */ |
|
| 555 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
| 556 | + { |
|
| 557 | + if (WP_DEBUG) { |
|
| 558 | + throw new EE_Error($msg); |
|
| 559 | + } |
|
| 560 | + EE_Error::add_error($msg, $file, $func, $line); |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * add success message |
|
| 567 | + * |
|
| 568 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 569 | + * separate messages for user || dev |
|
| 570 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 571 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 572 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 573 | + * @return void |
|
| 574 | + */ |
|
| 575 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
| 576 | + { |
|
| 577 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * add attention message |
|
| 584 | + * |
|
| 585 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 586 | + * separate messages for user || dev |
|
| 587 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 588 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 589 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 590 | + * @return void |
|
| 591 | + */ |
|
| 592 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
| 593 | + { |
|
| 594 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * add success message |
|
| 601 | + * |
|
| 602 | + * @param string $type whether the message is for a success or error notification |
|
| 603 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 604 | + * separate messages for user || dev |
|
| 605 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 606 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 607 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 608 | + * @return void |
|
| 609 | + */ |
|
| 610 | + private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null) |
|
| 611 | + { |
|
| 612 | + if (empty($msg)) { |
|
| 613 | + EE_Error::doing_it_wrong( |
|
| 614 | + 'EE_Error::add_' . $type . '()', |
|
| 615 | + sprintf( |
|
| 616 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
| 617 | + 'event_espresso'), |
|
| 618 | + $type, |
|
| 619 | + $file, |
|
| 620 | + $line |
|
| 621 | + ), |
|
| 622 | + EVENT_ESPRESSO_VERSION |
|
| 623 | + ); |
|
| 624 | + } |
|
| 625 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
| 626 | + EE_Error::doing_it_wrong( |
|
| 627 | + 'EE_Error::add_error()', |
|
| 628 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
| 629 | + 'event_espresso'), |
|
| 630 | + EVENT_ESPRESSO_VERSION |
|
| 631 | + ); |
|
| 632 | + } |
|
| 633 | + // get separate user and developer messages if they exist |
|
| 634 | + $msg = explode('||', $msg); |
|
| 635 | + $user_msg = $msg[0]; |
|
| 636 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 637 | + /** |
|
| 638 | + * Do an action so other code can be triggered when a notice is created |
|
| 639 | + * |
|
| 640 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
| 641 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
| 642 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
| 643 | + * @param string $file file where error was generated |
|
| 644 | + * @param string $func function where error was generated |
|
| 645 | + * @param string $line line where error was generated |
|
| 646 | + */ |
|
| 647 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
| 648 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 649 | + // add notice if message exists |
|
| 650 | + if (! empty($msg)) { |
|
| 651 | + // get error code |
|
| 652 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
| 653 | + if (WP_DEBUG && $type === 'errors') { |
|
| 654 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 655 | + } |
|
| 656 | + // add notice. Index by code if it's not blank |
|
| 657 | + if ($notice_code) { |
|
| 658 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
| 659 | + } else { |
|
| 660 | + self::$_espresso_notices[$type][] = $msg; |
|
| 661 | + } |
|
| 662 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * in some case it may be necessary to overwrite the existing success messages |
|
| 670 | + * |
|
| 671 | + * @return void |
|
| 672 | + */ |
|
| 673 | + public static function overwrite_success() |
|
| 674 | + { |
|
| 675 | + self::$_espresso_notices['success'] = false; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * in some case it may be necessary to overwrite the existing attention messages |
|
| 682 | + * |
|
| 683 | + * @return void |
|
| 684 | + */ |
|
| 685 | + public static function overwrite_attention() |
|
| 686 | + { |
|
| 687 | + self::$_espresso_notices['attention'] = false; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * in some case it may be necessary to overwrite the existing error messages |
|
| 694 | + * |
|
| 695 | + * @return void |
|
| 696 | + */ |
|
| 697 | + public static function overwrite_errors() |
|
| 698 | + { |
|
| 699 | + self::$_espresso_notices['errors'] = false; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * reset_notices |
|
| 706 | + * |
|
| 707 | + * @return void |
|
| 708 | + */ |
|
| 709 | + public static function reset_notices() |
|
| 710 | + { |
|
| 711 | + self::$_espresso_notices['success'] = false; |
|
| 712 | + self::$_espresso_notices['attention'] = false; |
|
| 713 | + self::$_espresso_notices['errors'] = false; |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * has_errors |
|
| 720 | + * |
|
| 721 | + * @return int |
|
| 722 | + */ |
|
| 723 | + public static function has_notices() |
|
| 724 | + { |
|
| 725 | + $has_notices = 0; |
|
| 726 | + // check for success messages |
|
| 727 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3 |
|
| 728 | + : $has_notices; |
|
| 729 | + // check for attention messages |
|
| 730 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2 |
|
| 731 | + : $has_notices; |
|
| 732 | + // check for error messages |
|
| 733 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1 |
|
| 734 | + : $has_notices; |
|
| 735 | + return $has_notices; |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
| 742 | + * |
|
| 743 | + * @since 4.9.0 |
|
| 744 | + * @return array |
|
| 745 | + */ |
|
| 746 | + public static function get_vanilla_notices() |
|
| 747 | + { |
|
| 748 | + return array( |
|
| 749 | + 'success' => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(), |
|
| 750 | + 'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention'] |
|
| 751 | + : array(), |
|
| 752 | + 'errors' => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(), |
|
| 753 | + ); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * compile all error or success messages into one string |
|
| 760 | + * |
|
| 761 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
| 762 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
| 763 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
| 764 | + * - ONLY do this just before redirecting |
|
| 765 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
| 766 | + * @return array |
|
| 767 | + */ |
|
| 768 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
| 769 | + { |
|
| 770 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 771 | + $success_messages = ''; |
|
| 772 | + $attention_messages = ''; |
|
| 773 | + $error_messages = ''; |
|
| 774 | + $print_scripts = false; |
|
| 775 | + // either save notices to the db |
|
| 776 | + if ($save_to_transient) { |
|
| 777 | + update_option('ee_notices', self::$_espresso_notices); |
|
| 778 | + return array(); |
|
| 779 | + } |
|
| 780 | + // grab any notices that have been previously saved |
|
| 781 | + if ($notices = get_option('ee_notices', false)) { |
|
| 782 | + foreach ($notices as $type => $notice) { |
|
| 783 | + if (is_array($notice) && ! empty($notice)) { |
|
| 784 | + // make sure that existing notice type is an array |
|
| 785 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
| 786 | + && ! empty(self::$_espresso_notices[$type]) |
|
| 787 | + ? self::$_espresso_notices[$type] : array(); |
|
| 788 | + // merge stored notices with any newly created ones |
|
| 789 | + self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
| 790 | + $print_scripts = true; |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + // now clear any stored notices |
|
| 794 | + update_option('ee_notices', false); |
|
| 795 | + } |
|
| 796 | + // check for success messages |
|
| 797 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
| 798 | + // combine messages |
|
| 799 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />'); |
|
| 800 | + $print_scripts = true; |
|
| 801 | + } |
|
| 802 | + // check for attention messages |
|
| 803 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
| 804 | + // combine messages |
|
| 805 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />'); |
|
| 806 | + $print_scripts = true; |
|
| 807 | + } |
|
| 808 | + // check for error messages |
|
| 809 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
| 810 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
| 811 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
| 812 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
| 813 | + // combine messages |
|
| 814 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />'); |
|
| 815 | + $print_scripts = true; |
|
| 816 | + } |
|
| 817 | + if ($format_output) { |
|
| 818 | + $notices = '<div id="espresso-notices">'; |
|
| 819 | + $close = is_admin() ? '' |
|
| 820 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
| 821 | + if ($success_messages !== '') { |
|
| 822 | + $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
| 823 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
| 824 | + //showMessage( $success_messages ); |
|
| 825 | + $notices .= '<div id="' |
|
| 826 | + . $css_id |
|
| 827 | + . '" class="espresso-notices ' |
|
| 828 | + . $css_class |
|
| 829 | + . '" style="display:none;"><p>' |
|
| 830 | + . $success_messages |
|
| 831 | + . '</p>' |
|
| 832 | + . $close |
|
| 833 | + . '</div>'; |
|
| 834 | + } |
|
| 835 | + if ($attention_messages !== '') { |
|
| 836 | + $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
| 837 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
| 838 | + //showMessage( $error_messages, TRUE ); |
|
| 839 | + $notices .= '<div id="' |
|
| 840 | + . $css_id |
|
| 841 | + . '" class="espresso-notices ' |
|
| 842 | + . $css_class |
|
| 843 | + . '" style="display:none;"><p>' |
|
| 844 | + . $attention_messages |
|
| 845 | + . '</p>' |
|
| 846 | + . $close |
|
| 847 | + . '</div>'; |
|
| 848 | + } |
|
| 849 | + if ($error_messages !== '') { |
|
| 850 | + $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
| 851 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
| 852 | + //showMessage( $error_messages, TRUE ); |
|
| 853 | + $notices .= '<div id="' |
|
| 854 | + . $css_id |
|
| 855 | + . '" class="espresso-notices ' |
|
| 856 | + . $css_class |
|
| 857 | + . '" style="display:none;"><p>' |
|
| 858 | + . $error_messages |
|
| 859 | + . '</p>' |
|
| 860 | + . $close |
|
| 861 | + . '</div>'; |
|
| 862 | + } |
|
| 863 | + $notices .= '</div>'; |
|
| 864 | + } else { |
|
| 865 | + $notices = array( |
|
| 866 | + 'success' => $success_messages, |
|
| 867 | + 'attention' => $attention_messages, |
|
| 868 | + 'errors' => $error_messages, |
|
| 869 | + ); |
|
| 870 | + if ($remove_empty) { |
|
| 871 | + // remove empty notices |
|
| 872 | + foreach ($notices as $type => $notice) { |
|
| 873 | + if (empty($notice)) { |
|
| 874 | + unset($notices[$type]); |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + } |
|
| 879 | + if ($print_scripts) { |
|
| 880 | + self::_print_scripts(); |
|
| 881 | + } |
|
| 882 | + return $notices; |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + /** |
|
| 888 | + * add_persistent_admin_notice |
|
| 889 | + * |
|
| 890 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 891 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
| 892 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
| 893 | + * @return void |
|
| 894 | + */ |
|
| 895 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
| 896 | + { |
|
| 897 | + if (! empty($pan_name) && ! empty($pan_message)) { |
|
| 898 | + $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
| 899 | + //maybe initialize persistent_admin_notices |
|
| 900 | + if (empty($persistent_admin_notices)) { |
|
| 901 | + add_option('ee_pers_admin_notices', array(), '', 'no'); |
|
| 902 | + } |
|
| 903 | + $pan_name = sanitize_key($pan_name); |
|
| 904 | + if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) { |
|
| 905 | + $persistent_admin_notices[$pan_name] = $pan_message; |
|
| 906 | + update_option('ee_pers_admin_notices', $persistent_admin_notices); |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * dismiss_persistent_admin_notice |
|
| 915 | + * |
|
| 916 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
| 917 | + * @param bool $purge |
|
| 918 | + * @param bool $return_immediately |
|
| 919 | + * @return void |
|
| 920 | + */ |
|
| 921 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false) |
|
| 922 | + { |
|
| 923 | + $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice') |
|
| 924 | + ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name; |
|
| 925 | + if (! empty($pan_name)) { |
|
| 926 | + $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
| 927 | + // check if notice we wish to dismiss is actually in the $persistent_admin_notices array |
|
| 928 | + if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) { |
|
| 929 | + // completely delete nag notice, or just NULL message so that it can NOT be added again ? |
|
| 930 | + if ($purge) { |
|
| 931 | + unset($persistent_admin_notices[$pan_name]); |
|
| 932 | + } else { |
|
| 933 | + $persistent_admin_notices[$pan_name] = null; |
|
| 934 | + } |
|
| 935 | + if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) { |
|
| 936 | + EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.', |
|
| 937 | + 'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__); |
|
| 938 | + } |
|
| 939 | + } |
|
| 940 | + } |
|
| 941 | + if ($return_immediately) { |
|
| 942 | + return; |
|
| 943 | + } |
|
| 944 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 945 | + // grab any notices and concatenate into string |
|
| 946 | + echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false)))); |
|
| 947 | + exit(); |
|
| 948 | + } |
|
| 949 | + // save errors to a transient to be displayed on next request (after redirect) |
|
| 950 | + EE_Error::get_notices(false, true); |
|
| 951 | + $return_url = EE_Registry::instance()->REQ->is_set('return_url') |
|
| 952 | + ? EE_Registry::instance()->REQ->get('return_url') : ''; |
|
| 953 | + wp_safe_redirect(urldecode($return_url)); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + |
|
| 958 | + /** |
|
| 959 | + * display_persistent_admin_notices |
|
| 960 | + * |
|
| 961 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 962 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
| 963 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
| 964 | + * @return string |
|
| 965 | + */ |
|
| 966 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
| 967 | + { |
|
| 968 | + if (! empty($pan_name) && ! empty($pan_message)) { |
|
| 969 | + $args = array( |
|
| 970 | + 'nag_notice' => $pan_name, |
|
| 971 | + 'return_url' => urlencode($return_url), |
|
| 972 | + 'ajax_url' => WP_AJAX_URL, |
|
| 973 | + 'unknown_error' => esc_html__( |
|
| 974 | + 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
| 975 | + 'event_espresso' |
|
| 976 | + ), |
|
| 977 | + ); |
|
| 978 | + EE_Registry::$i18n_js_strings = array_merge( |
|
| 979 | + EE_Registry::$i18n_js_strings, |
|
| 980 | + array('ee_dismiss' => $args) |
|
| 981 | + ); |
|
| 982 | + return ' |
|
| 983 | 983 | <div id="' |
| 984 | - . $pan_name |
|
| 985 | - . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;"> |
|
| 984 | + . $pan_name |
|
| 985 | + . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;"> |
|
| 986 | 986 | <p>' |
| 987 | - . $pan_message |
|
| 988 | - . '</p> |
|
| 987 | + . $pan_message |
|
| 988 | + . '</p> |
|
| 989 | 989 | <a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="' |
| 990 | - . $pan_name |
|
| 991 | - . '"> |
|
| 990 | + . $pan_name |
|
| 991 | + . '"> |
|
| 992 | 992 | <span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>' |
| 993 | - . __('Dismiss', 'event_espresso') |
|
| 994 | - . ' |
|
| 993 | + . __('Dismiss', 'event_espresso') |
|
| 994 | + . ' |
|
| 995 | 995 | </a> |
| 996 | 996 | <div style="clear:both;"></div> |
| 997 | 997 | </div>'; |
| 998 | - } |
|
| 999 | - return ''; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * get_persistent_admin_notices |
|
| 1006 | - * |
|
| 1007 | - * @param string $return_url |
|
| 1008 | - * @return string |
|
| 1009 | - */ |
|
| 1010 | - public static function get_persistent_admin_notices($return_url = '') |
|
| 1011 | - { |
|
| 1012 | - $notices = ''; |
|
| 1013 | - // check for persistent admin notices |
|
| 1014 | - //filter the list though so plugins can notify the admin in a different way if they want |
|
| 1015 | - $persistent_admin_notices = apply_filters( |
|
| 1016 | - 'FHEE__EE_Error__get_persistent_admin_notices', |
|
| 1017 | - get_option('ee_pers_admin_notices', false), |
|
| 1018 | - 'ee_pers_admin_notices', |
|
| 1019 | - $return_url |
|
| 1020 | - ); |
|
| 1021 | - if ($persistent_admin_notices) { |
|
| 1022 | - // load scripts |
|
| 1023 | - wp_register_script( |
|
| 1024 | - 'espresso_core', |
|
| 1025 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1026 | - array('jquery'), |
|
| 1027 | - EVENT_ESPRESSO_VERSION, |
|
| 1028 | - true |
|
| 1029 | - ); |
|
| 1030 | - wp_register_script( |
|
| 1031 | - 'ee_error_js', |
|
| 1032 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1033 | - array('espresso_core'), |
|
| 1034 | - EVENT_ESPRESSO_VERSION, |
|
| 1035 | - true |
|
| 1036 | - ); |
|
| 1037 | - wp_enqueue_script('ee_error_js'); |
|
| 1038 | - // and display notices |
|
| 1039 | - foreach ($persistent_admin_notices as $pan_name => $pan_message) { |
|
| 1040 | - $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url); |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - return $notices; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - |
|
| 1048 | - /** |
|
| 1049 | - * _print_scripts |
|
| 1050 | - * |
|
| 1051 | - * @param bool $force_print |
|
| 1052 | - * @return string |
|
| 1053 | - */ |
|
| 1054 | - private static function _print_scripts($force_print = false) |
|
| 1055 | - { |
|
| 1056 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1057 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
| 1058 | - return ''; |
|
| 1059 | - } |
|
| 1060 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
| 1061 | - wp_enqueue_style('espresso_default'); |
|
| 1062 | - wp_enqueue_style('espresso_custom_css'); |
|
| 1063 | - wp_enqueue_script('ee_error_js'); |
|
| 1064 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
| 1065 | - } |
|
| 1066 | - } else { |
|
| 1067 | - return ' |
|
| 998 | + } |
|
| 999 | + return ''; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * get_persistent_admin_notices |
|
| 1006 | + * |
|
| 1007 | + * @param string $return_url |
|
| 1008 | + * @return string |
|
| 1009 | + */ |
|
| 1010 | + public static function get_persistent_admin_notices($return_url = '') |
|
| 1011 | + { |
|
| 1012 | + $notices = ''; |
|
| 1013 | + // check for persistent admin notices |
|
| 1014 | + //filter the list though so plugins can notify the admin in a different way if they want |
|
| 1015 | + $persistent_admin_notices = apply_filters( |
|
| 1016 | + 'FHEE__EE_Error__get_persistent_admin_notices', |
|
| 1017 | + get_option('ee_pers_admin_notices', false), |
|
| 1018 | + 'ee_pers_admin_notices', |
|
| 1019 | + $return_url |
|
| 1020 | + ); |
|
| 1021 | + if ($persistent_admin_notices) { |
|
| 1022 | + // load scripts |
|
| 1023 | + wp_register_script( |
|
| 1024 | + 'espresso_core', |
|
| 1025 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1026 | + array('jquery'), |
|
| 1027 | + EVENT_ESPRESSO_VERSION, |
|
| 1028 | + true |
|
| 1029 | + ); |
|
| 1030 | + wp_register_script( |
|
| 1031 | + 'ee_error_js', |
|
| 1032 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1033 | + array('espresso_core'), |
|
| 1034 | + EVENT_ESPRESSO_VERSION, |
|
| 1035 | + true |
|
| 1036 | + ); |
|
| 1037 | + wp_enqueue_script('ee_error_js'); |
|
| 1038 | + // and display notices |
|
| 1039 | + foreach ($persistent_admin_notices as $pan_name => $pan_message) { |
|
| 1040 | + $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url); |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + return $notices; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + |
|
| 1048 | + /** |
|
| 1049 | + * _print_scripts |
|
| 1050 | + * |
|
| 1051 | + * @param bool $force_print |
|
| 1052 | + * @return string |
|
| 1053 | + */ |
|
| 1054 | + private static function _print_scripts($force_print = false) |
|
| 1055 | + { |
|
| 1056 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1057 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
| 1058 | + return ''; |
|
| 1059 | + } |
|
| 1060 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
| 1061 | + wp_enqueue_style('espresso_default'); |
|
| 1062 | + wp_enqueue_style('espresso_custom_css'); |
|
| 1063 | + wp_enqueue_script('ee_error_js'); |
|
| 1064 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
| 1065 | + } |
|
| 1066 | + } else { |
|
| 1067 | + return ' |
|
| 1068 | 1068 | <script> |
| 1069 | 1069 | /* <![CDATA[ */ |
| 1070 | 1070 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -1074,143 +1074,143 @@ discard block |
||
| 1074 | 1074 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
| 1075 | 1075 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
| 1076 | 1076 | '; |
| 1077 | - } |
|
| 1078 | - return ''; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * enqueue_error_scripts |
|
| 1085 | - * |
|
| 1086 | - * @return void |
|
| 1087 | - */ |
|
| 1088 | - public static function enqueue_error_scripts() |
|
| 1089 | - { |
|
| 1090 | - self::_print_scripts(); |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - |
|
| 1094 | - |
|
| 1095 | - /** |
|
| 1096 | - * create error code from filepath, function name, |
|
| 1097 | - * and line number where exception or error was thrown |
|
| 1098 | - * |
|
| 1099 | - * @param string $file |
|
| 1100 | - * @param string $func |
|
| 1101 | - * @param string $line |
|
| 1102 | - * @return string |
|
| 1103 | - */ |
|
| 1104 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
| 1105 | - { |
|
| 1106 | - $file = explode('.', basename($file)); |
|
| 1107 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
| 1108 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1109 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1110 | - return $error_code; |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - |
|
| 1115 | - /** |
|
| 1116 | - * write exception details to log file |
|
| 1117 | - * |
|
| 1118 | - * @param int $time |
|
| 1119 | - * @param array $ex |
|
| 1120 | - * @param bool $clear |
|
| 1121 | - * @return void |
|
| 1122 | - */ |
|
| 1123 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
| 1124 | - { |
|
| 1125 | - if (empty($ex)) { |
|
| 1126 | - return; |
|
| 1127 | - } |
|
| 1128 | - if (! $time) { |
|
| 1129 | - $time = time(); |
|
| 1130 | - } |
|
| 1131 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
| 1132 | - . PHP_EOL; |
|
| 1133 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1134 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1135 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1136 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1137 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1138 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1139 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1140 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
| 1141 | - . PHP_EOL; |
|
| 1142 | - try { |
|
| 1143 | - EEH_File::ensure_file_exists_and_is_writable( |
|
| 1144 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file |
|
| 1145 | - ); |
|
| 1146 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs'); |
|
| 1147 | - if (! $clear) { |
|
| 1148 | - //get existing log file and append new log info |
|
| 1149 | - $exception_log = EEH_File::get_file_contents( |
|
| 1150 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file |
|
| 1151 | - ) . $exception_log; |
|
| 1152 | - } |
|
| 1153 | - EEH_File::write_to_file( |
|
| 1154 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, |
|
| 1155 | - $exception_log |
|
| 1156 | - ); |
|
| 1157 | - } catch (EE_Error $e) { |
|
| 1158 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
| 1159 | - 'event_espresso'), $e->getMessage())); |
|
| 1160 | - return; |
|
| 1161 | - } |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - /** |
|
| 1167 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
| 1168 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
| 1169 | - * but the code execution is done in a manner that could lead to unexpected results |
|
| 1170 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
| 1171 | - * A good test for knowing whether to use this method is: |
|
| 1172 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
| 1173 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
| 1174 | - * 2. If this is loaded before something else, it won't break anything, |
|
| 1175 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
| 1176 | - * |
|
| 1177 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
| 1178 | - * @param string $function The function that was called |
|
| 1179 | - * @param string $message A message explaining what has been done incorrectly |
|
| 1180 | - * @param string $version The version of Event Espresso where the error was added |
|
| 1181 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 1182 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
| 1183 | - * but not have any notices appear until a later version. This allows developers |
|
| 1184 | - * extra time to update their code before notices appear. |
|
| 1185 | - * @param int $error_type |
|
| 1186 | - */ |
|
| 1187 | - public static function doing_it_wrong( |
|
| 1188 | - $function, |
|
| 1189 | - $message, |
|
| 1190 | - $version, |
|
| 1191 | - $applies_when = '', |
|
| 1192 | - $error_type = null |
|
| 1193 | - ) { |
|
| 1194 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 1195 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
| 1196 | - } |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - |
|
| 1200 | - |
|
| 1201 | - /** |
|
| 1202 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
| 1203 | - * |
|
| 1204 | - * @return array { |
|
| 1205 | - * @type array $success all the success messages |
|
| 1206 | - * @type array $errors all the error messages |
|
| 1207 | - * @type array $attention all the attention messages |
|
| 1208 | - * } |
|
| 1209 | - */ |
|
| 1210 | - public static function get_raw_notices() |
|
| 1211 | - { |
|
| 1212 | - return self::$_espresso_notices; |
|
| 1213 | - } |
|
| 1077 | + } |
|
| 1078 | + return ''; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * enqueue_error_scripts |
|
| 1085 | + * |
|
| 1086 | + * @return void |
|
| 1087 | + */ |
|
| 1088 | + public static function enqueue_error_scripts() |
|
| 1089 | + { |
|
| 1090 | + self::_print_scripts(); |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + |
|
| 1094 | + |
|
| 1095 | + /** |
|
| 1096 | + * create error code from filepath, function name, |
|
| 1097 | + * and line number where exception or error was thrown |
|
| 1098 | + * |
|
| 1099 | + * @param string $file |
|
| 1100 | + * @param string $func |
|
| 1101 | + * @param string $line |
|
| 1102 | + * @return string |
|
| 1103 | + */ |
|
| 1104 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
| 1105 | + { |
|
| 1106 | + $file = explode('.', basename($file)); |
|
| 1107 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
| 1108 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1109 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1110 | + return $error_code; |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + |
|
| 1115 | + /** |
|
| 1116 | + * write exception details to log file |
|
| 1117 | + * |
|
| 1118 | + * @param int $time |
|
| 1119 | + * @param array $ex |
|
| 1120 | + * @param bool $clear |
|
| 1121 | + * @return void |
|
| 1122 | + */ |
|
| 1123 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
| 1124 | + { |
|
| 1125 | + if (empty($ex)) { |
|
| 1126 | + return; |
|
| 1127 | + } |
|
| 1128 | + if (! $time) { |
|
| 1129 | + $time = time(); |
|
| 1130 | + } |
|
| 1131 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
| 1132 | + . PHP_EOL; |
|
| 1133 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1134 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1135 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1136 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1137 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1138 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1139 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1140 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
| 1141 | + . PHP_EOL; |
|
| 1142 | + try { |
|
| 1143 | + EEH_File::ensure_file_exists_and_is_writable( |
|
| 1144 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file |
|
| 1145 | + ); |
|
| 1146 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs'); |
|
| 1147 | + if (! $clear) { |
|
| 1148 | + //get existing log file and append new log info |
|
| 1149 | + $exception_log = EEH_File::get_file_contents( |
|
| 1150 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file |
|
| 1151 | + ) . $exception_log; |
|
| 1152 | + } |
|
| 1153 | + EEH_File::write_to_file( |
|
| 1154 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, |
|
| 1155 | + $exception_log |
|
| 1156 | + ); |
|
| 1157 | + } catch (EE_Error $e) { |
|
| 1158 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
| 1159 | + 'event_espresso'), $e->getMessage())); |
|
| 1160 | + return; |
|
| 1161 | + } |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + /** |
|
| 1167 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
| 1168 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
| 1169 | + * but the code execution is done in a manner that could lead to unexpected results |
|
| 1170 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
| 1171 | + * A good test for knowing whether to use this method is: |
|
| 1172 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
| 1173 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
| 1174 | + * 2. If this is loaded before something else, it won't break anything, |
|
| 1175 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
| 1176 | + * |
|
| 1177 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
| 1178 | + * @param string $function The function that was called |
|
| 1179 | + * @param string $message A message explaining what has been done incorrectly |
|
| 1180 | + * @param string $version The version of Event Espresso where the error was added |
|
| 1181 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 1182 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
| 1183 | + * but not have any notices appear until a later version. This allows developers |
|
| 1184 | + * extra time to update their code before notices appear. |
|
| 1185 | + * @param int $error_type |
|
| 1186 | + */ |
|
| 1187 | + public static function doing_it_wrong( |
|
| 1188 | + $function, |
|
| 1189 | + $message, |
|
| 1190 | + $version, |
|
| 1191 | + $applies_when = '', |
|
| 1192 | + $error_type = null |
|
| 1193 | + ) { |
|
| 1194 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 1195 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
| 1196 | + } |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + |
|
| 1200 | + |
|
| 1201 | + /** |
|
| 1202 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
| 1203 | + * |
|
| 1204 | + * @return array { |
|
| 1205 | + * @type array $success all the success messages |
|
| 1206 | + * @type array $errors all the error messages |
|
| 1207 | + * @type array $attention all the attention messages |
|
| 1208 | + * } |
|
| 1209 | + */ |
|
| 1210 | + public static function get_raw_notices() |
|
| 1211 | + { |
|
| 1212 | + return self::$_espresso_notices; |
|
| 1213 | + } |
|
| 1214 | 1214 | |
| 1215 | 1215 | |
| 1216 | 1216 | |
@@ -1226,27 +1226,27 @@ discard block |
||
| 1226 | 1226 | */ |
| 1227 | 1227 | function espresso_error_enqueue_scripts() |
| 1228 | 1228 | { |
| 1229 | - // js for error handling |
|
| 1230 | - wp_register_script( |
|
| 1231 | - 'espresso_core', |
|
| 1232 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1233 | - array('jquery'), |
|
| 1234 | - EVENT_ESPRESSO_VERSION, |
|
| 1235 | - false |
|
| 1236 | - ); |
|
| 1237 | - wp_register_script( |
|
| 1238 | - 'ee_error_js', |
|
| 1239 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1240 | - array('espresso_core'), |
|
| 1241 | - EVENT_ESPRESSO_VERSION, |
|
| 1242 | - false |
|
| 1243 | - ); |
|
| 1229 | + // js for error handling |
|
| 1230 | + wp_register_script( |
|
| 1231 | + 'espresso_core', |
|
| 1232 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1233 | + array('jquery'), |
|
| 1234 | + EVENT_ESPRESSO_VERSION, |
|
| 1235 | + false |
|
| 1236 | + ); |
|
| 1237 | + wp_register_script( |
|
| 1238 | + 'ee_error_js', |
|
| 1239 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1240 | + array('espresso_core'), |
|
| 1241 | + EVENT_ESPRESSO_VERSION, |
|
| 1242 | + false |
|
| 1243 | + ); |
|
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | 1246 | if (is_admin()) { |
| 1247 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1247 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1248 | 1248 | } else { |
| 1249 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1249 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1250 | 1250 | } |
| 1251 | 1251 | |
| 1252 | 1252 | |
@@ -164,7 +164,7 @@ |
||
| 164 | 164 | |
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | - * @param $ticket |
|
| 167 | + * @param \EE_Base_Class $ticket |
|
| 168 | 168 | * @throws DomainException |
| 169 | 169 | * @throws EE_Error |
| 170 | 170 | * @throws UnexpectedEntityException |
@@ -31,620 +31,620 @@ |
||
| 31 | 31 | class EventSpacesCalculator |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var EE_Event $event |
|
| 36 | - */ |
|
| 37 | - private $event; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var array $datetime_query_params |
|
| 41 | - */ |
|
| 42 | - private $datetime_query_params; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var EE_Ticket[] $active_tickets |
|
| 46 | - */ |
|
| 47 | - private $active_tickets = array(); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var EE_Datetime[] $datetimes |
|
| 51 | - */ |
|
| 52 | - private $datetimes = array(); |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Array of Ticket IDs grouped by Datetime |
|
| 56 | - * |
|
| 57 | - * @var array $datetimes |
|
| 58 | - */ |
|
| 59 | - private $datetime_tickets = array(); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Max spaces for each Datetime (reg limit - previous sold) |
|
| 63 | - * |
|
| 64 | - * @var array $datetime_spaces |
|
| 65 | - */ |
|
| 66 | - private $datetime_spaces = array(); |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Array of Datetime IDs grouped by Ticket |
|
| 70 | - * |
|
| 71 | - * @var array $ticket_datetimes |
|
| 72 | - */ |
|
| 73 | - private $ticket_datetimes = array(); |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 77 | - * |
|
| 78 | - * @var array $ticket_quantities |
|
| 79 | - */ |
|
| 80 | - private $ticket_quantities = array(); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * total quantity of sold and reserved for each ticket |
|
| 84 | - * |
|
| 85 | - * @var array $tickets_sold |
|
| 86 | - */ |
|
| 87 | - private $tickets_sold = array(); |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * total spaces available across all datetimes |
|
| 91 | - * |
|
| 92 | - * @var array $total_spaces |
|
| 93 | - */ |
|
| 94 | - private $total_spaces = array(); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @var boolean $debug |
|
| 98 | - */ |
|
| 99 | - private $debug = false; |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * EventSpacesCalculator constructor. |
|
| 105 | - * |
|
| 106 | - * @param EE_Event $event |
|
| 107 | - * @param array $datetime_query_params |
|
| 108 | - * @throws EE_Error |
|
| 109 | - */ |
|
| 110 | - public function __construct(EE_Event $event, array $datetime_query_params = array()) |
|
| 111 | - { |
|
| 112 | - $this->event = $event; |
|
| 113 | - $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @return EE_Ticket[] |
|
| 120 | - * @throws EE_Error |
|
| 121 | - * @throws InvalidDataTypeException |
|
| 122 | - * @throws InvalidInterfaceException |
|
| 123 | - * @throws InvalidArgumentException |
|
| 124 | - */ |
|
| 125 | - public function getActiveTickets() |
|
| 126 | - { |
|
| 127 | - if (empty($this->active_tickets)) { |
|
| 128 | - $this->active_tickets = $this->event->tickets( |
|
| 129 | - array( |
|
| 130 | - array( |
|
| 131 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 132 | - 'TKT_deleted' => false, |
|
| 133 | - ), |
|
| 134 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 135 | - ) |
|
| 136 | - ); |
|
| 137 | - } |
|
| 138 | - return $this->active_tickets; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param EE_Ticket[] $active_tickets |
|
| 145 | - * @throws EE_Error |
|
| 146 | - * @throws DomainException |
|
| 147 | - * @throws UnexpectedEntityException |
|
| 148 | - */ |
|
| 149 | - public function setActiveTickets(array $active_tickets = array()) |
|
| 150 | - { |
|
| 151 | - if ( ! empty($active_tickets)) { |
|
| 152 | - foreach ($active_tickets as $active_ticket) { |
|
| 153 | - $this->validateTicket($active_ticket); |
|
| 154 | - } |
|
| 155 | - // sort incoming array by ticket quantity (asc) |
|
| 156 | - usort( |
|
| 157 | - $active_tickets, |
|
| 158 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 159 | - if ($a->qty() === $b->qty()) { |
|
| 160 | - return 0; |
|
| 161 | - } |
|
| 162 | - return ($a->qty() < $b->qty()) |
|
| 163 | - ? -1 |
|
| 164 | - : 1; |
|
| 165 | - } |
|
| 166 | - ); |
|
| 167 | - } |
|
| 168 | - $this->active_tickets = $active_tickets; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @param $ticket |
|
| 175 | - * @throws DomainException |
|
| 176 | - * @throws EE_Error |
|
| 177 | - * @throws UnexpectedEntityException |
|
| 178 | - */ |
|
| 179 | - private function validateTicket($ticket) |
|
| 180 | - { |
|
| 181 | - if ( ! $ticket instanceof EE_Ticket) { |
|
| 182 | - throw new DomainException( |
|
| 183 | - esc_html__( |
|
| 184 | - 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
| 185 | - 'event_espresso' |
|
| 186 | - ) |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
| 190 | - throw new DomainException( |
|
| 191 | - sprintf( |
|
| 192 | - esc_html__( |
|
| 193 | - 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 194 | - 'event_espresso' |
|
| 195 | - ), |
|
| 196 | - $ticket->get_event_ID(), |
|
| 197 | - $this->event->ID() |
|
| 198 | - ) |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @return EE_Datetime[] |
|
| 207 | - */ |
|
| 208 | - public function getDatetimes() |
|
| 209 | - { |
|
| 210 | - return $this->datetimes; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @param EE_Datetime $datetime |
|
| 217 | - * @throws EE_Error |
|
| 218 | - * @throws DomainException |
|
| 219 | - */ |
|
| 220 | - public function setDatetime(EE_Datetime $datetime) |
|
| 221 | - { |
|
| 222 | - if ($datetime->event()->ID() !== $this->event->ID()) { |
|
| 223 | - throw new DomainException( |
|
| 224 | - sprintf( |
|
| 225 | - esc_html__( |
|
| 226 | - 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 227 | - 'event_espresso' |
|
| 228 | - ), |
|
| 229 | - $datetime->event()->ID(), |
|
| 230 | - $this->event->ID() |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - } |
|
| 234 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * calculate spaces remaining based on "saleable" tickets |
|
| 241 | - * |
|
| 242 | - * @return float|int |
|
| 243 | - * @throws EE_Error |
|
| 244 | - * @throws DomainException |
|
| 245 | - * @throws UnexpectedEntityException |
|
| 246 | - * @throws InvalidDataTypeException |
|
| 247 | - * @throws InvalidInterfaceException |
|
| 248 | - * @throws InvalidArgumentException |
|
| 249 | - */ |
|
| 250 | - public function spacesRemaining() |
|
| 251 | - { |
|
| 252 | - $this->initialize(); |
|
| 253 | - return $this->calculate(); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * calculates total available spaces for an event with no regard for sold tickets |
|
| 260 | - * |
|
| 261 | - * @return int|float |
|
| 262 | - * @throws EE_Error |
|
| 263 | - * @throws DomainException |
|
| 264 | - * @throws UnexpectedEntityException |
|
| 265 | - * @throws InvalidDataTypeException |
|
| 266 | - * @throws InvalidInterfaceException |
|
| 267 | - * @throws InvalidArgumentException |
|
| 268 | - */ |
|
| 269 | - public function totalSpacesAvailable() |
|
| 270 | - { |
|
| 271 | - $this->initialize(); |
|
| 272 | - return $this->calculate(false); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Loops through the active tickets for the event |
|
| 279 | - * and builds a series of data arrays that will be used for calculating |
|
| 280 | - * the total maximum available spaces, as well as the spaces remaining. |
|
| 281 | - * Because ticket quantities affect datetime spaces and vice versa, |
|
| 282 | - * we need to be constantly updating these data arrays as things change, |
|
| 283 | - * which is the entire reason for their existence. |
|
| 284 | - * |
|
| 285 | - * @throws EE_Error |
|
| 286 | - * @throws DomainException |
|
| 287 | - * @throws UnexpectedEntityException |
|
| 288 | - * @throws InvalidDataTypeException |
|
| 289 | - * @throws InvalidInterfaceException |
|
| 290 | - * @throws InvalidArgumentException |
|
| 291 | - */ |
|
| 292 | - private function initialize() |
|
| 293 | - { |
|
| 294 | - if ($this->debug) { |
|
| 295 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 296 | - } |
|
| 297 | - $this->datetime_tickets = array(); |
|
| 298 | - $this->datetime_spaces = array(); |
|
| 299 | - $this->ticket_datetimes = array(); |
|
| 300 | - $this->ticket_quantities = array(); |
|
| 301 | - $this->tickets_sold = array(); |
|
| 302 | - $this->total_spaces = array(); |
|
| 303 | - $active_tickets = $this->getActiveTickets(); |
|
| 304 | - if ( ! empty($active_tickets)) { |
|
| 305 | - foreach ($active_tickets as $ticket) { |
|
| 306 | - $this->validateTicket($ticket); |
|
| 307 | - // we need to index our data arrays using strings for the purpose of sorting, |
|
| 308 | - // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
| 309 | - $ticket_identifier = "T{$ticket->ID()}"; |
|
| 310 | - // to start, we'll just consider the raw qty to be the maximum availability for this ticket |
|
| 311 | - $max_tickets = $ticket->qty(); |
|
| 312 | - // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
| 313 | - $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
| 314 | - foreach ($ticket_datetimes as $datetime) { |
|
| 315 | - // save all datetimes |
|
| 316 | - $this->setDatetime($datetime); |
|
| 317 | - $datetime_identifier = "D{$datetime->ID()}"; |
|
| 318 | - $reg_limit = $datetime->reg_limit(); |
|
| 319 | - // ticket quantity can not exceed datetime reg limit |
|
| 320 | - $max_tickets = min($max_tickets, $reg_limit); |
|
| 321 | - // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
| 322 | - // we are going to move all of our data into the following arrays: |
|
| 323 | - // datetime spaces initially represents the reg limit for each datetime, |
|
| 324 | - // but this will get adjusted as tickets are accounted for |
|
| 325 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
| 326 | - // just an array of ticket IDs grouped by datetime |
|
| 327 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
| 328 | - // and an array of datetime IDs grouped by ticket |
|
| 329 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
| 330 | - } |
|
| 331 | - // total quantity of sold and reserved for each ticket |
|
| 332 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
| 333 | - // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 334 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - // sort datetime spaces by reg limit, but maintain our string indexes |
|
| 338 | - asort($this->datetime_spaces, SORT_NUMERIC); |
|
| 339 | - // datetime tickets need to be sorted in the SAME order as the above array... |
|
| 340 | - // so we'll just use array_merge() to take the structure of datetime_spaces |
|
| 341 | - // but overwrite all of the data with that from datetime_tickets |
|
| 342 | - $this->datetime_tickets = array_merge( |
|
| 343 | - $this->datetime_spaces, |
|
| 344 | - $this->datetime_tickets |
|
| 345 | - ); |
|
| 346 | - if ($this->debug) { |
|
| 347 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 348 | - \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
| 349 | - \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * performs calculations on initialized data |
|
| 357 | - * |
|
| 358 | - * @param bool $consider_sold |
|
| 359 | - * @return int|float |
|
| 360 | - */ |
|
| 361 | - private function calculate($consider_sold = true) |
|
| 362 | - { |
|
| 363 | - if ($this->debug) { |
|
| 364 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 365 | - } |
|
| 366 | - if ($consider_sold) { |
|
| 367 | - // subtract amounts sold from all ticket quantities and datetime spaces |
|
| 368 | - $this->adjustTicketQuantitiesDueToSales(); |
|
| 369 | - } |
|
| 370 | - foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
| 371 | - $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
| 372 | - } |
|
| 373 | - // total spaces available is just the sum of the spaces available for each datetime |
|
| 374 | - $spaces_remaining = array_sum($this->total_spaces); |
|
| 375 | - if ($this->debug) { |
|
| 376 | - \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
| 377 | - \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
| 378 | - \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
| 379 | - } |
|
| 380 | - return $spaces_remaining; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
| 386 | - */ |
|
| 387 | - private function adjustTicketQuantitiesDueToSales() |
|
| 388 | - { |
|
| 389 | - if ($this->debug) { |
|
| 390 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 391 | - } |
|
| 392 | - foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
|
| 393 | - if (isset($this->ticket_quantities[ $ticket_identifier ])){ |
|
| 394 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
| 395 | - if ($this->debug) { |
|
| 396 | - \EEH_Debug_Tools::printr("{$tickets_sold} sales for ticket {$ticket_identifier} ", 'subtracting', __FILE__, __LINE__); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - if ( |
|
| 400 | - isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 401 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 402 | - ){ |
|
| 403 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
| 404 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 405 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
| 406 | - if ($this->debug) { |
|
| 407 | - \EEH_Debug_Tools::printr("{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
| 408 | - 'subtracting', __FILE__, __LINE__); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * @param string $datetime_identifier |
|
| 420 | - * @param array $tickets |
|
| 421 | - */ |
|
| 422 | - private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
| 423 | - { |
|
| 424 | - // make sure a reg limit is set for the datetime |
|
| 425 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
| 426 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
| 427 | - : 0; |
|
| 428 | - // and bail if it is not |
|
| 429 | - if ( ! $reg_limit) { |
|
| 430 | - if ($this->debug) { |
|
| 431 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
| 432 | - } |
|
| 433 | - return; |
|
| 434 | - } |
|
| 435 | - if ($this->debug) { |
|
| 436 | - \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
| 437 | - \EEH_Debug_Tools::printr("{$reg_limit}", 'REG LIMIT', __FILE__, __LINE__); |
|
| 438 | - } |
|
| 439 | - // number of allocated spaces always starts at zero |
|
| 440 | - $spaces_allocated = 0; |
|
| 441 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
| 442 | - foreach ($tickets as $ticket_identifier) { |
|
| 443 | - $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
| 444 | - $datetime_identifier, |
|
| 445 | - $reg_limit, |
|
| 446 | - $ticket_identifier, |
|
| 447 | - $spaces_allocated |
|
| 448 | - ); |
|
| 449 | - } |
|
| 450 | - // spaces can't be negative |
|
| 451 | - $spaces_allocated = max($spaces_allocated, 0); |
|
| 452 | - if ($spaces_allocated) { |
|
| 453 | - // track any non-zero values |
|
| 454 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
| 455 | - if ($this->debug) { |
|
| 456 | - \EEH_Debug_Tools::printr((string)$spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
| 457 | - } |
|
| 458 | - } else { |
|
| 459 | - if ($this->debug) { |
|
| 460 | - \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - if ($this->debug) { |
|
| 464 | - \EEH_Debug_Tools::printr($this->total_spaces[ $datetime_identifier ], '$total_spaces', __FILE__, |
|
| 465 | - __LINE__); |
|
| 466 | - \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
| 467 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * @param string $datetime_identifier |
|
| 475 | - * @param int $reg_limit |
|
| 476 | - * @param string $ticket_identifier |
|
| 477 | - * @param int $spaces_allocated |
|
| 478 | - * @return int |
|
| 479 | - */ |
|
| 480 | - private function calculateAvailableSpacesForTicket( |
|
| 481 | - $datetime_identifier, |
|
| 482 | - $reg_limit, |
|
| 483 | - $ticket_identifier, |
|
| 484 | - $spaces_allocated |
|
| 485 | - ) { |
|
| 486 | - // make sure ticket quantity is set |
|
| 487 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
| 488 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
| 489 | - : 0; |
|
| 490 | - if ($this->debug) { |
|
| 491 | - \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
| 492 | - \EEH_Debug_Tools::printr("{$ticket_quantity}", "ticket $ticket_identifier quantity: ", |
|
| 493 | - __FILE__, __LINE__, 2); |
|
| 494 | - } |
|
| 495 | - if ($ticket_quantity) { |
|
| 496 | - if ($this->debug) { |
|
| 497 | - \EEH_Debug_Tools::printr( |
|
| 498 | - ($spaces_allocated <= $reg_limit) |
|
| 499 | - ? 'true' |
|
| 500 | - : 'false', |
|
| 501 | - ' . spaces_allocated <= reg_limit = ', |
|
| 502 | - __FILE__, __LINE__ |
|
| 503 | - ); |
|
| 504 | - } |
|
| 505 | - // if the datetime is NOT at full capacity yet |
|
| 506 | - if ($spaces_allocated <= $reg_limit) { |
|
| 507 | - // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
| 508 | - // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
| 509 | - // or the maximum ticket quantity |
|
| 510 | - $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
| 511 | - // adjust the available quantity in our tracking array |
|
| 512 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
| 513 | - // and increment spaces allocated for this datetime |
|
| 514 | - $spaces_allocated += $ticket_quantity; |
|
| 515 | - $at_capacity = $spaces_allocated >= $reg_limit; |
|
| 516 | - if ($this->debug) { |
|
| 517 | - \EEH_Debug_Tools::printr("{$ticket_quantity} {$ticket_identifier} tickets", ' > > allocate ', |
|
| 518 | - __FILE__, __LINE__, 3); |
|
| 519 | - if ($at_capacity) { |
|
| 520 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - // now adjust all other datetimes that allow access to this ticket |
|
| 524 | - $this->adjustDatetimes( |
|
| 525 | - $datetime_identifier, |
|
| 526 | - $ticket_identifier, |
|
| 527 | - $ticket_quantity, |
|
| 528 | - $at_capacity |
|
| 529 | - ); |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - return $spaces_allocated; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * subtracts ticket amounts from all datetime reg limits |
|
| 539 | - * that allow access to the ticket specified, |
|
| 540 | - * because that ticket could be used |
|
| 541 | - * to attend any of the datetimes it has access to |
|
| 542 | - * |
|
| 543 | - * @param string $datetime_identifier |
|
| 544 | - * @param string $ticket_identifier |
|
| 545 | - * @param bool $at_capacity |
|
| 546 | - * @param int $ticket_quantity |
|
| 547 | - */ |
|
| 548 | - private function adjustDatetimes( |
|
| 549 | - $datetime_identifier, |
|
| 550 | - $ticket_identifier, |
|
| 551 | - $ticket_quantity, |
|
| 552 | - $at_capacity |
|
| 553 | - ) { |
|
| 554 | - foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
| 555 | - if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
| 556 | - continue; |
|
| 557 | - } |
|
| 558 | - $adjusted = $this->adjustDatetimeSpaces( |
|
| 559 | - $datetime_ID, |
|
| 560 | - $ticket_identifier, |
|
| 561 | - $ticket_quantity |
|
| 562 | - ); |
|
| 563 | - // skip to next ticket if nothing changed |
|
| 564 | - if (! ($adjusted || $at_capacity)) { |
|
| 565 | - continue; |
|
| 566 | - } |
|
| 567 | - // then all of it's tickets are now unavailable |
|
| 568 | - foreach ($datetime_tickets as $datetime_ticket) { |
|
| 569 | - if ( |
|
| 570 | - ($ticket_identifier === $datetime_ticket || $at_capacity) |
|
| 571 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
| 572 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
| 573 | - ) { |
|
| 574 | - if ($this->debug) { |
|
| 575 | - \EEH_Debug_Tools::printr($datetime_ticket, ' . . . adjust ticket quantities for', __FILE__, |
|
| 576 | - __LINE__); |
|
| 577 | - } |
|
| 578 | - // if this datetime is at full capacity, set any tracked available quantities to zero |
|
| 579 | - // otherwise just subtract the ticket quantity |
|
| 580 | - $new_quantity = $at_capacity |
|
| 581 | - ? 0 |
|
| 582 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
| 583 | - // don't let ticket quantity go below zero |
|
| 584 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
| 585 | - if ($this->debug) { |
|
| 586 | - \EEH_Debug_Tools::printr( |
|
| 587 | - $at_capacity |
|
| 588 | - ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
| 589 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
| 590 | - " . . . . {$datetime_ticket} quantity set to ", |
|
| 591 | - __FILE__, __LINE__ |
|
| 592 | - ); |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
| 596 | - if ($datetime_ticket === $ticket_identifier) { |
|
| 597 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 598 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 599 | - ) { |
|
| 600 | - if ($this->debug) { |
|
| 601 | - \EEH_Debug_Tools::printr($datetime_ticket, ' . . adjust other Datetimes for', __FILE__, |
|
| 602 | - __LINE__); |
|
| 603 | - } |
|
| 604 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
| 605 | - // don't adjust the current datetime twice |
|
| 606 | - if ($datetime !== $datetime_identifier) { |
|
| 607 | - $this->adjustDatetimeSpaces( |
|
| 608 | - $datetime, |
|
| 609 | - $datetime_ticket, |
|
| 610 | - $ticket_quantity |
|
| 611 | - ); |
|
| 612 | - } |
|
| 613 | - } |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
| 621 | - { |
|
| 622 | - // does datetime have spaces available? |
|
| 623 | - // and does the supplied ticket have access to this datetime ? |
|
| 624 | - if ( |
|
| 625 | - $this->datetime_spaces[ $datetime_identifier ] > 0 |
|
| 626 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
| 627 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
| 628 | - ) { |
|
| 629 | - if ($this->debug) { |
|
| 630 | - \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
| 631 | - \EEH_Debug_Tools::printr("{$this->datetime_spaces[ $datetime_identifier ]}", " . . current {$datetime_identifier} spaces available", __FILE__, __LINE__); |
|
| 632 | - } |
|
| 633 | - // then decrement the available spaces for the datetime |
|
| 634 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
| 635 | - // but don't let quantities go below zero |
|
| 636 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
| 637 | - $this->datetime_spaces[ $datetime_identifier ], |
|
| 638 | - 0 |
|
| 639 | - ); |
|
| 640 | - if ($this->debug) { |
|
| 641 | - \EEH_Debug_Tools::printr("{$ticket_quantity}", |
|
| 642 | - " . . . {$datetime_identifier} capacity reduced by", __FILE__, __LINE__); |
|
| 643 | - } |
|
| 644 | - return true; |
|
| 645 | - } |
|
| 646 | - return false; |
|
| 647 | - } |
|
| 34 | + /** |
|
| 35 | + * @var EE_Event $event |
|
| 36 | + */ |
|
| 37 | + private $event; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var array $datetime_query_params |
|
| 41 | + */ |
|
| 42 | + private $datetime_query_params; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var EE_Ticket[] $active_tickets |
|
| 46 | + */ |
|
| 47 | + private $active_tickets = array(); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var EE_Datetime[] $datetimes |
|
| 51 | + */ |
|
| 52 | + private $datetimes = array(); |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Array of Ticket IDs grouped by Datetime |
|
| 56 | + * |
|
| 57 | + * @var array $datetimes |
|
| 58 | + */ |
|
| 59 | + private $datetime_tickets = array(); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Max spaces for each Datetime (reg limit - previous sold) |
|
| 63 | + * |
|
| 64 | + * @var array $datetime_spaces |
|
| 65 | + */ |
|
| 66 | + private $datetime_spaces = array(); |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Array of Datetime IDs grouped by Ticket |
|
| 70 | + * |
|
| 71 | + * @var array $ticket_datetimes |
|
| 72 | + */ |
|
| 73 | + private $ticket_datetimes = array(); |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 77 | + * |
|
| 78 | + * @var array $ticket_quantities |
|
| 79 | + */ |
|
| 80 | + private $ticket_quantities = array(); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * total quantity of sold and reserved for each ticket |
|
| 84 | + * |
|
| 85 | + * @var array $tickets_sold |
|
| 86 | + */ |
|
| 87 | + private $tickets_sold = array(); |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * total spaces available across all datetimes |
|
| 91 | + * |
|
| 92 | + * @var array $total_spaces |
|
| 93 | + */ |
|
| 94 | + private $total_spaces = array(); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var boolean $debug |
|
| 98 | + */ |
|
| 99 | + private $debug = false; |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * EventSpacesCalculator constructor. |
|
| 105 | + * |
|
| 106 | + * @param EE_Event $event |
|
| 107 | + * @param array $datetime_query_params |
|
| 108 | + * @throws EE_Error |
|
| 109 | + */ |
|
| 110 | + public function __construct(EE_Event $event, array $datetime_query_params = array()) |
|
| 111 | + { |
|
| 112 | + $this->event = $event; |
|
| 113 | + $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @return EE_Ticket[] |
|
| 120 | + * @throws EE_Error |
|
| 121 | + * @throws InvalidDataTypeException |
|
| 122 | + * @throws InvalidInterfaceException |
|
| 123 | + * @throws InvalidArgumentException |
|
| 124 | + */ |
|
| 125 | + public function getActiveTickets() |
|
| 126 | + { |
|
| 127 | + if (empty($this->active_tickets)) { |
|
| 128 | + $this->active_tickets = $this->event->tickets( |
|
| 129 | + array( |
|
| 130 | + array( |
|
| 131 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 132 | + 'TKT_deleted' => false, |
|
| 133 | + ), |
|
| 134 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 135 | + ) |
|
| 136 | + ); |
|
| 137 | + } |
|
| 138 | + return $this->active_tickets; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param EE_Ticket[] $active_tickets |
|
| 145 | + * @throws EE_Error |
|
| 146 | + * @throws DomainException |
|
| 147 | + * @throws UnexpectedEntityException |
|
| 148 | + */ |
|
| 149 | + public function setActiveTickets(array $active_tickets = array()) |
|
| 150 | + { |
|
| 151 | + if ( ! empty($active_tickets)) { |
|
| 152 | + foreach ($active_tickets as $active_ticket) { |
|
| 153 | + $this->validateTicket($active_ticket); |
|
| 154 | + } |
|
| 155 | + // sort incoming array by ticket quantity (asc) |
|
| 156 | + usort( |
|
| 157 | + $active_tickets, |
|
| 158 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
| 159 | + if ($a->qty() === $b->qty()) { |
|
| 160 | + return 0; |
|
| 161 | + } |
|
| 162 | + return ($a->qty() < $b->qty()) |
|
| 163 | + ? -1 |
|
| 164 | + : 1; |
|
| 165 | + } |
|
| 166 | + ); |
|
| 167 | + } |
|
| 168 | + $this->active_tickets = $active_tickets; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @param $ticket |
|
| 175 | + * @throws DomainException |
|
| 176 | + * @throws EE_Error |
|
| 177 | + * @throws UnexpectedEntityException |
|
| 178 | + */ |
|
| 179 | + private function validateTicket($ticket) |
|
| 180 | + { |
|
| 181 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 182 | + throw new DomainException( |
|
| 183 | + esc_html__( |
|
| 184 | + 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
| 185 | + 'event_espresso' |
|
| 186 | + ) |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
| 190 | + throw new DomainException( |
|
| 191 | + sprintf( |
|
| 192 | + esc_html__( |
|
| 193 | + 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 194 | + 'event_espresso' |
|
| 195 | + ), |
|
| 196 | + $ticket->get_event_ID(), |
|
| 197 | + $this->event->ID() |
|
| 198 | + ) |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @return EE_Datetime[] |
|
| 207 | + */ |
|
| 208 | + public function getDatetimes() |
|
| 209 | + { |
|
| 210 | + return $this->datetimes; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @param EE_Datetime $datetime |
|
| 217 | + * @throws EE_Error |
|
| 218 | + * @throws DomainException |
|
| 219 | + */ |
|
| 220 | + public function setDatetime(EE_Datetime $datetime) |
|
| 221 | + { |
|
| 222 | + if ($datetime->event()->ID() !== $this->event->ID()) { |
|
| 223 | + throw new DomainException( |
|
| 224 | + sprintf( |
|
| 225 | + esc_html__( |
|
| 226 | + 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 227 | + 'event_espresso' |
|
| 228 | + ), |
|
| 229 | + $datetime->event()->ID(), |
|
| 230 | + $this->event->ID() |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + } |
|
| 234 | + $this->datetimes[ $datetime->ID() ] = $datetime; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * calculate spaces remaining based on "saleable" tickets |
|
| 241 | + * |
|
| 242 | + * @return float|int |
|
| 243 | + * @throws EE_Error |
|
| 244 | + * @throws DomainException |
|
| 245 | + * @throws UnexpectedEntityException |
|
| 246 | + * @throws InvalidDataTypeException |
|
| 247 | + * @throws InvalidInterfaceException |
|
| 248 | + * @throws InvalidArgumentException |
|
| 249 | + */ |
|
| 250 | + public function spacesRemaining() |
|
| 251 | + { |
|
| 252 | + $this->initialize(); |
|
| 253 | + return $this->calculate(); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * calculates total available spaces for an event with no regard for sold tickets |
|
| 260 | + * |
|
| 261 | + * @return int|float |
|
| 262 | + * @throws EE_Error |
|
| 263 | + * @throws DomainException |
|
| 264 | + * @throws UnexpectedEntityException |
|
| 265 | + * @throws InvalidDataTypeException |
|
| 266 | + * @throws InvalidInterfaceException |
|
| 267 | + * @throws InvalidArgumentException |
|
| 268 | + */ |
|
| 269 | + public function totalSpacesAvailable() |
|
| 270 | + { |
|
| 271 | + $this->initialize(); |
|
| 272 | + return $this->calculate(false); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Loops through the active tickets for the event |
|
| 279 | + * and builds a series of data arrays that will be used for calculating |
|
| 280 | + * the total maximum available spaces, as well as the spaces remaining. |
|
| 281 | + * Because ticket quantities affect datetime spaces and vice versa, |
|
| 282 | + * we need to be constantly updating these data arrays as things change, |
|
| 283 | + * which is the entire reason for their existence. |
|
| 284 | + * |
|
| 285 | + * @throws EE_Error |
|
| 286 | + * @throws DomainException |
|
| 287 | + * @throws UnexpectedEntityException |
|
| 288 | + * @throws InvalidDataTypeException |
|
| 289 | + * @throws InvalidInterfaceException |
|
| 290 | + * @throws InvalidArgumentException |
|
| 291 | + */ |
|
| 292 | + private function initialize() |
|
| 293 | + { |
|
| 294 | + if ($this->debug) { |
|
| 295 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 296 | + } |
|
| 297 | + $this->datetime_tickets = array(); |
|
| 298 | + $this->datetime_spaces = array(); |
|
| 299 | + $this->ticket_datetimes = array(); |
|
| 300 | + $this->ticket_quantities = array(); |
|
| 301 | + $this->tickets_sold = array(); |
|
| 302 | + $this->total_spaces = array(); |
|
| 303 | + $active_tickets = $this->getActiveTickets(); |
|
| 304 | + if ( ! empty($active_tickets)) { |
|
| 305 | + foreach ($active_tickets as $ticket) { |
|
| 306 | + $this->validateTicket($ticket); |
|
| 307 | + // we need to index our data arrays using strings for the purpose of sorting, |
|
| 308 | + // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
| 309 | + $ticket_identifier = "T{$ticket->ID()}"; |
|
| 310 | + // to start, we'll just consider the raw qty to be the maximum availability for this ticket |
|
| 311 | + $max_tickets = $ticket->qty(); |
|
| 312 | + // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
| 313 | + $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
| 314 | + foreach ($ticket_datetimes as $datetime) { |
|
| 315 | + // save all datetimes |
|
| 316 | + $this->setDatetime($datetime); |
|
| 317 | + $datetime_identifier = "D{$datetime->ID()}"; |
|
| 318 | + $reg_limit = $datetime->reg_limit(); |
|
| 319 | + // ticket quantity can not exceed datetime reg limit |
|
| 320 | + $max_tickets = min($max_tickets, $reg_limit); |
|
| 321 | + // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
| 322 | + // we are going to move all of our data into the following arrays: |
|
| 323 | + // datetime spaces initially represents the reg limit for each datetime, |
|
| 324 | + // but this will get adjusted as tickets are accounted for |
|
| 325 | + $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
| 326 | + // just an array of ticket IDs grouped by datetime |
|
| 327 | + $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
| 328 | + // and an array of datetime IDs grouped by ticket |
|
| 329 | + $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
| 330 | + } |
|
| 331 | + // total quantity of sold and reserved for each ticket |
|
| 332 | + $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
| 333 | + // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 334 | + $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + // sort datetime spaces by reg limit, but maintain our string indexes |
|
| 338 | + asort($this->datetime_spaces, SORT_NUMERIC); |
|
| 339 | + // datetime tickets need to be sorted in the SAME order as the above array... |
|
| 340 | + // so we'll just use array_merge() to take the structure of datetime_spaces |
|
| 341 | + // but overwrite all of the data with that from datetime_tickets |
|
| 342 | + $this->datetime_tickets = array_merge( |
|
| 343 | + $this->datetime_spaces, |
|
| 344 | + $this->datetime_tickets |
|
| 345 | + ); |
|
| 346 | + if ($this->debug) { |
|
| 347 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 348 | + \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
| 349 | + \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * performs calculations on initialized data |
|
| 357 | + * |
|
| 358 | + * @param bool $consider_sold |
|
| 359 | + * @return int|float |
|
| 360 | + */ |
|
| 361 | + private function calculate($consider_sold = true) |
|
| 362 | + { |
|
| 363 | + if ($this->debug) { |
|
| 364 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 365 | + } |
|
| 366 | + if ($consider_sold) { |
|
| 367 | + // subtract amounts sold from all ticket quantities and datetime spaces |
|
| 368 | + $this->adjustTicketQuantitiesDueToSales(); |
|
| 369 | + } |
|
| 370 | + foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
| 371 | + $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
| 372 | + } |
|
| 373 | + // total spaces available is just the sum of the spaces available for each datetime |
|
| 374 | + $spaces_remaining = array_sum($this->total_spaces); |
|
| 375 | + if ($this->debug) { |
|
| 376 | + \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
| 377 | + \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
| 378 | + \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
| 379 | + } |
|
| 380 | + return $spaces_remaining; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
| 386 | + */ |
|
| 387 | + private function adjustTicketQuantitiesDueToSales() |
|
| 388 | + { |
|
| 389 | + if ($this->debug) { |
|
| 390 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 391 | + } |
|
| 392 | + foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
|
| 393 | + if (isset($this->ticket_quantities[ $ticket_identifier ])){ |
|
| 394 | + $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
| 395 | + if ($this->debug) { |
|
| 396 | + \EEH_Debug_Tools::printr("{$tickets_sold} sales for ticket {$ticket_identifier} ", 'subtracting', __FILE__, __LINE__); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + if ( |
|
| 400 | + isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 401 | + && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 402 | + ){ |
|
| 403 | + foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
| 404 | + if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 405 | + $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
| 406 | + if ($this->debug) { |
|
| 407 | + \EEH_Debug_Tools::printr("{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
| 408 | + 'subtracting', __FILE__, __LINE__); |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * @param string $datetime_identifier |
|
| 420 | + * @param array $tickets |
|
| 421 | + */ |
|
| 422 | + private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
| 423 | + { |
|
| 424 | + // make sure a reg limit is set for the datetime |
|
| 425 | + $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
| 426 | + ? $this->datetime_spaces[ $datetime_identifier ] |
|
| 427 | + : 0; |
|
| 428 | + // and bail if it is not |
|
| 429 | + if ( ! $reg_limit) { |
|
| 430 | + if ($this->debug) { |
|
| 431 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
| 432 | + } |
|
| 433 | + return; |
|
| 434 | + } |
|
| 435 | + if ($this->debug) { |
|
| 436 | + \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
| 437 | + \EEH_Debug_Tools::printr("{$reg_limit}", 'REG LIMIT', __FILE__, __LINE__); |
|
| 438 | + } |
|
| 439 | + // number of allocated spaces always starts at zero |
|
| 440 | + $spaces_allocated = 0; |
|
| 441 | + $this->total_spaces[ $datetime_identifier ] = 0; |
|
| 442 | + foreach ($tickets as $ticket_identifier) { |
|
| 443 | + $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
| 444 | + $datetime_identifier, |
|
| 445 | + $reg_limit, |
|
| 446 | + $ticket_identifier, |
|
| 447 | + $spaces_allocated |
|
| 448 | + ); |
|
| 449 | + } |
|
| 450 | + // spaces can't be negative |
|
| 451 | + $spaces_allocated = max($spaces_allocated, 0); |
|
| 452 | + if ($spaces_allocated) { |
|
| 453 | + // track any non-zero values |
|
| 454 | + $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
| 455 | + if ($this->debug) { |
|
| 456 | + \EEH_Debug_Tools::printr((string)$spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
| 457 | + } |
|
| 458 | + } else { |
|
| 459 | + if ($this->debug) { |
|
| 460 | + \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + if ($this->debug) { |
|
| 464 | + \EEH_Debug_Tools::printr($this->total_spaces[ $datetime_identifier ], '$total_spaces', __FILE__, |
|
| 465 | + __LINE__); |
|
| 466 | + \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
| 467 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * @param string $datetime_identifier |
|
| 475 | + * @param int $reg_limit |
|
| 476 | + * @param string $ticket_identifier |
|
| 477 | + * @param int $spaces_allocated |
|
| 478 | + * @return int |
|
| 479 | + */ |
|
| 480 | + private function calculateAvailableSpacesForTicket( |
|
| 481 | + $datetime_identifier, |
|
| 482 | + $reg_limit, |
|
| 483 | + $ticket_identifier, |
|
| 484 | + $spaces_allocated |
|
| 485 | + ) { |
|
| 486 | + // make sure ticket quantity is set |
|
| 487 | + $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
| 488 | + ? $this->ticket_quantities[ $ticket_identifier ] |
|
| 489 | + : 0; |
|
| 490 | + if ($this->debug) { |
|
| 491 | + \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
| 492 | + \EEH_Debug_Tools::printr("{$ticket_quantity}", "ticket $ticket_identifier quantity: ", |
|
| 493 | + __FILE__, __LINE__, 2); |
|
| 494 | + } |
|
| 495 | + if ($ticket_quantity) { |
|
| 496 | + if ($this->debug) { |
|
| 497 | + \EEH_Debug_Tools::printr( |
|
| 498 | + ($spaces_allocated <= $reg_limit) |
|
| 499 | + ? 'true' |
|
| 500 | + : 'false', |
|
| 501 | + ' . spaces_allocated <= reg_limit = ', |
|
| 502 | + __FILE__, __LINE__ |
|
| 503 | + ); |
|
| 504 | + } |
|
| 505 | + // if the datetime is NOT at full capacity yet |
|
| 506 | + if ($spaces_allocated <= $reg_limit) { |
|
| 507 | + // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
| 508 | + // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
| 509 | + // or the maximum ticket quantity |
|
| 510 | + $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
| 511 | + // adjust the available quantity in our tracking array |
|
| 512 | + $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
| 513 | + // and increment spaces allocated for this datetime |
|
| 514 | + $spaces_allocated += $ticket_quantity; |
|
| 515 | + $at_capacity = $spaces_allocated >= $reg_limit; |
|
| 516 | + if ($this->debug) { |
|
| 517 | + \EEH_Debug_Tools::printr("{$ticket_quantity} {$ticket_identifier} tickets", ' > > allocate ', |
|
| 518 | + __FILE__, __LINE__, 3); |
|
| 519 | + if ($at_capacity) { |
|
| 520 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + // now adjust all other datetimes that allow access to this ticket |
|
| 524 | + $this->adjustDatetimes( |
|
| 525 | + $datetime_identifier, |
|
| 526 | + $ticket_identifier, |
|
| 527 | + $ticket_quantity, |
|
| 528 | + $at_capacity |
|
| 529 | + ); |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + return $spaces_allocated; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * subtracts ticket amounts from all datetime reg limits |
|
| 539 | + * that allow access to the ticket specified, |
|
| 540 | + * because that ticket could be used |
|
| 541 | + * to attend any of the datetimes it has access to |
|
| 542 | + * |
|
| 543 | + * @param string $datetime_identifier |
|
| 544 | + * @param string $ticket_identifier |
|
| 545 | + * @param bool $at_capacity |
|
| 546 | + * @param int $ticket_quantity |
|
| 547 | + */ |
|
| 548 | + private function adjustDatetimes( |
|
| 549 | + $datetime_identifier, |
|
| 550 | + $ticket_identifier, |
|
| 551 | + $ticket_quantity, |
|
| 552 | + $at_capacity |
|
| 553 | + ) { |
|
| 554 | + foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
| 555 | + if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
| 556 | + continue; |
|
| 557 | + } |
|
| 558 | + $adjusted = $this->adjustDatetimeSpaces( |
|
| 559 | + $datetime_ID, |
|
| 560 | + $ticket_identifier, |
|
| 561 | + $ticket_quantity |
|
| 562 | + ); |
|
| 563 | + // skip to next ticket if nothing changed |
|
| 564 | + if (! ($adjusted || $at_capacity)) { |
|
| 565 | + continue; |
|
| 566 | + } |
|
| 567 | + // then all of it's tickets are now unavailable |
|
| 568 | + foreach ($datetime_tickets as $datetime_ticket) { |
|
| 569 | + if ( |
|
| 570 | + ($ticket_identifier === $datetime_ticket || $at_capacity) |
|
| 571 | + && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
| 572 | + && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
| 573 | + ) { |
|
| 574 | + if ($this->debug) { |
|
| 575 | + \EEH_Debug_Tools::printr($datetime_ticket, ' . . . adjust ticket quantities for', __FILE__, |
|
| 576 | + __LINE__); |
|
| 577 | + } |
|
| 578 | + // if this datetime is at full capacity, set any tracked available quantities to zero |
|
| 579 | + // otherwise just subtract the ticket quantity |
|
| 580 | + $new_quantity = $at_capacity |
|
| 581 | + ? 0 |
|
| 582 | + : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
| 583 | + // don't let ticket quantity go below zero |
|
| 584 | + $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
| 585 | + if ($this->debug) { |
|
| 586 | + \EEH_Debug_Tools::printr( |
|
| 587 | + $at_capacity |
|
| 588 | + ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
| 589 | + : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
| 590 | + " . . . . {$datetime_ticket} quantity set to ", |
|
| 591 | + __FILE__, __LINE__ |
|
| 592 | + ); |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
| 596 | + if ($datetime_ticket === $ticket_identifier) { |
|
| 597 | + if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 598 | + && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 599 | + ) { |
|
| 600 | + if ($this->debug) { |
|
| 601 | + \EEH_Debug_Tools::printr($datetime_ticket, ' . . adjust other Datetimes for', __FILE__, |
|
| 602 | + __LINE__); |
|
| 603 | + } |
|
| 604 | + foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
| 605 | + // don't adjust the current datetime twice |
|
| 606 | + if ($datetime !== $datetime_identifier) { |
|
| 607 | + $this->adjustDatetimeSpaces( |
|
| 608 | + $datetime, |
|
| 609 | + $datetime_ticket, |
|
| 610 | + $ticket_quantity |
|
| 611 | + ); |
|
| 612 | + } |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
| 621 | + { |
|
| 622 | + // does datetime have spaces available? |
|
| 623 | + // and does the supplied ticket have access to this datetime ? |
|
| 624 | + if ( |
|
| 625 | + $this->datetime_spaces[ $datetime_identifier ] > 0 |
|
| 626 | + && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
| 627 | + && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
| 628 | + ) { |
|
| 629 | + if ($this->debug) { |
|
| 630 | + \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
| 631 | + \EEH_Debug_Tools::printr("{$this->datetime_spaces[ $datetime_identifier ]}", " . . current {$datetime_identifier} spaces available", __FILE__, __LINE__); |
|
| 632 | + } |
|
| 633 | + // then decrement the available spaces for the datetime |
|
| 634 | + $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
| 635 | + // but don't let quantities go below zero |
|
| 636 | + $this->datetime_spaces[ $datetime_identifier ] = max( |
|
| 637 | + $this->datetime_spaces[ $datetime_identifier ], |
|
| 638 | + 0 |
|
| 639 | + ); |
|
| 640 | + if ($this->debug) { |
|
| 641 | + \EEH_Debug_Tools::printr("{$ticket_quantity}", |
|
| 642 | + " . . . {$datetime_identifier} capacity reduced by", __FILE__, __LINE__); |
|
| 643 | + } |
|
| 644 | + return true; |
|
| 645 | + } |
|
| 646 | + return false; |
|
| 647 | + } |
|
| 648 | 648 | |
| 649 | 649 | } |
| 650 | 650 | // Location: EventSpacesCalculator.php |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | // sort incoming array by ticket quantity (asc) |
| 156 | 156 | usort( |
| 157 | 157 | $active_tickets, |
| 158 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 158 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
| 159 | 159 | if ($a->qty() === $b->qty()) { |
| 160 | 160 | return 0; |
| 161 | 161 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | ) |
| 232 | 232 | ); |
| 233 | 233 | } |
| 234 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
| 234 | + $this->datetimes[$datetime->ID()] = $datetime; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -322,16 +322,16 @@ discard block |
||
| 322 | 322 | // we are going to move all of our data into the following arrays: |
| 323 | 323 | // datetime spaces initially represents the reg limit for each datetime, |
| 324 | 324 | // but this will get adjusted as tickets are accounted for |
| 325 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
| 325 | + $this->datetime_spaces[$datetime_identifier] = $reg_limit; |
|
| 326 | 326 | // just an array of ticket IDs grouped by datetime |
| 327 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
| 327 | + $this->datetime_tickets[$datetime_identifier][] = $ticket_identifier; |
|
| 328 | 328 | // and an array of datetime IDs grouped by ticket |
| 329 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
| 329 | + $this->ticket_datetimes[$ticket_identifier][] = $datetime_identifier; |
|
| 330 | 330 | } |
| 331 | 331 | // total quantity of sold and reserved for each ticket |
| 332 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
| 332 | + $this->tickets_sold[$ticket_identifier] = $ticket->sold() + $ticket->reserved(); |
|
| 333 | 333 | // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
| 334 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
| 334 | + $this->ticket_quantities[$ticket_identifier] = $max_tickets; |
|
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | // sort datetime spaces by reg limit, but maintain our string indexes |
@@ -390,19 +390,19 @@ discard block |
||
| 390 | 390 | \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
| 391 | 391 | } |
| 392 | 392 | foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
| 393 | - if (isset($this->ticket_quantities[ $ticket_identifier ])){ |
|
| 394 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
| 393 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
| 394 | + $this->ticket_quantities[$ticket_identifier] -= $tickets_sold; |
|
| 395 | 395 | if ($this->debug) { |
| 396 | 396 | \EEH_Debug_Tools::printr("{$tickets_sold} sales for ticket {$ticket_identifier} ", 'subtracting', __FILE__, __LINE__); |
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | if ( |
| 400 | - isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 401 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 402 | - ){ |
|
| 403 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
| 404 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 405 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
| 400 | + isset($this->ticket_datetimes[$ticket_identifier]) |
|
| 401 | + && is_array($this->ticket_datetimes[$ticket_identifier]) |
|
| 402 | + ) { |
|
| 403 | + foreach ($this->ticket_datetimes[$ticket_identifier] as $ticket_datetime) { |
|
| 404 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
| 405 | + $this->datetime_spaces[$ticket_datetime] -= $tickets_sold; |
|
| 406 | 406 | if ($this->debug) { |
| 407 | 407 | \EEH_Debug_Tools::printr("{$tickets_sold} sales for datetime {$ticket_datetime} ", |
| 408 | 408 | 'subtracting', __FILE__, __LINE__); |
@@ -422,8 +422,8 @@ discard block |
||
| 422 | 422 | private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
| 423 | 423 | { |
| 424 | 424 | // make sure a reg limit is set for the datetime |
| 425 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
| 426 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
| 425 | + $reg_limit = isset($this->datetime_spaces[$datetime_identifier]) |
|
| 426 | + ? $this->datetime_spaces[$datetime_identifier] |
|
| 427 | 427 | : 0; |
| 428 | 428 | // and bail if it is not |
| 429 | 429 | if ( ! $reg_limit) { |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | } |
| 439 | 439 | // number of allocated spaces always starts at zero |
| 440 | 440 | $spaces_allocated = 0; |
| 441 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
| 441 | + $this->total_spaces[$datetime_identifier] = 0; |
|
| 442 | 442 | foreach ($tickets as $ticket_identifier) { |
| 443 | 443 | $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
| 444 | 444 | $datetime_identifier, |
@@ -451,9 +451,9 @@ discard block |
||
| 451 | 451 | $spaces_allocated = max($spaces_allocated, 0); |
| 452 | 452 | if ($spaces_allocated) { |
| 453 | 453 | // track any non-zero values |
| 454 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
| 454 | + $this->total_spaces[$datetime_identifier] += $spaces_allocated; |
|
| 455 | 455 | if ($this->debug) { |
| 456 | - \EEH_Debug_Tools::printr((string)$spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
| 456 | + \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
| 457 | 457 | } |
| 458 | 458 | } else { |
| 459 | 459 | if ($this->debug) { |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | if ($this->debug) { |
| 464 | - \EEH_Debug_Tools::printr($this->total_spaces[ $datetime_identifier ], '$total_spaces', __FILE__, |
|
| 464 | + \EEH_Debug_Tools::printr($this->total_spaces[$datetime_identifier], '$total_spaces', __FILE__, |
|
| 465 | 465 | __LINE__); |
| 466 | 466 | \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
| 467 | 467 | \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
@@ -484,8 +484,8 @@ discard block |
||
| 484 | 484 | $spaces_allocated |
| 485 | 485 | ) { |
| 486 | 486 | // make sure ticket quantity is set |
| 487 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
| 488 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
| 487 | + $ticket_quantity = isset($this->ticket_quantities[$ticket_identifier]) |
|
| 488 | + ? $this->ticket_quantities[$ticket_identifier] |
|
| 489 | 489 | : 0; |
| 490 | 490 | if ($this->debug) { |
| 491 | 491 | \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
@@ -509,13 +509,13 @@ discard block |
||
| 509 | 509 | // or the maximum ticket quantity |
| 510 | 510 | $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
| 511 | 511 | // adjust the available quantity in our tracking array |
| 512 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
| 512 | + $this->ticket_quantities[$ticket_identifier] -= $ticket_quantity; |
|
| 513 | 513 | // and increment spaces allocated for this datetime |
| 514 | 514 | $spaces_allocated += $ticket_quantity; |
| 515 | 515 | $at_capacity = $spaces_allocated >= $reg_limit; |
| 516 | 516 | if ($this->debug) { |
| 517 | 517 | \EEH_Debug_Tools::printr("{$ticket_quantity} {$ticket_identifier} tickets", ' > > allocate ', |
| 518 | - __FILE__, __LINE__, 3); |
|
| 518 | + __FILE__, __LINE__, 3); |
|
| 519 | 519 | if ($at_capacity) { |
| 520 | 520 | \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
| 521 | 521 | } |
@@ -561,15 +561,15 @@ discard block |
||
| 561 | 561 | $ticket_quantity |
| 562 | 562 | ); |
| 563 | 563 | // skip to next ticket if nothing changed |
| 564 | - if (! ($adjusted || $at_capacity)) { |
|
| 564 | + if ( ! ($adjusted || $at_capacity)) { |
|
| 565 | 565 | continue; |
| 566 | 566 | } |
| 567 | 567 | // then all of it's tickets are now unavailable |
| 568 | 568 | foreach ($datetime_tickets as $datetime_ticket) { |
| 569 | 569 | if ( |
| 570 | 570 | ($ticket_identifier === $datetime_ticket || $at_capacity) |
| 571 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
| 572 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
| 571 | + && isset($this->ticket_quantities[$datetime_ticket]) |
|
| 572 | + && $this->ticket_quantities[$datetime_ticket] > 0 |
|
| 573 | 573 | ) { |
| 574 | 574 | if ($this->debug) { |
| 575 | 575 | \EEH_Debug_Tools::printr($datetime_ticket, ' . . . adjust ticket quantities for', __FILE__, |
@@ -579,14 +579,14 @@ discard block |
||
| 579 | 579 | // otherwise just subtract the ticket quantity |
| 580 | 580 | $new_quantity = $at_capacity |
| 581 | 581 | ? 0 |
| 582 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
| 582 | + : $this->ticket_quantities[$datetime_ticket] - $ticket_quantity; |
|
| 583 | 583 | // don't let ticket quantity go below zero |
| 584 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
| 584 | + $this->ticket_quantities[$datetime_ticket] = max($new_quantity, 0); |
|
| 585 | 585 | if ($this->debug) { |
| 586 | 586 | \EEH_Debug_Tools::printr( |
| 587 | 587 | $at_capacity |
| 588 | 588 | ? "0 because Datetime {$datetime_identifier} is at capacity" |
| 589 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
| 589 | + : "{$this->ticket_quantities[$datetime_ticket]}", |
|
| 590 | 590 | " . . . . {$datetime_ticket} quantity set to ", |
| 591 | 591 | __FILE__, __LINE__ |
| 592 | 592 | ); |
@@ -594,14 +594,14 @@ discard block |
||
| 594 | 594 | } |
| 595 | 595 | // but we also need to adjust spaces for any other datetimes this ticket has access to |
| 596 | 596 | if ($datetime_ticket === $ticket_identifier) { |
| 597 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 598 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 597 | + if (isset($this->ticket_datetimes[$datetime_ticket]) |
|
| 598 | + && is_array($this->ticket_datetimes[$datetime_ticket]) |
|
| 599 | 599 | ) { |
| 600 | 600 | if ($this->debug) { |
| 601 | 601 | \EEH_Debug_Tools::printr($datetime_ticket, ' . . adjust other Datetimes for', __FILE__, |
| 602 | 602 | __LINE__); |
| 603 | 603 | } |
| 604 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
| 604 | + foreach ($this->ticket_datetimes[$datetime_ticket] as $datetime) { |
|
| 605 | 605 | // don't adjust the current datetime twice |
| 606 | 606 | if ($datetime !== $datetime_identifier) { |
| 607 | 607 | $this->adjustDatetimeSpaces( |
@@ -622,19 +622,19 @@ discard block |
||
| 622 | 622 | // does datetime have spaces available? |
| 623 | 623 | // and does the supplied ticket have access to this datetime ? |
| 624 | 624 | if ( |
| 625 | - $this->datetime_spaces[ $datetime_identifier ] > 0 |
|
| 626 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
| 627 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
| 625 | + $this->datetime_spaces[$datetime_identifier] > 0 |
|
| 626 | + && isset($this->datetime_spaces[$datetime_identifier], $this->datetime_tickets[$datetime_identifier]) |
|
| 627 | + && in_array($ticket_identifier, $this->datetime_tickets[$datetime_identifier], true) |
|
| 628 | 628 | ) { |
| 629 | 629 | if ($this->debug) { |
| 630 | 630 | \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
| 631 | - \EEH_Debug_Tools::printr("{$this->datetime_spaces[ $datetime_identifier ]}", " . . current {$datetime_identifier} spaces available", __FILE__, __LINE__); |
|
| 631 | + \EEH_Debug_Tools::printr("{$this->datetime_spaces[$datetime_identifier]}", " . . current {$datetime_identifier} spaces available", __FILE__, __LINE__); |
|
| 632 | 632 | } |
| 633 | 633 | // then decrement the available spaces for the datetime |
| 634 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
| 634 | + $this->datetime_spaces[$datetime_identifier] -= $ticket_quantity; |
|
| 635 | 635 | // but don't let quantities go below zero |
| 636 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
| 637 | - $this->datetime_spaces[ $datetime_identifier ], |
|
| 636 | + $this->datetime_spaces[$datetime_identifier] = max( |
|
| 637 | + $this->datetime_spaces[$datetime_identifier], |
|
| 638 | 638 | 0 |
| 639 | 639 | ); |
| 640 | 640 | if ($this->debug) { |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
| 5 | 5 | |
| 6 | 6 | if (!defined('EVENT_ESPRESSO_VERSION')) { |
| 7 | - exit('No direct script access allowed'); |
|
| 7 | + exit('No direct script access allowed'); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | |
@@ -18,1289 +18,1289 @@ discard block |
||
| 18 | 18 | class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * cached value for the the logical active status for the event |
|
| 23 | - * |
|
| 24 | - * @see get_active_status() |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $_active_status = ''; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 31 | - * |
|
| 32 | - * @var EE_Datetime |
|
| 33 | - */ |
|
| 34 | - protected $_Primary_Datetime; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var EventSpacesCalculator $available_spaces_calculator |
|
| 38 | - */ |
|
| 39 | - protected $available_spaces_calculator; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param array $props_n_values incoming values |
|
| 44 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 45 | - * used.) |
|
| 46 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 47 | - * date_format and the second value is the time format |
|
| 48 | - * @return EE_Event |
|
| 49 | - * @throws EE_Error |
|
| 50 | - */ |
|
| 51 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 52 | - { |
|
| 53 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 54 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param array $props_n_values incoming values from the database |
|
| 60 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 61 | - * the website will be used. |
|
| 62 | - * @return EE_Event |
|
| 63 | - * @throws EE_Error |
|
| 64 | - */ |
|
| 65 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 66 | - { |
|
| 67 | - return new self($props_n_values, true, $timezone); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @return EventSpacesCalculator |
|
| 74 | - * @throws \EE_Error |
|
| 75 | - */ |
|
| 76 | - public function getAvailableSpacesCalculator() |
|
| 77 | - { |
|
| 78 | - if(! $this->available_spaces_calculator instanceof EventSpacesCalculator){ |
|
| 79 | - $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 80 | - } |
|
| 81 | - return $this->available_spaces_calculator; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 88 | - * |
|
| 89 | - * @param string $field_name |
|
| 90 | - * @param mixed $field_value |
|
| 91 | - * @param bool $use_default |
|
| 92 | - * @throws EE_Error |
|
| 93 | - */ |
|
| 94 | - public function set($field_name, $field_value, $use_default = false) |
|
| 95 | - { |
|
| 96 | - switch ($field_name) { |
|
| 97 | - case 'status' : |
|
| 98 | - $this->set_status($field_value, $use_default); |
|
| 99 | - break; |
|
| 100 | - default : |
|
| 101 | - parent::set($field_name, $field_value, $use_default); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * set_status |
|
| 108 | - * Checks if event status is being changed to SOLD OUT |
|
| 109 | - * and updates event meta data with previous event status |
|
| 110 | - * so that we can revert things if/when the event is no longer sold out |
|
| 111 | - * |
|
| 112 | - * @access public |
|
| 113 | - * @param string $new_status |
|
| 114 | - * @param bool $use_default |
|
| 115 | - * @return void |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function set_status($new_status = null, $use_default = false) |
|
| 119 | - { |
|
| 120 | - // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 121 | - if (empty($new_status) && !$use_default) { |
|
| 122 | - return; |
|
| 123 | - } |
|
| 124 | - // get current Event status |
|
| 125 | - $old_status = $this->status(); |
|
| 126 | - // if status has changed |
|
| 127 | - if ($old_status !== $new_status) { |
|
| 128 | - // TO sold_out |
|
| 129 | - if ($new_status === EEM_Event::sold_out) { |
|
| 130 | - // save the previous event status so that we can revert if the event is no longer sold out |
|
| 131 | - $this->add_post_meta('_previous_event_status', $old_status); |
|
| 132 | - do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 133 | - // OR FROM sold_out |
|
| 134 | - } else if ($old_status === EEM_Event::sold_out) { |
|
| 135 | - $this->delete_post_meta('_previous_event_status'); |
|
| 136 | - do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 137 | - } |
|
| 138 | - // update status |
|
| 139 | - parent::set('status', $new_status, $use_default); |
|
| 140 | - do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 141 | - return; |
|
| 142 | - } |
|
| 143 | - // even though the old value matches the new value, it's still good to |
|
| 144 | - // allow the parent set method to have a say |
|
| 145 | - parent::set('status', $new_status, $use_default); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Gets all the datetimes for this event |
|
| 151 | - * |
|
| 152 | - * @param array $query_params like EEM_Base::get_all |
|
| 153 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 154 | - * @throws EE_Error |
|
| 155 | - */ |
|
| 156 | - public function datetimes($query_params = array()) |
|
| 157 | - { |
|
| 158 | - return $this->get_many_related('Datetime', $query_params); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 164 | - * |
|
| 165 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 166 | - * @throws EE_Error |
|
| 167 | - */ |
|
| 168 | - public function datetimes_in_chronological_order() |
|
| 169 | - { |
|
| 170 | - return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 176 | - * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 177 | - * after running our query, so that this timezone isn't set for EVERY query |
|
| 178 | - * on EEM_Datetime for the rest of the request, no? |
|
| 179 | - * |
|
| 180 | - * @param boolean $show_expired whether or not to include expired events |
|
| 181 | - * @param boolean $show_deleted whether or not to include deleted events |
|
| 182 | - * @param null $limit |
|
| 183 | - * @return EE_Datetime[] |
|
| 184 | - * @throws EE_Error |
|
| 185 | - */ |
|
| 186 | - public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 187 | - { |
|
| 188 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 189 | - $this->ID(), |
|
| 190 | - $show_expired, |
|
| 191 | - $show_deleted, |
|
| 192 | - $limit |
|
| 193 | - ); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Returns one related datetime. Mostly only used by some legacy code. |
|
| 199 | - * |
|
| 200 | - * @return EE_Base_Class|EE_Datetime |
|
| 201 | - * @throws EE_Error |
|
| 202 | - */ |
|
| 203 | - public function first_datetime() |
|
| 204 | - { |
|
| 205 | - return $this->get_first_related('Datetime'); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Returns the 'primary' datetime for the event |
|
| 211 | - * |
|
| 212 | - * @param bool $try_to_exclude_expired |
|
| 213 | - * @param bool $try_to_exclude_deleted |
|
| 214 | - * @return EE_Datetime |
|
| 215 | - * @throws EE_Error |
|
| 216 | - */ |
|
| 217 | - public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 218 | - { |
|
| 219 | - if (!empty ($this->_Primary_Datetime)) { |
|
| 220 | - return $this->_Primary_Datetime; |
|
| 221 | - } |
|
| 222 | - $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 223 | - $this->ID(), |
|
| 224 | - $try_to_exclude_expired, |
|
| 225 | - $try_to_exclude_deleted |
|
| 226 | - ); |
|
| 227 | - return $this->_Primary_Datetime; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Gets all the tickets available for purchase of this event |
|
| 233 | - * |
|
| 234 | - * @param array $query_params like EEM_Base::get_all |
|
| 235 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 236 | - * @throws EE_Error |
|
| 237 | - */ |
|
| 238 | - public function tickets($query_params = array()) |
|
| 239 | - { |
|
| 240 | - //first get all datetimes |
|
| 241 | - $datetimes = $this->datetimes_ordered(); |
|
| 242 | - if (!$datetimes) { |
|
| 243 | - return array(); |
|
| 244 | - } |
|
| 245 | - $datetime_ids = array(); |
|
| 246 | - foreach ($datetimes as $datetime) { |
|
| 247 | - $datetime_ids[] = $datetime->ID(); |
|
| 248 | - } |
|
| 249 | - $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 250 | - //if incoming $query_params has where conditions let's merge but not override existing. |
|
| 251 | - if (is_array($query_params) && isset($query_params[0])) { |
|
| 252 | - $where_params = array_merge($query_params[0], $where_params); |
|
| 253 | - unset($query_params[0]); |
|
| 254 | - } |
|
| 255 | - //now add $where_params to $query_params |
|
| 256 | - $query_params[0] = $where_params; |
|
| 257 | - return EEM_Ticket::instance()->get_all($query_params); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * get all unexpired untrashed tickets |
|
| 263 | - * |
|
| 264 | - * @return EE_Ticket[] |
|
| 265 | - * @throws EE_Error |
|
| 266 | - */ |
|
| 267 | - public function active_tickets() |
|
| 268 | - { |
|
| 269 | - return $this->tickets(array( |
|
| 270 | - array( |
|
| 271 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 272 | - 'TKT_deleted' => false, |
|
| 273 | - ), |
|
| 274 | - )); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @return bool |
|
| 280 | - * @throws EE_Error |
|
| 281 | - */ |
|
| 282 | - public function additional_limit() |
|
| 283 | - { |
|
| 284 | - return $this->get('EVT_additional_limit'); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @return bool |
|
| 290 | - * @throws EE_Error |
|
| 291 | - */ |
|
| 292 | - public function allow_overflow() |
|
| 293 | - { |
|
| 294 | - return $this->get('EVT_allow_overflow'); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @return bool |
|
| 300 | - * @throws EE_Error |
|
| 301 | - */ |
|
| 302 | - public function created() |
|
| 303 | - { |
|
| 304 | - return $this->get('EVT_created'); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * @return bool |
|
| 310 | - * @throws EE_Error |
|
| 311 | - */ |
|
| 312 | - public function description() |
|
| 313 | - { |
|
| 314 | - return $this->get('EVT_desc'); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Runs do_shortcode and wpautop on the description |
|
| 320 | - * |
|
| 321 | - * @return string of html |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - public function description_filtered() |
|
| 325 | - { |
|
| 326 | - return $this->get_pretty('EVT_desc'); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * @return bool |
|
| 332 | - * @throws EE_Error |
|
| 333 | - */ |
|
| 334 | - public function display_description() |
|
| 335 | - { |
|
| 336 | - return $this->get('EVT_display_desc'); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * @return bool |
|
| 342 | - * @throws EE_Error |
|
| 343 | - */ |
|
| 344 | - public function display_ticket_selector() |
|
| 345 | - { |
|
| 346 | - return (bool)$this->get('EVT_display_ticket_selector'); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @return bool |
|
| 352 | - * @throws EE_Error |
|
| 353 | - */ |
|
| 354 | - public function external_url() |
|
| 355 | - { |
|
| 356 | - return $this->get('EVT_external_URL'); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @return bool |
|
| 362 | - * @throws EE_Error |
|
| 363 | - */ |
|
| 364 | - public function member_only() |
|
| 365 | - { |
|
| 366 | - return $this->get('EVT_member_only'); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * @return bool |
|
| 372 | - * @throws EE_Error |
|
| 373 | - */ |
|
| 374 | - public function phone() |
|
| 375 | - { |
|
| 376 | - return $this->get('EVT_phone'); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * @return bool |
|
| 382 | - * @throws EE_Error |
|
| 383 | - */ |
|
| 384 | - public function modified() |
|
| 385 | - { |
|
| 386 | - return $this->get('EVT_modified'); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * @return bool |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - public function name() |
|
| 395 | - { |
|
| 396 | - return $this->get('EVT_name'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * @return bool |
|
| 402 | - * @throws EE_Error |
|
| 403 | - */ |
|
| 404 | - public function order() |
|
| 405 | - { |
|
| 406 | - return $this->get('EVT_order'); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * @return bool|string |
|
| 412 | - * @throws EE_Error |
|
| 413 | - */ |
|
| 414 | - public function default_registration_status() |
|
| 415 | - { |
|
| 416 | - $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 417 | - return !empty($event_default_registration_status) |
|
| 418 | - ? $event_default_registration_status |
|
| 419 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * @param int $num_words |
|
| 425 | - * @param null $more |
|
| 426 | - * @param bool $not_full_desc |
|
| 427 | - * @return bool|string |
|
| 428 | - * @throws EE_Error |
|
| 429 | - */ |
|
| 430 | - public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 431 | - { |
|
| 432 | - $short_desc = $this->get('EVT_short_desc'); |
|
| 433 | - if (!empty($short_desc) || $not_full_desc) { |
|
| 434 | - return $short_desc; |
|
| 435 | - } |
|
| 436 | - $full_desc = $this->get('EVT_desc'); |
|
| 437 | - return wp_trim_words($full_desc, $num_words, $more); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * @return bool |
|
| 443 | - * @throws EE_Error |
|
| 444 | - */ |
|
| 445 | - public function slug() |
|
| 446 | - { |
|
| 447 | - return $this->get('EVT_slug'); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @return bool |
|
| 453 | - * @throws EE_Error |
|
| 454 | - */ |
|
| 455 | - public function timezone_string() |
|
| 456 | - { |
|
| 457 | - return $this->get('EVT_timezone_string'); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * @return bool |
|
| 463 | - * @throws EE_Error |
|
| 464 | - */ |
|
| 465 | - public function visible_on() |
|
| 466 | - { |
|
| 467 | - return $this->get('EVT_visible_on'); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @return int |
|
| 473 | - * @throws EE_Error |
|
| 474 | - */ |
|
| 475 | - public function wp_user() |
|
| 476 | - { |
|
| 477 | - return $this->get('EVT_wp_user'); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @return bool |
|
| 483 | - * @throws EE_Error |
|
| 484 | - */ |
|
| 485 | - public function donations() |
|
| 486 | - { |
|
| 487 | - return $this->get('EVT_donations'); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * @param $limit |
|
| 493 | - * @throws EE_Error |
|
| 494 | - */ |
|
| 495 | - public function set_additional_limit($limit) |
|
| 496 | - { |
|
| 497 | - $this->set('EVT_additional_limit', $limit); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @param $created |
|
| 503 | - * @throws EE_Error |
|
| 504 | - */ |
|
| 505 | - public function set_created($created) |
|
| 506 | - { |
|
| 507 | - $this->set('EVT_created', $created); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * @param $desc |
|
| 513 | - * @throws EE_Error |
|
| 514 | - */ |
|
| 515 | - public function set_description($desc) |
|
| 516 | - { |
|
| 517 | - $this->set('EVT_desc', $desc); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * @param $display_desc |
|
| 523 | - * @throws EE_Error |
|
| 524 | - */ |
|
| 525 | - public function set_display_description($display_desc) |
|
| 526 | - { |
|
| 527 | - $this->set('EVT_display_desc', $display_desc); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * @param $display_ticket_selector |
|
| 533 | - * @throws EE_Error |
|
| 534 | - */ |
|
| 535 | - public function set_display_ticket_selector($display_ticket_selector) |
|
| 536 | - { |
|
| 537 | - $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * @param $external_url |
|
| 543 | - * @throws EE_Error |
|
| 544 | - */ |
|
| 545 | - public function set_external_url($external_url) |
|
| 546 | - { |
|
| 547 | - $this->set('EVT_external_URL', $external_url); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * @param $member_only |
|
| 553 | - * @throws EE_Error |
|
| 554 | - */ |
|
| 555 | - public function set_member_only($member_only) |
|
| 556 | - { |
|
| 557 | - $this->set('EVT_member_only', $member_only); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * @param $event_phone |
|
| 563 | - * @throws EE_Error |
|
| 564 | - */ |
|
| 565 | - public function set_event_phone($event_phone) |
|
| 566 | - { |
|
| 567 | - $this->set('EVT_phone', $event_phone); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * @param $modified |
|
| 573 | - * @throws EE_Error |
|
| 574 | - */ |
|
| 575 | - public function set_modified($modified) |
|
| 576 | - { |
|
| 577 | - $this->set('EVT_modified', $modified); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * @param $name |
|
| 583 | - * @throws EE_Error |
|
| 584 | - */ |
|
| 585 | - public function set_name($name) |
|
| 586 | - { |
|
| 587 | - $this->set('EVT_name', $name); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * @param $order |
|
| 593 | - * @throws EE_Error |
|
| 594 | - */ |
|
| 595 | - public function set_order($order) |
|
| 596 | - { |
|
| 597 | - $this->set('EVT_order', $order); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * @param $short_desc |
|
| 603 | - * @throws EE_Error |
|
| 604 | - */ |
|
| 605 | - public function set_short_description($short_desc) |
|
| 606 | - { |
|
| 607 | - $this->set('EVT_short_desc', $short_desc); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * @param $slug |
|
| 613 | - * @throws EE_Error |
|
| 614 | - */ |
|
| 615 | - public function set_slug($slug) |
|
| 616 | - { |
|
| 617 | - $this->set('EVT_slug', $slug); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @param $timezone_string |
|
| 623 | - * @throws EE_Error |
|
| 624 | - */ |
|
| 625 | - public function set_timezone_string($timezone_string) |
|
| 626 | - { |
|
| 627 | - $this->set('EVT_timezone_string', $timezone_string); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * @param $visible_on |
|
| 633 | - * @throws EE_Error |
|
| 634 | - */ |
|
| 635 | - public function set_visible_on($visible_on) |
|
| 636 | - { |
|
| 637 | - $this->set('EVT_visible_on', $visible_on); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * @param $wp_user |
|
| 643 | - * @throws EE_Error |
|
| 644 | - */ |
|
| 645 | - public function set_wp_user($wp_user) |
|
| 646 | - { |
|
| 647 | - $this->set('EVT_wp_user', $wp_user); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * @param $default_registration_status |
|
| 653 | - * @throws EE_Error |
|
| 654 | - */ |
|
| 655 | - public function set_default_registration_status($default_registration_status) |
|
| 656 | - { |
|
| 657 | - $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @param $donations |
|
| 663 | - * @throws EE_Error |
|
| 664 | - */ |
|
| 665 | - public function set_donations($donations) |
|
| 666 | - { |
|
| 667 | - $this->set('EVT_donations', $donations); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Adds a venue to this event |
|
| 673 | - * |
|
| 674 | - * @param EE_Venue /int $venue_id_or_obj |
|
| 675 | - * @return EE_Base_Class|EE_Venue |
|
| 676 | - * @throws EE_Error |
|
| 677 | - */ |
|
| 678 | - public function add_venue($venue_id_or_obj) |
|
| 679 | - { |
|
| 680 | - return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * Removes a venue from the event |
|
| 686 | - * |
|
| 687 | - * @param EE_Venue /int $venue_id_or_obj |
|
| 688 | - * @return EE_Base_Class|EE_Venue |
|
| 689 | - * @throws EE_Error |
|
| 690 | - */ |
|
| 691 | - public function remove_venue($venue_id_or_obj) |
|
| 692 | - { |
|
| 693 | - return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
| 699 | - * |
|
| 700 | - * @param array $query_params like EEM_Base::get_all's $query_params |
|
| 701 | - * @return EE_Base_Class[]|EE_Venue[] |
|
| 702 | - * @throws EE_Error |
|
| 703 | - */ |
|
| 704 | - public function venues($query_params = array()) |
|
| 705 | - { |
|
| 706 | - return $this->get_many_related('Venue', $query_params); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * check if event id is present and if event is published |
|
| 712 | - * |
|
| 713 | - * @access public |
|
| 714 | - * @return boolean true yes, false no |
|
| 715 | - * @throws EE_Error |
|
| 716 | - */ |
|
| 717 | - private function _has_ID_and_is_published() |
|
| 718 | - { |
|
| 719 | - // first check if event id is present and not NULL, |
|
| 720 | - // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 721 | - return |
|
| 722 | - $this->ID() && $this->ID() !== null |
|
| 723 | - && ( |
|
| 724 | - $this->status() === 'publish' |
|
| 725 | - || $this->status() === EEM_Event::sold_out |
|
| 726 | - || $this->status() === EEM_Event::postponed |
|
| 727 | - || $this->status() === EEM_Event::cancelled |
|
| 728 | - ); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 734 | - * |
|
| 735 | - * @access public |
|
| 736 | - * @return boolean true yes, false no |
|
| 737 | - * @throws EE_Error |
|
| 738 | - */ |
|
| 739 | - public function is_upcoming() |
|
| 740 | - { |
|
| 741 | - // check if event id is present and if this event is published |
|
| 742 | - if ($this->is_inactive()) { |
|
| 743 | - return false; |
|
| 744 | - } |
|
| 745 | - // set initial value |
|
| 746 | - $upcoming = false; |
|
| 747 | - //next let's get all datetimes and loop through them |
|
| 748 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 749 | - foreach ($datetimes as $datetime) { |
|
| 750 | - if ($datetime instanceof EE_Datetime) { |
|
| 751 | - //if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 752 | - if ($datetime->is_expired()) { |
|
| 753 | - continue; |
|
| 754 | - } |
|
| 755 | - //if this dtt is active then we return false. |
|
| 756 | - if ($datetime->is_active()) { |
|
| 757 | - return false; |
|
| 758 | - } |
|
| 759 | - //otherwise let's check upcoming status |
|
| 760 | - $upcoming = $datetime->is_upcoming(); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - return $upcoming; |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - |
|
| 767 | - /** |
|
| 768 | - * @return bool |
|
| 769 | - * @throws EE_Error |
|
| 770 | - */ |
|
| 771 | - public function is_active() |
|
| 772 | - { |
|
| 773 | - // check if event id is present and if this event is published |
|
| 774 | - if ($this->is_inactive()) { |
|
| 775 | - return false; |
|
| 776 | - } |
|
| 777 | - // set initial value |
|
| 778 | - $active = false; |
|
| 779 | - //next let's get all datetimes and loop through them |
|
| 780 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 781 | - foreach ($datetimes as $datetime) { |
|
| 782 | - if ($datetime instanceof EE_Datetime) { |
|
| 783 | - //if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 784 | - if ($datetime->is_expired()) { |
|
| 785 | - continue; |
|
| 786 | - } |
|
| 787 | - //if this dtt is upcoming then we return false. |
|
| 788 | - if ($datetime->is_upcoming()) { |
|
| 789 | - return false; |
|
| 790 | - } |
|
| 791 | - //otherwise let's check active status |
|
| 792 | - $active = $datetime->is_active(); |
|
| 793 | - } |
|
| 794 | - } |
|
| 795 | - return $active; |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * @return bool |
|
| 801 | - * @throws EE_Error |
|
| 802 | - */ |
|
| 803 | - public function is_expired() |
|
| 804 | - { |
|
| 805 | - // check if event id is present and if this event is published |
|
| 806 | - if ($this->is_inactive()) { |
|
| 807 | - return false; |
|
| 808 | - } |
|
| 809 | - // set initial value |
|
| 810 | - $expired = false; |
|
| 811 | - //first let's get all datetimes and loop through them |
|
| 812 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 813 | - foreach ($datetimes as $datetime) { |
|
| 814 | - if ($datetime instanceof EE_Datetime) { |
|
| 815 | - //if this dtt is upcoming or active then we return false. |
|
| 816 | - if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 817 | - return false; |
|
| 818 | - } |
|
| 819 | - //otherwise let's check active status |
|
| 820 | - $expired = $datetime->is_expired(); |
|
| 821 | - } |
|
| 822 | - } |
|
| 823 | - return $expired; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * @return bool |
|
| 829 | - * @throws EE_Error |
|
| 830 | - */ |
|
| 831 | - public function is_inactive() |
|
| 832 | - { |
|
| 833 | - // check if event id is present and if this event is published |
|
| 834 | - if ($this->_has_ID_and_is_published()) { |
|
| 835 | - return false; |
|
| 836 | - } |
|
| 837 | - return true; |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - |
|
| 841 | - /** |
|
| 842 | - * calculate spaces remaining based on "saleable" tickets |
|
| 843 | - * |
|
| 844 | - * @param array $tickets |
|
| 845 | - * @param bool $filtered |
|
| 846 | - * @return int|float |
|
| 847 | - * @throws EE_Error |
|
| 848 | - * @throws DomainException |
|
| 849 | - * @throws UnexpectedEntityException |
|
| 850 | - */ |
|
| 851 | - public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 852 | - { |
|
| 853 | - $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 854 | - $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 855 | - return $filtered |
|
| 856 | - ? apply_filters( |
|
| 857 | - 'FHEE_EE_Event__spaces_remaining', |
|
| 858 | - $spaces_remaining, |
|
| 859 | - $this, |
|
| 860 | - $tickets |
|
| 861 | - ) |
|
| 862 | - : $spaces_remaining; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * perform_sold_out_status_check |
|
| 868 | - * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces available... |
|
| 869 | - * if NOT, then the event status will get toggled to 'sold_out' |
|
| 870 | - * |
|
| 871 | - * @return bool return the ACTUAL sold out state. |
|
| 872 | - * @throws EE_Error |
|
| 873 | - * @throws DomainException |
|
| 874 | - * @throws UnexpectedEntityException |
|
| 875 | - */ |
|
| 876 | - public function perform_sold_out_status_check() |
|
| 877 | - { |
|
| 878 | - // get all unexpired untrashed tickets |
|
| 879 | - $tickets = $this->active_tickets(); |
|
| 880 | - // if all the tickets are just expired, then don't update the event status to sold out |
|
| 881 | - if (empty($tickets)) { |
|
| 882 | - return true; |
|
| 883 | - } |
|
| 884 | - $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 885 | - if ($spaces_remaining < 1) { |
|
| 886 | - $this->set_status(EEM_Event::sold_out); |
|
| 887 | - $this->save(); |
|
| 888 | - $sold_out = true; |
|
| 889 | - } else { |
|
| 890 | - $sold_out = false; |
|
| 891 | - // was event previously marked as sold out ? |
|
| 892 | - if ($this->status() === EEM_Event::sold_out) { |
|
| 893 | - // revert status to previous value, if it was set |
|
| 894 | - $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 895 | - if ($previous_event_status) { |
|
| 896 | - $this->set_status($previous_event_status); |
|
| 897 | - $this->save(); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - } |
|
| 901 | - do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 902 | - return $sold_out; |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * This returns the total remaining spaces for sale on this event. |
|
| 909 | - * |
|
| 910 | - * @uses EE_Event::total_available_spaces() |
|
| 911 | - * @return float|int |
|
| 912 | - * @throws EE_Error |
|
| 913 | - * @throws DomainException |
|
| 914 | - * @throws UnexpectedEntityException |
|
| 915 | - */ |
|
| 916 | - public function spaces_remaining_for_sale() |
|
| 917 | - { |
|
| 918 | - return $this->total_available_spaces(true); |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * This returns the total spaces available for an event |
|
| 925 | - * while considering all the qtys on the tickets and the reg limits |
|
| 926 | - * on the datetimes attached to this event. |
|
| 927 | - * |
|
| 928 | - * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 929 | - * If this is false, then we return the most tickets that could ever be sold |
|
| 930 | - * for this event with the datetime and tickets setup on the event under optimal |
|
| 931 | - * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 932 | - * based on tickets sold. Depending on setup and stage of sales, this |
|
| 933 | - * may appear to equal remaining tickets. However, the more tickets are |
|
| 934 | - * sold out, the more accurate the "live" total is. |
|
| 935 | - * @return float|int |
|
| 936 | - * @throws EE_Error |
|
| 937 | - * @throws DomainException |
|
| 938 | - * @throws UnexpectedEntityException |
|
| 939 | - */ |
|
| 940 | - public function total_available_spaces($consider_sold = false) |
|
| 941 | - { |
|
| 942 | - $spaces_available = $consider_sold |
|
| 943 | - ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 944 | - : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 945 | - return apply_filters( |
|
| 946 | - 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 947 | - $spaces_available, |
|
| 948 | - $this, |
|
| 949 | - $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 950 | - $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 951 | - ); |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - |
|
| 955 | - /** |
|
| 956 | - * Checks if the event is set to sold out |
|
| 957 | - * |
|
| 958 | - * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 959 | - * actual status but also to flip the status if necessary to sold |
|
| 960 | - * out If false, we just check the existing status of the event |
|
| 961 | - * @return boolean |
|
| 962 | - * @throws EE_Error |
|
| 963 | - */ |
|
| 964 | - public function is_sold_out($actual = false) |
|
| 965 | - { |
|
| 966 | - if (!$actual) { |
|
| 967 | - return $this->status() === EEM_Event::sold_out; |
|
| 968 | - } |
|
| 969 | - return $this->perform_sold_out_status_check(); |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - /** |
|
| 974 | - * Checks if the event is marked as postponed |
|
| 975 | - * |
|
| 976 | - * @return boolean |
|
| 977 | - */ |
|
| 978 | - public function is_postponed() |
|
| 979 | - { |
|
| 980 | - return $this->status() === EEM_Event::postponed; |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - |
|
| 984 | - /** |
|
| 985 | - * Checks if the event is marked as cancelled |
|
| 986 | - * |
|
| 987 | - * @return boolean |
|
| 988 | - */ |
|
| 989 | - public function is_cancelled() |
|
| 990 | - { |
|
| 991 | - return $this->status() === EEM_Event::cancelled; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - |
|
| 995 | - /** |
|
| 996 | - * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 997 | - * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 998 | - * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 999 | - * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1000 | - * the event is considered expired. |
|
| 1001 | - * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a status |
|
| 1002 | - * set on the EVENT when it is not published and thus is done |
|
| 1003 | - * |
|
| 1004 | - * @param bool $reset |
|
| 1005 | - * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1006 | - * @throws EE_Error |
|
| 1007 | - */ |
|
| 1008 | - public function get_active_status($reset = false) |
|
| 1009 | - { |
|
| 1010 | - // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1011 | - if (!empty($this->_active_status) && !$reset) { |
|
| 1012 | - return $this->_active_status; |
|
| 1013 | - } |
|
| 1014 | - //first check if event id is present on this object |
|
| 1015 | - if (!$this->ID()) { |
|
| 1016 | - return false; |
|
| 1017 | - } |
|
| 1018 | - $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1019 | - //if event is published: |
|
| 1020 | - if ($this->status() === 'publish') { |
|
| 1021 | - //active? |
|
| 1022 | - if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event) > 0) { |
|
| 1023 | - $this->_active_status = EE_Datetime::active; |
|
| 1024 | - } else { |
|
| 1025 | - //upcoming? |
|
| 1026 | - if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0) { |
|
| 1027 | - $this->_active_status = EE_Datetime::upcoming; |
|
| 1028 | - } else { |
|
| 1029 | - //expired? |
|
| 1030 | - if ( |
|
| 1031 | - EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0 |
|
| 1032 | - ) { |
|
| 1033 | - $this->_active_status = EE_Datetime::expired; |
|
| 1034 | - } else { |
|
| 1035 | - //it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1036 | - //attached to the event. So in this case it will just be considered inactive. |
|
| 1037 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1038 | - } |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - } else { |
|
| 1042 | - //the event is not published, so let's just set it's active status according to its' post status |
|
| 1043 | - switch ($this->status()) { |
|
| 1044 | - case EEM_Event::sold_out : |
|
| 1045 | - $this->_active_status = EE_Datetime::sold_out; |
|
| 1046 | - break; |
|
| 1047 | - case EEM_Event::cancelled : |
|
| 1048 | - $this->_active_status = EE_Datetime::cancelled; |
|
| 1049 | - break; |
|
| 1050 | - case EEM_Event::postponed : |
|
| 1051 | - $this->_active_status = EE_Datetime::postponed; |
|
| 1052 | - break; |
|
| 1053 | - default : |
|
| 1054 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1055 | - } |
|
| 1056 | - } |
|
| 1057 | - return $this->_active_status; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - /** |
|
| 1062 | - * pretty_active_status |
|
| 1063 | - * |
|
| 1064 | - * @access public |
|
| 1065 | - * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1066 | - * @return mixed void|string |
|
| 1067 | - * @throws EE_Error |
|
| 1068 | - */ |
|
| 1069 | - public function pretty_active_status($echo = true) |
|
| 1070 | - { |
|
| 1071 | - $active_status = $this->get_active_status(); |
|
| 1072 | - $status = '<span class="ee-status event-active-status-' |
|
| 1073 | - . $active_status |
|
| 1074 | - . '">' |
|
| 1075 | - . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1076 | - . '</span>'; |
|
| 1077 | - if ($echo) { |
|
| 1078 | - echo $status; |
|
| 1079 | - return ''; |
|
| 1080 | - } |
|
| 1081 | - return $status; |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * @return bool|int |
|
| 1087 | - * @throws EE_Error |
|
| 1088 | - */ |
|
| 1089 | - public function get_number_of_tickets_sold() |
|
| 1090 | - { |
|
| 1091 | - $tkt_sold = 0; |
|
| 1092 | - if (!$this->ID()) { |
|
| 1093 | - return 0; |
|
| 1094 | - } |
|
| 1095 | - $datetimes = $this->datetimes(); |
|
| 1096 | - foreach ($datetimes as $datetime) { |
|
| 1097 | - if ($datetime instanceof EE_Datetime) { |
|
| 1098 | - $tkt_sold += $datetime->sold(); |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - return $tkt_sold; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * This just returns a count of all the registrations for this event |
|
| 1107 | - * |
|
| 1108 | - * @access public |
|
| 1109 | - * @return int |
|
| 1110 | - * @throws EE_Error |
|
| 1111 | - */ |
|
| 1112 | - public function get_count_of_all_registrations() |
|
| 1113 | - { |
|
| 1114 | - return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * This returns the ticket with the earliest start time that is |
|
| 1120 | - * available for this event (across all datetimes attached to the event) |
|
| 1121 | - * |
|
| 1122 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1123 | - * @throws EE_Error |
|
| 1124 | - */ |
|
| 1125 | - public function get_ticket_with_earliest_start_time() |
|
| 1126 | - { |
|
| 1127 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1128 | - $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1129 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * This returns the ticket with the latest end time that is available |
|
| 1135 | - * for this event (across all datetimes attached to the event) |
|
| 1136 | - * |
|
| 1137 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1138 | - * @throws EE_Error |
|
| 1139 | - */ |
|
| 1140 | - public function get_ticket_with_latest_end_time() |
|
| 1141 | - { |
|
| 1142 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1143 | - $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1144 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - |
|
| 1148 | - /** |
|
| 1149 | - * This returns whether there are any tickets on sale for this event. |
|
| 1150 | - * |
|
| 1151 | - * @return bool true = YES tickets on sale. |
|
| 1152 | - * @throws EE_Error |
|
| 1153 | - */ |
|
| 1154 | - public function tickets_on_sale() |
|
| 1155 | - { |
|
| 1156 | - $earliest_ticket = $this->get_ticket_with_earliest_start_time(); |
|
| 1157 | - $latest_ticket = $this->get_ticket_with_latest_end_time(); |
|
| 1158 | - if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) { |
|
| 1159 | - return false; |
|
| 1160 | - } |
|
| 1161 | - //check on sale for these two tickets. |
|
| 1162 | - if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) { |
|
| 1163 | - return true; |
|
| 1164 | - } |
|
| 1165 | - return false; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - |
|
| 1169 | - /** |
|
| 1170 | - * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1171 | - * to check for an external URL first |
|
| 1172 | - * |
|
| 1173 | - * @return string |
|
| 1174 | - * @throws EE_Error |
|
| 1175 | - */ |
|
| 1176 | - public function get_permalink() |
|
| 1177 | - { |
|
| 1178 | - if ($this->external_url()) { |
|
| 1179 | - return $this->external_url(); |
|
| 1180 | - } |
|
| 1181 | - return parent::get_permalink(); |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * Gets the first term for 'espresso_event_categories' we can find |
|
| 1187 | - * |
|
| 1188 | - * @param array $query_params like EEM_Base::get_all |
|
| 1189 | - * @return EE_Base_Class|EE_Term|null |
|
| 1190 | - * @throws EE_Error |
|
| 1191 | - */ |
|
| 1192 | - public function first_event_category($query_params = array()) |
|
| 1193 | - { |
|
| 1194 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1195 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1196 | - return EEM_Term::instance()->get_one($query_params); |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - |
|
| 1200 | - /** |
|
| 1201 | - * Gets all terms for 'espresso_event_categories' we can find |
|
| 1202 | - * |
|
| 1203 | - * @param array $query_params |
|
| 1204 | - * @return EE_Base_Class[]|EE_Term[] |
|
| 1205 | - * @throws EE_Error |
|
| 1206 | - */ |
|
| 1207 | - public function get_all_event_categories($query_params = array()) |
|
| 1208 | - { |
|
| 1209 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1210 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1211 | - return EEM_Term::instance()->get_all($query_params); |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - |
|
| 1215 | - /** |
|
| 1216 | - * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1217 | - * |
|
| 1218 | - * @param array $query_params @see EEM_Base::get_all |
|
| 1219 | - * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1220 | - * @throws EE_Error |
|
| 1221 | - */ |
|
| 1222 | - public function question_groups($query_params = array()) |
|
| 1223 | - { |
|
| 1224 | - $query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1225 | - return $this->get_many_related('Question_Group', $query_params); |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * Implementation for EEI_Has_Icon interface method. |
|
| 1231 | - * |
|
| 1232 | - * @see EEI_Visual_Representation for comments |
|
| 1233 | - * @return string |
|
| 1234 | - */ |
|
| 1235 | - public function get_icon() |
|
| 1236 | - { |
|
| 1237 | - return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - |
|
| 1241 | - /** |
|
| 1242 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1243 | - * |
|
| 1244 | - * @see EEI_Admin_Links for comments |
|
| 1245 | - * @return string |
|
| 1246 | - * @throws EE_Error |
|
| 1247 | - */ |
|
| 1248 | - public function get_admin_details_link() |
|
| 1249 | - { |
|
| 1250 | - return $this->get_admin_edit_link(); |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1256 | - * |
|
| 1257 | - * @see EEI_Admin_Links for comments |
|
| 1258 | - * @return string |
|
| 1259 | - * @throws EE_Error |
|
| 1260 | - */ |
|
| 1261 | - public function get_admin_edit_link() |
|
| 1262 | - { |
|
| 1263 | - return EEH_URL::add_query_args_and_nonce(array( |
|
| 1264 | - 'page' => 'espresso_events', |
|
| 1265 | - 'action' => 'edit', |
|
| 1266 | - 'post' => $this->ID(), |
|
| 1267 | - ), |
|
| 1268 | - admin_url('admin.php') |
|
| 1269 | - ); |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1275 | - * |
|
| 1276 | - * @see EEI_Admin_Links for comments |
|
| 1277 | - * @return string |
|
| 1278 | - */ |
|
| 1279 | - public function get_admin_settings_link() |
|
| 1280 | - { |
|
| 1281 | - return EEH_URL::add_query_args_and_nonce(array( |
|
| 1282 | - 'page' => 'espresso_events', |
|
| 1283 | - 'action' => 'default_event_settings', |
|
| 1284 | - ), |
|
| 1285 | - admin_url('admin.php') |
|
| 1286 | - ); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - |
|
| 1290 | - /** |
|
| 1291 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1292 | - * |
|
| 1293 | - * @see EEI_Admin_Links for comments |
|
| 1294 | - * @return string |
|
| 1295 | - */ |
|
| 1296 | - public function get_admin_overview_link() |
|
| 1297 | - { |
|
| 1298 | - return EEH_URL::add_query_args_and_nonce(array( |
|
| 1299 | - 'page' => 'espresso_events', |
|
| 1300 | - 'action' => 'default', |
|
| 1301 | - ), |
|
| 1302 | - admin_url('admin.php') |
|
| 1303 | - ); |
|
| 1304 | - } |
|
| 21 | + /** |
|
| 22 | + * cached value for the the logical active status for the event |
|
| 23 | + * |
|
| 24 | + * @see get_active_status() |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $_active_status = ''; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 31 | + * |
|
| 32 | + * @var EE_Datetime |
|
| 33 | + */ |
|
| 34 | + protected $_Primary_Datetime; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var EventSpacesCalculator $available_spaces_calculator |
|
| 38 | + */ |
|
| 39 | + protected $available_spaces_calculator; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param array $props_n_values incoming values |
|
| 44 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 45 | + * used.) |
|
| 46 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 47 | + * date_format and the second value is the time format |
|
| 48 | + * @return EE_Event |
|
| 49 | + * @throws EE_Error |
|
| 50 | + */ |
|
| 51 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 52 | + { |
|
| 53 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 54 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param array $props_n_values incoming values from the database |
|
| 60 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 61 | + * the website will be used. |
|
| 62 | + * @return EE_Event |
|
| 63 | + * @throws EE_Error |
|
| 64 | + */ |
|
| 65 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 66 | + { |
|
| 67 | + return new self($props_n_values, true, $timezone); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @return EventSpacesCalculator |
|
| 74 | + * @throws \EE_Error |
|
| 75 | + */ |
|
| 76 | + public function getAvailableSpacesCalculator() |
|
| 77 | + { |
|
| 78 | + if(! $this->available_spaces_calculator instanceof EventSpacesCalculator){ |
|
| 79 | + $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 80 | + } |
|
| 81 | + return $this->available_spaces_calculator; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 88 | + * |
|
| 89 | + * @param string $field_name |
|
| 90 | + * @param mixed $field_value |
|
| 91 | + * @param bool $use_default |
|
| 92 | + * @throws EE_Error |
|
| 93 | + */ |
|
| 94 | + public function set($field_name, $field_value, $use_default = false) |
|
| 95 | + { |
|
| 96 | + switch ($field_name) { |
|
| 97 | + case 'status' : |
|
| 98 | + $this->set_status($field_value, $use_default); |
|
| 99 | + break; |
|
| 100 | + default : |
|
| 101 | + parent::set($field_name, $field_value, $use_default); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * set_status |
|
| 108 | + * Checks if event status is being changed to SOLD OUT |
|
| 109 | + * and updates event meta data with previous event status |
|
| 110 | + * so that we can revert things if/when the event is no longer sold out |
|
| 111 | + * |
|
| 112 | + * @access public |
|
| 113 | + * @param string $new_status |
|
| 114 | + * @param bool $use_default |
|
| 115 | + * @return void |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function set_status($new_status = null, $use_default = false) |
|
| 119 | + { |
|
| 120 | + // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 121 | + if (empty($new_status) && !$use_default) { |
|
| 122 | + return; |
|
| 123 | + } |
|
| 124 | + // get current Event status |
|
| 125 | + $old_status = $this->status(); |
|
| 126 | + // if status has changed |
|
| 127 | + if ($old_status !== $new_status) { |
|
| 128 | + // TO sold_out |
|
| 129 | + if ($new_status === EEM_Event::sold_out) { |
|
| 130 | + // save the previous event status so that we can revert if the event is no longer sold out |
|
| 131 | + $this->add_post_meta('_previous_event_status', $old_status); |
|
| 132 | + do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 133 | + // OR FROM sold_out |
|
| 134 | + } else if ($old_status === EEM_Event::sold_out) { |
|
| 135 | + $this->delete_post_meta('_previous_event_status'); |
|
| 136 | + do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 137 | + } |
|
| 138 | + // update status |
|
| 139 | + parent::set('status', $new_status, $use_default); |
|
| 140 | + do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 141 | + return; |
|
| 142 | + } |
|
| 143 | + // even though the old value matches the new value, it's still good to |
|
| 144 | + // allow the parent set method to have a say |
|
| 145 | + parent::set('status', $new_status, $use_default); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Gets all the datetimes for this event |
|
| 151 | + * |
|
| 152 | + * @param array $query_params like EEM_Base::get_all |
|
| 153 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 154 | + * @throws EE_Error |
|
| 155 | + */ |
|
| 156 | + public function datetimes($query_params = array()) |
|
| 157 | + { |
|
| 158 | + return $this->get_many_related('Datetime', $query_params); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 164 | + * |
|
| 165 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 166 | + * @throws EE_Error |
|
| 167 | + */ |
|
| 168 | + public function datetimes_in_chronological_order() |
|
| 169 | + { |
|
| 170 | + return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 176 | + * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 177 | + * after running our query, so that this timezone isn't set for EVERY query |
|
| 178 | + * on EEM_Datetime for the rest of the request, no? |
|
| 179 | + * |
|
| 180 | + * @param boolean $show_expired whether or not to include expired events |
|
| 181 | + * @param boolean $show_deleted whether or not to include deleted events |
|
| 182 | + * @param null $limit |
|
| 183 | + * @return EE_Datetime[] |
|
| 184 | + * @throws EE_Error |
|
| 185 | + */ |
|
| 186 | + public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 187 | + { |
|
| 188 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 189 | + $this->ID(), |
|
| 190 | + $show_expired, |
|
| 191 | + $show_deleted, |
|
| 192 | + $limit |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Returns one related datetime. Mostly only used by some legacy code. |
|
| 199 | + * |
|
| 200 | + * @return EE_Base_Class|EE_Datetime |
|
| 201 | + * @throws EE_Error |
|
| 202 | + */ |
|
| 203 | + public function first_datetime() |
|
| 204 | + { |
|
| 205 | + return $this->get_first_related('Datetime'); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Returns the 'primary' datetime for the event |
|
| 211 | + * |
|
| 212 | + * @param bool $try_to_exclude_expired |
|
| 213 | + * @param bool $try_to_exclude_deleted |
|
| 214 | + * @return EE_Datetime |
|
| 215 | + * @throws EE_Error |
|
| 216 | + */ |
|
| 217 | + public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 218 | + { |
|
| 219 | + if (!empty ($this->_Primary_Datetime)) { |
|
| 220 | + return $this->_Primary_Datetime; |
|
| 221 | + } |
|
| 222 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 223 | + $this->ID(), |
|
| 224 | + $try_to_exclude_expired, |
|
| 225 | + $try_to_exclude_deleted |
|
| 226 | + ); |
|
| 227 | + return $this->_Primary_Datetime; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Gets all the tickets available for purchase of this event |
|
| 233 | + * |
|
| 234 | + * @param array $query_params like EEM_Base::get_all |
|
| 235 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 236 | + * @throws EE_Error |
|
| 237 | + */ |
|
| 238 | + public function tickets($query_params = array()) |
|
| 239 | + { |
|
| 240 | + //first get all datetimes |
|
| 241 | + $datetimes = $this->datetimes_ordered(); |
|
| 242 | + if (!$datetimes) { |
|
| 243 | + return array(); |
|
| 244 | + } |
|
| 245 | + $datetime_ids = array(); |
|
| 246 | + foreach ($datetimes as $datetime) { |
|
| 247 | + $datetime_ids[] = $datetime->ID(); |
|
| 248 | + } |
|
| 249 | + $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 250 | + //if incoming $query_params has where conditions let's merge but not override existing. |
|
| 251 | + if (is_array($query_params) && isset($query_params[0])) { |
|
| 252 | + $where_params = array_merge($query_params[0], $where_params); |
|
| 253 | + unset($query_params[0]); |
|
| 254 | + } |
|
| 255 | + //now add $where_params to $query_params |
|
| 256 | + $query_params[0] = $where_params; |
|
| 257 | + return EEM_Ticket::instance()->get_all($query_params); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * get all unexpired untrashed tickets |
|
| 263 | + * |
|
| 264 | + * @return EE_Ticket[] |
|
| 265 | + * @throws EE_Error |
|
| 266 | + */ |
|
| 267 | + public function active_tickets() |
|
| 268 | + { |
|
| 269 | + return $this->tickets(array( |
|
| 270 | + array( |
|
| 271 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 272 | + 'TKT_deleted' => false, |
|
| 273 | + ), |
|
| 274 | + )); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @return bool |
|
| 280 | + * @throws EE_Error |
|
| 281 | + */ |
|
| 282 | + public function additional_limit() |
|
| 283 | + { |
|
| 284 | + return $this->get('EVT_additional_limit'); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @return bool |
|
| 290 | + * @throws EE_Error |
|
| 291 | + */ |
|
| 292 | + public function allow_overflow() |
|
| 293 | + { |
|
| 294 | + return $this->get('EVT_allow_overflow'); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @return bool |
|
| 300 | + * @throws EE_Error |
|
| 301 | + */ |
|
| 302 | + public function created() |
|
| 303 | + { |
|
| 304 | + return $this->get('EVT_created'); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * @return bool |
|
| 310 | + * @throws EE_Error |
|
| 311 | + */ |
|
| 312 | + public function description() |
|
| 313 | + { |
|
| 314 | + return $this->get('EVT_desc'); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Runs do_shortcode and wpautop on the description |
|
| 320 | + * |
|
| 321 | + * @return string of html |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + public function description_filtered() |
|
| 325 | + { |
|
| 326 | + return $this->get_pretty('EVT_desc'); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * @return bool |
|
| 332 | + * @throws EE_Error |
|
| 333 | + */ |
|
| 334 | + public function display_description() |
|
| 335 | + { |
|
| 336 | + return $this->get('EVT_display_desc'); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * @return bool |
|
| 342 | + * @throws EE_Error |
|
| 343 | + */ |
|
| 344 | + public function display_ticket_selector() |
|
| 345 | + { |
|
| 346 | + return (bool)$this->get('EVT_display_ticket_selector'); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @return bool |
|
| 352 | + * @throws EE_Error |
|
| 353 | + */ |
|
| 354 | + public function external_url() |
|
| 355 | + { |
|
| 356 | + return $this->get('EVT_external_URL'); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @return bool |
|
| 362 | + * @throws EE_Error |
|
| 363 | + */ |
|
| 364 | + public function member_only() |
|
| 365 | + { |
|
| 366 | + return $this->get('EVT_member_only'); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * @return bool |
|
| 372 | + * @throws EE_Error |
|
| 373 | + */ |
|
| 374 | + public function phone() |
|
| 375 | + { |
|
| 376 | + return $this->get('EVT_phone'); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * @return bool |
|
| 382 | + * @throws EE_Error |
|
| 383 | + */ |
|
| 384 | + public function modified() |
|
| 385 | + { |
|
| 386 | + return $this->get('EVT_modified'); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * @return bool |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + public function name() |
|
| 395 | + { |
|
| 396 | + return $this->get('EVT_name'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * @return bool |
|
| 402 | + * @throws EE_Error |
|
| 403 | + */ |
|
| 404 | + public function order() |
|
| 405 | + { |
|
| 406 | + return $this->get('EVT_order'); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * @return bool|string |
|
| 412 | + * @throws EE_Error |
|
| 413 | + */ |
|
| 414 | + public function default_registration_status() |
|
| 415 | + { |
|
| 416 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 417 | + return !empty($event_default_registration_status) |
|
| 418 | + ? $event_default_registration_status |
|
| 419 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * @param int $num_words |
|
| 425 | + * @param null $more |
|
| 426 | + * @param bool $not_full_desc |
|
| 427 | + * @return bool|string |
|
| 428 | + * @throws EE_Error |
|
| 429 | + */ |
|
| 430 | + public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 431 | + { |
|
| 432 | + $short_desc = $this->get('EVT_short_desc'); |
|
| 433 | + if (!empty($short_desc) || $not_full_desc) { |
|
| 434 | + return $short_desc; |
|
| 435 | + } |
|
| 436 | + $full_desc = $this->get('EVT_desc'); |
|
| 437 | + return wp_trim_words($full_desc, $num_words, $more); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * @return bool |
|
| 443 | + * @throws EE_Error |
|
| 444 | + */ |
|
| 445 | + public function slug() |
|
| 446 | + { |
|
| 447 | + return $this->get('EVT_slug'); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @return bool |
|
| 453 | + * @throws EE_Error |
|
| 454 | + */ |
|
| 455 | + public function timezone_string() |
|
| 456 | + { |
|
| 457 | + return $this->get('EVT_timezone_string'); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * @return bool |
|
| 463 | + * @throws EE_Error |
|
| 464 | + */ |
|
| 465 | + public function visible_on() |
|
| 466 | + { |
|
| 467 | + return $this->get('EVT_visible_on'); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @return int |
|
| 473 | + * @throws EE_Error |
|
| 474 | + */ |
|
| 475 | + public function wp_user() |
|
| 476 | + { |
|
| 477 | + return $this->get('EVT_wp_user'); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @return bool |
|
| 483 | + * @throws EE_Error |
|
| 484 | + */ |
|
| 485 | + public function donations() |
|
| 486 | + { |
|
| 487 | + return $this->get('EVT_donations'); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * @param $limit |
|
| 493 | + * @throws EE_Error |
|
| 494 | + */ |
|
| 495 | + public function set_additional_limit($limit) |
|
| 496 | + { |
|
| 497 | + $this->set('EVT_additional_limit', $limit); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @param $created |
|
| 503 | + * @throws EE_Error |
|
| 504 | + */ |
|
| 505 | + public function set_created($created) |
|
| 506 | + { |
|
| 507 | + $this->set('EVT_created', $created); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * @param $desc |
|
| 513 | + * @throws EE_Error |
|
| 514 | + */ |
|
| 515 | + public function set_description($desc) |
|
| 516 | + { |
|
| 517 | + $this->set('EVT_desc', $desc); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * @param $display_desc |
|
| 523 | + * @throws EE_Error |
|
| 524 | + */ |
|
| 525 | + public function set_display_description($display_desc) |
|
| 526 | + { |
|
| 527 | + $this->set('EVT_display_desc', $display_desc); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * @param $display_ticket_selector |
|
| 533 | + * @throws EE_Error |
|
| 534 | + */ |
|
| 535 | + public function set_display_ticket_selector($display_ticket_selector) |
|
| 536 | + { |
|
| 537 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * @param $external_url |
|
| 543 | + * @throws EE_Error |
|
| 544 | + */ |
|
| 545 | + public function set_external_url($external_url) |
|
| 546 | + { |
|
| 547 | + $this->set('EVT_external_URL', $external_url); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * @param $member_only |
|
| 553 | + * @throws EE_Error |
|
| 554 | + */ |
|
| 555 | + public function set_member_only($member_only) |
|
| 556 | + { |
|
| 557 | + $this->set('EVT_member_only', $member_only); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * @param $event_phone |
|
| 563 | + * @throws EE_Error |
|
| 564 | + */ |
|
| 565 | + public function set_event_phone($event_phone) |
|
| 566 | + { |
|
| 567 | + $this->set('EVT_phone', $event_phone); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * @param $modified |
|
| 573 | + * @throws EE_Error |
|
| 574 | + */ |
|
| 575 | + public function set_modified($modified) |
|
| 576 | + { |
|
| 577 | + $this->set('EVT_modified', $modified); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * @param $name |
|
| 583 | + * @throws EE_Error |
|
| 584 | + */ |
|
| 585 | + public function set_name($name) |
|
| 586 | + { |
|
| 587 | + $this->set('EVT_name', $name); |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * @param $order |
|
| 593 | + * @throws EE_Error |
|
| 594 | + */ |
|
| 595 | + public function set_order($order) |
|
| 596 | + { |
|
| 597 | + $this->set('EVT_order', $order); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * @param $short_desc |
|
| 603 | + * @throws EE_Error |
|
| 604 | + */ |
|
| 605 | + public function set_short_description($short_desc) |
|
| 606 | + { |
|
| 607 | + $this->set('EVT_short_desc', $short_desc); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * @param $slug |
|
| 613 | + * @throws EE_Error |
|
| 614 | + */ |
|
| 615 | + public function set_slug($slug) |
|
| 616 | + { |
|
| 617 | + $this->set('EVT_slug', $slug); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @param $timezone_string |
|
| 623 | + * @throws EE_Error |
|
| 624 | + */ |
|
| 625 | + public function set_timezone_string($timezone_string) |
|
| 626 | + { |
|
| 627 | + $this->set('EVT_timezone_string', $timezone_string); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * @param $visible_on |
|
| 633 | + * @throws EE_Error |
|
| 634 | + */ |
|
| 635 | + public function set_visible_on($visible_on) |
|
| 636 | + { |
|
| 637 | + $this->set('EVT_visible_on', $visible_on); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * @param $wp_user |
|
| 643 | + * @throws EE_Error |
|
| 644 | + */ |
|
| 645 | + public function set_wp_user($wp_user) |
|
| 646 | + { |
|
| 647 | + $this->set('EVT_wp_user', $wp_user); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * @param $default_registration_status |
|
| 653 | + * @throws EE_Error |
|
| 654 | + */ |
|
| 655 | + public function set_default_registration_status($default_registration_status) |
|
| 656 | + { |
|
| 657 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * @param $donations |
|
| 663 | + * @throws EE_Error |
|
| 664 | + */ |
|
| 665 | + public function set_donations($donations) |
|
| 666 | + { |
|
| 667 | + $this->set('EVT_donations', $donations); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Adds a venue to this event |
|
| 673 | + * |
|
| 674 | + * @param EE_Venue /int $venue_id_or_obj |
|
| 675 | + * @return EE_Base_Class|EE_Venue |
|
| 676 | + * @throws EE_Error |
|
| 677 | + */ |
|
| 678 | + public function add_venue($venue_id_or_obj) |
|
| 679 | + { |
|
| 680 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * Removes a venue from the event |
|
| 686 | + * |
|
| 687 | + * @param EE_Venue /int $venue_id_or_obj |
|
| 688 | + * @return EE_Base_Class|EE_Venue |
|
| 689 | + * @throws EE_Error |
|
| 690 | + */ |
|
| 691 | + public function remove_venue($venue_id_or_obj) |
|
| 692 | + { |
|
| 693 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
| 699 | + * |
|
| 700 | + * @param array $query_params like EEM_Base::get_all's $query_params |
|
| 701 | + * @return EE_Base_Class[]|EE_Venue[] |
|
| 702 | + * @throws EE_Error |
|
| 703 | + */ |
|
| 704 | + public function venues($query_params = array()) |
|
| 705 | + { |
|
| 706 | + return $this->get_many_related('Venue', $query_params); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * check if event id is present and if event is published |
|
| 712 | + * |
|
| 713 | + * @access public |
|
| 714 | + * @return boolean true yes, false no |
|
| 715 | + * @throws EE_Error |
|
| 716 | + */ |
|
| 717 | + private function _has_ID_and_is_published() |
|
| 718 | + { |
|
| 719 | + // first check if event id is present and not NULL, |
|
| 720 | + // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 721 | + return |
|
| 722 | + $this->ID() && $this->ID() !== null |
|
| 723 | + && ( |
|
| 724 | + $this->status() === 'publish' |
|
| 725 | + || $this->status() === EEM_Event::sold_out |
|
| 726 | + || $this->status() === EEM_Event::postponed |
|
| 727 | + || $this->status() === EEM_Event::cancelled |
|
| 728 | + ); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 734 | + * |
|
| 735 | + * @access public |
|
| 736 | + * @return boolean true yes, false no |
|
| 737 | + * @throws EE_Error |
|
| 738 | + */ |
|
| 739 | + public function is_upcoming() |
|
| 740 | + { |
|
| 741 | + // check if event id is present and if this event is published |
|
| 742 | + if ($this->is_inactive()) { |
|
| 743 | + return false; |
|
| 744 | + } |
|
| 745 | + // set initial value |
|
| 746 | + $upcoming = false; |
|
| 747 | + //next let's get all datetimes and loop through them |
|
| 748 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 749 | + foreach ($datetimes as $datetime) { |
|
| 750 | + if ($datetime instanceof EE_Datetime) { |
|
| 751 | + //if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 752 | + if ($datetime->is_expired()) { |
|
| 753 | + continue; |
|
| 754 | + } |
|
| 755 | + //if this dtt is active then we return false. |
|
| 756 | + if ($datetime->is_active()) { |
|
| 757 | + return false; |
|
| 758 | + } |
|
| 759 | + //otherwise let's check upcoming status |
|
| 760 | + $upcoming = $datetime->is_upcoming(); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + return $upcoming; |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + |
|
| 767 | + /** |
|
| 768 | + * @return bool |
|
| 769 | + * @throws EE_Error |
|
| 770 | + */ |
|
| 771 | + public function is_active() |
|
| 772 | + { |
|
| 773 | + // check if event id is present and if this event is published |
|
| 774 | + if ($this->is_inactive()) { |
|
| 775 | + return false; |
|
| 776 | + } |
|
| 777 | + // set initial value |
|
| 778 | + $active = false; |
|
| 779 | + //next let's get all datetimes and loop through them |
|
| 780 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 781 | + foreach ($datetimes as $datetime) { |
|
| 782 | + if ($datetime instanceof EE_Datetime) { |
|
| 783 | + //if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 784 | + if ($datetime->is_expired()) { |
|
| 785 | + continue; |
|
| 786 | + } |
|
| 787 | + //if this dtt is upcoming then we return false. |
|
| 788 | + if ($datetime->is_upcoming()) { |
|
| 789 | + return false; |
|
| 790 | + } |
|
| 791 | + //otherwise let's check active status |
|
| 792 | + $active = $datetime->is_active(); |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | + return $active; |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * @return bool |
|
| 801 | + * @throws EE_Error |
|
| 802 | + */ |
|
| 803 | + public function is_expired() |
|
| 804 | + { |
|
| 805 | + // check if event id is present and if this event is published |
|
| 806 | + if ($this->is_inactive()) { |
|
| 807 | + return false; |
|
| 808 | + } |
|
| 809 | + // set initial value |
|
| 810 | + $expired = false; |
|
| 811 | + //first let's get all datetimes and loop through them |
|
| 812 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 813 | + foreach ($datetimes as $datetime) { |
|
| 814 | + if ($datetime instanceof EE_Datetime) { |
|
| 815 | + //if this dtt is upcoming or active then we return false. |
|
| 816 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 817 | + return false; |
|
| 818 | + } |
|
| 819 | + //otherwise let's check active status |
|
| 820 | + $expired = $datetime->is_expired(); |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | + return $expired; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * @return bool |
|
| 829 | + * @throws EE_Error |
|
| 830 | + */ |
|
| 831 | + public function is_inactive() |
|
| 832 | + { |
|
| 833 | + // check if event id is present and if this event is published |
|
| 834 | + if ($this->_has_ID_and_is_published()) { |
|
| 835 | + return false; |
|
| 836 | + } |
|
| 837 | + return true; |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + |
|
| 841 | + /** |
|
| 842 | + * calculate spaces remaining based on "saleable" tickets |
|
| 843 | + * |
|
| 844 | + * @param array $tickets |
|
| 845 | + * @param bool $filtered |
|
| 846 | + * @return int|float |
|
| 847 | + * @throws EE_Error |
|
| 848 | + * @throws DomainException |
|
| 849 | + * @throws UnexpectedEntityException |
|
| 850 | + */ |
|
| 851 | + public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 852 | + { |
|
| 853 | + $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 854 | + $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 855 | + return $filtered |
|
| 856 | + ? apply_filters( |
|
| 857 | + 'FHEE_EE_Event__spaces_remaining', |
|
| 858 | + $spaces_remaining, |
|
| 859 | + $this, |
|
| 860 | + $tickets |
|
| 861 | + ) |
|
| 862 | + : $spaces_remaining; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * perform_sold_out_status_check |
|
| 868 | + * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces available... |
|
| 869 | + * if NOT, then the event status will get toggled to 'sold_out' |
|
| 870 | + * |
|
| 871 | + * @return bool return the ACTUAL sold out state. |
|
| 872 | + * @throws EE_Error |
|
| 873 | + * @throws DomainException |
|
| 874 | + * @throws UnexpectedEntityException |
|
| 875 | + */ |
|
| 876 | + public function perform_sold_out_status_check() |
|
| 877 | + { |
|
| 878 | + // get all unexpired untrashed tickets |
|
| 879 | + $tickets = $this->active_tickets(); |
|
| 880 | + // if all the tickets are just expired, then don't update the event status to sold out |
|
| 881 | + if (empty($tickets)) { |
|
| 882 | + return true; |
|
| 883 | + } |
|
| 884 | + $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 885 | + if ($spaces_remaining < 1) { |
|
| 886 | + $this->set_status(EEM_Event::sold_out); |
|
| 887 | + $this->save(); |
|
| 888 | + $sold_out = true; |
|
| 889 | + } else { |
|
| 890 | + $sold_out = false; |
|
| 891 | + // was event previously marked as sold out ? |
|
| 892 | + if ($this->status() === EEM_Event::sold_out) { |
|
| 893 | + // revert status to previous value, if it was set |
|
| 894 | + $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 895 | + if ($previous_event_status) { |
|
| 896 | + $this->set_status($previous_event_status); |
|
| 897 | + $this->save(); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + } |
|
| 901 | + do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 902 | + return $sold_out; |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + |
|
| 906 | + |
|
| 907 | + /** |
|
| 908 | + * This returns the total remaining spaces for sale on this event. |
|
| 909 | + * |
|
| 910 | + * @uses EE_Event::total_available_spaces() |
|
| 911 | + * @return float|int |
|
| 912 | + * @throws EE_Error |
|
| 913 | + * @throws DomainException |
|
| 914 | + * @throws UnexpectedEntityException |
|
| 915 | + */ |
|
| 916 | + public function spaces_remaining_for_sale() |
|
| 917 | + { |
|
| 918 | + return $this->total_available_spaces(true); |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * This returns the total spaces available for an event |
|
| 925 | + * while considering all the qtys on the tickets and the reg limits |
|
| 926 | + * on the datetimes attached to this event. |
|
| 927 | + * |
|
| 928 | + * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 929 | + * If this is false, then we return the most tickets that could ever be sold |
|
| 930 | + * for this event with the datetime and tickets setup on the event under optimal |
|
| 931 | + * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 932 | + * based on tickets sold. Depending on setup and stage of sales, this |
|
| 933 | + * may appear to equal remaining tickets. However, the more tickets are |
|
| 934 | + * sold out, the more accurate the "live" total is. |
|
| 935 | + * @return float|int |
|
| 936 | + * @throws EE_Error |
|
| 937 | + * @throws DomainException |
|
| 938 | + * @throws UnexpectedEntityException |
|
| 939 | + */ |
|
| 940 | + public function total_available_spaces($consider_sold = false) |
|
| 941 | + { |
|
| 942 | + $spaces_available = $consider_sold |
|
| 943 | + ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 944 | + : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 945 | + return apply_filters( |
|
| 946 | + 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 947 | + $spaces_available, |
|
| 948 | + $this, |
|
| 949 | + $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 950 | + $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 951 | + ); |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + |
|
| 955 | + /** |
|
| 956 | + * Checks if the event is set to sold out |
|
| 957 | + * |
|
| 958 | + * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 959 | + * actual status but also to flip the status if necessary to sold |
|
| 960 | + * out If false, we just check the existing status of the event |
|
| 961 | + * @return boolean |
|
| 962 | + * @throws EE_Error |
|
| 963 | + */ |
|
| 964 | + public function is_sold_out($actual = false) |
|
| 965 | + { |
|
| 966 | + if (!$actual) { |
|
| 967 | + return $this->status() === EEM_Event::sold_out; |
|
| 968 | + } |
|
| 969 | + return $this->perform_sold_out_status_check(); |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + /** |
|
| 974 | + * Checks if the event is marked as postponed |
|
| 975 | + * |
|
| 976 | + * @return boolean |
|
| 977 | + */ |
|
| 978 | + public function is_postponed() |
|
| 979 | + { |
|
| 980 | + return $this->status() === EEM_Event::postponed; |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + |
|
| 984 | + /** |
|
| 985 | + * Checks if the event is marked as cancelled |
|
| 986 | + * |
|
| 987 | + * @return boolean |
|
| 988 | + */ |
|
| 989 | + public function is_cancelled() |
|
| 990 | + { |
|
| 991 | + return $this->status() === EEM_Event::cancelled; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + |
|
| 995 | + /** |
|
| 996 | + * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 997 | + * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 998 | + * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 999 | + * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1000 | + * the event is considered expired. |
|
| 1001 | + * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a status |
|
| 1002 | + * set on the EVENT when it is not published and thus is done |
|
| 1003 | + * |
|
| 1004 | + * @param bool $reset |
|
| 1005 | + * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1006 | + * @throws EE_Error |
|
| 1007 | + */ |
|
| 1008 | + public function get_active_status($reset = false) |
|
| 1009 | + { |
|
| 1010 | + // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1011 | + if (!empty($this->_active_status) && !$reset) { |
|
| 1012 | + return $this->_active_status; |
|
| 1013 | + } |
|
| 1014 | + //first check if event id is present on this object |
|
| 1015 | + if (!$this->ID()) { |
|
| 1016 | + return false; |
|
| 1017 | + } |
|
| 1018 | + $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1019 | + //if event is published: |
|
| 1020 | + if ($this->status() === 'publish') { |
|
| 1021 | + //active? |
|
| 1022 | + if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event) > 0) { |
|
| 1023 | + $this->_active_status = EE_Datetime::active; |
|
| 1024 | + } else { |
|
| 1025 | + //upcoming? |
|
| 1026 | + if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0) { |
|
| 1027 | + $this->_active_status = EE_Datetime::upcoming; |
|
| 1028 | + } else { |
|
| 1029 | + //expired? |
|
| 1030 | + if ( |
|
| 1031 | + EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0 |
|
| 1032 | + ) { |
|
| 1033 | + $this->_active_status = EE_Datetime::expired; |
|
| 1034 | + } else { |
|
| 1035 | + //it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1036 | + //attached to the event. So in this case it will just be considered inactive. |
|
| 1037 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1038 | + } |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + } else { |
|
| 1042 | + //the event is not published, so let's just set it's active status according to its' post status |
|
| 1043 | + switch ($this->status()) { |
|
| 1044 | + case EEM_Event::sold_out : |
|
| 1045 | + $this->_active_status = EE_Datetime::sold_out; |
|
| 1046 | + break; |
|
| 1047 | + case EEM_Event::cancelled : |
|
| 1048 | + $this->_active_status = EE_Datetime::cancelled; |
|
| 1049 | + break; |
|
| 1050 | + case EEM_Event::postponed : |
|
| 1051 | + $this->_active_status = EE_Datetime::postponed; |
|
| 1052 | + break; |
|
| 1053 | + default : |
|
| 1054 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1055 | + } |
|
| 1056 | + } |
|
| 1057 | + return $this->_active_status; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + /** |
|
| 1062 | + * pretty_active_status |
|
| 1063 | + * |
|
| 1064 | + * @access public |
|
| 1065 | + * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1066 | + * @return mixed void|string |
|
| 1067 | + * @throws EE_Error |
|
| 1068 | + */ |
|
| 1069 | + public function pretty_active_status($echo = true) |
|
| 1070 | + { |
|
| 1071 | + $active_status = $this->get_active_status(); |
|
| 1072 | + $status = '<span class="ee-status event-active-status-' |
|
| 1073 | + . $active_status |
|
| 1074 | + . '">' |
|
| 1075 | + . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1076 | + . '</span>'; |
|
| 1077 | + if ($echo) { |
|
| 1078 | + echo $status; |
|
| 1079 | + return ''; |
|
| 1080 | + } |
|
| 1081 | + return $status; |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * @return bool|int |
|
| 1087 | + * @throws EE_Error |
|
| 1088 | + */ |
|
| 1089 | + public function get_number_of_tickets_sold() |
|
| 1090 | + { |
|
| 1091 | + $tkt_sold = 0; |
|
| 1092 | + if (!$this->ID()) { |
|
| 1093 | + return 0; |
|
| 1094 | + } |
|
| 1095 | + $datetimes = $this->datetimes(); |
|
| 1096 | + foreach ($datetimes as $datetime) { |
|
| 1097 | + if ($datetime instanceof EE_Datetime) { |
|
| 1098 | + $tkt_sold += $datetime->sold(); |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + return $tkt_sold; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * This just returns a count of all the registrations for this event |
|
| 1107 | + * |
|
| 1108 | + * @access public |
|
| 1109 | + * @return int |
|
| 1110 | + * @throws EE_Error |
|
| 1111 | + */ |
|
| 1112 | + public function get_count_of_all_registrations() |
|
| 1113 | + { |
|
| 1114 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * This returns the ticket with the earliest start time that is |
|
| 1120 | + * available for this event (across all datetimes attached to the event) |
|
| 1121 | + * |
|
| 1122 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1123 | + * @throws EE_Error |
|
| 1124 | + */ |
|
| 1125 | + public function get_ticket_with_earliest_start_time() |
|
| 1126 | + { |
|
| 1127 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1128 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1129 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * This returns the ticket with the latest end time that is available |
|
| 1135 | + * for this event (across all datetimes attached to the event) |
|
| 1136 | + * |
|
| 1137 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1138 | + * @throws EE_Error |
|
| 1139 | + */ |
|
| 1140 | + public function get_ticket_with_latest_end_time() |
|
| 1141 | + { |
|
| 1142 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1143 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1144 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + |
|
| 1148 | + /** |
|
| 1149 | + * This returns whether there are any tickets on sale for this event. |
|
| 1150 | + * |
|
| 1151 | + * @return bool true = YES tickets on sale. |
|
| 1152 | + * @throws EE_Error |
|
| 1153 | + */ |
|
| 1154 | + public function tickets_on_sale() |
|
| 1155 | + { |
|
| 1156 | + $earliest_ticket = $this->get_ticket_with_earliest_start_time(); |
|
| 1157 | + $latest_ticket = $this->get_ticket_with_latest_end_time(); |
|
| 1158 | + if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) { |
|
| 1159 | + return false; |
|
| 1160 | + } |
|
| 1161 | + //check on sale for these two tickets. |
|
| 1162 | + if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) { |
|
| 1163 | + return true; |
|
| 1164 | + } |
|
| 1165 | + return false; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + |
|
| 1169 | + /** |
|
| 1170 | + * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1171 | + * to check for an external URL first |
|
| 1172 | + * |
|
| 1173 | + * @return string |
|
| 1174 | + * @throws EE_Error |
|
| 1175 | + */ |
|
| 1176 | + public function get_permalink() |
|
| 1177 | + { |
|
| 1178 | + if ($this->external_url()) { |
|
| 1179 | + return $this->external_url(); |
|
| 1180 | + } |
|
| 1181 | + return parent::get_permalink(); |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * Gets the first term for 'espresso_event_categories' we can find |
|
| 1187 | + * |
|
| 1188 | + * @param array $query_params like EEM_Base::get_all |
|
| 1189 | + * @return EE_Base_Class|EE_Term|null |
|
| 1190 | + * @throws EE_Error |
|
| 1191 | + */ |
|
| 1192 | + public function first_event_category($query_params = array()) |
|
| 1193 | + { |
|
| 1194 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1195 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1196 | + return EEM_Term::instance()->get_one($query_params); |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + |
|
| 1200 | + /** |
|
| 1201 | + * Gets all terms for 'espresso_event_categories' we can find |
|
| 1202 | + * |
|
| 1203 | + * @param array $query_params |
|
| 1204 | + * @return EE_Base_Class[]|EE_Term[] |
|
| 1205 | + * @throws EE_Error |
|
| 1206 | + */ |
|
| 1207 | + public function get_all_event_categories($query_params = array()) |
|
| 1208 | + { |
|
| 1209 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1210 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1211 | + return EEM_Term::instance()->get_all($query_params); |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + |
|
| 1215 | + /** |
|
| 1216 | + * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1217 | + * |
|
| 1218 | + * @param array $query_params @see EEM_Base::get_all |
|
| 1219 | + * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1220 | + * @throws EE_Error |
|
| 1221 | + */ |
|
| 1222 | + public function question_groups($query_params = array()) |
|
| 1223 | + { |
|
| 1224 | + $query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1225 | + return $this->get_many_related('Question_Group', $query_params); |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * Implementation for EEI_Has_Icon interface method. |
|
| 1231 | + * |
|
| 1232 | + * @see EEI_Visual_Representation for comments |
|
| 1233 | + * @return string |
|
| 1234 | + */ |
|
| 1235 | + public function get_icon() |
|
| 1236 | + { |
|
| 1237 | + return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + |
|
| 1241 | + /** |
|
| 1242 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1243 | + * |
|
| 1244 | + * @see EEI_Admin_Links for comments |
|
| 1245 | + * @return string |
|
| 1246 | + * @throws EE_Error |
|
| 1247 | + */ |
|
| 1248 | + public function get_admin_details_link() |
|
| 1249 | + { |
|
| 1250 | + return $this->get_admin_edit_link(); |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1256 | + * |
|
| 1257 | + * @see EEI_Admin_Links for comments |
|
| 1258 | + * @return string |
|
| 1259 | + * @throws EE_Error |
|
| 1260 | + */ |
|
| 1261 | + public function get_admin_edit_link() |
|
| 1262 | + { |
|
| 1263 | + return EEH_URL::add_query_args_and_nonce(array( |
|
| 1264 | + 'page' => 'espresso_events', |
|
| 1265 | + 'action' => 'edit', |
|
| 1266 | + 'post' => $this->ID(), |
|
| 1267 | + ), |
|
| 1268 | + admin_url('admin.php') |
|
| 1269 | + ); |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1275 | + * |
|
| 1276 | + * @see EEI_Admin_Links for comments |
|
| 1277 | + * @return string |
|
| 1278 | + */ |
|
| 1279 | + public function get_admin_settings_link() |
|
| 1280 | + { |
|
| 1281 | + return EEH_URL::add_query_args_and_nonce(array( |
|
| 1282 | + 'page' => 'espresso_events', |
|
| 1283 | + 'action' => 'default_event_settings', |
|
| 1284 | + ), |
|
| 1285 | + admin_url('admin.php') |
|
| 1286 | + ); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + |
|
| 1290 | + /** |
|
| 1291 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1292 | + * |
|
| 1293 | + * @see EEI_Admin_Links for comments |
|
| 1294 | + * @return string |
|
| 1295 | + */ |
|
| 1296 | + public function get_admin_overview_link() |
|
| 1297 | + { |
|
| 1298 | + return EEH_URL::add_query_args_and_nonce(array( |
|
| 1299 | + 'page' => 'espresso_events', |
|
| 1300 | + 'action' => 'default', |
|
| 1301 | + ), |
|
| 1302 | + admin_url('admin.php') |
|
| 1303 | + ); |
|
| 1304 | + } |
|
| 1305 | 1305 | |
| 1306 | 1306 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\core\domain\services\event\EventSpacesCalculator; |
| 4 | 4 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
| 5 | 5 | |
| 6 | -if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 7 | 7 | exit('No direct script access allowed'); |
| 8 | 8 | } |
| 9 | 9 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function getAvailableSpacesCalculator() |
| 77 | 77 | { |
| 78 | - if(! $this->available_spaces_calculator instanceof EventSpacesCalculator){ |
|
| 78 | + if ( ! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 79 | 79 | $this->available_spaces_calculator = new EventSpacesCalculator($this); |
| 80 | 80 | } |
| 81 | 81 | return $this->available_spaces_calculator; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | public function set_status($new_status = null, $use_default = false) |
| 119 | 119 | { |
| 120 | 120 | // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
| 121 | - if (empty($new_status) && !$use_default) { |
|
| 121 | + if (empty($new_status) && ! $use_default) { |
|
| 122 | 122 | return; |
| 123 | 123 | } |
| 124 | 124 | // get current Event status |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
| 218 | 218 | { |
| 219 | - if (!empty ($this->_Primary_Datetime)) { |
|
| 219 | + if ( ! empty ($this->_Primary_Datetime)) { |
|
| 220 | 220 | return $this->_Primary_Datetime; |
| 221 | 221 | } |
| 222 | 222 | $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | { |
| 240 | 240 | //first get all datetimes |
| 241 | 241 | $datetimes = $this->datetimes_ordered(); |
| 242 | - if (!$datetimes) { |
|
| 242 | + if ( ! $datetimes) { |
|
| 243 | 243 | return array(); |
| 244 | 244 | } |
| 245 | 245 | $datetime_ids = array(); |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | */ |
| 344 | 344 | public function display_ticket_selector() |
| 345 | 345 | { |
| 346 | - return (bool)$this->get('EVT_display_ticket_selector'); |
|
| 346 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | public function default_registration_status() |
| 415 | 415 | { |
| 416 | 416 | $event_default_registration_status = $this->get('EVT_default_registration_status'); |
| 417 | - return !empty($event_default_registration_status) |
|
| 417 | + return ! empty($event_default_registration_status) |
|
| 418 | 418 | ? $event_default_registration_status |
| 419 | 419 | : EE_Registry::instance()->CFG->registration->default_STS_ID; |
| 420 | 420 | } |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
| 431 | 431 | { |
| 432 | 432 | $short_desc = $this->get('EVT_short_desc'); |
| 433 | - if (!empty($short_desc) || $not_full_desc) { |
|
| 433 | + if ( ! empty($short_desc) || $not_full_desc) { |
|
| 434 | 434 | return $short_desc; |
| 435 | 435 | } |
| 436 | 436 | $full_desc = $this->get('EVT_desc'); |
@@ -963,7 +963,7 @@ discard block |
||
| 963 | 963 | */ |
| 964 | 964 | public function is_sold_out($actual = false) |
| 965 | 965 | { |
| 966 | - if (!$actual) { |
|
| 966 | + if ( ! $actual) { |
|
| 967 | 967 | return $this->status() === EEM_Event::sold_out; |
| 968 | 968 | } |
| 969 | 969 | return $this->perform_sold_out_status_check(); |
@@ -1008,11 +1008,11 @@ discard block |
||
| 1008 | 1008 | public function get_active_status($reset = false) |
| 1009 | 1009 | { |
| 1010 | 1010 | // if the active status has already been set, then just use that value (unless we are resetting it) |
| 1011 | - if (!empty($this->_active_status) && !$reset) { |
|
| 1011 | + if ( ! empty($this->_active_status) && ! $reset) { |
|
| 1012 | 1012 | return $this->_active_status; |
| 1013 | 1013 | } |
| 1014 | 1014 | //first check if event id is present on this object |
| 1015 | - if (!$this->ID()) { |
|
| 1015 | + if ( ! $this->ID()) { |
|
| 1016 | 1016 | return false; |
| 1017 | 1017 | } |
| 1018 | 1018 | $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
@@ -1089,7 +1089,7 @@ discard block |
||
| 1089 | 1089 | public function get_number_of_tickets_sold() |
| 1090 | 1090 | { |
| 1091 | 1091 | $tkt_sold = 0; |
| 1092 | - if (!$this->ID()) { |
|
| 1092 | + if ( ! $this->ID()) { |
|
| 1093 | 1093 | return 0; |
| 1094 | 1094 | } |
| 1095 | 1095 | $datetimes = $this->datetimes(); |
@@ -1155,7 +1155,7 @@ discard block |
||
| 1155 | 1155 | { |
| 1156 | 1156 | $earliest_ticket = $this->get_ticket_with_earliest_start_time(); |
| 1157 | 1157 | $latest_ticket = $this->get_ticket_with_latest_end_time(); |
| 1158 | - if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) { |
|
| 1158 | + if ( ! $latest_ticket instanceof EE_Ticket && ! $earliest_ticket instanceof EE_Ticket) { |
|
| 1159 | 1159 | return false; |
| 1160 | 1160 | } |
| 1161 | 1161 | //check on sale for these two tickets. |
@@ -1221,7 +1221,7 @@ discard block |
||
| 1221 | 1221 | */ |
| 1222 | 1222 | public function question_groups($query_params = array()) |
| 1223 | 1223 | { |
| 1224 | - $query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1224 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1225 | 1225 | return $this->get_many_related('Question_Group', $query_params); |
| 1226 | 1226 | } |
| 1227 | 1227 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | /** |
| 328 | 328 | * Get Timezone Transitions |
| 329 | 329 | * @param \DateTimeZone $date_time_zone |
| 330 | - * @param null $time |
|
| 330 | + * @param integer|null $time |
|
| 331 | 331 | * @param bool $first_only |
| 332 | 332 | * @return array|mixed |
| 333 | 333 | */ |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | /** |
| 344 | 344 | * Get Timezone Offset for given timezone object. |
| 345 | 345 | * @param \DateTimeZone $date_time_zone |
| 346 | - * @param null $time |
|
| 346 | + * @param integer|null $time |
|
| 347 | 347 | * @return mixed |
| 348 | 348 | * @throws \DomainException |
| 349 | 349 | */ |
@@ -1075,7 +1075,7 @@ discard block |
||
| 1075 | 1075 | * this method will add that "1" into your date regardless of the format. |
| 1076 | 1076 | * |
| 1077 | 1077 | * @param string $month |
| 1078 | - * @return string |
|
| 1078 | + * @return integer |
|
| 1079 | 1079 | */ |
| 1080 | 1080 | public static function first_of_month_timestamp($month = '') |
| 1081 | 1081 | { |
@@ -1227,7 +1227,7 @@ discard block |
||
| 1227 | 1227 | /** |
| 1228 | 1228 | * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
| 1229 | 1229 | * |
| 1230 | - * @param int|WP_User $user_id |
|
| 1230 | + * @param integer $user_id |
|
| 1231 | 1231 | * @return string |
| 1232 | 1232 | */ |
| 1233 | 1233 | public static function get_user_locale($user_id = 0) |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -26,364 +26,364 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * return the timezone set for the WP install |
|
| 31 | - * |
|
| 32 | - * @return string valid timezone string for PHP DateTimeZone() class |
|
| 33 | - */ |
|
| 34 | - public static function get_timezone() |
|
| 35 | - { |
|
| 36 | - return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * get_valid_timezone_string |
|
| 42 | - * ensures that a valid timezone string is returned |
|
| 43 | - * |
|
| 44 | - * @access protected |
|
| 45 | - * @param string $timezone_string |
|
| 46 | - * @return string |
|
| 47 | - * @throws \EE_Error |
|
| 48 | - */ |
|
| 49 | - public static function get_valid_timezone_string($timezone_string = '') |
|
| 50 | - { |
|
| 51 | - // if passed a value, then use that, else get WP option |
|
| 52 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 53 | - // value from above exists, use that, else get timezone string from gmt_offset |
|
| 54 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 55 | - EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 56 | - return $timezone_string; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 62 | - * |
|
| 63 | - * @static |
|
| 64 | - * @access public |
|
| 65 | - * @param string $timezone_string Timezone string to check |
|
| 66 | - * @param bool $throw_error |
|
| 67 | - * @return bool |
|
| 68 | - * @throws \EE_Error |
|
| 69 | - */ |
|
| 70 | - public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 71 | - { |
|
| 72 | - // easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it |
|
| 73 | - try { |
|
| 74 | - new DateTimeZone($timezone_string); |
|
| 75 | - } catch (Exception $e) { |
|
| 76 | - // sometimes we take exception to exceptions |
|
| 77 | - if (! $throw_error) { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - throw new EE_Error( |
|
| 81 | - sprintf( |
|
| 82 | - __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 83 | - 'event_espresso'), |
|
| 84 | - $timezone_string, |
|
| 85 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 86 | - '</a>' |
|
| 87 | - ) |
|
| 88 | - ); |
|
| 89 | - } |
|
| 90 | - return true; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * _create_timezone_object_from_timezone_name |
|
| 96 | - * |
|
| 97 | - * @access protected |
|
| 98 | - * @param string $gmt_offset |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 102 | - { |
|
| 103 | - $timezone_string = 'UTC'; |
|
| 104 | - //if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is |
|
| 105 | - //set because it will override `gmt_offset` via `pre_get_option` filter. If that's set, then let's just use |
|
| 106 | - //that! Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic. |
|
| 107 | - if ($gmt_offset === '') { |
|
| 108 | - //autoloaded so no need to set to a variable. There will not be multiple hits to the db. |
|
| 109 | - if (get_option('timezone_string')) { |
|
| 110 | - return get_option('timezone_string'); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - $gmt_offset = $gmt_offset !== '' ? $gmt_offset : get_option('gmt_offset'); |
|
| 114 | - $gmt_offset = (float) $gmt_offset; |
|
| 115 | - |
|
| 116 | - //if $gmt_offset is 0, then just return UTC |
|
| 117 | - if ($gmt_offset === (float) 0) { |
|
| 118 | - return $timezone_string; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - if ($gmt_offset !== '') { |
|
| 123 | - // convert GMT offset to seconds |
|
| 124 | - $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
|
| 125 | - // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 126 | - $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 127 | - //only use this timezone_string IF it's current offset matches the given offset |
|
| 128 | - try { |
|
| 129 | - $offset = self::get_timezone_offset(new DateTimeZone($timezone_string)); |
|
| 130 | - if ($offset !== $gmt_offset) { |
|
| 131 | - $timezone_string = false; |
|
| 132 | - } |
|
| 133 | - } catch (Exception $e) { |
|
| 134 | - $timezone_string = false; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 138 | - $timezone_string = $timezone_string !== false |
|
| 139 | - ? $timezone_string |
|
| 140 | - : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 141 | - return $timezone_string; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Gets the site's GMT offset based on either the timezone string |
|
| 146 | - * (in which case teh gmt offset will vary depending on the location's |
|
| 147 | - * observance of daylight savings time) or the gmt_offset wp option |
|
| 148 | - * |
|
| 149 | - * @return int seconds offset |
|
| 150 | - */ |
|
| 151 | - public static function get_site_timezone_gmt_offset() |
|
| 152 | - { |
|
| 153 | - $timezone_string = get_option('timezone_string'); |
|
| 154 | - if ($timezone_string) { |
|
| 155 | - try { |
|
| 156 | - $timezone = new DateTimeZone($timezone_string); |
|
| 157 | - return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 158 | - } catch (Exception $e) { |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - $offset = get_option('gmt_offset'); |
|
| 162 | - return (int)($offset * HOUR_IN_SECONDS); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Depending on PHP version, there might not bevalid current timezone strings to match these gmt_offsets in its |
|
| 168 | - * timezone tables. |
|
| 169 | - * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
| 170 | - * |
|
| 171 | - * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
| 172 | - * |
|
| 173 | - * @access public |
|
| 174 | - * @param int $gmt_offset |
|
| 175 | - * @return int |
|
| 176 | - */ |
|
| 177 | - public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 178 | - { |
|
| 179 | - //make sure $gmt_offset is int |
|
| 180 | - $gmt_offset = (int)$gmt_offset; |
|
| 181 | - switch ($gmt_offset) { |
|
| 182 | - //-12 |
|
| 183 | - case -43200: |
|
| 184 | - $gmt_offset = -39600; |
|
| 185 | - break; |
|
| 186 | - //-11.5 |
|
| 187 | - case -41400: |
|
| 188 | - $gmt_offset = -39600; |
|
| 189 | - break; |
|
| 190 | - //-10.5 |
|
| 191 | - case -37800: |
|
| 192 | - $gmt_offset = -39600; |
|
| 193 | - break; |
|
| 194 | - //-8.5 |
|
| 195 | - case -30600: |
|
| 196 | - $gmt_offset = -28800; |
|
| 197 | - break; |
|
| 198 | - //-7.5 |
|
| 199 | - case -27000: |
|
| 200 | - $gmt_offset = -25200; |
|
| 201 | - break; |
|
| 202 | - //-6.5 |
|
| 203 | - case -23400: |
|
| 204 | - $gmt_offset = -21600; |
|
| 205 | - break; |
|
| 206 | - //-5.5 |
|
| 207 | - case -19800: |
|
| 208 | - $gmt_offset = -18000; |
|
| 209 | - break; |
|
| 210 | - //-4.5 |
|
| 211 | - case -16200: |
|
| 212 | - $gmt_offset = -14400; |
|
| 213 | - break; |
|
| 214 | - //-3.5 |
|
| 215 | - case -12600: |
|
| 216 | - $gmt_offset = -10800; |
|
| 217 | - break; |
|
| 218 | - //-2.5 |
|
| 219 | - case -9000: |
|
| 220 | - $gmt_offset = -7200; |
|
| 221 | - break; |
|
| 222 | - //-1.5 |
|
| 223 | - case -5400: |
|
| 224 | - $gmt_offset = -3600; |
|
| 225 | - break; |
|
| 226 | - //-0.5 |
|
| 227 | - case -1800: |
|
| 228 | - $gmt_offset = 0; |
|
| 229 | - break; |
|
| 230 | - //.5 |
|
| 231 | - case 1800: |
|
| 232 | - $gmt_offset = 3600; |
|
| 233 | - break; |
|
| 234 | - //1.5 |
|
| 235 | - case 5400: |
|
| 236 | - $gmt_offset = 7200; |
|
| 237 | - break; |
|
| 238 | - //2.5 |
|
| 239 | - case 9000: |
|
| 240 | - $gmt_offset = 10800; |
|
| 241 | - break; |
|
| 242 | - //3.5 |
|
| 243 | - case 12600: |
|
| 244 | - $gmt_offset = 14400; |
|
| 245 | - break; |
|
| 246 | - |
|
| 247 | - //7.5 |
|
| 248 | - case 27000: |
|
| 249 | - $gmt_offset = 28800; |
|
| 250 | - break; |
|
| 251 | - //8.5 |
|
| 252 | - case 30600: |
|
| 253 | - $gmt_offset = 31500; |
|
| 254 | - break; |
|
| 255 | - //10.5 |
|
| 256 | - case 37800: |
|
| 257 | - $gmt_offset = 39600; |
|
| 258 | - break; |
|
| 259 | - //11.5 |
|
| 260 | - case 41400: |
|
| 261 | - $gmt_offset = 43200; |
|
| 262 | - break; |
|
| 263 | - //12.75 |
|
| 264 | - case 45900: |
|
| 265 | - $gmt_offset = 46800; |
|
| 266 | - break; |
|
| 267 | - //13.75 |
|
| 268 | - case 49500: |
|
| 269 | - $gmt_offset = 50400; |
|
| 270 | - break; |
|
| 271 | - } |
|
| 272 | - return $gmt_offset; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * get_timezone_string_from_abbreviations_list |
|
| 278 | - * |
|
| 279 | - * @access public |
|
| 280 | - * @param int $gmt_offset |
|
| 281 | - * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
| 282 | - * @return string |
|
| 283 | - * @throws \EE_Error |
|
| 284 | - */ |
|
| 285 | - public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
| 286 | - { |
|
| 287 | - $abbreviations = timezone_abbreviations_list(); |
|
| 288 | - foreach ($abbreviations as $abbreviation) { |
|
| 289 | - foreach ($abbreviation as $city) { |
|
| 290 | - if ($city['offset'] === $gmt_offset && $city['dst'] === false) { |
|
| 291 | - try { |
|
| 292 | - $offset = self::get_timezone_offset(new DateTimeZone($city['timezone_id'])); |
|
| 293 | - if ($offset !== $gmt_offset) { |
|
| 294 | - continue; |
|
| 295 | - } else { |
|
| 296 | - return $city['timezone_id']; |
|
| 297 | - } |
|
| 298 | - } catch (Exception $e) { |
|
| 299 | - continue; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
| 305 | - if ($coerce == true) { |
|
| 306 | - $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
| 307 | - self::adjust_invalid_gmt_offsets($gmt_offset), |
|
| 308 | - false |
|
| 309 | - ); |
|
| 310 | - if ($timezone_string) { |
|
| 311 | - return $timezone_string; |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - throw new EE_Error( |
|
| 315 | - sprintf( |
|
| 316 | - __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 317 | - 'event_espresso'), |
|
| 318 | - $gmt_offset, |
|
| 319 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 320 | - '</a>' |
|
| 321 | - ) |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Get Timezone Transitions |
|
| 329 | - * @param \DateTimeZone $date_time_zone |
|
| 330 | - * @param null $time |
|
| 331 | - * @param bool $first_only |
|
| 332 | - * @return array|mixed |
|
| 333 | - */ |
|
| 334 | - public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
| 335 | - { |
|
| 336 | - $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
| 337 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 338 | - $transitions = $date_time_zone->getTransitions($time); |
|
| 339 | - return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Get Timezone Offset for given timezone object. |
|
| 345 | - * @param \DateTimeZone $date_time_zone |
|
| 346 | - * @param null $time |
|
| 347 | - * @return mixed |
|
| 348 | - * @throws \DomainException |
|
| 349 | - */ |
|
| 350 | - public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
| 351 | - { |
|
| 352 | - $transitions = self::get_timezone_transitions($date_time_zone, $time); |
|
| 353 | - if (! isset($transitions['offset'])) { |
|
| 354 | - throw new DomainException(); |
|
| 355 | - } |
|
| 356 | - return $transitions['offset']; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @access public |
|
| 362 | - * @param string $timezone_string |
|
| 363 | - */ |
|
| 364 | - public static function timezone_select_input($timezone_string = '') |
|
| 365 | - { |
|
| 366 | - // get WP date time format |
|
| 367 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 368 | - // if passed a value, then use that, else get WP option |
|
| 369 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 370 | - // check if the timezone is valid but don't throw any errors if it isn't |
|
| 371 | - $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 372 | - $gmt_offset = get_option('gmt_offset'); |
|
| 373 | - |
|
| 374 | - $check_zone_info = true; |
|
| 375 | - if (empty($timezone_string)) { |
|
| 376 | - // Create a UTC+- zone if no timezone string exists |
|
| 377 | - $check_zone_info = false; |
|
| 378 | - if ($gmt_offset > 0) { |
|
| 379 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 380 | - } elseif ($gmt_offset < 0) { |
|
| 381 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 382 | - } else { |
|
| 383 | - $timezone_string = 'UTC'; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - ?> |
|
| 29 | + /** |
|
| 30 | + * return the timezone set for the WP install |
|
| 31 | + * |
|
| 32 | + * @return string valid timezone string for PHP DateTimeZone() class |
|
| 33 | + */ |
|
| 34 | + public static function get_timezone() |
|
| 35 | + { |
|
| 36 | + return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * get_valid_timezone_string |
|
| 42 | + * ensures that a valid timezone string is returned |
|
| 43 | + * |
|
| 44 | + * @access protected |
|
| 45 | + * @param string $timezone_string |
|
| 46 | + * @return string |
|
| 47 | + * @throws \EE_Error |
|
| 48 | + */ |
|
| 49 | + public static function get_valid_timezone_string($timezone_string = '') |
|
| 50 | + { |
|
| 51 | + // if passed a value, then use that, else get WP option |
|
| 52 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 53 | + // value from above exists, use that, else get timezone string from gmt_offset |
|
| 54 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 55 | + EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 56 | + return $timezone_string; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 62 | + * |
|
| 63 | + * @static |
|
| 64 | + * @access public |
|
| 65 | + * @param string $timezone_string Timezone string to check |
|
| 66 | + * @param bool $throw_error |
|
| 67 | + * @return bool |
|
| 68 | + * @throws \EE_Error |
|
| 69 | + */ |
|
| 70 | + public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 71 | + { |
|
| 72 | + // easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it |
|
| 73 | + try { |
|
| 74 | + new DateTimeZone($timezone_string); |
|
| 75 | + } catch (Exception $e) { |
|
| 76 | + // sometimes we take exception to exceptions |
|
| 77 | + if (! $throw_error) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + throw new EE_Error( |
|
| 81 | + sprintf( |
|
| 82 | + __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 83 | + 'event_espresso'), |
|
| 84 | + $timezone_string, |
|
| 85 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 86 | + '</a>' |
|
| 87 | + ) |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | + return true; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * _create_timezone_object_from_timezone_name |
|
| 96 | + * |
|
| 97 | + * @access protected |
|
| 98 | + * @param string $gmt_offset |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 102 | + { |
|
| 103 | + $timezone_string = 'UTC'; |
|
| 104 | + //if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is |
|
| 105 | + //set because it will override `gmt_offset` via `pre_get_option` filter. If that's set, then let's just use |
|
| 106 | + //that! Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic. |
|
| 107 | + if ($gmt_offset === '') { |
|
| 108 | + //autoloaded so no need to set to a variable. There will not be multiple hits to the db. |
|
| 109 | + if (get_option('timezone_string')) { |
|
| 110 | + return get_option('timezone_string'); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + $gmt_offset = $gmt_offset !== '' ? $gmt_offset : get_option('gmt_offset'); |
|
| 114 | + $gmt_offset = (float) $gmt_offset; |
|
| 115 | + |
|
| 116 | + //if $gmt_offset is 0, then just return UTC |
|
| 117 | + if ($gmt_offset === (float) 0) { |
|
| 118 | + return $timezone_string; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + if ($gmt_offset !== '') { |
|
| 123 | + // convert GMT offset to seconds |
|
| 124 | + $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
|
| 125 | + // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 126 | + $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 127 | + //only use this timezone_string IF it's current offset matches the given offset |
|
| 128 | + try { |
|
| 129 | + $offset = self::get_timezone_offset(new DateTimeZone($timezone_string)); |
|
| 130 | + if ($offset !== $gmt_offset) { |
|
| 131 | + $timezone_string = false; |
|
| 132 | + } |
|
| 133 | + } catch (Exception $e) { |
|
| 134 | + $timezone_string = false; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 138 | + $timezone_string = $timezone_string !== false |
|
| 139 | + ? $timezone_string |
|
| 140 | + : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 141 | + return $timezone_string; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Gets the site's GMT offset based on either the timezone string |
|
| 146 | + * (in which case teh gmt offset will vary depending on the location's |
|
| 147 | + * observance of daylight savings time) or the gmt_offset wp option |
|
| 148 | + * |
|
| 149 | + * @return int seconds offset |
|
| 150 | + */ |
|
| 151 | + public static function get_site_timezone_gmt_offset() |
|
| 152 | + { |
|
| 153 | + $timezone_string = get_option('timezone_string'); |
|
| 154 | + if ($timezone_string) { |
|
| 155 | + try { |
|
| 156 | + $timezone = new DateTimeZone($timezone_string); |
|
| 157 | + return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 158 | + } catch (Exception $e) { |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + $offset = get_option('gmt_offset'); |
|
| 162 | + return (int)($offset * HOUR_IN_SECONDS); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Depending on PHP version, there might not bevalid current timezone strings to match these gmt_offsets in its |
|
| 168 | + * timezone tables. |
|
| 169 | + * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
| 170 | + * |
|
| 171 | + * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
| 172 | + * |
|
| 173 | + * @access public |
|
| 174 | + * @param int $gmt_offset |
|
| 175 | + * @return int |
|
| 176 | + */ |
|
| 177 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 178 | + { |
|
| 179 | + //make sure $gmt_offset is int |
|
| 180 | + $gmt_offset = (int)$gmt_offset; |
|
| 181 | + switch ($gmt_offset) { |
|
| 182 | + //-12 |
|
| 183 | + case -43200: |
|
| 184 | + $gmt_offset = -39600; |
|
| 185 | + break; |
|
| 186 | + //-11.5 |
|
| 187 | + case -41400: |
|
| 188 | + $gmt_offset = -39600; |
|
| 189 | + break; |
|
| 190 | + //-10.5 |
|
| 191 | + case -37800: |
|
| 192 | + $gmt_offset = -39600; |
|
| 193 | + break; |
|
| 194 | + //-8.5 |
|
| 195 | + case -30600: |
|
| 196 | + $gmt_offset = -28800; |
|
| 197 | + break; |
|
| 198 | + //-7.5 |
|
| 199 | + case -27000: |
|
| 200 | + $gmt_offset = -25200; |
|
| 201 | + break; |
|
| 202 | + //-6.5 |
|
| 203 | + case -23400: |
|
| 204 | + $gmt_offset = -21600; |
|
| 205 | + break; |
|
| 206 | + //-5.5 |
|
| 207 | + case -19800: |
|
| 208 | + $gmt_offset = -18000; |
|
| 209 | + break; |
|
| 210 | + //-4.5 |
|
| 211 | + case -16200: |
|
| 212 | + $gmt_offset = -14400; |
|
| 213 | + break; |
|
| 214 | + //-3.5 |
|
| 215 | + case -12600: |
|
| 216 | + $gmt_offset = -10800; |
|
| 217 | + break; |
|
| 218 | + //-2.5 |
|
| 219 | + case -9000: |
|
| 220 | + $gmt_offset = -7200; |
|
| 221 | + break; |
|
| 222 | + //-1.5 |
|
| 223 | + case -5400: |
|
| 224 | + $gmt_offset = -3600; |
|
| 225 | + break; |
|
| 226 | + //-0.5 |
|
| 227 | + case -1800: |
|
| 228 | + $gmt_offset = 0; |
|
| 229 | + break; |
|
| 230 | + //.5 |
|
| 231 | + case 1800: |
|
| 232 | + $gmt_offset = 3600; |
|
| 233 | + break; |
|
| 234 | + //1.5 |
|
| 235 | + case 5400: |
|
| 236 | + $gmt_offset = 7200; |
|
| 237 | + break; |
|
| 238 | + //2.5 |
|
| 239 | + case 9000: |
|
| 240 | + $gmt_offset = 10800; |
|
| 241 | + break; |
|
| 242 | + //3.5 |
|
| 243 | + case 12600: |
|
| 244 | + $gmt_offset = 14400; |
|
| 245 | + break; |
|
| 246 | + |
|
| 247 | + //7.5 |
|
| 248 | + case 27000: |
|
| 249 | + $gmt_offset = 28800; |
|
| 250 | + break; |
|
| 251 | + //8.5 |
|
| 252 | + case 30600: |
|
| 253 | + $gmt_offset = 31500; |
|
| 254 | + break; |
|
| 255 | + //10.5 |
|
| 256 | + case 37800: |
|
| 257 | + $gmt_offset = 39600; |
|
| 258 | + break; |
|
| 259 | + //11.5 |
|
| 260 | + case 41400: |
|
| 261 | + $gmt_offset = 43200; |
|
| 262 | + break; |
|
| 263 | + //12.75 |
|
| 264 | + case 45900: |
|
| 265 | + $gmt_offset = 46800; |
|
| 266 | + break; |
|
| 267 | + //13.75 |
|
| 268 | + case 49500: |
|
| 269 | + $gmt_offset = 50400; |
|
| 270 | + break; |
|
| 271 | + } |
|
| 272 | + return $gmt_offset; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * get_timezone_string_from_abbreviations_list |
|
| 278 | + * |
|
| 279 | + * @access public |
|
| 280 | + * @param int $gmt_offset |
|
| 281 | + * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
| 282 | + * @return string |
|
| 283 | + * @throws \EE_Error |
|
| 284 | + */ |
|
| 285 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
| 286 | + { |
|
| 287 | + $abbreviations = timezone_abbreviations_list(); |
|
| 288 | + foreach ($abbreviations as $abbreviation) { |
|
| 289 | + foreach ($abbreviation as $city) { |
|
| 290 | + if ($city['offset'] === $gmt_offset && $city['dst'] === false) { |
|
| 291 | + try { |
|
| 292 | + $offset = self::get_timezone_offset(new DateTimeZone($city['timezone_id'])); |
|
| 293 | + if ($offset !== $gmt_offset) { |
|
| 294 | + continue; |
|
| 295 | + } else { |
|
| 296 | + return $city['timezone_id']; |
|
| 297 | + } |
|
| 298 | + } catch (Exception $e) { |
|
| 299 | + continue; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
| 305 | + if ($coerce == true) { |
|
| 306 | + $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
| 307 | + self::adjust_invalid_gmt_offsets($gmt_offset), |
|
| 308 | + false |
|
| 309 | + ); |
|
| 310 | + if ($timezone_string) { |
|
| 311 | + return $timezone_string; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + throw new EE_Error( |
|
| 315 | + sprintf( |
|
| 316 | + __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 317 | + 'event_espresso'), |
|
| 318 | + $gmt_offset, |
|
| 319 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 320 | + '</a>' |
|
| 321 | + ) |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Get Timezone Transitions |
|
| 329 | + * @param \DateTimeZone $date_time_zone |
|
| 330 | + * @param null $time |
|
| 331 | + * @param bool $first_only |
|
| 332 | + * @return array|mixed |
|
| 333 | + */ |
|
| 334 | + public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
| 335 | + { |
|
| 336 | + $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
| 337 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 338 | + $transitions = $date_time_zone->getTransitions($time); |
|
| 339 | + return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Get Timezone Offset for given timezone object. |
|
| 345 | + * @param \DateTimeZone $date_time_zone |
|
| 346 | + * @param null $time |
|
| 347 | + * @return mixed |
|
| 348 | + * @throws \DomainException |
|
| 349 | + */ |
|
| 350 | + public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
| 351 | + { |
|
| 352 | + $transitions = self::get_timezone_transitions($date_time_zone, $time); |
|
| 353 | + if (! isset($transitions['offset'])) { |
|
| 354 | + throw new DomainException(); |
|
| 355 | + } |
|
| 356 | + return $transitions['offset']; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @access public |
|
| 362 | + * @param string $timezone_string |
|
| 363 | + */ |
|
| 364 | + public static function timezone_select_input($timezone_string = '') |
|
| 365 | + { |
|
| 366 | + // get WP date time format |
|
| 367 | + $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 368 | + // if passed a value, then use that, else get WP option |
|
| 369 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 370 | + // check if the timezone is valid but don't throw any errors if it isn't |
|
| 371 | + $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 372 | + $gmt_offset = get_option('gmt_offset'); |
|
| 373 | + |
|
| 374 | + $check_zone_info = true; |
|
| 375 | + if (empty($timezone_string)) { |
|
| 376 | + // Create a UTC+- zone if no timezone string exists |
|
| 377 | + $check_zone_info = false; |
|
| 378 | + if ($gmt_offset > 0) { |
|
| 379 | + $timezone_string = 'UTC+' . $gmt_offset; |
|
| 380 | + } elseif ($gmt_offset < 0) { |
|
| 381 | + $timezone_string = 'UTC' . $gmt_offset; |
|
| 382 | + } else { |
|
| 383 | + $timezone_string = 'UTC'; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + ?> |
|
| 387 | 387 | |
| 388 | 388 | <p> |
| 389 | 389 | <label for="timezone_string"><?php _e('timezone'); ?></label> |
@@ -396,13 +396,13 @@ discard block |
||
| 396 | 396 | |
| 397 | 397 | <p> |
| 398 | 398 | <span><?php |
| 399 | - printf( |
|
| 400 | - __('%1$sUTC%2$s time is %3$s'), |
|
| 401 | - '<abbr title="Coordinated Universal Time">', |
|
| 402 | - '</abbr>', |
|
| 403 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 404 | - ); |
|
| 405 | - ?></span> |
|
| 399 | + printf( |
|
| 400 | + __('%1$sUTC%2$s time is %3$s'), |
|
| 401 | + '<abbr title="Coordinated Universal Time">', |
|
| 402 | + '</abbr>', |
|
| 403 | + '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 404 | + ); |
|
| 405 | + ?></span> |
|
| 406 | 406 | <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
| 407 | 407 | <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
| 408 | 408 | <?php endif; ?> |
@@ -411,693 +411,693 @@ discard block |
||
| 411 | 411 | <br/> |
| 412 | 412 | <span> |
| 413 | 413 | <?php |
| 414 | - // Set TZ so localtime works. |
|
| 415 | - date_default_timezone_set($timezone_string); |
|
| 416 | - $now = localtime(time(), true); |
|
| 417 | - if ($now['tm_isdst']) { |
|
| 418 | - _e('This timezone is currently in daylight saving time.'); |
|
| 419 | - } else { |
|
| 420 | - _e('This timezone is currently in standard time.'); |
|
| 421 | - } |
|
| 422 | - ?> |
|
| 414 | + // Set TZ so localtime works. |
|
| 415 | + date_default_timezone_set($timezone_string); |
|
| 416 | + $now = localtime(time(), true); |
|
| 417 | + if ($now['tm_isdst']) { |
|
| 418 | + _e('This timezone is currently in daylight saving time.'); |
|
| 419 | + } else { |
|
| 420 | + _e('This timezone is currently in standard time.'); |
|
| 421 | + } |
|
| 422 | + ?> |
|
| 423 | 423 | <br/> |
| 424 | 424 | <?php |
| 425 | - if (function_exists('timezone_transitions_get')) { |
|
| 426 | - $found = false; |
|
| 427 | - $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 428 | - $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 429 | - $right_now = time(); |
|
| 430 | - $tr['isdst'] = false; |
|
| 431 | - foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 432 | - if ($tr['ts'] > $right_now) { |
|
| 433 | - $found = true; |
|
| 434 | - break; |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - if ($found) { |
|
| 439 | - $message = $tr['isdst'] ? |
|
| 440 | - __(' Daylight saving time begins on: %s.') : |
|
| 441 | - __(' Standard time begins on: %s.'); |
|
| 442 | - // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
|
| 443 | - printf($message, |
|
| 444 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 445 | - } else { |
|
| 446 | - _e('This timezone does not observe daylight saving time.'); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - // Set back to UTC. |
|
| 450 | - date_default_timezone_set('UTC'); |
|
| 451 | - ?> |
|
| 425 | + if (function_exists('timezone_transitions_get')) { |
|
| 426 | + $found = false; |
|
| 427 | + $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 428 | + $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 429 | + $right_now = time(); |
|
| 430 | + $tr['isdst'] = false; |
|
| 431 | + foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 432 | + if ($tr['ts'] > $right_now) { |
|
| 433 | + $found = true; |
|
| 434 | + break; |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + if ($found) { |
|
| 439 | + $message = $tr['isdst'] ? |
|
| 440 | + __(' Daylight saving time begins on: %s.') : |
|
| 441 | + __(' Standard time begins on: %s.'); |
|
| 442 | + // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
|
| 443 | + printf($message, |
|
| 444 | + '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 445 | + } else { |
|
| 446 | + _e('This timezone does not observe daylight saving time.'); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + // Set back to UTC. |
|
| 450 | + date_default_timezone_set('UTC'); |
|
| 451 | + ?> |
|
| 452 | 452 | </span></p> |
| 453 | 453 | <?php |
| 454 | - endif; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 460 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 461 | - * the site is used. |
|
| 462 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 463 | - * computed timestamp (i.e. date_i18n() ) |
|
| 464 | - * |
|
| 465 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
| 466 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 467 | - * site will be used. |
|
| 468 | - * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 469 | - */ |
|
| 470 | - public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 471 | - { |
|
| 472 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 473 | - $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 474 | - $TimeZone = new DateTimeZone($timezone_string); |
|
| 475 | - |
|
| 476 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 477 | - $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 478 | - return (int)$DateTime->format('U') + (int)$offset; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * _set_date_time_field |
|
| 484 | - * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 485 | - * |
|
| 486 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 487 | - * @param DateTime $DateTime PHP DateTime object |
|
| 488 | - * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 489 | - * @return EE_Base_Class |
|
| 490 | - */ |
|
| 491 | - protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 492 | - { |
|
| 493 | - // grab current datetime format |
|
| 494 | - $current_format = $obj->get_format(); |
|
| 495 | - // set new full timestamp format |
|
| 496 | - $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 497 | - $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 498 | - // set the new date value using a full timestamp format so that no data is lost |
|
| 499 | - $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 500 | - // reset datetime formats |
|
| 501 | - $obj->set_date_format($current_format[0]); |
|
| 502 | - $obj->set_time_format($current_format[1]); |
|
| 503 | - return $obj; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * date_time_add |
|
| 509 | - * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 510 | - * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 511 | - * |
|
| 512 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 513 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 514 | - * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 515 | - * minutes, seconds) defaults to years |
|
| 516 | - * @param integer $value what you want to increment the time by |
|
| 517 | - * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 518 | - * (chaining) |
|
| 519 | - */ |
|
| 520 | - public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 521 | - { |
|
| 522 | - //get the raw UTC date. |
|
| 523 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 524 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 525 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * date_time_subtract |
|
| 531 | - * same as date_time_add except subtracting value instead of adding. |
|
| 532 | - * |
|
| 533 | - * @param \EE_Base_Class $obj |
|
| 534 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 535 | - * @param string $period |
|
| 536 | - * @param int $value |
|
| 537 | - * @return \EE_Base_Class |
|
| 538 | - */ |
|
| 539 | - public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 540 | - { |
|
| 541 | - //get the raw UTC date |
|
| 542 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 543 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 544 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 550 | - * |
|
| 551 | - * @param DateTime $DateTime DateTime object |
|
| 552 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 553 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 554 | - * @param integer $value What you want to increment the date by |
|
| 555 | - * @param string $operand What operand you wish to use for the calculation |
|
| 556 | - * @return \DateTime return whatever type came in. |
|
| 557 | - * @throws \EE_Error |
|
| 558 | - */ |
|
| 559 | - protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 560 | - { |
|
| 561 | - if (! $DateTime instanceof DateTime) { |
|
| 562 | - throw new EE_Error( |
|
| 563 | - sprintf( |
|
| 564 | - __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 565 | - print_r($DateTime, true) |
|
| 566 | - ) |
|
| 567 | - ); |
|
| 568 | - } |
|
| 569 | - switch ($period) { |
|
| 570 | - case 'years' : |
|
| 571 | - $value = 'P' . $value . 'Y'; |
|
| 572 | - break; |
|
| 573 | - case 'months' : |
|
| 574 | - $value = 'P' . $value . 'M'; |
|
| 575 | - break; |
|
| 576 | - case 'weeks' : |
|
| 577 | - $value = 'P' . $value . 'W'; |
|
| 578 | - break; |
|
| 579 | - case 'days' : |
|
| 580 | - $value = 'P' . $value . 'D'; |
|
| 581 | - break; |
|
| 582 | - case 'hours' : |
|
| 583 | - $value = 'PT' . $value . 'H'; |
|
| 584 | - break; |
|
| 585 | - case 'minutes' : |
|
| 586 | - $value = 'PT' . $value . 'M'; |
|
| 587 | - break; |
|
| 588 | - case 'seconds' : |
|
| 589 | - $value = 'PT' . $value . 'S'; |
|
| 590 | - break; |
|
| 591 | - } |
|
| 592 | - switch ($operand) { |
|
| 593 | - case '+': |
|
| 594 | - $DateTime->add(new DateInterval($value)); |
|
| 595 | - break; |
|
| 596 | - case '-': |
|
| 597 | - $DateTime->sub(new DateInterval($value)); |
|
| 598 | - break; |
|
| 599 | - } |
|
| 600 | - return $DateTime; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 606 | - * |
|
| 607 | - * @param int $timestamp Unix timestamp |
|
| 608 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 609 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 610 | - * @param integer $value What you want to increment the date by |
|
| 611 | - * @param string $operand What operand you wish to use for the calculation |
|
| 612 | - * @return \DateTime return whatever type came in. |
|
| 613 | - * @throws \EE_Error |
|
| 614 | - */ |
|
| 615 | - protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 616 | - { |
|
| 617 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 618 | - throw new EE_Error( |
|
| 619 | - sprintf( |
|
| 620 | - __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 621 | - print_r($timestamp, true) |
|
| 622 | - ) |
|
| 623 | - ); |
|
| 624 | - } |
|
| 625 | - switch ($period) { |
|
| 626 | - case 'years' : |
|
| 627 | - $value = YEAR_IN_SECONDS * $value; |
|
| 628 | - break; |
|
| 629 | - case 'months' : |
|
| 630 | - $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 631 | - break; |
|
| 632 | - case 'weeks' : |
|
| 633 | - $value = WEEK_IN_SECONDS * $value; |
|
| 634 | - break; |
|
| 635 | - case 'days' : |
|
| 636 | - $value = DAY_IN_SECONDS * $value; |
|
| 637 | - break; |
|
| 638 | - case 'hours' : |
|
| 639 | - $value = HOUR_IN_SECONDS * $value; |
|
| 640 | - break; |
|
| 641 | - case 'minutes' : |
|
| 642 | - $value = MINUTE_IN_SECONDS * $value; |
|
| 643 | - break; |
|
| 644 | - } |
|
| 645 | - switch ($operand) { |
|
| 646 | - case '+': |
|
| 647 | - $timestamp += $value; |
|
| 648 | - break; |
|
| 649 | - case '-': |
|
| 650 | - $timestamp -= $value; |
|
| 651 | - break; |
|
| 652 | - } |
|
| 653 | - return $timestamp; |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 659 | - * parameters and returns the new timestamp or DateTime. |
|
| 660 | - * |
|
| 661 | - * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 662 | - * @param string $period a value to indicate what interval is being used in the |
|
| 663 | - * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 664 | - * 'minutes', 'seconds'. Defaults to years. |
|
| 665 | - * @param integer $value What you want to increment the date by |
|
| 666 | - * @param string $operand What operand you wish to use for the calculation |
|
| 667 | - * @return mixed string|DateTime return whatever type came in. |
|
| 668 | - */ |
|
| 669 | - public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 670 | - { |
|
| 671 | - if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 672 | - return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 673 | - } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 674 | - return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 675 | - } else { |
|
| 676 | - //error |
|
| 677 | - return $DateTime_or_timestamp; |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 684 | - * and spit out the js and moment.js equivalent formats. |
|
| 685 | - * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 686 | - * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 687 | - * time picker. |
|
| 688 | - * |
|
| 689 | - * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 690 | - * @param null $date_format_string |
|
| 691 | - * @param null $time_format_string |
|
| 692 | - * @return array |
|
| 693 | - * array( |
|
| 694 | - * 'js' => array ( |
|
| 695 | - * 'date' => //date format |
|
| 696 | - * 'time' => //time format |
|
| 697 | - * ), |
|
| 698 | - * 'moment' => //date and time format. |
|
| 699 | - * ) |
|
| 700 | - */ |
|
| 701 | - public static function convert_php_to_js_and_moment_date_formats( |
|
| 702 | - $date_format_string = null, |
|
| 703 | - $time_format_string = null |
|
| 704 | - ) { |
|
| 705 | - if ($date_format_string === null) { |
|
| 706 | - $date_format_string = get_option('date_format'); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - if ($time_format_string === null) { |
|
| 710 | - $time_format_string = get_option('time_format'); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 714 | - $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 715 | - |
|
| 716 | - return array( |
|
| 717 | - 'js' => array( |
|
| 718 | - 'date' => $date_format['js'], |
|
| 719 | - 'time' => $time_format['js'], |
|
| 720 | - ), |
|
| 721 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 722 | - ); |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * This converts incoming format string into js and moment variations. |
|
| 728 | - * |
|
| 729 | - * @param string $format_string incoming php format string |
|
| 730 | - * @return array js and moment formats. |
|
| 731 | - */ |
|
| 732 | - protected static function _php_to_js_moment_converter($format_string) |
|
| 733 | - { |
|
| 734 | - /** |
|
| 735 | - * This is a map of symbols for formats. |
|
| 736 | - * The index is the php symbol, the equivalent values are in the array. |
|
| 737 | - * |
|
| 738 | - * @var array |
|
| 739 | - */ |
|
| 740 | - $symbols_map = array( |
|
| 741 | - // Day |
|
| 742 | - //01 |
|
| 743 | - 'd' => array( |
|
| 744 | - 'js' => 'dd', |
|
| 745 | - 'moment' => 'DD', |
|
| 746 | - ), |
|
| 747 | - //Mon |
|
| 748 | - 'D' => array( |
|
| 749 | - 'js' => 'D', |
|
| 750 | - 'moment' => 'ddd', |
|
| 751 | - ), |
|
| 752 | - //1,2,...31 |
|
| 753 | - 'j' => array( |
|
| 754 | - 'js' => 'd', |
|
| 755 | - 'moment' => 'D', |
|
| 756 | - ), |
|
| 757 | - //Monday |
|
| 758 | - 'l' => array( |
|
| 759 | - 'js' => 'DD', |
|
| 760 | - 'moment' => 'dddd', |
|
| 761 | - ), |
|
| 762 | - //ISO numeric representation of the day of the week (1-6) |
|
| 763 | - 'N' => array( |
|
| 764 | - 'js' => '', |
|
| 765 | - 'moment' => 'E', |
|
| 766 | - ), |
|
| 767 | - //st,nd.rd |
|
| 768 | - 'S' => array( |
|
| 769 | - 'js' => '', |
|
| 770 | - 'moment' => 'o', |
|
| 771 | - ), |
|
| 772 | - //numeric representation of day of week (0-6) |
|
| 773 | - 'w' => array( |
|
| 774 | - 'js' => '', |
|
| 775 | - 'moment' => 'd', |
|
| 776 | - ), |
|
| 777 | - //day of year starting from 0 (0-365) |
|
| 778 | - 'z' => array( |
|
| 779 | - 'js' => 'o', |
|
| 780 | - 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 781 | - ), |
|
| 782 | - // Week |
|
| 783 | - //ISO-8601 week number of year (weeks starting on monday) |
|
| 784 | - 'W' => array( |
|
| 785 | - 'js' => '', |
|
| 786 | - 'moment' => 'w', |
|
| 787 | - ), |
|
| 788 | - // Month |
|
| 789 | - // January...December |
|
| 790 | - 'F' => array( |
|
| 791 | - 'js' => 'MM', |
|
| 792 | - 'moment' => 'MMMM', |
|
| 793 | - ), |
|
| 794 | - //01...12 |
|
| 795 | - 'm' => array( |
|
| 796 | - 'js' => 'mm', |
|
| 797 | - 'moment' => 'MM', |
|
| 798 | - ), |
|
| 799 | - //Jan...Dec |
|
| 800 | - 'M' => array( |
|
| 801 | - 'js' => 'M', |
|
| 802 | - 'moment' => 'MMM', |
|
| 803 | - ), |
|
| 804 | - //1-12 |
|
| 805 | - 'n' => array( |
|
| 806 | - 'js' => 'm', |
|
| 807 | - 'moment' => 'M', |
|
| 808 | - ), |
|
| 809 | - //number of days in given month |
|
| 810 | - 't' => array( |
|
| 811 | - 'js' => '', |
|
| 812 | - 'moment' => '', |
|
| 813 | - ), |
|
| 814 | - // Year |
|
| 815 | - //whether leap year or not 1/0 |
|
| 816 | - 'L' => array( |
|
| 817 | - 'js' => '', |
|
| 818 | - 'moment' => '', |
|
| 819 | - ), |
|
| 820 | - //ISO-8601 year number |
|
| 821 | - 'o' => array( |
|
| 822 | - 'js' => '', |
|
| 823 | - 'moment' => 'GGGG', |
|
| 824 | - ), |
|
| 825 | - //1999...2003 |
|
| 826 | - 'Y' => array( |
|
| 827 | - 'js' => 'yy', |
|
| 828 | - 'moment' => 'YYYY', |
|
| 829 | - ), |
|
| 830 | - //99...03 |
|
| 831 | - 'y' => array( |
|
| 832 | - 'js' => 'y', |
|
| 833 | - 'moment' => 'YY', |
|
| 834 | - ), |
|
| 835 | - // Time |
|
| 836 | - // am/pm |
|
| 837 | - 'a' => array( |
|
| 838 | - 'js' => 'tt', |
|
| 839 | - 'moment' => 'a', |
|
| 840 | - ), |
|
| 841 | - // AM/PM |
|
| 842 | - 'A' => array( |
|
| 843 | - 'js' => 'TT', |
|
| 844 | - 'moment' => 'A', |
|
| 845 | - ), |
|
| 846 | - // Swatch Internet Time?!? |
|
| 847 | - 'B' => array( |
|
| 848 | - 'js' => '', |
|
| 849 | - 'moment' => '', |
|
| 850 | - ), |
|
| 851 | - //1...12 |
|
| 852 | - 'g' => array( |
|
| 853 | - 'js' => 'h', |
|
| 854 | - 'moment' => 'h', |
|
| 855 | - ), |
|
| 856 | - //0...23 |
|
| 857 | - 'G' => array( |
|
| 858 | - 'js' => 'H', |
|
| 859 | - 'moment' => 'H', |
|
| 860 | - ), |
|
| 861 | - //01...12 |
|
| 862 | - 'h' => array( |
|
| 863 | - 'js' => 'hh', |
|
| 864 | - 'moment' => 'hh', |
|
| 865 | - ), |
|
| 866 | - //00...23 |
|
| 867 | - 'H' => array( |
|
| 868 | - 'js' => 'HH', |
|
| 869 | - 'moment' => 'HH', |
|
| 870 | - ), |
|
| 871 | - //00..59 |
|
| 872 | - 'i' => array( |
|
| 873 | - 'js' => 'mm', |
|
| 874 | - 'moment' => 'mm', |
|
| 875 | - ), |
|
| 876 | - //seconds... 00...59 |
|
| 877 | - 's' => array( |
|
| 878 | - 'js' => 'ss', |
|
| 879 | - 'moment' => 'ss', |
|
| 880 | - ), |
|
| 881 | - //microseconds |
|
| 882 | - 'u' => array( |
|
| 883 | - 'js' => '', |
|
| 884 | - 'moment' => '', |
|
| 885 | - ), |
|
| 886 | - ); |
|
| 887 | - $jquery_ui_format = ""; |
|
| 888 | - $moment_format = ""; |
|
| 889 | - $escaping = false; |
|
| 890 | - for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 891 | - $char = $format_string[$i]; |
|
| 892 | - if ($char === '\\') { // PHP date format escaping character |
|
| 893 | - $i++; |
|
| 894 | - if ($escaping) { |
|
| 895 | - $jquery_ui_format .= $format_string[$i]; |
|
| 896 | - $moment_format .= $format_string[$i]; |
|
| 897 | - } else { |
|
| 898 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 899 | - $moment_format .= $format_string[$i]; |
|
| 900 | - } |
|
| 901 | - $escaping = true; |
|
| 902 | - } else { |
|
| 903 | - if ($escaping) { |
|
| 904 | - $jquery_ui_format .= "'"; |
|
| 905 | - $moment_format .= "'"; |
|
| 906 | - $escaping = false; |
|
| 907 | - } |
|
| 908 | - if (isset($symbols_map[$char])) { |
|
| 909 | - $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 910 | - $moment_format .= $symbols_map[$char]['moment']; |
|
| 911 | - } else { |
|
| 912 | - $jquery_ui_format .= $char; |
|
| 913 | - $moment_format .= $char; |
|
| 914 | - } |
|
| 915 | - } |
|
| 916 | - } |
|
| 917 | - return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 923 | - * |
|
| 924 | - * @param string $format_string Incoming format string for php date(). |
|
| 925 | - * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 926 | - * errors is returned. So for client code calling, check for is_array() to |
|
| 927 | - * indicate failed validations. |
|
| 928 | - */ |
|
| 929 | - public static function validate_format_string($format_string) |
|
| 930 | - { |
|
| 931 | - $error_msg = array(); |
|
| 932 | - //time format checks |
|
| 933 | - switch (true) { |
|
| 934 | - case strpos($format_string, 'h') !== false : |
|
| 935 | - case strpos($format_string, 'g') !== false : |
|
| 936 | - /** |
|
| 937 | - * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 938 | - * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 939 | - * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 940 | - */ |
|
| 941 | - if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 942 | - $error_msg[] = __('There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', |
|
| 943 | - 'event_espresso'); |
|
| 944 | - } |
|
| 945 | - break; |
|
| 946 | - |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - return empty($error_msg) ? true : $error_msg; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 955 | - * very next day then this method will return true. |
|
| 956 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 957 | - * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 958 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 959 | - * |
|
| 960 | - * @param mixed $date_1 |
|
| 961 | - * @param mixed $date_2 |
|
| 962 | - * @return bool |
|
| 963 | - */ |
|
| 964 | - public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 965 | - { |
|
| 966 | - |
|
| 967 | - if ( |
|
| 968 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 969 | - ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
|
| 970 | - ) { |
|
| 971 | - return false; |
|
| 972 | - } |
|
| 973 | - return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false; |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 979 | - * Functions. |
|
| 980 | - * |
|
| 981 | - * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 982 | - * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 983 | - * @return string |
|
| 984 | - */ |
|
| 985 | - public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 986 | - { |
|
| 987 | - try { |
|
| 988 | - /** need to account for timezone offset on the selects */ |
|
| 989 | - $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 990 | - } catch (Exception $e) { |
|
| 991 | - $DateTimeZone = null; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - /** |
|
| 995 | - * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 996 | - * Hence we do the calc for DateTimeZone::getOffset. |
|
| 997 | - */ |
|
| 998 | - $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 999 | - $query_interval = $offset < 0 |
|
| 1000 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1001 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 1002 | - return $query_interval; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - /** |
|
| 1006 | - * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 1007 | - * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 1008 | - * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 1009 | - * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 1010 | - * (although note that we remove any HTML that may be added) |
|
| 1011 | - * |
|
| 1012 | - * @return string |
|
| 1013 | - */ |
|
| 1014 | - public static function get_timezone_string_for_display() |
|
| 1015 | - { |
|
| 1016 | - $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 1017 | - if (! empty($pretty_timezone)) { |
|
| 1018 | - return esc_html($pretty_timezone); |
|
| 1019 | - } |
|
| 1020 | - $timezone_string = get_option('timezone_string'); |
|
| 1021 | - if ($timezone_string) { |
|
| 1022 | - static $mo_loaded = false; |
|
| 1023 | - // Load translations for continents and cities just like wp_timezone_choice does |
|
| 1024 | - if (! $mo_loaded) { |
|
| 1025 | - $locale = get_locale(); |
|
| 1026 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1027 | - load_textdomain('continents-cities', $mofile); |
|
| 1028 | - $mo_loaded = true; |
|
| 1029 | - } |
|
| 1030 | - //well that was easy. |
|
| 1031 | - $parts = explode('/', $timezone_string); |
|
| 1032 | - //remove the continent |
|
| 1033 | - unset($parts[0]); |
|
| 1034 | - $t_parts = array(); |
|
| 1035 | - foreach ($parts as $part) { |
|
| 1036 | - $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 1037 | - } |
|
| 1038 | - return implode(' - ', $t_parts); |
|
| 1039 | - } |
|
| 1040 | - //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 1041 | - $gmt_offset = get_option('gmt_offset'); |
|
| 1042 | - if (intval($gmt_offset) >= 0) { |
|
| 1043 | - $prefix = '+'; |
|
| 1044 | - } else { |
|
| 1045 | - $prefix = ''; |
|
| 1046 | - } |
|
| 1047 | - $parts = explode('.', (string)$gmt_offset); |
|
| 1048 | - if (count($parts) === 1) { |
|
| 1049 | - $parts[1] = '00'; |
|
| 1050 | - } else { |
|
| 1051 | - //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 1052 | - //to minutes, eg 30 or 15, respectively |
|
| 1053 | - $hour_fraction = (float)('0.' . $parts[1]); |
|
| 1054 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 1055 | - } |
|
| 1056 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - /** |
|
| 1062 | - * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 1063 | - * for a month using a string like "February" or "February 2017", |
|
| 1064 | - * and you don't specify a day as part of your string, |
|
| 1065 | - * then PHP will use whatever the current day of the month is. |
|
| 1066 | - * IF the current day of the month happens to be the 30th or 31st, |
|
| 1067 | - * then PHP gets really confused by a date like February 30, |
|
| 1068 | - * so instead of saying |
|
| 1069 | - * "Hey February only has 28 days (this year)... |
|
| 1070 | - * ...you must have meant the last day of the month!" |
|
| 1071 | - * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 1072 | - * because someone requesting February 30th obviously meant March 1st! |
|
| 1073 | - * The way around this is to always set the day to the first, |
|
| 1074 | - * so that the month will stay on the month you wanted. |
|
| 1075 | - * this method will add that "1" into your date regardless of the format. |
|
| 1076 | - * |
|
| 1077 | - * @param string $month |
|
| 1078 | - * @return string |
|
| 1079 | - */ |
|
| 1080 | - public static function first_of_month_timestamp($month = '') |
|
| 1081 | - { |
|
| 1082 | - $month = (string)$month; |
|
| 1083 | - $year = ''; |
|
| 1084 | - // check if the incoming string has a year in it or not |
|
| 1085 | - if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 1086 | - $year = $matches[0]; |
|
| 1087 | - // ten remove that from the month string as well as any spaces |
|
| 1088 | - $month = trim(str_replace($year, '', $month)); |
|
| 1089 | - // add a space before the year |
|
| 1090 | - $year = " {$year}"; |
|
| 1091 | - } |
|
| 1092 | - // return timestamp for something like "February 1 2017" |
|
| 1093 | - return strtotime("{$month} 1{$year}"); |
|
| 1094 | - } |
|
| 454 | + endif; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 460 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 461 | + * the site is used. |
|
| 462 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 463 | + * computed timestamp (i.e. date_i18n() ) |
|
| 464 | + * |
|
| 465 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
| 466 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 467 | + * site will be used. |
|
| 468 | + * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 469 | + */ |
|
| 470 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 471 | + { |
|
| 472 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 473 | + $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 474 | + $TimeZone = new DateTimeZone($timezone_string); |
|
| 475 | + |
|
| 476 | + $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 477 | + $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 478 | + return (int)$DateTime->format('U') + (int)$offset; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * _set_date_time_field |
|
| 484 | + * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 485 | + * |
|
| 486 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 487 | + * @param DateTime $DateTime PHP DateTime object |
|
| 488 | + * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 489 | + * @return EE_Base_Class |
|
| 490 | + */ |
|
| 491 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 492 | + { |
|
| 493 | + // grab current datetime format |
|
| 494 | + $current_format = $obj->get_format(); |
|
| 495 | + // set new full timestamp format |
|
| 496 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 497 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 498 | + // set the new date value using a full timestamp format so that no data is lost |
|
| 499 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 500 | + // reset datetime formats |
|
| 501 | + $obj->set_date_format($current_format[0]); |
|
| 502 | + $obj->set_time_format($current_format[1]); |
|
| 503 | + return $obj; |
|
| 504 | + } |
|
| 505 | + |
|
| 1095 | 506 | |
| 1096 | 507 | /** |
| 1097 | - * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
| 1098 | - * for this sites timezone, but the timestamp could be some other time GMT. |
|
| 1099 | - */ |
|
| 1100 | - public static function tomorrow() |
|
| 508 | + * date_time_add |
|
| 509 | + * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 510 | + * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 511 | + * |
|
| 512 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 513 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 514 | + * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 515 | + * minutes, seconds) defaults to years |
|
| 516 | + * @param integer $value what you want to increment the time by |
|
| 517 | + * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 518 | + * (chaining) |
|
| 519 | + */ |
|
| 520 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 521 | + { |
|
| 522 | + //get the raw UTC date. |
|
| 523 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 524 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 525 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * date_time_subtract |
|
| 531 | + * same as date_time_add except subtracting value instead of adding. |
|
| 532 | + * |
|
| 533 | + * @param \EE_Base_Class $obj |
|
| 534 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 535 | + * @param string $period |
|
| 536 | + * @param int $value |
|
| 537 | + * @return \EE_Base_Class |
|
| 538 | + */ |
|
| 539 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 540 | + { |
|
| 541 | + //get the raw UTC date |
|
| 542 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 543 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 544 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 550 | + * |
|
| 551 | + * @param DateTime $DateTime DateTime object |
|
| 552 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 553 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 554 | + * @param integer $value What you want to increment the date by |
|
| 555 | + * @param string $operand What operand you wish to use for the calculation |
|
| 556 | + * @return \DateTime return whatever type came in. |
|
| 557 | + * @throws \EE_Error |
|
| 558 | + */ |
|
| 559 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 560 | + { |
|
| 561 | + if (! $DateTime instanceof DateTime) { |
|
| 562 | + throw new EE_Error( |
|
| 563 | + sprintf( |
|
| 564 | + __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 565 | + print_r($DateTime, true) |
|
| 566 | + ) |
|
| 567 | + ); |
|
| 568 | + } |
|
| 569 | + switch ($period) { |
|
| 570 | + case 'years' : |
|
| 571 | + $value = 'P' . $value . 'Y'; |
|
| 572 | + break; |
|
| 573 | + case 'months' : |
|
| 574 | + $value = 'P' . $value . 'M'; |
|
| 575 | + break; |
|
| 576 | + case 'weeks' : |
|
| 577 | + $value = 'P' . $value . 'W'; |
|
| 578 | + break; |
|
| 579 | + case 'days' : |
|
| 580 | + $value = 'P' . $value . 'D'; |
|
| 581 | + break; |
|
| 582 | + case 'hours' : |
|
| 583 | + $value = 'PT' . $value . 'H'; |
|
| 584 | + break; |
|
| 585 | + case 'minutes' : |
|
| 586 | + $value = 'PT' . $value . 'M'; |
|
| 587 | + break; |
|
| 588 | + case 'seconds' : |
|
| 589 | + $value = 'PT' . $value . 'S'; |
|
| 590 | + break; |
|
| 591 | + } |
|
| 592 | + switch ($operand) { |
|
| 593 | + case '+': |
|
| 594 | + $DateTime->add(new DateInterval($value)); |
|
| 595 | + break; |
|
| 596 | + case '-': |
|
| 597 | + $DateTime->sub(new DateInterval($value)); |
|
| 598 | + break; |
|
| 599 | + } |
|
| 600 | + return $DateTime; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 606 | + * |
|
| 607 | + * @param int $timestamp Unix timestamp |
|
| 608 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 609 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 610 | + * @param integer $value What you want to increment the date by |
|
| 611 | + * @param string $operand What operand you wish to use for the calculation |
|
| 612 | + * @return \DateTime return whatever type came in. |
|
| 613 | + * @throws \EE_Error |
|
| 614 | + */ |
|
| 615 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 616 | + { |
|
| 617 | + if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 618 | + throw new EE_Error( |
|
| 619 | + sprintf( |
|
| 620 | + __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 621 | + print_r($timestamp, true) |
|
| 622 | + ) |
|
| 623 | + ); |
|
| 624 | + } |
|
| 625 | + switch ($period) { |
|
| 626 | + case 'years' : |
|
| 627 | + $value = YEAR_IN_SECONDS * $value; |
|
| 628 | + break; |
|
| 629 | + case 'months' : |
|
| 630 | + $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 631 | + break; |
|
| 632 | + case 'weeks' : |
|
| 633 | + $value = WEEK_IN_SECONDS * $value; |
|
| 634 | + break; |
|
| 635 | + case 'days' : |
|
| 636 | + $value = DAY_IN_SECONDS * $value; |
|
| 637 | + break; |
|
| 638 | + case 'hours' : |
|
| 639 | + $value = HOUR_IN_SECONDS * $value; |
|
| 640 | + break; |
|
| 641 | + case 'minutes' : |
|
| 642 | + $value = MINUTE_IN_SECONDS * $value; |
|
| 643 | + break; |
|
| 644 | + } |
|
| 645 | + switch ($operand) { |
|
| 646 | + case '+': |
|
| 647 | + $timestamp += $value; |
|
| 648 | + break; |
|
| 649 | + case '-': |
|
| 650 | + $timestamp -= $value; |
|
| 651 | + break; |
|
| 652 | + } |
|
| 653 | + return $timestamp; |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 659 | + * parameters and returns the new timestamp or DateTime. |
|
| 660 | + * |
|
| 661 | + * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 662 | + * @param string $period a value to indicate what interval is being used in the |
|
| 663 | + * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 664 | + * 'minutes', 'seconds'. Defaults to years. |
|
| 665 | + * @param integer $value What you want to increment the date by |
|
| 666 | + * @param string $operand What operand you wish to use for the calculation |
|
| 667 | + * @return mixed string|DateTime return whatever type came in. |
|
| 668 | + */ |
|
| 669 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 670 | + { |
|
| 671 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 672 | + return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 673 | + } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 674 | + return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 675 | + } else { |
|
| 676 | + //error |
|
| 677 | + return $DateTime_or_timestamp; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 684 | + * and spit out the js and moment.js equivalent formats. |
|
| 685 | + * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 686 | + * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 687 | + * time picker. |
|
| 688 | + * |
|
| 689 | + * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 690 | + * @param null $date_format_string |
|
| 691 | + * @param null $time_format_string |
|
| 692 | + * @return array |
|
| 693 | + * array( |
|
| 694 | + * 'js' => array ( |
|
| 695 | + * 'date' => //date format |
|
| 696 | + * 'time' => //time format |
|
| 697 | + * ), |
|
| 698 | + * 'moment' => //date and time format. |
|
| 699 | + * ) |
|
| 700 | + */ |
|
| 701 | + public static function convert_php_to_js_and_moment_date_formats( |
|
| 702 | + $date_format_string = null, |
|
| 703 | + $time_format_string = null |
|
| 704 | + ) { |
|
| 705 | + if ($date_format_string === null) { |
|
| 706 | + $date_format_string = get_option('date_format'); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + if ($time_format_string === null) { |
|
| 710 | + $time_format_string = get_option('time_format'); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 714 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 715 | + |
|
| 716 | + return array( |
|
| 717 | + 'js' => array( |
|
| 718 | + 'date' => $date_format['js'], |
|
| 719 | + 'time' => $time_format['js'], |
|
| 720 | + ), |
|
| 721 | + 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 722 | + ); |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * This converts incoming format string into js and moment variations. |
|
| 728 | + * |
|
| 729 | + * @param string $format_string incoming php format string |
|
| 730 | + * @return array js and moment formats. |
|
| 731 | + */ |
|
| 732 | + protected static function _php_to_js_moment_converter($format_string) |
|
| 733 | + { |
|
| 734 | + /** |
|
| 735 | + * This is a map of symbols for formats. |
|
| 736 | + * The index is the php symbol, the equivalent values are in the array. |
|
| 737 | + * |
|
| 738 | + * @var array |
|
| 739 | + */ |
|
| 740 | + $symbols_map = array( |
|
| 741 | + // Day |
|
| 742 | + //01 |
|
| 743 | + 'd' => array( |
|
| 744 | + 'js' => 'dd', |
|
| 745 | + 'moment' => 'DD', |
|
| 746 | + ), |
|
| 747 | + //Mon |
|
| 748 | + 'D' => array( |
|
| 749 | + 'js' => 'D', |
|
| 750 | + 'moment' => 'ddd', |
|
| 751 | + ), |
|
| 752 | + //1,2,...31 |
|
| 753 | + 'j' => array( |
|
| 754 | + 'js' => 'd', |
|
| 755 | + 'moment' => 'D', |
|
| 756 | + ), |
|
| 757 | + //Monday |
|
| 758 | + 'l' => array( |
|
| 759 | + 'js' => 'DD', |
|
| 760 | + 'moment' => 'dddd', |
|
| 761 | + ), |
|
| 762 | + //ISO numeric representation of the day of the week (1-6) |
|
| 763 | + 'N' => array( |
|
| 764 | + 'js' => '', |
|
| 765 | + 'moment' => 'E', |
|
| 766 | + ), |
|
| 767 | + //st,nd.rd |
|
| 768 | + 'S' => array( |
|
| 769 | + 'js' => '', |
|
| 770 | + 'moment' => 'o', |
|
| 771 | + ), |
|
| 772 | + //numeric representation of day of week (0-6) |
|
| 773 | + 'w' => array( |
|
| 774 | + 'js' => '', |
|
| 775 | + 'moment' => 'd', |
|
| 776 | + ), |
|
| 777 | + //day of year starting from 0 (0-365) |
|
| 778 | + 'z' => array( |
|
| 779 | + 'js' => 'o', |
|
| 780 | + 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 781 | + ), |
|
| 782 | + // Week |
|
| 783 | + //ISO-8601 week number of year (weeks starting on monday) |
|
| 784 | + 'W' => array( |
|
| 785 | + 'js' => '', |
|
| 786 | + 'moment' => 'w', |
|
| 787 | + ), |
|
| 788 | + // Month |
|
| 789 | + // January...December |
|
| 790 | + 'F' => array( |
|
| 791 | + 'js' => 'MM', |
|
| 792 | + 'moment' => 'MMMM', |
|
| 793 | + ), |
|
| 794 | + //01...12 |
|
| 795 | + 'm' => array( |
|
| 796 | + 'js' => 'mm', |
|
| 797 | + 'moment' => 'MM', |
|
| 798 | + ), |
|
| 799 | + //Jan...Dec |
|
| 800 | + 'M' => array( |
|
| 801 | + 'js' => 'M', |
|
| 802 | + 'moment' => 'MMM', |
|
| 803 | + ), |
|
| 804 | + //1-12 |
|
| 805 | + 'n' => array( |
|
| 806 | + 'js' => 'm', |
|
| 807 | + 'moment' => 'M', |
|
| 808 | + ), |
|
| 809 | + //number of days in given month |
|
| 810 | + 't' => array( |
|
| 811 | + 'js' => '', |
|
| 812 | + 'moment' => '', |
|
| 813 | + ), |
|
| 814 | + // Year |
|
| 815 | + //whether leap year or not 1/0 |
|
| 816 | + 'L' => array( |
|
| 817 | + 'js' => '', |
|
| 818 | + 'moment' => '', |
|
| 819 | + ), |
|
| 820 | + //ISO-8601 year number |
|
| 821 | + 'o' => array( |
|
| 822 | + 'js' => '', |
|
| 823 | + 'moment' => 'GGGG', |
|
| 824 | + ), |
|
| 825 | + //1999...2003 |
|
| 826 | + 'Y' => array( |
|
| 827 | + 'js' => 'yy', |
|
| 828 | + 'moment' => 'YYYY', |
|
| 829 | + ), |
|
| 830 | + //99...03 |
|
| 831 | + 'y' => array( |
|
| 832 | + 'js' => 'y', |
|
| 833 | + 'moment' => 'YY', |
|
| 834 | + ), |
|
| 835 | + // Time |
|
| 836 | + // am/pm |
|
| 837 | + 'a' => array( |
|
| 838 | + 'js' => 'tt', |
|
| 839 | + 'moment' => 'a', |
|
| 840 | + ), |
|
| 841 | + // AM/PM |
|
| 842 | + 'A' => array( |
|
| 843 | + 'js' => 'TT', |
|
| 844 | + 'moment' => 'A', |
|
| 845 | + ), |
|
| 846 | + // Swatch Internet Time?!? |
|
| 847 | + 'B' => array( |
|
| 848 | + 'js' => '', |
|
| 849 | + 'moment' => '', |
|
| 850 | + ), |
|
| 851 | + //1...12 |
|
| 852 | + 'g' => array( |
|
| 853 | + 'js' => 'h', |
|
| 854 | + 'moment' => 'h', |
|
| 855 | + ), |
|
| 856 | + //0...23 |
|
| 857 | + 'G' => array( |
|
| 858 | + 'js' => 'H', |
|
| 859 | + 'moment' => 'H', |
|
| 860 | + ), |
|
| 861 | + //01...12 |
|
| 862 | + 'h' => array( |
|
| 863 | + 'js' => 'hh', |
|
| 864 | + 'moment' => 'hh', |
|
| 865 | + ), |
|
| 866 | + //00...23 |
|
| 867 | + 'H' => array( |
|
| 868 | + 'js' => 'HH', |
|
| 869 | + 'moment' => 'HH', |
|
| 870 | + ), |
|
| 871 | + //00..59 |
|
| 872 | + 'i' => array( |
|
| 873 | + 'js' => 'mm', |
|
| 874 | + 'moment' => 'mm', |
|
| 875 | + ), |
|
| 876 | + //seconds... 00...59 |
|
| 877 | + 's' => array( |
|
| 878 | + 'js' => 'ss', |
|
| 879 | + 'moment' => 'ss', |
|
| 880 | + ), |
|
| 881 | + //microseconds |
|
| 882 | + 'u' => array( |
|
| 883 | + 'js' => '', |
|
| 884 | + 'moment' => '', |
|
| 885 | + ), |
|
| 886 | + ); |
|
| 887 | + $jquery_ui_format = ""; |
|
| 888 | + $moment_format = ""; |
|
| 889 | + $escaping = false; |
|
| 890 | + for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 891 | + $char = $format_string[$i]; |
|
| 892 | + if ($char === '\\') { // PHP date format escaping character |
|
| 893 | + $i++; |
|
| 894 | + if ($escaping) { |
|
| 895 | + $jquery_ui_format .= $format_string[$i]; |
|
| 896 | + $moment_format .= $format_string[$i]; |
|
| 897 | + } else { |
|
| 898 | + $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 899 | + $moment_format .= $format_string[$i]; |
|
| 900 | + } |
|
| 901 | + $escaping = true; |
|
| 902 | + } else { |
|
| 903 | + if ($escaping) { |
|
| 904 | + $jquery_ui_format .= "'"; |
|
| 905 | + $moment_format .= "'"; |
|
| 906 | + $escaping = false; |
|
| 907 | + } |
|
| 908 | + if (isset($symbols_map[$char])) { |
|
| 909 | + $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 910 | + $moment_format .= $symbols_map[$char]['moment']; |
|
| 911 | + } else { |
|
| 912 | + $jquery_ui_format .= $char; |
|
| 913 | + $moment_format .= $char; |
|
| 914 | + } |
|
| 915 | + } |
|
| 916 | + } |
|
| 917 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 923 | + * |
|
| 924 | + * @param string $format_string Incoming format string for php date(). |
|
| 925 | + * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 926 | + * errors is returned. So for client code calling, check for is_array() to |
|
| 927 | + * indicate failed validations. |
|
| 928 | + */ |
|
| 929 | + public static function validate_format_string($format_string) |
|
| 930 | + { |
|
| 931 | + $error_msg = array(); |
|
| 932 | + //time format checks |
|
| 933 | + switch (true) { |
|
| 934 | + case strpos($format_string, 'h') !== false : |
|
| 935 | + case strpos($format_string, 'g') !== false : |
|
| 936 | + /** |
|
| 937 | + * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 938 | + * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 939 | + * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 940 | + */ |
|
| 941 | + if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 942 | + $error_msg[] = __('There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', |
|
| 943 | + 'event_espresso'); |
|
| 944 | + } |
|
| 945 | + break; |
|
| 946 | + |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + return empty($error_msg) ? true : $error_msg; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 955 | + * very next day then this method will return true. |
|
| 956 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 957 | + * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 958 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 959 | + * |
|
| 960 | + * @param mixed $date_1 |
|
| 961 | + * @param mixed $date_2 |
|
| 962 | + * @return bool |
|
| 963 | + */ |
|
| 964 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 965 | + { |
|
| 966 | + |
|
| 967 | + if ( |
|
| 968 | + (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 969 | + ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
|
| 970 | + ) { |
|
| 971 | + return false; |
|
| 972 | + } |
|
| 973 | + return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false; |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 979 | + * Functions. |
|
| 980 | + * |
|
| 981 | + * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 982 | + * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 983 | + * @return string |
|
| 984 | + */ |
|
| 985 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 986 | + { |
|
| 987 | + try { |
|
| 988 | + /** need to account for timezone offset on the selects */ |
|
| 989 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 990 | + } catch (Exception $e) { |
|
| 991 | + $DateTimeZone = null; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + /** |
|
| 995 | + * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 996 | + * Hence we do the calc for DateTimeZone::getOffset. |
|
| 997 | + */ |
|
| 998 | + $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 999 | + $query_interval = $offset < 0 |
|
| 1000 | + ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1001 | + : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 1002 | + return $query_interval; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + /** |
|
| 1006 | + * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 1007 | + * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 1008 | + * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 1009 | + * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 1010 | + * (although note that we remove any HTML that may be added) |
|
| 1011 | + * |
|
| 1012 | + * @return string |
|
| 1013 | + */ |
|
| 1014 | + public static function get_timezone_string_for_display() |
|
| 1015 | + { |
|
| 1016 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 1017 | + if (! empty($pretty_timezone)) { |
|
| 1018 | + return esc_html($pretty_timezone); |
|
| 1019 | + } |
|
| 1020 | + $timezone_string = get_option('timezone_string'); |
|
| 1021 | + if ($timezone_string) { |
|
| 1022 | + static $mo_loaded = false; |
|
| 1023 | + // Load translations for continents and cities just like wp_timezone_choice does |
|
| 1024 | + if (! $mo_loaded) { |
|
| 1025 | + $locale = get_locale(); |
|
| 1026 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1027 | + load_textdomain('continents-cities', $mofile); |
|
| 1028 | + $mo_loaded = true; |
|
| 1029 | + } |
|
| 1030 | + //well that was easy. |
|
| 1031 | + $parts = explode('/', $timezone_string); |
|
| 1032 | + //remove the continent |
|
| 1033 | + unset($parts[0]); |
|
| 1034 | + $t_parts = array(); |
|
| 1035 | + foreach ($parts as $part) { |
|
| 1036 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 1037 | + } |
|
| 1038 | + return implode(' - ', $t_parts); |
|
| 1039 | + } |
|
| 1040 | + //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 1041 | + $gmt_offset = get_option('gmt_offset'); |
|
| 1042 | + if (intval($gmt_offset) >= 0) { |
|
| 1043 | + $prefix = '+'; |
|
| 1044 | + } else { |
|
| 1045 | + $prefix = ''; |
|
| 1046 | + } |
|
| 1047 | + $parts = explode('.', (string)$gmt_offset); |
|
| 1048 | + if (count($parts) === 1) { |
|
| 1049 | + $parts[1] = '00'; |
|
| 1050 | + } else { |
|
| 1051 | + //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 1052 | + //to minutes, eg 30 or 15, respectively |
|
| 1053 | + $hour_fraction = (float)('0.' . $parts[1]); |
|
| 1054 | + $parts[1] = (string)$hour_fraction * 60; |
|
| 1055 | + } |
|
| 1056 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + /** |
|
| 1062 | + * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 1063 | + * for a month using a string like "February" or "February 2017", |
|
| 1064 | + * and you don't specify a day as part of your string, |
|
| 1065 | + * then PHP will use whatever the current day of the month is. |
|
| 1066 | + * IF the current day of the month happens to be the 30th or 31st, |
|
| 1067 | + * then PHP gets really confused by a date like February 30, |
|
| 1068 | + * so instead of saying |
|
| 1069 | + * "Hey February only has 28 days (this year)... |
|
| 1070 | + * ...you must have meant the last day of the month!" |
|
| 1071 | + * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 1072 | + * because someone requesting February 30th obviously meant March 1st! |
|
| 1073 | + * The way around this is to always set the day to the first, |
|
| 1074 | + * so that the month will stay on the month you wanted. |
|
| 1075 | + * this method will add that "1" into your date regardless of the format. |
|
| 1076 | + * |
|
| 1077 | + * @param string $month |
|
| 1078 | + * @return string |
|
| 1079 | + */ |
|
| 1080 | + public static function first_of_month_timestamp($month = '') |
|
| 1081 | + { |
|
| 1082 | + $month = (string)$month; |
|
| 1083 | + $year = ''; |
|
| 1084 | + // check if the incoming string has a year in it or not |
|
| 1085 | + if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 1086 | + $year = $matches[0]; |
|
| 1087 | + // ten remove that from the month string as well as any spaces |
|
| 1088 | + $month = trim(str_replace($year, '', $month)); |
|
| 1089 | + // add a space before the year |
|
| 1090 | + $year = " {$year}"; |
|
| 1091 | + } |
|
| 1092 | + // return timestamp for something like "February 1 2017" |
|
| 1093 | + return strtotime("{$month} 1{$year}"); |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
| 1098 | + * for this sites timezone, but the timestamp could be some other time GMT. |
|
| 1099 | + */ |
|
| 1100 | + public static function tomorrow() |
|
| 1101 | 1101 | { |
| 1102 | 1102 | //The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
| 1103 | 1103 | //before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
@@ -1107,135 +1107,135 @@ discard block |
||
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | |
| 1110 | - /** |
|
| 1111 | - * ** |
|
| 1112 | - * Gives a nicely-formatted list of timezone strings. |
|
| 1113 | - * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
| 1114 | - * |
|
| 1115 | - * @since 4.9.40.rc.008 |
|
| 1116 | - * @staticvar bool $mo_loaded |
|
| 1117 | - * @staticvar string $locale_loaded |
|
| 1118 | - * @param string $selected_zone Selected timezone. |
|
| 1119 | - * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
| 1120 | - * @return string |
|
| 1121 | - */ |
|
| 1122 | - public static function wp_timezone_choice($selected_zone, $locale = null) |
|
| 1123 | - { |
|
| 1124 | - static $mo_loaded = false, $locale_loaded = null; |
|
| 1125 | - |
|
| 1126 | - $continents = array( |
|
| 1127 | - 'Africa', |
|
| 1128 | - 'America', |
|
| 1129 | - 'Antarctica', |
|
| 1130 | - 'Arctic', |
|
| 1131 | - 'Asia', |
|
| 1132 | - 'Atlantic', |
|
| 1133 | - 'Australia', |
|
| 1134 | - 'Europe', |
|
| 1135 | - 'Indian', |
|
| 1136 | - 'Pacific', |
|
| 1137 | - ); |
|
| 1138 | - |
|
| 1139 | - // Load translations for continents and cities. |
|
| 1140 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1141 | - $locale_loaded = $locale ? $locale : get_locale(); |
|
| 1142 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1143 | - unload_textdomain('continents-cities'); |
|
| 1144 | - load_textdomain('continents-cities', $mofile); |
|
| 1145 | - $mo_loaded = true; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - $zonen = array(); |
|
| 1149 | - foreach (timezone_identifiers_list() as $zone) { |
|
| 1150 | - $zone = explode('/', $zone); |
|
| 1151 | - if (! in_array($zone[0], $continents)) { |
|
| 1152 | - continue; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
| 1156 | - $exists = array( |
|
| 1157 | - 0 => (isset($zone[0]) && $zone[0]), |
|
| 1158 | - 1 => (isset($zone[1]) && $zone[1]), |
|
| 1159 | - 2 => (isset($zone[2]) && $zone[2]), |
|
| 1160 | - ); |
|
| 1161 | - $exists[3] = ($exists[0] && 'Etc' !== $zone[0]); |
|
| 1162 | - $exists[4] = ($exists[1] && $exists[3]); |
|
| 1163 | - $exists[5] = ($exists[2] && $exists[3]); |
|
| 1164 | - |
|
| 1165 | - $zonen[] = array( |
|
| 1166 | - 'continent' => ($exists[0] ? $zone[0] : ''), |
|
| 1167 | - 'city' => ($exists[1] ? $zone[1] : ''), |
|
| 1168 | - 'subcity' => ($exists[2] ? $zone[2] : ''), |
|
| 1169 | - 't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''), |
|
| 1170 | - 't_city' => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''), |
|
| 1171 | - 't_subcity' => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''), |
|
| 1172 | - ); |
|
| 1173 | - } |
|
| 1174 | - usort($zonen, '_wp_timezone_choice_usort_callback'); |
|
| 1175 | - |
|
| 1176 | - $structure = array(); |
|
| 1177 | - |
|
| 1178 | - if (empty($selected_zone)) { |
|
| 1179 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - foreach ($zonen as $key => $zone) { |
|
| 1183 | - // Build value in an array to join later |
|
| 1184 | - $value = array($zone['continent']); |
|
| 1185 | - |
|
| 1186 | - if (empty($zone['city'])) { |
|
| 1187 | - // It's at the continent level (generally won't happen) |
|
| 1188 | - $display = $zone['t_continent']; |
|
| 1189 | - } else { |
|
| 1190 | - // It's inside a continent group |
|
| 1191 | - |
|
| 1192 | - // Continent optgroup |
|
| 1193 | - if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1194 | - $label = $zone['t_continent']; |
|
| 1195 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - // Add the city to the value |
|
| 1199 | - $value[] = $zone['city']; |
|
| 1200 | - |
|
| 1201 | - $display = $zone['t_city']; |
|
| 1202 | - if (! empty($zone['subcity'])) { |
|
| 1203 | - // Add the subcity to the value |
|
| 1204 | - $value[] = $zone['subcity']; |
|
| 1205 | - $display .= ' - ' . $zone['t_subcity']; |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - // Build the value |
|
| 1210 | - $value = join('/', $value); |
|
| 1211 | - $selected = ''; |
|
| 1212 | - if ($value === $selected_zone) { |
|
| 1213 | - $selected = 'selected="selected" '; |
|
| 1214 | - } |
|
| 1215 | - $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
| 1216 | - |
|
| 1217 | - // Close continent optgroup |
|
| 1218 | - if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1219 | - $structure[] = '</optgroup>'; |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - return join("\n", $structure); |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - |
|
| 1227 | - /** |
|
| 1228 | - * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
| 1229 | - * |
|
| 1230 | - * @param int|WP_User $user_id |
|
| 1231 | - * @return string |
|
| 1232 | - */ |
|
| 1233 | - public static function get_user_locale($user_id = 0) |
|
| 1234 | - { |
|
| 1235 | - if (function_exists('get_user_locale')) { |
|
| 1236 | - return get_user_locale($user_id); |
|
| 1237 | - } |
|
| 1238 | - return get_locale(); |
|
| 1239 | - } |
|
| 1110 | + /** |
|
| 1111 | + * ** |
|
| 1112 | + * Gives a nicely-formatted list of timezone strings. |
|
| 1113 | + * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
| 1114 | + * |
|
| 1115 | + * @since 4.9.40.rc.008 |
|
| 1116 | + * @staticvar bool $mo_loaded |
|
| 1117 | + * @staticvar string $locale_loaded |
|
| 1118 | + * @param string $selected_zone Selected timezone. |
|
| 1119 | + * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
| 1120 | + * @return string |
|
| 1121 | + */ |
|
| 1122 | + public static function wp_timezone_choice($selected_zone, $locale = null) |
|
| 1123 | + { |
|
| 1124 | + static $mo_loaded = false, $locale_loaded = null; |
|
| 1125 | + |
|
| 1126 | + $continents = array( |
|
| 1127 | + 'Africa', |
|
| 1128 | + 'America', |
|
| 1129 | + 'Antarctica', |
|
| 1130 | + 'Arctic', |
|
| 1131 | + 'Asia', |
|
| 1132 | + 'Atlantic', |
|
| 1133 | + 'Australia', |
|
| 1134 | + 'Europe', |
|
| 1135 | + 'Indian', |
|
| 1136 | + 'Pacific', |
|
| 1137 | + ); |
|
| 1138 | + |
|
| 1139 | + // Load translations for continents and cities. |
|
| 1140 | + if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1141 | + $locale_loaded = $locale ? $locale : get_locale(); |
|
| 1142 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1143 | + unload_textdomain('continents-cities'); |
|
| 1144 | + load_textdomain('continents-cities', $mofile); |
|
| 1145 | + $mo_loaded = true; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + $zonen = array(); |
|
| 1149 | + foreach (timezone_identifiers_list() as $zone) { |
|
| 1150 | + $zone = explode('/', $zone); |
|
| 1151 | + if (! in_array($zone[0], $continents)) { |
|
| 1152 | + continue; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
| 1156 | + $exists = array( |
|
| 1157 | + 0 => (isset($zone[0]) && $zone[0]), |
|
| 1158 | + 1 => (isset($zone[1]) && $zone[1]), |
|
| 1159 | + 2 => (isset($zone[2]) && $zone[2]), |
|
| 1160 | + ); |
|
| 1161 | + $exists[3] = ($exists[0] && 'Etc' !== $zone[0]); |
|
| 1162 | + $exists[4] = ($exists[1] && $exists[3]); |
|
| 1163 | + $exists[5] = ($exists[2] && $exists[3]); |
|
| 1164 | + |
|
| 1165 | + $zonen[] = array( |
|
| 1166 | + 'continent' => ($exists[0] ? $zone[0] : ''), |
|
| 1167 | + 'city' => ($exists[1] ? $zone[1] : ''), |
|
| 1168 | + 'subcity' => ($exists[2] ? $zone[2] : ''), |
|
| 1169 | + 't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''), |
|
| 1170 | + 't_city' => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''), |
|
| 1171 | + 't_subcity' => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''), |
|
| 1172 | + ); |
|
| 1173 | + } |
|
| 1174 | + usort($zonen, '_wp_timezone_choice_usort_callback'); |
|
| 1175 | + |
|
| 1176 | + $structure = array(); |
|
| 1177 | + |
|
| 1178 | + if (empty($selected_zone)) { |
|
| 1179 | + $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + foreach ($zonen as $key => $zone) { |
|
| 1183 | + // Build value in an array to join later |
|
| 1184 | + $value = array($zone['continent']); |
|
| 1185 | + |
|
| 1186 | + if (empty($zone['city'])) { |
|
| 1187 | + // It's at the continent level (generally won't happen) |
|
| 1188 | + $display = $zone['t_continent']; |
|
| 1189 | + } else { |
|
| 1190 | + // It's inside a continent group |
|
| 1191 | + |
|
| 1192 | + // Continent optgroup |
|
| 1193 | + if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1194 | + $label = $zone['t_continent']; |
|
| 1195 | + $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + // Add the city to the value |
|
| 1199 | + $value[] = $zone['city']; |
|
| 1200 | + |
|
| 1201 | + $display = $zone['t_city']; |
|
| 1202 | + if (! empty($zone['subcity'])) { |
|
| 1203 | + // Add the subcity to the value |
|
| 1204 | + $value[] = $zone['subcity']; |
|
| 1205 | + $display .= ' - ' . $zone['t_subcity']; |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + // Build the value |
|
| 1210 | + $value = join('/', $value); |
|
| 1211 | + $selected = ''; |
|
| 1212 | + if ($value === $selected_zone) { |
|
| 1213 | + $selected = 'selected="selected" '; |
|
| 1214 | + } |
|
| 1215 | + $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
| 1216 | + |
|
| 1217 | + // Close continent optgroup |
|
| 1218 | + if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1219 | + $structure[] = '</optgroup>'; |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + return join("\n", $structure); |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + |
|
| 1227 | + /** |
|
| 1228 | + * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
| 1229 | + * |
|
| 1230 | + * @param int|WP_User $user_id |
|
| 1231 | + * @return string |
|
| 1232 | + */ |
|
| 1233 | + public static function get_user_locale($user_id = 0) |
|
| 1234 | + { |
|
| 1235 | + if (function_exists('get_user_locale')) { |
|
| 1236 | + return get_user_locale($user_id); |
|
| 1237 | + } |
|
| 1238 | + return get_locale(); |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | 1241 | }// end class EEH_DTT_Helper |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | new DateTimeZone($timezone_string); |
| 75 | 75 | } catch (Exception $e) { |
| 76 | 76 | // sometimes we take exception to exceptions |
| 77 | - if (! $throw_error) { |
|
| 77 | + if ( ! $throw_error) { |
|
| 78 | 78 | return false; |
| 79 | 79 | } |
| 80 | 80 | throw new EE_Error( |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | $offset = get_option('gmt_offset'); |
| 162 | - return (int)($offset * HOUR_IN_SECONDS); |
|
| 162 | + return (int) ($offset * HOUR_IN_SECONDS); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
| 178 | 178 | { |
| 179 | 179 | //make sure $gmt_offset is int |
| 180 | - $gmt_offset = (int)$gmt_offset; |
|
| 180 | + $gmt_offset = (int) $gmt_offset; |
|
| 181 | 181 | switch ($gmt_offset) { |
| 182 | 182 | //-12 |
| 183 | 183 | case -43200: |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
| 351 | 351 | { |
| 352 | 352 | $transitions = self::get_timezone_transitions($date_time_zone, $time); |
| 353 | - if (! isset($transitions['offset'])) { |
|
| 353 | + if ( ! isset($transitions['offset'])) { |
|
| 354 | 354 | throw new DomainException(); |
| 355 | 355 | } |
| 356 | 356 | return $transitions['offset']; |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | public static function timezone_select_input($timezone_string = '') |
| 365 | 365 | { |
| 366 | 366 | // get WP date time format |
| 367 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 367 | + $datetime_format = get_option('date_format').' '.get_option('time_format'); |
|
| 368 | 368 | // if passed a value, then use that, else get WP option |
| 369 | 369 | $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
| 370 | 370 | // check if the timezone is valid but don't throw any errors if it isn't |
@@ -376,9 +376,9 @@ discard block |
||
| 376 | 376 | // Create a UTC+- zone if no timezone string exists |
| 377 | 377 | $check_zone_info = false; |
| 378 | 378 | if ($gmt_offset > 0) { |
| 379 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 379 | + $timezone_string = 'UTC+'.$gmt_offset; |
|
| 380 | 380 | } elseif ($gmt_offset < 0) { |
| 381 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 381 | + $timezone_string = 'UTC'.$gmt_offset; |
|
| 382 | 382 | } else { |
| 383 | 383 | $timezone_string = 'UTC'; |
| 384 | 384 | } |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | __('%1$sUTC%2$s time is %3$s'), |
| 401 | 401 | '<abbr title="Coordinated Universal Time">', |
| 402 | 402 | '</abbr>', |
| 403 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 403 | + '<code>'.date_i18n($datetime_format, false, true).'</code>' |
|
| 404 | 404 | ); |
| 405 | 405 | ?></span> |
| 406 | - <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 407 | - <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
|
| 406 | + <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 407 | + <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span> |
|
| 408 | 408 | <?php endif; ?> |
| 409 | 409 | |
| 410 | 410 | <?php if ($check_zone_info && $timezone_string) : ?> |
@@ -437,11 +437,10 @@ discard block |
||
| 437 | 437 | |
| 438 | 438 | if ($found) { |
| 439 | 439 | $message = $tr['isdst'] ? |
| 440 | - __(' Daylight saving time begins on: %s.') : |
|
| 441 | - __(' Standard time begins on: %s.'); |
|
| 440 | + __(' Daylight saving time begins on: %s.') : __(' Standard time begins on: %s.'); |
|
| 442 | 441 | // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
| 443 | 442 | printf($message, |
| 444 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 443 | + '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >'); |
|
| 445 | 444 | } else { |
| 446 | 445 | _e('This timezone does not observe daylight saving time.'); |
| 447 | 446 | } |
@@ -469,13 +468,13 @@ discard block |
||
| 469 | 468 | */ |
| 470 | 469 | public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
| 471 | 470 | { |
| 472 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 471 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
|
| 473 | 472 | $timezone_string = self::get_valid_timezone_string($timezone_string); |
| 474 | 473 | $TimeZone = new DateTimeZone($timezone_string); |
| 475 | 474 | |
| 476 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 475 | + $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone); |
|
| 477 | 476 | $offset = timezone_offset_get($TimeZone, $DateTime); |
| 478 | - return (int)$DateTime->format('U') + (int)$offset; |
|
| 477 | + return (int) $DateTime->format('U') + (int) $offset; |
|
| 479 | 478 | } |
| 480 | 479 | |
| 481 | 480 | |
@@ -558,7 +557,7 @@ discard block |
||
| 558 | 557 | */ |
| 559 | 558 | protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
| 560 | 559 | { |
| 561 | - if (! $DateTime instanceof DateTime) { |
|
| 560 | + if ( ! $DateTime instanceof DateTime) { |
|
| 562 | 561 | throw new EE_Error( |
| 563 | 562 | sprintf( |
| 564 | 563 | __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
@@ -568,25 +567,25 @@ discard block |
||
| 568 | 567 | } |
| 569 | 568 | switch ($period) { |
| 570 | 569 | case 'years' : |
| 571 | - $value = 'P' . $value . 'Y'; |
|
| 570 | + $value = 'P'.$value.'Y'; |
|
| 572 | 571 | break; |
| 573 | 572 | case 'months' : |
| 574 | - $value = 'P' . $value . 'M'; |
|
| 573 | + $value = 'P'.$value.'M'; |
|
| 575 | 574 | break; |
| 576 | 575 | case 'weeks' : |
| 577 | - $value = 'P' . $value . 'W'; |
|
| 576 | + $value = 'P'.$value.'W'; |
|
| 578 | 577 | break; |
| 579 | 578 | case 'days' : |
| 580 | - $value = 'P' . $value . 'D'; |
|
| 579 | + $value = 'P'.$value.'D'; |
|
| 581 | 580 | break; |
| 582 | 581 | case 'hours' : |
| 583 | - $value = 'PT' . $value . 'H'; |
|
| 582 | + $value = 'PT'.$value.'H'; |
|
| 584 | 583 | break; |
| 585 | 584 | case 'minutes' : |
| 586 | - $value = 'PT' . $value . 'M'; |
|
| 585 | + $value = 'PT'.$value.'M'; |
|
| 587 | 586 | break; |
| 588 | 587 | case 'seconds' : |
| 589 | - $value = 'PT' . $value . 'S'; |
|
| 588 | + $value = 'PT'.$value.'S'; |
|
| 590 | 589 | break; |
| 591 | 590 | } |
| 592 | 591 | switch ($operand) { |
@@ -614,7 +613,7 @@ discard block |
||
| 614 | 613 | */ |
| 615 | 614 | protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
| 616 | 615 | { |
| 617 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 616 | + if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 618 | 617 | throw new EE_Error( |
| 619 | 618 | sprintf( |
| 620 | 619 | __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
@@ -718,7 +717,7 @@ discard block |
||
| 718 | 717 | 'date' => $date_format['js'], |
| 719 | 718 | 'time' => $time_format['js'], |
| 720 | 719 | ), |
| 721 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 720 | + 'moment' => $date_format['moment'].' '.$time_format['moment'], |
|
| 722 | 721 | ); |
| 723 | 722 | } |
| 724 | 723 | |
@@ -737,7 +736,7 @@ discard block |
||
| 737 | 736 | * |
| 738 | 737 | * @var array |
| 739 | 738 | */ |
| 740 | - $symbols_map = array( |
|
| 739 | + $symbols_map = array( |
|
| 741 | 740 | // Day |
| 742 | 741 | //01 |
| 743 | 742 | 'd' => array( |
@@ -895,7 +894,7 @@ discard block |
||
| 895 | 894 | $jquery_ui_format .= $format_string[$i]; |
| 896 | 895 | $moment_format .= $format_string[$i]; |
| 897 | 896 | } else { |
| 898 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 897 | + $jquery_ui_format .= '\''.$format_string[$i]; |
|
| 899 | 898 | $moment_format .= $format_string[$i]; |
| 900 | 899 | } |
| 901 | 900 | $escaping = true; |
@@ -965,7 +964,7 @@ discard block |
||
| 965 | 964 | { |
| 966 | 965 | |
| 967 | 966 | if ( |
| 968 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 967 | + ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 969 | 968 | ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
| 970 | 969 | ) { |
| 971 | 970 | return false; |
@@ -997,8 +996,8 @@ discard block |
||
| 997 | 996 | */ |
| 998 | 997 | $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
| 999 | 998 | $query_interval = $offset < 0 |
| 1000 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1001 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 999 | + ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)' |
|
| 1000 | + : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)'; |
|
| 1002 | 1001 | return $query_interval; |
| 1003 | 1002 | } |
| 1004 | 1003 | |
@@ -1014,16 +1013,16 @@ discard block |
||
| 1014 | 1013 | public static function get_timezone_string_for_display() |
| 1015 | 1014 | { |
| 1016 | 1015 | $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
| 1017 | - if (! empty($pretty_timezone)) { |
|
| 1016 | + if ( ! empty($pretty_timezone)) { |
|
| 1018 | 1017 | return esc_html($pretty_timezone); |
| 1019 | 1018 | } |
| 1020 | 1019 | $timezone_string = get_option('timezone_string'); |
| 1021 | 1020 | if ($timezone_string) { |
| 1022 | 1021 | static $mo_loaded = false; |
| 1023 | 1022 | // Load translations for continents and cities just like wp_timezone_choice does |
| 1024 | - if (! $mo_loaded) { |
|
| 1023 | + if ( ! $mo_loaded) { |
|
| 1025 | 1024 | $locale = get_locale(); |
| 1026 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1025 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo'; |
|
| 1027 | 1026 | load_textdomain('continents-cities', $mofile); |
| 1028 | 1027 | $mo_loaded = true; |
| 1029 | 1028 | } |
@@ -1044,16 +1043,16 @@ discard block |
||
| 1044 | 1043 | } else { |
| 1045 | 1044 | $prefix = ''; |
| 1046 | 1045 | } |
| 1047 | - $parts = explode('.', (string)$gmt_offset); |
|
| 1046 | + $parts = explode('.', (string) $gmt_offset); |
|
| 1048 | 1047 | if (count($parts) === 1) { |
| 1049 | 1048 | $parts[1] = '00'; |
| 1050 | 1049 | } else { |
| 1051 | 1050 | //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
| 1052 | 1051 | //to minutes, eg 30 or 15, respectively |
| 1053 | - $hour_fraction = (float)('0.' . $parts[1]); |
|
| 1054 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 1052 | + $hour_fraction = (float) ('0.'.$parts[1]); |
|
| 1053 | + $parts[1] = (string) $hour_fraction * 60; |
|
| 1055 | 1054 | } |
| 1056 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1055 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts)); |
|
| 1057 | 1056 | } |
| 1058 | 1057 | |
| 1059 | 1058 | |
@@ -1079,7 +1078,7 @@ discard block |
||
| 1079 | 1078 | */ |
| 1080 | 1079 | public static function first_of_month_timestamp($month = '') |
| 1081 | 1080 | { |
| 1082 | - $month = (string)$month; |
|
| 1081 | + $month = (string) $month; |
|
| 1083 | 1082 | $year = ''; |
| 1084 | 1083 | // check if the incoming string has a year in it or not |
| 1085 | 1084 | if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
@@ -1103,7 +1102,7 @@ discard block |
||
| 1103 | 1102 | //before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
| 1104 | 1103 | //not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
| 1105 | 1104 | //final timestamp is equivalent to midnight in this timezone as represented in GMT. |
| 1106 | - return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset()*-1); |
|
| 1105 | + return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
| 1107 | 1106 | } |
| 1108 | 1107 | |
| 1109 | 1108 | |
@@ -1137,9 +1136,9 @@ discard block |
||
| 1137 | 1136 | ); |
| 1138 | 1137 | |
| 1139 | 1138 | // Load translations for continents and cities. |
| 1140 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1139 | + if ( ! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1141 | 1140 | $locale_loaded = $locale ? $locale : get_locale(); |
| 1142 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1141 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo'; |
|
| 1143 | 1142 | unload_textdomain('continents-cities'); |
| 1144 | 1143 | load_textdomain('continents-cities', $mofile); |
| 1145 | 1144 | $mo_loaded = true; |
@@ -1148,12 +1147,12 @@ discard block |
||
| 1148 | 1147 | $zonen = array(); |
| 1149 | 1148 | foreach (timezone_identifiers_list() as $zone) { |
| 1150 | 1149 | $zone = explode('/', $zone); |
| 1151 | - if (! in_array($zone[0], $continents)) { |
|
| 1150 | + if ( ! in_array($zone[0], $continents)) { |
|
| 1152 | 1151 | continue; |
| 1153 | 1152 | } |
| 1154 | 1153 | |
| 1155 | 1154 | // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
| 1156 | - $exists = array( |
|
| 1155 | + $exists = array( |
|
| 1157 | 1156 | 0 => (isset($zone[0]) && $zone[0]), |
| 1158 | 1157 | 1 => (isset($zone[1]) && $zone[1]), |
| 1159 | 1158 | 2 => (isset($zone[2]) && $zone[2]), |
@@ -1176,7 +1175,7 @@ discard block |
||
| 1176 | 1175 | $structure = array(); |
| 1177 | 1176 | |
| 1178 | 1177 | if (empty($selected_zone)) { |
| 1179 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1178 | + $structure[] = '<option selected="selected" value="">'.__('Select a city').'</option>'; |
|
| 1180 | 1179 | } |
| 1181 | 1180 | |
| 1182 | 1181 | foreach ($zonen as $key => $zone) { |
@@ -1190,19 +1189,19 @@ discard block |
||
| 1190 | 1189 | // It's inside a continent group |
| 1191 | 1190 | |
| 1192 | 1191 | // Continent optgroup |
| 1193 | - if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1192 | + if ( ! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1194 | 1193 | $label = $zone['t_continent']; |
| 1195 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1194 | + $structure[] = '<optgroup label="'.esc_attr($label).'">'; |
|
| 1196 | 1195 | } |
| 1197 | 1196 | |
| 1198 | 1197 | // Add the city to the value |
| 1199 | 1198 | $value[] = $zone['city']; |
| 1200 | 1199 | |
| 1201 | 1200 | $display = $zone['t_city']; |
| 1202 | - if (! empty($zone['subcity'])) { |
|
| 1201 | + if ( ! empty($zone['subcity'])) { |
|
| 1203 | 1202 | // Add the subcity to the value |
| 1204 | 1203 | $value[] = $zone['subcity']; |
| 1205 | - $display .= ' - ' . $zone['t_subcity']; |
|
| 1204 | + $display .= ' - '.$zone['t_subcity']; |
|
| 1206 | 1205 | } |
| 1207 | 1206 | } |
| 1208 | 1207 | |
@@ -1212,10 +1211,10 @@ discard block |
||
| 1212 | 1211 | if ($value === $selected_zone) { |
| 1213 | 1212 | $selected = 'selected="selected" '; |
| 1214 | 1213 | } |
| 1215 | - $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
| 1214 | + $structure[] = '<option '.$selected.'value="'.esc_attr($value).'">'.esc_html($display)."</option>"; |
|
| 1216 | 1215 | |
| 1217 | 1216 | // Close continent optgroup |
| 1218 | - if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1217 | + if ( ! empty($zone['city']) && ( ! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1219 | 1218 | $structure[] = '</optgroup>'; |
| 1220 | 1219 | } |
| 1221 | 1220 | } |
@@ -15,395 +15,395 @@ discard block |
||
| 15 | 15 | final class EE_Admin implements InterminableInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @access private |
|
| 20 | - * @var EE_Admin $_instance |
|
| 21 | - */ |
|
| 22 | - private static $_instance; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - *@ singleton method used to instantiate class object |
|
| 27 | - *@ access public |
|
| 28 | - *@ return class instance |
|
| 29 | - * |
|
| 30 | - * @throws \EE_Error |
|
| 31 | - */ |
|
| 32 | - public static function instance() |
|
| 33 | - { |
|
| 34 | - // check if class object is instantiated |
|
| 35 | - if (! self::$_instance instanceof EE_Admin) { |
|
| 36 | - self::$_instance = new self(); |
|
| 37 | - } |
|
| 38 | - return self::$_instance; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return EE_Admin |
|
| 44 | - * @throws EE_Error |
|
| 45 | - */ |
|
| 46 | - public static function reset() |
|
| 47 | - { |
|
| 48 | - self::$_instance = null; |
|
| 49 | - return self::instance(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * class constructor |
|
| 55 | - * |
|
| 56 | - * @throws \EE_Error |
|
| 57 | - */ |
|
| 58 | - protected function __construct() |
|
| 59 | - { |
|
| 60 | - // define global EE_Admin constants |
|
| 61 | - $this->_define_all_constants(); |
|
| 62 | - // set autoloaders for our admin page classes based on included path information |
|
| 63 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 64 | - // admin hooks |
|
| 65 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 66 | - // load EE_Request_Handler early |
|
| 67 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 68 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 69 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 70 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 71 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 72 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 73 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 74 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 75 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 76 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 77 | - |
|
| 78 | - //reset Environment config (we only do this on admin page loads); |
|
| 79 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 80 | - |
|
| 81 | - do_action('AHEE__EE_Admin__loaded'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * _define_all_constants |
|
| 87 | - * define constants that are set globally for all admin pages |
|
| 88 | - * |
|
| 89 | - * @access private |
|
| 90 | - * @return void |
|
| 91 | - */ |
|
| 92 | - private function _define_all_constants() |
|
| 93 | - { |
|
| 94 | - if (! defined('EE_ADMIN_URL')) { |
|
| 95 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 99 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
| 106 | - * |
|
| 107 | - * @access public |
|
| 108 | - * @param array $links |
|
| 109 | - * @param string $plugin |
|
| 110 | - * @return array |
|
| 111 | - */ |
|
| 112 | - public function filter_plugin_actions($links, $plugin) |
|
| 113 | - { |
|
| 114 | - // set $main_file in stone |
|
| 115 | - static $main_file; |
|
| 116 | - // if $main_file is not set yet |
|
| 117 | - if (! $main_file) { |
|
| 118 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 119 | - } |
|
| 120 | - if ($plugin === $main_file) { |
|
| 121 | - // compare current plugin to this one |
|
| 122 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 123 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 124 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 125 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 126 | - . '</a>'; |
|
| 127 | - array_unshift($links, $maintenance_link); |
|
| 128 | - } else { |
|
| 129 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 130 | - . esc_html__('Settings', 'event_espresso') |
|
| 131 | - . '</a>'; |
|
| 132 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 133 | - . esc_html__('Events', 'event_espresso') |
|
| 134 | - . '</a>'; |
|
| 135 | - // add before other links |
|
| 136 | - array_unshift($links, $org_settings_link, $events_link); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - return $links; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * _get_request |
|
| 145 | - * |
|
| 146 | - * @access public |
|
| 147 | - * @return void |
|
| 148 | - * @throws EE_Error |
|
| 149 | - * @throws ReflectionException |
|
| 150 | - */ |
|
| 151 | - public function get_request() |
|
| 152 | - { |
|
| 153 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 154 | - EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * hide_admin_pages_except_maintenance_mode |
|
| 160 | - * |
|
| 161 | - * @access public |
|
| 162 | - * @param array $admin_page_folder_names |
|
| 163 | - * @return array |
|
| 164 | - */ |
|
| 165 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 166 | - { |
|
| 167 | - return array( |
|
| 168 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 177 | - * EE_Front_Controller's init phases have run |
|
| 178 | - * |
|
| 179 | - * @access public |
|
| 180 | - * @return void |
|
| 181 | - * @throws EE_Error |
|
| 182 | - * @throws ReflectionException |
|
| 183 | - */ |
|
| 184 | - public function init() |
|
| 185 | - { |
|
| 186 | - //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 187 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 188 | - //ok so we want to enable the entire admin |
|
| 189 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 190 | - add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 191 | - add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 192 | - //at a glance dashboard widget |
|
| 193 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 194 | - //filter for get_edit_post_link used on comments for custom post types |
|
| 195 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 196 | - } |
|
| 197 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 198 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | - try { |
|
| 200 | - //this loads the controller for the admin pages which will setup routing etc |
|
| 201 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 202 | - } catch (EE_Error $e) { |
|
| 203 | - $e->get_error(); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 207 | - //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 208 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 209 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 210 | - //exclude EE critical pages from all nav menus and wp_list_pages |
|
| 211 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 217 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 218 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 219 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 220 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 221 | - * |
|
| 222 | - * @param object $post_type WP post type object |
|
| 223 | - * @return object WP post type object |
|
| 224 | - */ |
|
| 225 | - public function remove_pages_from_nav_menu($post_type) |
|
| 226 | - { |
|
| 227 | - //if this isn't the "pages" post type let's get out |
|
| 228 | - if ($post_type->name !== 'page') { |
|
| 229 | - return $post_type; |
|
| 230 | - } |
|
| 231 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 232 | - |
|
| 233 | - $post_type->_default_query = array( |
|
| 234 | - 'post__not_in' => $critical_pages, |
|
| 235 | - ); |
|
| 236 | - return $post_type; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 242 | - * metaboxes get shown as well |
|
| 243 | - * |
|
| 244 | - * @access public |
|
| 245 | - * @return void |
|
| 246 | - */ |
|
| 247 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 248 | - { |
|
| 249 | - global $wp_meta_boxes, $pagenow; |
|
| 250 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | - return; |
|
| 252 | - } |
|
| 253 | - $user = wp_get_current_user(); |
|
| 254 | - //has this been done yet? |
|
| 255 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 256 | - return; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 260 | - $initial_meta_boxes = apply_filters( |
|
| 261 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 262 | - array( |
|
| 263 | - 'nav-menu-theme-locations', |
|
| 264 | - 'add-page', |
|
| 265 | - 'add-custom-links', |
|
| 266 | - 'add-category', |
|
| 267 | - 'add-espresso_events', |
|
| 268 | - 'add-espresso_venues', |
|
| 269 | - 'add-espresso_event_categories', |
|
| 270 | - 'add-espresso_venue_categories', |
|
| 271 | - 'add-post-type-post', |
|
| 272 | - 'add-post-type-page', |
|
| 273 | - ) |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - if (is_array($hidden_meta_boxes)) { |
|
| 277 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 278 | - if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 279 | - unset($hidden_meta_boxes[$key]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 285 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 291 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 292 | - * |
|
| 293 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 294 | - * addons etc. |
|
| 295 | - * @access public |
|
| 296 | - * @return void |
|
| 297 | - */ |
|
| 298 | - public function register_custom_nav_menu_boxes() |
|
| 299 | - { |
|
| 300 | - add_meta_box( |
|
| 301 | - 'add-extra-nav-menu-pages', |
|
| 302 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 303 | - array($this, 'ee_cpt_archive_pages'), |
|
| 304 | - 'nav-menus', |
|
| 305 | - 'side', |
|
| 306 | - 'core' |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 313 | - * |
|
| 314 | - * @since 4.3.0 |
|
| 315 | - * @param string $link the original link generated by wp |
|
| 316 | - * @param int $id post id |
|
| 317 | - * @return string the (maybe) modified link |
|
| 318 | - */ |
|
| 319 | - public function modify_edit_post_link($link, $id) |
|
| 320 | - { |
|
| 321 | - if (! $post = get_post($id)) { |
|
| 322 | - return $link; |
|
| 323 | - } |
|
| 324 | - if ($post->post_type === 'espresso_attendees') { |
|
| 325 | - $query_args = array( |
|
| 326 | - 'action' => 'edit_attendee', |
|
| 327 | - 'post' => $id, |
|
| 328 | - ); |
|
| 329 | - return EEH_URL::add_query_args_and_nonce( |
|
| 330 | - $query_args, |
|
| 331 | - admin_url('admin.php?page=espresso_registrations') |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - return $link; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - public function ee_cpt_archive_pages() |
|
| 339 | - { |
|
| 340 | - global $nav_menu_selected_id; |
|
| 341 | - |
|
| 342 | - $db_fields = false; |
|
| 343 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 344 | - $current_tab = 'event-archives'; |
|
| 345 | - |
|
| 346 | - /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
| 18 | + /** |
|
| 19 | + * @access private |
|
| 20 | + * @var EE_Admin $_instance |
|
| 21 | + */ |
|
| 22 | + private static $_instance; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + *@ singleton method used to instantiate class object |
|
| 27 | + *@ access public |
|
| 28 | + *@ return class instance |
|
| 29 | + * |
|
| 30 | + * @throws \EE_Error |
|
| 31 | + */ |
|
| 32 | + public static function instance() |
|
| 33 | + { |
|
| 34 | + // check if class object is instantiated |
|
| 35 | + if (! self::$_instance instanceof EE_Admin) { |
|
| 36 | + self::$_instance = new self(); |
|
| 37 | + } |
|
| 38 | + return self::$_instance; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return EE_Admin |
|
| 44 | + * @throws EE_Error |
|
| 45 | + */ |
|
| 46 | + public static function reset() |
|
| 47 | + { |
|
| 48 | + self::$_instance = null; |
|
| 49 | + return self::instance(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * class constructor |
|
| 55 | + * |
|
| 56 | + * @throws \EE_Error |
|
| 57 | + */ |
|
| 58 | + protected function __construct() |
|
| 59 | + { |
|
| 60 | + // define global EE_Admin constants |
|
| 61 | + $this->_define_all_constants(); |
|
| 62 | + // set autoloaders for our admin page classes based on included path information |
|
| 63 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 64 | + // admin hooks |
|
| 65 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 66 | + // load EE_Request_Handler early |
|
| 67 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 68 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 69 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 70 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 71 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 72 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 73 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 74 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 75 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 76 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 77 | + |
|
| 78 | + //reset Environment config (we only do this on admin page loads); |
|
| 79 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 80 | + |
|
| 81 | + do_action('AHEE__EE_Admin__loaded'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * _define_all_constants |
|
| 87 | + * define constants that are set globally for all admin pages |
|
| 88 | + * |
|
| 89 | + * @access private |
|
| 90 | + * @return void |
|
| 91 | + */ |
|
| 92 | + private function _define_all_constants() |
|
| 93 | + { |
|
| 94 | + if (! defined('EE_ADMIN_URL')) { |
|
| 95 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 99 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
| 106 | + * |
|
| 107 | + * @access public |
|
| 108 | + * @param array $links |
|
| 109 | + * @param string $plugin |
|
| 110 | + * @return array |
|
| 111 | + */ |
|
| 112 | + public function filter_plugin_actions($links, $plugin) |
|
| 113 | + { |
|
| 114 | + // set $main_file in stone |
|
| 115 | + static $main_file; |
|
| 116 | + // if $main_file is not set yet |
|
| 117 | + if (! $main_file) { |
|
| 118 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 119 | + } |
|
| 120 | + if ($plugin === $main_file) { |
|
| 121 | + // compare current plugin to this one |
|
| 122 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 123 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 124 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 125 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 126 | + . '</a>'; |
|
| 127 | + array_unshift($links, $maintenance_link); |
|
| 128 | + } else { |
|
| 129 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 130 | + . esc_html__('Settings', 'event_espresso') |
|
| 131 | + . '</a>'; |
|
| 132 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 133 | + . esc_html__('Events', 'event_espresso') |
|
| 134 | + . '</a>'; |
|
| 135 | + // add before other links |
|
| 136 | + array_unshift($links, $org_settings_link, $events_link); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + return $links; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * _get_request |
|
| 145 | + * |
|
| 146 | + * @access public |
|
| 147 | + * @return void |
|
| 148 | + * @throws EE_Error |
|
| 149 | + * @throws ReflectionException |
|
| 150 | + */ |
|
| 151 | + public function get_request() |
|
| 152 | + { |
|
| 153 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 154 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * hide_admin_pages_except_maintenance_mode |
|
| 160 | + * |
|
| 161 | + * @access public |
|
| 162 | + * @param array $admin_page_folder_names |
|
| 163 | + * @return array |
|
| 164 | + */ |
|
| 165 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 166 | + { |
|
| 167 | + return array( |
|
| 168 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | + 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | + 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 177 | + * EE_Front_Controller's init phases have run |
|
| 178 | + * |
|
| 179 | + * @access public |
|
| 180 | + * @return void |
|
| 181 | + * @throws EE_Error |
|
| 182 | + * @throws ReflectionException |
|
| 183 | + */ |
|
| 184 | + public function init() |
|
| 185 | + { |
|
| 186 | + //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 187 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 188 | + //ok so we want to enable the entire admin |
|
| 189 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 190 | + add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 191 | + add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 192 | + //at a glance dashboard widget |
|
| 193 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 194 | + //filter for get_edit_post_link used on comments for custom post types |
|
| 195 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 196 | + } |
|
| 197 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 198 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | + try { |
|
| 200 | + //this loads the controller for the admin pages which will setup routing etc |
|
| 201 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 202 | + } catch (EE_Error $e) { |
|
| 203 | + $e->get_error(); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 207 | + //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 208 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 209 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 210 | + //exclude EE critical pages from all nav menus and wp_list_pages |
|
| 211 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 217 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 218 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 219 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 220 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 221 | + * |
|
| 222 | + * @param object $post_type WP post type object |
|
| 223 | + * @return object WP post type object |
|
| 224 | + */ |
|
| 225 | + public function remove_pages_from_nav_menu($post_type) |
|
| 226 | + { |
|
| 227 | + //if this isn't the "pages" post type let's get out |
|
| 228 | + if ($post_type->name !== 'page') { |
|
| 229 | + return $post_type; |
|
| 230 | + } |
|
| 231 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 232 | + |
|
| 233 | + $post_type->_default_query = array( |
|
| 234 | + 'post__not_in' => $critical_pages, |
|
| 235 | + ); |
|
| 236 | + return $post_type; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 242 | + * metaboxes get shown as well |
|
| 243 | + * |
|
| 244 | + * @access public |
|
| 245 | + * @return void |
|
| 246 | + */ |
|
| 247 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 248 | + { |
|
| 249 | + global $wp_meta_boxes, $pagenow; |
|
| 250 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | + return; |
|
| 252 | + } |
|
| 253 | + $user = wp_get_current_user(); |
|
| 254 | + //has this been done yet? |
|
| 255 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 256 | + return; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 260 | + $initial_meta_boxes = apply_filters( |
|
| 261 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 262 | + array( |
|
| 263 | + 'nav-menu-theme-locations', |
|
| 264 | + 'add-page', |
|
| 265 | + 'add-custom-links', |
|
| 266 | + 'add-category', |
|
| 267 | + 'add-espresso_events', |
|
| 268 | + 'add-espresso_venues', |
|
| 269 | + 'add-espresso_event_categories', |
|
| 270 | + 'add-espresso_venue_categories', |
|
| 271 | + 'add-post-type-post', |
|
| 272 | + 'add-post-type-page', |
|
| 273 | + ) |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + if (is_array($hidden_meta_boxes)) { |
|
| 277 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 278 | + if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 279 | + unset($hidden_meta_boxes[$key]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 285 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 291 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 292 | + * |
|
| 293 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 294 | + * addons etc. |
|
| 295 | + * @access public |
|
| 296 | + * @return void |
|
| 297 | + */ |
|
| 298 | + public function register_custom_nav_menu_boxes() |
|
| 299 | + { |
|
| 300 | + add_meta_box( |
|
| 301 | + 'add-extra-nav-menu-pages', |
|
| 302 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 303 | + array($this, 'ee_cpt_archive_pages'), |
|
| 304 | + 'nav-menus', |
|
| 305 | + 'side', |
|
| 306 | + 'core' |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 313 | + * |
|
| 314 | + * @since 4.3.0 |
|
| 315 | + * @param string $link the original link generated by wp |
|
| 316 | + * @param int $id post id |
|
| 317 | + * @return string the (maybe) modified link |
|
| 318 | + */ |
|
| 319 | + public function modify_edit_post_link($link, $id) |
|
| 320 | + { |
|
| 321 | + if (! $post = get_post($id)) { |
|
| 322 | + return $link; |
|
| 323 | + } |
|
| 324 | + if ($post->post_type === 'espresso_attendees') { |
|
| 325 | + $query_args = array( |
|
| 326 | + 'action' => 'edit_attendee', |
|
| 327 | + 'post' => $id, |
|
| 328 | + ); |
|
| 329 | + return EEH_URL::add_query_args_and_nonce( |
|
| 330 | + $query_args, |
|
| 331 | + admin_url('admin.php?page=espresso_registrations') |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + return $link; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + public function ee_cpt_archive_pages() |
|
| 339 | + { |
|
| 340 | + global $nav_menu_selected_id; |
|
| 341 | + |
|
| 342 | + $db_fields = false; |
|
| 343 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 344 | + $current_tab = 'event-archives'; |
|
| 345 | + |
|
| 346 | + /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
| 347 | 347 | $current_tab = 'search'; |
| 348 | 348 | }/**/ |
| 349 | 349 | |
| 350 | - $removed_args = array( |
|
| 351 | - 'action', |
|
| 352 | - 'customlink-tab', |
|
| 353 | - 'edit-menu-item', |
|
| 354 | - 'menu-item', |
|
| 355 | - 'page-tab', |
|
| 356 | - '_wpnonce', |
|
| 357 | - ); |
|
| 350 | + $removed_args = array( |
|
| 351 | + 'action', |
|
| 352 | + 'customlink-tab', |
|
| 353 | + 'edit-menu-item', |
|
| 354 | + 'menu-item', |
|
| 355 | + 'page-tab', |
|
| 356 | + '_wpnonce', |
|
| 357 | + ); |
|
| 358 | 358 | |
| 359 | - ?> |
|
| 359 | + ?> |
|
| 360 | 360 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
| 361 | 361 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
| 362 | 362 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
| 363 | 363 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
| 364 | 364 | href="<?php if ($nav_menu_selected_id) { |
| 365 | - echo esc_url( |
|
| 366 | - add_query_arg( |
|
| 367 | - 'extra-nav-menu-pages-tab', |
|
| 368 | - 'event-archives', |
|
| 369 | - remove_query_arg($removed_args) |
|
| 370 | - ) |
|
| 371 | - ); |
|
| 372 | - } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 365 | + echo esc_url( |
|
| 366 | + add_query_arg( |
|
| 367 | + 'extra-nav-menu-pages-tab', |
|
| 368 | + 'event-archives', |
|
| 369 | + remove_query_arg($removed_args) |
|
| 370 | + ) |
|
| 371 | + ); |
|
| 372 | + } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 373 | 373 | <?php _e('Event Archive Pages', 'event_espresso'); ?> |
| 374 | 374 | </a> |
| 375 | 375 | </li> |
| 376 | 376 | |
| 377 | 377 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
| 378 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 379 | - ?>"> |
|
| 378 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 379 | + ?>"> |
|
| 380 | 380 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
| 381 | 381 | <?php |
| 382 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 383 | - $args['walker'] = $walker; |
|
| 384 | - echo walk_nav_menu_tree( |
|
| 385 | - array_map( |
|
| 386 | - array($this, '_setup_extra_nav_menu_pages_items'), |
|
| 387 | - $pages |
|
| 388 | - ), |
|
| 389 | - 0, |
|
| 390 | - (object) $args |
|
| 391 | - ); |
|
| 392 | - ?> |
|
| 382 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 383 | + $args['walker'] = $walker; |
|
| 384 | + echo walk_nav_menu_tree( |
|
| 385 | + array_map( |
|
| 386 | + array($this, '_setup_extra_nav_menu_pages_items'), |
|
| 387 | + $pages |
|
| 388 | + ), |
|
| 389 | + 0, |
|
| 390 | + (object) $args |
|
| 391 | + ); |
|
| 392 | + ?> |
|
| 393 | 393 | </ul> |
| 394 | 394 | </div><!-- /.tabs-panel --> |
| 395 | 395 | |
| 396 | 396 | <p class="button-controls"> |
| 397 | 397 | <span class="list-controls"> |
| 398 | 398 | <a href="<?php |
| 399 | - echo esc_url(add_query_arg( |
|
| 400 | - array( |
|
| 401 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 402 | - 'selectall' => 1, |
|
| 403 | - ), |
|
| 404 | - remove_query_arg($removed_args) |
|
| 405 | - )); |
|
| 406 | - ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
| 399 | + echo esc_url(add_query_arg( |
|
| 400 | + array( |
|
| 401 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 402 | + 'selectall' => 1, |
|
| 403 | + ), |
|
| 404 | + remove_query_arg($removed_args) |
|
| 405 | + )); |
|
| 406 | + ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
| 407 | 407 | </span> |
| 408 | 408 | <span class="add-to-menu"> |
| 409 | 409 | <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
@@ -416,491 +416,491 @@ discard block |
||
| 416 | 416 | |
| 417 | 417 | </div><!-- /.posttypediv --> |
| 418 | 418 | <?php |
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Returns an array of event archive nav items. |
|
| 424 | - * |
|
| 425 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 426 | - * method we use for getting the extra nav menu items |
|
| 427 | - * @return array |
|
| 428 | - */ |
|
| 429 | - private function _get_extra_nav_menu_pages_items() |
|
| 430 | - { |
|
| 431 | - $menuitems[] = array( |
|
| 432 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 433 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
| 434 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 435 | - ); |
|
| 436 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 442 | - * the properties and converts it to the menu item object. |
|
| 443 | - * |
|
| 444 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 445 | - * @param $menu_item_values |
|
| 446 | - * @return stdClass |
|
| 447 | - */ |
|
| 448 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 449 | - { |
|
| 450 | - $menu_item = new stdClass(); |
|
| 451 | - $keys = array( |
|
| 452 | - 'ID' => 0, |
|
| 453 | - 'db_id' => 0, |
|
| 454 | - 'menu_item_parent' => 0, |
|
| 455 | - 'object_id' => -1, |
|
| 456 | - 'post_parent' => 0, |
|
| 457 | - 'type' => 'custom', |
|
| 458 | - 'object' => '', |
|
| 459 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 460 | - 'title' => '', |
|
| 461 | - 'url' => '', |
|
| 462 | - 'target' => '', |
|
| 463 | - 'attr_title' => '', |
|
| 464 | - 'description' => '', |
|
| 465 | - 'classes' => array(), |
|
| 466 | - 'xfn' => '', |
|
| 467 | - ); |
|
| 468 | - |
|
| 469 | - foreach ($keys as $key => $value) { |
|
| 470 | - $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 471 | - } |
|
| 472 | - return $menu_item; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 478 | - * EE_Admin_Page route is called. |
|
| 479 | - * |
|
| 480 | - * @return void |
|
| 481 | - */ |
|
| 482 | - public function route_admin_request() |
|
| 483 | - { |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 489 | - * |
|
| 490 | - * @return void |
|
| 491 | - */ |
|
| 492 | - public function wp_loaded() |
|
| 493 | - { |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * admin_init |
|
| 499 | - * |
|
| 500 | - * @access public |
|
| 501 | - * @return void |
|
| 502 | - * @throws EE_Error |
|
| 503 | - * @throws ReflectionException |
|
| 504 | - */ |
|
| 505 | - public function admin_init() |
|
| 506 | - { |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 510 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 511 | - * - check if doing post processing. |
|
| 512 | - * - check if doing post processing of one of EE CPTs |
|
| 513 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 514 | - */ |
|
| 515 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 516 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 517 | - EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 523 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 524 | - * Pages" tab in the EE General Settings Admin page. |
|
| 525 | - * This is for user-proofing. |
|
| 526 | - */ |
|
| 527 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 533 | - * |
|
| 534 | - * @param string $output Current output. |
|
| 535 | - * @return string |
|
| 536 | - */ |
|
| 537 | - public function modify_dropdown_pages($output) |
|
| 538 | - { |
|
| 539 | - //get critical pages |
|
| 540 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 541 | - |
|
| 542 | - //split current output by line break for easier parsing. |
|
| 543 | - $split_output = explode("\n", $output); |
|
| 544 | - |
|
| 545 | - //loop through to remove any critical pages from the array. |
|
| 546 | - foreach ($critical_pages as $page_id) { |
|
| 547 | - $needle = 'value="' . $page_id . '"'; |
|
| 548 | - foreach ($split_output as $key => $haystack) { |
|
| 549 | - if (strpos($haystack, $needle) !== false) { |
|
| 550 | - unset($split_output[$key]); |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - //replace output with the new contents |
|
| 556 | - return implode("\n", $split_output); |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * enqueue all admin scripts that need loaded for admin pages |
|
| 562 | - * |
|
| 563 | - * @access public |
|
| 564 | - * @return void |
|
| 565 | - */ |
|
| 566 | - public function enqueue_admin_scripts() |
|
| 567 | - { |
|
| 568 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 569 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
| 570 | - // calls. |
|
| 571 | - wp_enqueue_script( |
|
| 572 | - 'ee-inject-wp', |
|
| 573 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 574 | - array('jquery'), |
|
| 575 | - EVENT_ESPRESSO_VERSION, |
|
| 576 | - true |
|
| 577 | - ); |
|
| 578 | - // register cookie script for future dependencies |
|
| 579 | - wp_register_script( |
|
| 580 | - 'jquery-cookie', |
|
| 581 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 582 | - array('jquery'), |
|
| 583 | - '2.1', |
|
| 584 | - true |
|
| 585 | - ); |
|
| 586 | - //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
| 587 | - // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 588 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
| 589 | - //joyride style |
|
| 590 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | - wp_register_style( |
|
| 592 | - 'ee-joyride-css', |
|
| 593 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 594 | - array('joyride-css'), |
|
| 595 | - EVENT_ESPRESSO_VERSION |
|
| 596 | - ); |
|
| 597 | - wp_register_script( |
|
| 598 | - 'joyride-modernizr', |
|
| 599 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 600 | - array(), |
|
| 601 | - '2.1', |
|
| 602 | - true |
|
| 603 | - ); |
|
| 604 | - //joyride JS |
|
| 605 | - wp_register_script( |
|
| 606 | - 'jquery-joyride', |
|
| 607 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 608 | - array('jquery-cookie', 'joyride-modernizr'), |
|
| 609 | - '2.1', |
|
| 610 | - true |
|
| 611 | - ); |
|
| 612 | - // wanna go for a joyride? |
|
| 613 | - wp_enqueue_style('ee-joyride-css'); |
|
| 614 | - wp_enqueue_script('jquery-joyride'); |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * display_admin_notices |
|
| 621 | - * |
|
| 622 | - * @access public |
|
| 623 | - * @return string |
|
| 624 | - */ |
|
| 625 | - public function display_admin_notices() |
|
| 626 | - { |
|
| 627 | - echo EE_Error::get_notices(); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * get_persistent_admin_notices |
|
| 633 | - * |
|
| 634 | - * @access public |
|
| 635 | - * @return void |
|
| 636 | - */ |
|
| 637 | - public function get_persistent_admin_notices() |
|
| 638 | - { |
|
| 639 | - // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
| 640 | - $args = array( |
|
| 641 | - 'page' => EE_Registry::instance()->REQ->is_set('page') |
|
| 642 | - ? EE_Registry::instance()->REQ->get('page') |
|
| 643 | - : '', |
|
| 644 | - 'action' => EE_Registry::instance()->REQ->is_set('action') |
|
| 645 | - ? EE_Registry::instance()->REQ->get('action') |
|
| 646 | - : '', |
|
| 647 | - ); |
|
| 648 | - $return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php')); |
|
| 649 | - //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 650 | - //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 651 | - //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 652 | - //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 653 | - if (! get_option('timezone_string')) { |
|
| 654 | - EE_Error::add_persistent_admin_notice( |
|
| 655 | - 'datetime_fix_notice', |
|
| 656 | - sprintf( |
|
| 657 | - esc_html__( |
|
| 658 | - '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 659 | - 'event_espresso' |
|
| 660 | - ), |
|
| 661 | - '<strong>', |
|
| 662 | - '</strong>', |
|
| 663 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 664 | - '</a>', |
|
| 665 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | - array( |
|
| 667 | - 'page' => 'espresso_maintenance_settings', |
|
| 668 | - 'action' => 'datetime_tools' |
|
| 669 | - ), |
|
| 670 | - admin_url('admin.php') |
|
| 671 | - ) . '">' |
|
| 672 | - ) |
|
| 673 | - ); |
|
| 674 | - } |
|
| 675 | - echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * dismiss_persistent_admin_notice |
|
| 681 | - * |
|
| 682 | - * @access public |
|
| 683 | - * @return void |
|
| 684 | - */ |
|
| 685 | - public function dismiss_ee_nag_notice_callback() |
|
| 686 | - { |
|
| 687 | - EE_Error::dismiss_persistent_admin_notice(); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * @param array $elements |
|
| 693 | - * @return array |
|
| 694 | - * @throws \EE_Error |
|
| 695 | - */ |
|
| 696 | - public function dashboard_glance_items($elements) |
|
| 697 | - { |
|
| 698 | - $elements = is_array($elements) ? $elements : array($elements); |
|
| 699 | - $events = EEM_Event::instance()->count(); |
|
| 700 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 701 | - array('page' => 'espresso_events'), |
|
| 702 | - admin_url('admin.php') |
|
| 703 | - ); |
|
| 704 | - $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 705 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 706 | - $registrations = EEM_Registration::instance()->count( |
|
| 707 | - array( |
|
| 708 | - array( |
|
| 709 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 710 | - ), |
|
| 711 | - ) |
|
| 712 | - ); |
|
| 713 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | - array('page' => 'espresso_registrations'), |
|
| 715 | - admin_url('admin.php') |
|
| 716 | - ); |
|
| 717 | - $items['registrations']['text'] = sprintf( |
|
| 718 | - _n('%s Registration', '%s Registrations', $registrations), |
|
| 719 | - number_format_i18n($registrations) |
|
| 720 | - ); |
|
| 721 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 722 | - |
|
| 723 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | - |
|
| 725 | - foreach ($items as $type => $item_properties) { |
|
| 726 | - $elements[] = sprintf( |
|
| 727 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 728 | - $item_properties['url'], |
|
| 729 | - $item_properties['title'], |
|
| 730 | - $item_properties['text'] |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - return $elements; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * check_for_invalid_datetime_formats |
|
| 739 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 740 | - * their selected format can be parsed by PHP |
|
| 741 | - * |
|
| 742 | - * @access public |
|
| 743 | - * @param $value |
|
| 744 | - * @param $option |
|
| 745 | - * @throws EE_Error |
|
| 746 | - * @return string |
|
| 747 | - */ |
|
| 748 | - public function check_for_invalid_datetime_formats($value, $option) |
|
| 749 | - { |
|
| 750 | - // check for date_format or time_format |
|
| 751 | - switch ($option) { |
|
| 752 | - case 'date_format': |
|
| 753 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 754 | - break; |
|
| 755 | - case 'time_format': |
|
| 756 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 757 | - break; |
|
| 758 | - default: |
|
| 759 | - $date_time_format = false; |
|
| 760 | - } |
|
| 761 | - // do we have a date_time format to check ? |
|
| 762 | - if ($date_time_format) { |
|
| 763 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 764 | - |
|
| 765 | - if (is_array($error_msg)) { |
|
| 766 | - $msg = '<p>' |
|
| 767 | - . sprintf( |
|
| 768 | - esc_html__( |
|
| 769 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 770 | - 'event_espresso' |
|
| 771 | - ), |
|
| 772 | - date($date_time_format), |
|
| 773 | - $date_time_format |
|
| 774 | - ) |
|
| 775 | - . '</p><p><ul>'; |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - foreach ($error_msg as $error) { |
|
| 779 | - $msg .= '<li>' . $error . '</li>'; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - $msg .= '</ul></p><p>' |
|
| 783 | - . sprintf( |
|
| 784 | - esc_html__( |
|
| 785 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 786 | - 'event_espresso' |
|
| 787 | - ), |
|
| 788 | - '<span style="color:#D54E21;">', |
|
| 789 | - '</span>' |
|
| 790 | - ) |
|
| 791 | - . '</p>'; |
|
| 792 | - |
|
| 793 | - // trigger WP settings error |
|
| 794 | - add_settings_error( |
|
| 795 | - 'date_format', |
|
| 796 | - 'date_format', |
|
| 797 | - $msg |
|
| 798 | - ); |
|
| 799 | - |
|
| 800 | - // set format to something valid |
|
| 801 | - switch ($option) { |
|
| 802 | - case 'date_format': |
|
| 803 | - $value = 'F j, Y'; |
|
| 804 | - break; |
|
| 805 | - case 'time_format': |
|
| 806 | - $value = 'g:i a'; |
|
| 807 | - break; |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - return $value; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 817 | - * |
|
| 818 | - * @access public |
|
| 819 | - * @param $content |
|
| 820 | - * @return string |
|
| 821 | - */ |
|
| 822 | - public function its_eSpresso($content) |
|
| 823 | - { |
|
| 824 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * espresso_admin_footer |
|
| 830 | - * |
|
| 831 | - * @access public |
|
| 832 | - * @return string |
|
| 833 | - */ |
|
| 834 | - public function espresso_admin_footer() |
|
| 835 | - { |
|
| 836 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * static method for registering ee admin page. |
|
| 842 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 843 | - * |
|
| 844 | - * @since 4.3.0 |
|
| 845 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 846 | - * @see EE_Register_Admin_Page::register() |
|
| 847 | - * @param $page_basename |
|
| 848 | - * @param $page_path |
|
| 849 | - * @param array $config |
|
| 850 | - * @return void |
|
| 851 | - * @throws EE_Error |
|
| 852 | - */ |
|
| 853 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 854 | - { |
|
| 855 | - EE_Error::doing_it_wrong( |
|
| 856 | - __METHOD__, |
|
| 857 | - sprintf( |
|
| 858 | - esc_html__( |
|
| 859 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 860 | - 'event_espresso' |
|
| 861 | - ), |
|
| 862 | - $page_basename |
|
| 863 | - ), |
|
| 864 | - '4.3' |
|
| 865 | - ); |
|
| 866 | - if (class_exists('EE_Register_Admin_Page')) { |
|
| 867 | - $config['page_path'] = $page_path; |
|
| 868 | - } |
|
| 869 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * @deprecated 4.8.41 |
|
| 875 | - * @access public |
|
| 876 | - * @param int $post_ID |
|
| 877 | - * @param \WP_Post $post |
|
| 878 | - * @return void |
|
| 879 | - */ |
|
| 880 | - public static function parse_post_content_on_save($post_ID, $post) |
|
| 881 | - { |
|
| 882 | - EE_Error::doing_it_wrong( |
|
| 883 | - __METHOD__, |
|
| 884 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 885 | - '4.8.41' |
|
| 886 | - ); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * @deprecated 4.8.41 |
|
| 892 | - * @access public |
|
| 893 | - * @param $option |
|
| 894 | - * @param $old_value |
|
| 895 | - * @param $value |
|
| 896 | - * @return void |
|
| 897 | - */ |
|
| 898 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 899 | - { |
|
| 900 | - EE_Error::doing_it_wrong( |
|
| 901 | - __METHOD__, |
|
| 902 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 903 | - '4.8.41' |
|
| 904 | - ); |
|
| 905 | - } |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Returns an array of event archive nav items. |
|
| 424 | + * |
|
| 425 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 426 | + * method we use for getting the extra nav menu items |
|
| 427 | + * @return array |
|
| 428 | + */ |
|
| 429 | + private function _get_extra_nav_menu_pages_items() |
|
| 430 | + { |
|
| 431 | + $menuitems[] = array( |
|
| 432 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 433 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
| 434 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 435 | + ); |
|
| 436 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 442 | + * the properties and converts it to the menu item object. |
|
| 443 | + * |
|
| 444 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 445 | + * @param $menu_item_values |
|
| 446 | + * @return stdClass |
|
| 447 | + */ |
|
| 448 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 449 | + { |
|
| 450 | + $menu_item = new stdClass(); |
|
| 451 | + $keys = array( |
|
| 452 | + 'ID' => 0, |
|
| 453 | + 'db_id' => 0, |
|
| 454 | + 'menu_item_parent' => 0, |
|
| 455 | + 'object_id' => -1, |
|
| 456 | + 'post_parent' => 0, |
|
| 457 | + 'type' => 'custom', |
|
| 458 | + 'object' => '', |
|
| 459 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 460 | + 'title' => '', |
|
| 461 | + 'url' => '', |
|
| 462 | + 'target' => '', |
|
| 463 | + 'attr_title' => '', |
|
| 464 | + 'description' => '', |
|
| 465 | + 'classes' => array(), |
|
| 466 | + 'xfn' => '', |
|
| 467 | + ); |
|
| 468 | + |
|
| 469 | + foreach ($keys as $key => $value) { |
|
| 470 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 471 | + } |
|
| 472 | + return $menu_item; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 478 | + * EE_Admin_Page route is called. |
|
| 479 | + * |
|
| 480 | + * @return void |
|
| 481 | + */ |
|
| 482 | + public function route_admin_request() |
|
| 483 | + { |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 489 | + * |
|
| 490 | + * @return void |
|
| 491 | + */ |
|
| 492 | + public function wp_loaded() |
|
| 493 | + { |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * admin_init |
|
| 499 | + * |
|
| 500 | + * @access public |
|
| 501 | + * @return void |
|
| 502 | + * @throws EE_Error |
|
| 503 | + * @throws ReflectionException |
|
| 504 | + */ |
|
| 505 | + public function admin_init() |
|
| 506 | + { |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 510 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 511 | + * - check if doing post processing. |
|
| 512 | + * - check if doing post processing of one of EE CPTs |
|
| 513 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 514 | + */ |
|
| 515 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 516 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 517 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 523 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 524 | + * Pages" tab in the EE General Settings Admin page. |
|
| 525 | + * This is for user-proofing. |
|
| 526 | + */ |
|
| 527 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 533 | + * |
|
| 534 | + * @param string $output Current output. |
|
| 535 | + * @return string |
|
| 536 | + */ |
|
| 537 | + public function modify_dropdown_pages($output) |
|
| 538 | + { |
|
| 539 | + //get critical pages |
|
| 540 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 541 | + |
|
| 542 | + //split current output by line break for easier parsing. |
|
| 543 | + $split_output = explode("\n", $output); |
|
| 544 | + |
|
| 545 | + //loop through to remove any critical pages from the array. |
|
| 546 | + foreach ($critical_pages as $page_id) { |
|
| 547 | + $needle = 'value="' . $page_id . '"'; |
|
| 548 | + foreach ($split_output as $key => $haystack) { |
|
| 549 | + if (strpos($haystack, $needle) !== false) { |
|
| 550 | + unset($split_output[$key]); |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + //replace output with the new contents |
|
| 556 | + return implode("\n", $split_output); |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * enqueue all admin scripts that need loaded for admin pages |
|
| 562 | + * |
|
| 563 | + * @access public |
|
| 564 | + * @return void |
|
| 565 | + */ |
|
| 566 | + public function enqueue_admin_scripts() |
|
| 567 | + { |
|
| 568 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 569 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
| 570 | + // calls. |
|
| 571 | + wp_enqueue_script( |
|
| 572 | + 'ee-inject-wp', |
|
| 573 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 574 | + array('jquery'), |
|
| 575 | + EVENT_ESPRESSO_VERSION, |
|
| 576 | + true |
|
| 577 | + ); |
|
| 578 | + // register cookie script for future dependencies |
|
| 579 | + wp_register_script( |
|
| 580 | + 'jquery-cookie', |
|
| 581 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 582 | + array('jquery'), |
|
| 583 | + '2.1', |
|
| 584 | + true |
|
| 585 | + ); |
|
| 586 | + //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
| 587 | + // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 588 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
| 589 | + //joyride style |
|
| 590 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | + wp_register_style( |
|
| 592 | + 'ee-joyride-css', |
|
| 593 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 594 | + array('joyride-css'), |
|
| 595 | + EVENT_ESPRESSO_VERSION |
|
| 596 | + ); |
|
| 597 | + wp_register_script( |
|
| 598 | + 'joyride-modernizr', |
|
| 599 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 600 | + array(), |
|
| 601 | + '2.1', |
|
| 602 | + true |
|
| 603 | + ); |
|
| 604 | + //joyride JS |
|
| 605 | + wp_register_script( |
|
| 606 | + 'jquery-joyride', |
|
| 607 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 608 | + array('jquery-cookie', 'joyride-modernizr'), |
|
| 609 | + '2.1', |
|
| 610 | + true |
|
| 611 | + ); |
|
| 612 | + // wanna go for a joyride? |
|
| 613 | + wp_enqueue_style('ee-joyride-css'); |
|
| 614 | + wp_enqueue_script('jquery-joyride'); |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * display_admin_notices |
|
| 621 | + * |
|
| 622 | + * @access public |
|
| 623 | + * @return string |
|
| 624 | + */ |
|
| 625 | + public function display_admin_notices() |
|
| 626 | + { |
|
| 627 | + echo EE_Error::get_notices(); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * get_persistent_admin_notices |
|
| 633 | + * |
|
| 634 | + * @access public |
|
| 635 | + * @return void |
|
| 636 | + */ |
|
| 637 | + public function get_persistent_admin_notices() |
|
| 638 | + { |
|
| 639 | + // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
| 640 | + $args = array( |
|
| 641 | + 'page' => EE_Registry::instance()->REQ->is_set('page') |
|
| 642 | + ? EE_Registry::instance()->REQ->get('page') |
|
| 643 | + : '', |
|
| 644 | + 'action' => EE_Registry::instance()->REQ->is_set('action') |
|
| 645 | + ? EE_Registry::instance()->REQ->get('action') |
|
| 646 | + : '', |
|
| 647 | + ); |
|
| 648 | + $return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php')); |
|
| 649 | + //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 650 | + //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 651 | + //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 652 | + //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 653 | + if (! get_option('timezone_string')) { |
|
| 654 | + EE_Error::add_persistent_admin_notice( |
|
| 655 | + 'datetime_fix_notice', |
|
| 656 | + sprintf( |
|
| 657 | + esc_html__( |
|
| 658 | + '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 659 | + 'event_espresso' |
|
| 660 | + ), |
|
| 661 | + '<strong>', |
|
| 662 | + '</strong>', |
|
| 663 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 664 | + '</a>', |
|
| 665 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | + array( |
|
| 667 | + 'page' => 'espresso_maintenance_settings', |
|
| 668 | + 'action' => 'datetime_tools' |
|
| 669 | + ), |
|
| 670 | + admin_url('admin.php') |
|
| 671 | + ) . '">' |
|
| 672 | + ) |
|
| 673 | + ); |
|
| 674 | + } |
|
| 675 | + echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * dismiss_persistent_admin_notice |
|
| 681 | + * |
|
| 682 | + * @access public |
|
| 683 | + * @return void |
|
| 684 | + */ |
|
| 685 | + public function dismiss_ee_nag_notice_callback() |
|
| 686 | + { |
|
| 687 | + EE_Error::dismiss_persistent_admin_notice(); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * @param array $elements |
|
| 693 | + * @return array |
|
| 694 | + * @throws \EE_Error |
|
| 695 | + */ |
|
| 696 | + public function dashboard_glance_items($elements) |
|
| 697 | + { |
|
| 698 | + $elements = is_array($elements) ? $elements : array($elements); |
|
| 699 | + $events = EEM_Event::instance()->count(); |
|
| 700 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 701 | + array('page' => 'espresso_events'), |
|
| 702 | + admin_url('admin.php') |
|
| 703 | + ); |
|
| 704 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 705 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 706 | + $registrations = EEM_Registration::instance()->count( |
|
| 707 | + array( |
|
| 708 | + array( |
|
| 709 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 710 | + ), |
|
| 711 | + ) |
|
| 712 | + ); |
|
| 713 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | + array('page' => 'espresso_registrations'), |
|
| 715 | + admin_url('admin.php') |
|
| 716 | + ); |
|
| 717 | + $items['registrations']['text'] = sprintf( |
|
| 718 | + _n('%s Registration', '%s Registrations', $registrations), |
|
| 719 | + number_format_i18n($registrations) |
|
| 720 | + ); |
|
| 721 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 722 | + |
|
| 723 | + $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | + |
|
| 725 | + foreach ($items as $type => $item_properties) { |
|
| 726 | + $elements[] = sprintf( |
|
| 727 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 728 | + $item_properties['url'], |
|
| 729 | + $item_properties['title'], |
|
| 730 | + $item_properties['text'] |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + return $elements; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * check_for_invalid_datetime_formats |
|
| 739 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 740 | + * their selected format can be parsed by PHP |
|
| 741 | + * |
|
| 742 | + * @access public |
|
| 743 | + * @param $value |
|
| 744 | + * @param $option |
|
| 745 | + * @throws EE_Error |
|
| 746 | + * @return string |
|
| 747 | + */ |
|
| 748 | + public function check_for_invalid_datetime_formats($value, $option) |
|
| 749 | + { |
|
| 750 | + // check for date_format or time_format |
|
| 751 | + switch ($option) { |
|
| 752 | + case 'date_format': |
|
| 753 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 754 | + break; |
|
| 755 | + case 'time_format': |
|
| 756 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 757 | + break; |
|
| 758 | + default: |
|
| 759 | + $date_time_format = false; |
|
| 760 | + } |
|
| 761 | + // do we have a date_time format to check ? |
|
| 762 | + if ($date_time_format) { |
|
| 763 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 764 | + |
|
| 765 | + if (is_array($error_msg)) { |
|
| 766 | + $msg = '<p>' |
|
| 767 | + . sprintf( |
|
| 768 | + esc_html__( |
|
| 769 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 770 | + 'event_espresso' |
|
| 771 | + ), |
|
| 772 | + date($date_time_format), |
|
| 773 | + $date_time_format |
|
| 774 | + ) |
|
| 775 | + . '</p><p><ul>'; |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + foreach ($error_msg as $error) { |
|
| 779 | + $msg .= '<li>' . $error . '</li>'; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + $msg .= '</ul></p><p>' |
|
| 783 | + . sprintf( |
|
| 784 | + esc_html__( |
|
| 785 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 786 | + 'event_espresso' |
|
| 787 | + ), |
|
| 788 | + '<span style="color:#D54E21;">', |
|
| 789 | + '</span>' |
|
| 790 | + ) |
|
| 791 | + . '</p>'; |
|
| 792 | + |
|
| 793 | + // trigger WP settings error |
|
| 794 | + add_settings_error( |
|
| 795 | + 'date_format', |
|
| 796 | + 'date_format', |
|
| 797 | + $msg |
|
| 798 | + ); |
|
| 799 | + |
|
| 800 | + // set format to something valid |
|
| 801 | + switch ($option) { |
|
| 802 | + case 'date_format': |
|
| 803 | + $value = 'F j, Y'; |
|
| 804 | + break; |
|
| 805 | + case 'time_format': |
|
| 806 | + $value = 'g:i a'; |
|
| 807 | + break; |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + return $value; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 817 | + * |
|
| 818 | + * @access public |
|
| 819 | + * @param $content |
|
| 820 | + * @return string |
|
| 821 | + */ |
|
| 822 | + public function its_eSpresso($content) |
|
| 823 | + { |
|
| 824 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * espresso_admin_footer |
|
| 830 | + * |
|
| 831 | + * @access public |
|
| 832 | + * @return string |
|
| 833 | + */ |
|
| 834 | + public function espresso_admin_footer() |
|
| 835 | + { |
|
| 836 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * static method for registering ee admin page. |
|
| 842 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 843 | + * |
|
| 844 | + * @since 4.3.0 |
|
| 845 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 846 | + * @see EE_Register_Admin_Page::register() |
|
| 847 | + * @param $page_basename |
|
| 848 | + * @param $page_path |
|
| 849 | + * @param array $config |
|
| 850 | + * @return void |
|
| 851 | + * @throws EE_Error |
|
| 852 | + */ |
|
| 853 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 854 | + { |
|
| 855 | + EE_Error::doing_it_wrong( |
|
| 856 | + __METHOD__, |
|
| 857 | + sprintf( |
|
| 858 | + esc_html__( |
|
| 859 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 860 | + 'event_espresso' |
|
| 861 | + ), |
|
| 862 | + $page_basename |
|
| 863 | + ), |
|
| 864 | + '4.3' |
|
| 865 | + ); |
|
| 866 | + if (class_exists('EE_Register_Admin_Page')) { |
|
| 867 | + $config['page_path'] = $page_path; |
|
| 868 | + } |
|
| 869 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * @deprecated 4.8.41 |
|
| 875 | + * @access public |
|
| 876 | + * @param int $post_ID |
|
| 877 | + * @param \WP_Post $post |
|
| 878 | + * @return void |
|
| 879 | + */ |
|
| 880 | + public static function parse_post_content_on_save($post_ID, $post) |
|
| 881 | + { |
|
| 882 | + EE_Error::doing_it_wrong( |
|
| 883 | + __METHOD__, |
|
| 884 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 885 | + '4.8.41' |
|
| 886 | + ); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * @deprecated 4.8.41 |
|
| 892 | + * @access public |
|
| 893 | + * @param $option |
|
| 894 | + * @param $old_value |
|
| 895 | + * @param $value |
|
| 896 | + * @return void |
|
| 897 | + */ |
|
| 898 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 899 | + { |
|
| 900 | + EE_Error::doing_it_wrong( |
|
| 901 | + __METHOD__, |
|
| 902 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 903 | + '4.8.41' |
|
| 904 | + ); |
|
| 905 | + } |
|
| 906 | 906 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public static function instance() |
| 33 | 33 | { |
| 34 | 34 | // check if class object is instantiated |
| 35 | - if (! self::$_instance instanceof EE_Admin) { |
|
| 35 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
| 36 | 36 | self::$_instance = new self(); |
| 37 | 37 | } |
| 38 | 38 | return self::$_instance; |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | private function _define_all_constants() |
| 93 | 93 | { |
| 94 | - if (! defined('EE_ADMIN_URL')) { |
|
| 95 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 94 | + if ( ! defined('EE_ADMIN_URL')) { |
|
| 95 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
| 96 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
| 97 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
| 98 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
| 99 | 99 | define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | // set $main_file in stone |
| 115 | 115 | static $main_file; |
| 116 | 116 | // if $main_file is not set yet |
| 117 | - if (! $main_file) { |
|
| 117 | + if ( ! $main_file) { |
|
| 118 | 118 | $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
| 119 | 119 | } |
| 120 | 120 | if ($plugin === $main_file) { |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
| 166 | 166 | { |
| 167 | 167 | return array( |
| 168 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 168 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
| 169 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
| 170 | + 'support' => EE_ADMIN_PAGES.'support'.DS, |
|
| 171 | 171 | ); |
| 172 | 172 | } |
| 173 | 173 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
| 196 | 196 | } |
| 197 | 197 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
| 198 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 198 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | 199 | try { |
| 200 | 200 | //this loads the controller for the admin pages which will setup routing etc |
| 201 | 201 | EE_Registry::instance()->load_core('Admin_Page_Loader'); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | public function enable_hidden_ee_nav_menu_metaboxes() |
| 248 | 248 | { |
| 249 | 249 | global $wp_meta_boxes, $pagenow; |
| 250 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 250 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | 251 | return; |
| 252 | 252 | } |
| 253 | 253 | $user = wp_get_current_user(); |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | */ |
| 319 | 319 | public function modify_edit_post_link($link, $id) |
| 320 | 320 | { |
| 321 | - if (! $post = get_post($id)) { |
|
| 321 | + if ( ! $post = get_post($id)) { |
|
| 322 | 322 | return $link; |
| 323 | 323 | } |
| 324 | 324 | if ($post->post_type === 'espresso_attendees') { |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | |
| 545 | 545 | //loop through to remove any critical pages from the array. |
| 546 | 546 | foreach ($critical_pages as $page_id) { |
| 547 | - $needle = 'value="' . $page_id . '"'; |
|
| 547 | + $needle = 'value="'.$page_id.'"'; |
|
| 548 | 548 | foreach ($split_output as $key => $haystack) { |
| 549 | 549 | if (strpos($haystack, $needle) !== false) { |
| 550 | 550 | unset($split_output[$key]); |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | // calls. |
| 571 | 571 | wp_enqueue_script( |
| 572 | 572 | 'ee-inject-wp', |
| 573 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 573 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
| 574 | 574 | array('jquery'), |
| 575 | 575 | EVENT_ESPRESSO_VERSION, |
| 576 | 576 | true |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | // register cookie script for future dependencies |
| 579 | 579 | wp_register_script( |
| 580 | 580 | 'jquery-cookie', |
| 581 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 581 | + EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', |
|
| 582 | 582 | array('jquery'), |
| 583 | 583 | '2.1', |
| 584 | 584 | true |
@@ -587,16 +587,16 @@ discard block |
||
| 587 | 587 | // via: add_filter('FHEE_load_joyride', '__return_true' ); |
| 588 | 588 | if (apply_filters('FHEE_load_joyride', false)) { |
| 589 | 589 | //joyride style |
| 590 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 590 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | 591 | wp_register_style( |
| 592 | 592 | 'ee-joyride-css', |
| 593 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 593 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
| 594 | 594 | array('joyride-css'), |
| 595 | 595 | EVENT_ESPRESSO_VERSION |
| 596 | 596 | ); |
| 597 | 597 | wp_register_script( |
| 598 | 598 | 'joyride-modernizr', |
| 599 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 599 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
| 600 | 600 | array(), |
| 601 | 601 | '2.1', |
| 602 | 602 | true |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | //joyride JS |
| 605 | 605 | wp_register_script( |
| 606 | 606 | 'jquery-joyride', |
| 607 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 607 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
| 608 | 608 | array('jquery-cookie', 'joyride-modernizr'), |
| 609 | 609 | '2.1', |
| 610 | 610 | true |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | public function get_persistent_admin_notices() |
| 638 | 638 | { |
| 639 | 639 | // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
| 640 | - $args = array( |
|
| 640 | + $args = array( |
|
| 641 | 641 | 'page' => EE_Registry::instance()->REQ->is_set('page') |
| 642 | 642 | ? EE_Registry::instance()->REQ->get('page') |
| 643 | 643 | : '', |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
| 651 | 651 | //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
| 652 | 652 | //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
| 653 | - if (! get_option('timezone_string')) { |
|
| 653 | + if ( ! get_option('timezone_string')) { |
|
| 654 | 654 | EE_Error::add_persistent_admin_notice( |
| 655 | 655 | 'datetime_fix_notice', |
| 656 | 656 | sprintf( |
@@ -662,13 +662,13 @@ discard block |
||
| 662 | 662 | '</strong>', |
| 663 | 663 | '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
| 664 | 664 | '</a>', |
| 665 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 665 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | 666 | array( |
| 667 | 667 | 'page' => 'espresso_maintenance_settings', |
| 668 | 668 | 'action' => 'datetime_tools' |
| 669 | 669 | ), |
| 670 | 670 | admin_url('admin.php') |
| 671 | - ) . '">' |
|
| 671 | + ).'">' |
|
| 672 | 672 | ) |
| 673 | 673 | ); |
| 674 | 674 | } |
@@ -710,21 +710,21 @@ discard block |
||
| 710 | 710 | ), |
| 711 | 711 | ) |
| 712 | 712 | ); |
| 713 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 713 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | 714 | array('page' => 'espresso_registrations'), |
| 715 | 715 | admin_url('admin.php') |
| 716 | 716 | ); |
| 717 | - $items['registrations']['text'] = sprintf( |
|
| 717 | + $items['registrations']['text'] = sprintf( |
|
| 718 | 718 | _n('%s Registration', '%s Registrations', $registrations), |
| 719 | 719 | number_format_i18n($registrations) |
| 720 | 720 | ); |
| 721 | 721 | $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
| 722 | 722 | |
| 723 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 723 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | 724 | |
| 725 | 725 | foreach ($items as $type => $item_properties) { |
| 726 | 726 | $elements[] = sprintf( |
| 727 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 727 | + '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', |
|
| 728 | 728 | $item_properties['url'], |
| 729 | 729 | $item_properties['title'], |
| 730 | 730 | $item_properties['text'] |
@@ -750,10 +750,10 @@ discard block |
||
| 750 | 750 | // check for date_format or time_format |
| 751 | 751 | switch ($option) { |
| 752 | 752 | case 'date_format': |
| 753 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 753 | + $date_time_format = $value.' '.get_option('time_format'); |
|
| 754 | 754 | break; |
| 755 | 755 | case 'time_format': |
| 756 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 756 | + $date_time_format = get_option('date_format').' '.$value; |
|
| 757 | 757 | break; |
| 758 | 758 | default: |
| 759 | 759 | $date_time_format = false; |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | |
| 777 | 777 | |
| 778 | 778 | foreach ($error_msg as $error) { |
| 779 | - $msg .= '<li>' . $error . '</li>'; |
|
| 779 | + $msg .= '<li>'.$error.'</li>'; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | $msg .= '</ul></p><p>' |
@@ -15,753 +15,753 @@ |
||
| 15 | 15 | class EE_Datetime_Field extends EE_Model_Field_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
| 20 | - * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
| 21 | - * |
|
| 22 | - * @type string unix_timestamp_regex |
|
| 23 | - */ |
|
| 24 | - const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @type string mysql_timestamp_format |
|
| 28 | - */ |
|
| 29 | - const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @type string mysql_date_format |
|
| 33 | - */ |
|
| 34 | - const mysql_date_format = 'Y-m-d'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @type string mysql_time_format |
|
| 38 | - */ |
|
| 39 | - const mysql_time_format = 'H:i:s'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Const for using in the default value. If the field's default is set to this, |
|
| 43 | - * then we will return the time of calling `get_default_value()`, not |
|
| 44 | - * just the current time at construction |
|
| 45 | - */ |
|
| 46 | - const now = 'now'; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * The following properties hold the default formats for date and time. |
|
| 50 | - * Defaults are set via the constructor and can be overridden on class instantiation. |
|
| 51 | - * However they can also be overridden later by the set_format() method |
|
| 52 | - * (and corresponding set_date_format, set_time_format methods); |
|
| 53 | - */ |
|
| 54 | - /** |
|
| 55 | - * @type string $_date_format |
|
| 56 | - */ |
|
| 57 | - protected $_date_format = ''; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @type string $_time_format |
|
| 61 | - */ |
|
| 62 | - protected $_time_format = ''; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @type string $_pretty_date_format |
|
| 66 | - */ |
|
| 67 | - protected $_pretty_date_format = ''; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @type string $_pretty_time_format |
|
| 71 | - */ |
|
| 72 | - protected $_pretty_time_format = ''; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @type DateTimeZone $_DateTimeZone |
|
| 76 | - */ |
|
| 77 | - protected $_DateTimeZone; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @type DateTimeZone $_UTC_DateTimeZone |
|
| 81 | - */ |
|
| 82 | - protected $_UTC_DateTimeZone; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @type DateTimeZone $_blog_DateTimeZone |
|
| 86 | - */ |
|
| 87 | - protected $_blog_DateTimeZone; |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
| 92 | - * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
| 93 | - * and time returned via getters. |
|
| 94 | - * |
|
| 95 | - * @var mixed (null|string) |
|
| 96 | - */ |
|
| 97 | - protected $_date_time_output; |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * timezone string |
|
| 102 | - * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
| 103 | - * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
| 104 | - * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
| 105 | - * |
|
| 106 | - * @var string |
|
| 107 | - */ |
|
| 108 | - protected $_timezone_string; |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
| 113 | - * offsets for comparison purposes). |
|
| 114 | - * |
|
| 115 | - * @var int |
|
| 116 | - */ |
|
| 117 | - protected $_blog_offset; |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param string $table_column |
|
| 123 | - * @param string $nice_name |
|
| 124 | - * @param bool $nullable |
|
| 125 | - * @param string $default_value |
|
| 126 | - * @param string $timezone_string |
|
| 127 | - * @param string $date_format |
|
| 128 | - * @param string $time_format |
|
| 129 | - * @param string $pretty_date_format |
|
| 130 | - * @param string $pretty_time_format |
|
| 131 | - * @throws EE_Error |
|
| 132 | - * @throws InvalidArgumentException |
|
| 133 | - */ |
|
| 134 | - public function __construct( |
|
| 135 | - $table_column, |
|
| 136 | - $nice_name, |
|
| 137 | - $nullable, |
|
| 138 | - $default_value, |
|
| 139 | - $timezone_string = '', |
|
| 140 | - $date_format = '', |
|
| 141 | - $time_format = '', |
|
| 142 | - $pretty_date_format = '', |
|
| 143 | - $pretty_time_format = '' |
|
| 144 | - ) { |
|
| 145 | - |
|
| 146 | - $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 147 | - $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 148 | - $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
| 149 | - $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
| 150 | - |
|
| 151 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 152 | - $this->set_timezone($timezone_string); |
|
| 153 | - $this->setSchemaFormat('date-time'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @return DateTimeZone |
|
| 159 | - * @throws \EE_Error |
|
| 160 | - */ |
|
| 161 | - public function get_UTC_DateTimeZone() |
|
| 162 | - { |
|
| 163 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
| 164 | - ? $this->_UTC_DateTimeZone |
|
| 165 | - : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @return DateTimeZone |
|
| 171 | - * @throws \EE_Error |
|
| 172 | - */ |
|
| 173 | - public function get_blog_DateTimeZone() |
|
| 174 | - { |
|
| 175 | - return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
| 176 | - ? $this->_blog_DateTimeZone |
|
| 177 | - : $this->_create_timezone_object_from_timezone_string(''); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
| 183 | - * |
|
| 184 | - * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
| 185 | - * timestamp |
|
| 186 | - * @return DateTime |
|
| 187 | - */ |
|
| 188 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 189 | - { |
|
| 190 | - return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
| 196 | - * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
| 197 | - * |
|
| 198 | - * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
| 199 | - * @return string The final assembled format string. |
|
| 200 | - */ |
|
| 201 | - protected function _get_date_time_output($pretty = false) |
|
| 202 | - { |
|
| 203 | - |
|
| 204 | - switch ($this->_date_time_output) { |
|
| 205 | - case 'time' : |
|
| 206 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 207 | - break; |
|
| 208 | - |
|
| 209 | - case 'date' : |
|
| 210 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 211 | - break; |
|
| 212 | - |
|
| 213 | - default : |
|
| 214 | - return $pretty |
|
| 215 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 216 | - : $this->_date_format . ' ' . $this->_time_format; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
| 223 | - * returned (using the format properties) |
|
| 224 | - * |
|
| 225 | - * @param string $what acceptable values are 'time' or 'date'. |
|
| 226 | - * Any other value will be set but will always result |
|
| 227 | - * in both 'date' and 'time' being returned. |
|
| 228 | - * @return void |
|
| 229 | - */ |
|
| 230 | - public function set_date_time_output($what = null) |
|
| 231 | - { |
|
| 232 | - $this->_date_time_output = $what; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 238 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 239 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
| 240 | - * We also set some other properties in this method. |
|
| 241 | - * |
|
| 242 | - * @param string $timezone_string A valid timezone string as described by @link |
|
| 243 | - * http://www.php.net/manual/en/timezones.php |
|
| 244 | - * @return void |
|
| 245 | - * @throws \EE_Error |
|
| 246 | - */ |
|
| 247 | - public function set_timezone($timezone_string) |
|
| 248 | - { |
|
| 249 | - if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
| 250 | - // leave the timezone AS-IS if we already have one and |
|
| 251 | - // the function arg didn't provide one |
|
| 252 | - return; |
|
| 253 | - } |
|
| 254 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 255 | - $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
| 256 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * _create_timezone_object_from_timezone_name |
|
| 262 | - * |
|
| 263 | - * @access protected |
|
| 264 | - * @param string $timezone_string |
|
| 265 | - * @return \DateTimeZone |
|
| 266 | - * @throws \EE_Error |
|
| 267 | - */ |
|
| 268 | - protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
| 269 | - { |
|
| 270 | - return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * This just returns whatever is set for the current timezone. |
|
| 276 | - * |
|
| 277 | - * @access public |
|
| 278 | - * @return string timezone string |
|
| 279 | - */ |
|
| 280 | - public function get_timezone() |
|
| 281 | - { |
|
| 282 | - return $this->_timezone_string; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * set the $_date_format property |
|
| 288 | - * |
|
| 289 | - * @access public |
|
| 290 | - * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
| 291 | - * @param bool $pretty Whether to set pretty format or not. |
|
| 292 | - * @return void |
|
| 293 | - */ |
|
| 294 | - public function set_date_format($format, $pretty = false) |
|
| 295 | - { |
|
| 296 | - if ($pretty) { |
|
| 297 | - $this->_pretty_date_format = $format; |
|
| 298 | - } else { |
|
| 299 | - $this->_date_format = $format; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * return the $_date_format property value. |
|
| 306 | - * |
|
| 307 | - * @param bool $pretty Whether to get pretty format or not. |
|
| 308 | - * @return string |
|
| 309 | - */ |
|
| 310 | - public function get_date_format($pretty = false) |
|
| 311 | - { |
|
| 312 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * set the $_time_format property |
|
| 318 | - * |
|
| 319 | - * @access public |
|
| 320 | - * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
| 321 | - * @param bool $pretty Whether to set pretty format or not. |
|
| 322 | - * @return void |
|
| 323 | - */ |
|
| 324 | - public function set_time_format($format, $pretty = false) |
|
| 325 | - { |
|
| 326 | - if ($pretty) { |
|
| 327 | - $this->_pretty_time_format = $format; |
|
| 328 | - } else { |
|
| 329 | - $this->_time_format = $format; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * return the $_time_format property value. |
|
| 336 | - * |
|
| 337 | - * @param bool $pretty Whether to get pretty format or not. |
|
| 338 | - * @return string |
|
| 339 | - */ |
|
| 340 | - public function get_time_format($pretty = false) |
|
| 341 | - { |
|
| 342 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * set the $_pretty_date_format property |
|
| 348 | - * |
|
| 349 | - * @access public |
|
| 350 | - * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
| 351 | - * @return void |
|
| 352 | - */ |
|
| 353 | - public function set_pretty_date_format($format) |
|
| 354 | - { |
|
| 355 | - $this->_pretty_date_format = $format; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * set the $_pretty_time_format property |
|
| 361 | - * |
|
| 362 | - * @access public |
|
| 363 | - * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
| 364 | - * @return void |
|
| 365 | - */ |
|
| 366 | - public function set_pretty_time_format($format) |
|
| 367 | - { |
|
| 368 | - $this->_pretty_time_format = $format; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Only sets the time portion of the datetime. |
|
| 374 | - * |
|
| 375 | - * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
| 376 | - * @param DateTime $current current DateTime object for the datetime field |
|
| 377 | - * @return DateTime |
|
| 378 | - */ |
|
| 379 | - public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
| 380 | - { |
|
| 381 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 382 | - // Otherwise parse the string. |
|
| 383 | - if ($time_to_set_string instanceof DateTime) { |
|
| 384 | - $parsed = array( |
|
| 385 | - 'hour' => $time_to_set_string->format('H'), |
|
| 386 | - 'minute' => $time_to_set_string->format('i'), |
|
| 387 | - 'second' => $time_to_set_string->format('s'), |
|
| 388 | - ); |
|
| 389 | - } else { |
|
| 390 | - //parse incoming string |
|
| 391 | - $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - //make sure $current is in the correct timezone. |
|
| 395 | - $current->setTimezone($this->_DateTimeZone); |
|
| 396 | - |
|
| 397 | - return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Only sets the date portion of the datetime. |
|
| 403 | - * |
|
| 404 | - * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
| 405 | - * @param DateTime $current current DateTime object for the datetime field |
|
| 406 | - * @return DateTime |
|
| 407 | - */ |
|
| 408 | - public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
| 409 | - { |
|
| 410 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 411 | - // Otherwise parse the string. |
|
| 412 | - if ($date_to_set_string instanceof DateTime) { |
|
| 413 | - $parsed = array( |
|
| 414 | - 'year' => $date_to_set_string->format('Y'), |
|
| 415 | - 'month' => $date_to_set_string->format('m'), |
|
| 416 | - 'day' => $date_to_set_string->format('d'), |
|
| 417 | - ); |
|
| 418 | - } else { |
|
| 419 | - //parse incoming string |
|
| 420 | - $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - //make sure $current is in the correct timezone |
|
| 424 | - $current->setTimezone($this->_DateTimeZone); |
|
| 425 | - |
|
| 426 | - return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
| 432 | - * datetime gets to this stage it should ALREADY be in UTC time |
|
| 433 | - * |
|
| 434 | - * @param DateTime $DateTime |
|
| 435 | - * @return string formatted date time for given timezone |
|
| 436 | - * @throws \EE_Error |
|
| 437 | - */ |
|
| 438 | - public function prepare_for_get($DateTime) |
|
| 439 | - { |
|
| 440 | - return $this->_prepare_for_display($DateTime); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
| 446 | - * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
| 447 | - * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
| 448 | - * abbreviation to the date_string. |
|
| 449 | - * |
|
| 450 | - * @param mixed $DateTime |
|
| 451 | - * @param null $schema |
|
| 452 | - * @return string |
|
| 453 | - * @throws \EE_Error |
|
| 454 | - */ |
|
| 455 | - public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
| 456 | - { |
|
| 457 | - return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 463 | - * timezone). |
|
| 464 | - * |
|
| 465 | - * @param DateTime $DateTime |
|
| 466 | - * @param bool|string $schema |
|
| 467 | - * @return string |
|
| 468 | - * @throws \EE_Error |
|
| 469 | - */ |
|
| 470 | - protected function _prepare_for_display($DateTime, $schema = false) |
|
| 471 | - { |
|
| 472 | - if (! $DateTime instanceof DateTime) { |
|
| 473 | - if ($this->_nullable) { |
|
| 474 | - return ''; |
|
| 475 | - } else { |
|
| 476 | - if (WP_DEBUG) { |
|
| 477 | - throw new EE_Error( |
|
| 478 | - sprintf( |
|
| 479 | - __( |
|
| 480 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
| 481 | - 'event_espresso' |
|
| 482 | - ), |
|
| 483 | - $this->_nicename |
|
| 484 | - ) |
|
| 485 | - ); |
|
| 486 | - } else { |
|
| 487 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
| 488 | - EE_Error::add_error( |
|
| 489 | - sprintf( |
|
| 490 | - __( |
|
| 491 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
| 492 | - 'event_espresso' |
|
| 493 | - ), |
|
| 494 | - $this->_nicename |
|
| 495 | - ) |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - $format_string = $this->_get_date_time_output($schema); |
|
| 501 | - //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
| 502 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
| 503 | - if ($schema) { |
|
| 504 | - if ($this->_display_timezone()) { |
|
| 505 | - //must be explicit because schema could equal true. |
|
| 506 | - if ($schema === 'no_html') { |
|
| 507 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 508 | - } else { |
|
| 509 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 510 | - } |
|
| 511 | - } else { |
|
| 512 | - $timezone_string = ''; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - return $DateTime->format($format_string) . $timezone_string; |
|
| 516 | - } else { |
|
| 517 | - return $DateTime->format($format_string); |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 524 | - * timezone). |
|
| 525 | - * |
|
| 526 | - * @param mixed $datetime_value u |
|
| 527 | - * @return string mysql timestamp in UTC |
|
| 528 | - * @throws \EE_Error |
|
| 529 | - */ |
|
| 530 | - public function prepare_for_use_in_db($datetime_value) |
|
| 531 | - { |
|
| 532 | - //we allow an empty value or DateTime object, but nothing else. |
|
| 533 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 534 | - throw new EE_Error( |
|
| 535 | - sprintf( |
|
| 536 | - __( |
|
| 537 | - 'The incoming value being prepared for setting in the database must either be empty or a php |
|
| 18 | + /** |
|
| 19 | + * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
| 20 | + * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
| 21 | + * |
|
| 22 | + * @type string unix_timestamp_regex |
|
| 23 | + */ |
|
| 24 | + const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @type string mysql_timestamp_format |
|
| 28 | + */ |
|
| 29 | + const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @type string mysql_date_format |
|
| 33 | + */ |
|
| 34 | + const mysql_date_format = 'Y-m-d'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @type string mysql_time_format |
|
| 38 | + */ |
|
| 39 | + const mysql_time_format = 'H:i:s'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Const for using in the default value. If the field's default is set to this, |
|
| 43 | + * then we will return the time of calling `get_default_value()`, not |
|
| 44 | + * just the current time at construction |
|
| 45 | + */ |
|
| 46 | + const now = 'now'; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * The following properties hold the default formats for date and time. |
|
| 50 | + * Defaults are set via the constructor and can be overridden on class instantiation. |
|
| 51 | + * However they can also be overridden later by the set_format() method |
|
| 52 | + * (and corresponding set_date_format, set_time_format methods); |
|
| 53 | + */ |
|
| 54 | + /** |
|
| 55 | + * @type string $_date_format |
|
| 56 | + */ |
|
| 57 | + protected $_date_format = ''; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @type string $_time_format |
|
| 61 | + */ |
|
| 62 | + protected $_time_format = ''; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @type string $_pretty_date_format |
|
| 66 | + */ |
|
| 67 | + protected $_pretty_date_format = ''; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @type string $_pretty_time_format |
|
| 71 | + */ |
|
| 72 | + protected $_pretty_time_format = ''; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @type DateTimeZone $_DateTimeZone |
|
| 76 | + */ |
|
| 77 | + protected $_DateTimeZone; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @type DateTimeZone $_UTC_DateTimeZone |
|
| 81 | + */ |
|
| 82 | + protected $_UTC_DateTimeZone; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @type DateTimeZone $_blog_DateTimeZone |
|
| 86 | + */ |
|
| 87 | + protected $_blog_DateTimeZone; |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
| 92 | + * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
| 93 | + * and time returned via getters. |
|
| 94 | + * |
|
| 95 | + * @var mixed (null|string) |
|
| 96 | + */ |
|
| 97 | + protected $_date_time_output; |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * timezone string |
|
| 102 | + * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
| 103 | + * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
| 104 | + * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
| 105 | + * |
|
| 106 | + * @var string |
|
| 107 | + */ |
|
| 108 | + protected $_timezone_string; |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
| 113 | + * offsets for comparison purposes). |
|
| 114 | + * |
|
| 115 | + * @var int |
|
| 116 | + */ |
|
| 117 | + protected $_blog_offset; |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param string $table_column |
|
| 123 | + * @param string $nice_name |
|
| 124 | + * @param bool $nullable |
|
| 125 | + * @param string $default_value |
|
| 126 | + * @param string $timezone_string |
|
| 127 | + * @param string $date_format |
|
| 128 | + * @param string $time_format |
|
| 129 | + * @param string $pretty_date_format |
|
| 130 | + * @param string $pretty_time_format |
|
| 131 | + * @throws EE_Error |
|
| 132 | + * @throws InvalidArgumentException |
|
| 133 | + */ |
|
| 134 | + public function __construct( |
|
| 135 | + $table_column, |
|
| 136 | + $nice_name, |
|
| 137 | + $nullable, |
|
| 138 | + $default_value, |
|
| 139 | + $timezone_string = '', |
|
| 140 | + $date_format = '', |
|
| 141 | + $time_format = '', |
|
| 142 | + $pretty_date_format = '', |
|
| 143 | + $pretty_time_format = '' |
|
| 144 | + ) { |
|
| 145 | + |
|
| 146 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 147 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 148 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
| 149 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
| 150 | + |
|
| 151 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 152 | + $this->set_timezone($timezone_string); |
|
| 153 | + $this->setSchemaFormat('date-time'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @return DateTimeZone |
|
| 159 | + * @throws \EE_Error |
|
| 160 | + */ |
|
| 161 | + public function get_UTC_DateTimeZone() |
|
| 162 | + { |
|
| 163 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
| 164 | + ? $this->_UTC_DateTimeZone |
|
| 165 | + : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @return DateTimeZone |
|
| 171 | + * @throws \EE_Error |
|
| 172 | + */ |
|
| 173 | + public function get_blog_DateTimeZone() |
|
| 174 | + { |
|
| 175 | + return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
| 176 | + ? $this->_blog_DateTimeZone |
|
| 177 | + : $this->_create_timezone_object_from_timezone_string(''); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
| 183 | + * |
|
| 184 | + * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
| 185 | + * timestamp |
|
| 186 | + * @return DateTime |
|
| 187 | + */ |
|
| 188 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 189 | + { |
|
| 190 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
| 196 | + * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
| 197 | + * |
|
| 198 | + * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
| 199 | + * @return string The final assembled format string. |
|
| 200 | + */ |
|
| 201 | + protected function _get_date_time_output($pretty = false) |
|
| 202 | + { |
|
| 203 | + |
|
| 204 | + switch ($this->_date_time_output) { |
|
| 205 | + case 'time' : |
|
| 206 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 207 | + break; |
|
| 208 | + |
|
| 209 | + case 'date' : |
|
| 210 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 211 | + break; |
|
| 212 | + |
|
| 213 | + default : |
|
| 214 | + return $pretty |
|
| 215 | + ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 216 | + : $this->_date_format . ' ' . $this->_time_format; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
| 223 | + * returned (using the format properties) |
|
| 224 | + * |
|
| 225 | + * @param string $what acceptable values are 'time' or 'date'. |
|
| 226 | + * Any other value will be set but will always result |
|
| 227 | + * in both 'date' and 'time' being returned. |
|
| 228 | + * @return void |
|
| 229 | + */ |
|
| 230 | + public function set_date_time_output($what = null) |
|
| 231 | + { |
|
| 232 | + $this->_date_time_output = $what; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 238 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 239 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
| 240 | + * We also set some other properties in this method. |
|
| 241 | + * |
|
| 242 | + * @param string $timezone_string A valid timezone string as described by @link |
|
| 243 | + * http://www.php.net/manual/en/timezones.php |
|
| 244 | + * @return void |
|
| 245 | + * @throws \EE_Error |
|
| 246 | + */ |
|
| 247 | + public function set_timezone($timezone_string) |
|
| 248 | + { |
|
| 249 | + if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
| 250 | + // leave the timezone AS-IS if we already have one and |
|
| 251 | + // the function arg didn't provide one |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 255 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
| 256 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * _create_timezone_object_from_timezone_name |
|
| 262 | + * |
|
| 263 | + * @access protected |
|
| 264 | + * @param string $timezone_string |
|
| 265 | + * @return \DateTimeZone |
|
| 266 | + * @throws \EE_Error |
|
| 267 | + */ |
|
| 268 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
| 269 | + { |
|
| 270 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * This just returns whatever is set for the current timezone. |
|
| 276 | + * |
|
| 277 | + * @access public |
|
| 278 | + * @return string timezone string |
|
| 279 | + */ |
|
| 280 | + public function get_timezone() |
|
| 281 | + { |
|
| 282 | + return $this->_timezone_string; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * set the $_date_format property |
|
| 288 | + * |
|
| 289 | + * @access public |
|
| 290 | + * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
| 291 | + * @param bool $pretty Whether to set pretty format or not. |
|
| 292 | + * @return void |
|
| 293 | + */ |
|
| 294 | + public function set_date_format($format, $pretty = false) |
|
| 295 | + { |
|
| 296 | + if ($pretty) { |
|
| 297 | + $this->_pretty_date_format = $format; |
|
| 298 | + } else { |
|
| 299 | + $this->_date_format = $format; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * return the $_date_format property value. |
|
| 306 | + * |
|
| 307 | + * @param bool $pretty Whether to get pretty format or not. |
|
| 308 | + * @return string |
|
| 309 | + */ |
|
| 310 | + public function get_date_format($pretty = false) |
|
| 311 | + { |
|
| 312 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * set the $_time_format property |
|
| 318 | + * |
|
| 319 | + * @access public |
|
| 320 | + * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
| 321 | + * @param bool $pretty Whether to set pretty format or not. |
|
| 322 | + * @return void |
|
| 323 | + */ |
|
| 324 | + public function set_time_format($format, $pretty = false) |
|
| 325 | + { |
|
| 326 | + if ($pretty) { |
|
| 327 | + $this->_pretty_time_format = $format; |
|
| 328 | + } else { |
|
| 329 | + $this->_time_format = $format; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * return the $_time_format property value. |
|
| 336 | + * |
|
| 337 | + * @param bool $pretty Whether to get pretty format or not. |
|
| 338 | + * @return string |
|
| 339 | + */ |
|
| 340 | + public function get_time_format($pretty = false) |
|
| 341 | + { |
|
| 342 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * set the $_pretty_date_format property |
|
| 348 | + * |
|
| 349 | + * @access public |
|
| 350 | + * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
| 351 | + * @return void |
|
| 352 | + */ |
|
| 353 | + public function set_pretty_date_format($format) |
|
| 354 | + { |
|
| 355 | + $this->_pretty_date_format = $format; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * set the $_pretty_time_format property |
|
| 361 | + * |
|
| 362 | + * @access public |
|
| 363 | + * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
| 364 | + * @return void |
|
| 365 | + */ |
|
| 366 | + public function set_pretty_time_format($format) |
|
| 367 | + { |
|
| 368 | + $this->_pretty_time_format = $format; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Only sets the time portion of the datetime. |
|
| 374 | + * |
|
| 375 | + * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
| 376 | + * @param DateTime $current current DateTime object for the datetime field |
|
| 377 | + * @return DateTime |
|
| 378 | + */ |
|
| 379 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
| 380 | + { |
|
| 381 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 382 | + // Otherwise parse the string. |
|
| 383 | + if ($time_to_set_string instanceof DateTime) { |
|
| 384 | + $parsed = array( |
|
| 385 | + 'hour' => $time_to_set_string->format('H'), |
|
| 386 | + 'minute' => $time_to_set_string->format('i'), |
|
| 387 | + 'second' => $time_to_set_string->format('s'), |
|
| 388 | + ); |
|
| 389 | + } else { |
|
| 390 | + //parse incoming string |
|
| 391 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + //make sure $current is in the correct timezone. |
|
| 395 | + $current->setTimezone($this->_DateTimeZone); |
|
| 396 | + |
|
| 397 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Only sets the date portion of the datetime. |
|
| 403 | + * |
|
| 404 | + * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
| 405 | + * @param DateTime $current current DateTime object for the datetime field |
|
| 406 | + * @return DateTime |
|
| 407 | + */ |
|
| 408 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
| 409 | + { |
|
| 410 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 411 | + // Otherwise parse the string. |
|
| 412 | + if ($date_to_set_string instanceof DateTime) { |
|
| 413 | + $parsed = array( |
|
| 414 | + 'year' => $date_to_set_string->format('Y'), |
|
| 415 | + 'month' => $date_to_set_string->format('m'), |
|
| 416 | + 'day' => $date_to_set_string->format('d'), |
|
| 417 | + ); |
|
| 418 | + } else { |
|
| 419 | + //parse incoming string |
|
| 420 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + //make sure $current is in the correct timezone |
|
| 424 | + $current->setTimezone($this->_DateTimeZone); |
|
| 425 | + |
|
| 426 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
| 432 | + * datetime gets to this stage it should ALREADY be in UTC time |
|
| 433 | + * |
|
| 434 | + * @param DateTime $DateTime |
|
| 435 | + * @return string formatted date time for given timezone |
|
| 436 | + * @throws \EE_Error |
|
| 437 | + */ |
|
| 438 | + public function prepare_for_get($DateTime) |
|
| 439 | + { |
|
| 440 | + return $this->_prepare_for_display($DateTime); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
| 446 | + * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
| 447 | + * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
| 448 | + * abbreviation to the date_string. |
|
| 449 | + * |
|
| 450 | + * @param mixed $DateTime |
|
| 451 | + * @param null $schema |
|
| 452 | + * @return string |
|
| 453 | + * @throws \EE_Error |
|
| 454 | + */ |
|
| 455 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
| 456 | + { |
|
| 457 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 463 | + * timezone). |
|
| 464 | + * |
|
| 465 | + * @param DateTime $DateTime |
|
| 466 | + * @param bool|string $schema |
|
| 467 | + * @return string |
|
| 468 | + * @throws \EE_Error |
|
| 469 | + */ |
|
| 470 | + protected function _prepare_for_display($DateTime, $schema = false) |
|
| 471 | + { |
|
| 472 | + if (! $DateTime instanceof DateTime) { |
|
| 473 | + if ($this->_nullable) { |
|
| 474 | + return ''; |
|
| 475 | + } else { |
|
| 476 | + if (WP_DEBUG) { |
|
| 477 | + throw new EE_Error( |
|
| 478 | + sprintf( |
|
| 479 | + __( |
|
| 480 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
| 481 | + 'event_espresso' |
|
| 482 | + ), |
|
| 483 | + $this->_nicename |
|
| 484 | + ) |
|
| 485 | + ); |
|
| 486 | + } else { |
|
| 487 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
| 488 | + EE_Error::add_error( |
|
| 489 | + sprintf( |
|
| 490 | + __( |
|
| 491 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
| 492 | + 'event_espresso' |
|
| 493 | + ), |
|
| 494 | + $this->_nicename |
|
| 495 | + ) |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + $format_string = $this->_get_date_time_output($schema); |
|
| 501 | + //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
| 502 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
| 503 | + if ($schema) { |
|
| 504 | + if ($this->_display_timezone()) { |
|
| 505 | + //must be explicit because schema could equal true. |
|
| 506 | + if ($schema === 'no_html') { |
|
| 507 | + $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 508 | + } else { |
|
| 509 | + $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 510 | + } |
|
| 511 | + } else { |
|
| 512 | + $timezone_string = ''; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + return $DateTime->format($format_string) . $timezone_string; |
|
| 516 | + } else { |
|
| 517 | + return $DateTime->format($format_string); |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 524 | + * timezone). |
|
| 525 | + * |
|
| 526 | + * @param mixed $datetime_value u |
|
| 527 | + * @return string mysql timestamp in UTC |
|
| 528 | + * @throws \EE_Error |
|
| 529 | + */ |
|
| 530 | + public function prepare_for_use_in_db($datetime_value) |
|
| 531 | + { |
|
| 532 | + //we allow an empty value or DateTime object, but nothing else. |
|
| 533 | + if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 534 | + throw new EE_Error( |
|
| 535 | + sprintf( |
|
| 536 | + __( |
|
| 537 | + 'The incoming value being prepared for setting in the database must either be empty or a php |
|
| 538 | 538 | DateTime object, instead of: %1$s %2$s', |
| 539 | - 'event_espresso' |
|
| 540 | - ), |
|
| 541 | - '<br />', |
|
| 542 | - print_r($datetime_value, true) |
|
| 543 | - ) |
|
| 544 | - ); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - if ($datetime_value instanceof DateTime) { |
|
| 548 | - if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
| 549 | - $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
| 553 | - EE_Datetime_Field::mysql_timestamp_format |
|
| 554 | - ); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
| 558 | - return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
| 564 | - * allowed) |
|
| 565 | - * |
|
| 566 | - * @param string $datetime_string mysql timestamp in UTC |
|
| 567 | - * @return mixed null | DateTime |
|
| 568 | - * @throws \EE_Error |
|
| 569 | - */ |
|
| 570 | - public function prepare_for_set_from_db($datetime_string) |
|
| 571 | - { |
|
| 572 | - //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
| 573 | - if (empty($datetime_string) && $this->_nullable) { |
|
| 574 | - return null; |
|
| 575 | - } |
|
| 576 | - // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
| 577 | - if (empty($datetime_string)) { |
|
| 578 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 579 | - } else { |
|
| 580 | - $DateTime = DateTime::createFromFormat( |
|
| 581 | - EE_Datetime_Field::mysql_timestamp_format, |
|
| 582 | - $datetime_string, |
|
| 583 | - $this->get_UTC_DateTimeZone() |
|
| 584 | - ); |
|
| 585 | - if ($DateTime instanceof \DateTime) { |
|
| 586 | - $DateTime = new DbSafeDateTime( |
|
| 587 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 588 | - $this->get_UTC_DateTimeZone() |
|
| 589 | - ); |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
| 594 | - // if still no datetime object, then let's just use now |
|
| 595 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 596 | - } |
|
| 597 | - // THEN apply the field's set DateTimeZone |
|
| 598 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
| 599 | - |
|
| 600 | - return $DateTime; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * All this method does is determine if we're going to display the timezone string or not on any output. |
|
| 606 | - * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
| 607 | - * If so, then true. |
|
| 608 | - * |
|
| 609 | - * @return bool true for yes false for no |
|
| 610 | - * @throws \EE_Error |
|
| 611 | - */ |
|
| 612 | - protected function _display_timezone() |
|
| 613 | - { |
|
| 614 | - |
|
| 615 | - // first let's do a comparison of timezone strings. |
|
| 616 | - // If they match then we can get out without any further calculations |
|
| 617 | - $blog_string = get_option('timezone_string'); |
|
| 618 | - if ($blog_string === $this->_timezone_string) { |
|
| 619 | - return false; |
|
| 620 | - } |
|
| 621 | - // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
| 622 | - $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
| 623 | - $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
| 624 | - // now compare |
|
| 625 | - return $blog_offset !== $this_offset; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
| 631 | - * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
| 632 | - * with. |
|
| 633 | - * |
|
| 634 | - * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
| 635 | - * in the format that is set on the date_field (or DateTime |
|
| 636 | - * object)! |
|
| 637 | - * @return DateTime |
|
| 638 | - */ |
|
| 639 | - protected function _get_date_object($date_string) |
|
| 640 | - { |
|
| 641 | - //first if this is an empty date_string and nullable is allowed, just return null. |
|
| 642 | - if ($this->_nullable && empty($date_string)) { |
|
| 643 | - return null; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - // if incoming date |
|
| 647 | - if ($date_string instanceof DateTime) { |
|
| 648 | - $date_string->setTimezone($this->_DateTimeZone); |
|
| 649 | - |
|
| 650 | - return $date_string; |
|
| 651 | - } |
|
| 652 | - // if empty date_string and made it here. |
|
| 653 | - // Return a datetime object for now in the given timezone. |
|
| 654 | - if (empty($date_string)) { |
|
| 655 | - return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 656 | - } |
|
| 657 | - // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
| 658 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
| 659 | - try { |
|
| 660 | - // This is operating under the assumption that the incoming Unix timestamp |
|
| 661 | - // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
| 662 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 663 | - $DateTime->setTimestamp($date_string); |
|
| 664 | - |
|
| 665 | - return $DateTime; |
|
| 666 | - } catch (Exception $e) { |
|
| 667 | - // should be rare, but if things got fooled then let's just continue |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
| 671 | - //create the DateTime object. |
|
| 672 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 673 | - try { |
|
| 674 | - $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
| 675 | - if ($DateTime instanceof DateTime) { |
|
| 676 | - $DateTime = new DbSafeDateTime( |
|
| 677 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 678 | - $this->_DateTimeZone |
|
| 679 | - ); |
|
| 680 | - } |
|
| 681 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
| 682 | - throw new EE_Error( |
|
| 683 | - sprintf( |
|
| 684 | - __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
| 685 | - $date_string, |
|
| 686 | - $format |
|
| 687 | - ) |
|
| 688 | - ); |
|
| 689 | - } |
|
| 690 | - } catch (Exception $e) { |
|
| 691 | - // if we made it here then likely then something went really wrong. |
|
| 692 | - // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
| 693 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - return $DateTime; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * get_timezone_transitions |
|
| 703 | - * |
|
| 704 | - * @param \DateTimeZone $DateTimeZone |
|
| 705 | - * @param int $time |
|
| 706 | - * @param bool $first_only |
|
| 707 | - * @return mixed |
|
| 708 | - */ |
|
| 709 | - public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
| 710 | - { |
|
| 711 | - return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only); |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * get_timezone_offset |
|
| 718 | - * |
|
| 719 | - * @param \DateTimeZone $DateTimeZone |
|
| 720 | - * @param int $time |
|
| 721 | - * @return mixed |
|
| 722 | - * @throws \DomainException |
|
| 723 | - */ |
|
| 724 | - public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
| 725 | - { |
|
| 726 | - return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * This will take an incoming timezone string and return the abbreviation for that timezone |
|
| 732 | - * |
|
| 733 | - * @param string $timezone_string |
|
| 734 | - * @return string abbreviation |
|
| 735 | - * @throws \EE_Error |
|
| 736 | - */ |
|
| 737 | - public function get_timezone_abbrev($timezone_string) |
|
| 738 | - { |
|
| 739 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 740 | - $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
| 741 | - |
|
| 742 | - return $dateTime->format('T'); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - /** |
|
| 746 | - * Overrides the parent to allow for having a dynamic "now" value |
|
| 747 | - * |
|
| 748 | - * @return mixed |
|
| 749 | - */ |
|
| 750 | - public function get_default_value() |
|
| 751 | - { |
|
| 752 | - if ($this->_default_value === EE_Datetime_Field::now) { |
|
| 753 | - return time(); |
|
| 754 | - } else { |
|
| 755 | - return parent::get_default_value(); |
|
| 756 | - } |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - |
|
| 760 | - public function getSchemaDescription() |
|
| 761 | - { |
|
| 762 | - return sprintf( |
|
| 763 | - esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
| 764 | - $this->get_nicename() |
|
| 765 | - ); |
|
| 766 | - } |
|
| 539 | + 'event_espresso' |
|
| 540 | + ), |
|
| 541 | + '<br />', |
|
| 542 | + print_r($datetime_value, true) |
|
| 543 | + ) |
|
| 544 | + ); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + if ($datetime_value instanceof DateTime) { |
|
| 548 | + if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
| 549 | + $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
| 553 | + EE_Datetime_Field::mysql_timestamp_format |
|
| 554 | + ); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
| 558 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
| 564 | + * allowed) |
|
| 565 | + * |
|
| 566 | + * @param string $datetime_string mysql timestamp in UTC |
|
| 567 | + * @return mixed null | DateTime |
|
| 568 | + * @throws \EE_Error |
|
| 569 | + */ |
|
| 570 | + public function prepare_for_set_from_db($datetime_string) |
|
| 571 | + { |
|
| 572 | + //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
| 573 | + if (empty($datetime_string) && $this->_nullable) { |
|
| 574 | + return null; |
|
| 575 | + } |
|
| 576 | + // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
| 577 | + if (empty($datetime_string)) { |
|
| 578 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 579 | + } else { |
|
| 580 | + $DateTime = DateTime::createFromFormat( |
|
| 581 | + EE_Datetime_Field::mysql_timestamp_format, |
|
| 582 | + $datetime_string, |
|
| 583 | + $this->get_UTC_DateTimeZone() |
|
| 584 | + ); |
|
| 585 | + if ($DateTime instanceof \DateTime) { |
|
| 586 | + $DateTime = new DbSafeDateTime( |
|
| 587 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 588 | + $this->get_UTC_DateTimeZone() |
|
| 589 | + ); |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
| 594 | + // if still no datetime object, then let's just use now |
|
| 595 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 596 | + } |
|
| 597 | + // THEN apply the field's set DateTimeZone |
|
| 598 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
| 599 | + |
|
| 600 | + return $DateTime; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * All this method does is determine if we're going to display the timezone string or not on any output. |
|
| 606 | + * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
| 607 | + * If so, then true. |
|
| 608 | + * |
|
| 609 | + * @return bool true for yes false for no |
|
| 610 | + * @throws \EE_Error |
|
| 611 | + */ |
|
| 612 | + protected function _display_timezone() |
|
| 613 | + { |
|
| 614 | + |
|
| 615 | + // first let's do a comparison of timezone strings. |
|
| 616 | + // If they match then we can get out without any further calculations |
|
| 617 | + $blog_string = get_option('timezone_string'); |
|
| 618 | + if ($blog_string === $this->_timezone_string) { |
|
| 619 | + return false; |
|
| 620 | + } |
|
| 621 | + // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
| 622 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
| 623 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
| 624 | + // now compare |
|
| 625 | + return $blog_offset !== $this_offset; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
| 631 | + * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
| 632 | + * with. |
|
| 633 | + * |
|
| 634 | + * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
| 635 | + * in the format that is set on the date_field (or DateTime |
|
| 636 | + * object)! |
|
| 637 | + * @return DateTime |
|
| 638 | + */ |
|
| 639 | + protected function _get_date_object($date_string) |
|
| 640 | + { |
|
| 641 | + //first if this is an empty date_string and nullable is allowed, just return null. |
|
| 642 | + if ($this->_nullable && empty($date_string)) { |
|
| 643 | + return null; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + // if incoming date |
|
| 647 | + if ($date_string instanceof DateTime) { |
|
| 648 | + $date_string->setTimezone($this->_DateTimeZone); |
|
| 649 | + |
|
| 650 | + return $date_string; |
|
| 651 | + } |
|
| 652 | + // if empty date_string and made it here. |
|
| 653 | + // Return a datetime object for now in the given timezone. |
|
| 654 | + if (empty($date_string)) { |
|
| 655 | + return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 656 | + } |
|
| 657 | + // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
| 658 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
| 659 | + try { |
|
| 660 | + // This is operating under the assumption that the incoming Unix timestamp |
|
| 661 | + // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
| 662 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 663 | + $DateTime->setTimestamp($date_string); |
|
| 664 | + |
|
| 665 | + return $DateTime; |
|
| 666 | + } catch (Exception $e) { |
|
| 667 | + // should be rare, but if things got fooled then let's just continue |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
| 671 | + //create the DateTime object. |
|
| 672 | + $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 673 | + try { |
|
| 674 | + $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
| 675 | + if ($DateTime instanceof DateTime) { |
|
| 676 | + $DateTime = new DbSafeDateTime( |
|
| 677 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 678 | + $this->_DateTimeZone |
|
| 679 | + ); |
|
| 680 | + } |
|
| 681 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
| 682 | + throw new EE_Error( |
|
| 683 | + sprintf( |
|
| 684 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
| 685 | + $date_string, |
|
| 686 | + $format |
|
| 687 | + ) |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | + } catch (Exception $e) { |
|
| 691 | + // if we made it here then likely then something went really wrong. |
|
| 692 | + // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
| 693 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + return $DateTime; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * get_timezone_transitions |
|
| 703 | + * |
|
| 704 | + * @param \DateTimeZone $DateTimeZone |
|
| 705 | + * @param int $time |
|
| 706 | + * @param bool $first_only |
|
| 707 | + * @return mixed |
|
| 708 | + */ |
|
| 709 | + public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
| 710 | + { |
|
| 711 | + return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only); |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * get_timezone_offset |
|
| 718 | + * |
|
| 719 | + * @param \DateTimeZone $DateTimeZone |
|
| 720 | + * @param int $time |
|
| 721 | + * @return mixed |
|
| 722 | + * @throws \DomainException |
|
| 723 | + */ |
|
| 724 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
| 725 | + { |
|
| 726 | + return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * This will take an incoming timezone string and return the abbreviation for that timezone |
|
| 732 | + * |
|
| 733 | + * @param string $timezone_string |
|
| 734 | + * @return string abbreviation |
|
| 735 | + * @throws \EE_Error |
|
| 736 | + */ |
|
| 737 | + public function get_timezone_abbrev($timezone_string) |
|
| 738 | + { |
|
| 739 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 740 | + $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
| 741 | + |
|
| 742 | + return $dateTime->format('T'); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + /** |
|
| 746 | + * Overrides the parent to allow for having a dynamic "now" value |
|
| 747 | + * |
|
| 748 | + * @return mixed |
|
| 749 | + */ |
|
| 750 | + public function get_default_value() |
|
| 751 | + { |
|
| 752 | + if ($this->_default_value === EE_Datetime_Field::now) { |
|
| 753 | + return time(); |
|
| 754 | + } else { |
|
| 755 | + return parent::get_default_value(); |
|
| 756 | + } |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + |
|
| 760 | + public function getSchemaDescription() |
|
| 761 | + { |
|
| 762 | + return sprintf( |
|
| 763 | + esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
| 764 | + $this->get_nicename() |
|
| 765 | + ); |
|
| 766 | + } |
|
| 767 | 767 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | public function processShortcode($attributes = array()) |
| 113 | 113 | { |
| 114 | 114 | // grab attributes and merge with defaults |
| 115 | - $attributes = $this->getAttributes((array)$attributes); |
|
| 115 | + $attributes = $this->getAttributes((array) $attributes); |
|
| 116 | 116 | $archive = is_archive(); |
| 117 | 117 | $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
| 118 | 118 | // don't display on archives unless 'display_on_archives' is true |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | private function validateEntities(array $attributes) |
| 202 | 202 | { |
| 203 | - if (! $this->template_args['event'] instanceof EE_Event |
|
| 203 | + if ( ! $this->template_args['event'] instanceof EE_Event |
|
| 204 | 204 | || ( |
| 205 | 205 | empty($attributes['event_id']) |
| 206 | 206 | && $attributes['datetime_id'] |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | private function getDatetime(array $attributes) |
| 317 | 317 | { |
| 318 | - if (! empty($attributes['datetime_id'])) { |
|
| 318 | + if ( ! empty($attributes['datetime_id'])) { |
|
| 319 | 319 | $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
| 320 | 320 | if ($datetime instanceof EE_Datetime) { |
| 321 | 321 | return $datetime; |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | private function getTicket(array $attributes) |
| 337 | 337 | { |
| 338 | - if (! empty($attributes['ticket_id'])) { |
|
| 338 | + if ( ! empty($attributes['ticket_id'])) { |
|
| 339 | 339 | $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
| 340 | 340 | if ($ticket instanceof EE_Ticket) { |
| 341 | 341 | return $ticket; |
@@ -30,339 +30,339 @@ |
||
| 30 | 30 | class EspressoEventAttendees extends EspressoShortcode |
| 31 | 31 | { |
| 32 | 32 | |
| 33 | - private $query_params = array( |
|
| 34 | - 0 => array() |
|
| 35 | - ); |
|
| 36 | - |
|
| 37 | - private $template_args = array( |
|
| 38 | - 'contacts' => array(), |
|
| 39 | - 'event' => null, |
|
| 40 | - 'datetime' => null, |
|
| 41 | - 'ticket' => null, |
|
| 42 | - ); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * the actual shortcode tag that gets registered with WordPress |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public function getTag() |
|
| 50 | - { |
|
| 51 | - return 'ESPRESSO_EVENT_ATTENDEES'; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * the time in seconds to cache the results of the processShortcode() method |
|
| 58 | - * 0 means the processShortcode() results will NOT be cached at all |
|
| 59 | - * |
|
| 60 | - * @return int |
|
| 61 | - */ |
|
| 62 | - public function cacheExpiration() |
|
| 63 | - { |
|
| 64 | - return 0; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
| 71 | - * this may be required for shortcodes that utilize a corresponding module, |
|
| 72 | - * and need to enqueue assets for that module |
|
| 73 | - * |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 76 | - public function initializeShortcode() |
|
| 77 | - { |
|
| 78 | - $this->shortcodeHasBeenInitialized(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event. |
|
| 84 | - * [ESPRESSO_EVENT_ATTENDEES] |
|
| 85 | - * - defaults to attendees for earliest active event, or earliest upcoming event. |
|
| 86 | - * [ESPRESSO_EVENT_ATTENDEES event_id=123] |
|
| 87 | - * - attendees for specific event. |
|
| 88 | - * [ESPRESSO_EVENT_ATTENDEES datetime_id=245] |
|
| 89 | - * - attendees for a specific datetime. |
|
| 90 | - * [ESPRESSO_EVENT_ATTENDEES ticket_id=123] |
|
| 91 | - * - attendees for a specific ticket. |
|
| 92 | - * [ESPRESSO_EVENT_ATTENDEES status=all] |
|
| 93 | - * - specific registration status (use status id) or all for all attendees regardless of status. |
|
| 94 | - * Note default is to only return approved attendees |
|
| 95 | - * [ESPRESSO_EVENT_ATTENDEES show_gravatar=true] |
|
| 96 | - * - default is to not return gravatar. Otherwise if this is set then return gravatar for email address given. |
|
| 97 | - * [ESPRESSO_EVENT_ATTENDEES display_on_archives=true] |
|
| 98 | - * - default is to not display attendees list on archive pages. |
|
| 99 | - * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
| 100 | - * If more than one of those params is included, then preference is given to the following: |
|
| 101 | - * - event_id is used whenever its present and any others are ignored. |
|
| 102 | - * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
| 103 | - * - otherwise ticket_id is used if present. |
|
| 104 | - * |
|
| 105 | - * @param array $attributes |
|
| 106 | - * @return string |
|
| 107 | - * @throws EE_Error |
|
| 108 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 109 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 110 | - * @throws \InvalidArgumentException |
|
| 111 | - */ |
|
| 112 | - public function processShortcode($attributes = array()) |
|
| 113 | - { |
|
| 114 | - // grab attributes and merge with defaults |
|
| 115 | - $attributes = $this->getAttributes((array)$attributes); |
|
| 116 | - $archive = is_archive(); |
|
| 117 | - $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
|
| 118 | - // don't display on archives unless 'display_on_archives' is true |
|
| 119 | - if ($archive && ! $display_on_archives) { |
|
| 120 | - return ''; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - try { |
|
| 124 | - $this->setBaseTemplateArguments($attributes); |
|
| 125 | - $this->validateEntities($attributes); |
|
| 126 | - $this->setBaseQueryParams(); |
|
| 127 | - } catch (EntityNotFoundException $e) { |
|
| 128 | - if (WP_DEBUG) { |
|
| 129 | - return '<div class="important-notice ee-error">' |
|
| 130 | - . $e->getMessage() |
|
| 131 | - . '</div>'; |
|
| 132 | - } |
|
| 133 | - return ''; |
|
| 134 | - } |
|
| 135 | - $this->setAdditionalQueryParams($attributes); |
|
| 136 | - //get contacts! |
|
| 137 | - $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params); |
|
| 138 | - //all set let's load up the template and return. |
|
| 139 | - return EEH_Template::locate_template( |
|
| 140 | - 'loop-espresso_event_attendees.php', |
|
| 141 | - $this->template_args |
|
| 142 | - ); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * merge incoming attributes with filtered defaults |
|
| 149 | - * |
|
| 150 | - * @param array $attributes |
|
| 151 | - * @return array |
|
| 152 | - */ |
|
| 153 | - private function getAttributes(array $attributes) |
|
| 154 | - { |
|
| 155 | - return (array) apply_filters( |
|
| 156 | - 'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', |
|
| 157 | - $attributes + array( |
|
| 158 | - 'event_id' => null, |
|
| 159 | - 'datetime_id' => null, |
|
| 160 | - 'ticket_id' => null, |
|
| 161 | - 'status' => EEM_Registration::status_id_approved, |
|
| 162 | - 'show_gravatar' => false, |
|
| 163 | - 'display_on_archives' => false, |
|
| 164 | - ) |
|
| 165 | - ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Set all the base template arguments from the incoming attributes. |
|
| 171 | - * |
|
| 172 | - * * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
| 173 | - * If more than one of those params is included, then preference is given to the following: |
|
| 174 | - * - event_id is used whenever its present and any others are ignored. |
|
| 175 | - * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
| 176 | - * - otherwise ticket_id is used if present. |
|
| 177 | - * |
|
| 178 | - * @param array $attributes |
|
| 179 | - * @throws EE_Error |
|
| 180 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 181 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 182 | - * @throws \InvalidArgumentException |
|
| 183 | - */ |
|
| 184 | - private function setBaseTemplateArguments(array $attributes) |
|
| 185 | - { |
|
| 186 | - $this->template_args['show_gravatar'] = $attributes['show_gravatar']; |
|
| 187 | - $this->template_args['event'] = $this->getEvent($attributes); |
|
| 188 | - $this->template_args['datetime'] = empty($attributes['event_id']) |
|
| 189 | - ? $this->getDatetime($attributes) |
|
| 190 | - : null; |
|
| 191 | - $this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id']) |
|
| 192 | - ? $this->getTicket($attributes) |
|
| 193 | - : null; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Validates the presence of entities for the given attribute values. |
|
| 199 | - * @param array $attributes |
|
| 200 | - * @throws EntityNotFoundException |
|
| 201 | - */ |
|
| 202 | - private function validateEntities(array $attributes) |
|
| 203 | - { |
|
| 204 | - if (! $this->template_args['event'] instanceof EE_Event |
|
| 205 | - || ( |
|
| 206 | - empty($attributes['event_id']) |
|
| 207 | - && $attributes['datetime_id'] |
|
| 208 | - && ! $this->template_args['datetime'] instanceof EE_Datetime |
|
| 209 | - ) |
|
| 210 | - || ( |
|
| 211 | - empty($attributes['event_id']) |
|
| 212 | - && empty($attributes['datetime_id']) |
|
| 213 | - && $attributes['ticket_id'] |
|
| 214 | - && ! $this->template_args['ticket'] instanceof EE_Ticket |
|
| 215 | - ) |
|
| 216 | - ) { |
|
| 217 | - throw new EntityNotFoundException( |
|
| 218 | - '', |
|
| 219 | - '', |
|
| 220 | - esc_html__( |
|
| 221 | - 'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly. Please double check the arguments you used for any typos. In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', |
|
| 222 | - 'event_espresso' |
|
| 223 | - ) |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Sets the query params for the base query elements. |
|
| 231 | - */ |
|
| 232 | - private function setBaseQueryParams() |
|
| 233 | - { |
|
| 234 | - switch (true) { |
|
| 235 | - case $this->template_args['datetime'] instanceof EE_Datetime: |
|
| 236 | - $this->query_params = array( |
|
| 237 | - 0 => array( |
|
| 238 | - 'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID() |
|
| 239 | - ), |
|
| 240 | - 'default_where_conditions' => 'this_model_only' |
|
| 241 | - ); |
|
| 242 | - break; |
|
| 243 | - case $this->template_args['ticket'] instanceof EE_Ticket: |
|
| 244 | - $this->query_params[0] = array( |
|
| 245 | - 'Registration.TKT_ID' => $this->template_args['ticket']->ID() |
|
| 246 | - ); |
|
| 247 | - break; |
|
| 248 | - case $this->template_args['event'] instanceof EE_Event: |
|
| 249 | - $this->query_params[0] = array( |
|
| 250 | - 'Registration.EVT_ID' => $this->template_args['event']->ID() |
|
| 251 | - ); |
|
| 252 | - break; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @param array $attributes |
|
| 259 | - * @return EE_Event|null |
|
| 260 | - * @throws EE_Error |
|
| 261 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 262 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 263 | - * @throws \InvalidArgumentException |
|
| 264 | - */ |
|
| 265 | - private function getEvent(array $attributes) |
|
| 266 | - { |
|
| 267 | - switch (true) { |
|
| 268 | - case ! empty($attributes['event_id']): |
|
| 269 | - $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); |
|
| 270 | - break; |
|
| 271 | - case ! empty($attributes['datetime_id']): |
|
| 272 | - $event = EEM_Event::instance()->get_one(array( |
|
| 273 | - array( |
|
| 274 | - 'Datetime.DTT_ID' => $attributes['datetime_id'] |
|
| 275 | - ) |
|
| 276 | - )); |
|
| 277 | - break; |
|
| 278 | - case ! empty($attributes['ticket_id']): |
|
| 279 | - $event = EEM_Event::instance()->get_one(array( |
|
| 280 | - array( |
|
| 281 | - 'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'] |
|
| 282 | - ) |
|
| 283 | - )); |
|
| 284 | - break; |
|
| 285 | - case is_espresso_event(): |
|
| 286 | - $event = EEH_Event_View::get_event(); |
|
| 287 | - break; |
|
| 288 | - default: |
|
| 289 | - // one last shot... |
|
| 290 | - // try getting the earliest active event |
|
| 291 | - $events = EEM_Event::instance()->get_active_events(array( |
|
| 292 | - 'limit' => 1, |
|
| 293 | - 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
| 294 | - )); |
|
| 295 | - // if none then get the next upcoming |
|
| 296 | - $events = empty($events) |
|
| 297 | - ? EEM_Event::instance()->get_upcoming_events(array( |
|
| 298 | - 'limit' => 1, |
|
| 299 | - 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
| 300 | - )) |
|
| 301 | - : $events; |
|
| 302 | - $event = reset($events); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - return $event instanceof EE_Event ? $event : null; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * @param array $attributes |
|
| 311 | - * @return EE_Datetime|null |
|
| 312 | - * @throws EE_Error |
|
| 313 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 314 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 315 | - * @throws \InvalidArgumentException |
|
| 316 | - */ |
|
| 317 | - private function getDatetime(array $attributes) |
|
| 318 | - { |
|
| 319 | - if (! empty($attributes['datetime_id'])) { |
|
| 320 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
|
| 321 | - if ($datetime instanceof EE_Datetime) { |
|
| 322 | - return $datetime; |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - return null; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * @param array $attributes |
|
| 331 | - * @return \EE_Base_Class|EE_Ticket|null |
|
| 332 | - * @throws EE_Error |
|
| 333 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 334 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 335 | - * @throws \InvalidArgumentException |
|
| 336 | - */ |
|
| 337 | - private function getTicket(array $attributes) |
|
| 338 | - { |
|
| 339 | - if (! empty($attributes['ticket_id'])) { |
|
| 340 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
|
| 341 | - if ($ticket instanceof EE_Ticket) { |
|
| 342 | - return $ticket; |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - return null; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @param array $attributes |
|
| 352 | - * @throws EE_Error |
|
| 353 | - */ |
|
| 354 | - private function setAdditionalQueryParams(array $attributes) |
|
| 355 | - { |
|
| 356 | - $reg_status_array = EEM_Registration::reg_status_array(); |
|
| 357 | - if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) { |
|
| 358 | - $this->query_params[0]['Registration.STS_ID'] = $attributes['status']; |
|
| 359 | - } |
|
| 360 | - $this->query_params['group_by'] = array('ATT_ID'); |
|
| 361 | - $this->query_params['order_by'] = (array) apply_filters( |
|
| 362 | - 'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', |
|
| 363 | - array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC') |
|
| 364 | - ); |
|
| 365 | - } |
|
| 33 | + private $query_params = array( |
|
| 34 | + 0 => array() |
|
| 35 | + ); |
|
| 36 | + |
|
| 37 | + private $template_args = array( |
|
| 38 | + 'contacts' => array(), |
|
| 39 | + 'event' => null, |
|
| 40 | + 'datetime' => null, |
|
| 41 | + 'ticket' => null, |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * the actual shortcode tag that gets registered with WordPress |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public function getTag() |
|
| 50 | + { |
|
| 51 | + return 'ESPRESSO_EVENT_ATTENDEES'; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * the time in seconds to cache the results of the processShortcode() method |
|
| 58 | + * 0 means the processShortcode() results will NOT be cached at all |
|
| 59 | + * |
|
| 60 | + * @return int |
|
| 61 | + */ |
|
| 62 | + public function cacheExpiration() |
|
| 63 | + { |
|
| 64 | + return 0; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
| 71 | + * this may be required for shortcodes that utilize a corresponding module, |
|
| 72 | + * and need to enqueue assets for that module |
|
| 73 | + * |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | + public function initializeShortcode() |
|
| 77 | + { |
|
| 78 | + $this->shortcodeHasBeenInitialized(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event. |
|
| 84 | + * [ESPRESSO_EVENT_ATTENDEES] |
|
| 85 | + * - defaults to attendees for earliest active event, or earliest upcoming event. |
|
| 86 | + * [ESPRESSO_EVENT_ATTENDEES event_id=123] |
|
| 87 | + * - attendees for specific event. |
|
| 88 | + * [ESPRESSO_EVENT_ATTENDEES datetime_id=245] |
|
| 89 | + * - attendees for a specific datetime. |
|
| 90 | + * [ESPRESSO_EVENT_ATTENDEES ticket_id=123] |
|
| 91 | + * - attendees for a specific ticket. |
|
| 92 | + * [ESPRESSO_EVENT_ATTENDEES status=all] |
|
| 93 | + * - specific registration status (use status id) or all for all attendees regardless of status. |
|
| 94 | + * Note default is to only return approved attendees |
|
| 95 | + * [ESPRESSO_EVENT_ATTENDEES show_gravatar=true] |
|
| 96 | + * - default is to not return gravatar. Otherwise if this is set then return gravatar for email address given. |
|
| 97 | + * [ESPRESSO_EVENT_ATTENDEES display_on_archives=true] |
|
| 98 | + * - default is to not display attendees list on archive pages. |
|
| 99 | + * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
| 100 | + * If more than one of those params is included, then preference is given to the following: |
|
| 101 | + * - event_id is used whenever its present and any others are ignored. |
|
| 102 | + * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
| 103 | + * - otherwise ticket_id is used if present. |
|
| 104 | + * |
|
| 105 | + * @param array $attributes |
|
| 106 | + * @return string |
|
| 107 | + * @throws EE_Error |
|
| 108 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 109 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 110 | + * @throws \InvalidArgumentException |
|
| 111 | + */ |
|
| 112 | + public function processShortcode($attributes = array()) |
|
| 113 | + { |
|
| 114 | + // grab attributes and merge with defaults |
|
| 115 | + $attributes = $this->getAttributes((array)$attributes); |
|
| 116 | + $archive = is_archive(); |
|
| 117 | + $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
|
| 118 | + // don't display on archives unless 'display_on_archives' is true |
|
| 119 | + if ($archive && ! $display_on_archives) { |
|
| 120 | + return ''; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + try { |
|
| 124 | + $this->setBaseTemplateArguments($attributes); |
|
| 125 | + $this->validateEntities($attributes); |
|
| 126 | + $this->setBaseQueryParams(); |
|
| 127 | + } catch (EntityNotFoundException $e) { |
|
| 128 | + if (WP_DEBUG) { |
|
| 129 | + return '<div class="important-notice ee-error">' |
|
| 130 | + . $e->getMessage() |
|
| 131 | + . '</div>'; |
|
| 132 | + } |
|
| 133 | + return ''; |
|
| 134 | + } |
|
| 135 | + $this->setAdditionalQueryParams($attributes); |
|
| 136 | + //get contacts! |
|
| 137 | + $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params); |
|
| 138 | + //all set let's load up the template and return. |
|
| 139 | + return EEH_Template::locate_template( |
|
| 140 | + 'loop-espresso_event_attendees.php', |
|
| 141 | + $this->template_args |
|
| 142 | + ); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * merge incoming attributes with filtered defaults |
|
| 149 | + * |
|
| 150 | + * @param array $attributes |
|
| 151 | + * @return array |
|
| 152 | + */ |
|
| 153 | + private function getAttributes(array $attributes) |
|
| 154 | + { |
|
| 155 | + return (array) apply_filters( |
|
| 156 | + 'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', |
|
| 157 | + $attributes + array( |
|
| 158 | + 'event_id' => null, |
|
| 159 | + 'datetime_id' => null, |
|
| 160 | + 'ticket_id' => null, |
|
| 161 | + 'status' => EEM_Registration::status_id_approved, |
|
| 162 | + 'show_gravatar' => false, |
|
| 163 | + 'display_on_archives' => false, |
|
| 164 | + ) |
|
| 165 | + ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Set all the base template arguments from the incoming attributes. |
|
| 171 | + * |
|
| 172 | + * * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
| 173 | + * If more than one of those params is included, then preference is given to the following: |
|
| 174 | + * - event_id is used whenever its present and any others are ignored. |
|
| 175 | + * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
| 176 | + * - otherwise ticket_id is used if present. |
|
| 177 | + * |
|
| 178 | + * @param array $attributes |
|
| 179 | + * @throws EE_Error |
|
| 180 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 181 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 182 | + * @throws \InvalidArgumentException |
|
| 183 | + */ |
|
| 184 | + private function setBaseTemplateArguments(array $attributes) |
|
| 185 | + { |
|
| 186 | + $this->template_args['show_gravatar'] = $attributes['show_gravatar']; |
|
| 187 | + $this->template_args['event'] = $this->getEvent($attributes); |
|
| 188 | + $this->template_args['datetime'] = empty($attributes['event_id']) |
|
| 189 | + ? $this->getDatetime($attributes) |
|
| 190 | + : null; |
|
| 191 | + $this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id']) |
|
| 192 | + ? $this->getTicket($attributes) |
|
| 193 | + : null; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Validates the presence of entities for the given attribute values. |
|
| 199 | + * @param array $attributes |
|
| 200 | + * @throws EntityNotFoundException |
|
| 201 | + */ |
|
| 202 | + private function validateEntities(array $attributes) |
|
| 203 | + { |
|
| 204 | + if (! $this->template_args['event'] instanceof EE_Event |
|
| 205 | + || ( |
|
| 206 | + empty($attributes['event_id']) |
|
| 207 | + && $attributes['datetime_id'] |
|
| 208 | + && ! $this->template_args['datetime'] instanceof EE_Datetime |
|
| 209 | + ) |
|
| 210 | + || ( |
|
| 211 | + empty($attributes['event_id']) |
|
| 212 | + && empty($attributes['datetime_id']) |
|
| 213 | + && $attributes['ticket_id'] |
|
| 214 | + && ! $this->template_args['ticket'] instanceof EE_Ticket |
|
| 215 | + ) |
|
| 216 | + ) { |
|
| 217 | + throw new EntityNotFoundException( |
|
| 218 | + '', |
|
| 219 | + '', |
|
| 220 | + esc_html__( |
|
| 221 | + 'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly. Please double check the arguments you used for any typos. In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', |
|
| 222 | + 'event_espresso' |
|
| 223 | + ) |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Sets the query params for the base query elements. |
|
| 231 | + */ |
|
| 232 | + private function setBaseQueryParams() |
|
| 233 | + { |
|
| 234 | + switch (true) { |
|
| 235 | + case $this->template_args['datetime'] instanceof EE_Datetime: |
|
| 236 | + $this->query_params = array( |
|
| 237 | + 0 => array( |
|
| 238 | + 'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID() |
|
| 239 | + ), |
|
| 240 | + 'default_where_conditions' => 'this_model_only' |
|
| 241 | + ); |
|
| 242 | + break; |
|
| 243 | + case $this->template_args['ticket'] instanceof EE_Ticket: |
|
| 244 | + $this->query_params[0] = array( |
|
| 245 | + 'Registration.TKT_ID' => $this->template_args['ticket']->ID() |
|
| 246 | + ); |
|
| 247 | + break; |
|
| 248 | + case $this->template_args['event'] instanceof EE_Event: |
|
| 249 | + $this->query_params[0] = array( |
|
| 250 | + 'Registration.EVT_ID' => $this->template_args['event']->ID() |
|
| 251 | + ); |
|
| 252 | + break; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @param array $attributes |
|
| 259 | + * @return EE_Event|null |
|
| 260 | + * @throws EE_Error |
|
| 261 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 262 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 263 | + * @throws \InvalidArgumentException |
|
| 264 | + */ |
|
| 265 | + private function getEvent(array $attributes) |
|
| 266 | + { |
|
| 267 | + switch (true) { |
|
| 268 | + case ! empty($attributes['event_id']): |
|
| 269 | + $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); |
|
| 270 | + break; |
|
| 271 | + case ! empty($attributes['datetime_id']): |
|
| 272 | + $event = EEM_Event::instance()->get_one(array( |
|
| 273 | + array( |
|
| 274 | + 'Datetime.DTT_ID' => $attributes['datetime_id'] |
|
| 275 | + ) |
|
| 276 | + )); |
|
| 277 | + break; |
|
| 278 | + case ! empty($attributes['ticket_id']): |
|
| 279 | + $event = EEM_Event::instance()->get_one(array( |
|
| 280 | + array( |
|
| 281 | + 'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'] |
|
| 282 | + ) |
|
| 283 | + )); |
|
| 284 | + break; |
|
| 285 | + case is_espresso_event(): |
|
| 286 | + $event = EEH_Event_View::get_event(); |
|
| 287 | + break; |
|
| 288 | + default: |
|
| 289 | + // one last shot... |
|
| 290 | + // try getting the earliest active event |
|
| 291 | + $events = EEM_Event::instance()->get_active_events(array( |
|
| 292 | + 'limit' => 1, |
|
| 293 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
| 294 | + )); |
|
| 295 | + // if none then get the next upcoming |
|
| 296 | + $events = empty($events) |
|
| 297 | + ? EEM_Event::instance()->get_upcoming_events(array( |
|
| 298 | + 'limit' => 1, |
|
| 299 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
| 300 | + )) |
|
| 301 | + : $events; |
|
| 302 | + $event = reset($events); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + return $event instanceof EE_Event ? $event : null; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * @param array $attributes |
|
| 311 | + * @return EE_Datetime|null |
|
| 312 | + * @throws EE_Error |
|
| 313 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 314 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 315 | + * @throws \InvalidArgumentException |
|
| 316 | + */ |
|
| 317 | + private function getDatetime(array $attributes) |
|
| 318 | + { |
|
| 319 | + if (! empty($attributes['datetime_id'])) { |
|
| 320 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
|
| 321 | + if ($datetime instanceof EE_Datetime) { |
|
| 322 | + return $datetime; |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + return null; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * @param array $attributes |
|
| 331 | + * @return \EE_Base_Class|EE_Ticket|null |
|
| 332 | + * @throws EE_Error |
|
| 333 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 334 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 335 | + * @throws \InvalidArgumentException |
|
| 336 | + */ |
|
| 337 | + private function getTicket(array $attributes) |
|
| 338 | + { |
|
| 339 | + if (! empty($attributes['ticket_id'])) { |
|
| 340 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
|
| 341 | + if ($ticket instanceof EE_Ticket) { |
|
| 342 | + return $ticket; |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + return null; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @param array $attributes |
|
| 352 | + * @throws EE_Error |
|
| 353 | + */ |
|
| 354 | + private function setAdditionalQueryParams(array $attributes) |
|
| 355 | + { |
|
| 356 | + $reg_status_array = EEM_Registration::reg_status_array(); |
|
| 357 | + if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) { |
|
| 358 | + $this->query_params[0]['Registration.STS_ID'] = $attributes['status']; |
|
| 359 | + } |
|
| 360 | + $this->query_params['group_by'] = array('ATT_ID'); |
|
| 361 | + $this->query_params['order_by'] = (array) apply_filters( |
|
| 362 | + 'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', |
|
| 363 | + array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC') |
|
| 364 | + ); |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | 367 | |
| 368 | 368 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $this->_columns = array_merge( $columns, $this->_columns ); |
| 91 | 91 | $this->_primary_column = '_REG_att_checked_in'; |
| 92 | 92 | if ( ! empty( $evt_id ) |
| 93 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 93 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 94 | 94 | 'ee_read_registrations', |
| 95 | 95 | 'espresso_registrations_registrations_reports', |
| 96 | 96 | $evt_id |
@@ -107,44 +107,44 @@ discard block |
||
| 107 | 107 | ), |
| 108 | 108 | ); |
| 109 | 109 | } |
| 110 | - $this->_bottom_buttons['report_filtered'] = array( |
|
| 111 | - 'route' => 'registrations_checkin_report', |
|
| 112 | - 'extra_request' => array( |
|
| 113 | - 'use_filters' => true, |
|
| 114 | - 'filters' => array_merge( |
|
| 115 | - array( |
|
| 116 | - 'EVT_ID' => $evt_id, |
|
| 117 | - ), |
|
| 118 | - array_diff_key( |
|
| 119 | - $this->_req_data, |
|
| 120 | - array_flip( |
|
| 121 | - array( |
|
| 122 | - 'page', |
|
| 123 | - 'action', |
|
| 124 | - 'default_nonce', |
|
| 125 | - ) |
|
| 126 | - ) |
|
| 127 | - ) |
|
| 128 | - ), |
|
| 129 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 130 | - ), |
|
| 131 | - ); |
|
| 110 | + $this->_bottom_buttons['report_filtered'] = array( |
|
| 111 | + 'route' => 'registrations_checkin_report', |
|
| 112 | + 'extra_request' => array( |
|
| 113 | + 'use_filters' => true, |
|
| 114 | + 'filters' => array_merge( |
|
| 115 | + array( |
|
| 116 | + 'EVT_ID' => $evt_id, |
|
| 117 | + ), |
|
| 118 | + array_diff_key( |
|
| 119 | + $this->_req_data, |
|
| 120 | + array_flip( |
|
| 121 | + array( |
|
| 122 | + 'page', |
|
| 123 | + 'action', |
|
| 124 | + 'default_nonce', |
|
| 125 | + ) |
|
| 126 | + ) |
|
| 127 | + ) |
|
| 128 | + ), |
|
| 129 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 130 | + ), |
|
| 131 | + ); |
|
| 132 | 132 | $this->_sortable_columns = array( |
| 133 | - /** |
|
| 134 | - * Allows users to change the default sort if they wish. |
|
| 135 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
| 136 | - * |
|
| 137 | - * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
| 138 | - * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
| 139 | - * for a specific list table you can use the provided reference to this object instance. |
|
| 140 | - */ |
|
| 133 | + /** |
|
| 134 | + * Allows users to change the default sort if they wish. |
|
| 135 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
| 136 | + * |
|
| 137 | + * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
| 138 | + * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
| 139 | + * for a specific list table you can use the provided reference to this object instance. |
|
| 140 | + */ |
|
| 141 | 141 | 'ATT_name' => array( |
| 142 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
| 143 | - true, |
|
| 144 | - $this |
|
| 145 | - ) |
|
| 146 | - ? array( 'ATT_lname' => true ) |
|
| 147 | - : array( 'ATT_fname' => true ), |
|
| 142 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
| 143 | + true, |
|
| 144 | + $this |
|
| 145 | + ) |
|
| 146 | + ? array( 'ATT_lname' => true ) |
|
| 147 | + : array( 'ATT_fname' => true ), |
|
| 148 | 148 | 'Event' => array( 'Event.EVT.Name' => false ), |
| 149 | 149 | ); |
| 150 | 150 | $this->_hidden_columns = array(); |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | if ( ! $evt->get_count_of_all_registrations() ) { |
| 204 | 204 | continue; |
| 205 | 205 | } |
| 206 | - $evts[] = array( |
|
| 206 | + $evts[] = array( |
|
| 207 | 207 | 'id' => $evt->ID(), |
| 208 | 208 | 'text' => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt), |
| 209 | 209 | 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
@@ -227,8 +227,8 @@ discard block |
||
| 227 | 227 | if ( count( $this->_dtts_for_event ) > 1 ) { |
| 228 | 228 | $dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' ); |
| 229 | 229 | foreach ( $this->_dtts_for_event as $dtt ) { |
| 230 | - $datetime_string = $dtt->name(); |
|
| 231 | - $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : ''; |
|
| 230 | + $datetime_string = $dtt->name(); |
|
| 231 | + $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : ''; |
|
| 232 | 232 | $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
| 233 | 233 | $dtts[ $dtt->ID() ] = $datetime_string; |
| 234 | 234 | } |
@@ -301,16 +301,16 @@ discard block |
||
| 301 | 301 | |
| 302 | 302 | |
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * column_REG_att_checked_in |
|
| 306 | - * |
|
| 307 | - * @param EE_Registration $item |
|
| 308 | - * @return string |
|
| 309 | - * @throws EE_Error |
|
| 310 | - * @throws InvalidArgumentException |
|
| 311 | - * @throws InvalidDataTypeException |
|
| 312 | - * @throws InvalidInterfaceException |
|
| 313 | - */ |
|
| 304 | + /** |
|
| 305 | + * column_REG_att_checked_in |
|
| 306 | + * |
|
| 307 | + * @param EE_Registration $item |
|
| 308 | + * @return string |
|
| 309 | + * @throws EE_Error |
|
| 310 | + * @throws InvalidArgumentException |
|
| 311 | + * @throws InvalidDataTypeException |
|
| 312 | + * @throws InvalidInterfaceException |
|
| 313 | + */ |
|
| 314 | 314 | public function column__REG_att_checked_in( EE_Registration $item ) { |
| 315 | 315 | $attendee = $item->attendee(); |
| 316 | 316 | $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
@@ -321,13 +321,13 @@ discard block |
||
| 321 | 321 | $this->_cur_dtt_id = $latest_related_datetime->ID(); |
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | - $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
| 325 | - $item, |
|
| 326 | - $this->_cur_dtt_id |
|
| 327 | - ); |
|
| 324 | + $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
| 325 | + $item, |
|
| 326 | + $this->_cur_dtt_id |
|
| 327 | + ); |
|
| 328 | 328 | $nonce = wp_create_nonce( 'checkin_nonce' ); |
| 329 | 329 | $toggle_active = ! empty ( $this->_cur_dtt_id ) |
| 330 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 330 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 331 | 331 | 'ee_edit_checkin', |
| 332 | 332 | 'espresso_registrations_toggle_checkin_status', |
| 333 | 333 | $item->ID() |
@@ -336,11 +336,11 @@ discard block |
||
| 336 | 336 | : ''; |
| 337 | 337 | $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
| 338 | 338 | return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
| 339 | - . ' data-_regid="' . $item->ID() . '"' |
|
| 340 | - . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
| 341 | - . ' data-nonce="' . $nonce . '">' |
|
| 342 | - . '</span>' |
|
| 343 | - . $mobile_view_content; |
|
| 339 | + . ' data-_regid="' . $item->ID() . '"' |
|
| 340 | + . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
| 341 | + . ' data-nonce="' . $nonce . '">' |
|
| 342 | + . '</span>' |
|
| 343 | + . $mobile_view_content; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | |
@@ -365,8 +365,8 @@ discard block |
||
| 365 | 365 | 'espresso_registrations_edit_attendee' |
| 366 | 366 | ) |
| 367 | 367 | ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">' |
| 368 | - . $item->attendee()->full_name() |
|
| 369 | - . '</a>' |
|
| 368 | + . $item->attendee()->full_name() |
|
| 369 | + . '</a>' |
|
| 370 | 370 | : $item->attendee()->full_name(); |
| 371 | 371 | $name_link .= $item->count() === 1 |
| 372 | 372 | ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | ? $latest_related_datetime->ID() |
| 402 | 402 | : $DTT_ID; |
| 403 | 403 | if ( ! empty( $DTT_ID ) |
| 404 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 404 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 405 | 405 | 'ee_read_checkins', |
| 406 | 406 | 'espresso_registrations_registration_checkins' |
| 407 | 407 | ) |
@@ -515,15 +515,15 @@ discard block |
||
| 515 | 515 | ) ? ' |
| 516 | 516 | <span class="reg-pad-rght"> |
| 517 | 517 | <a class="status-' |
| 518 | - . $item->transaction()->status_ID() |
|
| 519 | - . '" href="' |
|
| 520 | - . $view_txn_lnk_url |
|
| 521 | - . '" title="' |
|
| 522 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
| 523 | - . '"> |
|
| 518 | + . $item->transaction()->status_ID() |
|
| 519 | + . '" href="' |
|
| 520 | + . $view_txn_lnk_url |
|
| 521 | + . '" title="' |
|
| 522 | + . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
| 523 | + . '"> |
|
| 524 | 524 | ' |
| 525 | - . $item->transaction()->pretty_paid() |
|
| 526 | - . ' |
|
| 525 | + . $item->transaction()->pretty_paid() |
|
| 526 | + . ' |
|
| 527 | 527 | </a> |
| 528 | 528 | <span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
| 529 | 529 | } |
@@ -556,12 +556,12 @@ discard block |
||
| 556 | 556 | 'ee_read_transaction', |
| 557 | 557 | 'espresso_transactions_view_transaction' |
| 558 | 558 | ) ? '<a href="' |
| 559 | - . $view_txn_url |
|
| 560 | - . '" title="' |
|
| 561 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
| 562 | - . '"><span class="reg-pad-rght">' |
|
| 563 | - . $txn_total |
|
| 564 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
| 559 | + . $view_txn_url |
|
| 560 | + . '" title="' |
|
| 561 | + . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
| 562 | + . '"><span class="reg-pad-rght">' |
|
| 563 | + . $txn_total |
|
| 564 | + . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
| 565 | 565 | } else { |
| 566 | 566 | return '<span class="reg-pad-rght"></span>'; |
| 567 | 567 | } |
@@ -45,51 +45,51 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @param \Registrations_Admin_Page $admin_page |
| 47 | 47 | */ |
| 48 | - public function __construct( $admin_page ) { |
|
| 49 | - parent::__construct( $admin_page ); |
|
| 48 | + public function __construct($admin_page) { |
|
| 49 | + parent::__construct($admin_page); |
|
| 50 | 50 | $this->_status = $this->_admin_page->get_registration_status_array(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | protected function _setup_data() { |
| 56 | - $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( $this->_per_page ) |
|
| 57 | - : $this->_admin_page->get_event_attendees( $this->_per_page, false, true ); |
|
| 56 | + $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page) |
|
| 57 | + : $this->_admin_page->get_event_attendees($this->_per_page, false, true); |
|
| 58 | 58 | $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( |
| 59 | 59 | $this->_per_page, |
| 60 | 60 | true |
| 61 | - ) : $this->_admin_page->get_event_attendees( $this->_per_page, true, true ); |
|
| 61 | + ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | protected function _set_properties() { |
| 67 | - $evt_id = isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : null; |
|
| 67 | + $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 68 | 68 | $this->_wp_list_args = array( |
| 69 | - 'singular' => __( 'registrant', 'event_espresso' ), |
|
| 70 | - 'plural' => __( 'registrants', 'event_espresso' ), |
|
| 69 | + 'singular' => __('registrant', 'event_espresso'), |
|
| 70 | + 'plural' => __('registrants', 'event_espresso'), |
|
| 71 | 71 | 'ajax' => true, |
| 72 | 72 | 'screen' => $this->_admin_page->get_current_screen()->id, |
| 73 | 73 | ); |
| 74 | 74 | $columns = array(); |
| 75 | 75 | //$columns['_Reg_Status'] = ''; |
| 76 | - if ( ! empty( $evt_id ) ) { |
|
| 76 | + if ( ! empty($evt_id)) { |
|
| 77 | 77 | $columns['cb'] = '<input type="checkbox" />'; //Render a checkbox instead of text |
| 78 | 78 | $this->_has_checkbox_column = true; |
| 79 | 79 | } |
| 80 | 80 | $this->_columns = array( |
| 81 | 81 | '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>', |
| 82 | - 'ATT_name' => __( 'Registrant', 'event_espresso' ), |
|
| 83 | - 'ATT_email' => __( 'Email Address', 'event_espresso' ), |
|
| 84 | - 'Event' => __( 'Event', 'event_espresso' ), |
|
| 85 | - 'PRC_name' => __( 'TKT Option', 'event_espresso' ), |
|
| 86 | - '_REG_final_price' => __( 'Price', 'event_espresso' ), |
|
| 87 | - 'TXN_paid' => __( 'Paid', 'event_espresso' ), |
|
| 88 | - 'TXN_total' => __( 'Total', 'event_espresso' ), |
|
| 82 | + 'ATT_name' => __('Registrant', 'event_espresso'), |
|
| 83 | + 'ATT_email' => __('Email Address', 'event_espresso'), |
|
| 84 | + 'Event' => __('Event', 'event_espresso'), |
|
| 85 | + 'PRC_name' => __('TKT Option', 'event_espresso'), |
|
| 86 | + '_REG_final_price' => __('Price', 'event_espresso'), |
|
| 87 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
| 88 | + 'TXN_total' => __('Total', 'event_espresso'), |
|
| 89 | 89 | ); |
| 90 | - $this->_columns = array_merge( $columns, $this->_columns ); |
|
| 90 | + $this->_columns = array_merge($columns, $this->_columns); |
|
| 91 | 91 | $this->_primary_column = '_REG_att_checked_in'; |
| 92 | - if ( ! empty( $evt_id ) |
|
| 92 | + if ( ! empty($evt_id) |
|
| 93 | 93 | && EE_Registry::instance()->CAP->current_user_can( |
| 94 | 94 | 'ee_read_registrations', |
| 95 | 95 | 'espresso_registrations_registrations_reports', |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | 'extra_request' => |
| 103 | 103 | array( |
| 104 | 104 | 'EVT_ID' => $evt_id, |
| 105 | - 'return_url' => urlencode( "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" ), |
|
| 105 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 106 | 106 | ), |
| 107 | 107 | ), |
| 108 | 108 | ); |
@@ -143,12 +143,12 @@ discard block |
||
| 143 | 143 | true, |
| 144 | 144 | $this |
| 145 | 145 | ) |
| 146 | - ? array( 'ATT_lname' => true ) |
|
| 147 | - : array( 'ATT_fname' => true ), |
|
| 148 | - 'Event' => array( 'Event.EVT.Name' => false ), |
|
| 146 | + ? array('ATT_lname' => true) |
|
| 147 | + : array('ATT_fname' => true), |
|
| 148 | + 'Event' => array('Event.EVT.Name' => false), |
|
| 149 | 149 | ); |
| 150 | 150 | $this->_hidden_columns = array(); |
| 151 | - $this->_evt = EEM_Event::instance()->get_one_by_ID( $evt_id ); |
|
| 151 | + $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id); |
|
| 152 | 152 | $this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array(); |
| 153 | 153 | } |
| 154 | 154 | |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | * @param \EE_Registration $item |
| 159 | 159 | * @return string |
| 160 | 160 | */ |
| 161 | - protected function _get_row_class( $item ) { |
|
| 162 | - $class = parent::_get_row_class( $item ); |
|
| 161 | + protected function _get_row_class($item) { |
|
| 162 | + $class = parent::_get_row_class($item); |
|
| 163 | 163 | //add status class |
| 164 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
| 165 | - if ( $this->_has_checkbox_column ) { |
|
| 164 | + $class .= ' ee-status-strip reg-status-'.$item->status_ID(); |
|
| 165 | + if ($this->_has_checkbox_column) { |
|
| 166 | 166 | $class .= ' has-checkbox-column'; |
| 167 | 167 | } |
| 168 | 168 | return $class; |
@@ -176,61 +176,61 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | protected function _get_table_filters() { |
| 178 | 178 | $filters = $where = array(); |
| 179 | - $current_EVT_ID = isset( $this->_req_data['event_id'] ) ? (int) $this->_req_data['event_id'] : 0; |
|
| 180 | - if ( empty( $this->_dtts_for_event ) || count( $this->_dtts_for_event ) === 1 ) { |
|
| 179 | + $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0; |
|
| 180 | + if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
|
| 181 | 181 | //this means we don't have an event so let's setup a filter dropdown for all the events to select |
| 182 | 182 | //note possible capability restrictions |
| 183 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_events', 'get_events' ) ) { |
|
| 184 | - $where['status**'] = array( '!=', 'private' ); |
|
| 183 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 184 | + $where['status**'] = array('!=', 'private'); |
|
| 185 | 185 | } |
| 186 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) { |
|
| 186 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 187 | 187 | $where['EVT_wp_user'] = get_current_user_id(); |
| 188 | 188 | } |
| 189 | 189 | $events = EEM_Event::instance()->get_all( |
| 190 | 190 | array( |
| 191 | 191 | $where, |
| 192 | - 'order_by' => array( 'Datetime.DTT_EVT_start' => 'DESC' ), |
|
| 192 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'), |
|
| 193 | 193 | ) |
| 194 | 194 | ); |
| 195 | 195 | $evts[] = array( |
| 196 | 196 | 'id' => 0, |
| 197 | - 'text' => __( 'To toggle Check-in status, select an event', 'event_espresso' ), |
|
| 197 | + 'text' => __('To toggle Check-in status, select an event', 'event_espresso'), |
|
| 198 | 198 | ); |
| 199 | 199 | $checked = 'checked'; |
| 200 | 200 | /** @var EE_Event $evt */ |
| 201 | - foreach ( $events as $evt ) { |
|
| 201 | + foreach ($events as $evt) { |
|
| 202 | 202 | //any registrations for this event? |
| 203 | - if ( ! $evt->get_count_of_all_registrations() ) { |
|
| 203 | + if ( ! $evt->get_count_of_all_registrations()) { |
|
| 204 | 204 | continue; |
| 205 | 205 | } |
| 206 | 206 | $evts[] = array( |
| 207 | 207 | 'id' => $evt->ID(), |
| 208 | - 'text' => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt), |
|
| 208 | + 'text' => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get('EVT_name'), $evt), |
|
| 209 | 209 | 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
| 210 | 210 | ); |
| 211 | - if ( $evt->ID() === $current_EVT_ID && $evt->is_expired() ) { |
|
| 211 | + if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) { |
|
| 212 | 212 | $checked = ''; |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | $event_filter = '<div class="ee-event-filter">'; |
| 216 | - $event_filter .= EEH_Form_Fields::select_input( 'event_id', $evts, $current_EVT_ID ); |
|
| 216 | + $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
|
| 217 | 217 | $event_filter .= '<span class="ee-event-filter-toggle">'; |
| 218 | - $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
| 219 | - $event_filter .= __( 'Hide Expired Events', 'event_espresso' ); |
|
| 218 | + $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> '; |
|
| 219 | + $event_filter .= __('Hide Expired Events', 'event_espresso'); |
|
| 220 | 220 | $event_filter .= '</span>'; |
| 221 | 221 | $event_filter .= '</div>'; |
| 222 | 222 | $filters[] = $event_filter; |
| 223 | 223 | } |
| 224 | - if ( ! empty( $this->_dtts_for_event ) ) { |
|
| 224 | + if ( ! empty($this->_dtts_for_event)) { |
|
| 225 | 225 | //DTT datetimes filter |
| 226 | - $this->_cur_dtt_id = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0; |
|
| 227 | - if ( count( $this->_dtts_for_event ) > 1 ) { |
|
| 228 | - $dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' ); |
|
| 229 | - foreach ( $this->_dtts_for_event as $dtt ) { |
|
| 226 | + $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
|
| 227 | + if (count($this->_dtts_for_event) > 1) { |
|
| 228 | + $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso'); |
|
| 229 | + foreach ($this->_dtts_for_event as $dtt) { |
|
| 230 | 230 | $datetime_string = $dtt->name(); |
| 231 | - $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : ''; |
|
| 232 | - $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
| 233 | - $dtts[ $dtt->ID() ] = $datetime_string; |
|
| 231 | + $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : ''; |
|
| 232 | + $datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string; |
|
| 233 | + $dtts[$dtt->ID()] = $datetime_string; |
|
| 234 | 234 | } |
| 235 | 235 | $input = new EE_Select_Input( |
| 236 | 236 | $dtts, |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | ) |
| 242 | 242 | ); |
| 243 | 243 | $filters[] = $input->get_html_for_input(); |
| 244 | - $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
| 244 | + $filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">'; |
|
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | return $filters; |
@@ -260,22 +260,22 @@ discard block |
||
| 260 | 260 | * @throws \EE_Error |
| 261 | 261 | */ |
| 262 | 262 | protected function _get_total_event_attendees() { |
| 263 | - $EVT_ID = isset( $this->_req_data['event_id'] ) ? absint( $this->_req_data['event_id'] ) : false; |
|
| 263 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 264 | 264 | $DTT_ID = $this->_cur_dtt_id; |
| 265 | 265 | $query_params = array(); |
| 266 | - if ( $EVT_ID ) { |
|
| 266 | + if ($EVT_ID) { |
|
| 267 | 267 | $query_params[0]['EVT_ID'] = $EVT_ID; |
| 268 | 268 | } |
| 269 | 269 | //if DTT is included we only show for that datetime. Otherwise we're showing for all datetimes (the event). |
| 270 | - if ( $DTT_ID ) { |
|
| 270 | + if ($DTT_ID) { |
|
| 271 | 271 | $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
| 272 | 272 | } |
| 273 | 273 | $status_ids_array = apply_filters( |
| 274 | 274 | 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
| 275 | - array( EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved ) |
|
| 275 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 276 | 276 | ); |
| 277 | - $query_params[0]['STS_ID'] = array( 'IN', $status_ids_array ); |
|
| 278 | - return EEM_Registration::instance()->count( $query_params ); |
|
| 277 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 278 | + return EEM_Registration::instance()->count($query_params); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -284,8 +284,8 @@ discard block |
||
| 284 | 284 | * @param \EE_Registration $item |
| 285 | 285 | * @return string |
| 286 | 286 | */ |
| 287 | - public function column__Reg_Status( EE_Registration $item ) { |
|
| 288 | - return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>'; |
|
| 287 | + public function column__Reg_Status(EE_Registration $item) { |
|
| 288 | + return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>'; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | |
@@ -295,8 +295,8 @@ discard block |
||
| 295 | 295 | * @return string |
| 296 | 296 | * @throws \EE_Error |
| 297 | 297 | */ |
| 298 | - public function column_cb( $item ) { |
|
| 299 | - return sprintf( '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID() ); |
|
| 298 | + public function column_cb($item) { |
|
| 299 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID()); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | |
@@ -311,13 +311,13 @@ discard block |
||
| 311 | 311 | * @throws InvalidDataTypeException |
| 312 | 312 | * @throws InvalidInterfaceException |
| 313 | 313 | */ |
| 314 | - public function column__REG_att_checked_in( EE_Registration $item ) { |
|
| 314 | + public function column__REG_att_checked_in(EE_Registration $item) { |
|
| 315 | 315 | $attendee = $item->attendee(); |
| 316 | 316 | $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
| 317 | 317 | |
| 318 | - if ( $this->_cur_dtt_id === 0 && count( $this->_dtts_for_event ) === 1 ) { |
|
| 318 | + if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) { |
|
| 319 | 319 | $latest_related_datetime = $item->get_latest_related_datetime(); |
| 320 | - if ( $latest_related_datetime instanceof EE_Datetime ) { |
|
| 320 | + if ($latest_related_datetime instanceof EE_Datetime) { |
|
| 321 | 321 | $this->_cur_dtt_id = $latest_related_datetime->ID(); |
| 322 | 322 | } |
| 323 | 323 | } |
@@ -325,8 +325,8 @@ discard block |
||
| 325 | 325 | $item, |
| 326 | 326 | $this->_cur_dtt_id |
| 327 | 327 | ); |
| 328 | - $nonce = wp_create_nonce( 'checkin_nonce' ); |
|
| 329 | - $toggle_active = ! empty ( $this->_cur_dtt_id ) |
|
| 328 | + $nonce = wp_create_nonce('checkin_nonce'); |
|
| 329 | + $toggle_active = ! empty ($this->_cur_dtt_id) |
|
| 330 | 330 | && EE_Registry::instance()->CAP->current_user_can( |
| 331 | 331 | 'ee_edit_checkin', |
| 332 | 332 | 'espresso_registrations_toggle_checkin_status', |
@@ -334,11 +334,11 @@ discard block |
||
| 334 | 334 | ) |
| 335 | 335 | ? ' clickable trigger-checkin' |
| 336 | 336 | : ''; |
| 337 | - $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
| 338 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
|
| 339 | - . ' data-_regid="' . $item->ID() . '"' |
|
| 340 | - . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
| 341 | - . ' data-nonce="' . $nonce . '">' |
|
| 337 | + $mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>'; |
|
| 338 | + return '<span class="'.$checkin_status_dashicon->cssClasses().$toggle_active.'"' |
|
| 339 | + . ' data-_regid="'.$item->ID().'"' |
|
| 340 | + . ' data-dttid="'.$this->_cur_dtt_id.'"' |
|
| 341 | + . ' data-nonce="'.$nonce.'">' |
|
| 342 | 342 | . '</span>' |
| 343 | 343 | . $mobile_view_content; |
| 344 | 344 | } |
@@ -350,21 +350,21 @@ discard block |
||
| 350 | 350 | * @return mixed|string|void |
| 351 | 351 | * @throws \EE_Error |
| 352 | 352 | */ |
| 353 | - public function column_ATT_name( EE_Registration $item ) { |
|
| 353 | + public function column_ATT_name(EE_Registration $item) { |
|
| 354 | 354 | $attendee = $item->attendee(); |
| 355 | - if ( ! $attendee instanceof EE_Attendee ) { |
|
| 356 | - return __( 'No contact record for this registration.', 'event_espresso' ); |
|
| 355 | + if ( ! $attendee instanceof EE_Attendee) { |
|
| 356 | + return __('No contact record for this registration.', 'event_espresso'); |
|
| 357 | 357 | } |
| 358 | 358 | // edit attendee link |
| 359 | 359 | $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
| 360 | - array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ), |
|
| 360 | + array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
| 361 | 361 | REG_ADMIN_URL |
| 362 | 362 | ); |
| 363 | 363 | $name_link = EE_Registry::instance()->CAP->current_user_can( |
| 364 | 364 | 'ee_edit_contacts', |
| 365 | 365 | 'espresso_registrations_edit_attendee' |
| 366 | 366 | ) |
| 367 | - ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">' |
|
| 367 | + ? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
| 368 | 368 | . $item->attendee()->full_name() |
| 369 | 369 | . '</a>' |
| 370 | 370 | : $item->attendee()->full_name(); |
@@ -372,10 +372,10 @@ discard block |
||
| 372 | 372 | ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
| 373 | 373 | : ''; |
| 374 | 374 | //add group details |
| 375 | - $name_link .= ' ' . sprintf( __( '(%s of %s)', 'event_espresso' ), $item->count(), $item->group_size() ); |
|
| 375 | + $name_link .= ' '.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 376 | 376 | //add regcode |
| 377 | 377 | $link = EE_Admin_Page::add_query_args_and_nonce( |
| 378 | - array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ), |
|
| 378 | + array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
| 379 | 379 | REG_ADMIN_URL |
| 380 | 380 | ); |
| 381 | 381 | $name_link .= '<br>'; |
@@ -384,50 +384,50 @@ discard block |
||
| 384 | 384 | 'view_registration', |
| 385 | 385 | $item->ID() |
| 386 | 386 | ) |
| 387 | - ? '<a href="' . $link . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">' |
|
| 387 | + ? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
| 388 | 388 | . $item->reg_code() |
| 389 | 389 | . '</a>' |
| 390 | 390 | : $item->reg_code(); |
| 391 | 391 | //status |
| 392 | 392 | $name_link .= '<br><span class="ee-status-text-small">'; |
| 393 | - $name_link .= EEH_Template::pretty_status( $item->status_ID(), false, 'sentence' ); |
|
| 393 | + $name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence'); |
|
| 394 | 394 | $name_link .= '</span>'; |
| 395 | 395 | $actions = array(); |
| 396 | 396 | $DTT_ID = $this->_cur_dtt_id; |
| 397 | - $latest_related_datetime = empty( $DTT_ID ) && ! empty( $this->_req_data['event_id'] ) && $item instanceof EE_Registration |
|
| 397 | + $latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration |
|
| 398 | 398 | ? $item->get_latest_related_datetime() |
| 399 | 399 | : null; |
| 400 | 400 | $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
| 401 | 401 | ? $latest_related_datetime->ID() |
| 402 | 402 | : $DTT_ID; |
| 403 | - if ( ! empty( $DTT_ID ) |
|
| 403 | + if ( ! empty($DTT_ID) |
|
| 404 | 404 | && EE_Registry::instance()->CAP->current_user_can( |
| 405 | 405 | 'ee_read_checkins', |
| 406 | 406 | 'espresso_registrations_registration_checkins' |
| 407 | 407 | ) |
| 408 | 408 | ) { |
| 409 | 409 | $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce( |
| 410 | - array( 'action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID ) |
|
| 410 | + array('action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID) |
|
| 411 | 411 | ); |
| 412 | 412 | // get the timestamps for this registration's checkins, related to the selected datetime |
| 413 | - $timestamps = $item->get_many_related( 'Checkin', array( array( 'DTT_ID' => $DTT_ID ) ) ); |
|
| 414 | - if( ! empty( $timestamps ) ) { |
|
| 413 | + $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID))); |
|
| 414 | + if ( ! empty($timestamps)) { |
|
| 415 | 415 | // get the last timestamp |
| 416 | - $last_timestamp = end( $timestamps ); |
|
| 416 | + $last_timestamp = end($timestamps); |
|
| 417 | 417 | // checked in or checked out? |
| 418 | - $checkin_status = $last_timestamp->get( 'CHK_in' ) |
|
| 419 | - ? esc_html__( 'Checked In', 'event_espresso' ) |
|
| 420 | - : esc_html__( 'Checked Out', 'event_espresso' ); |
|
| 418 | + $checkin_status = $last_timestamp->get('CHK_in') |
|
| 419 | + ? esc_html__('Checked In', 'event_espresso') |
|
| 420 | + : esc_html__('Checked Out', 'event_espresso'); |
|
| 421 | 421 | // get timestamp string |
| 422 | - $timestamp_string = $last_timestamp->get_datetime( 'CHK_timestamp' ); |
|
| 423 | - $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' . esc_attr__( |
|
| 422 | + $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
|
| 423 | + $actions['checkin'] = '<a href="'.$checkin_list_url.'" title="'.esc_attr__( |
|
| 424 | 424 | 'View this registrant\'s check-ins/checkouts for the datetime', |
| 425 | 425 | 'event_espresso' |
| 426 | - ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
| 426 | + ).'">'.$checkin_status.': '.$timestamp_string.'</a>'; |
|
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | - return ( ! empty( $DTT_ID ) && ! empty( $timestamps ) ) |
|
| 430 | - ? sprintf( '%1$s %2$s', $name_link, $this->row_actions( $actions, true ) ) |
|
| 429 | + return ( ! empty($DTT_ID) && ! empty($timestamps)) |
|
| 430 | + ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
|
| 431 | 431 | : $name_link; |
| 432 | 432 | } |
| 433 | 433 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | * @param \EE_Registration $item |
| 438 | 438 | * @return string |
| 439 | 439 | */ |
| 440 | - public function column_ATT_email( EE_Registration $item ) { |
|
| 440 | + public function column_ATT_email(EE_Registration $item) { |
|
| 441 | 441 | $attendee = $item->attendee(); |
| 442 | 442 | return $attendee instanceof EE_Attendee ? $attendee->email() : ''; |
| 443 | 443 | } |
@@ -449,22 +449,22 @@ discard block |
||
| 449 | 449 | * @return bool|string |
| 450 | 450 | * @throws \EE_Error |
| 451 | 451 | */ |
| 452 | - public function column_Event( EE_Registration $item ) { |
|
| 452 | + public function column_Event(EE_Registration $item) { |
|
| 453 | 453 | try { |
| 454 | 454 | $event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event(); |
| 455 | 455 | $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
| 456 | - array( 'action' => 'event_registrations', 'event_id' => $event->ID() ), |
|
| 456 | + array('action' => 'event_registrations', 'event_id' => $event->ID()), |
|
| 457 | 457 | REG_ADMIN_URL |
| 458 | 458 | ); |
| 459 | 459 | $event_label = EE_Registry::instance()->CAP->current_user_can( |
| 460 | 460 | 'ee_read_checkins', |
| 461 | 461 | 'espresso_registrations_registration_checkins' |
| 462 | - ) ? '<a href="' . $chkin_lnk_url . '" title="' . esc_attr__( |
|
| 462 | + ) ? '<a href="'.$chkin_lnk_url.'" title="'.esc_attr__( |
|
| 463 | 463 | 'View Checkins for this Event', |
| 464 | 464 | 'event_espresso' |
| 465 | - ) . '">' . $event->name() . '</a>' : $event->name(); |
|
| 466 | - } catch ( \EventEspresso\core\exceptions\EntityNotFoundException $e ) { |
|
| 467 | - $event_label = esc_html__( 'Unknown', 'event_espresso' ); |
|
| 465 | + ).'">'.$event->name().'</a>' : $event->name(); |
|
| 466 | + } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
| 467 | + $event_label = esc_html__('Unknown', 'event_espresso'); |
|
| 468 | 468 | } |
| 469 | 469 | return $event_label; |
| 470 | 470 | } |
@@ -475,8 +475,8 @@ discard block |
||
| 475 | 475 | * @param \EE_Registration $item |
| 476 | 476 | * @return mixed|string|void |
| 477 | 477 | */ |
| 478 | - public function column_PRC_name( EE_Registration $item ) { |
|
| 479 | - return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __( "Unknown", "event_espresso" ); |
|
| 478 | + public function column_PRC_name(EE_Registration $item) { |
|
| 479 | + return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso"); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | |
@@ -487,8 +487,8 @@ discard block |
||
| 487 | 487 | * @param \EE_Registration $item |
| 488 | 488 | * @return string |
| 489 | 489 | */ |
| 490 | - public function column__REG_final_price( EE_Registration $item ) { |
|
| 491 | - return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>'; |
|
| 490 | + public function column__REG_final_price(EE_Registration $item) { |
|
| 491 | + return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>'; |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | |
@@ -500,13 +500,13 @@ discard block |
||
| 500 | 500 | * @return string |
| 501 | 501 | * @throws \EE_Error |
| 502 | 502 | */ |
| 503 | - public function column_TXN_paid( EE_Registration $item ) { |
|
| 504 | - if ( $item->count() === 1 ) { |
|
| 505 | - if ( $item->transaction()->paid() >= $item->transaction()->total() ) { |
|
| 503 | + public function column_TXN_paid(EE_Registration $item) { |
|
| 504 | + if ($item->count() === 1) { |
|
| 505 | + if ($item->transaction()->paid() >= $item->transaction()->total()) { |
|
| 506 | 506 | return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
| 507 | 507 | } else { |
| 508 | 508 | $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
| 509 | - array( 'action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID() ), |
|
| 509 | + array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()), |
|
| 510 | 510 | TXN_ADMIN_URL |
| 511 | 511 | ); |
| 512 | 512 | return EE_Registry::instance()->CAP->current_user_can( |
@@ -519,13 +519,13 @@ discard block |
||
| 519 | 519 | . '" href="' |
| 520 | 520 | . $view_txn_lnk_url |
| 521 | 521 | . '" title="' |
| 522 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
| 522 | + . esc_attr__('View Transaction', 'event_espresso') |
|
| 523 | 523 | . '"> |
| 524 | 524 | ' |
| 525 | 525 | . $item->transaction()->pretty_paid() |
| 526 | 526 | . ' |
| 527 | 527 | </a> |
| 528 | - <span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
| 528 | + <span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>'; |
|
| 529 | 529 | } |
| 530 | 530 | } else { |
| 531 | 531 | return '<span class="reg-pad-rght"></span>'; |
@@ -541,13 +541,13 @@ discard block |
||
| 541 | 541 | * @return string |
| 542 | 542 | * @throws \EE_Error |
| 543 | 543 | */ |
| 544 | - public function column_TXN_total( EE_Registration $item ) { |
|
| 544 | + public function column_TXN_total(EE_Registration $item) { |
|
| 545 | 545 | $txn = $item->transaction(); |
| 546 | - $view_txn_url = add_query_arg( array( 'action' => 'view_transaction', 'TXN_ID' => $txn->ID() ), TXN_ADMIN_URL ); |
|
| 547 | - if ( $item->get( 'REG_count' ) === 1 ) { |
|
| 546 | + $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL); |
|
| 547 | + if ($item->get('REG_count') === 1) { |
|
| 548 | 548 | $line_total_obj = $txn->total_line_item(); |
| 549 | 549 | $txn_total = $line_total_obj instanceof EE_Line_Item |
| 550 | - ? $line_total_obj->get_pretty( 'LIN_total' ) |
|
| 550 | + ? $line_total_obj->get_pretty('LIN_total') |
|
| 551 | 551 | : __( |
| 552 | 552 | 'View Transaction', |
| 553 | 553 | 'event_espresso' |
@@ -558,10 +558,10 @@ discard block |
||
| 558 | 558 | ) ? '<a href="' |
| 559 | 559 | . $view_txn_url |
| 560 | 560 | . '" title="' |
| 561 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
| 561 | + . esc_attr__('View Transaction', 'event_espresso') |
|
| 562 | 562 | . '"><span class="reg-pad-rght">' |
| 563 | 563 | . $txn_total |
| 564 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
| 564 | + . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>'; |
|
| 565 | 565 | } else { |
| 566 | 566 | return '<span class="reg-pad-rght"></span>'; |
| 567 | 567 | } |
@@ -90,8 +90,8 @@ |
||
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | public function column_CHK_in( EE_Checkin $item ) { |
| 93 | - $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
| 94 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>'; |
|
| 93 | + $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
| 94 | + return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>'; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | - public function __construct( $admin_page ) { |
|
| 33 | + public function __construct($admin_page) { |
|
| 34 | 34 | parent::__construct($admin_page); |
| 35 | 35 | } |
| 36 | 36 | |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | protected function _setup_data() { |
| 41 | - $this->_data = $this->_get_checkins( $this->_per_page ); |
|
| 42 | - $this->_all_data_count = $this->_get_checkins( $this->_per_page, TRUE ); |
|
| 41 | + $this->_data = $this->_get_checkins($this->_per_page); |
|
| 42 | + $this->_all_data_count = $this->_get_checkins($this->_per_page, TRUE); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | ); |
| 61 | 61 | |
| 62 | 62 | $this->_sortable_columns = array( |
| 63 | - 'CHK_timestamp' => array( 'CHK_timestamp' => TRUE ) |
|
| 63 | + 'CHK_timestamp' => array('CHK_timestamp' => TRUE) |
|
| 64 | 64 | ); |
| 65 | 65 | |
| 66 | 66 | $this->_primary_column = 'CHK_in'; |
@@ -84,24 +84,24 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
| 87 | - function column_cb($item ) { |
|
| 88 | - return sprintf( '<input type="checkbox" name="checkbox[%1$s]" />', $item->ID() ); |
|
| 87 | + function column_cb($item) { |
|
| 88 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID()); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
| 92 | - public function column_CHK_in( EE_Checkin $item ) { |
|
| 92 | + public function column_CHK_in(EE_Checkin $item) { |
|
| 93 | 93 | $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
| 94 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>'; |
|
| 94 | + return '<span class="'.$checkin_status_dashicon->cssClasses().'"></span><span class="show-on-mobile-view-only">'.$item->get_datetime('CHK_timestamp').'</span>'; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
| 98 | 98 | |
| 99 | - function column_CHK_timestamp( EE_Checkin $item ) { |
|
| 99 | + function column_CHK_timestamp(EE_Checkin $item) { |
|
| 100 | 100 | $actions = array(); |
| 101 | - $delete_url = EE_Admin_Page::add_query_args_and_nonce( array('action' => 'delete_checkin_row', 'DTT_ID' => $this->_req_data['DTT_ID'], '_REGID' => $this->_req_data['_REGID'], 'CHK_ID' => $item->ID() ) ); |
|
| 102 | - $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( 'ee_delete_checkins', 'espresso_registrations_delete_checkin_row' ) ? '<a href="' . $delete_url . '" title="' . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' . __('Delete', 'event_espresso') . '</a>' : ''; |
|
| 101 | + $delete_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_checkin_row', 'DTT_ID' => $this->_req_data['DTT_ID'], '_REGID' => $this->_req_data['_REGID'], 'CHK_ID' => $item->ID())); |
|
| 102 | + $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can('ee_delete_checkins', 'espresso_registrations_delete_checkin_row') ? '<a href="'.$delete_url.'" title="'.esc_attr__('Click here to delete this check-in record', 'event_espresso').'">'.__('Delete', 'event_espresso').'</a>' : ''; |
|
| 103 | 103 | |
| 104 | - return sprintf( '%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions) ); |
|
| 104 | + return sprintf('%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions)); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
@@ -116,30 +116,30 @@ discard block |
||
| 116 | 116 | * @param bool $count Whether to return a count or not |
| 117 | 117 | * @return EE_Checkin[]|int |
| 118 | 118 | */ |
| 119 | - protected function _get_checkins( $per_page = 10, $count = FALSE ) { |
|
| 120 | - $REG_ID = isset( $this->_req_data['_REGID'] ) ? $this->_req_data['_REGID'] : FALSE; |
|
| 121 | - $DTT_ID = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : FALSE; |
|
| 119 | + protected function _get_checkins($per_page = 10, $count = FALSE) { |
|
| 120 | + $REG_ID = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : FALSE; |
|
| 121 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : FALSE; |
|
| 122 | 122 | |
| 123 | 123 | //if user does not have the capability for the checkins for this registration then get out! |
| 124 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_checkin', 'espresso_registrations_registration_checkins', $REG_ID ) ) { |
|
| 124 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', 'espresso_registrations_registration_checkins', $REG_ID)) { |
|
| 125 | 125 | return $count ? 0 : array(); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | //if no reg id then get out cause need a reg id |
| 129 | - if ( empty( $REG_ID ) || empty( $DTT_ID ) ) |
|
| 130 | - throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') ); |
|
| 129 | + if (empty($REG_ID) || empty($DTT_ID)) |
|
| 130 | + throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso')); |
|
| 131 | 131 | |
| 132 | 132 | //set orderby |
| 133 | 133 | $orderby = 'CHK_timestamp'; //note that with this table we're only providing the option to orderby the timestamp value. |
| 134 | 134 | |
| 135 | - $order = !empty( $this->_req_data['order'] ) ? $this->_req_data['order'] : 'ASC'; |
|
| 135 | + $order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 136 | 136 | |
| 137 | - $current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1; |
|
| 138 | - $per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page; |
|
| 137 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 138 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 139 | 139 | $limit = NULL; |
| 140 | - if ( !$count ) { |
|
| 141 | - $offset = ($current_page-1)*$per_page; |
|
| 142 | - $limit = array( $offset, $per_page ); |
|
| 140 | + if ( ! $count) { |
|
| 141 | + $offset = ($current_page - 1) * $per_page; |
|
| 142 | + $limit = array($offset, $per_page); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $_where = array( |
@@ -147,13 +147,13 @@ discard block |
||
| 147 | 147 | 'DTT_ID' => $DTT_ID |
| 148 | 148 | ); |
| 149 | 149 | |
| 150 | - $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
| 150 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
| 151 | 151 | |
| 152 | 152 | //if no per_page value then we just want to return a count of all Check-ins |
| 153 | - if ( $count ) |
|
| 154 | - return EEM_Checkin::instance()->count( array( $_where ) ); |
|
| 153 | + if ($count) |
|
| 154 | + return EEM_Checkin::instance()->count(array($_where)); |
|
| 155 | 155 | |
| 156 | - return $count ? EEM_Checkin::instance()->count( array( $_where ) ) : EEM_Checkin::instance()->get_all($query_params); |
|
| 156 | + return $count ? EEM_Checkin::instance()->count(array($_where)) : EEM_Checkin::instance()->get_all($query_params); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | } //end class EE_Registration_CheckIn_List_Table |
@@ -1,6 +1,8 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\ui\browser\checkins\entities\CheckinStatusDashicon; |
| 2 | 2 | |
| 3 | -if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | +} |
|
| 4 | 6 | /** |
| 5 | 7 | * Event Espresso |
| 6 | 8 | * |
@@ -126,8 +128,9 @@ discard block |
||
| 126 | 128 | } |
| 127 | 129 | |
| 128 | 130 | //if no reg id then get out cause need a reg id |
| 129 | - if ( empty( $REG_ID ) || empty( $DTT_ID ) ) |
|
| 130 | - throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') ); |
|
| 131 | + if ( empty( $REG_ID ) || empty( $DTT_ID ) ) { |
|
| 132 | + throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') ); |
|
| 133 | + } |
|
| 131 | 134 | |
| 132 | 135 | //set orderby |
| 133 | 136 | $orderby = 'CHK_timestamp'; //note that with this table we're only providing the option to orderby the timestamp value. |
@@ -150,8 +153,9 @@ discard block |
||
| 150 | 153 | $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
| 151 | 154 | |
| 152 | 155 | //if no per_page value then we just want to return a count of all Check-ins |
| 153 | - if ( $count ) |
|
| 154 | - return EEM_Checkin::instance()->count( array( $_where ) ); |
|
| 156 | + if ( $count ) { |
|
| 157 | + return EEM_Checkin::instance()->count( array( $_where ) ); |
|
| 158 | + } |
|
| 155 | 159 | |
| 156 | 160 | return $count ? EEM_Checkin::instance()->count( array( $_where ) ) : EEM_Checkin::instance()->get_all($query_params); |
| 157 | 161 | } |