@@ -17,607 +17,607 @@ |
||
| 17 | 17 | class EE_Cron_Tasks extends EE_Base |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
| 22 | - * so we'll set our retry time for just over 10 minutes to avoid that |
|
| 23 | - */ |
|
| 24 | - const reschedule_timeout = 605; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var EE_Cron_Tasks |
|
| 29 | - */ |
|
| 30 | - private static $_instance; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @return EE_Cron_Tasks |
|
| 35 | - * @throws ReflectionException |
|
| 36 | - * @throws EE_Error |
|
| 37 | - * @throws InvalidArgumentException |
|
| 38 | - * @throws InvalidInterfaceException |
|
| 39 | - * @throws InvalidDataTypeException |
|
| 40 | - */ |
|
| 41 | - public static function instance() |
|
| 42 | - { |
|
| 43 | - if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
| 44 | - self::$_instance = new self(); |
|
| 45 | - } |
|
| 46 | - return self::$_instance; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @access private |
|
| 52 | - * @throws InvalidDataTypeException |
|
| 53 | - * @throws InvalidInterfaceException |
|
| 54 | - * @throws InvalidArgumentException |
|
| 55 | - * @throws EE_Error |
|
| 56 | - * @throws ReflectionException |
|
| 57 | - */ |
|
| 58 | - private function __construct() |
|
| 59 | - { |
|
| 60 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 61 | - // verify that WP Cron is enabled |
|
| 62 | - if ( |
|
| 63 | - defined('DISABLE_WP_CRON') |
|
| 64 | - && DISABLE_WP_CRON |
|
| 65 | - && is_admin() |
|
| 66 | - && ! get_option('ee_disabled_wp_cron_check') |
|
| 67 | - ) { |
|
| 68 | - /** |
|
| 69 | - * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
| 70 | - * config is loaded. |
|
| 71 | - * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
| 72 | - * wanting to not have this functionality can just register its own action at a priority after this one to |
|
| 73 | - * reverse any changes. |
|
| 74 | - */ |
|
| 75 | - add_action( |
|
| 76 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
| 77 | - function () |
|
| 78 | - { |
|
| 79 | - EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
| 80 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 81 | - add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
| 82 | - } |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - // UPDATE TRANSACTION WITH PAYMENT |
|
| 86 | - add_action( |
|
| 87 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 88 | - array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
| 89 | - 10, |
|
| 90 | - 2 |
|
| 91 | - ); |
|
| 92 | - // ABANDONED / EXPIRED TRANSACTION CHECK |
|
| 93 | - add_action( |
|
| 94 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 95 | - array('EE_Cron_Tasks', 'expired_transaction_check'), |
|
| 96 | - 10, |
|
| 97 | - 1 |
|
| 98 | - ); |
|
| 99 | - // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
| 100 | - add_action( |
|
| 101 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 102 | - array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
| 103 | - ); |
|
| 104 | - // logging |
|
| 105 | - add_action( |
|
| 106 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
| 107 | - array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
| 108 | - ); |
|
| 109 | - EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
| 110 | - //clean out old gateway logs |
|
| 111 | - add_action( |
|
| 112 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
| 113 | - array('EE_Cron_Tasks', 'clean_out_old_gateway_logs') |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @access protected |
|
| 120 | - * @return void |
|
| 121 | - */ |
|
| 122 | - public static function log_scheduled_ee_crons() |
|
| 123 | - { |
|
| 124 | - $ee_crons = array( |
|
| 125 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
| 126 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 127 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 128 | - ); |
|
| 129 | - $crons = (array) get_option('cron'); |
|
| 130 | - if (! is_array($crons)) { |
|
| 131 | - return; |
|
| 132 | - } |
|
| 133 | - foreach ($crons as $timestamp => $cron) { |
|
| 134 | - /** @var array[] $cron */ |
|
| 135 | - foreach ($ee_crons as $ee_cron) { |
|
| 136 | - if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
| 137 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
| 138 | - foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
| 139 | - if (! empty($ee_cron_details['args'])) { |
|
| 140 | - do_action( |
|
| 141 | - 'AHEE_log', |
|
| 142 | - __CLASS__, |
|
| 143 | - __FUNCTION__, |
|
| 144 | - print_r($ee_cron_details['args'], true), |
|
| 145 | - "{$ee_cron} args" |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * reschedule_cron_for_transactions_if_maintenance_mode |
|
| 158 | - * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
| 159 | - * |
|
| 160 | - * @param string $cron_task |
|
| 161 | - * @param array $TXN_IDs |
|
| 162 | - * @return bool |
|
| 163 | - * @throws DomainException |
|
| 164 | - */ |
|
| 165 | - public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) |
|
| 166 | - { |
|
| 167 | - if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 168 | - throw new DomainException( |
|
| 169 | - sprintf( |
|
| 170 | - __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
| 171 | - $cron_task |
|
| 172 | - ) |
|
| 173 | - ); |
|
| 174 | - } |
|
| 175 | - // reschedule the cron if we can't hit the db right now |
|
| 176 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 177 | - foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
| 178 | - // ensure $additional_vars is an array |
|
| 179 | - $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
| 180 | - // reset cron job for the TXN |
|
| 181 | - call_user_func_array( |
|
| 182 | - array('EE_Cron_Tasks', $cron_task), |
|
| 183 | - array_merge( |
|
| 184 | - array( |
|
| 185 | - time() + (10 * MINUTE_IN_SECONDS), |
|
| 186 | - $TXN_ID, |
|
| 187 | - ), |
|
| 188 | - $additional_vars |
|
| 189 | - ) |
|
| 190 | - ); |
|
| 191 | - } |
|
| 192 | - return true; |
|
| 193 | - } |
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * array of TXN IDs and the payment |
|
| 206 | - * |
|
| 207 | - * @var array |
|
| 208 | - */ |
|
| 209 | - protected static $_update_transactions_with_payment = array(); |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * schedule_update_transaction_with_payment |
|
| 214 | - * sets a wp_schedule_single_event() for updating any TXNs that may |
|
| 215 | - * require updating due to recently received payments |
|
| 216 | - * |
|
| 217 | - * @param int $timestamp |
|
| 218 | - * @param int $TXN_ID |
|
| 219 | - * @param int $PAY_ID |
|
| 220 | - */ |
|
| 221 | - public static function schedule_update_transaction_with_payment( |
|
| 222 | - $timestamp, |
|
| 223 | - $TXN_ID, |
|
| 224 | - $PAY_ID |
|
| 225 | - ) { |
|
| 226 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 227 | - // validate $TXN_ID and $timestamp |
|
| 228 | - $TXN_ID = absint($TXN_ID); |
|
| 229 | - $timestamp = absint($timestamp); |
|
| 230 | - if ($TXN_ID && $timestamp) { |
|
| 231 | - wp_schedule_single_event( |
|
| 232 | - $timestamp, |
|
| 233 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 234 | - array($TXN_ID, $PAY_ID) |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * setup_update_for_transaction_with_payment |
|
| 242 | - * this is the callback for the action hook: |
|
| 243 | - * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
| 244 | - * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
| 245 | - * The passed TXN_ID and associated payment gets added to an array, and then |
|
| 246 | - * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
| 247 | - * 'shutdown' which will actually handle the processing of any |
|
| 248 | - * transactions requiring updating, because doing so now would be too early |
|
| 249 | - * and the required resources may not be available |
|
| 250 | - * |
|
| 251 | - * @param int $TXN_ID |
|
| 252 | - * @param int $PAY_ID |
|
| 253 | - */ |
|
| 254 | - public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
|
| 255 | - { |
|
| 256 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 257 | - if (absint($TXN_ID)) { |
|
| 258 | - self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
| 259 | - add_action( |
|
| 260 | - 'shutdown', |
|
| 261 | - array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
| 262 | - 5 |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * update_transaction_with_payment |
|
| 270 | - * loops through the self::$_abandoned_transactions array |
|
| 271 | - * and attempts to finalize any TXNs that have not been completed |
|
| 272 | - * but have had their sessions expired, most likely due to a user not |
|
| 273 | - * returning from an off-site payment gateway |
|
| 274 | - * |
|
| 275 | - * @throws EE_Error |
|
| 276 | - * @throws DomainException |
|
| 277 | - * @throws InvalidDataTypeException |
|
| 278 | - * @throws InvalidInterfaceException |
|
| 279 | - * @throws InvalidArgumentException |
|
| 280 | - * @throws ReflectionException |
|
| 281 | - * @throws RuntimeException |
|
| 282 | - */ |
|
| 283 | - public static function update_transaction_with_payment() |
|
| 284 | - { |
|
| 285 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 286 | - if ( |
|
| 287 | - // are there any TXNs that need cleaning up ? |
|
| 288 | - empty(self::$_update_transactions_with_payment) |
|
| 289 | - // reschedule the cron if we can't hit the db right now |
|
| 290 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 291 | - 'schedule_update_transaction_with_payment', |
|
| 292 | - self::$_update_transactions_with_payment |
|
| 293 | - ) |
|
| 294 | - ) { |
|
| 295 | - return; |
|
| 296 | - } |
|
| 297 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 298 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 299 | - // set revisit flag for payment processor |
|
| 300 | - $payment_processor->set_revisit(); |
|
| 301 | - // load EEM_Transaction |
|
| 302 | - EE_Registry::instance()->load_model('Transaction'); |
|
| 303 | - foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
| 304 | - // reschedule the cron if we can't hit the db right now |
|
| 305 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 306 | - // reset cron job for updating the TXN |
|
| 307 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
| 308 | - time() + EE_Cron_Tasks::reschedule_timeout, |
|
| 309 | - $TXN_ID, |
|
| 310 | - $PAY_ID |
|
| 311 | - ); |
|
| 312 | - continue; |
|
| 313 | - } |
|
| 314 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 315 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 316 | - // verify transaction |
|
| 317 | - if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
| 318 | - // now try to update the TXN with any payments |
|
| 319 | - $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
| 320 | - } |
|
| 321 | - unset(self::$_update_transactions_with_payment[ $TXN_ID ]); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - /***************** EXPIRED TRANSACTION CHECK *****************/ |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * array of TXN IDs |
|
| 337 | - * |
|
| 338 | - * @var array |
|
| 339 | - */ |
|
| 340 | - protected static $_expired_transactions = array(); |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * schedule_expired_transaction_check |
|
| 346 | - * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
| 347 | - * |
|
| 348 | - * @param int $timestamp |
|
| 349 | - * @param int $TXN_ID |
|
| 350 | - */ |
|
| 351 | - public static function schedule_expired_transaction_check( |
|
| 352 | - $timestamp, |
|
| 353 | - $TXN_ID |
|
| 354 | - ) { |
|
| 355 | - // validate $TXN_ID and $timestamp |
|
| 356 | - $TXN_ID = absint($TXN_ID); |
|
| 357 | - $timestamp = absint($timestamp); |
|
| 358 | - if ($TXN_ID && $timestamp) { |
|
| 359 | - wp_schedule_single_event( |
|
| 360 | - $timestamp, |
|
| 361 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 362 | - array($TXN_ID) |
|
| 363 | - ); |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * expired_transaction_check |
|
| 371 | - * this is the callback for the action hook: |
|
| 372 | - * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
| 373 | - * which is utilized by wp_schedule_single_event() |
|
| 374 | - * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
| 375 | - * The passed TXN_ID gets added to an array, and then the |
|
| 376 | - * process_expired_transactions() function is hooked into |
|
| 377 | - * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
| 378 | - * processing of any failed transactions, because doing so now would be |
|
| 379 | - * too early and the required resources may not be available |
|
| 380 | - * |
|
| 381 | - * @param int $TXN_ID |
|
| 382 | - */ |
|
| 383 | - public static function expired_transaction_check($TXN_ID = 0) |
|
| 384 | - { |
|
| 385 | - if (absint($TXN_ID)) { |
|
| 386 | - self::$_expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
| 387 | - add_action( |
|
| 388 | - 'shutdown', |
|
| 389 | - array('EE_Cron_Tasks', 'process_expired_transactions'), |
|
| 390 | - 5 |
|
| 391 | - ); |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * process_expired_transactions |
|
| 399 | - * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
| 400 | - * |
|
| 401 | - * @throws EE_Error |
|
| 402 | - * @throws InvalidDataTypeException |
|
| 403 | - * @throws InvalidInterfaceException |
|
| 404 | - * @throws InvalidArgumentException |
|
| 405 | - * @throws ReflectionException |
|
| 406 | - * @throws DomainException |
|
| 407 | - * @throws RuntimeException |
|
| 408 | - */ |
|
| 409 | - public static function process_expired_transactions() |
|
| 410 | - { |
|
| 411 | - if ( |
|
| 412 | - // are there any TXNs that need cleaning up ? |
|
| 413 | - empty(self::$_expired_transactions) |
|
| 414 | - // reschedule the cron if we can't hit the db right now |
|
| 415 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 416 | - 'schedule_expired_transaction_check', |
|
| 417 | - self::$_expired_transactions |
|
| 418 | - ) |
|
| 419 | - ) { |
|
| 420 | - return; |
|
| 421 | - } |
|
| 422 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 423 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 424 | - // set revisit flag for txn processor |
|
| 425 | - $transaction_processor->set_revisit(); |
|
| 426 | - // load EEM_Transaction |
|
| 427 | - EE_Registry::instance()->load_model('Transaction'); |
|
| 428 | - foreach (self::$_expired_transactions as $TXN_ID) { |
|
| 429 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 430 | - // verify transaction and whether it is failed or not |
|
| 431 | - if ($transaction instanceof EE_Transaction) { |
|
| 432 | - switch ($transaction->status_ID()) { |
|
| 433 | - // Completed TXNs |
|
| 434 | - case EEM_Transaction::complete_status_code : |
|
| 435 | - do_action( |
|
| 436 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
| 437 | - $transaction |
|
| 438 | - ); |
|
| 439 | - break; |
|
| 440 | - // Overpaid TXNs |
|
| 441 | - case EEM_Transaction::overpaid_status_code : |
|
| 442 | - do_action( |
|
| 443 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
| 444 | - $transaction |
|
| 445 | - ); |
|
| 446 | - break; |
|
| 447 | - // Incomplete TXNs |
|
| 448 | - case EEM_Transaction::incomplete_status_code : |
|
| 449 | - do_action( |
|
| 450 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 451 | - $transaction |
|
| 452 | - ); |
|
| 453 | - // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
| 454 | - break; |
|
| 455 | - // Abandoned TXNs |
|
| 456 | - case EEM_Transaction::abandoned_status_code : |
|
| 457 | - // run hook before updating transaction, primarily so |
|
| 458 | - // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
| 459 | - do_action( |
|
| 460 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 461 | - $transaction |
|
| 462 | - ); |
|
| 463 | - // don't finalize the TXN if it has already been completed |
|
| 464 | - if ($transaction->all_reg_steps_completed() !== true) { |
|
| 465 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 466 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 467 | - // let's simulate an IPN here which will trigger any notifications that need to go out |
|
| 468 | - $payment_processor->update_txn_based_on_payment( |
|
| 469 | - $transaction, |
|
| 470 | - $transaction->last_payment(), |
|
| 471 | - true, |
|
| 472 | - true |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - break; |
|
| 476 | - // Failed TXNs |
|
| 477 | - case EEM_Transaction::failed_status_code : |
|
| 478 | - do_action( |
|
| 479 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 480 | - $transaction |
|
| 481 | - ); |
|
| 482 | - // todo : perform garbage collection here and remove clean_out_junk_transactions() |
|
| 483 | - //$registrations = $transaction->registrations(); |
|
| 484 | - //if ( ! empty( $registrations ) ) { |
|
| 485 | - // foreach ( $registrations as $registration ) { |
|
| 486 | - // if ( $registration instanceof EE_Registration ) { |
|
| 487 | - //$delete_registration = true; |
|
| 488 | - //if ( $registration->attendee() instanceof EE_Attendee ) { |
|
| 489 | - // $delete_registration = false; |
|
| 490 | - //} |
|
| 491 | - //if ( $delete_registration ) { |
|
| 492 | - // $registration->delete_permanently(); |
|
| 493 | - // $registration->delete_related_permanently(); |
|
| 494 | - //} |
|
| 495 | - // } |
|
| 496 | - // } |
|
| 497 | - //} |
|
| 498 | - break; |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - unset(self::$_expired_transactions[ $TXN_ID ]); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /************* END OF EXPIRED TRANSACTION CHECK *************/ |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' |
|
| 517 | - * which is setup during activation to run on an hourly cron |
|
| 518 | - * |
|
| 519 | - * @throws EE_Error |
|
| 520 | - * @throws InvalidArgumentException |
|
| 521 | - * @throws InvalidDataTypeException |
|
| 522 | - * @throws InvalidInterfaceException |
|
| 523 | - * @throws DomainException |
|
| 524 | - */ |
|
| 525 | - public static function clean_out_junk_transactions() |
|
| 526 | - { |
|
| 527 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 528 | - EED_Ticket_Sales_Monitor::reset_reservation_counts(); |
|
| 529 | - EEM_Transaction::instance('')->delete_junk_transactions(); |
|
| 530 | - EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
|
| 531 | - EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
| 539 | - * |
|
| 540 | - * @throws EE_Error |
|
| 541 | - * @throws InvalidDataTypeException |
|
| 542 | - * @throws InvalidInterfaceException |
|
| 543 | - * @throws InvalidArgumentException |
|
| 544 | - */ |
|
| 545 | - public static function clean_out_old_gateway_logs() |
|
| 546 | - { |
|
| 547 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 548 | - $time_diff_for_comparison = apply_filters( |
|
| 549 | - 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
| 550 | - '-1 week' |
|
| 551 | - ); |
|
| 552 | - EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * @var array |
|
| 563 | - */ |
|
| 564 | - protected static $_abandoned_transactions = array(); |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * @deprecated |
|
| 569 | - * @param int $timestamp |
|
| 570 | - * @param int $TXN_ID |
|
| 571 | - */ |
|
| 572 | - public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID) |
|
| 573 | - { |
|
| 574 | - EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * @deprecated |
|
| 580 | - * @param int $TXN_ID |
|
| 581 | - */ |
|
| 582 | - public static function check_for_abandoned_transactions($TXN_ID = 0) |
|
| 583 | - { |
|
| 584 | - EE_Cron_Tasks::expired_transaction_check($TXN_ID); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * @deprecated |
|
| 590 | - * @throws EE_Error |
|
| 591 | - * @throws DomainException |
|
| 592 | - * @throws InvalidDataTypeException |
|
| 593 | - * @throws InvalidInterfaceException |
|
| 594 | - * @throws InvalidArgumentException |
|
| 595 | - * @throws ReflectionException |
|
| 596 | - * @throws RuntimeException |
|
| 597 | - */ |
|
| 598 | - public static function finalize_abandoned_transactions() |
|
| 599 | - { |
|
| 600 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 601 | - if ( |
|
| 602 | - // are there any TXNs that need cleaning up ? |
|
| 603 | - empty(self::$_abandoned_transactions) |
|
| 604 | - // reschedule the cron if we can't hit the db right now |
|
| 605 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 606 | - 'schedule_expired_transaction_check', |
|
| 607 | - self::$_abandoned_transactions |
|
| 608 | - ) |
|
| 609 | - ) { |
|
| 610 | - return; |
|
| 611 | - } |
|
| 612 | - // combine our arrays of transaction IDs |
|
| 613 | - self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions; |
|
| 614 | - // and deal with abandoned transactions here now... |
|
| 615 | - EE_Cron_Tasks::process_expired_transactions(); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
| 20 | + /** |
|
| 21 | + * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
| 22 | + * so we'll set our retry time for just over 10 minutes to avoid that |
|
| 23 | + */ |
|
| 24 | + const reschedule_timeout = 605; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var EE_Cron_Tasks |
|
| 29 | + */ |
|
| 30 | + private static $_instance; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @return EE_Cron_Tasks |
|
| 35 | + * @throws ReflectionException |
|
| 36 | + * @throws EE_Error |
|
| 37 | + * @throws InvalidArgumentException |
|
| 38 | + * @throws InvalidInterfaceException |
|
| 39 | + * @throws InvalidDataTypeException |
|
| 40 | + */ |
|
| 41 | + public static function instance() |
|
| 42 | + { |
|
| 43 | + if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
| 44 | + self::$_instance = new self(); |
|
| 45 | + } |
|
| 46 | + return self::$_instance; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @access private |
|
| 52 | + * @throws InvalidDataTypeException |
|
| 53 | + * @throws InvalidInterfaceException |
|
| 54 | + * @throws InvalidArgumentException |
|
| 55 | + * @throws EE_Error |
|
| 56 | + * @throws ReflectionException |
|
| 57 | + */ |
|
| 58 | + private function __construct() |
|
| 59 | + { |
|
| 60 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 61 | + // verify that WP Cron is enabled |
|
| 62 | + if ( |
|
| 63 | + defined('DISABLE_WP_CRON') |
|
| 64 | + && DISABLE_WP_CRON |
|
| 65 | + && is_admin() |
|
| 66 | + && ! get_option('ee_disabled_wp_cron_check') |
|
| 67 | + ) { |
|
| 68 | + /** |
|
| 69 | + * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
| 70 | + * config is loaded. |
|
| 71 | + * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
| 72 | + * wanting to not have this functionality can just register its own action at a priority after this one to |
|
| 73 | + * reverse any changes. |
|
| 74 | + */ |
|
| 75 | + add_action( |
|
| 76 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
| 77 | + function () |
|
| 78 | + { |
|
| 79 | + EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
| 80 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 81 | + add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
| 82 | + } |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + // UPDATE TRANSACTION WITH PAYMENT |
|
| 86 | + add_action( |
|
| 87 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 88 | + array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
| 89 | + 10, |
|
| 90 | + 2 |
|
| 91 | + ); |
|
| 92 | + // ABANDONED / EXPIRED TRANSACTION CHECK |
|
| 93 | + add_action( |
|
| 94 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 95 | + array('EE_Cron_Tasks', 'expired_transaction_check'), |
|
| 96 | + 10, |
|
| 97 | + 1 |
|
| 98 | + ); |
|
| 99 | + // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
| 100 | + add_action( |
|
| 101 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 102 | + array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
| 103 | + ); |
|
| 104 | + // logging |
|
| 105 | + add_action( |
|
| 106 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
| 107 | + array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
| 108 | + ); |
|
| 109 | + EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
| 110 | + //clean out old gateway logs |
|
| 111 | + add_action( |
|
| 112 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
| 113 | + array('EE_Cron_Tasks', 'clean_out_old_gateway_logs') |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @access protected |
|
| 120 | + * @return void |
|
| 121 | + */ |
|
| 122 | + public static function log_scheduled_ee_crons() |
|
| 123 | + { |
|
| 124 | + $ee_crons = array( |
|
| 125 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
| 126 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 127 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 128 | + ); |
|
| 129 | + $crons = (array) get_option('cron'); |
|
| 130 | + if (! is_array($crons)) { |
|
| 131 | + return; |
|
| 132 | + } |
|
| 133 | + foreach ($crons as $timestamp => $cron) { |
|
| 134 | + /** @var array[] $cron */ |
|
| 135 | + foreach ($ee_crons as $ee_cron) { |
|
| 136 | + if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
| 137 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
| 138 | + foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
| 139 | + if (! empty($ee_cron_details['args'])) { |
|
| 140 | + do_action( |
|
| 141 | + 'AHEE_log', |
|
| 142 | + __CLASS__, |
|
| 143 | + __FUNCTION__, |
|
| 144 | + print_r($ee_cron_details['args'], true), |
|
| 145 | + "{$ee_cron} args" |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * reschedule_cron_for_transactions_if_maintenance_mode |
|
| 158 | + * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
| 159 | + * |
|
| 160 | + * @param string $cron_task |
|
| 161 | + * @param array $TXN_IDs |
|
| 162 | + * @return bool |
|
| 163 | + * @throws DomainException |
|
| 164 | + */ |
|
| 165 | + public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) |
|
| 166 | + { |
|
| 167 | + if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 168 | + throw new DomainException( |
|
| 169 | + sprintf( |
|
| 170 | + __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
| 171 | + $cron_task |
|
| 172 | + ) |
|
| 173 | + ); |
|
| 174 | + } |
|
| 175 | + // reschedule the cron if we can't hit the db right now |
|
| 176 | + if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 177 | + foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
| 178 | + // ensure $additional_vars is an array |
|
| 179 | + $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
| 180 | + // reset cron job for the TXN |
|
| 181 | + call_user_func_array( |
|
| 182 | + array('EE_Cron_Tasks', $cron_task), |
|
| 183 | + array_merge( |
|
| 184 | + array( |
|
| 185 | + time() + (10 * MINUTE_IN_SECONDS), |
|
| 186 | + $TXN_ID, |
|
| 187 | + ), |
|
| 188 | + $additional_vars |
|
| 189 | + ) |
|
| 190 | + ); |
|
| 191 | + } |
|
| 192 | + return true; |
|
| 193 | + } |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * array of TXN IDs and the payment |
|
| 206 | + * |
|
| 207 | + * @var array |
|
| 208 | + */ |
|
| 209 | + protected static $_update_transactions_with_payment = array(); |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * schedule_update_transaction_with_payment |
|
| 214 | + * sets a wp_schedule_single_event() for updating any TXNs that may |
|
| 215 | + * require updating due to recently received payments |
|
| 216 | + * |
|
| 217 | + * @param int $timestamp |
|
| 218 | + * @param int $TXN_ID |
|
| 219 | + * @param int $PAY_ID |
|
| 220 | + */ |
|
| 221 | + public static function schedule_update_transaction_with_payment( |
|
| 222 | + $timestamp, |
|
| 223 | + $TXN_ID, |
|
| 224 | + $PAY_ID |
|
| 225 | + ) { |
|
| 226 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 227 | + // validate $TXN_ID and $timestamp |
|
| 228 | + $TXN_ID = absint($TXN_ID); |
|
| 229 | + $timestamp = absint($timestamp); |
|
| 230 | + if ($TXN_ID && $timestamp) { |
|
| 231 | + wp_schedule_single_event( |
|
| 232 | + $timestamp, |
|
| 233 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 234 | + array($TXN_ID, $PAY_ID) |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * setup_update_for_transaction_with_payment |
|
| 242 | + * this is the callback for the action hook: |
|
| 243 | + * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
| 244 | + * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
| 245 | + * The passed TXN_ID and associated payment gets added to an array, and then |
|
| 246 | + * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
| 247 | + * 'shutdown' which will actually handle the processing of any |
|
| 248 | + * transactions requiring updating, because doing so now would be too early |
|
| 249 | + * and the required resources may not be available |
|
| 250 | + * |
|
| 251 | + * @param int $TXN_ID |
|
| 252 | + * @param int $PAY_ID |
|
| 253 | + */ |
|
| 254 | + public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
|
| 255 | + { |
|
| 256 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 257 | + if (absint($TXN_ID)) { |
|
| 258 | + self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
| 259 | + add_action( |
|
| 260 | + 'shutdown', |
|
| 261 | + array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
| 262 | + 5 |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * update_transaction_with_payment |
|
| 270 | + * loops through the self::$_abandoned_transactions array |
|
| 271 | + * and attempts to finalize any TXNs that have not been completed |
|
| 272 | + * but have had their sessions expired, most likely due to a user not |
|
| 273 | + * returning from an off-site payment gateway |
|
| 274 | + * |
|
| 275 | + * @throws EE_Error |
|
| 276 | + * @throws DomainException |
|
| 277 | + * @throws InvalidDataTypeException |
|
| 278 | + * @throws InvalidInterfaceException |
|
| 279 | + * @throws InvalidArgumentException |
|
| 280 | + * @throws ReflectionException |
|
| 281 | + * @throws RuntimeException |
|
| 282 | + */ |
|
| 283 | + public static function update_transaction_with_payment() |
|
| 284 | + { |
|
| 285 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 286 | + if ( |
|
| 287 | + // are there any TXNs that need cleaning up ? |
|
| 288 | + empty(self::$_update_transactions_with_payment) |
|
| 289 | + // reschedule the cron if we can't hit the db right now |
|
| 290 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 291 | + 'schedule_update_transaction_with_payment', |
|
| 292 | + self::$_update_transactions_with_payment |
|
| 293 | + ) |
|
| 294 | + ) { |
|
| 295 | + return; |
|
| 296 | + } |
|
| 297 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 298 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 299 | + // set revisit flag for payment processor |
|
| 300 | + $payment_processor->set_revisit(); |
|
| 301 | + // load EEM_Transaction |
|
| 302 | + EE_Registry::instance()->load_model('Transaction'); |
|
| 303 | + foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
| 304 | + // reschedule the cron if we can't hit the db right now |
|
| 305 | + if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 306 | + // reset cron job for updating the TXN |
|
| 307 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
| 308 | + time() + EE_Cron_Tasks::reschedule_timeout, |
|
| 309 | + $TXN_ID, |
|
| 310 | + $PAY_ID |
|
| 311 | + ); |
|
| 312 | + continue; |
|
| 313 | + } |
|
| 314 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 315 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 316 | + // verify transaction |
|
| 317 | + if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
| 318 | + // now try to update the TXN with any payments |
|
| 319 | + $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
| 320 | + } |
|
| 321 | + unset(self::$_update_transactions_with_payment[ $TXN_ID ]); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + /***************** EXPIRED TRANSACTION CHECK *****************/ |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * array of TXN IDs |
|
| 337 | + * |
|
| 338 | + * @var array |
|
| 339 | + */ |
|
| 340 | + protected static $_expired_transactions = array(); |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * schedule_expired_transaction_check |
|
| 346 | + * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
| 347 | + * |
|
| 348 | + * @param int $timestamp |
|
| 349 | + * @param int $TXN_ID |
|
| 350 | + */ |
|
| 351 | + public static function schedule_expired_transaction_check( |
|
| 352 | + $timestamp, |
|
| 353 | + $TXN_ID |
|
| 354 | + ) { |
|
| 355 | + // validate $TXN_ID and $timestamp |
|
| 356 | + $TXN_ID = absint($TXN_ID); |
|
| 357 | + $timestamp = absint($timestamp); |
|
| 358 | + if ($TXN_ID && $timestamp) { |
|
| 359 | + wp_schedule_single_event( |
|
| 360 | + $timestamp, |
|
| 361 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 362 | + array($TXN_ID) |
|
| 363 | + ); |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * expired_transaction_check |
|
| 371 | + * this is the callback for the action hook: |
|
| 372 | + * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
| 373 | + * which is utilized by wp_schedule_single_event() |
|
| 374 | + * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
| 375 | + * The passed TXN_ID gets added to an array, and then the |
|
| 376 | + * process_expired_transactions() function is hooked into |
|
| 377 | + * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
| 378 | + * processing of any failed transactions, because doing so now would be |
|
| 379 | + * too early and the required resources may not be available |
|
| 380 | + * |
|
| 381 | + * @param int $TXN_ID |
|
| 382 | + */ |
|
| 383 | + public static function expired_transaction_check($TXN_ID = 0) |
|
| 384 | + { |
|
| 385 | + if (absint($TXN_ID)) { |
|
| 386 | + self::$_expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
| 387 | + add_action( |
|
| 388 | + 'shutdown', |
|
| 389 | + array('EE_Cron_Tasks', 'process_expired_transactions'), |
|
| 390 | + 5 |
|
| 391 | + ); |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * process_expired_transactions |
|
| 399 | + * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
| 400 | + * |
|
| 401 | + * @throws EE_Error |
|
| 402 | + * @throws InvalidDataTypeException |
|
| 403 | + * @throws InvalidInterfaceException |
|
| 404 | + * @throws InvalidArgumentException |
|
| 405 | + * @throws ReflectionException |
|
| 406 | + * @throws DomainException |
|
| 407 | + * @throws RuntimeException |
|
| 408 | + */ |
|
| 409 | + public static function process_expired_transactions() |
|
| 410 | + { |
|
| 411 | + if ( |
|
| 412 | + // are there any TXNs that need cleaning up ? |
|
| 413 | + empty(self::$_expired_transactions) |
|
| 414 | + // reschedule the cron if we can't hit the db right now |
|
| 415 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 416 | + 'schedule_expired_transaction_check', |
|
| 417 | + self::$_expired_transactions |
|
| 418 | + ) |
|
| 419 | + ) { |
|
| 420 | + return; |
|
| 421 | + } |
|
| 422 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 423 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 424 | + // set revisit flag for txn processor |
|
| 425 | + $transaction_processor->set_revisit(); |
|
| 426 | + // load EEM_Transaction |
|
| 427 | + EE_Registry::instance()->load_model('Transaction'); |
|
| 428 | + foreach (self::$_expired_transactions as $TXN_ID) { |
|
| 429 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 430 | + // verify transaction and whether it is failed or not |
|
| 431 | + if ($transaction instanceof EE_Transaction) { |
|
| 432 | + switch ($transaction->status_ID()) { |
|
| 433 | + // Completed TXNs |
|
| 434 | + case EEM_Transaction::complete_status_code : |
|
| 435 | + do_action( |
|
| 436 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
| 437 | + $transaction |
|
| 438 | + ); |
|
| 439 | + break; |
|
| 440 | + // Overpaid TXNs |
|
| 441 | + case EEM_Transaction::overpaid_status_code : |
|
| 442 | + do_action( |
|
| 443 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
| 444 | + $transaction |
|
| 445 | + ); |
|
| 446 | + break; |
|
| 447 | + // Incomplete TXNs |
|
| 448 | + case EEM_Transaction::incomplete_status_code : |
|
| 449 | + do_action( |
|
| 450 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 451 | + $transaction |
|
| 452 | + ); |
|
| 453 | + // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
| 454 | + break; |
|
| 455 | + // Abandoned TXNs |
|
| 456 | + case EEM_Transaction::abandoned_status_code : |
|
| 457 | + // run hook before updating transaction, primarily so |
|
| 458 | + // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
| 459 | + do_action( |
|
| 460 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 461 | + $transaction |
|
| 462 | + ); |
|
| 463 | + // don't finalize the TXN if it has already been completed |
|
| 464 | + if ($transaction->all_reg_steps_completed() !== true) { |
|
| 465 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 466 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 467 | + // let's simulate an IPN here which will trigger any notifications that need to go out |
|
| 468 | + $payment_processor->update_txn_based_on_payment( |
|
| 469 | + $transaction, |
|
| 470 | + $transaction->last_payment(), |
|
| 471 | + true, |
|
| 472 | + true |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + break; |
|
| 476 | + // Failed TXNs |
|
| 477 | + case EEM_Transaction::failed_status_code : |
|
| 478 | + do_action( |
|
| 479 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 480 | + $transaction |
|
| 481 | + ); |
|
| 482 | + // todo : perform garbage collection here and remove clean_out_junk_transactions() |
|
| 483 | + //$registrations = $transaction->registrations(); |
|
| 484 | + //if ( ! empty( $registrations ) ) { |
|
| 485 | + // foreach ( $registrations as $registration ) { |
|
| 486 | + // if ( $registration instanceof EE_Registration ) { |
|
| 487 | + //$delete_registration = true; |
|
| 488 | + //if ( $registration->attendee() instanceof EE_Attendee ) { |
|
| 489 | + // $delete_registration = false; |
|
| 490 | + //} |
|
| 491 | + //if ( $delete_registration ) { |
|
| 492 | + // $registration->delete_permanently(); |
|
| 493 | + // $registration->delete_related_permanently(); |
|
| 494 | + //} |
|
| 495 | + // } |
|
| 496 | + // } |
|
| 497 | + //} |
|
| 498 | + break; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + unset(self::$_expired_transactions[ $TXN_ID ]); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /************* END OF EXPIRED TRANSACTION CHECK *************/ |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' |
|
| 517 | + * which is setup during activation to run on an hourly cron |
|
| 518 | + * |
|
| 519 | + * @throws EE_Error |
|
| 520 | + * @throws InvalidArgumentException |
|
| 521 | + * @throws InvalidDataTypeException |
|
| 522 | + * @throws InvalidInterfaceException |
|
| 523 | + * @throws DomainException |
|
| 524 | + */ |
|
| 525 | + public static function clean_out_junk_transactions() |
|
| 526 | + { |
|
| 527 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 528 | + EED_Ticket_Sales_Monitor::reset_reservation_counts(); |
|
| 529 | + EEM_Transaction::instance('')->delete_junk_transactions(); |
|
| 530 | + EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
|
| 531 | + EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
| 539 | + * |
|
| 540 | + * @throws EE_Error |
|
| 541 | + * @throws InvalidDataTypeException |
|
| 542 | + * @throws InvalidInterfaceException |
|
| 543 | + * @throws InvalidArgumentException |
|
| 544 | + */ |
|
| 545 | + public static function clean_out_old_gateway_logs() |
|
| 546 | + { |
|
| 547 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 548 | + $time_diff_for_comparison = apply_filters( |
|
| 549 | + 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
| 550 | + '-1 week' |
|
| 551 | + ); |
|
| 552 | + EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * @var array |
|
| 563 | + */ |
|
| 564 | + protected static $_abandoned_transactions = array(); |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * @deprecated |
|
| 569 | + * @param int $timestamp |
|
| 570 | + * @param int $TXN_ID |
|
| 571 | + */ |
|
| 572 | + public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID) |
|
| 573 | + { |
|
| 574 | + EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * @deprecated |
|
| 580 | + * @param int $TXN_ID |
|
| 581 | + */ |
|
| 582 | + public static function check_for_abandoned_transactions($TXN_ID = 0) |
|
| 583 | + { |
|
| 584 | + EE_Cron_Tasks::expired_transaction_check($TXN_ID); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * @deprecated |
|
| 590 | + * @throws EE_Error |
|
| 591 | + * @throws DomainException |
|
| 592 | + * @throws InvalidDataTypeException |
|
| 593 | + * @throws InvalidInterfaceException |
|
| 594 | + * @throws InvalidArgumentException |
|
| 595 | + * @throws ReflectionException |
|
| 596 | + * @throws RuntimeException |
|
| 597 | + */ |
|
| 598 | + public static function finalize_abandoned_transactions() |
|
| 599 | + { |
|
| 600 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 601 | + if ( |
|
| 602 | + // are there any TXNs that need cleaning up ? |
|
| 603 | + empty(self::$_abandoned_transactions) |
|
| 604 | + // reschedule the cron if we can't hit the db right now |
|
| 605 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 606 | + 'schedule_expired_transaction_check', |
|
| 607 | + self::$_abandoned_transactions |
|
| 608 | + ) |
|
| 609 | + ) { |
|
| 610 | + return; |
|
| 611 | + } |
|
| 612 | + // combine our arrays of transaction IDs |
|
| 613 | + self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions; |
|
| 614 | + // and deal with abandoned transactions here now... |
|
| 615 | + EE_Cron_Tasks::process_expired_transactions(); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
| 621 | 621 | } |
| 622 | 622 | // End of file EE_Cron_Tasks.core.php |
| 623 | 623 | // Location: /EE_Cron_Tasks.core.php |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public static function instance() |
| 42 | 42 | { |
| 43 | - if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
| 43 | + if ( ! self::$_instance instanceof EE_Cron_Tasks) { |
|
| 44 | 44 | self::$_instance = new self(); |
| 45 | 45 | } |
| 46 | 46 | return self::$_instance; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | add_action( |
| 76 | 76 | 'AHEE__EE_System__load_core_configuration__complete', |
| 77 | - function () |
|
| 77 | + function() |
|
| 78 | 78 | { |
| 79 | 79 | EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
| 80 | 80 | EE_Registry::instance()->NET_CFG->update_config(true, false); |
@@ -126,17 +126,17 @@ discard block |
||
| 126 | 126 | 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
| 127 | 127 | 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
| 128 | 128 | ); |
| 129 | - $crons = (array) get_option('cron'); |
|
| 130 | - if (! is_array($crons)) { |
|
| 129 | + $crons = (array) get_option('cron'); |
|
| 130 | + if ( ! is_array($crons)) { |
|
| 131 | 131 | return; |
| 132 | 132 | } |
| 133 | 133 | foreach ($crons as $timestamp => $cron) { |
| 134 | 134 | /** @var array[] $cron */ |
| 135 | 135 | foreach ($ee_crons as $ee_cron) { |
| 136 | - if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
| 136 | + if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) { |
|
| 137 | 137 | do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
| 138 | - foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
| 139 | - if (! empty($ee_cron_details['args'])) { |
|
| 138 | + foreach ($cron[$ee_cron] as $ee_cron_details) { |
|
| 139 | + if ( ! empty($ee_cron_details['args'])) { |
|
| 140 | 140 | do_action( |
| 141 | 141 | 'AHEE_log', |
| 142 | 142 | __CLASS__, |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) |
| 166 | 166 | { |
| 167 | - if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 167 | + if ( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 168 | 168 | throw new DomainException( |
| 169 | 169 | sprintf( |
| 170 | 170 | __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | ); |
| 174 | 174 | } |
| 175 | 175 | // reschedule the cron if we can't hit the db right now |
| 176 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 176 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 177 | 177 | foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
| 178 | 178 | // ensure $additional_vars is an array |
| 179 | 179 | $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | { |
| 256 | 256 | do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
| 257 | 257 | if (absint($TXN_ID)) { |
| 258 | - self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
| 258 | + self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID; |
|
| 259 | 259 | add_action( |
| 260 | 260 | 'shutdown', |
| 261 | 261 | array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | EE_Registry::instance()->load_model('Transaction'); |
| 303 | 303 | foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
| 304 | 304 | // reschedule the cron if we can't hit the db right now |
| 305 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 305 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 306 | 306 | // reset cron job for updating the TXN |
| 307 | 307 | EE_Cron_Tasks::schedule_update_transaction_with_payment( |
| 308 | 308 | time() + EE_Cron_Tasks::reschedule_timeout, |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | // now try to update the TXN with any payments |
| 319 | 319 | $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
| 320 | 320 | } |
| 321 | - unset(self::$_update_transactions_with_payment[ $TXN_ID ]); |
|
| 321 | + unset(self::$_update_transactions_with_payment[$TXN_ID]); |
|
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | 324 | |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | public static function expired_transaction_check($TXN_ID = 0) |
| 384 | 384 | { |
| 385 | 385 | if (absint($TXN_ID)) { |
| 386 | - self::$_expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
| 386 | + self::$_expired_transactions[$TXN_ID] = $TXN_ID; |
|
| 387 | 387 | add_action( |
| 388 | 388 | 'shutdown', |
| 389 | 389 | array('EE_Cron_Tasks', 'process_expired_transactions'), |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | break; |
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | - unset(self::$_expired_transactions[ $TXN_ID ]); |
|
| 501 | + unset(self::$_expired_transactions[$TXN_ID]); |
|
| 502 | 502 | } |
| 503 | 503 | } |
| 504 | 504 | |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 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 | require_once(EE_MODELS . 'EEM_Base.model.php'); |
| 10 | 10 | |
@@ -20,193 +20,193 @@ discard block |
||
| 20 | 20 | class EEM_Transaction extends EEM_Base |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - // private instance of the Transaction object |
|
| 24 | - protected static $_instance; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
| 28 | - * but payment is pending. This is the state for transactions where payment is promised |
|
| 29 | - * from an offline gateway. |
|
| 30 | - */ |
|
| 31 | - // const open_status_code = 'TPN'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
| 35 | - * either due to a technical reason (server or computer crash during registration), |
|
| 36 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
| 37 | - */ |
|
| 38 | - const failed_status_code = 'TFL'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
| 42 | - * either due to a technical reason (server or computer crash during registration), |
|
| 43 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
| 44 | - * HOWEVER... |
|
| 45 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
| 46 | - * registrant |
|
| 47 | - */ |
|
| 48 | - const abandoned_status_code = 'TAB'; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
| 52 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
| 53 | - */ |
|
| 54 | - const incomplete_status_code = 'TIN'; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
| 58 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
| 59 | - */ |
|
| 60 | - const complete_status_code = 'TCM'; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
| 64 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
| 65 | - */ |
|
| 66 | - const overpaid_status_code = 'TOP'; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * private constructor to prevent direct creation |
|
| 71 | - * |
|
| 72 | - * @Constructor |
|
| 73 | - * @access protected |
|
| 74 | - * |
|
| 75 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
| 76 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
| 77 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
| 78 | - * timezone in the 'timezone_string' wp option) |
|
| 79 | - * |
|
| 80 | - * @return EEM_Transaction |
|
| 81 | - * @throws \EE_Error |
|
| 82 | - */ |
|
| 83 | - protected function __construct($timezone) |
|
| 84 | - { |
|
| 85 | - $this->singular_item = __('Transaction', 'event_espresso'); |
|
| 86 | - $this->plural_item = __('Transactions', 'event_espresso'); |
|
| 87 | - |
|
| 88 | - $this->_tables = array( |
|
| 89 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
| 90 | - ); |
|
| 91 | - $this->_fields = array( |
|
| 92 | - 'TransactionTable' => array( |
|
| 93 | - 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
| 94 | - 'TXN_timestamp' => new EE_Datetime_Field('TXN_timestamp', |
|
| 95 | - __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, |
|
| 96 | - $timezone), |
|
| 97 | - 'TXN_total' => new EE_Money_Field('TXN_total', |
|
| 98 | - __('Total value of Transaction', 'event_espresso'), false, 0), |
|
| 99 | - 'TXN_paid' => new EE_Money_Field('TXN_paid', |
|
| 100 | - __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
| 101 | - 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), |
|
| 102 | - false, EEM_Transaction::failed_status_code, 'Status'), |
|
| 103 | - 'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', |
|
| 104 | - __('Serialized session data', 'event_espresso'), true, ''), |
|
| 105 | - 'TXN_hash_salt' => new EE_Plain_Text_Field('TXN_hash_salt', |
|
| 106 | - __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
| 107 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', |
|
| 108 | - __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), |
|
| 109 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', |
|
| 110 | - __('Registration Steps', 'event_espresso'), false, array()), |
|
| 111 | - ) |
|
| 112 | - ); |
|
| 113 | - $this->_model_relations = array( |
|
| 114 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 115 | - 'Payment' => new EE_Has_Many_Relation(), |
|
| 116 | - 'Status' => new EE_Belongs_To_Relation(), |
|
| 117 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
| 118 | - //you can delete a transaction without needing to delete its line items |
|
| 119 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
| 120 | - 'Message' => new EE_Has_Many_Relation() |
|
| 121 | - ); |
|
| 122 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
| 123 | - parent::__construct($timezone); |
|
| 124 | - |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * txn_status_array |
|
| 130 | - * get list of transaction statuses |
|
| 131 | - * |
|
| 132 | - * @access public |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - public static function txn_status_array() |
|
| 136 | - { |
|
| 137 | - return apply_filters( |
|
| 138 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
| 139 | - array( |
|
| 140 | - EEM_Transaction::overpaid_status_code, |
|
| 141 | - EEM_Transaction::complete_status_code, |
|
| 142 | - EEM_Transaction::incomplete_status_code, |
|
| 143 | - EEM_Transaction::abandoned_status_code, |
|
| 144 | - EEM_Transaction::failed_status_code, |
|
| 145 | - ) |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
| 151 | - * |
|
| 152 | - * @access public |
|
| 153 | - * |
|
| 154 | - * @param string $period |
|
| 155 | - * |
|
| 156 | - * @return \stdClass[] |
|
| 157 | - */ |
|
| 158 | - public function get_revenue_per_day_report($period = '-1 month') |
|
| 159 | - { |
|
| 160 | - $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), |
|
| 161 | - 'Y-m-d H:i:s', 'UTC'); |
|
| 162 | - |
|
| 163 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
| 164 | - |
|
| 165 | - return $this->_get_all_wpdb_results( |
|
| 166 | - array( |
|
| 167 | - array( |
|
| 168 | - 'TXN_timestamp' => array('>=', $sql_date) |
|
| 169 | - ), |
|
| 170 | - 'group_by' => 'txnDate', |
|
| 171 | - 'order_by' => array('TXN_timestamp' => 'ASC') |
|
| 172 | - ), |
|
| 173 | - OBJECT, |
|
| 174 | - array( |
|
| 175 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
| 176 | - 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
| 177 | - ) |
|
| 178 | - ); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
| 184 | - * |
|
| 185 | - * @access public |
|
| 186 | - * |
|
| 187 | - * @param string $period |
|
| 188 | - * |
|
| 189 | - * @throws \EE_Error |
|
| 190 | - * @return mixed |
|
| 191 | - */ |
|
| 192 | - public function get_revenue_per_event_report($period = '-1 month') |
|
| 193 | - { |
|
| 194 | - global $wpdb; |
|
| 195 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
| 196 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
| 197 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
| 198 | - $event_table = $wpdb->posts; |
|
| 199 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
| 200 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
| 201 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
| 202 | - $extra_event_on_join = ''; |
|
| 203 | - //exclude events not authored by user if permissions in effect |
|
| 204 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
| 205 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $wpdb->get_results( |
|
| 209 | - "SELECT |
|
| 23 | + // private instance of the Transaction object |
|
| 24 | + protected static $_instance; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
| 28 | + * but payment is pending. This is the state for transactions where payment is promised |
|
| 29 | + * from an offline gateway. |
|
| 30 | + */ |
|
| 31 | + // const open_status_code = 'TPN'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
| 35 | + * either due to a technical reason (server or computer crash during registration), |
|
| 36 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
| 37 | + */ |
|
| 38 | + const failed_status_code = 'TFL'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
| 42 | + * either due to a technical reason (server or computer crash during registration), |
|
| 43 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
| 44 | + * HOWEVER... |
|
| 45 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
| 46 | + * registrant |
|
| 47 | + */ |
|
| 48 | + const abandoned_status_code = 'TAB'; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
| 52 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
| 53 | + */ |
|
| 54 | + const incomplete_status_code = 'TIN'; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
| 58 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
| 59 | + */ |
|
| 60 | + const complete_status_code = 'TCM'; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
| 64 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
| 65 | + */ |
|
| 66 | + const overpaid_status_code = 'TOP'; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * private constructor to prevent direct creation |
|
| 71 | + * |
|
| 72 | + * @Constructor |
|
| 73 | + * @access protected |
|
| 74 | + * |
|
| 75 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
| 76 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
| 77 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
| 78 | + * timezone in the 'timezone_string' wp option) |
|
| 79 | + * |
|
| 80 | + * @return EEM_Transaction |
|
| 81 | + * @throws \EE_Error |
|
| 82 | + */ |
|
| 83 | + protected function __construct($timezone) |
|
| 84 | + { |
|
| 85 | + $this->singular_item = __('Transaction', 'event_espresso'); |
|
| 86 | + $this->plural_item = __('Transactions', 'event_espresso'); |
|
| 87 | + |
|
| 88 | + $this->_tables = array( |
|
| 89 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
| 90 | + ); |
|
| 91 | + $this->_fields = array( |
|
| 92 | + 'TransactionTable' => array( |
|
| 93 | + 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
| 94 | + 'TXN_timestamp' => new EE_Datetime_Field('TXN_timestamp', |
|
| 95 | + __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, |
|
| 96 | + $timezone), |
|
| 97 | + 'TXN_total' => new EE_Money_Field('TXN_total', |
|
| 98 | + __('Total value of Transaction', 'event_espresso'), false, 0), |
|
| 99 | + 'TXN_paid' => new EE_Money_Field('TXN_paid', |
|
| 100 | + __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
| 101 | + 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), |
|
| 102 | + false, EEM_Transaction::failed_status_code, 'Status'), |
|
| 103 | + 'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', |
|
| 104 | + __('Serialized session data', 'event_espresso'), true, ''), |
|
| 105 | + 'TXN_hash_salt' => new EE_Plain_Text_Field('TXN_hash_salt', |
|
| 106 | + __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
| 107 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', |
|
| 108 | + __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), |
|
| 109 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', |
|
| 110 | + __('Registration Steps', 'event_espresso'), false, array()), |
|
| 111 | + ) |
|
| 112 | + ); |
|
| 113 | + $this->_model_relations = array( |
|
| 114 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 115 | + 'Payment' => new EE_Has_Many_Relation(), |
|
| 116 | + 'Status' => new EE_Belongs_To_Relation(), |
|
| 117 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
| 118 | + //you can delete a transaction without needing to delete its line items |
|
| 119 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
| 120 | + 'Message' => new EE_Has_Many_Relation() |
|
| 121 | + ); |
|
| 122 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
| 123 | + parent::__construct($timezone); |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * txn_status_array |
|
| 130 | + * get list of transaction statuses |
|
| 131 | + * |
|
| 132 | + * @access public |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + public static function txn_status_array() |
|
| 136 | + { |
|
| 137 | + return apply_filters( |
|
| 138 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
| 139 | + array( |
|
| 140 | + EEM_Transaction::overpaid_status_code, |
|
| 141 | + EEM_Transaction::complete_status_code, |
|
| 142 | + EEM_Transaction::incomplete_status_code, |
|
| 143 | + EEM_Transaction::abandoned_status_code, |
|
| 144 | + EEM_Transaction::failed_status_code, |
|
| 145 | + ) |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
| 151 | + * |
|
| 152 | + * @access public |
|
| 153 | + * |
|
| 154 | + * @param string $period |
|
| 155 | + * |
|
| 156 | + * @return \stdClass[] |
|
| 157 | + */ |
|
| 158 | + public function get_revenue_per_day_report($period = '-1 month') |
|
| 159 | + { |
|
| 160 | + $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), |
|
| 161 | + 'Y-m-d H:i:s', 'UTC'); |
|
| 162 | + |
|
| 163 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
| 164 | + |
|
| 165 | + return $this->_get_all_wpdb_results( |
|
| 166 | + array( |
|
| 167 | + array( |
|
| 168 | + 'TXN_timestamp' => array('>=', $sql_date) |
|
| 169 | + ), |
|
| 170 | + 'group_by' => 'txnDate', |
|
| 171 | + 'order_by' => array('TXN_timestamp' => 'ASC') |
|
| 172 | + ), |
|
| 173 | + OBJECT, |
|
| 174 | + array( |
|
| 175 | + 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
| 176 | + 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
| 177 | + ) |
|
| 178 | + ); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
| 184 | + * |
|
| 185 | + * @access public |
|
| 186 | + * |
|
| 187 | + * @param string $period |
|
| 188 | + * |
|
| 189 | + * @throws \EE_Error |
|
| 190 | + * @return mixed |
|
| 191 | + */ |
|
| 192 | + public function get_revenue_per_event_report($period = '-1 month') |
|
| 193 | + { |
|
| 194 | + global $wpdb; |
|
| 195 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
| 196 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
| 197 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
| 198 | + $event_table = $wpdb->posts; |
|
| 199 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
| 200 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
| 201 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
| 202 | + $extra_event_on_join = ''; |
|
| 203 | + //exclude events not authored by user if permissions in effect |
|
| 204 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
| 205 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $wpdb->get_results( |
|
| 209 | + "SELECT |
|
| 210 | 210 | Transaction_Event.event_name AS event_name, |
| 211 | 211 | SUM(Transaction_Event.paid) AS revenue |
| 212 | 212 | FROM |
@@ -234,223 +234,223 @@ discard block |
||
| 234 | 234 | $extra_event_on_join |
| 235 | 235 | ) AS Transaction_Event |
| 236 | 236 | GROUP BY event_name", |
| 237 | - OBJECT |
|
| 238 | - ); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
| 244 | - * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
| 245 | - * the registration pointed to by reg_url_link), if not returns null |
|
| 246 | - * |
|
| 247 | - * @param string $reg_url_link |
|
| 248 | - * |
|
| 249 | - * @return EE_Transaction |
|
| 250 | - */ |
|
| 251 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
| 252 | - { |
|
| 253 | - return $this->get_one(array( |
|
| 254 | - array( |
|
| 255 | - 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', |
|
| 256 | - '') |
|
| 257 | - ) |
|
| 258 | - )); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Updates the provided EE_Transaction with all the applicable payments |
|
| 264 | - * (or fetch the EE_Transaction from its ID) |
|
| 265 | - * |
|
| 266 | - * @deprecated |
|
| 267 | - * |
|
| 268 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
| 269 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
| 270 | - * |
|
| 271 | - * @return boolean |
|
| 272 | - * @throws \EE_Error |
|
| 273 | - */ |
|
| 274 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
| 275 | - { |
|
| 276 | - EE_Error::doing_it_wrong( |
|
| 277 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 278 | - sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 279 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
| 280 | - '4.6.0' |
|
| 281 | - ); |
|
| 282 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 283 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 284 | - |
|
| 285 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
| 286 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
| 287 | - ); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
| 292 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
| 293 | - * and so we only use wpdb directly and only do minimal joins. |
|
| 294 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
| 295 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
| 296 | - * it, it's probably not junk (regardless of what status it has). |
|
| 297 | - * The downside to this approach is that is addons are listening for object deletions |
|
| 298 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
| 299 | - * to catch these types of deletions. |
|
| 300 | - * |
|
| 301 | - * @global WPDB $wpdb |
|
| 302 | - * @return mixed |
|
| 303 | - */ |
|
| 304 | - public function delete_junk_transactions() |
|
| 305 | - { |
|
| 306 | - /** @type WPDB $wpdb */ |
|
| 307 | - global $wpdb; |
|
| 308 | - $deleted = false; |
|
| 309 | - $time_to_leave_alone = apply_filters( |
|
| 310 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' |
|
| 311 | - , WEEK_IN_SECONDS |
|
| 312 | - ); |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
| 317 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
| 318 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
| 319 | - */ |
|
| 320 | - $ids_query = apply_filters( |
|
| 321 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
| 322 | - array( |
|
| 323 | - 0 => array( |
|
| 324 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
| 325 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
| 326 | - 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
| 327 | - ) |
|
| 328 | - ), |
|
| 329 | - $time_to_leave_alone |
|
| 330 | - ); |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
| 335 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
| 336 | - */ |
|
| 337 | - $txn_ids = apply_filters( |
|
| 338 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
| 339 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
| 340 | - $time_to_leave_alone |
|
| 341 | - ); |
|
| 342 | - //now that we have the ids to delete |
|
| 343 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
| 344 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
| 345 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
| 346 | - // let's get deletin'... |
|
| 347 | - // Why no wpdb->prepare? Because the data is trusted. |
|
| 348 | - // We got the ids from the original query to get them FROM |
|
| 349 | - // the db (which is sanitized) so no need to prepare them again. |
|
| 350 | - $query = ' |
|
| 237 | + OBJECT |
|
| 238 | + ); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
| 244 | + * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
| 245 | + * the registration pointed to by reg_url_link), if not returns null |
|
| 246 | + * |
|
| 247 | + * @param string $reg_url_link |
|
| 248 | + * |
|
| 249 | + * @return EE_Transaction |
|
| 250 | + */ |
|
| 251 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
| 252 | + { |
|
| 253 | + return $this->get_one(array( |
|
| 254 | + array( |
|
| 255 | + 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', |
|
| 256 | + '') |
|
| 257 | + ) |
|
| 258 | + )); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Updates the provided EE_Transaction with all the applicable payments |
|
| 264 | + * (or fetch the EE_Transaction from its ID) |
|
| 265 | + * |
|
| 266 | + * @deprecated |
|
| 267 | + * |
|
| 268 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
| 269 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
| 270 | + * |
|
| 271 | + * @return boolean |
|
| 272 | + * @throws \EE_Error |
|
| 273 | + */ |
|
| 274 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
| 275 | + { |
|
| 276 | + EE_Error::doing_it_wrong( |
|
| 277 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 278 | + sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 279 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
| 280 | + '4.6.0' |
|
| 281 | + ); |
|
| 282 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 283 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 284 | + |
|
| 285 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
| 286 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
| 287 | + ); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
| 292 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
| 293 | + * and so we only use wpdb directly and only do minimal joins. |
|
| 294 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
| 295 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
| 296 | + * it, it's probably not junk (regardless of what status it has). |
|
| 297 | + * The downside to this approach is that is addons are listening for object deletions |
|
| 298 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
| 299 | + * to catch these types of deletions. |
|
| 300 | + * |
|
| 301 | + * @global WPDB $wpdb |
|
| 302 | + * @return mixed |
|
| 303 | + */ |
|
| 304 | + public function delete_junk_transactions() |
|
| 305 | + { |
|
| 306 | + /** @type WPDB $wpdb */ |
|
| 307 | + global $wpdb; |
|
| 308 | + $deleted = false; |
|
| 309 | + $time_to_leave_alone = apply_filters( |
|
| 310 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' |
|
| 311 | + , WEEK_IN_SECONDS |
|
| 312 | + ); |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
| 317 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
| 318 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
| 319 | + */ |
|
| 320 | + $ids_query = apply_filters( |
|
| 321 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
| 322 | + array( |
|
| 323 | + 0 => array( |
|
| 324 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
| 325 | + 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
| 326 | + 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
| 327 | + ) |
|
| 328 | + ), |
|
| 329 | + $time_to_leave_alone |
|
| 330 | + ); |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
| 335 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
| 336 | + */ |
|
| 337 | + $txn_ids = apply_filters( |
|
| 338 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
| 339 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
| 340 | + $time_to_leave_alone |
|
| 341 | + ); |
|
| 342 | + //now that we have the ids to delete |
|
| 343 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
| 344 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
| 345 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
| 346 | + // let's get deletin'... |
|
| 347 | + // Why no wpdb->prepare? Because the data is trusted. |
|
| 348 | + // We got the ids from the original query to get them FROM |
|
| 349 | + // the db (which is sanitized) so no need to prepare them again. |
|
| 350 | + $query = ' |
|
| 351 | 351 | DELETE |
| 352 | 352 | FROM ' . $this->table() . ' |
| 353 | 353 | WHERE |
| 354 | 354 | TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
| 355 | - $deleted = $wpdb->query($query); |
|
| 356 | - } |
|
| 357 | - if ($deleted) { |
|
| 358 | - /** |
|
| 359 | - * Allows code to do something after the transactions have been deleted. |
|
| 360 | - */ |
|
| 361 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - return $deleted; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * @param array $transaction_IDs |
|
| 370 | - * |
|
| 371 | - * @return bool |
|
| 372 | - */ |
|
| 373 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
| 374 | - { |
|
| 375 | - $locked_transactions = get_option('ee_locked_transactions', array()); |
|
| 376 | - $update = false; |
|
| 377 | - foreach ($transaction_IDs as $TXN_ID) { |
|
| 378 | - if (isset($locked_transactions[$TXN_ID])) { |
|
| 379 | - unset($locked_transactions[$TXN_ID]); |
|
| 380 | - $update = true; |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - if ($update) { |
|
| 384 | - update_option('ee_locked_transactions', $locked_transactions); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - return $update; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * returns an array of EE_Transaction objects whose timestamp is greater than |
|
| 394 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
| 395 | - * |
|
| 396 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
| 397 | - * @throws EE_Error |
|
| 398 | - * @throws InvalidArgumentException |
|
| 399 | - * @throws InvalidDataTypeException |
|
| 400 | - * @throws InvalidInterfaceException |
|
| 401 | - */ |
|
| 402 | - public function get_transactions_in_progress() |
|
| 403 | - { |
|
| 404 | - return $this->_get_transactions_in_progress(); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
| 411 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
| 412 | - * |
|
| 413 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
| 414 | - * @throws EE_Error |
|
| 415 | - * @throws InvalidArgumentException |
|
| 416 | - * @throws InvalidDataTypeException |
|
| 417 | - * @throws InvalidInterfaceException |
|
| 418 | - */ |
|
| 419 | - public function get_transactions_not_in_progress() |
|
| 420 | - { |
|
| 421 | - return $this->_get_transactions_in_progress('<='); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * @param string $comparison |
|
| 428 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
| 429 | - * @throws EE_Error |
|
| 430 | - * @throws InvalidArgumentException |
|
| 431 | - * @throws InvalidDataTypeException |
|
| 432 | - * @throws InvalidInterfaceException |
|
| 433 | - */ |
|
| 434 | - private function _get_transactions_in_progress($comparison = '>=') |
|
| 435 | - { |
|
| 436 | - $comparison = $comparison === '>=' || $comparison === '<=' |
|
| 437 | - ? $comparison |
|
| 438 | - : '>='; |
|
| 439 | - return $this->get_all( |
|
| 440 | - array( |
|
| 441 | - array( |
|
| 442 | - 'TXN_timestamp' => array( |
|
| 443 | - $comparison, |
|
| 444 | - time() - EE_Registry::instance()->SSN->lifespan() |
|
| 445 | - ), |
|
| 446 | - 'STS_ID' => array( |
|
| 447 | - '!=', |
|
| 448 | - EEM_Transaction::complete_status_code |
|
| 449 | - ), |
|
| 450 | - ) |
|
| 451 | - ) |
|
| 452 | - ); |
|
| 453 | - } |
|
| 355 | + $deleted = $wpdb->query($query); |
|
| 356 | + } |
|
| 357 | + if ($deleted) { |
|
| 358 | + /** |
|
| 359 | + * Allows code to do something after the transactions have been deleted. |
|
| 360 | + */ |
|
| 361 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + return $deleted; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * @param array $transaction_IDs |
|
| 370 | + * |
|
| 371 | + * @return bool |
|
| 372 | + */ |
|
| 373 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
| 374 | + { |
|
| 375 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
| 376 | + $update = false; |
|
| 377 | + foreach ($transaction_IDs as $TXN_ID) { |
|
| 378 | + if (isset($locked_transactions[$TXN_ID])) { |
|
| 379 | + unset($locked_transactions[$TXN_ID]); |
|
| 380 | + $update = true; |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + if ($update) { |
|
| 384 | + update_option('ee_locked_transactions', $locked_transactions); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + return $update; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * returns an array of EE_Transaction objects whose timestamp is greater than |
|
| 394 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
| 395 | + * |
|
| 396 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
| 397 | + * @throws EE_Error |
|
| 398 | + * @throws InvalidArgumentException |
|
| 399 | + * @throws InvalidDataTypeException |
|
| 400 | + * @throws InvalidInterfaceException |
|
| 401 | + */ |
|
| 402 | + public function get_transactions_in_progress() |
|
| 403 | + { |
|
| 404 | + return $this->_get_transactions_in_progress(); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
| 411 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
| 412 | + * |
|
| 413 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
| 414 | + * @throws EE_Error |
|
| 415 | + * @throws InvalidArgumentException |
|
| 416 | + * @throws InvalidDataTypeException |
|
| 417 | + * @throws InvalidInterfaceException |
|
| 418 | + */ |
|
| 419 | + public function get_transactions_not_in_progress() |
|
| 420 | + { |
|
| 421 | + return $this->_get_transactions_in_progress('<='); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * @param string $comparison |
|
| 428 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
| 429 | + * @throws EE_Error |
|
| 430 | + * @throws InvalidArgumentException |
|
| 431 | + * @throws InvalidDataTypeException |
|
| 432 | + * @throws InvalidInterfaceException |
|
| 433 | + */ |
|
| 434 | + private function _get_transactions_in_progress($comparison = '>=') |
|
| 435 | + { |
|
| 436 | + $comparison = $comparison === '>=' || $comparison === '<=' |
|
| 437 | + ? $comparison |
|
| 438 | + : '>='; |
|
| 439 | + return $this->get_all( |
|
| 440 | + array( |
|
| 441 | + array( |
|
| 442 | + 'TXN_timestamp' => array( |
|
| 443 | + $comparison, |
|
| 444 | + time() - EE_Registry::instance()->SSN->lifespan() |
|
| 445 | + ), |
|
| 446 | + 'STS_ID' => array( |
|
| 447 | + '!=', |
|
| 448 | + EEM_Transaction::complete_status_code |
|
| 449 | + ), |
|
| 450 | + ) |
|
| 451 | + ) |
|
| 452 | + ); |
|
| 453 | + } |
|
| 454 | 454 | |
| 455 | 455 | |
| 456 | 456 | } |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function __construct() { |
| 33 | 33 | parent::__construct( |
| 34 | - __( 'Event Espresso Upcoming Events', 'event_espresso' ), |
|
| 35 | - array( 'description' => __( 'A widget to display your upcoming events.', 'event_espresso' )) |
|
| 34 | + __('Event Espresso Upcoming Events', 'event_espresso'), |
|
| 35 | + array('description' => __('A widget to display your upcoming events.', 'event_espresso')) |
|
| 36 | 36 | ); |
| 37 | 37 | } |
| 38 | 38 | |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | * @param array $instance Previously saved values from database. |
| 46 | 46 | * @return string|void |
| 47 | 47 | */ |
| 48 | - public function form( $instance ) { |
|
| 48 | + public function form($instance) { |
|
| 49 | 49 | |
| 50 | - EE_Registry::instance()->load_class( 'Question_Option', array(), FALSE, FALSE, TRUE ); |
|
| 50 | + EE_Registry::instance()->load_class('Question_Option', array(), FALSE, FALSE, TRUE); |
|
| 51 | 51 | // Set up some default widget settings. |
| 52 | 52 | $defaults = array( |
| 53 | 53 | 'title' => __('Upcoming Events', 'event_espresso'), |
@@ -63,16 +63,16 @@ discard block |
||
| 63 | 63 | 'image_size' => 'medium' |
| 64 | 64 | ); |
| 65 | 65 | |
| 66 | - $instance = wp_parse_args( (array) $instance, $defaults ); |
|
| 66 | + $instance = wp_parse_args((array) $instance, $defaults); |
|
| 67 | 67 | // don't add HTML labels for EE_Form_Fields generated inputs |
| 68 | - add_filter( 'FHEE__EEH_Form_Fields__label_html', '__return_empty_string' ); |
|
| 68 | + add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string'); |
|
| 69 | 69 | $yes_no_values = array( |
| 70 | - EE_Question_Option::new_instance( array( 'QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))), |
|
| 71 | - EE_Question_Option::new_instance( array( 'QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso'))) |
|
| 70 | + EE_Question_Option::new_instance(array('QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))), |
|
| 71 | + EE_Question_Option::new_instance(array('QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso'))) |
|
| 72 | 72 | ); |
| 73 | 73 | $sort_values = array( |
| 74 | - EE_Question_Option::new_instance( array( 'QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))), |
|
| 75 | - EE_Question_Option::new_instance( array( 'QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso'))) |
|
| 74 | + EE_Question_Option::new_instance(array('QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))), |
|
| 75 | + EE_Question_Option::new_instance(array('QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso'))) |
|
| 76 | 76 | ); |
| 77 | 77 | |
| 78 | 78 | ?> |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | <label for="<?php echo $this->get_field_id('title'); ?>"> |
| 84 | 84 | <?php _e('Title:', 'event_espresso'); ?> |
| 85 | 85 | </label> |
| 86 | - <input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" type="text" /> |
|
| 86 | + <input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" type="text" /> |
|
| 87 | 87 | </p> |
| 88 | 88 | <p> |
| 89 | 89 | <label for="<?php echo $this->get_field_id('category_name'); ?>"> |
@@ -92,16 +92,16 @@ discard block |
||
| 92 | 92 | <?php |
| 93 | 93 | $event_categories = array(); |
| 94 | 94 | /** @type EEM_Term $EEM_Term */ |
| 95 | - $EEM_Term = EE_Registry::instance()->load_model( 'Term' ); |
|
| 96 | - $categories = $EEM_Term->get_all_ee_categories( TRUE ); |
|
| 97 | - if ( $categories ) { |
|
| 98 | - foreach ( $categories as $category ) { |
|
| 99 | - if ( $category instanceof EE_Term ) { |
|
| 100 | - $event_categories[] = EE_Question_Option::new_instance( array( 'QSO_value' => $category->get( 'slug' ), 'QSO_desc' => $category->get( 'name' ))); |
|
| 95 | + $EEM_Term = EE_Registry::instance()->load_model('Term'); |
|
| 96 | + $categories = $EEM_Term->get_all_ee_categories(TRUE); |
|
| 97 | + if ($categories) { |
|
| 98 | + foreach ($categories as $category) { |
|
| 99 | + if ($category instanceof EE_Term) { |
|
| 100 | + $event_categories[] = EE_Question_Option::new_instance(array('QSO_value' => $category->get('slug'), 'QSO_desc' => $category->get('name'))); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | - array_unshift( $event_categories, EE_Question_Option::new_instance( array( 'QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso')))); |
|
| 104 | + array_unshift($event_categories, EE_Question_Option::new_instance(array('QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso')))); |
|
| 105 | 105 | echo EEH_Form_Fields::select( |
| 106 | 106 | __('Event Category:', 'event_espresso'), |
| 107 | 107 | $instance['category_name'], |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | __('Show Expired Events:', 'event_espresso'), |
| 127 | 127 | $instance['show_expired'], |
| 128 | 128 | array( |
| 129 | - EE_Question_Option::new_instance( array( 'QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), |
|
| 130 | - EE_Question_Option::new_instance( array( 'QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), |
|
| 131 | - EE_Question_Option::new_instance( array( 'QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), |
|
| 129 | + EE_Question_Option::new_instance(array('QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), |
|
| 130 | + EE_Question_Option::new_instance(array('QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), |
|
| 131 | + EE_Question_Option::new_instance(array('QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), |
|
| 132 | 132 | ), |
| 133 | 133 | $this->get_field_name('show_expired'), |
| 134 | 134 | $this->get_field_id('show_expired') |
@@ -156,16 +156,16 @@ discard block |
||
| 156 | 156 | <?php |
| 157 | 157 | $image_sizes = array(); |
| 158 | 158 | $sizes = get_intermediate_image_sizes(); |
| 159 | - if ( $sizes ) { |
|
| 159 | + if ($sizes) { |
|
| 160 | 160 | // loop thru images and create option objects out of them |
| 161 | - foreach ( $sizes as $image_size ) { |
|
| 162 | - $image_size = trim( $image_size ); |
|
| 161 | + foreach ($sizes as $image_size) { |
|
| 162 | + $image_size = trim($image_size); |
|
| 163 | 163 | // no big images plz |
| 164 | - if ( ! in_array( $image_size, array( 'large', 'post-thumbnail' ))) { |
|
| 165 | - $image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => $image_size, 'QSO_desc' => $image_size )); |
|
| 164 | + if ( ! in_array($image_size, array('large', 'post-thumbnail'))) { |
|
| 165 | + $image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => $image_size, 'QSO_desc' => $image_size)); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | - $image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => 'none', 'QSO_desc' => __('don\'t show images', 'event_espresso') )); |
|
| 168 | + $image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => 'none', 'QSO_desc' => __('don\'t show images', 'event_espresso'))); |
|
| 169 | 169 | } |
| 170 | 170 | echo EEH_Form_Fields::select( |
| 171 | 171 | __('Image Size:', 'event_espresso'), |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | <label for="<?php echo $this->get_field_id('date_limit'); ?>"> |
| 224 | 224 | <?php _e('Number of Dates to Display:', 'event_espresso'); ?> |
| 225 | 225 | </label> |
| 226 | - <input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr( $instance['date_limit'] ); ?>" size="3" type="text" /> |
|
| 226 | + <input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr($instance['date_limit']); ?>" size="3" type="text" /> |
|
| 227 | 227 | </p> |
| 228 | 228 | <p> |
| 229 | 229 | <label for="<?php echo $this->get_field_id('date_range'); ?>"> |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * |
| 256 | 256 | * @return array Updated safe values to be saved. |
| 257 | 257 | */ |
| 258 | - public function update( $new_instance, $old_instance ) { |
|
| 258 | + public function update($new_instance, $old_instance) { |
|
| 259 | 259 | $instance = $old_instance; |
| 260 | - $instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
|
| 260 | + $instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : ''; |
|
| 261 | 261 | $instance['category_name'] = $new_instance['category_name']; |
| 262 | 262 | $instance['show_expired'] = $new_instance['show_expired']; |
| 263 | 263 | $instance['limit'] = $new_instance['limit']; |
@@ -281,18 +281,18 @@ discard block |
||
| 281 | 281 | * @param array $args Widget arguments. |
| 282 | 282 | * @param array $instance Saved values from database. |
| 283 | 283 | */ |
| 284 | - public function widget( $args, $instance ) { |
|
| 284 | + public function widget($args, $instance) { |
|
| 285 | 285 | |
| 286 | 286 | global $post; |
| 287 | 287 | // make sure there is some kinda post object |
| 288 | - if ( $post instanceof WP_Post ) { |
|
| 288 | + if ($post instanceof WP_Post) { |
|
| 289 | 289 | $before_widget = ''; |
| 290 | 290 | $before_title = ''; |
| 291 | 291 | $after_title = ''; |
| 292 | 292 | $after_widget = ''; |
| 293 | 293 | // but NOT an events archives page, cuz that would be like two event lists on the same page |
| 294 | - $show_everywhere = isset( $instance['show_everywhere'] ) ? (bool) absint( $instance['show_everywhere'] ) : TRUE; |
|
| 295 | - if ( $show_everywhere || ! ( $post->post_type == 'espresso_events' && is_archive() )) { |
|
| 294 | + $show_everywhere = isset($instance['show_everywhere']) ? (bool) absint($instance['show_everywhere']) : TRUE; |
|
| 295 | + if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) { |
|
| 296 | 296 | // let's use some of the event helper functions' |
| 297 | 297 | // make separate vars out of attributes |
| 298 | 298 | |
@@ -311,88 +311,88 @@ discard block |
||
| 311 | 311 | // Before widget (defined by themes). |
| 312 | 312 | echo $before_widget; |
| 313 | 313 | // Display the widget title if one was input (before and after defined by themes). |
| 314 | - if ( ! empty( $title )) { |
|
| 315 | - echo $before_title . $title . $after_title; |
|
| 314 | + if ( ! empty($title)) { |
|
| 315 | + echo $before_title.$title.$after_title; |
|
| 316 | 316 | } |
| 317 | 317 | // grab widget settings |
| 318 | - $category = isset( $instance['category_name'] ) && ! empty( $instance['category_name'] ) ? $instance['category_name'] : FALSE; |
|
| 319 | - $show_expired = isset( $instance['show_expired'] ) ? absint( $instance['show_expired'] ) : 0; |
|
| 320 | - $image_size = isset( $instance['image_size'] ) && ! empty( $instance['image_size'] ) ? $instance['image_size'] : 'medium'; |
|
| 321 | - $show_desc = isset( $instance['show_desc'] ) ? (bool) absint( $instance['show_desc'] ) : TRUE; |
|
| 322 | - $show_dates = isset( $instance['show_dates'] ) ? (bool) absint( $instance['show_dates'] ) : TRUE; |
|
| 323 | - $date_limit = isset( $instance['date_limit'] ) && ! empty( $instance['date_limit'] ) ? $instance['date_limit'] : NULL; |
|
| 324 | - $date_range = isset( $instance['date_range'] ) && ! empty( $instance['date_range'] ) ? $instance['date_range'] : FALSE; |
|
| 318 | + $category = isset($instance['category_name']) && ! empty($instance['category_name']) ? $instance['category_name'] : FALSE; |
|
| 319 | + $show_expired = isset($instance['show_expired']) ? absint($instance['show_expired']) : 0; |
|
| 320 | + $image_size = isset($instance['image_size']) && ! empty($instance['image_size']) ? $instance['image_size'] : 'medium'; |
|
| 321 | + $show_desc = isset($instance['show_desc']) ? (bool) absint($instance['show_desc']) : TRUE; |
|
| 322 | + $show_dates = isset($instance['show_dates']) ? (bool) absint($instance['show_dates']) : TRUE; |
|
| 323 | + $date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) ? $instance['date_limit'] : NULL; |
|
| 324 | + $date_range = isset($instance['date_range']) && ! empty($instance['date_range']) ? $instance['date_range'] : FALSE; |
|
| 325 | 325 | // start to build our where clause |
| 326 | 326 | $where = array( |
| 327 | 327 | // 'Datetime.DTT_is_primary' => 1, |
| 328 | - 'status' => array( 'IN', array( 'publish', 'sold_out' ) ) |
|
| 328 | + 'status' => array('IN', array('publish', 'sold_out')) |
|
| 329 | 329 | ); |
| 330 | 330 | // add category |
| 331 | - if ( $category ) { |
|
| 331 | + if ($category) { |
|
| 332 | 332 | $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
| 333 | 333 | $where['Term_Taxonomy.Term.slug'] = $category; |
| 334 | 334 | } |
| 335 | 335 | // if NOT expired then we want events that start today or in the future |
| 336 | 336 | // if NOT show expired then we want events that start today or in the future |
| 337 | - if ( $show_expired == 0 ) { |
|
| 338 | - $where['Datetime.DTT_EVT_end'] = array( '>=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ); |
|
| 337 | + if ($show_expired == 0) { |
|
| 338 | + $where['Datetime.DTT_EVT_end'] = array('>=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')); |
|
| 339 | 339 | } |
| 340 | 340 | // if show ONLY expired we want events that ended prior to today |
| 341 | - if ( $show_expired == 2 ) { |
|
| 342 | - $where['Datetime.DTT_EVT_end'] = array( '<=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ); |
|
| 341 | + if ($show_expired == 2) { |
|
| 342 | + $where['Datetime.DTT_EVT_end'] = array('<=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')); |
|
| 343 | 343 | } |
| 344 | 344 | // allow $where to be filtered |
| 345 | - $where = apply_filters( 'FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired ); |
|
| 345 | + $where = apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired); |
|
| 346 | 346 | // run the query |
| 347 | - $events = EE_Registry::instance()->load_model( 'Event' )->get_all( array( |
|
| 347 | + $events = EE_Registry::instance()->load_model('Event')->get_all(array( |
|
| 348 | 348 | $where, |
| 349 | - 'limit' => $instance['limit'] > 0 ? '0,' . $instance['limit'] : '0,10', |
|
| 349 | + 'limit' => $instance['limit'] > 0 ? '0,'.$instance['limit'] : '0,10', |
|
| 350 | 350 | 'order_by' => 'Datetime.DTT_EVT_start', |
| 351 | 351 | 'order' => isset($instance['sort']) ? $instance['sort'] : 'ASC', |
| 352 | 352 | 'group_by' => 'EVT_ID' |
| 353 | 353 | )); |
| 354 | 354 | |
| 355 | - if ( ! empty( $events )) { |
|
| 355 | + if ( ! empty($events)) { |
|
| 356 | 356 | echo '<ul class="ee-upcoming-events-widget-ul">'; |
| 357 | - foreach ( $events as $event ) { |
|
| 358 | - if ( $event instanceof EE_Event && ( !is_single() || $post->ID != $event->ID() ) ) { |
|
| 357 | + foreach ($events as $event) { |
|
| 358 | + if ($event instanceof EE_Event && ( ! is_single() || $post->ID != $event->ID())) { |
|
| 359 | 359 | //printr( $event, '$event <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 360 | - echo '<li id="ee-upcoming-events-widget-li-' . $event->ID() . '" class="ee-upcoming-events-widget-li">'; |
|
| 360 | + echo '<li id="ee-upcoming-events-widget-li-'.$event->ID().'" class="ee-upcoming-events-widget-li">'; |
|
| 361 | 361 | // how big is the event name ? |
| 362 | - $name_length = strlen( $event->name() ); |
|
| 363 | - switch( $name_length ) { |
|
| 362 | + $name_length = strlen($event->name()); |
|
| 363 | + switch ($name_length) { |
|
| 364 | 364 | case $name_length > 70 : |
| 365 | - $len_class = ' three-line'; |
|
| 365 | + $len_class = ' three-line'; |
|
| 366 | 366 | break; |
| 367 | 367 | case $name_length > 35 : |
| 368 | - $len_class = ' two-line'; |
|
| 368 | + $len_class = ' two-line'; |
|
| 369 | 369 | break; |
| 370 | 370 | default : |
| 371 | - $len_class = ' one-line'; |
|
| 371 | + $len_class = ' one-line'; |
|
| 372 | 372 | } |
| 373 | - $event_url = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event ); |
|
| 374 | - echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a' . $len_class . '" href="' . $event_url . '">' . $event->name() . '</a></h5>'; |
|
| 375 | - if ( post_password_required( $event->ID() ) ) { |
|
| 376 | - $pswd_form = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form( $event->ID() ), $event ); |
|
| 373 | + $event_url = apply_filters('FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event); |
|
| 374 | + echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a'.$len_class.'" href="'.$event_url.'">'.$event->name().'</a></h5>'; |
|
| 375 | + if (post_password_required($event->ID())) { |
|
| 376 | + $pswd_form = apply_filters('FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form($event->ID()), $event); |
|
| 377 | 377 | echo $pswd_form; |
| 378 | 378 | } else { |
| 379 | - if ( has_post_thumbnail( $event->ID() ) && $image_size != 'none' ) { |
|
| 380 | - echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="' . $event_url . '">' . get_the_post_thumbnail( $event->ID(), $image_size ) . '</a></div>'; |
|
| 379 | + if (has_post_thumbnail($event->ID()) && $image_size != 'none') { |
|
| 380 | + echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="'.$event_url.'">'.get_the_post_thumbnail($event->ID(), $image_size).'</a></div>'; |
|
| 381 | 381 | } |
| 382 | - $desc = $event->short_description( 25 ); |
|
| 383 | - if ( $show_dates ) { |
|
| 384 | - $date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', get_option( 'date_format' )); |
|
| 385 | - $time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', get_option( 'time_format' )); |
|
| 386 | - $single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', get_option( 'date_format' )); |
|
| 387 | - $single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', get_option( 'time_format' )); |
|
| 388 | - if ( $date_range == TRUE ) { |
|
| 389 | - echo espresso_event_date_range( $date_format, $time_format, $single_date_format, $single_time_format, $event->ID() ); |
|
| 390 | - }else{ |
|
| 391 | - echo espresso_list_of_event_dates( $event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit ); |
|
| 382 | + $desc = $event->short_description(25); |
|
| 383 | + if ($show_dates) { |
|
| 384 | + $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', get_option('date_format')); |
|
| 385 | + $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', get_option('time_format')); |
|
| 386 | + $single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', get_option('date_format')); |
|
| 387 | + $single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', get_option('time_format')); |
|
| 388 | + if ($date_range == TRUE) { |
|
| 389 | + echo espresso_event_date_range($date_format, $time_format, $single_date_format, $single_time_format, $event->ID()); |
|
| 390 | + } else { |
|
| 391 | + echo espresso_list_of_event_dates($event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit); |
|
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | - if ( $show_desc && $desc ) { |
|
| 395 | - echo '<p style="margin-top: .5em">' . $desc . '</p>'; |
|
| 394 | + if ($show_desc && $desc) { |
|
| 395 | + echo '<p style="margin-top: .5em">'.$desc.'</p>'; |
|
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | echo '</li>'; |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @return string |
| 417 | 417 | */ |
| 418 | 418 | public function make_the_title_a_link($title) { |
| 419 | - return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>'; |
|
| 419 | + return '<a href="'.EEH_Event_View::event_archive_url().'">'.$title.'</a>'; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | } |
@@ -17,2443 +17,2443 @@ discard block |
||
| 17 | 17 | final class EE_Config implements ResettableInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - const OPTION_NAME = 'ee_config'; |
|
| 20 | + const OPTION_NAME = 'ee_config'; |
|
| 21 | + |
|
| 22 | + const LOG_NAME = 'ee_config_log'; |
|
| 23 | + |
|
| 24 | + const LOG_LENGTH = 100; |
|
| 25 | + |
|
| 26 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * instance of the EE_Config object |
|
| 31 | + * |
|
| 32 | + * @var EE_Config $_instance |
|
| 33 | + * @access private |
|
| 34 | + */ |
|
| 35 | + private static $_instance; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var boolean $_logging_enabled |
|
| 39 | + */ |
|
| 40 | + private static $_logging_enabled = false; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 44 | + */ |
|
| 45 | + private $legacy_shortcodes_manager; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * An StdClass whose property names are addon slugs, |
|
| 49 | + * and values are their config classes |
|
| 50 | + * |
|
| 51 | + * @var StdClass |
|
| 52 | + */ |
|
| 53 | + public $addons; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var EE_Admin_Config |
|
| 57 | + */ |
|
| 58 | + public $admin; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var EE_Core_Config |
|
| 62 | + */ |
|
| 63 | + public $core; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var EE_Currency_Config |
|
| 67 | + */ |
|
| 68 | + public $currency; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var EE_Organization_Config |
|
| 72 | + */ |
|
| 73 | + public $organization; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var EE_Registration_Config |
|
| 77 | + */ |
|
| 78 | + public $registration; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @var EE_Template_Config |
|
| 82 | + */ |
|
| 83 | + public $template_settings; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Holds EE environment values. |
|
| 87 | + * |
|
| 88 | + * @var EE_Environment_Config |
|
| 89 | + */ |
|
| 90 | + public $environment; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * settings pertaining to Google maps |
|
| 94 | + * |
|
| 95 | + * @var EE_Map_Config |
|
| 96 | + */ |
|
| 97 | + public $map_settings; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * settings pertaining to Taxes |
|
| 101 | + * |
|
| 102 | + * @var EE_Tax_Config |
|
| 103 | + */ |
|
| 104 | + public $tax_settings; |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Settings pertaining to global messages settings. |
|
| 109 | + * |
|
| 110 | + * @var EE_Messages_Config |
|
| 111 | + */ |
|
| 112 | + public $messages; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @deprecated |
|
| 116 | + * @var EE_Gateway_Config |
|
| 117 | + */ |
|
| 118 | + public $gateway; |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @var array $_addon_option_names |
|
| 122 | + * @access private |
|
| 123 | + */ |
|
| 124 | + private $_addon_option_names = array(); |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @var array $_module_route_map |
|
| 128 | + * @access private |
|
| 129 | + */ |
|
| 130 | + private static $_module_route_map = array(); |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @var array $_module_forward_map |
|
| 134 | + * @access private |
|
| 135 | + */ |
|
| 136 | + private static $_module_forward_map = array(); |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @var array $_module_view_map |
|
| 140 | + * @access private |
|
| 141 | + */ |
|
| 142 | + private static $_module_view_map = array(); |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @singleton method used to instantiate class object |
|
| 148 | + * @access public |
|
| 149 | + * @return EE_Config instance |
|
| 150 | + */ |
|
| 151 | + public static function instance() |
|
| 152 | + { |
|
| 153 | + // check if class object is instantiated, and instantiated properly |
|
| 154 | + if (! self::$_instance instanceof EE_Config) { |
|
| 155 | + self::$_instance = new self(); |
|
| 156 | + } |
|
| 157 | + return self::$_instance; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Resets the config |
|
| 164 | + * |
|
| 165 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 166 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 167 | + * reflect its state in the database |
|
| 168 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 169 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 170 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 171 | + * site was put into maintenance mode) |
|
| 172 | + * @return EE_Config |
|
| 173 | + */ |
|
| 174 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 175 | + { |
|
| 176 | + if (self::$_instance instanceof EE_Config) { |
|
| 177 | + if ($hard_reset) { |
|
| 178 | + self::$_instance->legacy_shortcodes_manager = null; |
|
| 179 | + self::$_instance->_addon_option_names = array(); |
|
| 180 | + self::$_instance->_initialize_config(); |
|
| 181 | + self::$_instance->update_espresso_config(); |
|
| 182 | + } |
|
| 183 | + self::$_instance->update_addon_option_names(); |
|
| 184 | + } |
|
| 185 | + self::$_instance = null; |
|
| 186 | + //we don't need to reset the static properties imo because those should |
|
| 187 | + //only change when a module is added or removed. Currently we don't |
|
| 188 | + //support removing a module during a request when it previously existed |
|
| 189 | + if ($reinstantiate) { |
|
| 190 | + return self::instance(); |
|
| 191 | + } else { |
|
| 192 | + return null; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * class constructor |
|
| 200 | + * |
|
| 201 | + * @access private |
|
| 202 | + */ |
|
| 203 | + private function __construct() |
|
| 204 | + { |
|
| 205 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 206 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 207 | + // setup empty config classes |
|
| 208 | + $this->_initialize_config(); |
|
| 209 | + // load existing EE site settings |
|
| 210 | + $this->_load_core_config(); |
|
| 211 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 212 | + $this->_verify_config(); |
|
| 213 | + // register shortcodes and modules |
|
| 214 | + add_action( |
|
| 215 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 216 | + array($this, 'register_shortcodes_and_modules'), |
|
| 217 | + 999 |
|
| 218 | + ); |
|
| 219 | + // initialize shortcodes and modules |
|
| 220 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 221 | + // register widgets |
|
| 222 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 223 | + // shutdown |
|
| 224 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 225 | + // construct__end hook |
|
| 226 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 227 | + // hardcoded hack |
|
| 228 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @return boolean |
|
| 235 | + */ |
|
| 236 | + public static function logging_enabled() |
|
| 237 | + { |
|
| 238 | + return self::$_logging_enabled; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * use to get the current theme if needed from static context |
|
| 245 | + * |
|
| 246 | + * @return string current theme set. |
|
| 247 | + */ |
|
| 248 | + public static function get_current_theme() |
|
| 249 | + { |
|
| 250 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 251 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * _initialize_config |
|
| 258 | + * |
|
| 259 | + * @access private |
|
| 260 | + * @return void |
|
| 261 | + */ |
|
| 262 | + private function _initialize_config() |
|
| 263 | + { |
|
| 264 | + EE_Config::trim_log(); |
|
| 265 | + //set defaults |
|
| 266 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 267 | + $this->addons = new stdClass(); |
|
| 268 | + // set _module_route_map |
|
| 269 | + EE_Config::$_module_route_map = array(); |
|
| 270 | + // set _module_forward_map |
|
| 271 | + EE_Config::$_module_forward_map = array(); |
|
| 272 | + // set _module_view_map |
|
| 273 | + EE_Config::$_module_view_map = array(); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * load core plugin configuration |
|
| 280 | + * |
|
| 281 | + * @access private |
|
| 282 | + * @return void |
|
| 283 | + */ |
|
| 284 | + private function _load_core_config() |
|
| 285 | + { |
|
| 286 | + // load_core_config__start hook |
|
| 287 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 288 | + $espresso_config = $this->get_espresso_config(); |
|
| 289 | + foreach ($espresso_config as $config => $settings) { |
|
| 290 | + // load_core_config__start hook |
|
| 291 | + $settings = apply_filters( |
|
| 292 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 293 | + $settings, |
|
| 294 | + $config, |
|
| 295 | + $this |
|
| 296 | + ); |
|
| 297 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 298 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 299 | + //call configs populate method to ensure any defaults are set for empty values. |
|
| 300 | + if (method_exists($settings, 'populate')) { |
|
| 301 | + $this->{$config}->populate(); |
|
| 302 | + } |
|
| 303 | + if (method_exists($settings, 'do_hooks')) { |
|
| 304 | + $this->{$config}->do_hooks(); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 309 | + $this->update_espresso_config(); |
|
| 310 | + } |
|
| 311 | + // load_core_config__end hook |
|
| 312 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * _verify_config |
|
| 319 | + * |
|
| 320 | + * @access protected |
|
| 321 | + * @return void |
|
| 322 | + */ |
|
| 323 | + protected function _verify_config() |
|
| 324 | + { |
|
| 325 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 326 | + ? $this->core |
|
| 327 | + : new EE_Core_Config(); |
|
| 328 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 329 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 330 | + ? $this->organization |
|
| 331 | + : new EE_Organization_Config(); |
|
| 332 | + $this->organization = apply_filters( |
|
| 333 | + 'FHEE__EE_Config___initialize_config__organization', |
|
| 334 | + $this->organization |
|
| 335 | + ); |
|
| 336 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 337 | + ? $this->currency |
|
| 338 | + : new EE_Currency_Config(); |
|
| 339 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 340 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 341 | + ? $this->registration |
|
| 342 | + : new EE_Registration_Config(); |
|
| 343 | + $this->registration = apply_filters( |
|
| 344 | + 'FHEE__EE_Config___initialize_config__registration', |
|
| 345 | + $this->registration |
|
| 346 | + ); |
|
| 347 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 348 | + ? $this->admin |
|
| 349 | + : new EE_Admin_Config(); |
|
| 350 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 351 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 352 | + ? $this->template_settings |
|
| 353 | + : new EE_Template_Config(); |
|
| 354 | + $this->template_settings = apply_filters( |
|
| 355 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 356 | + $this->template_settings |
|
| 357 | + ); |
|
| 358 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 359 | + ? $this->map_settings |
|
| 360 | + : new EE_Map_Config(); |
|
| 361 | + $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
| 362 | + $this->map_settings); |
|
| 363 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 364 | + ? $this->environment |
|
| 365 | + : new EE_Environment_Config(); |
|
| 366 | + $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
| 367 | + $this->environment); |
|
| 368 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 369 | + ? $this->tax_settings |
|
| 370 | + : new EE_Tax_Config(); |
|
| 371 | + $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
| 372 | + $this->tax_settings); |
|
| 373 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 374 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 375 | + ? $this->messages |
|
| 376 | + : new EE_Messages_Config(); |
|
| 377 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 378 | + ? $this->gateway |
|
| 379 | + : new EE_Gateway_Config(); |
|
| 380 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 381 | + $this->legacy_shortcodes_manager = null; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * get_espresso_config |
|
| 387 | + * |
|
| 388 | + * @access public |
|
| 389 | + * @return array of espresso config stuff |
|
| 390 | + */ |
|
| 391 | + public function get_espresso_config() |
|
| 392 | + { |
|
| 393 | + // grab espresso configuration |
|
| 394 | + return apply_filters( |
|
| 395 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 396 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 397 | + ); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * double_check_config_comparison |
|
| 404 | + * |
|
| 405 | + * @access public |
|
| 406 | + * @param string $option |
|
| 407 | + * @param $old_value |
|
| 408 | + * @param $value |
|
| 409 | + */ |
|
| 410 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 411 | + { |
|
| 412 | + // make sure we're checking the ee config |
|
| 413 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 414 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 415 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 416 | + if ($value != $old_value) { |
|
| 417 | + // if they are NOT the same, then remove the hook, |
|
| 418 | + // which means the subsequent update results will be based solely on the update query results |
|
| 419 | + // the reason we do this is because, as stated above, |
|
| 420 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 421 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 422 | + // If values are found to match their previous old value, |
|
| 423 | + // then WP bails before performing any update. |
|
| 424 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 425 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 426 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 427 | + // MySQL MAY ALSO NOT perform the update because |
|
| 428 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 429 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 430 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 431 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * update_espresso_config |
|
| 440 | + * |
|
| 441 | + * @access public |
|
| 442 | + */ |
|
| 443 | + protected function _reset_espresso_addon_config() |
|
| 444 | + { |
|
| 445 | + $this->_addon_option_names = array(); |
|
| 446 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 447 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 448 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 449 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 450 | + } |
|
| 451 | + $this->addons->{$addon_name} = null; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * update_espresso_config |
|
| 459 | + * |
|
| 460 | + * @access public |
|
| 461 | + * @param bool $add_success |
|
| 462 | + * @param bool $add_error |
|
| 463 | + * @return bool |
|
| 464 | + */ |
|
| 465 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 466 | + { |
|
| 467 | + // don't allow config updates during WP heartbeats |
|
| 468 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 469 | + return false; |
|
| 470 | + } |
|
| 471 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 472 | + //$clone = clone( self::$_instance ); |
|
| 473 | + //self::$_instance = NULL; |
|
| 474 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 475 | + $this->_reset_espresso_addon_config(); |
|
| 476 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 477 | + // but BEFORE the actual update occurs |
|
| 478 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 479 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 480 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 481 | + $this->legacy_shortcodes_manager = null; |
|
| 482 | + // now update "ee_config" |
|
| 483 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 484 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 485 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 486 | + // if not saved... check if the hook we just added still exists; |
|
| 487 | + // if it does, it means one of two things: |
|
| 488 | + // that update_option bailed at the ( $value === $old_value ) conditional, |
|
| 489 | + // or... |
|
| 490 | + // the db update query returned 0 rows affected |
|
| 491 | + // (probably because the data value was the same from it's perspective) |
|
| 492 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 493 | + // but just means no update occurred, so don't display an error to the user. |
|
| 494 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 495 | + // then it means that something truly went wrong |
|
| 496 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 497 | + // remove our action since we don't want it in the system anymore |
|
| 498 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 499 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 500 | + //self::$_instance = $clone; |
|
| 501 | + //unset( $clone ); |
|
| 502 | + // if config remains the same or was updated successfully |
|
| 503 | + if ($saved) { |
|
| 504 | + if ($add_success) { |
|
| 505 | + EE_Error::add_success( |
|
| 506 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 507 | + __FILE__, |
|
| 508 | + __FUNCTION__, |
|
| 509 | + __LINE__ |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + return true; |
|
| 513 | + } else { |
|
| 514 | + if ($add_error) { |
|
| 515 | + EE_Error::add_error( |
|
| 516 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 517 | + __FILE__, |
|
| 518 | + __FUNCTION__, |
|
| 519 | + __LINE__ |
|
| 520 | + ); |
|
| 521 | + } |
|
| 522 | + return false; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * _verify_config_params |
|
| 530 | + * |
|
| 531 | + * @access private |
|
| 532 | + * @param string $section |
|
| 533 | + * @param string $name |
|
| 534 | + * @param string $config_class |
|
| 535 | + * @param EE_Config_Base $config_obj |
|
| 536 | + * @param array $tests_to_run |
|
| 537 | + * @param bool $display_errors |
|
| 538 | + * @return bool TRUE on success, FALSE on fail |
|
| 539 | + */ |
|
| 540 | + private function _verify_config_params( |
|
| 541 | + $section = '', |
|
| 542 | + $name = '', |
|
| 543 | + $config_class = '', |
|
| 544 | + $config_obj = null, |
|
| 545 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 546 | + $display_errors = true |
|
| 547 | + ) { |
|
| 548 | + try { |
|
| 549 | + foreach ($tests_to_run as $test) { |
|
| 550 | + switch ($test) { |
|
| 551 | + // TEST #1 : check that section was set |
|
| 552 | + case 1 : |
|
| 553 | + if (empty($section)) { |
|
| 554 | + if ($display_errors) { |
|
| 555 | + throw new EE_Error( |
|
| 556 | + sprintf( |
|
| 557 | + __( |
|
| 558 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 559 | + 'event_espresso' |
|
| 560 | + ), |
|
| 561 | + $config_class |
|
| 562 | + ) |
|
| 563 | + ); |
|
| 564 | + } |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + break; |
|
| 568 | + // TEST #2 : check that settings section exists |
|
| 569 | + case 2 : |
|
| 570 | + if (! isset($this->{$section})) { |
|
| 571 | + if ($display_errors) { |
|
| 572 | + throw new EE_Error( |
|
| 573 | + sprintf( |
|
| 574 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 575 | + $section |
|
| 576 | + ) |
|
| 577 | + ); |
|
| 578 | + } |
|
| 579 | + return false; |
|
| 580 | + } |
|
| 581 | + break; |
|
| 582 | + // TEST #3 : check that section is the proper format |
|
| 583 | + case 3 : |
|
| 584 | + if ( |
|
| 585 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 586 | + ) { |
|
| 587 | + if ($display_errors) { |
|
| 588 | + throw new EE_Error( |
|
| 589 | + sprintf( |
|
| 590 | + __( |
|
| 591 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 592 | + 'event_espresso' |
|
| 593 | + ), |
|
| 594 | + $section |
|
| 595 | + ) |
|
| 596 | + ); |
|
| 597 | + } |
|
| 598 | + return false; |
|
| 599 | + } |
|
| 600 | + break; |
|
| 601 | + // TEST #4 : check that config section name has been set |
|
| 602 | + case 4 : |
|
| 603 | + if (empty($name)) { |
|
| 604 | + if ($display_errors) { |
|
| 605 | + throw new EE_Error( |
|
| 606 | + __( |
|
| 607 | + 'No name has been provided for the specific configuration section.', |
|
| 608 | + 'event_espresso' |
|
| 609 | + ) |
|
| 610 | + ); |
|
| 611 | + } |
|
| 612 | + return false; |
|
| 613 | + } |
|
| 614 | + break; |
|
| 615 | + // TEST #5 : check that a config class name has been set |
|
| 616 | + case 5 : |
|
| 617 | + if (empty($config_class)) { |
|
| 618 | + if ($display_errors) { |
|
| 619 | + throw new EE_Error( |
|
| 620 | + __( |
|
| 621 | + 'No class name has been provided for the specific configuration section.', |
|
| 622 | + 'event_espresso' |
|
| 623 | + ) |
|
| 624 | + ); |
|
| 625 | + } |
|
| 626 | + return false; |
|
| 627 | + } |
|
| 628 | + break; |
|
| 629 | + // TEST #6 : verify config class is accessible |
|
| 630 | + case 6 : |
|
| 631 | + if (! class_exists($config_class)) { |
|
| 632 | + if ($display_errors) { |
|
| 633 | + throw new EE_Error( |
|
| 634 | + sprintf( |
|
| 635 | + __( |
|
| 636 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 637 | + 'event_espresso' |
|
| 638 | + ), |
|
| 639 | + $config_class |
|
| 640 | + ) |
|
| 641 | + ); |
|
| 642 | + } |
|
| 643 | + return false; |
|
| 644 | + } |
|
| 645 | + break; |
|
| 646 | + // TEST #7 : check that config has even been set |
|
| 647 | + case 7 : |
|
| 648 | + if (! isset($this->{$section}->{$name})) { |
|
| 649 | + if ($display_errors) { |
|
| 650 | + throw new EE_Error( |
|
| 651 | + sprintf( |
|
| 652 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 653 | + $section, |
|
| 654 | + $name |
|
| 655 | + ) |
|
| 656 | + ); |
|
| 657 | + } |
|
| 658 | + return false; |
|
| 659 | + } else { |
|
| 660 | + // and make sure it's not serialized |
|
| 661 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 662 | + } |
|
| 663 | + break; |
|
| 664 | + // TEST #8 : check that config is the requested type |
|
| 665 | + case 8 : |
|
| 666 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 667 | + if ($display_errors) { |
|
| 668 | + throw new EE_Error( |
|
| 669 | + sprintf( |
|
| 670 | + __( |
|
| 671 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 672 | + 'event_espresso' |
|
| 673 | + ), |
|
| 674 | + $section, |
|
| 675 | + $name, |
|
| 676 | + $config_class |
|
| 677 | + ) |
|
| 678 | + ); |
|
| 679 | + } |
|
| 680 | + return false; |
|
| 681 | + } |
|
| 682 | + break; |
|
| 683 | + // TEST #9 : verify config object |
|
| 684 | + case 9 : |
|
| 685 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 686 | + if ($display_errors) { |
|
| 687 | + throw new EE_Error( |
|
| 688 | + sprintf( |
|
| 689 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 690 | + print_r($config_obj, true) |
|
| 691 | + ) |
|
| 692 | + ); |
|
| 693 | + } |
|
| 694 | + return false; |
|
| 695 | + } |
|
| 696 | + break; |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | + } catch (EE_Error $e) { |
|
| 700 | + $e->get_error(); |
|
| 701 | + } |
|
| 702 | + // you have successfully run the gauntlet |
|
| 703 | + return true; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * _generate_config_option_name |
|
| 710 | + * |
|
| 711 | + * @access protected |
|
| 712 | + * @param string $section |
|
| 713 | + * @param string $name |
|
| 714 | + * @return string |
|
| 715 | + */ |
|
| 716 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 717 | + { |
|
| 718 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * _set_config_class |
|
| 725 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 726 | + * |
|
| 727 | + * @access private |
|
| 728 | + * @param string $config_class |
|
| 729 | + * @param string $name |
|
| 730 | + * @return string |
|
| 731 | + */ |
|
| 732 | + private function _set_config_class($config_class = '', $name = '') |
|
| 733 | + { |
|
| 734 | + return ! empty($config_class) |
|
| 735 | + ? $config_class |
|
| 736 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * set_config |
|
| 743 | + * |
|
| 744 | + * @access protected |
|
| 745 | + * @param string $section |
|
| 746 | + * @param string $name |
|
| 747 | + * @param string $config_class |
|
| 748 | + * @param EE_Config_Base $config_obj |
|
| 749 | + * @return EE_Config_Base |
|
| 750 | + */ |
|
| 751 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 752 | + { |
|
| 753 | + // ensure config class is set to something |
|
| 754 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 755 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 756 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 757 | + return null; |
|
| 758 | + } |
|
| 759 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 760 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 761 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 762 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 763 | + $this->update_addon_option_names(); |
|
| 764 | + } |
|
| 765 | + // verify the incoming config object but suppress errors |
|
| 766 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 767 | + $config_obj = new $config_class(); |
|
| 768 | + } |
|
| 769 | + if (get_option($config_option_name)) { |
|
| 770 | + EE_Config::log($config_option_name); |
|
| 771 | + update_option($config_option_name, $config_obj); |
|
| 772 | + $this->{$section}->{$name} = $config_obj; |
|
| 773 | + return $this->{$section}->{$name}; |
|
| 774 | + } else { |
|
| 775 | + // create a wp-option for this config |
|
| 776 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 777 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 778 | + return $this->{$section}->{$name}; |
|
| 779 | + } else { |
|
| 780 | + EE_Error::add_error( |
|
| 781 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 782 | + __FILE__, |
|
| 783 | + __FUNCTION__, |
|
| 784 | + __LINE__ |
|
| 785 | + ); |
|
| 786 | + return null; |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * update_config |
|
| 795 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 796 | + * |
|
| 797 | + * @access public |
|
| 798 | + * @param string $section |
|
| 799 | + * @param string $name |
|
| 800 | + * @param EE_Config_Base|string $config_obj |
|
| 801 | + * @param bool $throw_errors |
|
| 802 | + * @return bool |
|
| 803 | + */ |
|
| 804 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 805 | + { |
|
| 806 | + // don't allow config updates during WP heartbeats |
|
| 807 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 808 | + return false; |
|
| 809 | + } |
|
| 810 | + $config_obj = maybe_unserialize($config_obj); |
|
| 811 | + // get class name of the incoming object |
|
| 812 | + $config_class = get_class($config_obj); |
|
| 813 | + // run tests 1-5 and 9 to verify config |
|
| 814 | + if (! $this->_verify_config_params( |
|
| 815 | + $section, |
|
| 816 | + $name, |
|
| 817 | + $config_class, |
|
| 818 | + $config_obj, |
|
| 819 | + array(1, 2, 3, 4, 7, 9) |
|
| 820 | + ) |
|
| 821 | + ) { |
|
| 822 | + return false; |
|
| 823 | + } |
|
| 824 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 825 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 826 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 827 | + // save new config to db |
|
| 828 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 829 | + return true; |
|
| 830 | + } |
|
| 831 | + } else { |
|
| 832 | + // first check if the record already exists |
|
| 833 | + $existing_config = get_option($config_option_name); |
|
| 834 | + $config_obj = serialize($config_obj); |
|
| 835 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 836 | + if ($existing_config == $config_obj) { |
|
| 837 | + $this->{$section}->{$name} = $config_obj; |
|
| 838 | + return true; |
|
| 839 | + } else if (update_option($config_option_name, $config_obj)) { |
|
| 840 | + EE_Config::log($config_option_name); |
|
| 841 | + // update wp-option for this config class |
|
| 842 | + $this->{$section}->{$name} = $config_obj; |
|
| 843 | + return true; |
|
| 844 | + } elseif ($throw_errors) { |
|
| 845 | + EE_Error::add_error( |
|
| 846 | + sprintf( |
|
| 847 | + __( |
|
| 848 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 849 | + 'event_espresso' |
|
| 850 | + ), |
|
| 851 | + $config_class, |
|
| 852 | + 'EE_Config->' . $section . '->' . $name |
|
| 853 | + ), |
|
| 854 | + __FILE__, |
|
| 855 | + __FUNCTION__, |
|
| 856 | + __LINE__ |
|
| 857 | + ); |
|
| 858 | + } |
|
| 859 | + } |
|
| 860 | + return false; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * get_config |
|
| 867 | + * |
|
| 868 | + * @access public |
|
| 869 | + * @param string $section |
|
| 870 | + * @param string $name |
|
| 871 | + * @param string $config_class |
|
| 872 | + * @return mixed EE_Config_Base | NULL |
|
| 873 | + */ |
|
| 874 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 875 | + { |
|
| 876 | + // ensure config class is set to something |
|
| 877 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 878 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 879 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 880 | + return null; |
|
| 881 | + } |
|
| 882 | + // now test if the requested config object exists, but suppress errors |
|
| 883 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 884 | + // config already exists, so pass it back |
|
| 885 | + return $this->{$section}->{$name}; |
|
| 886 | + } |
|
| 887 | + // load config option from db if it exists |
|
| 888 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 889 | + // verify the newly retrieved config object, but suppress errors |
|
| 890 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 891 | + // config is good, so set it and pass it back |
|
| 892 | + $this->{$section}->{$name} = $config_obj; |
|
| 893 | + return $this->{$section}->{$name}; |
|
| 894 | + } |
|
| 895 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 896 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 897 | + // verify the newly created config object |
|
| 898 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 899 | + return $this->{$section}->{$name}; |
|
| 900 | + } else { |
|
| 901 | + EE_Error::add_error( |
|
| 902 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 903 | + __FILE__, |
|
| 904 | + __FUNCTION__, |
|
| 905 | + __LINE__ |
|
| 906 | + ); |
|
| 907 | + } |
|
| 908 | + return null; |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * get_config_option |
|
| 915 | + * |
|
| 916 | + * @access public |
|
| 917 | + * @param string $config_option_name |
|
| 918 | + * @return mixed EE_Config_Base | FALSE |
|
| 919 | + */ |
|
| 920 | + public function get_config_option($config_option_name = '') |
|
| 921 | + { |
|
| 922 | + // retrieve the wp-option for this config class. |
|
| 923 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 924 | + if (empty($config_option)) { |
|
| 925 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 926 | + } |
|
| 927 | + return $config_option; |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + |
|
| 932 | + /** |
|
| 933 | + * log |
|
| 934 | + * |
|
| 935 | + * @param string $config_option_name |
|
| 936 | + */ |
|
| 937 | + public static function log($config_option_name = '') |
|
| 938 | + { |
|
| 939 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 940 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 941 | + //copy incoming $_REQUEST and sanitize it so we can save it |
|
| 942 | + $_request = $_REQUEST; |
|
| 943 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 944 | + $config_log[(string)microtime(true)] = array( |
|
| 945 | + 'config_name' => $config_option_name, |
|
| 946 | + 'request' => $_request, |
|
| 947 | + ); |
|
| 948 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + |
|
| 954 | + /** |
|
| 955 | + * trim_log |
|
| 956 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 957 | + */ |
|
| 958 | + public static function trim_log() |
|
| 959 | + { |
|
| 960 | + if (! EE_Config::logging_enabled()) { |
|
| 961 | + return; |
|
| 962 | + } |
|
| 963 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 964 | + $log_length = count($config_log); |
|
| 965 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 966 | + ksort($config_log); |
|
| 967 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 968 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 969 | + } |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * get_page_for_posts |
|
| 976 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 977 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 978 | + * |
|
| 979 | + * @access public |
|
| 980 | + * @return string |
|
| 981 | + */ |
|
| 982 | + public static function get_page_for_posts() |
|
| 983 | + { |
|
| 984 | + $page_for_posts = get_option('page_for_posts'); |
|
| 985 | + if (! $page_for_posts) { |
|
| 986 | + return 'posts'; |
|
| 987 | + } |
|
| 988 | + /** @type WPDB $wpdb */ |
|
| 989 | + global $wpdb; |
|
| 990 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 991 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + |
|
| 995 | + |
|
| 996 | + /** |
|
| 997 | + * register_shortcodes_and_modules. |
|
| 998 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 999 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 1000 | + * so they can help trigger maintenance mode if it's needed |
|
| 1001 | + * |
|
| 1002 | + * @access public |
|
| 1003 | + * @return void |
|
| 1004 | + */ |
|
| 1005 | + public function register_shortcodes_and_modules() |
|
| 1006 | + { |
|
| 1007 | + // allow modules to set hooks for the rest of the system |
|
| 1008 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + |
|
| 1012 | + |
|
| 1013 | + /** |
|
| 1014 | + * initialize_shortcodes_and_modules |
|
| 1015 | + * meaning they can start adding their hooks to get stuff done |
|
| 1016 | + * |
|
| 1017 | + * @access public |
|
| 1018 | + * @return void |
|
| 1019 | + */ |
|
| 1020 | + public function initialize_shortcodes_and_modules() |
|
| 1021 | + { |
|
| 1022 | + // allow modules to set hooks for the rest of the system |
|
| 1023 | + $this->_initialize_modules(); |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * widgets_init |
|
| 1030 | + * |
|
| 1031 | + * @access private |
|
| 1032 | + * @return void |
|
| 1033 | + */ |
|
| 1034 | + public function widgets_init() |
|
| 1035 | + { |
|
| 1036 | + //only init widgets on admin pages when not in complete maintenance, and |
|
| 1037 | + //on frontend when not in any maintenance mode |
|
| 1038 | + if ( |
|
| 1039 | + ! EE_Maintenance_Mode::instance()->level() |
|
| 1040 | + || ( |
|
| 1041 | + is_admin() |
|
| 1042 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1043 | + ) |
|
| 1044 | + ) { |
|
| 1045 | + // grab list of installed widgets |
|
| 1046 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1047 | + // filter list of modules to register |
|
| 1048 | + $widgets_to_register = apply_filters( |
|
| 1049 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1050 | + $widgets_to_register |
|
| 1051 | + ); |
|
| 1052 | + if (! empty($widgets_to_register)) { |
|
| 1053 | + // cycle thru widget folders |
|
| 1054 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1055 | + // add to list of installed widget modules |
|
| 1056 | + EE_Config::register_ee_widget($widget_path); |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + // filter list of installed modules |
|
| 1060 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1061 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1062 | + EE_Registry::instance()->widgets |
|
| 1063 | + ); |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + /** |
|
| 1070 | + * register_ee_widget - makes core aware of this widget |
|
| 1071 | + * |
|
| 1072 | + * @access public |
|
| 1073 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1074 | + * @return void |
|
| 1075 | + */ |
|
| 1076 | + public static function register_ee_widget($widget_path = null) |
|
| 1077 | + { |
|
| 1078 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1079 | + $widget_ext = '.widget.php'; |
|
| 1080 | + // make all separators match |
|
| 1081 | + $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1082 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1083 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1084 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1085 | + $file_name = explode('.', basename($widget_path)); |
|
| 1086 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1087 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1088 | + // sanitize shortcode directory name |
|
| 1089 | + $widget = sanitize_key($widget); |
|
| 1090 | + // now we need to rebuild the shortcode path |
|
| 1091 | + $widget_path = explode(DS, $widget_path); |
|
| 1092 | + // remove last segment |
|
| 1093 | + array_pop($widget_path); |
|
| 1094 | + // glue it back together |
|
| 1095 | + $widget_path = implode(DS, $widget_path); |
|
| 1096 | + } else { |
|
| 1097 | + // grab and sanitize widget directory name |
|
| 1098 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1099 | + } |
|
| 1100 | + // create classname from widget directory name |
|
| 1101 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1102 | + // add class prefix |
|
| 1103 | + $widget_class = 'EEW_' . $widget; |
|
| 1104 | + // does the widget exist ? |
|
| 1105 | + if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1106 | + $msg = sprintf( |
|
| 1107 | + __( |
|
| 1108 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1109 | + 'event_espresso' |
|
| 1110 | + ), |
|
| 1111 | + $widget_class, |
|
| 1112 | + $widget_path . DS . $widget_class . $widget_ext |
|
| 1113 | + ); |
|
| 1114 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1115 | + return; |
|
| 1116 | + } |
|
| 1117 | + // load the widget class file |
|
| 1118 | + require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1119 | + // verify that class exists |
|
| 1120 | + if (! class_exists($widget_class)) { |
|
| 1121 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1122 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1123 | + return; |
|
| 1124 | + } |
|
| 1125 | + register_widget($widget_class); |
|
| 1126 | + // add to array of registered widgets |
|
| 1127 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + |
|
| 1131 | + |
|
| 1132 | + /** |
|
| 1133 | + * _register_modules |
|
| 1134 | + * |
|
| 1135 | + * @access private |
|
| 1136 | + * @return array |
|
| 1137 | + */ |
|
| 1138 | + private function _register_modules() |
|
| 1139 | + { |
|
| 1140 | + // grab list of installed modules |
|
| 1141 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1142 | + // filter list of modules to register |
|
| 1143 | + $modules_to_register = apply_filters( |
|
| 1144 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1145 | + $modules_to_register |
|
| 1146 | + ); |
|
| 1147 | + if (! empty($modules_to_register)) { |
|
| 1148 | + // loop through folders |
|
| 1149 | + foreach ($modules_to_register as $module_path) { |
|
| 1150 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1151 | + if ( |
|
| 1152 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1153 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1154 | + ) { |
|
| 1155 | + // add to list of installed modules |
|
| 1156 | + EE_Config::register_module($module_path); |
|
| 1157 | + } |
|
| 1158 | + } |
|
| 1159 | + } |
|
| 1160 | + // filter list of installed modules |
|
| 1161 | + return apply_filters( |
|
| 1162 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1163 | + EE_Registry::instance()->modules |
|
| 1164 | + ); |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + |
|
| 1168 | + |
|
| 1169 | + /** |
|
| 1170 | + * register_module - makes core aware of this module |
|
| 1171 | + * |
|
| 1172 | + * @access public |
|
| 1173 | + * @param string $module_path - full path up to and including module folder |
|
| 1174 | + * @return bool |
|
| 1175 | + */ |
|
| 1176 | + public static function register_module($module_path = null) |
|
| 1177 | + { |
|
| 1178 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1179 | + $module_ext = '.module.php'; |
|
| 1180 | + // make all separators match |
|
| 1181 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1182 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1183 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1184 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1185 | + $module_file = explode('.', basename($module_path)); |
|
| 1186 | + // now we need to rebuild the shortcode path |
|
| 1187 | + $module_path = explode(DS, $module_path); |
|
| 1188 | + // remove last segment |
|
| 1189 | + array_pop($module_path); |
|
| 1190 | + // glue it back together |
|
| 1191 | + $module_path = implode(DS, $module_path) . DS; |
|
| 1192 | + // take first segment from file name pieces and sanitize it |
|
| 1193 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1194 | + // ensure class prefix is added |
|
| 1195 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1196 | + } else { |
|
| 1197 | + // we need to generate the filename based off of the folder name |
|
| 1198 | + // grab and sanitize module name |
|
| 1199 | + $module = strtolower(basename($module_path)); |
|
| 1200 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1201 | + // like trailingslashit() |
|
| 1202 | + $module_path = rtrim($module_path, DS) . DS; |
|
| 1203 | + // create classname from module directory name |
|
| 1204 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1205 | + // add class prefix |
|
| 1206 | + $module_class = 'EED_' . $module; |
|
| 1207 | + } |
|
| 1208 | + // does the module exist ? |
|
| 1209 | + if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1210 | + $msg = sprintf( |
|
| 1211 | + __( |
|
| 1212 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1213 | + 'event_espresso' |
|
| 1214 | + ), |
|
| 1215 | + $module |
|
| 1216 | + ); |
|
| 1217 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1218 | + return false; |
|
| 1219 | + } |
|
| 1220 | + // load the module class file |
|
| 1221 | + require_once($module_path . $module_class . $module_ext); |
|
| 1222 | + // verify that class exists |
|
| 1223 | + if (! class_exists($module_class)) { |
|
| 1224 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1225 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1226 | + return false; |
|
| 1227 | + } |
|
| 1228 | + // add to array of registered modules |
|
| 1229 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1230 | + do_action( |
|
| 1231 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1232 | + $module_class, |
|
| 1233 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1234 | + ); |
|
| 1235 | + return true; |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * _initialize_modules |
|
| 1242 | + * allow modules to set hooks for the rest of the system |
|
| 1243 | + * |
|
| 1244 | + * @access private |
|
| 1245 | + * @return void |
|
| 1246 | + */ |
|
| 1247 | + private function _initialize_modules() |
|
| 1248 | + { |
|
| 1249 | + // cycle thru shortcode folders |
|
| 1250 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1251 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1252 | + // which set hooks ? |
|
| 1253 | + if (is_admin()) { |
|
| 1254 | + // fire immediately |
|
| 1255 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1256 | + } else { |
|
| 1257 | + // delay until other systems are online |
|
| 1258 | + add_action( |
|
| 1259 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1260 | + array($module_class, 'set_hooks') |
|
| 1261 | + ); |
|
| 1262 | + } |
|
| 1263 | + } |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + |
|
| 1267 | + |
|
| 1268 | + /** |
|
| 1269 | + * register_route - adds module method routes to route_map |
|
| 1270 | + * |
|
| 1271 | + * @access public |
|
| 1272 | + * @param string $route - "pretty" public alias for module method |
|
| 1273 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1274 | + * @param string $method_name - the actual module method to be routed to |
|
| 1275 | + * @param string $key - url param key indicating a route is being called |
|
| 1276 | + * @return bool |
|
| 1277 | + */ |
|
| 1278 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1279 | + { |
|
| 1280 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1281 | + $module = str_replace('EED_', '', $module); |
|
| 1282 | + $module_class = 'EED_' . $module; |
|
| 1283 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1284 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1285 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1286 | + return false; |
|
| 1287 | + } |
|
| 1288 | + if (empty($route)) { |
|
| 1289 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1290 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1291 | + return false; |
|
| 1292 | + } |
|
| 1293 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1294 | + $msg = sprintf( |
|
| 1295 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1296 | + $route |
|
| 1297 | + ); |
|
| 1298 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1299 | + return false; |
|
| 1300 | + } |
|
| 1301 | + EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1302 | + return true; |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + |
|
| 1306 | + |
|
| 1307 | + /** |
|
| 1308 | + * get_route - get module method route |
|
| 1309 | + * |
|
| 1310 | + * @access public |
|
| 1311 | + * @param string $route - "pretty" public alias for module method |
|
| 1312 | + * @param string $key - url param key indicating a route is being called |
|
| 1313 | + * @return string |
|
| 1314 | + */ |
|
| 1315 | + public static function get_route($route = null, $key = 'ee') |
|
| 1316 | + { |
|
| 1317 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1318 | + $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1319 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1320 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1321 | + } |
|
| 1322 | + return null; |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + |
|
| 1326 | + |
|
| 1327 | + /** |
|
| 1328 | + * get_routes - get ALL module method routes |
|
| 1329 | + * |
|
| 1330 | + * @access public |
|
| 1331 | + * @return array |
|
| 1332 | + */ |
|
| 1333 | + public static function get_routes() |
|
| 1334 | + { |
|
| 1335 | + return EE_Config::$_module_route_map; |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + |
|
| 1339 | + |
|
| 1340 | + /** |
|
| 1341 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1342 | + * |
|
| 1343 | + * @access public |
|
| 1344 | + * @param string $route - "pretty" public alias for module method |
|
| 1345 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1346 | + * class, allows different forwards to be served based on status |
|
| 1347 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1348 | + * @param string $key - url param key indicating a route is being called |
|
| 1349 | + * @return bool |
|
| 1350 | + */ |
|
| 1351 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1352 | + { |
|
| 1353 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1354 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1355 | + $msg = sprintf( |
|
| 1356 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1357 | + $route |
|
| 1358 | + ); |
|
| 1359 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1360 | + return false; |
|
| 1361 | + } |
|
| 1362 | + if (empty($forward)) { |
|
| 1363 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1364 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1365 | + return false; |
|
| 1366 | + } |
|
| 1367 | + if (is_array($forward)) { |
|
| 1368 | + if (! isset($forward[1])) { |
|
| 1369 | + $msg = sprintf( |
|
| 1370 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1371 | + $route |
|
| 1372 | + ); |
|
| 1373 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1374 | + return false; |
|
| 1375 | + } |
|
| 1376 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1377 | + $msg = sprintf( |
|
| 1378 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1379 | + $forward[1], |
|
| 1380 | + $route |
|
| 1381 | + ); |
|
| 1382 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1383 | + return false; |
|
| 1384 | + } |
|
| 1385 | + } else if (! function_exists($forward)) { |
|
| 1386 | + $msg = sprintf( |
|
| 1387 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1388 | + $forward, |
|
| 1389 | + $route |
|
| 1390 | + ); |
|
| 1391 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1392 | + return false; |
|
| 1393 | + } |
|
| 1394 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1395 | + return true; |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + |
|
| 1399 | + |
|
| 1400 | + /** |
|
| 1401 | + * get_forward - get forwarding route |
|
| 1402 | + * |
|
| 1403 | + * @access public |
|
| 1404 | + * @param string $route - "pretty" public alias for module method |
|
| 1405 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1406 | + * allows different forwards to be served based on status |
|
| 1407 | + * @param string $key - url param key indicating a route is being called |
|
| 1408 | + * @return string |
|
| 1409 | + */ |
|
| 1410 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1411 | + { |
|
| 1412 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1413 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1414 | + return apply_filters( |
|
| 1415 | + 'FHEE__EE_Config__get_forward', |
|
| 1416 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1417 | + $route, |
|
| 1418 | + $status |
|
| 1419 | + ); |
|
| 1420 | + } |
|
| 1421 | + return null; |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + |
|
| 1425 | + |
|
| 1426 | + /** |
|
| 1427 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1428 | + * results |
|
| 1429 | + * |
|
| 1430 | + * @access public |
|
| 1431 | + * @param string $route - "pretty" public alias for module method |
|
| 1432 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1433 | + * allows different views to be served based on status |
|
| 1434 | + * @param string $view |
|
| 1435 | + * @param string $key - url param key indicating a route is being called |
|
| 1436 | + * @return bool |
|
| 1437 | + */ |
|
| 1438 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1439 | + { |
|
| 1440 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1441 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1442 | + $msg = sprintf( |
|
| 1443 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1444 | + $route |
|
| 1445 | + ); |
|
| 1446 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1447 | + return false; |
|
| 1448 | + } |
|
| 1449 | + if (! is_readable($view)) { |
|
| 1450 | + $msg = sprintf( |
|
| 1451 | + __( |
|
| 1452 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1453 | + 'event_espresso' |
|
| 1454 | + ), |
|
| 1455 | + $view |
|
| 1456 | + ); |
|
| 1457 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1458 | + return false; |
|
| 1459 | + } |
|
| 1460 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1461 | + return true; |
|
| 1462 | + } |
|
| 1463 | + |
|
| 1464 | + |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * get_view - get view for route and status |
|
| 1468 | + * |
|
| 1469 | + * @access public |
|
| 1470 | + * @param string $route - "pretty" public alias for module method |
|
| 1471 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1472 | + * allows different views to be served based on status |
|
| 1473 | + * @param string $key - url param key indicating a route is being called |
|
| 1474 | + * @return string |
|
| 1475 | + */ |
|
| 1476 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1477 | + { |
|
| 1478 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1479 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1480 | + return apply_filters( |
|
| 1481 | + 'FHEE__EE_Config__get_view', |
|
| 1482 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1483 | + $route, |
|
| 1484 | + $status |
|
| 1485 | + ); |
|
| 1486 | + } |
|
| 1487 | + return null; |
|
| 1488 | + } |
|
| 1489 | + |
|
| 1490 | + |
|
| 1491 | + |
|
| 1492 | + public function update_addon_option_names() |
|
| 1493 | + { |
|
| 1494 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + |
|
| 1498 | + |
|
| 1499 | + public function shutdown() |
|
| 1500 | + { |
|
| 1501 | + $this->update_addon_option_names(); |
|
| 1502 | + } |
|
| 1503 | + |
|
| 1504 | + |
|
| 1505 | + |
|
| 1506 | + /** |
|
| 1507 | + * @return LegacyShortcodesManager |
|
| 1508 | + */ |
|
| 1509 | + public static function getLegacyShortcodesManager() |
|
| 1510 | + { |
|
| 1511 | + |
|
| 1512 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1513 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1514 | + EE_Registry::instance() |
|
| 1515 | + ); |
|
| 1516 | + } |
|
| 1517 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + |
|
| 1521 | + |
|
| 1522 | + /** |
|
| 1523 | + * register_shortcode - makes core aware of this shortcode |
|
| 1524 | + * |
|
| 1525 | + * @deprecated 4.9.26 |
|
| 1526 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1527 | + * @return bool |
|
| 1528 | + */ |
|
| 1529 | + public static function register_shortcode($shortcode_path = null) |
|
| 1530 | + { |
|
| 1531 | + EE_Error::doing_it_wrong( |
|
| 1532 | + __METHOD__, |
|
| 1533 | + __( |
|
| 1534 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1535 | + 'event_espresso' |
|
| 1536 | + ), |
|
| 1537 | + '4.9.26' |
|
| 1538 | + ); |
|
| 1539 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1540 | + } |
|
| 21 | 1541 | |
| 22 | - const LOG_NAME = 'ee_config_log'; |
|
| 23 | 1542 | |
| 24 | - const LOG_LENGTH = 100; |
|
| 25 | 1543 | |
| 26 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * instance of the EE_Config object |
|
| 31 | - * |
|
| 32 | - * @var EE_Config $_instance |
|
| 33 | - * @access private |
|
| 34 | - */ |
|
| 35 | - private static $_instance; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var boolean $_logging_enabled |
|
| 39 | - */ |
|
| 40 | - private static $_logging_enabled = false; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 44 | - */ |
|
| 45 | - private $legacy_shortcodes_manager; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * An StdClass whose property names are addon slugs, |
|
| 49 | - * and values are their config classes |
|
| 50 | - * |
|
| 51 | - * @var StdClass |
|
| 52 | - */ |
|
| 53 | - public $addons; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var EE_Admin_Config |
|
| 57 | - */ |
|
| 58 | - public $admin; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var EE_Core_Config |
|
| 62 | - */ |
|
| 63 | - public $core; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var EE_Currency_Config |
|
| 67 | - */ |
|
| 68 | - public $currency; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var EE_Organization_Config |
|
| 72 | - */ |
|
| 73 | - public $organization; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var EE_Registration_Config |
|
| 77 | - */ |
|
| 78 | - public $registration; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @var EE_Template_Config |
|
| 82 | - */ |
|
| 83 | - public $template_settings; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Holds EE environment values. |
|
| 87 | - * |
|
| 88 | - * @var EE_Environment_Config |
|
| 89 | - */ |
|
| 90 | - public $environment; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * settings pertaining to Google maps |
|
| 94 | - * |
|
| 95 | - * @var EE_Map_Config |
|
| 96 | - */ |
|
| 97 | - public $map_settings; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * settings pertaining to Taxes |
|
| 101 | - * |
|
| 102 | - * @var EE_Tax_Config |
|
| 103 | - */ |
|
| 104 | - public $tax_settings; |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Settings pertaining to global messages settings. |
|
| 109 | - * |
|
| 110 | - * @var EE_Messages_Config |
|
| 111 | - */ |
|
| 112 | - public $messages; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @deprecated |
|
| 116 | - * @var EE_Gateway_Config |
|
| 117 | - */ |
|
| 118 | - public $gateway; |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @var array $_addon_option_names |
|
| 122 | - * @access private |
|
| 123 | - */ |
|
| 124 | - private $_addon_option_names = array(); |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @var array $_module_route_map |
|
| 128 | - * @access private |
|
| 129 | - */ |
|
| 130 | - private static $_module_route_map = array(); |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @var array $_module_forward_map |
|
| 134 | - * @access private |
|
| 135 | - */ |
|
| 136 | - private static $_module_forward_map = array(); |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @var array $_module_view_map |
|
| 140 | - * @access private |
|
| 141 | - */ |
|
| 142 | - private static $_module_view_map = array(); |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @singleton method used to instantiate class object |
|
| 148 | - * @access public |
|
| 149 | - * @return EE_Config instance |
|
| 150 | - */ |
|
| 151 | - public static function instance() |
|
| 152 | - { |
|
| 153 | - // check if class object is instantiated, and instantiated properly |
|
| 154 | - if (! self::$_instance instanceof EE_Config) { |
|
| 155 | - self::$_instance = new self(); |
|
| 156 | - } |
|
| 157 | - return self::$_instance; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Resets the config |
|
| 164 | - * |
|
| 165 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 166 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 167 | - * reflect its state in the database |
|
| 168 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 169 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 170 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 171 | - * site was put into maintenance mode) |
|
| 172 | - * @return EE_Config |
|
| 173 | - */ |
|
| 174 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 175 | - { |
|
| 176 | - if (self::$_instance instanceof EE_Config) { |
|
| 177 | - if ($hard_reset) { |
|
| 178 | - self::$_instance->legacy_shortcodes_manager = null; |
|
| 179 | - self::$_instance->_addon_option_names = array(); |
|
| 180 | - self::$_instance->_initialize_config(); |
|
| 181 | - self::$_instance->update_espresso_config(); |
|
| 182 | - } |
|
| 183 | - self::$_instance->update_addon_option_names(); |
|
| 184 | - } |
|
| 185 | - self::$_instance = null; |
|
| 186 | - //we don't need to reset the static properties imo because those should |
|
| 187 | - //only change when a module is added or removed. Currently we don't |
|
| 188 | - //support removing a module during a request when it previously existed |
|
| 189 | - if ($reinstantiate) { |
|
| 190 | - return self::instance(); |
|
| 191 | - } else { |
|
| 192 | - return null; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * class constructor |
|
| 200 | - * |
|
| 201 | - * @access private |
|
| 202 | - */ |
|
| 203 | - private function __construct() |
|
| 204 | - { |
|
| 205 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 206 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 207 | - // setup empty config classes |
|
| 208 | - $this->_initialize_config(); |
|
| 209 | - // load existing EE site settings |
|
| 210 | - $this->_load_core_config(); |
|
| 211 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 212 | - $this->_verify_config(); |
|
| 213 | - // register shortcodes and modules |
|
| 214 | - add_action( |
|
| 215 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 216 | - array($this, 'register_shortcodes_and_modules'), |
|
| 217 | - 999 |
|
| 218 | - ); |
|
| 219 | - // initialize shortcodes and modules |
|
| 220 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 221 | - // register widgets |
|
| 222 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 223 | - // shutdown |
|
| 224 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 225 | - // construct__end hook |
|
| 226 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 227 | - // hardcoded hack |
|
| 228 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @return boolean |
|
| 235 | - */ |
|
| 236 | - public static function logging_enabled() |
|
| 237 | - { |
|
| 238 | - return self::$_logging_enabled; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * use to get the current theme if needed from static context |
|
| 245 | - * |
|
| 246 | - * @return string current theme set. |
|
| 247 | - */ |
|
| 248 | - public static function get_current_theme() |
|
| 249 | - { |
|
| 250 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 251 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * _initialize_config |
|
| 258 | - * |
|
| 259 | - * @access private |
|
| 260 | - * @return void |
|
| 261 | - */ |
|
| 262 | - private function _initialize_config() |
|
| 263 | - { |
|
| 264 | - EE_Config::trim_log(); |
|
| 265 | - //set defaults |
|
| 266 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 267 | - $this->addons = new stdClass(); |
|
| 268 | - // set _module_route_map |
|
| 269 | - EE_Config::$_module_route_map = array(); |
|
| 270 | - // set _module_forward_map |
|
| 271 | - EE_Config::$_module_forward_map = array(); |
|
| 272 | - // set _module_view_map |
|
| 273 | - EE_Config::$_module_view_map = array(); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * load core plugin configuration |
|
| 280 | - * |
|
| 281 | - * @access private |
|
| 282 | - * @return void |
|
| 283 | - */ |
|
| 284 | - private function _load_core_config() |
|
| 285 | - { |
|
| 286 | - // load_core_config__start hook |
|
| 287 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 288 | - $espresso_config = $this->get_espresso_config(); |
|
| 289 | - foreach ($espresso_config as $config => $settings) { |
|
| 290 | - // load_core_config__start hook |
|
| 291 | - $settings = apply_filters( |
|
| 292 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 293 | - $settings, |
|
| 294 | - $config, |
|
| 295 | - $this |
|
| 296 | - ); |
|
| 297 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 298 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 299 | - //call configs populate method to ensure any defaults are set for empty values. |
|
| 300 | - if (method_exists($settings, 'populate')) { |
|
| 301 | - $this->{$config}->populate(); |
|
| 302 | - } |
|
| 303 | - if (method_exists($settings, 'do_hooks')) { |
|
| 304 | - $this->{$config}->do_hooks(); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 309 | - $this->update_espresso_config(); |
|
| 310 | - } |
|
| 311 | - // load_core_config__end hook |
|
| 312 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * _verify_config |
|
| 319 | - * |
|
| 320 | - * @access protected |
|
| 321 | - * @return void |
|
| 322 | - */ |
|
| 323 | - protected function _verify_config() |
|
| 324 | - { |
|
| 325 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 326 | - ? $this->core |
|
| 327 | - : new EE_Core_Config(); |
|
| 328 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 329 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 330 | - ? $this->organization |
|
| 331 | - : new EE_Organization_Config(); |
|
| 332 | - $this->organization = apply_filters( |
|
| 333 | - 'FHEE__EE_Config___initialize_config__organization', |
|
| 334 | - $this->organization |
|
| 335 | - ); |
|
| 336 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 337 | - ? $this->currency |
|
| 338 | - : new EE_Currency_Config(); |
|
| 339 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 340 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 341 | - ? $this->registration |
|
| 342 | - : new EE_Registration_Config(); |
|
| 343 | - $this->registration = apply_filters( |
|
| 344 | - 'FHEE__EE_Config___initialize_config__registration', |
|
| 345 | - $this->registration |
|
| 346 | - ); |
|
| 347 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 348 | - ? $this->admin |
|
| 349 | - : new EE_Admin_Config(); |
|
| 350 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 351 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 352 | - ? $this->template_settings |
|
| 353 | - : new EE_Template_Config(); |
|
| 354 | - $this->template_settings = apply_filters( |
|
| 355 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 356 | - $this->template_settings |
|
| 357 | - ); |
|
| 358 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 359 | - ? $this->map_settings |
|
| 360 | - : new EE_Map_Config(); |
|
| 361 | - $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
| 362 | - $this->map_settings); |
|
| 363 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 364 | - ? $this->environment |
|
| 365 | - : new EE_Environment_Config(); |
|
| 366 | - $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
| 367 | - $this->environment); |
|
| 368 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 369 | - ? $this->tax_settings |
|
| 370 | - : new EE_Tax_Config(); |
|
| 371 | - $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
| 372 | - $this->tax_settings); |
|
| 373 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 374 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 375 | - ? $this->messages |
|
| 376 | - : new EE_Messages_Config(); |
|
| 377 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 378 | - ? $this->gateway |
|
| 379 | - : new EE_Gateway_Config(); |
|
| 380 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 381 | - $this->legacy_shortcodes_manager = null; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * get_espresso_config |
|
| 387 | - * |
|
| 388 | - * @access public |
|
| 389 | - * @return array of espresso config stuff |
|
| 390 | - */ |
|
| 391 | - public function get_espresso_config() |
|
| 392 | - { |
|
| 393 | - // grab espresso configuration |
|
| 394 | - return apply_filters( |
|
| 395 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 396 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 397 | - ); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * double_check_config_comparison |
|
| 404 | - * |
|
| 405 | - * @access public |
|
| 406 | - * @param string $option |
|
| 407 | - * @param $old_value |
|
| 408 | - * @param $value |
|
| 409 | - */ |
|
| 410 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 411 | - { |
|
| 412 | - // make sure we're checking the ee config |
|
| 413 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 414 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 415 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 416 | - if ($value != $old_value) { |
|
| 417 | - // if they are NOT the same, then remove the hook, |
|
| 418 | - // which means the subsequent update results will be based solely on the update query results |
|
| 419 | - // the reason we do this is because, as stated above, |
|
| 420 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 421 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 422 | - // If values are found to match their previous old value, |
|
| 423 | - // then WP bails before performing any update. |
|
| 424 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 425 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 426 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 427 | - // MySQL MAY ALSO NOT perform the update because |
|
| 428 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 429 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 430 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 431 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * update_espresso_config |
|
| 440 | - * |
|
| 441 | - * @access public |
|
| 442 | - */ |
|
| 443 | - protected function _reset_espresso_addon_config() |
|
| 444 | - { |
|
| 445 | - $this->_addon_option_names = array(); |
|
| 446 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 447 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 448 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 449 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 450 | - } |
|
| 451 | - $this->addons->{$addon_name} = null; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * update_espresso_config |
|
| 459 | - * |
|
| 460 | - * @access public |
|
| 461 | - * @param bool $add_success |
|
| 462 | - * @param bool $add_error |
|
| 463 | - * @return bool |
|
| 464 | - */ |
|
| 465 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 466 | - { |
|
| 467 | - // don't allow config updates during WP heartbeats |
|
| 468 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 469 | - return false; |
|
| 470 | - } |
|
| 471 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 472 | - //$clone = clone( self::$_instance ); |
|
| 473 | - //self::$_instance = NULL; |
|
| 474 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 475 | - $this->_reset_espresso_addon_config(); |
|
| 476 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 477 | - // but BEFORE the actual update occurs |
|
| 478 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 479 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 480 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 481 | - $this->legacy_shortcodes_manager = null; |
|
| 482 | - // now update "ee_config" |
|
| 483 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 484 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 485 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 486 | - // if not saved... check if the hook we just added still exists; |
|
| 487 | - // if it does, it means one of two things: |
|
| 488 | - // that update_option bailed at the ( $value === $old_value ) conditional, |
|
| 489 | - // or... |
|
| 490 | - // the db update query returned 0 rows affected |
|
| 491 | - // (probably because the data value was the same from it's perspective) |
|
| 492 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 493 | - // but just means no update occurred, so don't display an error to the user. |
|
| 494 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 495 | - // then it means that something truly went wrong |
|
| 496 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 497 | - // remove our action since we don't want it in the system anymore |
|
| 498 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 499 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 500 | - //self::$_instance = $clone; |
|
| 501 | - //unset( $clone ); |
|
| 502 | - // if config remains the same or was updated successfully |
|
| 503 | - if ($saved) { |
|
| 504 | - if ($add_success) { |
|
| 505 | - EE_Error::add_success( |
|
| 506 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 507 | - __FILE__, |
|
| 508 | - __FUNCTION__, |
|
| 509 | - __LINE__ |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - return true; |
|
| 513 | - } else { |
|
| 514 | - if ($add_error) { |
|
| 515 | - EE_Error::add_error( |
|
| 516 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 517 | - __FILE__, |
|
| 518 | - __FUNCTION__, |
|
| 519 | - __LINE__ |
|
| 520 | - ); |
|
| 521 | - } |
|
| 522 | - return false; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * _verify_config_params |
|
| 530 | - * |
|
| 531 | - * @access private |
|
| 532 | - * @param string $section |
|
| 533 | - * @param string $name |
|
| 534 | - * @param string $config_class |
|
| 535 | - * @param EE_Config_Base $config_obj |
|
| 536 | - * @param array $tests_to_run |
|
| 537 | - * @param bool $display_errors |
|
| 538 | - * @return bool TRUE on success, FALSE on fail |
|
| 539 | - */ |
|
| 540 | - private function _verify_config_params( |
|
| 541 | - $section = '', |
|
| 542 | - $name = '', |
|
| 543 | - $config_class = '', |
|
| 544 | - $config_obj = null, |
|
| 545 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 546 | - $display_errors = true |
|
| 547 | - ) { |
|
| 548 | - try { |
|
| 549 | - foreach ($tests_to_run as $test) { |
|
| 550 | - switch ($test) { |
|
| 551 | - // TEST #1 : check that section was set |
|
| 552 | - case 1 : |
|
| 553 | - if (empty($section)) { |
|
| 554 | - if ($display_errors) { |
|
| 555 | - throw new EE_Error( |
|
| 556 | - sprintf( |
|
| 557 | - __( |
|
| 558 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 559 | - 'event_espresso' |
|
| 560 | - ), |
|
| 561 | - $config_class |
|
| 562 | - ) |
|
| 563 | - ); |
|
| 564 | - } |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - break; |
|
| 568 | - // TEST #2 : check that settings section exists |
|
| 569 | - case 2 : |
|
| 570 | - if (! isset($this->{$section})) { |
|
| 571 | - if ($display_errors) { |
|
| 572 | - throw new EE_Error( |
|
| 573 | - sprintf( |
|
| 574 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 575 | - $section |
|
| 576 | - ) |
|
| 577 | - ); |
|
| 578 | - } |
|
| 579 | - return false; |
|
| 580 | - } |
|
| 581 | - break; |
|
| 582 | - // TEST #3 : check that section is the proper format |
|
| 583 | - case 3 : |
|
| 584 | - if ( |
|
| 585 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 586 | - ) { |
|
| 587 | - if ($display_errors) { |
|
| 588 | - throw new EE_Error( |
|
| 589 | - sprintf( |
|
| 590 | - __( |
|
| 591 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 592 | - 'event_espresso' |
|
| 593 | - ), |
|
| 594 | - $section |
|
| 595 | - ) |
|
| 596 | - ); |
|
| 597 | - } |
|
| 598 | - return false; |
|
| 599 | - } |
|
| 600 | - break; |
|
| 601 | - // TEST #4 : check that config section name has been set |
|
| 602 | - case 4 : |
|
| 603 | - if (empty($name)) { |
|
| 604 | - if ($display_errors) { |
|
| 605 | - throw new EE_Error( |
|
| 606 | - __( |
|
| 607 | - 'No name has been provided for the specific configuration section.', |
|
| 608 | - 'event_espresso' |
|
| 609 | - ) |
|
| 610 | - ); |
|
| 611 | - } |
|
| 612 | - return false; |
|
| 613 | - } |
|
| 614 | - break; |
|
| 615 | - // TEST #5 : check that a config class name has been set |
|
| 616 | - case 5 : |
|
| 617 | - if (empty($config_class)) { |
|
| 618 | - if ($display_errors) { |
|
| 619 | - throw new EE_Error( |
|
| 620 | - __( |
|
| 621 | - 'No class name has been provided for the specific configuration section.', |
|
| 622 | - 'event_espresso' |
|
| 623 | - ) |
|
| 624 | - ); |
|
| 625 | - } |
|
| 626 | - return false; |
|
| 627 | - } |
|
| 628 | - break; |
|
| 629 | - // TEST #6 : verify config class is accessible |
|
| 630 | - case 6 : |
|
| 631 | - if (! class_exists($config_class)) { |
|
| 632 | - if ($display_errors) { |
|
| 633 | - throw new EE_Error( |
|
| 634 | - sprintf( |
|
| 635 | - __( |
|
| 636 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 637 | - 'event_espresso' |
|
| 638 | - ), |
|
| 639 | - $config_class |
|
| 640 | - ) |
|
| 641 | - ); |
|
| 642 | - } |
|
| 643 | - return false; |
|
| 644 | - } |
|
| 645 | - break; |
|
| 646 | - // TEST #7 : check that config has even been set |
|
| 647 | - case 7 : |
|
| 648 | - if (! isset($this->{$section}->{$name})) { |
|
| 649 | - if ($display_errors) { |
|
| 650 | - throw new EE_Error( |
|
| 651 | - sprintf( |
|
| 652 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 653 | - $section, |
|
| 654 | - $name |
|
| 655 | - ) |
|
| 656 | - ); |
|
| 657 | - } |
|
| 658 | - return false; |
|
| 659 | - } else { |
|
| 660 | - // and make sure it's not serialized |
|
| 661 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 662 | - } |
|
| 663 | - break; |
|
| 664 | - // TEST #8 : check that config is the requested type |
|
| 665 | - case 8 : |
|
| 666 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 667 | - if ($display_errors) { |
|
| 668 | - throw new EE_Error( |
|
| 669 | - sprintf( |
|
| 670 | - __( |
|
| 671 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 672 | - 'event_espresso' |
|
| 673 | - ), |
|
| 674 | - $section, |
|
| 675 | - $name, |
|
| 676 | - $config_class |
|
| 677 | - ) |
|
| 678 | - ); |
|
| 679 | - } |
|
| 680 | - return false; |
|
| 681 | - } |
|
| 682 | - break; |
|
| 683 | - // TEST #9 : verify config object |
|
| 684 | - case 9 : |
|
| 685 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 686 | - if ($display_errors) { |
|
| 687 | - throw new EE_Error( |
|
| 688 | - sprintf( |
|
| 689 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 690 | - print_r($config_obj, true) |
|
| 691 | - ) |
|
| 692 | - ); |
|
| 693 | - } |
|
| 694 | - return false; |
|
| 695 | - } |
|
| 696 | - break; |
|
| 697 | - } |
|
| 698 | - } |
|
| 699 | - } catch (EE_Error $e) { |
|
| 700 | - $e->get_error(); |
|
| 701 | - } |
|
| 702 | - // you have successfully run the gauntlet |
|
| 703 | - return true; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * _generate_config_option_name |
|
| 710 | - * |
|
| 711 | - * @access protected |
|
| 712 | - * @param string $section |
|
| 713 | - * @param string $name |
|
| 714 | - * @return string |
|
| 715 | - */ |
|
| 716 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 717 | - { |
|
| 718 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * _set_config_class |
|
| 725 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 726 | - * |
|
| 727 | - * @access private |
|
| 728 | - * @param string $config_class |
|
| 729 | - * @param string $name |
|
| 730 | - * @return string |
|
| 731 | - */ |
|
| 732 | - private function _set_config_class($config_class = '', $name = '') |
|
| 733 | - { |
|
| 734 | - return ! empty($config_class) |
|
| 735 | - ? $config_class |
|
| 736 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * set_config |
|
| 743 | - * |
|
| 744 | - * @access protected |
|
| 745 | - * @param string $section |
|
| 746 | - * @param string $name |
|
| 747 | - * @param string $config_class |
|
| 748 | - * @param EE_Config_Base $config_obj |
|
| 749 | - * @return EE_Config_Base |
|
| 750 | - */ |
|
| 751 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 752 | - { |
|
| 753 | - // ensure config class is set to something |
|
| 754 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 755 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 756 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 757 | - return null; |
|
| 758 | - } |
|
| 759 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 760 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 761 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 762 | - $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 763 | - $this->update_addon_option_names(); |
|
| 764 | - } |
|
| 765 | - // verify the incoming config object but suppress errors |
|
| 766 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 767 | - $config_obj = new $config_class(); |
|
| 768 | - } |
|
| 769 | - if (get_option($config_option_name)) { |
|
| 770 | - EE_Config::log($config_option_name); |
|
| 771 | - update_option($config_option_name, $config_obj); |
|
| 772 | - $this->{$section}->{$name} = $config_obj; |
|
| 773 | - return $this->{$section}->{$name}; |
|
| 774 | - } else { |
|
| 775 | - // create a wp-option for this config |
|
| 776 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 777 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 778 | - return $this->{$section}->{$name}; |
|
| 779 | - } else { |
|
| 780 | - EE_Error::add_error( |
|
| 781 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 782 | - __FILE__, |
|
| 783 | - __FUNCTION__, |
|
| 784 | - __LINE__ |
|
| 785 | - ); |
|
| 786 | - return null; |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * update_config |
|
| 795 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 796 | - * |
|
| 797 | - * @access public |
|
| 798 | - * @param string $section |
|
| 799 | - * @param string $name |
|
| 800 | - * @param EE_Config_Base|string $config_obj |
|
| 801 | - * @param bool $throw_errors |
|
| 802 | - * @return bool |
|
| 803 | - */ |
|
| 804 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 805 | - { |
|
| 806 | - // don't allow config updates during WP heartbeats |
|
| 807 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 808 | - return false; |
|
| 809 | - } |
|
| 810 | - $config_obj = maybe_unserialize($config_obj); |
|
| 811 | - // get class name of the incoming object |
|
| 812 | - $config_class = get_class($config_obj); |
|
| 813 | - // run tests 1-5 and 9 to verify config |
|
| 814 | - if (! $this->_verify_config_params( |
|
| 815 | - $section, |
|
| 816 | - $name, |
|
| 817 | - $config_class, |
|
| 818 | - $config_obj, |
|
| 819 | - array(1, 2, 3, 4, 7, 9) |
|
| 820 | - ) |
|
| 821 | - ) { |
|
| 822 | - return false; |
|
| 823 | - } |
|
| 824 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 825 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 826 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 827 | - // save new config to db |
|
| 828 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 829 | - return true; |
|
| 830 | - } |
|
| 831 | - } else { |
|
| 832 | - // first check if the record already exists |
|
| 833 | - $existing_config = get_option($config_option_name); |
|
| 834 | - $config_obj = serialize($config_obj); |
|
| 835 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 836 | - if ($existing_config == $config_obj) { |
|
| 837 | - $this->{$section}->{$name} = $config_obj; |
|
| 838 | - return true; |
|
| 839 | - } else if (update_option($config_option_name, $config_obj)) { |
|
| 840 | - EE_Config::log($config_option_name); |
|
| 841 | - // update wp-option for this config class |
|
| 842 | - $this->{$section}->{$name} = $config_obj; |
|
| 843 | - return true; |
|
| 844 | - } elseif ($throw_errors) { |
|
| 845 | - EE_Error::add_error( |
|
| 846 | - sprintf( |
|
| 847 | - __( |
|
| 848 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 849 | - 'event_espresso' |
|
| 850 | - ), |
|
| 851 | - $config_class, |
|
| 852 | - 'EE_Config->' . $section . '->' . $name |
|
| 853 | - ), |
|
| 854 | - __FILE__, |
|
| 855 | - __FUNCTION__, |
|
| 856 | - __LINE__ |
|
| 857 | - ); |
|
| 858 | - } |
|
| 859 | - } |
|
| 860 | - return false; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * get_config |
|
| 867 | - * |
|
| 868 | - * @access public |
|
| 869 | - * @param string $section |
|
| 870 | - * @param string $name |
|
| 871 | - * @param string $config_class |
|
| 872 | - * @return mixed EE_Config_Base | NULL |
|
| 873 | - */ |
|
| 874 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 875 | - { |
|
| 876 | - // ensure config class is set to something |
|
| 877 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 878 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 879 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 880 | - return null; |
|
| 881 | - } |
|
| 882 | - // now test if the requested config object exists, but suppress errors |
|
| 883 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 884 | - // config already exists, so pass it back |
|
| 885 | - return $this->{$section}->{$name}; |
|
| 886 | - } |
|
| 887 | - // load config option from db if it exists |
|
| 888 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 889 | - // verify the newly retrieved config object, but suppress errors |
|
| 890 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 891 | - // config is good, so set it and pass it back |
|
| 892 | - $this->{$section}->{$name} = $config_obj; |
|
| 893 | - return $this->{$section}->{$name}; |
|
| 894 | - } |
|
| 895 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 896 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 897 | - // verify the newly created config object |
|
| 898 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 899 | - return $this->{$section}->{$name}; |
|
| 900 | - } else { |
|
| 901 | - EE_Error::add_error( |
|
| 902 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 903 | - __FILE__, |
|
| 904 | - __FUNCTION__, |
|
| 905 | - __LINE__ |
|
| 906 | - ); |
|
| 907 | - } |
|
| 908 | - return null; |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * get_config_option |
|
| 915 | - * |
|
| 916 | - * @access public |
|
| 917 | - * @param string $config_option_name |
|
| 918 | - * @return mixed EE_Config_Base | FALSE |
|
| 919 | - */ |
|
| 920 | - public function get_config_option($config_option_name = '') |
|
| 921 | - { |
|
| 922 | - // retrieve the wp-option for this config class. |
|
| 923 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 924 | - if (empty($config_option)) { |
|
| 925 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 926 | - } |
|
| 927 | - return $config_option; |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - |
|
| 932 | - /** |
|
| 933 | - * log |
|
| 934 | - * |
|
| 935 | - * @param string $config_option_name |
|
| 936 | - */ |
|
| 937 | - public static function log($config_option_name = '') |
|
| 938 | - { |
|
| 939 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 940 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 941 | - //copy incoming $_REQUEST and sanitize it so we can save it |
|
| 942 | - $_request = $_REQUEST; |
|
| 943 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 944 | - $config_log[(string)microtime(true)] = array( |
|
| 945 | - 'config_name' => $config_option_name, |
|
| 946 | - 'request' => $_request, |
|
| 947 | - ); |
|
| 948 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - |
|
| 954 | - /** |
|
| 955 | - * trim_log |
|
| 956 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 957 | - */ |
|
| 958 | - public static function trim_log() |
|
| 959 | - { |
|
| 960 | - if (! EE_Config::logging_enabled()) { |
|
| 961 | - return; |
|
| 962 | - } |
|
| 963 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 964 | - $log_length = count($config_log); |
|
| 965 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 966 | - ksort($config_log); |
|
| 967 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 968 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 969 | - } |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * get_page_for_posts |
|
| 976 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 977 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 978 | - * |
|
| 979 | - * @access public |
|
| 980 | - * @return string |
|
| 981 | - */ |
|
| 982 | - public static function get_page_for_posts() |
|
| 983 | - { |
|
| 984 | - $page_for_posts = get_option('page_for_posts'); |
|
| 985 | - if (! $page_for_posts) { |
|
| 986 | - return 'posts'; |
|
| 987 | - } |
|
| 988 | - /** @type WPDB $wpdb */ |
|
| 989 | - global $wpdb; |
|
| 990 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 991 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - |
|
| 995 | - |
|
| 996 | - /** |
|
| 997 | - * register_shortcodes_and_modules. |
|
| 998 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 999 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 1000 | - * so they can help trigger maintenance mode if it's needed |
|
| 1001 | - * |
|
| 1002 | - * @access public |
|
| 1003 | - * @return void |
|
| 1004 | - */ |
|
| 1005 | - public function register_shortcodes_and_modules() |
|
| 1006 | - { |
|
| 1007 | - // allow modules to set hooks for the rest of the system |
|
| 1008 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - |
|
| 1012 | - |
|
| 1013 | - /** |
|
| 1014 | - * initialize_shortcodes_and_modules |
|
| 1015 | - * meaning they can start adding their hooks to get stuff done |
|
| 1016 | - * |
|
| 1017 | - * @access public |
|
| 1018 | - * @return void |
|
| 1019 | - */ |
|
| 1020 | - public function initialize_shortcodes_and_modules() |
|
| 1021 | - { |
|
| 1022 | - // allow modules to set hooks for the rest of the system |
|
| 1023 | - $this->_initialize_modules(); |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * widgets_init |
|
| 1030 | - * |
|
| 1031 | - * @access private |
|
| 1032 | - * @return void |
|
| 1033 | - */ |
|
| 1034 | - public function widgets_init() |
|
| 1035 | - { |
|
| 1036 | - //only init widgets on admin pages when not in complete maintenance, and |
|
| 1037 | - //on frontend when not in any maintenance mode |
|
| 1038 | - if ( |
|
| 1039 | - ! EE_Maintenance_Mode::instance()->level() |
|
| 1040 | - || ( |
|
| 1041 | - is_admin() |
|
| 1042 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1043 | - ) |
|
| 1044 | - ) { |
|
| 1045 | - // grab list of installed widgets |
|
| 1046 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1047 | - // filter list of modules to register |
|
| 1048 | - $widgets_to_register = apply_filters( |
|
| 1049 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1050 | - $widgets_to_register |
|
| 1051 | - ); |
|
| 1052 | - if (! empty($widgets_to_register)) { |
|
| 1053 | - // cycle thru widget folders |
|
| 1054 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1055 | - // add to list of installed widget modules |
|
| 1056 | - EE_Config::register_ee_widget($widget_path); |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - // filter list of installed modules |
|
| 1060 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1061 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1062 | - EE_Registry::instance()->widgets |
|
| 1063 | - ); |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - /** |
|
| 1070 | - * register_ee_widget - makes core aware of this widget |
|
| 1071 | - * |
|
| 1072 | - * @access public |
|
| 1073 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1074 | - * @return void |
|
| 1075 | - */ |
|
| 1076 | - public static function register_ee_widget($widget_path = null) |
|
| 1077 | - { |
|
| 1078 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1079 | - $widget_ext = '.widget.php'; |
|
| 1080 | - // make all separators match |
|
| 1081 | - $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1082 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1083 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1084 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1085 | - $file_name = explode('.', basename($widget_path)); |
|
| 1086 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1087 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1088 | - // sanitize shortcode directory name |
|
| 1089 | - $widget = sanitize_key($widget); |
|
| 1090 | - // now we need to rebuild the shortcode path |
|
| 1091 | - $widget_path = explode(DS, $widget_path); |
|
| 1092 | - // remove last segment |
|
| 1093 | - array_pop($widget_path); |
|
| 1094 | - // glue it back together |
|
| 1095 | - $widget_path = implode(DS, $widget_path); |
|
| 1096 | - } else { |
|
| 1097 | - // grab and sanitize widget directory name |
|
| 1098 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1099 | - } |
|
| 1100 | - // create classname from widget directory name |
|
| 1101 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1102 | - // add class prefix |
|
| 1103 | - $widget_class = 'EEW_' . $widget; |
|
| 1104 | - // does the widget exist ? |
|
| 1105 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1106 | - $msg = sprintf( |
|
| 1107 | - __( |
|
| 1108 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1109 | - 'event_espresso' |
|
| 1110 | - ), |
|
| 1111 | - $widget_class, |
|
| 1112 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1113 | - ); |
|
| 1114 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1115 | - return; |
|
| 1116 | - } |
|
| 1117 | - // load the widget class file |
|
| 1118 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1119 | - // verify that class exists |
|
| 1120 | - if (! class_exists($widget_class)) { |
|
| 1121 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1122 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1123 | - return; |
|
| 1124 | - } |
|
| 1125 | - register_widget($widget_class); |
|
| 1126 | - // add to array of registered widgets |
|
| 1127 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - |
|
| 1131 | - |
|
| 1132 | - /** |
|
| 1133 | - * _register_modules |
|
| 1134 | - * |
|
| 1135 | - * @access private |
|
| 1136 | - * @return array |
|
| 1137 | - */ |
|
| 1138 | - private function _register_modules() |
|
| 1139 | - { |
|
| 1140 | - // grab list of installed modules |
|
| 1141 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1142 | - // filter list of modules to register |
|
| 1143 | - $modules_to_register = apply_filters( |
|
| 1144 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1145 | - $modules_to_register |
|
| 1146 | - ); |
|
| 1147 | - if (! empty($modules_to_register)) { |
|
| 1148 | - // loop through folders |
|
| 1149 | - foreach ($modules_to_register as $module_path) { |
|
| 1150 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1151 | - if ( |
|
| 1152 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1153 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1154 | - ) { |
|
| 1155 | - // add to list of installed modules |
|
| 1156 | - EE_Config::register_module($module_path); |
|
| 1157 | - } |
|
| 1158 | - } |
|
| 1159 | - } |
|
| 1160 | - // filter list of installed modules |
|
| 1161 | - return apply_filters( |
|
| 1162 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1163 | - EE_Registry::instance()->modules |
|
| 1164 | - ); |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - |
|
| 1168 | - |
|
| 1169 | - /** |
|
| 1170 | - * register_module - makes core aware of this module |
|
| 1171 | - * |
|
| 1172 | - * @access public |
|
| 1173 | - * @param string $module_path - full path up to and including module folder |
|
| 1174 | - * @return bool |
|
| 1175 | - */ |
|
| 1176 | - public static function register_module($module_path = null) |
|
| 1177 | - { |
|
| 1178 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1179 | - $module_ext = '.module.php'; |
|
| 1180 | - // make all separators match |
|
| 1181 | - $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1182 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1183 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1184 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1185 | - $module_file = explode('.', basename($module_path)); |
|
| 1186 | - // now we need to rebuild the shortcode path |
|
| 1187 | - $module_path = explode(DS, $module_path); |
|
| 1188 | - // remove last segment |
|
| 1189 | - array_pop($module_path); |
|
| 1190 | - // glue it back together |
|
| 1191 | - $module_path = implode(DS, $module_path) . DS; |
|
| 1192 | - // take first segment from file name pieces and sanitize it |
|
| 1193 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1194 | - // ensure class prefix is added |
|
| 1195 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1196 | - } else { |
|
| 1197 | - // we need to generate the filename based off of the folder name |
|
| 1198 | - // grab and sanitize module name |
|
| 1199 | - $module = strtolower(basename($module_path)); |
|
| 1200 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1201 | - // like trailingslashit() |
|
| 1202 | - $module_path = rtrim($module_path, DS) . DS; |
|
| 1203 | - // create classname from module directory name |
|
| 1204 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1205 | - // add class prefix |
|
| 1206 | - $module_class = 'EED_' . $module; |
|
| 1207 | - } |
|
| 1208 | - // does the module exist ? |
|
| 1209 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1210 | - $msg = sprintf( |
|
| 1211 | - __( |
|
| 1212 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1213 | - 'event_espresso' |
|
| 1214 | - ), |
|
| 1215 | - $module |
|
| 1216 | - ); |
|
| 1217 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1218 | - return false; |
|
| 1219 | - } |
|
| 1220 | - // load the module class file |
|
| 1221 | - require_once($module_path . $module_class . $module_ext); |
|
| 1222 | - // verify that class exists |
|
| 1223 | - if (! class_exists($module_class)) { |
|
| 1224 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1225 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1226 | - return false; |
|
| 1227 | - } |
|
| 1228 | - // add to array of registered modules |
|
| 1229 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1230 | - do_action( |
|
| 1231 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1232 | - $module_class, |
|
| 1233 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1234 | - ); |
|
| 1235 | - return true; |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * _initialize_modules |
|
| 1242 | - * allow modules to set hooks for the rest of the system |
|
| 1243 | - * |
|
| 1244 | - * @access private |
|
| 1245 | - * @return void |
|
| 1246 | - */ |
|
| 1247 | - private function _initialize_modules() |
|
| 1248 | - { |
|
| 1249 | - // cycle thru shortcode folders |
|
| 1250 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1251 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1252 | - // which set hooks ? |
|
| 1253 | - if (is_admin()) { |
|
| 1254 | - // fire immediately |
|
| 1255 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1256 | - } else { |
|
| 1257 | - // delay until other systems are online |
|
| 1258 | - add_action( |
|
| 1259 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1260 | - array($module_class, 'set_hooks') |
|
| 1261 | - ); |
|
| 1262 | - } |
|
| 1263 | - } |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - |
|
| 1267 | - |
|
| 1268 | - /** |
|
| 1269 | - * register_route - adds module method routes to route_map |
|
| 1270 | - * |
|
| 1271 | - * @access public |
|
| 1272 | - * @param string $route - "pretty" public alias for module method |
|
| 1273 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1274 | - * @param string $method_name - the actual module method to be routed to |
|
| 1275 | - * @param string $key - url param key indicating a route is being called |
|
| 1276 | - * @return bool |
|
| 1277 | - */ |
|
| 1278 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1279 | - { |
|
| 1280 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1281 | - $module = str_replace('EED_', '', $module); |
|
| 1282 | - $module_class = 'EED_' . $module; |
|
| 1283 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1284 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1285 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1286 | - return false; |
|
| 1287 | - } |
|
| 1288 | - if (empty($route)) { |
|
| 1289 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1290 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1291 | - return false; |
|
| 1292 | - } |
|
| 1293 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1294 | - $msg = sprintf( |
|
| 1295 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1296 | - $route |
|
| 1297 | - ); |
|
| 1298 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1299 | - return false; |
|
| 1300 | - } |
|
| 1301 | - EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1302 | - return true; |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * get_route - get module method route |
|
| 1309 | - * |
|
| 1310 | - * @access public |
|
| 1311 | - * @param string $route - "pretty" public alias for module method |
|
| 1312 | - * @param string $key - url param key indicating a route is being called |
|
| 1313 | - * @return string |
|
| 1314 | - */ |
|
| 1315 | - public static function get_route($route = null, $key = 'ee') |
|
| 1316 | - { |
|
| 1317 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1318 | - $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1319 | - if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1320 | - return EE_Config::$_module_route_map[$key][$route]; |
|
| 1321 | - } |
|
| 1322 | - return null; |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - |
|
| 1326 | - |
|
| 1327 | - /** |
|
| 1328 | - * get_routes - get ALL module method routes |
|
| 1329 | - * |
|
| 1330 | - * @access public |
|
| 1331 | - * @return array |
|
| 1332 | - */ |
|
| 1333 | - public static function get_routes() |
|
| 1334 | - { |
|
| 1335 | - return EE_Config::$_module_route_map; |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - |
|
| 1339 | - |
|
| 1340 | - /** |
|
| 1341 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1342 | - * |
|
| 1343 | - * @access public |
|
| 1344 | - * @param string $route - "pretty" public alias for module method |
|
| 1345 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1346 | - * class, allows different forwards to be served based on status |
|
| 1347 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1348 | - * @param string $key - url param key indicating a route is being called |
|
| 1349 | - * @return bool |
|
| 1350 | - */ |
|
| 1351 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1352 | - { |
|
| 1353 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1354 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1355 | - $msg = sprintf( |
|
| 1356 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1357 | - $route |
|
| 1358 | - ); |
|
| 1359 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1360 | - return false; |
|
| 1361 | - } |
|
| 1362 | - if (empty($forward)) { |
|
| 1363 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1364 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1365 | - return false; |
|
| 1366 | - } |
|
| 1367 | - if (is_array($forward)) { |
|
| 1368 | - if (! isset($forward[1])) { |
|
| 1369 | - $msg = sprintf( |
|
| 1370 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1371 | - $route |
|
| 1372 | - ); |
|
| 1373 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1374 | - return false; |
|
| 1375 | - } |
|
| 1376 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1377 | - $msg = sprintf( |
|
| 1378 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1379 | - $forward[1], |
|
| 1380 | - $route |
|
| 1381 | - ); |
|
| 1382 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1383 | - return false; |
|
| 1384 | - } |
|
| 1385 | - } else if (! function_exists($forward)) { |
|
| 1386 | - $msg = sprintf( |
|
| 1387 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1388 | - $forward, |
|
| 1389 | - $route |
|
| 1390 | - ); |
|
| 1391 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1392 | - return false; |
|
| 1393 | - } |
|
| 1394 | - EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1395 | - return true; |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - |
|
| 1399 | - |
|
| 1400 | - /** |
|
| 1401 | - * get_forward - get forwarding route |
|
| 1402 | - * |
|
| 1403 | - * @access public |
|
| 1404 | - * @param string $route - "pretty" public alias for module method |
|
| 1405 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1406 | - * allows different forwards to be served based on status |
|
| 1407 | - * @param string $key - url param key indicating a route is being called |
|
| 1408 | - * @return string |
|
| 1409 | - */ |
|
| 1410 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1411 | - { |
|
| 1412 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1413 | - if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1414 | - return apply_filters( |
|
| 1415 | - 'FHEE__EE_Config__get_forward', |
|
| 1416 | - EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1417 | - $route, |
|
| 1418 | - $status |
|
| 1419 | - ); |
|
| 1420 | - } |
|
| 1421 | - return null; |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - |
|
| 1425 | - |
|
| 1426 | - /** |
|
| 1427 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1428 | - * results |
|
| 1429 | - * |
|
| 1430 | - * @access public |
|
| 1431 | - * @param string $route - "pretty" public alias for module method |
|
| 1432 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1433 | - * allows different views to be served based on status |
|
| 1434 | - * @param string $view |
|
| 1435 | - * @param string $key - url param key indicating a route is being called |
|
| 1436 | - * @return bool |
|
| 1437 | - */ |
|
| 1438 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1439 | - { |
|
| 1440 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1441 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1442 | - $msg = sprintf( |
|
| 1443 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1444 | - $route |
|
| 1445 | - ); |
|
| 1446 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1447 | - return false; |
|
| 1448 | - } |
|
| 1449 | - if (! is_readable($view)) { |
|
| 1450 | - $msg = sprintf( |
|
| 1451 | - __( |
|
| 1452 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1453 | - 'event_espresso' |
|
| 1454 | - ), |
|
| 1455 | - $view |
|
| 1456 | - ); |
|
| 1457 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1458 | - return false; |
|
| 1459 | - } |
|
| 1460 | - EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1461 | - return true; |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * get_view - get view for route and status |
|
| 1468 | - * |
|
| 1469 | - * @access public |
|
| 1470 | - * @param string $route - "pretty" public alias for module method |
|
| 1471 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1472 | - * allows different views to be served based on status |
|
| 1473 | - * @param string $key - url param key indicating a route is being called |
|
| 1474 | - * @return string |
|
| 1475 | - */ |
|
| 1476 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1477 | - { |
|
| 1478 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1479 | - if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1480 | - return apply_filters( |
|
| 1481 | - 'FHEE__EE_Config__get_view', |
|
| 1482 | - EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1483 | - $route, |
|
| 1484 | - $status |
|
| 1485 | - ); |
|
| 1486 | - } |
|
| 1487 | - return null; |
|
| 1488 | - } |
|
| 1489 | - |
|
| 1490 | - |
|
| 1491 | - |
|
| 1492 | - public function update_addon_option_names() |
|
| 1493 | - { |
|
| 1494 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - |
|
| 1498 | - |
|
| 1499 | - public function shutdown() |
|
| 1500 | - { |
|
| 1501 | - $this->update_addon_option_names(); |
|
| 1502 | - } |
|
| 1503 | - |
|
| 1504 | - |
|
| 1505 | - |
|
| 1506 | - /** |
|
| 1507 | - * @return LegacyShortcodesManager |
|
| 1508 | - */ |
|
| 1509 | - public static function getLegacyShortcodesManager() |
|
| 1510 | - { |
|
| 1511 | - |
|
| 1512 | - if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1513 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1514 | - EE_Registry::instance() |
|
| 1515 | - ); |
|
| 1516 | - } |
|
| 1517 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - |
|
| 1521 | - |
|
| 1522 | - /** |
|
| 1523 | - * register_shortcode - makes core aware of this shortcode |
|
| 1524 | - * |
|
| 1525 | - * @deprecated 4.9.26 |
|
| 1526 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1527 | - * @return bool |
|
| 1528 | - */ |
|
| 1529 | - public static function register_shortcode($shortcode_path = null) |
|
| 1530 | - { |
|
| 1531 | - EE_Error::doing_it_wrong( |
|
| 1532 | - __METHOD__, |
|
| 1533 | - __( |
|
| 1534 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1535 | - 'event_espresso' |
|
| 1536 | - ), |
|
| 1537 | - '4.9.26' |
|
| 1538 | - ); |
|
| 1539 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - |
|
| 1543 | - |
|
| 1544 | -} |
|
| 1545 | - |
|
| 1546 | - |
|
| 1547 | - |
|
| 1548 | -/** |
|
| 1549 | - * Base class used for config classes. These classes should generally not have |
|
| 1550 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1551 | - * basically, they should just be well-defined stdClasses |
|
| 1552 | - */ |
|
| 1553 | -class EE_Config_Base |
|
| 1554 | -{ |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * Utility function for escaping the value of a property and returning. |
|
| 1558 | - * |
|
| 1559 | - * @param string $property property name (checks to see if exists). |
|
| 1560 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1561 | - * @throws \EE_Error |
|
| 1562 | - */ |
|
| 1563 | - public function get_pretty($property) |
|
| 1564 | - { |
|
| 1565 | - if (! property_exists($this, $property)) { |
|
| 1566 | - throw new EE_Error( |
|
| 1567 | - sprintf( |
|
| 1568 | - __( |
|
| 1569 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1570 | - 'event_espresso' |
|
| 1571 | - ), |
|
| 1572 | - get_class($this), |
|
| 1573 | - $property |
|
| 1574 | - ) |
|
| 1575 | - ); |
|
| 1576 | - } |
|
| 1577 | - //just handling escaping of strings for now. |
|
| 1578 | - if (is_string($this->{$property})) { |
|
| 1579 | - return stripslashes($this->{$property}); |
|
| 1580 | - } |
|
| 1581 | - return $this->{$property}; |
|
| 1582 | - } |
|
| 1583 | - |
|
| 1584 | - |
|
| 1585 | - |
|
| 1586 | - public function populate() |
|
| 1587 | - { |
|
| 1588 | - //grab defaults via a new instance of this class. |
|
| 1589 | - $class_name = get_class($this); |
|
| 1590 | - $defaults = new $class_name; |
|
| 1591 | - //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1592 | - //default from our $defaults object. |
|
| 1593 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1594 | - if ($this->{$property} === null) { |
|
| 1595 | - $this->{$property} = $value; |
|
| 1596 | - } |
|
| 1597 | - } |
|
| 1598 | - //cleanup |
|
| 1599 | - unset($defaults); |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - |
|
| 1603 | - |
|
| 1604 | - /** |
|
| 1605 | - * __isset |
|
| 1606 | - * |
|
| 1607 | - * @param $a |
|
| 1608 | - * @return bool |
|
| 1609 | - */ |
|
| 1610 | - public function __isset($a) |
|
| 1611 | - { |
|
| 1612 | - return false; |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - |
|
| 1616 | - |
|
| 1617 | - /** |
|
| 1618 | - * __unset |
|
| 1619 | - * |
|
| 1620 | - * @param $a |
|
| 1621 | - * @return bool |
|
| 1622 | - */ |
|
| 1623 | - public function __unset($a) |
|
| 1624 | - { |
|
| 1625 | - return false; |
|
| 1626 | - } |
|
| 1627 | - |
|
| 1628 | - |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * __clone |
|
| 1632 | - */ |
|
| 1633 | - public function __clone() |
|
| 1634 | - { |
|
| 1635 | - } |
|
| 1636 | - |
|
| 1637 | - |
|
| 1638 | - |
|
| 1639 | - /** |
|
| 1640 | - * __wakeup |
|
| 1641 | - */ |
|
| 1642 | - public function __wakeup() |
|
| 1643 | - { |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * __destruct |
|
| 1650 | - */ |
|
| 1651 | - public function __destruct() |
|
| 1652 | - { |
|
| 1653 | - } |
|
| 1654 | -} |
|
| 1655 | - |
|
| 1656 | - |
|
| 1657 | - |
|
| 1658 | -/** |
|
| 1659 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1660 | - */ |
|
| 1661 | -class EE_Core_Config extends EE_Config_Base |
|
| 1662 | -{ |
|
| 1663 | - |
|
| 1664 | - public $current_blog_id; |
|
| 1665 | - |
|
| 1666 | - public $ee_ueip_optin; |
|
| 1667 | - |
|
| 1668 | - public $ee_ueip_has_notified; |
|
| 1669 | - |
|
| 1670 | - /** |
|
| 1671 | - * Not to be confused with the 4 critical page variables (See |
|
| 1672 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1673 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1674 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1675 | - * |
|
| 1676 | - * @var array |
|
| 1677 | - */ |
|
| 1678 | - public $post_shortcodes; |
|
| 1679 | - |
|
| 1680 | - public $module_route_map; |
|
| 1681 | - |
|
| 1682 | - public $module_forward_map; |
|
| 1683 | - |
|
| 1684 | - public $module_view_map; |
|
| 1685 | - |
|
| 1686 | - /** |
|
| 1687 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1688 | - * |
|
| 1689 | - * @var int |
|
| 1690 | - */ |
|
| 1691 | - public $reg_page_id; |
|
| 1692 | - |
|
| 1693 | - public $txn_page_id; |
|
| 1694 | - |
|
| 1695 | - public $thank_you_page_id; |
|
| 1696 | - |
|
| 1697 | - public $cancel_page_id; |
|
| 1698 | - |
|
| 1699 | - /** |
|
| 1700 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1701 | - * |
|
| 1702 | - * @var int |
|
| 1703 | - */ |
|
| 1704 | - public $reg_page_url; |
|
| 1705 | - |
|
| 1706 | - public $txn_page_url; |
|
| 1707 | - |
|
| 1708 | - public $thank_you_page_url; |
|
| 1709 | - |
|
| 1710 | - public $cancel_page_url; |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1714 | - */ |
|
| 1715 | - public $event_cpt_slug; |
|
| 1716 | - |
|
| 1717 | - |
|
| 1718 | - /** |
|
| 1719 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1720 | - * request across blog switches in a multisite context. |
|
| 1721 | - * Avoids extra queries to the db for this option. |
|
| 1722 | - * |
|
| 1723 | - * @var bool |
|
| 1724 | - */ |
|
| 1725 | - public static $ee_ueip_option; |
|
| 1726 | - |
|
| 1727 | - |
|
| 1728 | - |
|
| 1729 | - /** |
|
| 1730 | - * class constructor |
|
| 1731 | - * |
|
| 1732 | - * @access public |
|
| 1733 | - */ |
|
| 1734 | - public function __construct() |
|
| 1735 | - { |
|
| 1736 | - // set default organization settings |
|
| 1737 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1738 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1739 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1740 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1741 | - $this->post_shortcodes = array(); |
|
| 1742 | - $this->module_route_map = array(); |
|
| 1743 | - $this->module_forward_map = array(); |
|
| 1744 | - $this->module_view_map = array(); |
|
| 1745 | - // critical EE page IDs |
|
| 1746 | - $this->reg_page_id = 0; |
|
| 1747 | - $this->txn_page_id = 0; |
|
| 1748 | - $this->thank_you_page_id = 0; |
|
| 1749 | - $this->cancel_page_id = 0; |
|
| 1750 | - // critical EE page URLs |
|
| 1751 | - $this->reg_page_url = ''; |
|
| 1752 | - $this->txn_page_url = ''; |
|
| 1753 | - $this->thank_you_page_url = ''; |
|
| 1754 | - $this->cancel_page_url = ''; |
|
| 1755 | - //cpt slugs |
|
| 1756 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1757 | - //ueip constant check |
|
| 1758 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1759 | - $this->ee_ueip_optin = false; |
|
| 1760 | - $this->ee_ueip_has_notified = true; |
|
| 1761 | - } |
|
| 1762 | - } |
|
| 1763 | - |
|
| 1764 | - |
|
| 1765 | - |
|
| 1766 | - /** |
|
| 1767 | - * @return array |
|
| 1768 | - */ |
|
| 1769 | - public function get_critical_pages_array() |
|
| 1770 | - { |
|
| 1771 | - return array( |
|
| 1772 | - $this->reg_page_id, |
|
| 1773 | - $this->txn_page_id, |
|
| 1774 | - $this->thank_you_page_id, |
|
| 1775 | - $this->cancel_page_id, |
|
| 1776 | - ); |
|
| 1777 | - } |
|
| 1778 | - |
|
| 1779 | - |
|
| 1780 | - |
|
| 1781 | - /** |
|
| 1782 | - * @return array |
|
| 1783 | - */ |
|
| 1784 | - public function get_critical_pages_shortcodes_array() |
|
| 1785 | - { |
|
| 1786 | - return array( |
|
| 1787 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1788 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1789 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1790 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1791 | - ); |
|
| 1792 | - } |
|
| 1793 | - |
|
| 1794 | - |
|
| 1795 | - |
|
| 1796 | - /** |
|
| 1797 | - * gets/returns URL for EE reg_page |
|
| 1798 | - * |
|
| 1799 | - * @access public |
|
| 1800 | - * @return string |
|
| 1801 | - */ |
|
| 1802 | - public function reg_page_url() |
|
| 1803 | - { |
|
| 1804 | - if (! $this->reg_page_url) { |
|
| 1805 | - $this->reg_page_url = add_query_arg( |
|
| 1806 | - array('uts' => time()), |
|
| 1807 | - get_permalink($this->reg_page_id) |
|
| 1808 | - ) . '#checkout'; |
|
| 1809 | - } |
|
| 1810 | - return $this->reg_page_url; |
|
| 1811 | - } |
|
| 1812 | - |
|
| 1813 | - |
|
| 1814 | - |
|
| 1815 | - /** |
|
| 1816 | - * gets/returns URL for EE txn_page |
|
| 1817 | - * |
|
| 1818 | - * @param array $query_args like what gets passed to |
|
| 1819 | - * add_query_arg() as the first argument |
|
| 1820 | - * @access public |
|
| 1821 | - * @return string |
|
| 1822 | - */ |
|
| 1823 | - public function txn_page_url($query_args = array()) |
|
| 1824 | - { |
|
| 1825 | - if (! $this->txn_page_url) { |
|
| 1826 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1827 | - } |
|
| 1828 | - if ($query_args) { |
|
| 1829 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1830 | - } else { |
|
| 1831 | - return $this->txn_page_url; |
|
| 1832 | - } |
|
| 1833 | - } |
|
| 1834 | - |
|
| 1835 | - |
|
| 1836 | - |
|
| 1837 | - /** |
|
| 1838 | - * gets/returns URL for EE thank_you_page |
|
| 1839 | - * |
|
| 1840 | - * @param array $query_args like what gets passed to |
|
| 1841 | - * add_query_arg() as the first argument |
|
| 1842 | - * @access public |
|
| 1843 | - * @return string |
|
| 1844 | - */ |
|
| 1845 | - public function thank_you_page_url($query_args = array()) |
|
| 1846 | - { |
|
| 1847 | - if (! $this->thank_you_page_url) { |
|
| 1848 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1849 | - } |
|
| 1850 | - if ($query_args) { |
|
| 1851 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1852 | - } else { |
|
| 1853 | - return $this->thank_you_page_url; |
|
| 1854 | - } |
|
| 1855 | - } |
|
| 1856 | - |
|
| 1857 | - |
|
| 1858 | - |
|
| 1859 | - /** |
|
| 1860 | - * gets/returns URL for EE cancel_page |
|
| 1861 | - * |
|
| 1862 | - * @access public |
|
| 1863 | - * @return string |
|
| 1864 | - */ |
|
| 1865 | - public function cancel_page_url() |
|
| 1866 | - { |
|
| 1867 | - if (! $this->cancel_page_url) { |
|
| 1868 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1869 | - } |
|
| 1870 | - return $this->cancel_page_url; |
|
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - |
|
| 1874 | - |
|
| 1875 | - /** |
|
| 1876 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1877 | - * |
|
| 1878 | - * @since 4.7.5 |
|
| 1879 | - */ |
|
| 1880 | - protected function _reset_urls() |
|
| 1881 | - { |
|
| 1882 | - $this->reg_page_url = ''; |
|
| 1883 | - $this->txn_page_url = ''; |
|
| 1884 | - $this->cancel_page_url = ''; |
|
| 1885 | - $this->thank_you_page_url = ''; |
|
| 1886 | - } |
|
| 1887 | - |
|
| 1888 | - |
|
| 1889 | - |
|
| 1890 | - /** |
|
| 1891 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1892 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1893 | - * on the main site only. |
|
| 1894 | - * |
|
| 1895 | - * @return mixed|void |
|
| 1896 | - */ |
|
| 1897 | - protected function _get_main_ee_ueip_optin() |
|
| 1898 | - { |
|
| 1899 | - //if this is the main site then we can just bypass our direct query. |
|
| 1900 | - if (is_main_site()) { |
|
| 1901 | - return get_option('ee_ueip_optin', false); |
|
| 1902 | - } |
|
| 1903 | - //is this already cached for this request? If so use it. |
|
| 1904 | - if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1905 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1906 | - } |
|
| 1907 | - global $wpdb; |
|
| 1908 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1909 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1910 | - $option = 'ee_ueip_optin'; |
|
| 1911 | - //set correct table for query |
|
| 1912 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1913 | - //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1914 | - //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1915 | - //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1916 | - //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1917 | - //for the purpose of caching. |
|
| 1918 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1919 | - if (false !== $pre) { |
|
| 1920 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1921 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1922 | - } |
|
| 1923 | - $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1924 | - $option)); |
|
| 1925 | - if (is_object($row)) { |
|
| 1926 | - $value = $row->option_value; |
|
| 1927 | - } else { //option does not exist so use default. |
|
| 1928 | - return apply_filters('default_option_' . $option, false, $option); |
|
| 1929 | - } |
|
| 1930 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1931 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - |
|
| 1935 | - |
|
| 1936 | - /** |
|
| 1937 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1938 | - * on the object. |
|
| 1939 | - * |
|
| 1940 | - * @return array |
|
| 1941 | - */ |
|
| 1942 | - public function __sleep() |
|
| 1943 | - { |
|
| 1944 | - //reset all url properties |
|
| 1945 | - $this->_reset_urls(); |
|
| 1946 | - //return what to save to db |
|
| 1947 | - return array_keys(get_object_vars($this)); |
|
| 1948 | - } |
|
| 1949 | - |
|
| 1950 | -} |
|
| 1951 | - |
|
| 1952 | - |
|
| 1953 | - |
|
| 1954 | -/** |
|
| 1955 | - * Config class for storing info on the Organization |
|
| 1956 | - */ |
|
| 1957 | -class EE_Organization_Config extends EE_Config_Base |
|
| 1958 | -{ |
|
| 1959 | - |
|
| 1960 | - /** |
|
| 1961 | - * @var string $name |
|
| 1962 | - * eg EE4.1 |
|
| 1963 | - */ |
|
| 1964 | - public $name; |
|
| 1965 | - |
|
| 1966 | - /** |
|
| 1967 | - * @var string $address_1 |
|
| 1968 | - * eg 123 Onna Road |
|
| 1969 | - */ |
|
| 1970 | - public $address_1; |
|
| 1971 | - |
|
| 1972 | - /** |
|
| 1973 | - * @var string $address_2 |
|
| 1974 | - * eg PO Box 123 |
|
| 1975 | - */ |
|
| 1976 | - public $address_2; |
|
| 1977 | - |
|
| 1978 | - /** |
|
| 1979 | - * @var string $city |
|
| 1980 | - * eg Inna City |
|
| 1981 | - */ |
|
| 1982 | - public $city; |
|
| 1983 | - |
|
| 1984 | - /** |
|
| 1985 | - * @var int $STA_ID |
|
| 1986 | - * eg 4 |
|
| 1987 | - */ |
|
| 1988 | - public $STA_ID; |
|
| 1989 | - |
|
| 1990 | - /** |
|
| 1991 | - * @var string $CNT_ISO |
|
| 1992 | - * eg US |
|
| 1993 | - */ |
|
| 1994 | - public $CNT_ISO; |
|
| 1995 | - |
|
| 1996 | - /** |
|
| 1997 | - * @var string $zip |
|
| 1998 | - * eg 12345 or V1A 2B3 |
|
| 1999 | - */ |
|
| 2000 | - public $zip; |
|
| 2001 | - |
|
| 2002 | - /** |
|
| 2003 | - * @var string $email |
|
| 2004 | - * eg [email protected] |
|
| 2005 | - */ |
|
| 2006 | - public $email; |
|
| 2007 | - |
|
| 2008 | - |
|
| 2009 | - /** |
|
| 2010 | - * @var string $phone |
|
| 2011 | - * eg. 111-111-1111 |
|
| 2012 | - */ |
|
| 2013 | - public $phone; |
|
| 2014 | - |
|
| 2015 | - |
|
| 2016 | - /** |
|
| 2017 | - * @var string $vat |
|
| 2018 | - * VAT/Tax Number |
|
| 2019 | - */ |
|
| 2020 | - public $vat; |
|
| 2021 | - |
|
| 2022 | - /** |
|
| 2023 | - * @var string $logo_url |
|
| 2024 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2025 | - */ |
|
| 2026 | - public $logo_url; |
|
| 2027 | - |
|
| 2028 | - |
|
| 2029 | - /** |
|
| 2030 | - * The below are all various properties for holding links to organization social network profiles |
|
| 2031 | - * |
|
| 2032 | - * @var string |
|
| 2033 | - */ |
|
| 2034 | - /** |
|
| 2035 | - * facebook (facebook.com/profile.name) |
|
| 2036 | - * |
|
| 2037 | - * @var string |
|
| 2038 | - */ |
|
| 2039 | - public $facebook; |
|
| 2040 | - |
|
| 2041 | - |
|
| 2042 | - /** |
|
| 2043 | - * twitter (twitter.com/twitter_handle) |
|
| 2044 | - * |
|
| 2045 | - * @var string |
|
| 2046 | - */ |
|
| 2047 | - public $twitter; |
|
| 2048 | - |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2052 | - * |
|
| 2053 | - * @var string |
|
| 2054 | - */ |
|
| 2055 | - public $linkedin; |
|
| 2056 | - |
|
| 2057 | - |
|
| 2058 | - /** |
|
| 2059 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2060 | - * |
|
| 2061 | - * @var string |
|
| 2062 | - */ |
|
| 2063 | - public $pinterest; |
|
| 2064 | - |
|
| 2065 | - |
|
| 2066 | - /** |
|
| 2067 | - * google+ (google.com/+profileName) |
|
| 2068 | - * |
|
| 2069 | - * @var string |
|
| 2070 | - */ |
|
| 2071 | - public $google; |
|
| 2072 | - |
|
| 2073 | - |
|
| 2074 | - /** |
|
| 2075 | - * instagram (instagram.com/handle) |
|
| 2076 | - * |
|
| 2077 | - * @var string |
|
| 2078 | - */ |
|
| 2079 | - public $instagram; |
|
| 2080 | - |
|
| 2081 | - |
|
| 2082 | - |
|
| 2083 | - /** |
|
| 2084 | - * class constructor |
|
| 2085 | - * |
|
| 2086 | - * @access public |
|
| 2087 | - */ |
|
| 2088 | - public function __construct() |
|
| 2089 | - { |
|
| 2090 | - // set default organization settings |
|
| 2091 | - //decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2092 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2093 | - $this->address_1 = '123 Onna Road'; |
|
| 2094 | - $this->address_2 = 'PO Box 123'; |
|
| 2095 | - $this->city = 'Inna City'; |
|
| 2096 | - $this->STA_ID = 4; |
|
| 2097 | - $this->CNT_ISO = 'US'; |
|
| 2098 | - $this->zip = '12345'; |
|
| 2099 | - $this->email = get_bloginfo('admin_email'); |
|
| 2100 | - $this->phone = ''; |
|
| 2101 | - $this->vat = '123456789'; |
|
| 2102 | - $this->logo_url = ''; |
|
| 2103 | - $this->facebook = ''; |
|
| 2104 | - $this->twitter = ''; |
|
| 2105 | - $this->linkedin = ''; |
|
| 2106 | - $this->pinterest = ''; |
|
| 2107 | - $this->google = ''; |
|
| 2108 | - $this->instagram = ''; |
|
| 2109 | - } |
|
| 2110 | - |
|
| 2111 | -} |
|
| 2112 | - |
|
| 2113 | - |
|
| 2114 | - |
|
| 2115 | -/** |
|
| 2116 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2117 | - */ |
|
| 2118 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2119 | -{ |
|
| 2120 | - |
|
| 2121 | - /** |
|
| 2122 | - * @var string $code |
|
| 2123 | - * eg 'US' |
|
| 2124 | - */ |
|
| 2125 | - public $code; |
|
| 2126 | - |
|
| 2127 | - /** |
|
| 2128 | - * @var string $name |
|
| 2129 | - * eg 'Dollar' |
|
| 2130 | - */ |
|
| 2131 | - public $name; |
|
| 2132 | - |
|
| 2133 | - /** |
|
| 2134 | - * plural name |
|
| 2135 | - * |
|
| 2136 | - * @var string $plural |
|
| 2137 | - * eg 'Dollars' |
|
| 2138 | - */ |
|
| 2139 | - public $plural; |
|
| 2140 | - |
|
| 2141 | - /** |
|
| 2142 | - * currency sign |
|
| 2143 | - * |
|
| 2144 | - * @var string $sign |
|
| 2145 | - * eg '$' |
|
| 2146 | - */ |
|
| 2147 | - public $sign; |
|
| 2148 | - |
|
| 2149 | - /** |
|
| 2150 | - * Whether the currency sign should come before the number or not |
|
| 2151 | - * |
|
| 2152 | - * @var boolean $sign_b4 |
|
| 2153 | - */ |
|
| 2154 | - public $sign_b4; |
|
| 2155 | - |
|
| 2156 | - /** |
|
| 2157 | - * How many digits should come after the decimal place |
|
| 2158 | - * |
|
| 2159 | - * @var int $dec_plc |
|
| 2160 | - */ |
|
| 2161 | - public $dec_plc; |
|
| 2162 | - |
|
| 2163 | - /** |
|
| 2164 | - * Symbol to use for decimal mark |
|
| 2165 | - * |
|
| 2166 | - * @var string $dec_mrk |
|
| 2167 | - * eg '.' |
|
| 2168 | - */ |
|
| 2169 | - public $dec_mrk; |
|
| 2170 | - |
|
| 2171 | - /** |
|
| 2172 | - * Symbol to use for thousands |
|
| 2173 | - * |
|
| 2174 | - * @var string $thsnds |
|
| 2175 | - * eg ',' |
|
| 2176 | - */ |
|
| 2177 | - public $thsnds; |
|
| 2178 | - |
|
| 2179 | - |
|
| 2180 | - |
|
| 2181 | - /** |
|
| 2182 | - * class constructor |
|
| 2183 | - * |
|
| 2184 | - * @access public |
|
| 2185 | - * @param string $CNT_ISO |
|
| 2186 | - * @throws \EE_Error |
|
| 2187 | - */ |
|
| 2188 | - public function __construct($CNT_ISO = '') |
|
| 2189 | - { |
|
| 2190 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2191 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2192 | - // get country code from organization settings or use default |
|
| 2193 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2194 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2195 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2196 | - : ''; |
|
| 2197 | - // but override if requested |
|
| 2198 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2199 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2200 | - if ( |
|
| 2201 | - ! empty($CNT_ISO) |
|
| 2202 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2203 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2204 | - ) { |
|
| 2205 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2206 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2207 | - if ($country instanceof EE_Country) { |
|
| 2208 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2209 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2210 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2211 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2212 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2213 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2214 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2215 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2216 | - } |
|
| 2217 | - } |
|
| 2218 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2219 | - if (empty($this->code)) { |
|
| 2220 | - // set default currency settings |
|
| 2221 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2222 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2223 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2224 | - $this->sign = '$'; // currency sign: $ |
|
| 2225 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2226 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2227 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2228 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2229 | - } |
|
| 2230 | - } |
|
| 2231 | -} |
|
| 2232 | - |
|
| 2233 | - |
|
| 2234 | - |
|
| 2235 | -/** |
|
| 2236 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2237 | - */ |
|
| 2238 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2239 | -{ |
|
| 2240 | - |
|
| 2241 | - /** |
|
| 2242 | - * Default registration status |
|
| 2243 | - * |
|
| 2244 | - * @var string $default_STS_ID |
|
| 2245 | - * eg 'RPP' |
|
| 2246 | - */ |
|
| 2247 | - public $default_STS_ID; |
|
| 2248 | - |
|
| 2249 | - |
|
| 2250 | - /** |
|
| 2251 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2252 | - * registrations) |
|
| 2253 | - * @var int |
|
| 2254 | - */ |
|
| 2255 | - public $default_maximum_number_of_tickets; |
|
| 2256 | - |
|
| 2257 | - |
|
| 2258 | - /** |
|
| 2259 | - * level of validation to apply to email addresses |
|
| 2260 | - * |
|
| 2261 | - * @var string $email_validation_level |
|
| 2262 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2263 | - */ |
|
| 2264 | - public $email_validation_level; |
|
| 2265 | - |
|
| 2266 | - /** |
|
| 2267 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2268 | - * |
|
| 2269 | - * @var boolean $show_pending_payment_options |
|
| 2270 | - */ |
|
| 2271 | - public $show_pending_payment_options; |
|
| 2272 | - |
|
| 2273 | - /** |
|
| 2274 | - * Whether to skip the registration confirmation page |
|
| 2275 | - * |
|
| 2276 | - * @var boolean $skip_reg_confirmation |
|
| 2277 | - */ |
|
| 2278 | - public $skip_reg_confirmation; |
|
| 2279 | - |
|
| 2280 | - /** |
|
| 2281 | - * an array of SPCO reg steps where: |
|
| 2282 | - * the keys denotes the reg step order |
|
| 2283 | - * each element consists of an array with the following elements: |
|
| 2284 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2285 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2286 | - * "slug" => the URL param used to trigger the reg step |
|
| 2287 | - * |
|
| 2288 | - * @var array $reg_steps |
|
| 2289 | - */ |
|
| 2290 | - public $reg_steps; |
|
| 2291 | - |
|
| 2292 | - /** |
|
| 2293 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2294 | - * |
|
| 2295 | - * @var boolean $reg_confirmation_last |
|
| 2296 | - */ |
|
| 2297 | - public $reg_confirmation_last; |
|
| 2298 | - |
|
| 2299 | - /** |
|
| 2300 | - * Whether or not to enable the EE Bot Trap |
|
| 2301 | - * |
|
| 2302 | - * @var boolean $use_bot_trap |
|
| 2303 | - */ |
|
| 2304 | - public $use_bot_trap; |
|
| 2305 | - |
|
| 2306 | - /** |
|
| 2307 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2308 | - * |
|
| 2309 | - * @var boolean $use_encryption |
|
| 2310 | - */ |
|
| 2311 | - public $use_encryption; |
|
| 1544 | +} |
|
| 2312 | 1545 | |
| 2313 | - /** |
|
| 2314 | - * Whether or not to use ReCaptcha |
|
| 2315 | - * |
|
| 2316 | - * @var boolean $use_captcha |
|
| 2317 | - */ |
|
| 2318 | - public $use_captcha; |
|
| 2319 | 1546 | |
| 2320 | - /** |
|
| 2321 | - * ReCaptcha Theme |
|
| 2322 | - * |
|
| 2323 | - * @var string $recaptcha_theme |
|
| 2324 | - * options: 'dark ', 'light' |
|
| 2325 | - */ |
|
| 2326 | - public $recaptcha_theme; |
|
| 2327 | 1547 | |
| 2328 | - /** |
|
| 2329 | - * ReCaptcha Type |
|
| 2330 | - * |
|
| 2331 | - * @var string $recaptcha_type |
|
| 2332 | - * options: 'audio', 'image' |
|
| 2333 | - */ |
|
| 2334 | - public $recaptcha_type; |
|
| 1548 | +/** |
|
| 1549 | + * Base class used for config classes. These classes should generally not have |
|
| 1550 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1551 | + * basically, they should just be well-defined stdClasses |
|
| 1552 | + */ |
|
| 1553 | +class EE_Config_Base |
|
| 1554 | +{ |
|
| 2335 | 1555 | |
| 2336 | - /** |
|
| 2337 | - * ReCaptcha language |
|
| 2338 | - * |
|
| 2339 | - * @var string $recaptcha_language |
|
| 2340 | - * eg 'en' |
|
| 2341 | - */ |
|
| 2342 | - public $recaptcha_language; |
|
| 1556 | + /** |
|
| 1557 | + * Utility function for escaping the value of a property and returning. |
|
| 1558 | + * |
|
| 1559 | + * @param string $property property name (checks to see if exists). |
|
| 1560 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1561 | + * @throws \EE_Error |
|
| 1562 | + */ |
|
| 1563 | + public function get_pretty($property) |
|
| 1564 | + { |
|
| 1565 | + if (! property_exists($this, $property)) { |
|
| 1566 | + throw new EE_Error( |
|
| 1567 | + sprintf( |
|
| 1568 | + __( |
|
| 1569 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1570 | + 'event_espresso' |
|
| 1571 | + ), |
|
| 1572 | + get_class($this), |
|
| 1573 | + $property |
|
| 1574 | + ) |
|
| 1575 | + ); |
|
| 1576 | + } |
|
| 1577 | + //just handling escaping of strings for now. |
|
| 1578 | + if (is_string($this->{$property})) { |
|
| 1579 | + return stripslashes($this->{$property}); |
|
| 1580 | + } |
|
| 1581 | + return $this->{$property}; |
|
| 1582 | + } |
|
| 1583 | + |
|
| 1584 | + |
|
| 1585 | + |
|
| 1586 | + public function populate() |
|
| 1587 | + { |
|
| 1588 | + //grab defaults via a new instance of this class. |
|
| 1589 | + $class_name = get_class($this); |
|
| 1590 | + $defaults = new $class_name; |
|
| 1591 | + //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1592 | + //default from our $defaults object. |
|
| 1593 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1594 | + if ($this->{$property} === null) { |
|
| 1595 | + $this->{$property} = $value; |
|
| 1596 | + } |
|
| 1597 | + } |
|
| 1598 | + //cleanup |
|
| 1599 | + unset($defaults); |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + |
|
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * __isset |
|
| 1606 | + * |
|
| 1607 | + * @param $a |
|
| 1608 | + * @return bool |
|
| 1609 | + */ |
|
| 1610 | + public function __isset($a) |
|
| 1611 | + { |
|
| 1612 | + return false; |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + |
|
| 1616 | + |
|
| 1617 | + /** |
|
| 1618 | + * __unset |
|
| 1619 | + * |
|
| 1620 | + * @param $a |
|
| 1621 | + * @return bool |
|
| 1622 | + */ |
|
| 1623 | + public function __unset($a) |
|
| 1624 | + { |
|
| 1625 | + return false; |
|
| 1626 | + } |
|
| 1627 | + |
|
| 1628 | + |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * __clone |
|
| 1632 | + */ |
|
| 1633 | + public function __clone() |
|
| 1634 | + { |
|
| 1635 | + } |
|
| 1636 | + |
|
| 1637 | + |
|
| 1638 | + |
|
| 1639 | + /** |
|
| 1640 | + * __wakeup |
|
| 1641 | + */ |
|
| 1642 | + public function __wakeup() |
|
| 1643 | + { |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * __destruct |
|
| 1650 | + */ |
|
| 1651 | + public function __destruct() |
|
| 1652 | + { |
|
| 1653 | + } |
|
| 1654 | +} |
|
| 2343 | 1655 | |
| 2344 | - /** |
|
| 2345 | - * ReCaptcha public key |
|
| 2346 | - * |
|
| 2347 | - * @var string $recaptcha_publickey |
|
| 2348 | - */ |
|
| 2349 | - public $recaptcha_publickey; |
|
| 2350 | 1656 | |
| 2351 | - /** |
|
| 2352 | - * ReCaptcha private key |
|
| 2353 | - * |
|
| 2354 | - * @var string $recaptcha_privatekey |
|
| 2355 | - */ |
|
| 2356 | - public $recaptcha_privatekey; |
|
| 2357 | 1657 | |
| 2358 | - /** |
|
| 2359 | - * ReCaptcha width |
|
| 2360 | - * |
|
| 2361 | - * @var int $recaptcha_width |
|
| 2362 | - * @deprecated |
|
| 2363 | - */ |
|
| 2364 | - public $recaptcha_width; |
|
| 1658 | +/** |
|
| 1659 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1660 | + */ |
|
| 1661 | +class EE_Core_Config extends EE_Config_Base |
|
| 1662 | +{ |
|
| 2365 | 1663 | |
| 2366 | - /** |
|
| 2367 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2368 | - * |
|
| 2369 | - * @var boolean $track_invalid_checkout_access |
|
| 2370 | - */ |
|
| 2371 | - protected $track_invalid_checkout_access = true; |
|
| 1664 | + public $current_blog_id; |
|
| 1665 | + |
|
| 1666 | + public $ee_ueip_optin; |
|
| 1667 | + |
|
| 1668 | + public $ee_ueip_has_notified; |
|
| 1669 | + |
|
| 1670 | + /** |
|
| 1671 | + * Not to be confused with the 4 critical page variables (See |
|
| 1672 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1673 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1674 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1675 | + * |
|
| 1676 | + * @var array |
|
| 1677 | + */ |
|
| 1678 | + public $post_shortcodes; |
|
| 1679 | + |
|
| 1680 | + public $module_route_map; |
|
| 1681 | + |
|
| 1682 | + public $module_forward_map; |
|
| 1683 | + |
|
| 1684 | + public $module_view_map; |
|
| 1685 | + |
|
| 1686 | + /** |
|
| 1687 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1688 | + * |
|
| 1689 | + * @var int |
|
| 1690 | + */ |
|
| 1691 | + public $reg_page_id; |
|
| 1692 | + |
|
| 1693 | + public $txn_page_id; |
|
| 1694 | + |
|
| 1695 | + public $thank_you_page_id; |
|
| 1696 | + |
|
| 1697 | + public $cancel_page_id; |
|
| 1698 | + |
|
| 1699 | + /** |
|
| 1700 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1701 | + * |
|
| 1702 | + * @var int |
|
| 1703 | + */ |
|
| 1704 | + public $reg_page_url; |
|
| 1705 | + |
|
| 1706 | + public $txn_page_url; |
|
| 1707 | + |
|
| 1708 | + public $thank_you_page_url; |
|
| 1709 | + |
|
| 1710 | + public $cancel_page_url; |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1714 | + */ |
|
| 1715 | + public $event_cpt_slug; |
|
| 1716 | + |
|
| 1717 | + |
|
| 1718 | + /** |
|
| 1719 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1720 | + * request across blog switches in a multisite context. |
|
| 1721 | + * Avoids extra queries to the db for this option. |
|
| 1722 | + * |
|
| 1723 | + * @var bool |
|
| 1724 | + */ |
|
| 1725 | + public static $ee_ueip_option; |
|
| 1726 | + |
|
| 1727 | + |
|
| 1728 | + |
|
| 1729 | + /** |
|
| 1730 | + * class constructor |
|
| 1731 | + * |
|
| 1732 | + * @access public |
|
| 1733 | + */ |
|
| 1734 | + public function __construct() |
|
| 1735 | + { |
|
| 1736 | + // set default organization settings |
|
| 1737 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1738 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1739 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1740 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1741 | + $this->post_shortcodes = array(); |
|
| 1742 | + $this->module_route_map = array(); |
|
| 1743 | + $this->module_forward_map = array(); |
|
| 1744 | + $this->module_view_map = array(); |
|
| 1745 | + // critical EE page IDs |
|
| 1746 | + $this->reg_page_id = 0; |
|
| 1747 | + $this->txn_page_id = 0; |
|
| 1748 | + $this->thank_you_page_id = 0; |
|
| 1749 | + $this->cancel_page_id = 0; |
|
| 1750 | + // critical EE page URLs |
|
| 1751 | + $this->reg_page_url = ''; |
|
| 1752 | + $this->txn_page_url = ''; |
|
| 1753 | + $this->thank_you_page_url = ''; |
|
| 1754 | + $this->cancel_page_url = ''; |
|
| 1755 | + //cpt slugs |
|
| 1756 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1757 | + //ueip constant check |
|
| 1758 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1759 | + $this->ee_ueip_optin = false; |
|
| 1760 | + $this->ee_ueip_has_notified = true; |
|
| 1761 | + } |
|
| 1762 | + } |
|
| 1763 | + |
|
| 1764 | + |
|
| 1765 | + |
|
| 1766 | + /** |
|
| 1767 | + * @return array |
|
| 1768 | + */ |
|
| 1769 | + public function get_critical_pages_array() |
|
| 1770 | + { |
|
| 1771 | + return array( |
|
| 1772 | + $this->reg_page_id, |
|
| 1773 | + $this->txn_page_id, |
|
| 1774 | + $this->thank_you_page_id, |
|
| 1775 | + $this->cancel_page_id, |
|
| 1776 | + ); |
|
| 1777 | + } |
|
| 1778 | + |
|
| 1779 | + |
|
| 1780 | + |
|
| 1781 | + /** |
|
| 1782 | + * @return array |
|
| 1783 | + */ |
|
| 1784 | + public function get_critical_pages_shortcodes_array() |
|
| 1785 | + { |
|
| 1786 | + return array( |
|
| 1787 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1788 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1789 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1790 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1791 | + ); |
|
| 1792 | + } |
|
| 1793 | + |
|
| 1794 | + |
|
| 1795 | + |
|
| 1796 | + /** |
|
| 1797 | + * gets/returns URL for EE reg_page |
|
| 1798 | + * |
|
| 1799 | + * @access public |
|
| 1800 | + * @return string |
|
| 1801 | + */ |
|
| 1802 | + public function reg_page_url() |
|
| 1803 | + { |
|
| 1804 | + if (! $this->reg_page_url) { |
|
| 1805 | + $this->reg_page_url = add_query_arg( |
|
| 1806 | + array('uts' => time()), |
|
| 1807 | + get_permalink($this->reg_page_id) |
|
| 1808 | + ) . '#checkout'; |
|
| 1809 | + } |
|
| 1810 | + return $this->reg_page_url; |
|
| 1811 | + } |
|
| 1812 | + |
|
| 1813 | + |
|
| 1814 | + |
|
| 1815 | + /** |
|
| 1816 | + * gets/returns URL for EE txn_page |
|
| 1817 | + * |
|
| 1818 | + * @param array $query_args like what gets passed to |
|
| 1819 | + * add_query_arg() as the first argument |
|
| 1820 | + * @access public |
|
| 1821 | + * @return string |
|
| 1822 | + */ |
|
| 1823 | + public function txn_page_url($query_args = array()) |
|
| 1824 | + { |
|
| 1825 | + if (! $this->txn_page_url) { |
|
| 1826 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1827 | + } |
|
| 1828 | + if ($query_args) { |
|
| 1829 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1830 | + } else { |
|
| 1831 | + return $this->txn_page_url; |
|
| 1832 | + } |
|
| 1833 | + } |
|
| 1834 | + |
|
| 1835 | + |
|
| 1836 | + |
|
| 1837 | + /** |
|
| 1838 | + * gets/returns URL for EE thank_you_page |
|
| 1839 | + * |
|
| 1840 | + * @param array $query_args like what gets passed to |
|
| 1841 | + * add_query_arg() as the first argument |
|
| 1842 | + * @access public |
|
| 1843 | + * @return string |
|
| 1844 | + */ |
|
| 1845 | + public function thank_you_page_url($query_args = array()) |
|
| 1846 | + { |
|
| 1847 | + if (! $this->thank_you_page_url) { |
|
| 1848 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1849 | + } |
|
| 1850 | + if ($query_args) { |
|
| 1851 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1852 | + } else { |
|
| 1853 | + return $this->thank_you_page_url; |
|
| 1854 | + } |
|
| 1855 | + } |
|
| 1856 | + |
|
| 1857 | + |
|
| 1858 | + |
|
| 1859 | + /** |
|
| 1860 | + * gets/returns URL for EE cancel_page |
|
| 1861 | + * |
|
| 1862 | + * @access public |
|
| 1863 | + * @return string |
|
| 1864 | + */ |
|
| 1865 | + public function cancel_page_url() |
|
| 1866 | + { |
|
| 1867 | + if (! $this->cancel_page_url) { |
|
| 1868 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1869 | + } |
|
| 1870 | + return $this->cancel_page_url; |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + |
|
| 1874 | + |
|
| 1875 | + /** |
|
| 1876 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1877 | + * |
|
| 1878 | + * @since 4.7.5 |
|
| 1879 | + */ |
|
| 1880 | + protected function _reset_urls() |
|
| 1881 | + { |
|
| 1882 | + $this->reg_page_url = ''; |
|
| 1883 | + $this->txn_page_url = ''; |
|
| 1884 | + $this->cancel_page_url = ''; |
|
| 1885 | + $this->thank_you_page_url = ''; |
|
| 1886 | + } |
|
| 1887 | + |
|
| 1888 | + |
|
| 1889 | + |
|
| 1890 | + /** |
|
| 1891 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1892 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1893 | + * on the main site only. |
|
| 1894 | + * |
|
| 1895 | + * @return mixed|void |
|
| 1896 | + */ |
|
| 1897 | + protected function _get_main_ee_ueip_optin() |
|
| 1898 | + { |
|
| 1899 | + //if this is the main site then we can just bypass our direct query. |
|
| 1900 | + if (is_main_site()) { |
|
| 1901 | + return get_option('ee_ueip_optin', false); |
|
| 1902 | + } |
|
| 1903 | + //is this already cached for this request? If so use it. |
|
| 1904 | + if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1905 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1906 | + } |
|
| 1907 | + global $wpdb; |
|
| 1908 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1909 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1910 | + $option = 'ee_ueip_optin'; |
|
| 1911 | + //set correct table for query |
|
| 1912 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1913 | + //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1914 | + //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1915 | + //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1916 | + //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1917 | + //for the purpose of caching. |
|
| 1918 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1919 | + if (false !== $pre) { |
|
| 1920 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1921 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1922 | + } |
|
| 1923 | + $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1924 | + $option)); |
|
| 1925 | + if (is_object($row)) { |
|
| 1926 | + $value = $row->option_value; |
|
| 1927 | + } else { //option does not exist so use default. |
|
| 1928 | + return apply_filters('default_option_' . $option, false, $option); |
|
| 1929 | + } |
|
| 1930 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1931 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + |
|
| 1935 | + |
|
| 1936 | + /** |
|
| 1937 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1938 | + * on the object. |
|
| 1939 | + * |
|
| 1940 | + * @return array |
|
| 1941 | + */ |
|
| 1942 | + public function __sleep() |
|
| 1943 | + { |
|
| 1944 | + //reset all url properties |
|
| 1945 | + $this->_reset_urls(); |
|
| 1946 | + //return what to save to db |
|
| 1947 | + return array_keys(get_object_vars($this)); |
|
| 1948 | + } |
|
| 2372 | 1949 | |
| 1950 | +} |
|
| 2373 | 1951 | |
| 2374 | 1952 | |
| 2375 | - /** |
|
| 2376 | - * class constructor |
|
| 2377 | - * |
|
| 2378 | - * @access public |
|
| 2379 | - */ |
|
| 2380 | - public function __construct() |
|
| 2381 | - { |
|
| 2382 | - // set default registration settings |
|
| 2383 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2384 | - $this->email_validation_level = 'wp_default'; |
|
| 2385 | - $this->show_pending_payment_options = true; |
|
| 2386 | - $this->skip_reg_confirmation = false; |
|
| 2387 | - $this->reg_steps = array(); |
|
| 2388 | - $this->reg_confirmation_last = false; |
|
| 2389 | - $this->use_bot_trap = true; |
|
| 2390 | - $this->use_encryption = true; |
|
| 2391 | - $this->use_captcha = false; |
|
| 2392 | - $this->recaptcha_theme = 'light'; |
|
| 2393 | - $this->recaptcha_type = 'image'; |
|
| 2394 | - $this->recaptcha_language = 'en'; |
|
| 2395 | - $this->recaptcha_publickey = null; |
|
| 2396 | - $this->recaptcha_privatekey = null; |
|
| 2397 | - $this->recaptcha_width = 500; |
|
| 2398 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2399 | - } |
|
| 2400 | - |
|
| 2401 | - |
|
| 2402 | - |
|
| 2403 | - /** |
|
| 2404 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2405 | - * |
|
| 2406 | - * @since 4.8.8.rc.019 |
|
| 2407 | - */ |
|
| 2408 | - public function do_hooks() |
|
| 2409 | - { |
|
| 2410 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2411 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2412 | - } |
|
| 2413 | 1953 | |
| 1954 | +/** |
|
| 1955 | + * Config class for storing info on the Organization |
|
| 1956 | + */ |
|
| 1957 | +class EE_Organization_Config extends EE_Config_Base |
|
| 1958 | +{ |
|
| 2414 | 1959 | |
| 1960 | + /** |
|
| 1961 | + * @var string $name |
|
| 1962 | + * eg EE4.1 |
|
| 1963 | + */ |
|
| 1964 | + public $name; |
|
| 1965 | + |
|
| 1966 | + /** |
|
| 1967 | + * @var string $address_1 |
|
| 1968 | + * eg 123 Onna Road |
|
| 1969 | + */ |
|
| 1970 | + public $address_1; |
|
| 1971 | + |
|
| 1972 | + /** |
|
| 1973 | + * @var string $address_2 |
|
| 1974 | + * eg PO Box 123 |
|
| 1975 | + */ |
|
| 1976 | + public $address_2; |
|
| 1977 | + |
|
| 1978 | + /** |
|
| 1979 | + * @var string $city |
|
| 1980 | + * eg Inna City |
|
| 1981 | + */ |
|
| 1982 | + public $city; |
|
| 1983 | + |
|
| 1984 | + /** |
|
| 1985 | + * @var int $STA_ID |
|
| 1986 | + * eg 4 |
|
| 1987 | + */ |
|
| 1988 | + public $STA_ID; |
|
| 1989 | + |
|
| 1990 | + /** |
|
| 1991 | + * @var string $CNT_ISO |
|
| 1992 | + * eg US |
|
| 1993 | + */ |
|
| 1994 | + public $CNT_ISO; |
|
| 1995 | + |
|
| 1996 | + /** |
|
| 1997 | + * @var string $zip |
|
| 1998 | + * eg 12345 or V1A 2B3 |
|
| 1999 | + */ |
|
| 2000 | + public $zip; |
|
| 2001 | + |
|
| 2002 | + /** |
|
| 2003 | + * @var string $email |
|
| 2004 | + * eg [email protected] |
|
| 2005 | + */ |
|
| 2006 | + public $email; |
|
| 2007 | + |
|
| 2008 | + |
|
| 2009 | + /** |
|
| 2010 | + * @var string $phone |
|
| 2011 | + * eg. 111-111-1111 |
|
| 2012 | + */ |
|
| 2013 | + public $phone; |
|
| 2014 | + |
|
| 2015 | + |
|
| 2016 | + /** |
|
| 2017 | + * @var string $vat |
|
| 2018 | + * VAT/Tax Number |
|
| 2019 | + */ |
|
| 2020 | + public $vat; |
|
| 2021 | + |
|
| 2022 | + /** |
|
| 2023 | + * @var string $logo_url |
|
| 2024 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2025 | + */ |
|
| 2026 | + public $logo_url; |
|
| 2027 | + |
|
| 2028 | + |
|
| 2029 | + /** |
|
| 2030 | + * The below are all various properties for holding links to organization social network profiles |
|
| 2031 | + * |
|
| 2032 | + * @var string |
|
| 2033 | + */ |
|
| 2034 | + /** |
|
| 2035 | + * facebook (facebook.com/profile.name) |
|
| 2036 | + * |
|
| 2037 | + * @var string |
|
| 2038 | + */ |
|
| 2039 | + public $facebook; |
|
| 2040 | + |
|
| 2041 | + |
|
| 2042 | + /** |
|
| 2043 | + * twitter (twitter.com/twitter_handle) |
|
| 2044 | + * |
|
| 2045 | + * @var string |
|
| 2046 | + */ |
|
| 2047 | + public $twitter; |
|
| 2048 | + |
|
| 2049 | + |
|
| 2050 | + /** |
|
| 2051 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2052 | + * |
|
| 2053 | + * @var string |
|
| 2054 | + */ |
|
| 2055 | + public $linkedin; |
|
| 2056 | + |
|
| 2057 | + |
|
| 2058 | + /** |
|
| 2059 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2060 | + * |
|
| 2061 | + * @var string |
|
| 2062 | + */ |
|
| 2063 | + public $pinterest; |
|
| 2064 | + |
|
| 2065 | + |
|
| 2066 | + /** |
|
| 2067 | + * google+ (google.com/+profileName) |
|
| 2068 | + * |
|
| 2069 | + * @var string |
|
| 2070 | + */ |
|
| 2071 | + public $google; |
|
| 2072 | + |
|
| 2073 | + |
|
| 2074 | + /** |
|
| 2075 | + * instagram (instagram.com/handle) |
|
| 2076 | + * |
|
| 2077 | + * @var string |
|
| 2078 | + */ |
|
| 2079 | + public $instagram; |
|
| 2080 | + |
|
| 2081 | + |
|
| 2082 | + |
|
| 2083 | + /** |
|
| 2084 | + * class constructor |
|
| 2085 | + * |
|
| 2086 | + * @access public |
|
| 2087 | + */ |
|
| 2088 | + public function __construct() |
|
| 2089 | + { |
|
| 2090 | + // set default organization settings |
|
| 2091 | + //decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2092 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2093 | + $this->address_1 = '123 Onna Road'; |
|
| 2094 | + $this->address_2 = 'PO Box 123'; |
|
| 2095 | + $this->city = 'Inna City'; |
|
| 2096 | + $this->STA_ID = 4; |
|
| 2097 | + $this->CNT_ISO = 'US'; |
|
| 2098 | + $this->zip = '12345'; |
|
| 2099 | + $this->email = get_bloginfo('admin_email'); |
|
| 2100 | + $this->phone = ''; |
|
| 2101 | + $this->vat = '123456789'; |
|
| 2102 | + $this->logo_url = ''; |
|
| 2103 | + $this->facebook = ''; |
|
| 2104 | + $this->twitter = ''; |
|
| 2105 | + $this->linkedin = ''; |
|
| 2106 | + $this->pinterest = ''; |
|
| 2107 | + $this->google = ''; |
|
| 2108 | + $this->instagram = ''; |
|
| 2109 | + } |
|
| 2415 | 2110 | |
| 2416 | - /** |
|
| 2417 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
| 2418 | - * field matches the config setting for default_STS_ID. |
|
| 2419 | - */ |
|
| 2420 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2421 | - { |
|
| 2422 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2423 | - } |
|
| 2111 | +} |
|
| 2424 | 2112 | |
| 2425 | 2113 | |
| 2426 | - /** |
|
| 2427 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2428 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2429 | - */ |
|
| 2430 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2431 | - { |
|
| 2432 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2433 | - } |
|
| 2434 | 2114 | |
| 2115 | +/** |
|
| 2116 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2117 | + */ |
|
| 2118 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2119 | +{ |
|
| 2435 | 2120 | |
| 2121 | + /** |
|
| 2122 | + * @var string $code |
|
| 2123 | + * eg 'US' |
|
| 2124 | + */ |
|
| 2125 | + public $code; |
|
| 2126 | + |
|
| 2127 | + /** |
|
| 2128 | + * @var string $name |
|
| 2129 | + * eg 'Dollar' |
|
| 2130 | + */ |
|
| 2131 | + public $name; |
|
| 2132 | + |
|
| 2133 | + /** |
|
| 2134 | + * plural name |
|
| 2135 | + * |
|
| 2136 | + * @var string $plural |
|
| 2137 | + * eg 'Dollars' |
|
| 2138 | + */ |
|
| 2139 | + public $plural; |
|
| 2140 | + |
|
| 2141 | + /** |
|
| 2142 | + * currency sign |
|
| 2143 | + * |
|
| 2144 | + * @var string $sign |
|
| 2145 | + * eg '$' |
|
| 2146 | + */ |
|
| 2147 | + public $sign; |
|
| 2148 | + |
|
| 2149 | + /** |
|
| 2150 | + * Whether the currency sign should come before the number or not |
|
| 2151 | + * |
|
| 2152 | + * @var boolean $sign_b4 |
|
| 2153 | + */ |
|
| 2154 | + public $sign_b4; |
|
| 2155 | + |
|
| 2156 | + /** |
|
| 2157 | + * How many digits should come after the decimal place |
|
| 2158 | + * |
|
| 2159 | + * @var int $dec_plc |
|
| 2160 | + */ |
|
| 2161 | + public $dec_plc; |
|
| 2162 | + |
|
| 2163 | + /** |
|
| 2164 | + * Symbol to use for decimal mark |
|
| 2165 | + * |
|
| 2166 | + * @var string $dec_mrk |
|
| 2167 | + * eg '.' |
|
| 2168 | + */ |
|
| 2169 | + public $dec_mrk; |
|
| 2170 | + |
|
| 2171 | + /** |
|
| 2172 | + * Symbol to use for thousands |
|
| 2173 | + * |
|
| 2174 | + * @var string $thsnds |
|
| 2175 | + * eg ',' |
|
| 2176 | + */ |
|
| 2177 | + public $thsnds; |
|
| 2178 | + |
|
| 2179 | + |
|
| 2180 | + |
|
| 2181 | + /** |
|
| 2182 | + * class constructor |
|
| 2183 | + * |
|
| 2184 | + * @access public |
|
| 2185 | + * @param string $CNT_ISO |
|
| 2186 | + * @throws \EE_Error |
|
| 2187 | + */ |
|
| 2188 | + public function __construct($CNT_ISO = '') |
|
| 2189 | + { |
|
| 2190 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2191 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2192 | + // get country code from organization settings or use default |
|
| 2193 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2194 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2195 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2196 | + : ''; |
|
| 2197 | + // but override if requested |
|
| 2198 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2199 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2200 | + if ( |
|
| 2201 | + ! empty($CNT_ISO) |
|
| 2202 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2203 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2204 | + ) { |
|
| 2205 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2206 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2207 | + if ($country instanceof EE_Country) { |
|
| 2208 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2209 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2210 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2211 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2212 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2213 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2214 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2215 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2216 | + } |
|
| 2217 | + } |
|
| 2218 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2219 | + if (empty($this->code)) { |
|
| 2220 | + // set default currency settings |
|
| 2221 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2222 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2223 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2224 | + $this->sign = '$'; // currency sign: $ |
|
| 2225 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2226 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2227 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2228 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2229 | + } |
|
| 2230 | + } |
|
| 2231 | +} |
|
| 2436 | 2232 | |
| 2437 | - /** |
|
| 2438 | - * @return boolean |
|
| 2439 | - */ |
|
| 2440 | - public function track_invalid_checkout_access() |
|
| 2441 | - { |
|
| 2442 | - return $this->track_invalid_checkout_access; |
|
| 2443 | - } |
|
| 2444 | 2233 | |
| 2445 | 2234 | |
| 2235 | +/** |
|
| 2236 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2237 | + */ |
|
| 2238 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2239 | +{ |
|
| 2446 | 2240 | |
| 2447 | - /** |
|
| 2448 | - * @param boolean $track_invalid_checkout_access |
|
| 2449 | - */ |
|
| 2450 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2451 | - { |
|
| 2452 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2453 | - $track_invalid_checkout_access, |
|
| 2454 | - FILTER_VALIDATE_BOOLEAN |
|
| 2455 | - ); |
|
| 2456 | - } |
|
| 2241 | + /** |
|
| 2242 | + * Default registration status |
|
| 2243 | + * |
|
| 2244 | + * @var string $default_STS_ID |
|
| 2245 | + * eg 'RPP' |
|
| 2246 | + */ |
|
| 2247 | + public $default_STS_ID; |
|
| 2248 | + |
|
| 2249 | + |
|
| 2250 | + /** |
|
| 2251 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2252 | + * registrations) |
|
| 2253 | + * @var int |
|
| 2254 | + */ |
|
| 2255 | + public $default_maximum_number_of_tickets; |
|
| 2256 | + |
|
| 2257 | + |
|
| 2258 | + /** |
|
| 2259 | + * level of validation to apply to email addresses |
|
| 2260 | + * |
|
| 2261 | + * @var string $email_validation_level |
|
| 2262 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2263 | + */ |
|
| 2264 | + public $email_validation_level; |
|
| 2265 | + |
|
| 2266 | + /** |
|
| 2267 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2268 | + * |
|
| 2269 | + * @var boolean $show_pending_payment_options |
|
| 2270 | + */ |
|
| 2271 | + public $show_pending_payment_options; |
|
| 2272 | + |
|
| 2273 | + /** |
|
| 2274 | + * Whether to skip the registration confirmation page |
|
| 2275 | + * |
|
| 2276 | + * @var boolean $skip_reg_confirmation |
|
| 2277 | + */ |
|
| 2278 | + public $skip_reg_confirmation; |
|
| 2279 | + |
|
| 2280 | + /** |
|
| 2281 | + * an array of SPCO reg steps where: |
|
| 2282 | + * the keys denotes the reg step order |
|
| 2283 | + * each element consists of an array with the following elements: |
|
| 2284 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2285 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2286 | + * "slug" => the URL param used to trigger the reg step |
|
| 2287 | + * |
|
| 2288 | + * @var array $reg_steps |
|
| 2289 | + */ |
|
| 2290 | + public $reg_steps; |
|
| 2291 | + |
|
| 2292 | + /** |
|
| 2293 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2294 | + * |
|
| 2295 | + * @var boolean $reg_confirmation_last |
|
| 2296 | + */ |
|
| 2297 | + public $reg_confirmation_last; |
|
| 2298 | + |
|
| 2299 | + /** |
|
| 2300 | + * Whether or not to enable the EE Bot Trap |
|
| 2301 | + * |
|
| 2302 | + * @var boolean $use_bot_trap |
|
| 2303 | + */ |
|
| 2304 | + public $use_bot_trap; |
|
| 2305 | + |
|
| 2306 | + /** |
|
| 2307 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2308 | + * |
|
| 2309 | + * @var boolean $use_encryption |
|
| 2310 | + */ |
|
| 2311 | + public $use_encryption; |
|
| 2312 | + |
|
| 2313 | + /** |
|
| 2314 | + * Whether or not to use ReCaptcha |
|
| 2315 | + * |
|
| 2316 | + * @var boolean $use_captcha |
|
| 2317 | + */ |
|
| 2318 | + public $use_captcha; |
|
| 2319 | + |
|
| 2320 | + /** |
|
| 2321 | + * ReCaptcha Theme |
|
| 2322 | + * |
|
| 2323 | + * @var string $recaptcha_theme |
|
| 2324 | + * options: 'dark ', 'light' |
|
| 2325 | + */ |
|
| 2326 | + public $recaptcha_theme; |
|
| 2327 | + |
|
| 2328 | + /** |
|
| 2329 | + * ReCaptcha Type |
|
| 2330 | + * |
|
| 2331 | + * @var string $recaptcha_type |
|
| 2332 | + * options: 'audio', 'image' |
|
| 2333 | + */ |
|
| 2334 | + public $recaptcha_type; |
|
| 2335 | + |
|
| 2336 | + /** |
|
| 2337 | + * ReCaptcha language |
|
| 2338 | + * |
|
| 2339 | + * @var string $recaptcha_language |
|
| 2340 | + * eg 'en' |
|
| 2341 | + */ |
|
| 2342 | + public $recaptcha_language; |
|
| 2343 | + |
|
| 2344 | + /** |
|
| 2345 | + * ReCaptcha public key |
|
| 2346 | + * |
|
| 2347 | + * @var string $recaptcha_publickey |
|
| 2348 | + */ |
|
| 2349 | + public $recaptcha_publickey; |
|
| 2350 | + |
|
| 2351 | + /** |
|
| 2352 | + * ReCaptcha private key |
|
| 2353 | + * |
|
| 2354 | + * @var string $recaptcha_privatekey |
|
| 2355 | + */ |
|
| 2356 | + public $recaptcha_privatekey; |
|
| 2357 | + |
|
| 2358 | + /** |
|
| 2359 | + * ReCaptcha width |
|
| 2360 | + * |
|
| 2361 | + * @var int $recaptcha_width |
|
| 2362 | + * @deprecated |
|
| 2363 | + */ |
|
| 2364 | + public $recaptcha_width; |
|
| 2365 | + |
|
| 2366 | + /** |
|
| 2367 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2368 | + * |
|
| 2369 | + * @var boolean $track_invalid_checkout_access |
|
| 2370 | + */ |
|
| 2371 | + protected $track_invalid_checkout_access = true; |
|
| 2372 | + |
|
| 2373 | + |
|
| 2374 | + |
|
| 2375 | + /** |
|
| 2376 | + * class constructor |
|
| 2377 | + * |
|
| 2378 | + * @access public |
|
| 2379 | + */ |
|
| 2380 | + public function __construct() |
|
| 2381 | + { |
|
| 2382 | + // set default registration settings |
|
| 2383 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2384 | + $this->email_validation_level = 'wp_default'; |
|
| 2385 | + $this->show_pending_payment_options = true; |
|
| 2386 | + $this->skip_reg_confirmation = false; |
|
| 2387 | + $this->reg_steps = array(); |
|
| 2388 | + $this->reg_confirmation_last = false; |
|
| 2389 | + $this->use_bot_trap = true; |
|
| 2390 | + $this->use_encryption = true; |
|
| 2391 | + $this->use_captcha = false; |
|
| 2392 | + $this->recaptcha_theme = 'light'; |
|
| 2393 | + $this->recaptcha_type = 'image'; |
|
| 2394 | + $this->recaptcha_language = 'en'; |
|
| 2395 | + $this->recaptcha_publickey = null; |
|
| 2396 | + $this->recaptcha_privatekey = null; |
|
| 2397 | + $this->recaptcha_width = 500; |
|
| 2398 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2399 | + } |
|
| 2400 | + |
|
| 2401 | + |
|
| 2402 | + |
|
| 2403 | + /** |
|
| 2404 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2405 | + * |
|
| 2406 | + * @since 4.8.8.rc.019 |
|
| 2407 | + */ |
|
| 2408 | + public function do_hooks() |
|
| 2409 | + { |
|
| 2410 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2411 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2412 | + } |
|
| 2413 | + |
|
| 2414 | + |
|
| 2415 | + |
|
| 2416 | + /** |
|
| 2417 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
| 2418 | + * field matches the config setting for default_STS_ID. |
|
| 2419 | + */ |
|
| 2420 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2421 | + { |
|
| 2422 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2423 | + } |
|
| 2424 | + |
|
| 2425 | + |
|
| 2426 | + /** |
|
| 2427 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2428 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2429 | + */ |
|
| 2430 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2431 | + { |
|
| 2432 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2433 | + } |
|
| 2434 | + |
|
| 2435 | + |
|
| 2436 | + |
|
| 2437 | + /** |
|
| 2438 | + * @return boolean |
|
| 2439 | + */ |
|
| 2440 | + public function track_invalid_checkout_access() |
|
| 2441 | + { |
|
| 2442 | + return $this->track_invalid_checkout_access; |
|
| 2443 | + } |
|
| 2444 | + |
|
| 2445 | + |
|
| 2446 | + |
|
| 2447 | + /** |
|
| 2448 | + * @param boolean $track_invalid_checkout_access |
|
| 2449 | + */ |
|
| 2450 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2451 | + { |
|
| 2452 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2453 | + $track_invalid_checkout_access, |
|
| 2454 | + FILTER_VALIDATE_BOOLEAN |
|
| 2455 | + ); |
|
| 2456 | + } |
|
| 2457 | 2457 | |
| 2458 | 2458 | |
| 2459 | 2459 | |
@@ -2467,160 +2467,160 @@ discard block |
||
| 2467 | 2467 | class EE_Admin_Config extends EE_Config_Base |
| 2468 | 2468 | { |
| 2469 | 2469 | |
| 2470 | - /** |
|
| 2471 | - * @var boolean $use_personnel_manager |
|
| 2472 | - */ |
|
| 2473 | - public $use_personnel_manager; |
|
| 2474 | - |
|
| 2475 | - /** |
|
| 2476 | - * @var boolean $use_dashboard_widget |
|
| 2477 | - */ |
|
| 2478 | - public $use_dashboard_widget; |
|
| 2479 | - |
|
| 2480 | - /** |
|
| 2481 | - * @var int $events_in_dashboard |
|
| 2482 | - */ |
|
| 2483 | - public $events_in_dashboard; |
|
| 2484 | - |
|
| 2485 | - /** |
|
| 2486 | - * @var boolean $use_event_timezones |
|
| 2487 | - */ |
|
| 2488 | - public $use_event_timezones; |
|
| 2489 | - |
|
| 2490 | - /** |
|
| 2491 | - * @var boolean $use_full_logging |
|
| 2492 | - */ |
|
| 2493 | - public $use_full_logging; |
|
| 2494 | - |
|
| 2495 | - /** |
|
| 2496 | - * @var string $log_file_name |
|
| 2497 | - */ |
|
| 2498 | - public $log_file_name; |
|
| 2499 | - |
|
| 2500 | - /** |
|
| 2501 | - * @var string $debug_file_name |
|
| 2502 | - */ |
|
| 2503 | - public $debug_file_name; |
|
| 2504 | - |
|
| 2505 | - /** |
|
| 2506 | - * @var boolean $use_remote_logging |
|
| 2507 | - */ |
|
| 2508 | - public $use_remote_logging; |
|
| 2509 | - |
|
| 2510 | - /** |
|
| 2511 | - * @var string $remote_logging_url |
|
| 2512 | - */ |
|
| 2513 | - public $remote_logging_url; |
|
| 2514 | - |
|
| 2515 | - /** |
|
| 2516 | - * @var boolean $show_reg_footer |
|
| 2517 | - */ |
|
| 2518 | - public $show_reg_footer; |
|
| 2519 | - |
|
| 2520 | - /** |
|
| 2521 | - * @var string $affiliate_id |
|
| 2522 | - */ |
|
| 2523 | - public $affiliate_id; |
|
| 2524 | - |
|
| 2525 | - /** |
|
| 2526 | - * help tours on or off (global setting) |
|
| 2527 | - * |
|
| 2528 | - * @var boolean |
|
| 2529 | - */ |
|
| 2530 | - public $help_tour_activation; |
|
| 2531 | - |
|
| 2532 | - /** |
|
| 2533 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2534 | - * but is incompatible with some server configuration errors |
|
| 2535 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2536 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2537 | - * |
|
| 2538 | - * @var boolean $encode_session_data |
|
| 2539 | - */ |
|
| 2540 | - private $encode_session_data = false; |
|
| 2541 | - |
|
| 2542 | - |
|
| 2543 | - |
|
| 2544 | - /** |
|
| 2545 | - * class constructor |
|
| 2546 | - * |
|
| 2547 | - * @access public |
|
| 2548 | - */ |
|
| 2549 | - public function __construct() |
|
| 2550 | - { |
|
| 2551 | - // set default general admin settings |
|
| 2552 | - $this->use_personnel_manager = true; |
|
| 2553 | - $this->use_dashboard_widget = true; |
|
| 2554 | - $this->events_in_dashboard = 30; |
|
| 2555 | - $this->use_event_timezones = false; |
|
| 2556 | - $this->use_full_logging = false; |
|
| 2557 | - $this->use_remote_logging = false; |
|
| 2558 | - $this->remote_logging_url = null; |
|
| 2559 | - $this->show_reg_footer = true; |
|
| 2560 | - $this->affiliate_id = 'default'; |
|
| 2561 | - $this->help_tour_activation = true; |
|
| 2562 | - $this->encode_session_data = false; |
|
| 2563 | - } |
|
| 2564 | - |
|
| 2565 | - |
|
| 2566 | - |
|
| 2567 | - /** |
|
| 2568 | - * @param bool $reset |
|
| 2569 | - * @return string |
|
| 2570 | - */ |
|
| 2571 | - public function log_file_name($reset = false) |
|
| 2572 | - { |
|
| 2573 | - if (empty($this->log_file_name) || $reset) { |
|
| 2574 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2575 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2576 | - } |
|
| 2577 | - return $this->log_file_name; |
|
| 2578 | - } |
|
| 2579 | - |
|
| 2580 | - |
|
| 2581 | - |
|
| 2582 | - /** |
|
| 2583 | - * @param bool $reset |
|
| 2584 | - * @return string |
|
| 2585 | - */ |
|
| 2586 | - public function debug_file_name($reset = false) |
|
| 2587 | - { |
|
| 2588 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2589 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2590 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2591 | - } |
|
| 2592 | - return $this->debug_file_name; |
|
| 2593 | - } |
|
| 2594 | - |
|
| 2595 | - |
|
| 2596 | - |
|
| 2597 | - /** |
|
| 2598 | - * @return string |
|
| 2599 | - */ |
|
| 2600 | - public function affiliate_id() |
|
| 2601 | - { |
|
| 2602 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2603 | - } |
|
| 2604 | - |
|
| 2605 | - |
|
| 2606 | - |
|
| 2607 | - /** |
|
| 2608 | - * @return boolean |
|
| 2609 | - */ |
|
| 2610 | - public function encode_session_data() |
|
| 2611 | - { |
|
| 2612 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2613 | - } |
|
| 2614 | - |
|
| 2615 | - |
|
| 2616 | - |
|
| 2617 | - /** |
|
| 2618 | - * @param boolean $encode_session_data |
|
| 2619 | - */ |
|
| 2620 | - public function set_encode_session_data($encode_session_data) |
|
| 2621 | - { |
|
| 2622 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2623 | - } |
|
| 2470 | + /** |
|
| 2471 | + * @var boolean $use_personnel_manager |
|
| 2472 | + */ |
|
| 2473 | + public $use_personnel_manager; |
|
| 2474 | + |
|
| 2475 | + /** |
|
| 2476 | + * @var boolean $use_dashboard_widget |
|
| 2477 | + */ |
|
| 2478 | + public $use_dashboard_widget; |
|
| 2479 | + |
|
| 2480 | + /** |
|
| 2481 | + * @var int $events_in_dashboard |
|
| 2482 | + */ |
|
| 2483 | + public $events_in_dashboard; |
|
| 2484 | + |
|
| 2485 | + /** |
|
| 2486 | + * @var boolean $use_event_timezones |
|
| 2487 | + */ |
|
| 2488 | + public $use_event_timezones; |
|
| 2489 | + |
|
| 2490 | + /** |
|
| 2491 | + * @var boolean $use_full_logging |
|
| 2492 | + */ |
|
| 2493 | + public $use_full_logging; |
|
| 2494 | + |
|
| 2495 | + /** |
|
| 2496 | + * @var string $log_file_name |
|
| 2497 | + */ |
|
| 2498 | + public $log_file_name; |
|
| 2499 | + |
|
| 2500 | + /** |
|
| 2501 | + * @var string $debug_file_name |
|
| 2502 | + */ |
|
| 2503 | + public $debug_file_name; |
|
| 2504 | + |
|
| 2505 | + /** |
|
| 2506 | + * @var boolean $use_remote_logging |
|
| 2507 | + */ |
|
| 2508 | + public $use_remote_logging; |
|
| 2509 | + |
|
| 2510 | + /** |
|
| 2511 | + * @var string $remote_logging_url |
|
| 2512 | + */ |
|
| 2513 | + public $remote_logging_url; |
|
| 2514 | + |
|
| 2515 | + /** |
|
| 2516 | + * @var boolean $show_reg_footer |
|
| 2517 | + */ |
|
| 2518 | + public $show_reg_footer; |
|
| 2519 | + |
|
| 2520 | + /** |
|
| 2521 | + * @var string $affiliate_id |
|
| 2522 | + */ |
|
| 2523 | + public $affiliate_id; |
|
| 2524 | + |
|
| 2525 | + /** |
|
| 2526 | + * help tours on or off (global setting) |
|
| 2527 | + * |
|
| 2528 | + * @var boolean |
|
| 2529 | + */ |
|
| 2530 | + public $help_tour_activation; |
|
| 2531 | + |
|
| 2532 | + /** |
|
| 2533 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2534 | + * but is incompatible with some server configuration errors |
|
| 2535 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2536 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2537 | + * |
|
| 2538 | + * @var boolean $encode_session_data |
|
| 2539 | + */ |
|
| 2540 | + private $encode_session_data = false; |
|
| 2541 | + |
|
| 2542 | + |
|
| 2543 | + |
|
| 2544 | + /** |
|
| 2545 | + * class constructor |
|
| 2546 | + * |
|
| 2547 | + * @access public |
|
| 2548 | + */ |
|
| 2549 | + public function __construct() |
|
| 2550 | + { |
|
| 2551 | + // set default general admin settings |
|
| 2552 | + $this->use_personnel_manager = true; |
|
| 2553 | + $this->use_dashboard_widget = true; |
|
| 2554 | + $this->events_in_dashboard = 30; |
|
| 2555 | + $this->use_event_timezones = false; |
|
| 2556 | + $this->use_full_logging = false; |
|
| 2557 | + $this->use_remote_logging = false; |
|
| 2558 | + $this->remote_logging_url = null; |
|
| 2559 | + $this->show_reg_footer = true; |
|
| 2560 | + $this->affiliate_id = 'default'; |
|
| 2561 | + $this->help_tour_activation = true; |
|
| 2562 | + $this->encode_session_data = false; |
|
| 2563 | + } |
|
| 2564 | + |
|
| 2565 | + |
|
| 2566 | + |
|
| 2567 | + /** |
|
| 2568 | + * @param bool $reset |
|
| 2569 | + * @return string |
|
| 2570 | + */ |
|
| 2571 | + public function log_file_name($reset = false) |
|
| 2572 | + { |
|
| 2573 | + if (empty($this->log_file_name) || $reset) { |
|
| 2574 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2575 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2576 | + } |
|
| 2577 | + return $this->log_file_name; |
|
| 2578 | + } |
|
| 2579 | + |
|
| 2580 | + |
|
| 2581 | + |
|
| 2582 | + /** |
|
| 2583 | + * @param bool $reset |
|
| 2584 | + * @return string |
|
| 2585 | + */ |
|
| 2586 | + public function debug_file_name($reset = false) |
|
| 2587 | + { |
|
| 2588 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2589 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2590 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2591 | + } |
|
| 2592 | + return $this->debug_file_name; |
|
| 2593 | + } |
|
| 2594 | + |
|
| 2595 | + |
|
| 2596 | + |
|
| 2597 | + /** |
|
| 2598 | + * @return string |
|
| 2599 | + */ |
|
| 2600 | + public function affiliate_id() |
|
| 2601 | + { |
|
| 2602 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2603 | + } |
|
| 2604 | + |
|
| 2605 | + |
|
| 2606 | + |
|
| 2607 | + /** |
|
| 2608 | + * @return boolean |
|
| 2609 | + */ |
|
| 2610 | + public function encode_session_data() |
|
| 2611 | + { |
|
| 2612 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2613 | + } |
|
| 2614 | + |
|
| 2615 | + |
|
| 2616 | + |
|
| 2617 | + /** |
|
| 2618 | + * @param boolean $encode_session_data |
|
| 2619 | + */ |
|
| 2620 | + public function set_encode_session_data($encode_session_data) |
|
| 2621 | + { |
|
| 2622 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2623 | + } |
|
| 2624 | 2624 | |
| 2625 | 2625 | |
| 2626 | 2626 | |
@@ -2634,71 +2634,71 @@ discard block |
||
| 2634 | 2634 | class EE_Template_Config extends EE_Config_Base |
| 2635 | 2635 | { |
| 2636 | 2636 | |
| 2637 | - /** |
|
| 2638 | - * @var boolean $enable_default_style |
|
| 2639 | - */ |
|
| 2640 | - public $enable_default_style; |
|
| 2641 | - |
|
| 2642 | - /** |
|
| 2643 | - * @var string $custom_style_sheet |
|
| 2644 | - */ |
|
| 2645 | - public $custom_style_sheet; |
|
| 2646 | - |
|
| 2647 | - /** |
|
| 2648 | - * @var boolean $display_address_in_regform |
|
| 2649 | - */ |
|
| 2650 | - public $display_address_in_regform; |
|
| 2651 | - |
|
| 2652 | - /** |
|
| 2653 | - * @var int $display_description_on_multi_reg_page |
|
| 2654 | - */ |
|
| 2655 | - public $display_description_on_multi_reg_page; |
|
| 2656 | - |
|
| 2657 | - /** |
|
| 2658 | - * @var boolean $use_custom_templates |
|
| 2659 | - */ |
|
| 2660 | - public $use_custom_templates; |
|
| 2661 | - |
|
| 2662 | - /** |
|
| 2663 | - * @var string $current_espresso_theme |
|
| 2664 | - */ |
|
| 2665 | - public $current_espresso_theme; |
|
| 2666 | - |
|
| 2667 | - /** |
|
| 2668 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2669 | - */ |
|
| 2670 | - public $EED_Ticket_Selector; |
|
| 2671 | - |
|
| 2672 | - /** |
|
| 2673 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2674 | - */ |
|
| 2675 | - public $EED_Event_Single; |
|
| 2676 | - |
|
| 2677 | - /** |
|
| 2678 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2679 | - */ |
|
| 2680 | - public $EED_Events_Archive; |
|
| 2681 | - |
|
| 2682 | - |
|
| 2683 | - |
|
| 2684 | - /** |
|
| 2685 | - * class constructor |
|
| 2686 | - * |
|
| 2687 | - * @access public |
|
| 2688 | - */ |
|
| 2689 | - public function __construct() |
|
| 2690 | - { |
|
| 2691 | - // set default template settings |
|
| 2692 | - $this->enable_default_style = true; |
|
| 2693 | - $this->custom_style_sheet = null; |
|
| 2694 | - $this->display_address_in_regform = true; |
|
| 2695 | - $this->display_description_on_multi_reg_page = false; |
|
| 2696 | - $this->use_custom_templates = false; |
|
| 2697 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2698 | - $this->EED_Event_Single = null; |
|
| 2699 | - $this->EED_Events_Archive = null; |
|
| 2700 | - $this->EED_Ticket_Selector = null; |
|
| 2701 | - } |
|
| 2637 | + /** |
|
| 2638 | + * @var boolean $enable_default_style |
|
| 2639 | + */ |
|
| 2640 | + public $enable_default_style; |
|
| 2641 | + |
|
| 2642 | + /** |
|
| 2643 | + * @var string $custom_style_sheet |
|
| 2644 | + */ |
|
| 2645 | + public $custom_style_sheet; |
|
| 2646 | + |
|
| 2647 | + /** |
|
| 2648 | + * @var boolean $display_address_in_regform |
|
| 2649 | + */ |
|
| 2650 | + public $display_address_in_regform; |
|
| 2651 | + |
|
| 2652 | + /** |
|
| 2653 | + * @var int $display_description_on_multi_reg_page |
|
| 2654 | + */ |
|
| 2655 | + public $display_description_on_multi_reg_page; |
|
| 2656 | + |
|
| 2657 | + /** |
|
| 2658 | + * @var boolean $use_custom_templates |
|
| 2659 | + */ |
|
| 2660 | + public $use_custom_templates; |
|
| 2661 | + |
|
| 2662 | + /** |
|
| 2663 | + * @var string $current_espresso_theme |
|
| 2664 | + */ |
|
| 2665 | + public $current_espresso_theme; |
|
| 2666 | + |
|
| 2667 | + /** |
|
| 2668 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2669 | + */ |
|
| 2670 | + public $EED_Ticket_Selector; |
|
| 2671 | + |
|
| 2672 | + /** |
|
| 2673 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2674 | + */ |
|
| 2675 | + public $EED_Event_Single; |
|
| 2676 | + |
|
| 2677 | + /** |
|
| 2678 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2679 | + */ |
|
| 2680 | + public $EED_Events_Archive; |
|
| 2681 | + |
|
| 2682 | + |
|
| 2683 | + |
|
| 2684 | + /** |
|
| 2685 | + * class constructor |
|
| 2686 | + * |
|
| 2687 | + * @access public |
|
| 2688 | + */ |
|
| 2689 | + public function __construct() |
|
| 2690 | + { |
|
| 2691 | + // set default template settings |
|
| 2692 | + $this->enable_default_style = true; |
|
| 2693 | + $this->custom_style_sheet = null; |
|
| 2694 | + $this->display_address_in_regform = true; |
|
| 2695 | + $this->display_description_on_multi_reg_page = false; |
|
| 2696 | + $this->use_custom_templates = false; |
|
| 2697 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2698 | + $this->EED_Event_Single = null; |
|
| 2699 | + $this->EED_Events_Archive = null; |
|
| 2700 | + $this->EED_Ticket_Selector = null; |
|
| 2701 | + } |
|
| 2702 | 2702 | |
| 2703 | 2703 | } |
| 2704 | 2704 | |
@@ -2710,115 +2710,115 @@ discard block |
||
| 2710 | 2710 | class EE_Map_Config extends EE_Config_Base |
| 2711 | 2711 | { |
| 2712 | 2712 | |
| 2713 | - /** |
|
| 2714 | - * @var boolean $use_google_maps |
|
| 2715 | - */ |
|
| 2716 | - public $use_google_maps; |
|
| 2717 | - |
|
| 2718 | - /** |
|
| 2719 | - * @var string $api_key |
|
| 2720 | - */ |
|
| 2721 | - public $google_map_api_key; |
|
| 2722 | - |
|
| 2723 | - /** |
|
| 2724 | - * @var int $event_details_map_width |
|
| 2725 | - */ |
|
| 2726 | - public $event_details_map_width; |
|
| 2727 | - |
|
| 2728 | - /** |
|
| 2729 | - * @var int $event_details_map_height |
|
| 2730 | - */ |
|
| 2731 | - public $event_details_map_height; |
|
| 2732 | - |
|
| 2733 | - /** |
|
| 2734 | - * @var int $event_details_map_zoom |
|
| 2735 | - */ |
|
| 2736 | - public $event_details_map_zoom; |
|
| 2737 | - |
|
| 2738 | - /** |
|
| 2739 | - * @var boolean $event_details_display_nav |
|
| 2740 | - */ |
|
| 2741 | - public $event_details_display_nav; |
|
| 2742 | - |
|
| 2743 | - /** |
|
| 2744 | - * @var boolean $event_details_nav_size |
|
| 2745 | - */ |
|
| 2746 | - public $event_details_nav_size; |
|
| 2747 | - |
|
| 2748 | - /** |
|
| 2749 | - * @var string $event_details_control_type |
|
| 2750 | - */ |
|
| 2751 | - public $event_details_control_type; |
|
| 2752 | - |
|
| 2753 | - /** |
|
| 2754 | - * @var string $event_details_map_align |
|
| 2755 | - */ |
|
| 2756 | - public $event_details_map_align; |
|
| 2757 | - |
|
| 2758 | - /** |
|
| 2759 | - * @var int $event_list_map_width |
|
| 2760 | - */ |
|
| 2761 | - public $event_list_map_width; |
|
| 2762 | - |
|
| 2763 | - /** |
|
| 2764 | - * @var int $event_list_map_height |
|
| 2765 | - */ |
|
| 2766 | - public $event_list_map_height; |
|
| 2767 | - |
|
| 2768 | - /** |
|
| 2769 | - * @var int $event_list_map_zoom |
|
| 2770 | - */ |
|
| 2771 | - public $event_list_map_zoom; |
|
| 2772 | - |
|
| 2773 | - /** |
|
| 2774 | - * @var boolean $event_list_display_nav |
|
| 2775 | - */ |
|
| 2776 | - public $event_list_display_nav; |
|
| 2777 | - |
|
| 2778 | - /** |
|
| 2779 | - * @var boolean $event_list_nav_size |
|
| 2780 | - */ |
|
| 2781 | - public $event_list_nav_size; |
|
| 2782 | - |
|
| 2783 | - /** |
|
| 2784 | - * @var string $event_list_control_type |
|
| 2785 | - */ |
|
| 2786 | - public $event_list_control_type; |
|
| 2787 | - |
|
| 2788 | - /** |
|
| 2789 | - * @var string $event_list_map_align |
|
| 2790 | - */ |
|
| 2791 | - public $event_list_map_align; |
|
| 2792 | - |
|
| 2793 | - |
|
| 2794 | - |
|
| 2795 | - /** |
|
| 2796 | - * class constructor |
|
| 2797 | - * |
|
| 2798 | - * @access public |
|
| 2799 | - */ |
|
| 2800 | - public function __construct() |
|
| 2801 | - { |
|
| 2802 | - // set default map settings |
|
| 2803 | - $this->use_google_maps = true; |
|
| 2804 | - $this->google_map_api_key = ''; |
|
| 2805 | - // for event details pages (reg page) |
|
| 2806 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2807 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2808 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2809 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2810 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2811 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2812 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2813 | - // for event list pages |
|
| 2814 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2815 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2816 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2817 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2818 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2819 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2820 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2821 | - } |
|
| 2713 | + /** |
|
| 2714 | + * @var boolean $use_google_maps |
|
| 2715 | + */ |
|
| 2716 | + public $use_google_maps; |
|
| 2717 | + |
|
| 2718 | + /** |
|
| 2719 | + * @var string $api_key |
|
| 2720 | + */ |
|
| 2721 | + public $google_map_api_key; |
|
| 2722 | + |
|
| 2723 | + /** |
|
| 2724 | + * @var int $event_details_map_width |
|
| 2725 | + */ |
|
| 2726 | + public $event_details_map_width; |
|
| 2727 | + |
|
| 2728 | + /** |
|
| 2729 | + * @var int $event_details_map_height |
|
| 2730 | + */ |
|
| 2731 | + public $event_details_map_height; |
|
| 2732 | + |
|
| 2733 | + /** |
|
| 2734 | + * @var int $event_details_map_zoom |
|
| 2735 | + */ |
|
| 2736 | + public $event_details_map_zoom; |
|
| 2737 | + |
|
| 2738 | + /** |
|
| 2739 | + * @var boolean $event_details_display_nav |
|
| 2740 | + */ |
|
| 2741 | + public $event_details_display_nav; |
|
| 2742 | + |
|
| 2743 | + /** |
|
| 2744 | + * @var boolean $event_details_nav_size |
|
| 2745 | + */ |
|
| 2746 | + public $event_details_nav_size; |
|
| 2747 | + |
|
| 2748 | + /** |
|
| 2749 | + * @var string $event_details_control_type |
|
| 2750 | + */ |
|
| 2751 | + public $event_details_control_type; |
|
| 2752 | + |
|
| 2753 | + /** |
|
| 2754 | + * @var string $event_details_map_align |
|
| 2755 | + */ |
|
| 2756 | + public $event_details_map_align; |
|
| 2757 | + |
|
| 2758 | + /** |
|
| 2759 | + * @var int $event_list_map_width |
|
| 2760 | + */ |
|
| 2761 | + public $event_list_map_width; |
|
| 2762 | + |
|
| 2763 | + /** |
|
| 2764 | + * @var int $event_list_map_height |
|
| 2765 | + */ |
|
| 2766 | + public $event_list_map_height; |
|
| 2767 | + |
|
| 2768 | + /** |
|
| 2769 | + * @var int $event_list_map_zoom |
|
| 2770 | + */ |
|
| 2771 | + public $event_list_map_zoom; |
|
| 2772 | + |
|
| 2773 | + /** |
|
| 2774 | + * @var boolean $event_list_display_nav |
|
| 2775 | + */ |
|
| 2776 | + public $event_list_display_nav; |
|
| 2777 | + |
|
| 2778 | + /** |
|
| 2779 | + * @var boolean $event_list_nav_size |
|
| 2780 | + */ |
|
| 2781 | + public $event_list_nav_size; |
|
| 2782 | + |
|
| 2783 | + /** |
|
| 2784 | + * @var string $event_list_control_type |
|
| 2785 | + */ |
|
| 2786 | + public $event_list_control_type; |
|
| 2787 | + |
|
| 2788 | + /** |
|
| 2789 | + * @var string $event_list_map_align |
|
| 2790 | + */ |
|
| 2791 | + public $event_list_map_align; |
|
| 2792 | + |
|
| 2793 | + |
|
| 2794 | + |
|
| 2795 | + /** |
|
| 2796 | + * class constructor |
|
| 2797 | + * |
|
| 2798 | + * @access public |
|
| 2799 | + */ |
|
| 2800 | + public function __construct() |
|
| 2801 | + { |
|
| 2802 | + // set default map settings |
|
| 2803 | + $this->use_google_maps = true; |
|
| 2804 | + $this->google_map_api_key = ''; |
|
| 2805 | + // for event details pages (reg page) |
|
| 2806 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2807 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2808 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2809 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2810 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2811 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2812 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2813 | + // for event list pages |
|
| 2814 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2815 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2816 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2817 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2818 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2819 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2820 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2821 | + } |
|
| 2822 | 2822 | |
| 2823 | 2823 | } |
| 2824 | 2824 | |
@@ -2830,47 +2830,47 @@ discard block |
||
| 2830 | 2830 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2831 | 2831 | { |
| 2832 | 2832 | |
| 2833 | - public $display_status_banner; |
|
| 2833 | + public $display_status_banner; |
|
| 2834 | 2834 | |
| 2835 | - public $display_description; |
|
| 2835 | + public $display_description; |
|
| 2836 | 2836 | |
| 2837 | - public $display_ticket_selector; |
|
| 2837 | + public $display_ticket_selector; |
|
| 2838 | 2838 | |
| 2839 | - public $display_datetimes; |
|
| 2839 | + public $display_datetimes; |
|
| 2840 | 2840 | |
| 2841 | - public $display_venue; |
|
| 2841 | + public $display_venue; |
|
| 2842 | 2842 | |
| 2843 | - public $display_expired_events; |
|
| 2843 | + public $display_expired_events; |
|
| 2844 | 2844 | |
| 2845 | - public $use_sortable_display_order; |
|
| 2845 | + public $use_sortable_display_order; |
|
| 2846 | 2846 | |
| 2847 | - public $display_order_tickets; |
|
| 2847 | + public $display_order_tickets; |
|
| 2848 | 2848 | |
| 2849 | - public $display_order_datetimes; |
|
| 2849 | + public $display_order_datetimes; |
|
| 2850 | 2850 | |
| 2851 | - public $display_order_event; |
|
| 2851 | + public $display_order_event; |
|
| 2852 | 2852 | |
| 2853 | - public $display_order_venue; |
|
| 2853 | + public $display_order_venue; |
|
| 2854 | 2854 | |
| 2855 | 2855 | |
| 2856 | 2856 | |
| 2857 | - /** |
|
| 2858 | - * class constructor |
|
| 2859 | - */ |
|
| 2860 | - public function __construct() |
|
| 2861 | - { |
|
| 2862 | - $this->display_status_banner = 0; |
|
| 2863 | - $this->display_description = 1; |
|
| 2864 | - $this->display_ticket_selector = 0; |
|
| 2865 | - $this->display_datetimes = 1; |
|
| 2866 | - $this->display_venue = 0; |
|
| 2867 | - $this->display_expired_events = 0; |
|
| 2868 | - $this->use_sortable_display_order = false; |
|
| 2869 | - $this->display_order_tickets = 100; |
|
| 2870 | - $this->display_order_datetimes = 110; |
|
| 2871 | - $this->display_order_event = 120; |
|
| 2872 | - $this->display_order_venue = 130; |
|
| 2873 | - } |
|
| 2857 | + /** |
|
| 2858 | + * class constructor |
|
| 2859 | + */ |
|
| 2860 | + public function __construct() |
|
| 2861 | + { |
|
| 2862 | + $this->display_status_banner = 0; |
|
| 2863 | + $this->display_description = 1; |
|
| 2864 | + $this->display_ticket_selector = 0; |
|
| 2865 | + $this->display_datetimes = 1; |
|
| 2866 | + $this->display_venue = 0; |
|
| 2867 | + $this->display_expired_events = 0; |
|
| 2868 | + $this->use_sortable_display_order = false; |
|
| 2869 | + $this->display_order_tickets = 100; |
|
| 2870 | + $this->display_order_datetimes = 110; |
|
| 2871 | + $this->display_order_event = 120; |
|
| 2872 | + $this->display_order_venue = 130; |
|
| 2873 | + } |
|
| 2874 | 2874 | } |
| 2875 | 2875 | |
| 2876 | 2876 | |
@@ -2881,35 +2881,35 @@ discard block |
||
| 2881 | 2881 | class EE_Event_Single_Config extends EE_Config_Base |
| 2882 | 2882 | { |
| 2883 | 2883 | |
| 2884 | - public $display_status_banner_single; |
|
| 2884 | + public $display_status_banner_single; |
|
| 2885 | 2885 | |
| 2886 | - public $display_venue; |
|
| 2886 | + public $display_venue; |
|
| 2887 | 2887 | |
| 2888 | - public $use_sortable_display_order; |
|
| 2888 | + public $use_sortable_display_order; |
|
| 2889 | 2889 | |
| 2890 | - public $display_order_tickets; |
|
| 2890 | + public $display_order_tickets; |
|
| 2891 | 2891 | |
| 2892 | - public $display_order_datetimes; |
|
| 2892 | + public $display_order_datetimes; |
|
| 2893 | 2893 | |
| 2894 | - public $display_order_event; |
|
| 2894 | + public $display_order_event; |
|
| 2895 | 2895 | |
| 2896 | - public $display_order_venue; |
|
| 2896 | + public $display_order_venue; |
|
| 2897 | 2897 | |
| 2898 | 2898 | |
| 2899 | 2899 | |
| 2900 | - /** |
|
| 2901 | - * class constructor |
|
| 2902 | - */ |
|
| 2903 | - public function __construct() |
|
| 2904 | - { |
|
| 2905 | - $this->display_status_banner_single = 0; |
|
| 2906 | - $this->display_venue = 1; |
|
| 2907 | - $this->use_sortable_display_order = false; |
|
| 2908 | - $this->display_order_tickets = 100; |
|
| 2909 | - $this->display_order_datetimes = 110; |
|
| 2910 | - $this->display_order_event = 120; |
|
| 2911 | - $this->display_order_venue = 130; |
|
| 2912 | - } |
|
| 2900 | + /** |
|
| 2901 | + * class constructor |
|
| 2902 | + */ |
|
| 2903 | + public function __construct() |
|
| 2904 | + { |
|
| 2905 | + $this->display_status_banner_single = 0; |
|
| 2906 | + $this->display_venue = 1; |
|
| 2907 | + $this->use_sortable_display_order = false; |
|
| 2908 | + $this->display_order_tickets = 100; |
|
| 2909 | + $this->display_order_datetimes = 110; |
|
| 2910 | + $this->display_order_event = 120; |
|
| 2911 | + $this->display_order_venue = 130; |
|
| 2912 | + } |
|
| 2913 | 2913 | } |
| 2914 | 2914 | |
| 2915 | 2915 | |
@@ -2920,152 +2920,152 @@ discard block |
||
| 2920 | 2920 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 2921 | 2921 | { |
| 2922 | 2922 | |
| 2923 | - /** |
|
| 2924 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2925 | - */ |
|
| 2926 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2927 | - |
|
| 2928 | - /** |
|
| 2929 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2930 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2931 | - */ |
|
| 2932 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2933 | - |
|
| 2934 | - /** |
|
| 2935 | - * @var boolean $show_ticket_sale_columns |
|
| 2936 | - */ |
|
| 2937 | - public $show_ticket_sale_columns; |
|
| 2938 | - |
|
| 2939 | - /** |
|
| 2940 | - * @var boolean $show_ticket_details |
|
| 2941 | - */ |
|
| 2942 | - public $show_ticket_details; |
|
| 2943 | - |
|
| 2944 | - /** |
|
| 2945 | - * @var boolean $show_expired_tickets |
|
| 2946 | - */ |
|
| 2947 | - public $show_expired_tickets; |
|
| 2948 | - |
|
| 2949 | - /** |
|
| 2950 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 2951 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 2952 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2953 | - * |
|
| 2954 | - * @var string $show_datetime_selector |
|
| 2955 | - */ |
|
| 2956 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2957 | - |
|
| 2958 | - /** |
|
| 2959 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2960 | - * |
|
| 2961 | - * @var int $datetime_selector_threshold |
|
| 2962 | - */ |
|
| 2963 | - private $datetime_selector_threshold = 3; |
|
| 2964 | - |
|
| 2965 | - |
|
| 2966 | - |
|
| 2967 | - /** |
|
| 2968 | - * class constructor |
|
| 2969 | - */ |
|
| 2970 | - public function __construct() |
|
| 2971 | - { |
|
| 2972 | - $this->show_ticket_sale_columns = true; |
|
| 2973 | - $this->show_ticket_details = true; |
|
| 2974 | - $this->show_expired_tickets = true; |
|
| 2975 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 2976 | - $this->datetime_selector_threshold = 3; |
|
| 2977 | - } |
|
| 2978 | - |
|
| 2979 | - |
|
| 2980 | - |
|
| 2981 | - /** |
|
| 2982 | - * returns true if a datetime selector should be displayed |
|
| 2983 | - * |
|
| 2984 | - * @param array $datetimes |
|
| 2985 | - * @return bool |
|
| 2986 | - */ |
|
| 2987 | - public function showDatetimeSelector(array $datetimes) |
|
| 2988 | - { |
|
| 2989 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 2990 | - return ! ( |
|
| 2991 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 2992 | - || ( |
|
| 2993 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 2994 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 2995 | - ) |
|
| 2996 | - ); |
|
| 2997 | - } |
|
| 2998 | - |
|
| 2999 | - |
|
| 3000 | - |
|
| 3001 | - /** |
|
| 3002 | - * @return string |
|
| 3003 | - */ |
|
| 3004 | - public function getShowDatetimeSelector() |
|
| 3005 | - { |
|
| 3006 | - return $this->show_datetime_selector; |
|
| 3007 | - } |
|
| 3008 | - |
|
| 3009 | - |
|
| 3010 | - |
|
| 3011 | - /** |
|
| 3012 | - * @param bool $keys_only |
|
| 3013 | - * @return array |
|
| 3014 | - */ |
|
| 3015 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3016 | - { |
|
| 3017 | - return $keys_only |
|
| 3018 | - ? array( |
|
| 3019 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3020 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3021 | - ) |
|
| 3022 | - : array( |
|
| 3023 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3024 | - 'Do not show date & time filter', 'event_espresso' |
|
| 3025 | - ), |
|
| 3026 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3027 | - 'Maybe show date & time filter', 'event_espresso' |
|
| 3028 | - ), |
|
| 3029 | - ); |
|
| 3030 | - } |
|
| 3031 | - |
|
| 3032 | - |
|
| 3033 | - |
|
| 3034 | - /** |
|
| 3035 | - * @param string $show_datetime_selector |
|
| 3036 | - */ |
|
| 3037 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3038 | - { |
|
| 3039 | - $this->show_datetime_selector = in_array( |
|
| 3040 | - $show_datetime_selector, |
|
| 3041 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3042 | - true |
|
| 3043 | - ) |
|
| 3044 | - ? $show_datetime_selector |
|
| 3045 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3046 | - } |
|
| 3047 | - |
|
| 3048 | - |
|
| 3049 | - |
|
| 3050 | - /** |
|
| 3051 | - * @return int |
|
| 3052 | - */ |
|
| 3053 | - public function getDatetimeSelectorThreshold() |
|
| 3054 | - { |
|
| 3055 | - return $this->datetime_selector_threshold; |
|
| 3056 | - } |
|
| 3057 | - |
|
| 3058 | - |
|
| 3059 | - |
|
| 3060 | - |
|
| 3061 | - /** |
|
| 3062 | - * @param int $datetime_selector_threshold |
|
| 3063 | - */ |
|
| 3064 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3065 | - { |
|
| 3066 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3067 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3068 | - } |
|
| 2923 | + /** |
|
| 2924 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2925 | + */ |
|
| 2926 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2927 | + |
|
| 2928 | + /** |
|
| 2929 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2930 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2931 | + */ |
|
| 2932 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2933 | + |
|
| 2934 | + /** |
|
| 2935 | + * @var boolean $show_ticket_sale_columns |
|
| 2936 | + */ |
|
| 2937 | + public $show_ticket_sale_columns; |
|
| 2938 | + |
|
| 2939 | + /** |
|
| 2940 | + * @var boolean $show_ticket_details |
|
| 2941 | + */ |
|
| 2942 | + public $show_ticket_details; |
|
| 2943 | + |
|
| 2944 | + /** |
|
| 2945 | + * @var boolean $show_expired_tickets |
|
| 2946 | + */ |
|
| 2947 | + public $show_expired_tickets; |
|
| 2948 | + |
|
| 2949 | + /** |
|
| 2950 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 2951 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 2952 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2953 | + * |
|
| 2954 | + * @var string $show_datetime_selector |
|
| 2955 | + */ |
|
| 2956 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2957 | + |
|
| 2958 | + /** |
|
| 2959 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2960 | + * |
|
| 2961 | + * @var int $datetime_selector_threshold |
|
| 2962 | + */ |
|
| 2963 | + private $datetime_selector_threshold = 3; |
|
| 2964 | + |
|
| 2965 | + |
|
| 2966 | + |
|
| 2967 | + /** |
|
| 2968 | + * class constructor |
|
| 2969 | + */ |
|
| 2970 | + public function __construct() |
|
| 2971 | + { |
|
| 2972 | + $this->show_ticket_sale_columns = true; |
|
| 2973 | + $this->show_ticket_details = true; |
|
| 2974 | + $this->show_expired_tickets = true; |
|
| 2975 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 2976 | + $this->datetime_selector_threshold = 3; |
|
| 2977 | + } |
|
| 2978 | + |
|
| 2979 | + |
|
| 2980 | + |
|
| 2981 | + /** |
|
| 2982 | + * returns true if a datetime selector should be displayed |
|
| 2983 | + * |
|
| 2984 | + * @param array $datetimes |
|
| 2985 | + * @return bool |
|
| 2986 | + */ |
|
| 2987 | + public function showDatetimeSelector(array $datetimes) |
|
| 2988 | + { |
|
| 2989 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 2990 | + return ! ( |
|
| 2991 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 2992 | + || ( |
|
| 2993 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 2994 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 2995 | + ) |
|
| 2996 | + ); |
|
| 2997 | + } |
|
| 2998 | + |
|
| 2999 | + |
|
| 3000 | + |
|
| 3001 | + /** |
|
| 3002 | + * @return string |
|
| 3003 | + */ |
|
| 3004 | + public function getShowDatetimeSelector() |
|
| 3005 | + { |
|
| 3006 | + return $this->show_datetime_selector; |
|
| 3007 | + } |
|
| 3008 | + |
|
| 3009 | + |
|
| 3010 | + |
|
| 3011 | + /** |
|
| 3012 | + * @param bool $keys_only |
|
| 3013 | + * @return array |
|
| 3014 | + */ |
|
| 3015 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3016 | + { |
|
| 3017 | + return $keys_only |
|
| 3018 | + ? array( |
|
| 3019 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3020 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3021 | + ) |
|
| 3022 | + : array( |
|
| 3023 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3024 | + 'Do not show date & time filter', 'event_espresso' |
|
| 3025 | + ), |
|
| 3026 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3027 | + 'Maybe show date & time filter', 'event_espresso' |
|
| 3028 | + ), |
|
| 3029 | + ); |
|
| 3030 | + } |
|
| 3031 | + |
|
| 3032 | + |
|
| 3033 | + |
|
| 3034 | + /** |
|
| 3035 | + * @param string $show_datetime_selector |
|
| 3036 | + */ |
|
| 3037 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3038 | + { |
|
| 3039 | + $this->show_datetime_selector = in_array( |
|
| 3040 | + $show_datetime_selector, |
|
| 3041 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3042 | + true |
|
| 3043 | + ) |
|
| 3044 | + ? $show_datetime_selector |
|
| 3045 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3046 | + } |
|
| 3047 | + |
|
| 3048 | + |
|
| 3049 | + |
|
| 3050 | + /** |
|
| 3051 | + * @return int |
|
| 3052 | + */ |
|
| 3053 | + public function getDatetimeSelectorThreshold() |
|
| 3054 | + { |
|
| 3055 | + return $this->datetime_selector_threshold; |
|
| 3056 | + } |
|
| 3057 | + |
|
| 3058 | + |
|
| 3059 | + |
|
| 3060 | + |
|
| 3061 | + /** |
|
| 3062 | + * @param int $datetime_selector_threshold |
|
| 3063 | + */ |
|
| 3064 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3065 | + { |
|
| 3066 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3067 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3068 | + } |
|
| 3069 | 3069 | |
| 3070 | 3070 | |
| 3071 | 3071 | |
@@ -3083,85 +3083,85 @@ discard block |
||
| 3083 | 3083 | class EE_Environment_Config extends EE_Config_Base |
| 3084 | 3084 | { |
| 3085 | 3085 | |
| 3086 | - /** |
|
| 3087 | - * Hold any php environment variables that we want to track. |
|
| 3088 | - * |
|
| 3089 | - * @var stdClass; |
|
| 3090 | - */ |
|
| 3091 | - public $php; |
|
| 3092 | - |
|
| 3093 | - |
|
| 3094 | - |
|
| 3095 | - /** |
|
| 3096 | - * constructor |
|
| 3097 | - */ |
|
| 3098 | - public function __construct() |
|
| 3099 | - { |
|
| 3100 | - $this->php = new stdClass(); |
|
| 3101 | - $this->_set_php_values(); |
|
| 3102 | - } |
|
| 3103 | - |
|
| 3104 | - |
|
| 3105 | - |
|
| 3106 | - /** |
|
| 3107 | - * This sets the php environment variables. |
|
| 3108 | - * |
|
| 3109 | - * @since 4.4.0 |
|
| 3110 | - * @return void |
|
| 3111 | - */ |
|
| 3112 | - protected function _set_php_values() |
|
| 3113 | - { |
|
| 3114 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3115 | - $this->php->version = phpversion(); |
|
| 3116 | - } |
|
| 3117 | - |
|
| 3118 | - |
|
| 3119 | - |
|
| 3120 | - /** |
|
| 3121 | - * helper method for determining whether input_count is |
|
| 3122 | - * reaching the potential maximum the server can handle |
|
| 3123 | - * according to max_input_vars |
|
| 3124 | - * |
|
| 3125 | - * @param int $input_count the count of input vars. |
|
| 3126 | - * @return array { |
|
| 3127 | - * An array that represents whether available space and if no available space the error |
|
| 3128 | - * message. |
|
| 3129 | - * @type bool $has_space whether more inputs can be added. |
|
| 3130 | - * @type string $msg Any message to be displayed. |
|
| 3131 | - * } |
|
| 3132 | - */ |
|
| 3133 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3134 | - { |
|
| 3135 | - if (! empty($this->php->max_input_vars) |
|
| 3136 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3137 | - && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3138 | - ) { |
|
| 3139 | - return sprintf( |
|
| 3140 | - __( |
|
| 3141 | - 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3142 | - 'event_espresso' |
|
| 3143 | - ), |
|
| 3144 | - '<br>', |
|
| 3145 | - $input_count, |
|
| 3146 | - $this->php->max_input_vars |
|
| 3147 | - ); |
|
| 3148 | - } else { |
|
| 3149 | - return ''; |
|
| 3150 | - } |
|
| 3151 | - } |
|
| 3152 | - |
|
| 3153 | - |
|
| 3154 | - |
|
| 3155 | - /** |
|
| 3156 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3157 | - * |
|
| 3158 | - * @since 4.4.1 |
|
| 3159 | - * @return void |
|
| 3160 | - */ |
|
| 3161 | - public function recheck_values() |
|
| 3162 | - { |
|
| 3163 | - $this->_set_php_values(); |
|
| 3164 | - } |
|
| 3086 | + /** |
|
| 3087 | + * Hold any php environment variables that we want to track. |
|
| 3088 | + * |
|
| 3089 | + * @var stdClass; |
|
| 3090 | + */ |
|
| 3091 | + public $php; |
|
| 3092 | + |
|
| 3093 | + |
|
| 3094 | + |
|
| 3095 | + /** |
|
| 3096 | + * constructor |
|
| 3097 | + */ |
|
| 3098 | + public function __construct() |
|
| 3099 | + { |
|
| 3100 | + $this->php = new stdClass(); |
|
| 3101 | + $this->_set_php_values(); |
|
| 3102 | + } |
|
| 3103 | + |
|
| 3104 | + |
|
| 3105 | + |
|
| 3106 | + /** |
|
| 3107 | + * This sets the php environment variables. |
|
| 3108 | + * |
|
| 3109 | + * @since 4.4.0 |
|
| 3110 | + * @return void |
|
| 3111 | + */ |
|
| 3112 | + protected function _set_php_values() |
|
| 3113 | + { |
|
| 3114 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3115 | + $this->php->version = phpversion(); |
|
| 3116 | + } |
|
| 3117 | + |
|
| 3118 | + |
|
| 3119 | + |
|
| 3120 | + /** |
|
| 3121 | + * helper method for determining whether input_count is |
|
| 3122 | + * reaching the potential maximum the server can handle |
|
| 3123 | + * according to max_input_vars |
|
| 3124 | + * |
|
| 3125 | + * @param int $input_count the count of input vars. |
|
| 3126 | + * @return array { |
|
| 3127 | + * An array that represents whether available space and if no available space the error |
|
| 3128 | + * message. |
|
| 3129 | + * @type bool $has_space whether more inputs can be added. |
|
| 3130 | + * @type string $msg Any message to be displayed. |
|
| 3131 | + * } |
|
| 3132 | + */ |
|
| 3133 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3134 | + { |
|
| 3135 | + if (! empty($this->php->max_input_vars) |
|
| 3136 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3137 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3138 | + ) { |
|
| 3139 | + return sprintf( |
|
| 3140 | + __( |
|
| 3141 | + 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3142 | + 'event_espresso' |
|
| 3143 | + ), |
|
| 3144 | + '<br>', |
|
| 3145 | + $input_count, |
|
| 3146 | + $this->php->max_input_vars |
|
| 3147 | + ); |
|
| 3148 | + } else { |
|
| 3149 | + return ''; |
|
| 3150 | + } |
|
| 3151 | + } |
|
| 3152 | + |
|
| 3153 | + |
|
| 3154 | + |
|
| 3155 | + /** |
|
| 3156 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3157 | + * |
|
| 3158 | + * @since 4.4.1 |
|
| 3159 | + * @return void |
|
| 3160 | + */ |
|
| 3161 | + public function recheck_values() |
|
| 3162 | + { |
|
| 3163 | + $this->_set_php_values(); |
|
| 3164 | + } |
|
| 3165 | 3165 | |
| 3166 | 3166 | |
| 3167 | 3167 | |
@@ -3179,22 +3179,22 @@ discard block |
||
| 3179 | 3179 | class EE_Tax_Config extends EE_Config_Base |
| 3180 | 3180 | { |
| 3181 | 3181 | |
| 3182 | - /* |
|
| 3182 | + /* |
|
| 3183 | 3183 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3184 | 3184 | * |
| 3185 | 3185 | * @var boolean $prices_displayed_including_taxes |
| 3186 | 3186 | */ |
| 3187 | - public $prices_displayed_including_taxes; |
|
| 3187 | + public $prices_displayed_including_taxes; |
|
| 3188 | 3188 | |
| 3189 | 3189 | |
| 3190 | 3190 | |
| 3191 | - /** |
|
| 3192 | - * class constructor |
|
| 3193 | - */ |
|
| 3194 | - public function __construct() |
|
| 3195 | - { |
|
| 3196 | - $this->prices_displayed_including_taxes = true; |
|
| 3197 | - } |
|
| 3191 | + /** |
|
| 3192 | + * class constructor |
|
| 3193 | + */ |
|
| 3194 | + public function __construct() |
|
| 3195 | + { |
|
| 3196 | + $this->prices_displayed_including_taxes = true; |
|
| 3197 | + } |
|
| 3198 | 3198 | } |
| 3199 | 3199 | |
| 3200 | 3200 | |
@@ -3209,17 +3209,17 @@ discard block |
||
| 3209 | 3209 | class EE_Messages_Config extends EE_Config_Base |
| 3210 | 3210 | { |
| 3211 | 3211 | |
| 3212 | - /** |
|
| 3213 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3214 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3215 | - * |
|
| 3216 | - * @var integer |
|
| 3217 | - */ |
|
| 3218 | - public $delete_threshold; |
|
| 3219 | - |
|
| 3220 | - public function __construct() { |
|
| 3221 | - $this->delete_threshold = 0; |
|
| 3222 | - } |
|
| 3212 | + /** |
|
| 3213 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3214 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3215 | + * |
|
| 3216 | + * @var integer |
|
| 3217 | + */ |
|
| 3218 | + public $delete_threshold; |
|
| 3219 | + |
|
| 3220 | + public function __construct() { |
|
| 3221 | + $this->delete_threshold = 0; |
|
| 3222 | + } |
|
| 3223 | 3223 | } |
| 3224 | 3224 | |
| 3225 | 3225 | |
@@ -3231,34 +3231,34 @@ discard block |
||
| 3231 | 3231 | class EE_Gateway_Config extends EE_Config_Base |
| 3232 | 3232 | { |
| 3233 | 3233 | |
| 3234 | - /** |
|
| 3235 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3236 | - * with any config info the gateway wants to store |
|
| 3237 | - * |
|
| 3238 | - * @var array |
|
| 3239 | - */ |
|
| 3240 | - public $payment_settings; |
|
| 3241 | - |
|
| 3242 | - /** |
|
| 3243 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3244 | - * the gateway is stored in the uploads directory |
|
| 3245 | - * |
|
| 3246 | - * @var array |
|
| 3247 | - */ |
|
| 3248 | - public $active_gateways; |
|
| 3249 | - |
|
| 3250 | - |
|
| 3251 | - |
|
| 3252 | - /** |
|
| 3253 | - * class constructor |
|
| 3254 | - * |
|
| 3255 | - * @deprecated |
|
| 3256 | - */ |
|
| 3257 | - public function __construct() |
|
| 3258 | - { |
|
| 3259 | - $this->payment_settings = array(); |
|
| 3260 | - $this->active_gateways = array('Invoice' => false); |
|
| 3261 | - } |
|
| 3234 | + /** |
|
| 3235 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3236 | + * with any config info the gateway wants to store |
|
| 3237 | + * |
|
| 3238 | + * @var array |
|
| 3239 | + */ |
|
| 3240 | + public $payment_settings; |
|
| 3241 | + |
|
| 3242 | + /** |
|
| 3243 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3244 | + * the gateway is stored in the uploads directory |
|
| 3245 | + * |
|
| 3246 | + * @var array |
|
| 3247 | + */ |
|
| 3248 | + public $active_gateways; |
|
| 3249 | + |
|
| 3250 | + |
|
| 3251 | + |
|
| 3252 | + /** |
|
| 3253 | + * class constructor |
|
| 3254 | + * |
|
| 3255 | + * @deprecated |
|
| 3256 | + */ |
|
| 3257 | + public function __construct() |
|
| 3258 | + { |
|
| 3259 | + $this->payment_settings = array(); |
|
| 3260 | + $this->active_gateways = array('Invoice' => false); |
|
| 3261 | + } |
|
| 3262 | 3262 | } |
| 3263 | 3263 | |
| 3264 | 3264 | // End of file EE_Config.core.php |
@@ -23,996 +23,996 @@ |
||
| 23 | 23 | class EED_Ticket_Sales_Monitor extends EED_Module |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - const debug = false; // true false |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * an array of raw ticket data from EED_Ticket_Selector |
|
| 30 | - * |
|
| 31 | - * @var array $ticket_selections |
|
| 32 | - */ |
|
| 33 | - protected $ticket_selections = array(); |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
| 37 | - * according to how they are displayed in the actual Ticket_Selector |
|
| 38 | - * this tracks the current row being processed |
|
| 39 | - * |
|
| 40 | - * @var int $current_row |
|
| 41 | - */ |
|
| 42 | - protected $current_row = 0; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * an array for tracking names of tickets that have sold out |
|
| 46 | - * |
|
| 47 | - * @var array $sold_out_tickets |
|
| 48 | - */ |
|
| 49 | - protected $sold_out_tickets = array(); |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * an array for tracking names of tickets that have had their quantities reduced |
|
| 53 | - * |
|
| 54 | - * @var array $decremented_tickets |
|
| 55 | - */ |
|
| 56 | - protected $decremented_tickets = array(); |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 62 | - * |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 65 | - public static function set_hooks() |
|
| 66 | - { |
|
| 67 | - // release tickets for expired carts |
|
| 68 | - add_action( |
|
| 69 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 70 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
| 71 | - 1 |
|
| 72 | - ); |
|
| 73 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
| 74 | - add_filter( |
|
| 75 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
| 76 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
| 77 | - 20, |
|
| 78 | - 3 |
|
| 79 | - ); |
|
| 80 | - // add notices for sold out tickets |
|
| 81 | - add_action( |
|
| 82 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 83 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
| 84 | - 10 |
|
| 85 | - ); |
|
| 86 | - // handle ticket quantities adjusted in cart |
|
| 87 | - //add_action( |
|
| 88 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
| 89 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
| 90 | - // 10, 2 |
|
| 91 | - //); |
|
| 92 | - // handle tickets deleted from cart |
|
| 93 | - add_action( |
|
| 94 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
| 95 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
| 96 | - 10, |
|
| 97 | - 2 |
|
| 98 | - ); |
|
| 99 | - // handle emptied carts |
|
| 100 | - add_action( |
|
| 101 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
| 102 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 103 | - 10, |
|
| 104 | - 1 |
|
| 105 | - ); |
|
| 106 | - add_action( |
|
| 107 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
| 108 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 109 | - 10, |
|
| 110 | - 1 |
|
| 111 | - ); |
|
| 112 | - // handle cancelled registrations |
|
| 113 | - add_action( |
|
| 114 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
| 115 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
| 116 | - 10, |
|
| 117 | - 1 |
|
| 118 | - ); |
|
| 119 | - // cron tasks |
|
| 120 | - add_action( |
|
| 121 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 122 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 123 | - 10, |
|
| 124 | - 1 |
|
| 125 | - ); |
|
| 126 | - add_action( |
|
| 127 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 128 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 129 | - 10, |
|
| 130 | - 1 |
|
| 131 | - ); |
|
| 132 | - add_action( |
|
| 133 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 134 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
| 135 | - 10, |
|
| 136 | - 1 |
|
| 137 | - ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 144 | - * |
|
| 145 | - * @return void |
|
| 146 | - */ |
|
| 147 | - public static function set_hooks_admin() |
|
| 148 | - { |
|
| 149 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
| 156 | - */ |
|
| 157 | - public static function instance() |
|
| 158 | - { |
|
| 159 | - return parent::get_instance(__CLASS__); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param WP_Query $WP_Query |
|
| 166 | - * @return void |
|
| 167 | - */ |
|
| 168 | - public function run($WP_Query) |
|
| 169 | - { |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Retrieves grand totals from the line items that have no TXN ID |
|
| 180 | - * and timestamps less than the current time minus the session lifespan. |
|
| 181 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
| 182 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
| 183 | - * |
|
| 184 | - * @return void |
|
| 185 | - * @throws DomainException |
|
| 186 | - * @throws EE_Error |
|
| 187 | - * @throws InvalidArgumentException |
|
| 188 | - * @throws InvalidDataTypeException |
|
| 189 | - * @throws InvalidInterfaceException |
|
| 190 | - * @throws UnexpectedEntityException |
|
| 191 | - */ |
|
| 192 | - public static function release_tickets_for_expired_carts() |
|
| 193 | - { |
|
| 194 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
| 195 | - $expired_ticket_IDs = array(); |
|
| 196 | - $valid_ticket_line_items = array(); |
|
| 197 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
| 198 | - if (empty($total_line_items)) { |
|
| 199 | - do_action( |
|
| 200 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 201 | - $total_line_items, |
|
| 202 | - $valid_ticket_line_items, |
|
| 203 | - $expired_ticket_IDs |
|
| 204 | - ); |
|
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
| 208 | - foreach ($total_line_items as $total_line_item) { |
|
| 209 | - /** @var EE_Line_Item $total_line_item */ |
|
| 210 | - $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
| 211 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 212 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
| 213 | - continue; |
|
| 214 | - } |
|
| 215 | - if ($total_line_item->timestamp(true) <= $expired) { |
|
| 216 | - $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
| 217 | - } else { |
|
| 218 | - $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - if (! empty($expired_ticket_IDs)) { |
|
| 223 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 224 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
| 225 | - $valid_ticket_line_items |
|
| 226 | - ); |
|
| 227 | - // let's get rid of expired line items so that they can't interfere with tracking |
|
| 228 | - add_action( |
|
| 229 | - 'shutdown', |
|
| 230 | - array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
| 231 | - 999 |
|
| 232 | - ); |
|
| 233 | - } |
|
| 234 | - do_action( |
|
| 235 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 236 | - $total_line_items, |
|
| 237 | - $valid_ticket_line_items, |
|
| 238 | - $expired_ticket_IDs |
|
| 239 | - ); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
| 250 | - * |
|
| 251 | - * @param int $qty |
|
| 252 | - * @param EE_Ticket $ticket |
|
| 253 | - * @return bool |
|
| 254 | - * @throws UnexpectedEntityException |
|
| 255 | - * @throws EE_Error |
|
| 256 | - */ |
|
| 257 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
| 258 | - { |
|
| 259 | - $qty = absint($qty); |
|
| 260 | - if ($qty > 0) { |
|
| 261 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
| 262 | - } |
|
| 263 | - if (self::debug) { |
|
| 264 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 265 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 266 | - } |
|
| 267 | - return $qty; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
| 274 | - * |
|
| 275 | - * @param EE_Ticket $ticket |
|
| 276 | - * @param int $qty |
|
| 277 | - * @return int |
|
| 278 | - * @throws UnexpectedEntityException |
|
| 279 | - * @throws EE_Error |
|
| 280 | - */ |
|
| 281 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
| 282 | - { |
|
| 283 | - if (self::debug) { |
|
| 284 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 285 | - } |
|
| 286 | - if (! $ticket instanceof EE_Ticket) { |
|
| 287 | - return 0; |
|
| 288 | - } |
|
| 289 | - if (self::debug) { |
|
| 290 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 291 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
| 292 | - } |
|
| 293 | - $ticket->refresh_from_db(); |
|
| 294 | - // first let's determine the ticket availability based on sales |
|
| 295 | - $available = $ticket->qty('saleable'); |
|
| 296 | - if (self::debug) { |
|
| 297 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
| 298 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
| 299 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 300 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 301 | - echo '<br /> . . . available: ' . $available; |
|
| 302 | - } |
|
| 303 | - if ($available < 1) { |
|
| 304 | - $this->_ticket_sold_out($ticket); |
|
| 305 | - return 0; |
|
| 306 | - } |
|
| 307 | - if (self::debug) { |
|
| 308 | - echo '<br /> . . . qty: ' . $qty; |
|
| 309 | - } |
|
| 310 | - if ($available < $qty) { |
|
| 311 | - $qty = $available; |
|
| 312 | - if (self::debug) { |
|
| 313 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
| 314 | - } |
|
| 315 | - $this->_ticket_quantity_decremented($ticket); |
|
| 316 | - } |
|
| 317 | - $this->_reserve_ticket($ticket, $qty); |
|
| 318 | - return $qty; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * increments ticket reserved based on quantity passed |
|
| 325 | - * |
|
| 326 | - * @param EE_Ticket $ticket |
|
| 327 | - * @param int $quantity |
|
| 328 | - * @return bool |
|
| 329 | - * @throws EE_Error |
|
| 330 | - */ |
|
| 331 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 332 | - { |
|
| 333 | - if (self::debug) { |
|
| 334 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
| 335 | - } |
|
| 336 | - $ticket->increase_reserved($quantity); |
|
| 337 | - return $ticket->save(); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * @param EE_Ticket $ticket |
|
| 344 | - * @param int $quantity |
|
| 345 | - * @return bool |
|
| 346 | - * @throws EE_Error |
|
| 347 | - */ |
|
| 348 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 349 | - { |
|
| 350 | - if (self::debug) { |
|
| 351 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
| 352 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 353 | - } |
|
| 354 | - $ticket->decrease_reserved($quantity); |
|
| 355 | - if (self::debug) { |
|
| 356 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 357 | - } |
|
| 358 | - return $ticket->save() ? 1 : 0; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * removes quantities within the ticket selector based on zero ticket availability |
|
| 365 | - * |
|
| 366 | - * @param EE_Ticket $ticket |
|
| 367 | - * @return void |
|
| 368 | - * @throws UnexpectedEntityException |
|
| 369 | - * @throws EE_Error |
|
| 370 | - */ |
|
| 371 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
| 372 | - { |
|
| 373 | - if (self::debug) { |
|
| 374 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 375 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 376 | - } |
|
| 377 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
| 384 | - * |
|
| 385 | - * @param EE_Ticket $ticket |
|
| 386 | - * @return void |
|
| 387 | - * @throws UnexpectedEntityException |
|
| 388 | - * @throws EE_Error |
|
| 389 | - */ |
|
| 390 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
| 391 | - { |
|
| 392 | - if (self::debug) { |
|
| 393 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 394 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 395 | - } |
|
| 396 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * builds string out of ticket and event name |
|
| 403 | - * |
|
| 404 | - * @param EE_Ticket $ticket |
|
| 405 | - * @return string |
|
| 406 | - * @throws UnexpectedEntityException |
|
| 407 | - * @throws EE_Error |
|
| 408 | - */ |
|
| 409 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
| 410 | - { |
|
| 411 | - $event = $ticket->get_related_event(); |
|
| 412 | - if ($event instanceof EE_Event) { |
|
| 413 | - $ticket_name = sprintf( |
|
| 414 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
| 415 | - $ticket->name(), |
|
| 416 | - $event->name() |
|
| 417 | - ); |
|
| 418 | - } else { |
|
| 419 | - $ticket_name = $ticket->name(); |
|
| 420 | - } |
|
| 421 | - return $ticket_name; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /********************************** EVENT CART **********************************/ |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * releases or reserves ticket(s) based on quantity passed |
|
| 432 | - * |
|
| 433 | - * @param EE_Line_Item $line_item |
|
| 434 | - * @param int $quantity |
|
| 435 | - * @return void |
|
| 436 | - * @throws EE_Error |
|
| 437 | - * @throws InvalidArgumentException |
|
| 438 | - * @throws InvalidDataTypeException |
|
| 439 | - * @throws InvalidInterfaceException |
|
| 440 | - */ |
|
| 441 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
| 442 | - { |
|
| 443 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
| 444 | - if ($ticket instanceof EE_Ticket) { |
|
| 445 | - if ($quantity > 0) { |
|
| 446 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
| 447 | - } else { |
|
| 448 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * releases reserved ticket(s) based on quantity passed |
|
| 457 | - * |
|
| 458 | - * @param EE_Ticket $ticket |
|
| 459 | - * @param int $quantity |
|
| 460 | - * @return void |
|
| 461 | - * @throws EE_Error |
|
| 462 | - */ |
|
| 463 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
| 464 | - { |
|
| 465 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /********************************** POST_NOTICES **********************************/ |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * @return void |
|
| 476 | - * @throws EE_Error |
|
| 477 | - * @throws InvalidArgumentException |
|
| 478 | - * @throws ReflectionException |
|
| 479 | - * @throws InvalidDataTypeException |
|
| 480 | - * @throws InvalidInterfaceException |
|
| 481 | - */ |
|
| 482 | - public static function post_notices() |
|
| 483 | - { |
|
| 484 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * @return void |
|
| 491 | - * @throws EE_Error |
|
| 492 | - * @throws InvalidArgumentException |
|
| 493 | - * @throws ReflectionException |
|
| 494 | - * @throws InvalidDataTypeException |
|
| 495 | - * @throws InvalidInterfaceException |
|
| 496 | - */ |
|
| 497 | - protected function _post_notices() |
|
| 498 | - { |
|
| 499 | - if (self::debug) { |
|
| 500 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 501 | - } |
|
| 502 | - $refresh_msg = ''; |
|
| 503 | - $none_added_msg = ''; |
|
| 504 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 505 | - $refresh_msg = __( |
|
| 506 | - 'Please refresh the page to view updated ticket quantities.', |
|
| 507 | - 'event_espresso' |
|
| 508 | - ); |
|
| 509 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
| 510 | - } |
|
| 511 | - if (! empty($this->sold_out_tickets)) { |
|
| 512 | - EE_Error::add_attention( |
|
| 513 | - sprintf( |
|
| 514 | - apply_filters( |
|
| 515 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
| 516 | - __( |
|
| 517 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 518 | - 'event_espresso' |
|
| 519 | - ) |
|
| 520 | - ), |
|
| 521 | - '<br />', |
|
| 522 | - implode('<br />', $this->sold_out_tickets), |
|
| 523 | - $none_added_msg, |
|
| 524 | - $refresh_msg |
|
| 525 | - ) |
|
| 526 | - ); |
|
| 527 | - // alter code flow in the Ticket Selector for better UX |
|
| 528 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
| 529 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
| 530 | - $this->sold_out_tickets = array(); |
|
| 531 | - // and reset the cart |
|
| 532 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
| 533 | - } |
|
| 534 | - if (! empty($this->decremented_tickets)) { |
|
| 535 | - EE_Error::add_attention( |
|
| 536 | - sprintf( |
|
| 537 | - apply_filters( |
|
| 538 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
| 539 | - __( |
|
| 540 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 541 | - 'event_espresso' |
|
| 542 | - ) |
|
| 543 | - ), |
|
| 544 | - '<br />', |
|
| 545 | - implode('<br />', $this->decremented_tickets), |
|
| 546 | - $none_added_msg, |
|
| 547 | - $refresh_msg |
|
| 548 | - ) |
|
| 549 | - ); |
|
| 550 | - $this->decremented_tickets = array(); |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
| 562 | - * by default, will NOT release tickets for finalized transactions |
|
| 563 | - * |
|
| 564 | - * @param EE_Transaction $transaction |
|
| 565 | - * @return int |
|
| 566 | - * @throws EE_Error |
|
| 567 | - * @throws InvalidSessionDataException |
|
| 568 | - */ |
|
| 569 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
| 570 | - { |
|
| 571 | - if (self::debug) { |
|
| 572 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 573 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
| 574 | - } |
|
| 575 | - // check if 'finalize_registration' step has been completed... |
|
| 576 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 577 | - if (self::debug) { |
|
| 578 | - // DEBUG LOG |
|
| 579 | - EEH_Debug_Tools::log( |
|
| 580 | - __CLASS__, |
|
| 581 | - __FUNCTION__, |
|
| 582 | - __LINE__, |
|
| 583 | - array('finalized' => $finalized), |
|
| 584 | - false, |
|
| 585 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 586 | - ); |
|
| 587 | - } |
|
| 588 | - // how many tickets were released |
|
| 589 | - $count = 0; |
|
| 590 | - if (self::debug) { |
|
| 591 | - echo '<br /> . . . finalized: ' . $finalized; |
|
| 592 | - } |
|
| 593 | - $release_tickets_with_TXN_status = array( |
|
| 594 | - EEM_Transaction::failed_status_code, |
|
| 595 | - EEM_Transaction::abandoned_status_code, |
|
| 596 | - EEM_Transaction::incomplete_status_code, |
|
| 597 | - ); |
|
| 598 | - // if the session is getting cleared BEFORE the TXN has been finalized |
|
| 599 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 600 | - // let's cancel any reserved tickets |
|
| 601 | - $registrations = $transaction->registrations(); |
|
| 602 | - if (! empty($registrations)) { |
|
| 603 | - foreach ($registrations as $registration) { |
|
| 604 | - if ($registration instanceof EE_Registration) { |
|
| 605 | - $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - return $count; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * releases reserved tickets for an EE_Registration |
|
| 617 | - * by default, will NOT release tickets for APPROVED registrations |
|
| 618 | - * |
|
| 619 | - * @param EE_Registration $registration |
|
| 620 | - * @param EE_Transaction $transaction |
|
| 621 | - * @return int |
|
| 622 | - * @throws EE_Error |
|
| 623 | - */ |
|
| 624 | - protected function _release_reserved_ticket_for_registration( |
|
| 625 | - EE_Registration $registration, |
|
| 626 | - EE_Transaction $transaction |
|
| 627 | - ) { |
|
| 628 | - $STS_ID = $transaction->status_ID(); |
|
| 629 | - if (self::debug) { |
|
| 630 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 631 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
| 632 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
| 633 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
| 634 | - } |
|
| 635 | - if ( |
|
| 636 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
| 637 | - $STS_ID === EEM_Transaction::failed_status_code |
|
| 638 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
| 639 | - || ( |
|
| 640 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
| 641 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
| 642 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 643 | - ) |
|
| 644 | - ) { |
|
| 645 | - $ticket = $registration->ticket(); |
|
| 646 | - if ($ticket instanceof EE_Ticket) { |
|
| 647 | - return $this->_release_reserved_ticket($ticket); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - return 0; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - /********************************** SESSION_CART_RESET **********************************/ |
|
| 656 | - |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
| 661 | - * |
|
| 662 | - * @param EE_Session $session |
|
| 663 | - * @return void |
|
| 664 | - * @throws EE_Error |
|
| 665 | - * @throws InvalidArgumentException |
|
| 666 | - * @throws ReflectionException |
|
| 667 | - * @throws InvalidDataTypeException |
|
| 668 | - * @throws InvalidInterfaceException |
|
| 669 | - */ |
|
| 670 | - public static function session_cart_reset(EE_Session $session) |
|
| 671 | - { |
|
| 672 | - if (self::debug) { |
|
| 673 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 674 | - } |
|
| 675 | - $cart = $session->cart(); |
|
| 676 | - if ($cart instanceof EE_Cart) { |
|
| 677 | - if (self::debug) { |
|
| 678 | - echo '<br /><br /> cart instance of EE_Cart: '; |
|
| 679 | - } |
|
| 680 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
| 681 | - } else { |
|
| 682 | - if (self::debug) { |
|
| 683 | - echo '<br /><br /> invalid EE_Cart: '; |
|
| 684 | - var_export($cart, true); |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * releases reserved tickets in the EE_Cart |
|
| 693 | - * |
|
| 694 | - * @param EE_Cart $cart |
|
| 695 | - * @return void |
|
| 696 | - * @throws EE_Error |
|
| 697 | - * @throws InvalidArgumentException |
|
| 698 | - * @throws ReflectionException |
|
| 699 | - * @throws InvalidDataTypeException |
|
| 700 | - * @throws InvalidInterfaceException |
|
| 701 | - */ |
|
| 702 | - protected function _session_cart_reset(EE_Cart $cart) |
|
| 703 | - { |
|
| 704 | - if (self::debug) { |
|
| 705 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 706 | - } |
|
| 707 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
| 708 | - $ticket_line_items = $cart->get_tickets(); |
|
| 709 | - if (empty($ticket_line_items)) { |
|
| 710 | - return; |
|
| 711 | - } |
|
| 712 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 713 | - if (self::debug) { |
|
| 714 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 715 | - } |
|
| 716 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
| 717 | - if (self::debug) { |
|
| 718 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 719 | - } |
|
| 720 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
| 721 | - if ($ticket instanceof EE_Ticket) { |
|
| 722 | - if (self::debug) { |
|
| 723 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
| 724 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 725 | - } |
|
| 726 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - } |
|
| 730 | - if (self::debug) { |
|
| 731 | - echo '<br /><br /> RESET COMPLETED '; |
|
| 732 | - } |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
| 743 | - * |
|
| 744 | - * @param EE_Session $session |
|
| 745 | - * @return void |
|
| 746 | - * @throws EE_Error |
|
| 747 | - * @throws InvalidSessionDataException |
|
| 748 | - */ |
|
| 749 | - public static function session_checkout_reset(EE_Session $session) |
|
| 750 | - { |
|
| 751 | - $checkout = $session->checkout(); |
|
| 752 | - if ($checkout instanceof EE_Checkout) { |
|
| 753 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 754 | - } |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - |
|
| 759 | - /** |
|
| 760 | - * releases reserved tickets for the EE_Checkout->transaction |
|
| 761 | - * |
|
| 762 | - * @param EE_Checkout $checkout |
|
| 763 | - * @return void |
|
| 764 | - * @throws EE_Error |
|
| 765 | - * @throws InvalidSessionDataException |
|
| 766 | - */ |
|
| 767 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
| 768 | - { |
|
| 769 | - if (self::debug) { |
|
| 770 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 771 | - } |
|
| 772 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
| 773 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
| 774 | - return; |
|
| 775 | - } |
|
| 776 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - |
|
| 780 | - |
|
| 781 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
| 782 | - |
|
| 783 | - |
|
| 784 | - |
|
| 785 | - /** |
|
| 786 | - * @param EE_Session $session |
|
| 787 | - * @return void |
|
| 788 | - */ |
|
| 789 | - public static function session_expired_reset(EE_Session $session) |
|
| 790 | - { |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - |
|
| 795 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
| 801 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
| 802 | - * |
|
| 803 | - * @param EE_Transaction $transaction |
|
| 804 | - * @return void |
|
| 805 | - * @throws EE_Error |
|
| 806 | - * @throws InvalidSessionDataException |
|
| 807 | - */ |
|
| 808 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
| 809 | - { |
|
| 810 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
| 811 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
| 812 | - if (self::debug) { |
|
| 813 | - // DEBUG LOG |
|
| 814 | - EEH_Debug_Tools::log( |
|
| 815 | - __CLASS__, |
|
| 816 | - __FUNCTION__, |
|
| 817 | - __LINE__, |
|
| 818 | - array($transaction), |
|
| 819 | - false, |
|
| 820 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 821 | - ); |
|
| 822 | - } |
|
| 823 | - return; |
|
| 824 | - } |
|
| 825 | - // have their been any successful payments made ? |
|
| 826 | - $payments = $transaction->payments(); |
|
| 827 | - foreach ($payments as $payment) { |
|
| 828 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
| 829 | - if (self::debug) { |
|
| 830 | - // DEBUG LOG |
|
| 831 | - EEH_Debug_Tools::log( |
|
| 832 | - __CLASS__, |
|
| 833 | - __FUNCTION__, |
|
| 834 | - __LINE__, |
|
| 835 | - array($payment), |
|
| 836 | - false, |
|
| 837 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 838 | - ); |
|
| 839 | - } |
|
| 840 | - return; |
|
| 841 | - } |
|
| 842 | - } |
|
| 843 | - // since you haven't even attempted to pay for your ticket... |
|
| 844 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - |
|
| 849 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
| 850 | - |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
| 855 | - * |
|
| 856 | - * @param EE_Transaction $transaction |
|
| 857 | - * @return void |
|
| 858 | - * @throws EE_Error |
|
| 859 | - * @throws InvalidSessionDataException |
|
| 860 | - */ |
|
| 861 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
| 862 | - { |
|
| 863 | - // since you haven't even attempted to pay for your ticket... |
|
| 864 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
| 870 | - |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * Resets all ticket and datetime reserved counts to zero |
|
| 875 | - * Tickets that are currently associated with a Transaction that is in progress |
|
| 876 | - * |
|
| 877 | - * @throws EE_Error |
|
| 878 | - * @throws DomainException |
|
| 879 | - * @throws InvalidDataTypeException |
|
| 880 | - * @throws InvalidInterfaceException |
|
| 881 | - * @throws InvalidArgumentException |
|
| 882 | - * @throws UnexpectedEntityException |
|
| 883 | - */ |
|
| 884 | - public static function reset_reservation_counts() |
|
| 885 | - { |
|
| 886 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 887 | - $valid_reserved_tickets = array(); |
|
| 888 | - /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
| 889 | - $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
| 890 | - foreach ($transactions_not_in_progress as $transaction) { |
|
| 891 | - // if this TXN has been fully completed, then skip it |
|
| 892 | - if ($transaction->reg_step_completed('finalize_registration')) { |
|
| 893 | - continue; |
|
| 894 | - } |
|
| 895 | - $total_line_item = $transaction->total_line_item(); |
|
| 896 | - // $transaction_in_progress->line |
|
| 897 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
| 898 | - throw new DomainException( |
|
| 899 | - esc_html__( |
|
| 900 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
| 901 | - 'event_espresso' |
|
| 902 | - ) |
|
| 903 | - ); |
|
| 904 | - } |
|
| 905 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 906 | - $total_line_item |
|
| 907 | - ); |
|
| 908 | - } |
|
| 909 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
| 910 | - foreach ($total_line_items as $total_line_item) { |
|
| 911 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 912 | - $total_line_item |
|
| 913 | - ); |
|
| 914 | - } |
|
| 915 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 916 | - EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
| 917 | - $valid_reserved_tickets |
|
| 918 | - ); |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * @param EE_Line_Item $total_line_item |
|
| 925 | - * @return EE_Line_Item[] |
|
| 926 | - */ |
|
| 927 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
| 928 | - { |
|
| 929 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 930 | - $valid_reserved_tickets = array(); |
|
| 931 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 932 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 933 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
| 934 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
| 935 | - } |
|
| 936 | - } |
|
| 937 | - return $valid_reserved_tickets; |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * @param EE_Ticket[] $tickets_with_reservations |
|
| 944 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
| 945 | - * @return int |
|
| 946 | - * @throws UnexpectedEntityException |
|
| 947 | - * @throws DomainException |
|
| 948 | - * @throws EE_Error |
|
| 949 | - */ |
|
| 950 | - private static function release_reservations_for_tickets( |
|
| 951 | - array $tickets_with_reservations, |
|
| 952 | - array $valid_reserved_ticket_line_items = array() |
|
| 953 | - ) { |
|
| 954 | - $total_tickets_released = 0; |
|
| 955 | - $sold_out_events = array(); |
|
| 956 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
| 957 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 958 | - continue; |
|
| 959 | - } |
|
| 960 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
| 961 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
| 962 | - if ( |
|
| 963 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
| 964 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
| 965 | - ) { |
|
| 966 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
| 967 | - } |
|
| 968 | - } |
|
| 969 | - if ($reserved_qty > 0) { |
|
| 970 | - $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
| 971 | - $ticket_with_reservations->save(); |
|
| 972 | - $total_tickets_released += $reserved_qty; |
|
| 973 | - $event = $ticket_with_reservations->get_related_event(); |
|
| 974 | - // track sold out events |
|
| 975 | - if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
| 976 | - $sold_out_events[] = $event; |
|
| 977 | - } |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - // double check whether sold out events should remain sold out after releasing tickets |
|
| 981 | - if($sold_out_events !== array()){ |
|
| 982 | - foreach ($sold_out_events as $sold_out_event) { |
|
| 983 | - /** @var EE_Event $sold_out_event */ |
|
| 984 | - $sold_out_event->perform_sold_out_status_check(); |
|
| 985 | - } |
|
| 986 | - } |
|
| 987 | - return $total_tickets_released; |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - |
|
| 991 | - |
|
| 992 | - /********************************** SHUTDOWN **********************************/ |
|
| 993 | - |
|
| 994 | - |
|
| 995 | - |
|
| 996 | - /** |
|
| 997 | - * @return false|int |
|
| 998 | - * @throws EE_Error |
|
| 999 | - * @throws InvalidArgumentException |
|
| 1000 | - * @throws InvalidDataTypeException |
|
| 1001 | - * @throws InvalidInterfaceException |
|
| 1002 | - */ |
|
| 1003 | - public static function clear_expired_line_items_with_no_transaction() |
|
| 1004 | - { |
|
| 1005 | - /** @type WPDB $wpdb */ |
|
| 1006 | - global $wpdb; |
|
| 1007 | - return $wpdb->query( |
|
| 1008 | - $wpdb->prepare( |
|
| 1009 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 26 | + const debug = false; // true false |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * an array of raw ticket data from EED_Ticket_Selector |
|
| 30 | + * |
|
| 31 | + * @var array $ticket_selections |
|
| 32 | + */ |
|
| 33 | + protected $ticket_selections = array(); |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
| 37 | + * according to how they are displayed in the actual Ticket_Selector |
|
| 38 | + * this tracks the current row being processed |
|
| 39 | + * |
|
| 40 | + * @var int $current_row |
|
| 41 | + */ |
|
| 42 | + protected $current_row = 0; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * an array for tracking names of tickets that have sold out |
|
| 46 | + * |
|
| 47 | + * @var array $sold_out_tickets |
|
| 48 | + */ |
|
| 49 | + protected $sold_out_tickets = array(); |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * an array for tracking names of tickets that have had their quantities reduced |
|
| 53 | + * |
|
| 54 | + * @var array $decremented_tickets |
|
| 55 | + */ |
|
| 56 | + protected $decremented_tickets = array(); |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 62 | + * |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | + public static function set_hooks() |
|
| 66 | + { |
|
| 67 | + // release tickets for expired carts |
|
| 68 | + add_action( |
|
| 69 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 70 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
| 71 | + 1 |
|
| 72 | + ); |
|
| 73 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
| 74 | + add_filter( |
|
| 75 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
| 76 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
| 77 | + 20, |
|
| 78 | + 3 |
|
| 79 | + ); |
|
| 80 | + // add notices for sold out tickets |
|
| 81 | + add_action( |
|
| 82 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 83 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
| 84 | + 10 |
|
| 85 | + ); |
|
| 86 | + // handle ticket quantities adjusted in cart |
|
| 87 | + //add_action( |
|
| 88 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
| 89 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
| 90 | + // 10, 2 |
|
| 91 | + //); |
|
| 92 | + // handle tickets deleted from cart |
|
| 93 | + add_action( |
|
| 94 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
| 95 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
| 96 | + 10, |
|
| 97 | + 2 |
|
| 98 | + ); |
|
| 99 | + // handle emptied carts |
|
| 100 | + add_action( |
|
| 101 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
| 102 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 103 | + 10, |
|
| 104 | + 1 |
|
| 105 | + ); |
|
| 106 | + add_action( |
|
| 107 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
| 108 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 109 | + 10, |
|
| 110 | + 1 |
|
| 111 | + ); |
|
| 112 | + // handle cancelled registrations |
|
| 113 | + add_action( |
|
| 114 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
| 115 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
| 116 | + 10, |
|
| 117 | + 1 |
|
| 118 | + ); |
|
| 119 | + // cron tasks |
|
| 120 | + add_action( |
|
| 121 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 122 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 123 | + 10, |
|
| 124 | + 1 |
|
| 125 | + ); |
|
| 126 | + add_action( |
|
| 127 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 128 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 129 | + 10, |
|
| 130 | + 1 |
|
| 131 | + ); |
|
| 132 | + add_action( |
|
| 133 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 134 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
| 135 | + 10, |
|
| 136 | + 1 |
|
| 137 | + ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 144 | + * |
|
| 145 | + * @return void |
|
| 146 | + */ |
|
| 147 | + public static function set_hooks_admin() |
|
| 148 | + { |
|
| 149 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
| 156 | + */ |
|
| 157 | + public static function instance() |
|
| 158 | + { |
|
| 159 | + return parent::get_instance(__CLASS__); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param WP_Query $WP_Query |
|
| 166 | + * @return void |
|
| 167 | + */ |
|
| 168 | + public function run($WP_Query) |
|
| 169 | + { |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Retrieves grand totals from the line items that have no TXN ID |
|
| 180 | + * and timestamps less than the current time minus the session lifespan. |
|
| 181 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
| 182 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
| 183 | + * |
|
| 184 | + * @return void |
|
| 185 | + * @throws DomainException |
|
| 186 | + * @throws EE_Error |
|
| 187 | + * @throws InvalidArgumentException |
|
| 188 | + * @throws InvalidDataTypeException |
|
| 189 | + * @throws InvalidInterfaceException |
|
| 190 | + * @throws UnexpectedEntityException |
|
| 191 | + */ |
|
| 192 | + public static function release_tickets_for_expired_carts() |
|
| 193 | + { |
|
| 194 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
| 195 | + $expired_ticket_IDs = array(); |
|
| 196 | + $valid_ticket_line_items = array(); |
|
| 197 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
| 198 | + if (empty($total_line_items)) { |
|
| 199 | + do_action( |
|
| 200 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 201 | + $total_line_items, |
|
| 202 | + $valid_ticket_line_items, |
|
| 203 | + $expired_ticket_IDs |
|
| 204 | + ); |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
| 208 | + foreach ($total_line_items as $total_line_item) { |
|
| 209 | + /** @var EE_Line_Item $total_line_item */ |
|
| 210 | + $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
| 211 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 212 | + if (! $ticket_line_item instanceof EE_Line_Item) { |
|
| 213 | + continue; |
|
| 214 | + } |
|
| 215 | + if ($total_line_item->timestamp(true) <= $expired) { |
|
| 216 | + $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
| 217 | + } else { |
|
| 218 | + $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + if (! empty($expired_ticket_IDs)) { |
|
| 223 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 224 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
| 225 | + $valid_ticket_line_items |
|
| 226 | + ); |
|
| 227 | + // let's get rid of expired line items so that they can't interfere with tracking |
|
| 228 | + add_action( |
|
| 229 | + 'shutdown', |
|
| 230 | + array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
| 231 | + 999 |
|
| 232 | + ); |
|
| 233 | + } |
|
| 234 | + do_action( |
|
| 235 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 236 | + $total_line_items, |
|
| 237 | + $valid_ticket_line_items, |
|
| 238 | + $expired_ticket_IDs |
|
| 239 | + ); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
| 250 | + * |
|
| 251 | + * @param int $qty |
|
| 252 | + * @param EE_Ticket $ticket |
|
| 253 | + * @return bool |
|
| 254 | + * @throws UnexpectedEntityException |
|
| 255 | + * @throws EE_Error |
|
| 256 | + */ |
|
| 257 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
| 258 | + { |
|
| 259 | + $qty = absint($qty); |
|
| 260 | + if ($qty > 0) { |
|
| 261 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
| 262 | + } |
|
| 263 | + if (self::debug) { |
|
| 264 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 265 | + echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 266 | + } |
|
| 267 | + return $qty; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
| 274 | + * |
|
| 275 | + * @param EE_Ticket $ticket |
|
| 276 | + * @param int $qty |
|
| 277 | + * @return int |
|
| 278 | + * @throws UnexpectedEntityException |
|
| 279 | + * @throws EE_Error |
|
| 280 | + */ |
|
| 281 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
| 282 | + { |
|
| 283 | + if (self::debug) { |
|
| 284 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 285 | + } |
|
| 286 | + if (! $ticket instanceof EE_Ticket) { |
|
| 287 | + return 0; |
|
| 288 | + } |
|
| 289 | + if (self::debug) { |
|
| 290 | + echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 291 | + echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
| 292 | + } |
|
| 293 | + $ticket->refresh_from_db(); |
|
| 294 | + // first let's determine the ticket availability based on sales |
|
| 295 | + $available = $ticket->qty('saleable'); |
|
| 296 | + if (self::debug) { |
|
| 297 | + echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
| 298 | + echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
| 299 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 300 | + echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 301 | + echo '<br /> . . . available: ' . $available; |
|
| 302 | + } |
|
| 303 | + if ($available < 1) { |
|
| 304 | + $this->_ticket_sold_out($ticket); |
|
| 305 | + return 0; |
|
| 306 | + } |
|
| 307 | + if (self::debug) { |
|
| 308 | + echo '<br /> . . . qty: ' . $qty; |
|
| 309 | + } |
|
| 310 | + if ($available < $qty) { |
|
| 311 | + $qty = $available; |
|
| 312 | + if (self::debug) { |
|
| 313 | + echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
| 314 | + } |
|
| 315 | + $this->_ticket_quantity_decremented($ticket); |
|
| 316 | + } |
|
| 317 | + $this->_reserve_ticket($ticket, $qty); |
|
| 318 | + return $qty; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * increments ticket reserved based on quantity passed |
|
| 325 | + * |
|
| 326 | + * @param EE_Ticket $ticket |
|
| 327 | + * @param int $quantity |
|
| 328 | + * @return bool |
|
| 329 | + * @throws EE_Error |
|
| 330 | + */ |
|
| 331 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 332 | + { |
|
| 333 | + if (self::debug) { |
|
| 334 | + echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
| 335 | + } |
|
| 336 | + $ticket->increase_reserved($quantity); |
|
| 337 | + return $ticket->save(); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * @param EE_Ticket $ticket |
|
| 344 | + * @param int $quantity |
|
| 345 | + * @return bool |
|
| 346 | + * @throws EE_Error |
|
| 347 | + */ |
|
| 348 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 349 | + { |
|
| 350 | + if (self::debug) { |
|
| 351 | + echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
| 352 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 353 | + } |
|
| 354 | + $ticket->decrease_reserved($quantity); |
|
| 355 | + if (self::debug) { |
|
| 356 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 357 | + } |
|
| 358 | + return $ticket->save() ? 1 : 0; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * removes quantities within the ticket selector based on zero ticket availability |
|
| 365 | + * |
|
| 366 | + * @param EE_Ticket $ticket |
|
| 367 | + * @return void |
|
| 368 | + * @throws UnexpectedEntityException |
|
| 369 | + * @throws EE_Error |
|
| 370 | + */ |
|
| 371 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
| 372 | + { |
|
| 373 | + if (self::debug) { |
|
| 374 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 375 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 376 | + } |
|
| 377 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
| 384 | + * |
|
| 385 | + * @param EE_Ticket $ticket |
|
| 386 | + * @return void |
|
| 387 | + * @throws UnexpectedEntityException |
|
| 388 | + * @throws EE_Error |
|
| 389 | + */ |
|
| 390 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
| 391 | + { |
|
| 392 | + if (self::debug) { |
|
| 393 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 394 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 395 | + } |
|
| 396 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * builds string out of ticket and event name |
|
| 403 | + * |
|
| 404 | + * @param EE_Ticket $ticket |
|
| 405 | + * @return string |
|
| 406 | + * @throws UnexpectedEntityException |
|
| 407 | + * @throws EE_Error |
|
| 408 | + */ |
|
| 409 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
| 410 | + { |
|
| 411 | + $event = $ticket->get_related_event(); |
|
| 412 | + if ($event instanceof EE_Event) { |
|
| 413 | + $ticket_name = sprintf( |
|
| 414 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
| 415 | + $ticket->name(), |
|
| 416 | + $event->name() |
|
| 417 | + ); |
|
| 418 | + } else { |
|
| 419 | + $ticket_name = $ticket->name(); |
|
| 420 | + } |
|
| 421 | + return $ticket_name; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /********************************** EVENT CART **********************************/ |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * releases or reserves ticket(s) based on quantity passed |
|
| 432 | + * |
|
| 433 | + * @param EE_Line_Item $line_item |
|
| 434 | + * @param int $quantity |
|
| 435 | + * @return void |
|
| 436 | + * @throws EE_Error |
|
| 437 | + * @throws InvalidArgumentException |
|
| 438 | + * @throws InvalidDataTypeException |
|
| 439 | + * @throws InvalidInterfaceException |
|
| 440 | + */ |
|
| 441 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
| 442 | + { |
|
| 443 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
| 444 | + if ($ticket instanceof EE_Ticket) { |
|
| 445 | + if ($quantity > 0) { |
|
| 446 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
| 447 | + } else { |
|
| 448 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * releases reserved ticket(s) based on quantity passed |
|
| 457 | + * |
|
| 458 | + * @param EE_Ticket $ticket |
|
| 459 | + * @param int $quantity |
|
| 460 | + * @return void |
|
| 461 | + * @throws EE_Error |
|
| 462 | + */ |
|
| 463 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
| 464 | + { |
|
| 465 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /********************************** POST_NOTICES **********************************/ |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * @return void |
|
| 476 | + * @throws EE_Error |
|
| 477 | + * @throws InvalidArgumentException |
|
| 478 | + * @throws ReflectionException |
|
| 479 | + * @throws InvalidDataTypeException |
|
| 480 | + * @throws InvalidInterfaceException |
|
| 481 | + */ |
|
| 482 | + public static function post_notices() |
|
| 483 | + { |
|
| 484 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * @return void |
|
| 491 | + * @throws EE_Error |
|
| 492 | + * @throws InvalidArgumentException |
|
| 493 | + * @throws ReflectionException |
|
| 494 | + * @throws InvalidDataTypeException |
|
| 495 | + * @throws InvalidInterfaceException |
|
| 496 | + */ |
|
| 497 | + protected function _post_notices() |
|
| 498 | + { |
|
| 499 | + if (self::debug) { |
|
| 500 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 501 | + } |
|
| 502 | + $refresh_msg = ''; |
|
| 503 | + $none_added_msg = ''; |
|
| 504 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 505 | + $refresh_msg = __( |
|
| 506 | + 'Please refresh the page to view updated ticket quantities.', |
|
| 507 | + 'event_espresso' |
|
| 508 | + ); |
|
| 509 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
| 510 | + } |
|
| 511 | + if (! empty($this->sold_out_tickets)) { |
|
| 512 | + EE_Error::add_attention( |
|
| 513 | + sprintf( |
|
| 514 | + apply_filters( |
|
| 515 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
| 516 | + __( |
|
| 517 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 518 | + 'event_espresso' |
|
| 519 | + ) |
|
| 520 | + ), |
|
| 521 | + '<br />', |
|
| 522 | + implode('<br />', $this->sold_out_tickets), |
|
| 523 | + $none_added_msg, |
|
| 524 | + $refresh_msg |
|
| 525 | + ) |
|
| 526 | + ); |
|
| 527 | + // alter code flow in the Ticket Selector for better UX |
|
| 528 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
| 529 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
| 530 | + $this->sold_out_tickets = array(); |
|
| 531 | + // and reset the cart |
|
| 532 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
| 533 | + } |
|
| 534 | + if (! empty($this->decremented_tickets)) { |
|
| 535 | + EE_Error::add_attention( |
|
| 536 | + sprintf( |
|
| 537 | + apply_filters( |
|
| 538 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
| 539 | + __( |
|
| 540 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 541 | + 'event_espresso' |
|
| 542 | + ) |
|
| 543 | + ), |
|
| 544 | + '<br />', |
|
| 545 | + implode('<br />', $this->decremented_tickets), |
|
| 546 | + $none_added_msg, |
|
| 547 | + $refresh_msg |
|
| 548 | + ) |
|
| 549 | + ); |
|
| 550 | + $this->decremented_tickets = array(); |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
| 562 | + * by default, will NOT release tickets for finalized transactions |
|
| 563 | + * |
|
| 564 | + * @param EE_Transaction $transaction |
|
| 565 | + * @return int |
|
| 566 | + * @throws EE_Error |
|
| 567 | + * @throws InvalidSessionDataException |
|
| 568 | + */ |
|
| 569 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
| 570 | + { |
|
| 571 | + if (self::debug) { |
|
| 572 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 573 | + echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
| 574 | + } |
|
| 575 | + // check if 'finalize_registration' step has been completed... |
|
| 576 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 577 | + if (self::debug) { |
|
| 578 | + // DEBUG LOG |
|
| 579 | + EEH_Debug_Tools::log( |
|
| 580 | + __CLASS__, |
|
| 581 | + __FUNCTION__, |
|
| 582 | + __LINE__, |
|
| 583 | + array('finalized' => $finalized), |
|
| 584 | + false, |
|
| 585 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 586 | + ); |
|
| 587 | + } |
|
| 588 | + // how many tickets were released |
|
| 589 | + $count = 0; |
|
| 590 | + if (self::debug) { |
|
| 591 | + echo '<br /> . . . finalized: ' . $finalized; |
|
| 592 | + } |
|
| 593 | + $release_tickets_with_TXN_status = array( |
|
| 594 | + EEM_Transaction::failed_status_code, |
|
| 595 | + EEM_Transaction::abandoned_status_code, |
|
| 596 | + EEM_Transaction::incomplete_status_code, |
|
| 597 | + ); |
|
| 598 | + // if the session is getting cleared BEFORE the TXN has been finalized |
|
| 599 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 600 | + // let's cancel any reserved tickets |
|
| 601 | + $registrations = $transaction->registrations(); |
|
| 602 | + if (! empty($registrations)) { |
|
| 603 | + foreach ($registrations as $registration) { |
|
| 604 | + if ($registration instanceof EE_Registration) { |
|
| 605 | + $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + return $count; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * releases reserved tickets for an EE_Registration |
|
| 617 | + * by default, will NOT release tickets for APPROVED registrations |
|
| 618 | + * |
|
| 619 | + * @param EE_Registration $registration |
|
| 620 | + * @param EE_Transaction $transaction |
|
| 621 | + * @return int |
|
| 622 | + * @throws EE_Error |
|
| 623 | + */ |
|
| 624 | + protected function _release_reserved_ticket_for_registration( |
|
| 625 | + EE_Registration $registration, |
|
| 626 | + EE_Transaction $transaction |
|
| 627 | + ) { |
|
| 628 | + $STS_ID = $transaction->status_ID(); |
|
| 629 | + if (self::debug) { |
|
| 630 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 631 | + echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
| 632 | + echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
| 633 | + echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
| 634 | + } |
|
| 635 | + if ( |
|
| 636 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
| 637 | + $STS_ID === EEM_Transaction::failed_status_code |
|
| 638 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
| 639 | + || ( |
|
| 640 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
| 641 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
| 642 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 643 | + ) |
|
| 644 | + ) { |
|
| 645 | + $ticket = $registration->ticket(); |
|
| 646 | + if ($ticket instanceof EE_Ticket) { |
|
| 647 | + return $this->_release_reserved_ticket($ticket); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + return 0; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + /********************************** SESSION_CART_RESET **********************************/ |
|
| 656 | + |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
| 661 | + * |
|
| 662 | + * @param EE_Session $session |
|
| 663 | + * @return void |
|
| 664 | + * @throws EE_Error |
|
| 665 | + * @throws InvalidArgumentException |
|
| 666 | + * @throws ReflectionException |
|
| 667 | + * @throws InvalidDataTypeException |
|
| 668 | + * @throws InvalidInterfaceException |
|
| 669 | + */ |
|
| 670 | + public static function session_cart_reset(EE_Session $session) |
|
| 671 | + { |
|
| 672 | + if (self::debug) { |
|
| 673 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 674 | + } |
|
| 675 | + $cart = $session->cart(); |
|
| 676 | + if ($cart instanceof EE_Cart) { |
|
| 677 | + if (self::debug) { |
|
| 678 | + echo '<br /><br /> cart instance of EE_Cart: '; |
|
| 679 | + } |
|
| 680 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
| 681 | + } else { |
|
| 682 | + if (self::debug) { |
|
| 683 | + echo '<br /><br /> invalid EE_Cart: '; |
|
| 684 | + var_export($cart, true); |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * releases reserved tickets in the EE_Cart |
|
| 693 | + * |
|
| 694 | + * @param EE_Cart $cart |
|
| 695 | + * @return void |
|
| 696 | + * @throws EE_Error |
|
| 697 | + * @throws InvalidArgumentException |
|
| 698 | + * @throws ReflectionException |
|
| 699 | + * @throws InvalidDataTypeException |
|
| 700 | + * @throws InvalidInterfaceException |
|
| 701 | + */ |
|
| 702 | + protected function _session_cart_reset(EE_Cart $cart) |
|
| 703 | + { |
|
| 704 | + if (self::debug) { |
|
| 705 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 706 | + } |
|
| 707 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
| 708 | + $ticket_line_items = $cart->get_tickets(); |
|
| 709 | + if (empty($ticket_line_items)) { |
|
| 710 | + return; |
|
| 711 | + } |
|
| 712 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 713 | + if (self::debug) { |
|
| 714 | + echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 715 | + } |
|
| 716 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
| 717 | + if (self::debug) { |
|
| 718 | + echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 719 | + } |
|
| 720 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
| 721 | + if ($ticket instanceof EE_Ticket) { |
|
| 722 | + if (self::debug) { |
|
| 723 | + echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
| 724 | + echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 725 | + } |
|
| 726 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | + if (self::debug) { |
|
| 731 | + echo '<br /><br /> RESET COMPLETED '; |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
| 743 | + * |
|
| 744 | + * @param EE_Session $session |
|
| 745 | + * @return void |
|
| 746 | + * @throws EE_Error |
|
| 747 | + * @throws InvalidSessionDataException |
|
| 748 | + */ |
|
| 749 | + public static function session_checkout_reset(EE_Session $session) |
|
| 750 | + { |
|
| 751 | + $checkout = $session->checkout(); |
|
| 752 | + if ($checkout instanceof EE_Checkout) { |
|
| 753 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + |
|
| 759 | + /** |
|
| 760 | + * releases reserved tickets for the EE_Checkout->transaction |
|
| 761 | + * |
|
| 762 | + * @param EE_Checkout $checkout |
|
| 763 | + * @return void |
|
| 764 | + * @throws EE_Error |
|
| 765 | + * @throws InvalidSessionDataException |
|
| 766 | + */ |
|
| 767 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
| 768 | + { |
|
| 769 | + if (self::debug) { |
|
| 770 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 771 | + } |
|
| 772 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
| 773 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
| 774 | + return; |
|
| 775 | + } |
|
| 776 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + |
|
| 780 | + |
|
| 781 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
| 782 | + |
|
| 783 | + |
|
| 784 | + |
|
| 785 | + /** |
|
| 786 | + * @param EE_Session $session |
|
| 787 | + * @return void |
|
| 788 | + */ |
|
| 789 | + public static function session_expired_reset(EE_Session $session) |
|
| 790 | + { |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + |
|
| 795 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
| 801 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
| 802 | + * |
|
| 803 | + * @param EE_Transaction $transaction |
|
| 804 | + * @return void |
|
| 805 | + * @throws EE_Error |
|
| 806 | + * @throws InvalidSessionDataException |
|
| 807 | + */ |
|
| 808 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
| 809 | + { |
|
| 810 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
| 811 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
| 812 | + if (self::debug) { |
|
| 813 | + // DEBUG LOG |
|
| 814 | + EEH_Debug_Tools::log( |
|
| 815 | + __CLASS__, |
|
| 816 | + __FUNCTION__, |
|
| 817 | + __LINE__, |
|
| 818 | + array($transaction), |
|
| 819 | + false, |
|
| 820 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 821 | + ); |
|
| 822 | + } |
|
| 823 | + return; |
|
| 824 | + } |
|
| 825 | + // have their been any successful payments made ? |
|
| 826 | + $payments = $transaction->payments(); |
|
| 827 | + foreach ($payments as $payment) { |
|
| 828 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
| 829 | + if (self::debug) { |
|
| 830 | + // DEBUG LOG |
|
| 831 | + EEH_Debug_Tools::log( |
|
| 832 | + __CLASS__, |
|
| 833 | + __FUNCTION__, |
|
| 834 | + __LINE__, |
|
| 835 | + array($payment), |
|
| 836 | + false, |
|
| 837 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 838 | + ); |
|
| 839 | + } |
|
| 840 | + return; |
|
| 841 | + } |
|
| 842 | + } |
|
| 843 | + // since you haven't even attempted to pay for your ticket... |
|
| 844 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
| 850 | + |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
| 855 | + * |
|
| 856 | + * @param EE_Transaction $transaction |
|
| 857 | + * @return void |
|
| 858 | + * @throws EE_Error |
|
| 859 | + * @throws InvalidSessionDataException |
|
| 860 | + */ |
|
| 861 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
| 862 | + { |
|
| 863 | + // since you haven't even attempted to pay for your ticket... |
|
| 864 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
| 870 | + |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * Resets all ticket and datetime reserved counts to zero |
|
| 875 | + * Tickets that are currently associated with a Transaction that is in progress |
|
| 876 | + * |
|
| 877 | + * @throws EE_Error |
|
| 878 | + * @throws DomainException |
|
| 879 | + * @throws InvalidDataTypeException |
|
| 880 | + * @throws InvalidInterfaceException |
|
| 881 | + * @throws InvalidArgumentException |
|
| 882 | + * @throws UnexpectedEntityException |
|
| 883 | + */ |
|
| 884 | + public static function reset_reservation_counts() |
|
| 885 | + { |
|
| 886 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 887 | + $valid_reserved_tickets = array(); |
|
| 888 | + /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
| 889 | + $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
| 890 | + foreach ($transactions_not_in_progress as $transaction) { |
|
| 891 | + // if this TXN has been fully completed, then skip it |
|
| 892 | + if ($transaction->reg_step_completed('finalize_registration')) { |
|
| 893 | + continue; |
|
| 894 | + } |
|
| 895 | + $total_line_item = $transaction->total_line_item(); |
|
| 896 | + // $transaction_in_progress->line |
|
| 897 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
| 898 | + throw new DomainException( |
|
| 899 | + esc_html__( |
|
| 900 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
| 901 | + 'event_espresso' |
|
| 902 | + ) |
|
| 903 | + ); |
|
| 904 | + } |
|
| 905 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 906 | + $total_line_item |
|
| 907 | + ); |
|
| 908 | + } |
|
| 909 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
| 910 | + foreach ($total_line_items as $total_line_item) { |
|
| 911 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 912 | + $total_line_item |
|
| 913 | + ); |
|
| 914 | + } |
|
| 915 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 916 | + EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
| 917 | + $valid_reserved_tickets |
|
| 918 | + ); |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * @param EE_Line_Item $total_line_item |
|
| 925 | + * @return EE_Line_Item[] |
|
| 926 | + */ |
|
| 927 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
| 928 | + { |
|
| 929 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 930 | + $valid_reserved_tickets = array(); |
|
| 931 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 932 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 933 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
| 934 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
| 935 | + } |
|
| 936 | + } |
|
| 937 | + return $valid_reserved_tickets; |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * @param EE_Ticket[] $tickets_with_reservations |
|
| 944 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
| 945 | + * @return int |
|
| 946 | + * @throws UnexpectedEntityException |
|
| 947 | + * @throws DomainException |
|
| 948 | + * @throws EE_Error |
|
| 949 | + */ |
|
| 950 | + private static function release_reservations_for_tickets( |
|
| 951 | + array $tickets_with_reservations, |
|
| 952 | + array $valid_reserved_ticket_line_items = array() |
|
| 953 | + ) { |
|
| 954 | + $total_tickets_released = 0; |
|
| 955 | + $sold_out_events = array(); |
|
| 956 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
| 957 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 958 | + continue; |
|
| 959 | + } |
|
| 960 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
| 961 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
| 962 | + if ( |
|
| 963 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
| 964 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
| 965 | + ) { |
|
| 966 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
| 967 | + } |
|
| 968 | + } |
|
| 969 | + if ($reserved_qty > 0) { |
|
| 970 | + $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
| 971 | + $ticket_with_reservations->save(); |
|
| 972 | + $total_tickets_released += $reserved_qty; |
|
| 973 | + $event = $ticket_with_reservations->get_related_event(); |
|
| 974 | + // track sold out events |
|
| 975 | + if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
| 976 | + $sold_out_events[] = $event; |
|
| 977 | + } |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + // double check whether sold out events should remain sold out after releasing tickets |
|
| 981 | + if($sold_out_events !== array()){ |
|
| 982 | + foreach ($sold_out_events as $sold_out_event) { |
|
| 983 | + /** @var EE_Event $sold_out_event */ |
|
| 984 | + $sold_out_event->perform_sold_out_status_check(); |
|
| 985 | + } |
|
| 986 | + } |
|
| 987 | + return $total_tickets_released; |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + |
|
| 991 | + |
|
| 992 | + /********************************** SHUTDOWN **********************************/ |
|
| 993 | + |
|
| 994 | + |
|
| 995 | + |
|
| 996 | + /** |
|
| 997 | + * @return false|int |
|
| 998 | + * @throws EE_Error |
|
| 999 | + * @throws InvalidArgumentException |
|
| 1000 | + * @throws InvalidDataTypeException |
|
| 1001 | + * @throws InvalidInterfaceException |
|
| 1002 | + */ |
|
| 1003 | + public static function clear_expired_line_items_with_no_transaction() |
|
| 1004 | + { |
|
| 1005 | + /** @type WPDB $wpdb */ |
|
| 1006 | + global $wpdb; |
|
| 1007 | + return $wpdb->query( |
|
| 1008 | + $wpdb->prepare( |
|
| 1009 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 1010 | 1010 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
| 1011 | - // use GMT time because that's what LIN_timestamps are in |
|
| 1012 | - date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
| 1013 | - ) |
|
| 1014 | - ); |
|
| 1015 | - } |
|
| 1011 | + // use GMT time because that's what LIN_timestamps are in |
|
| 1012 | + date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
| 1013 | + ) |
|
| 1014 | + ); |
|
| 1015 | + } |
|
| 1016 | 1016 | |
| 1017 | 1017 | } |
| 1018 | 1018 | // End of file EED_Ticket_Sales_Monitor.module.php |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | class EED_Ticket_Sales_Monitor extends EED_Module |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - const debug = false; // true false |
|
| 26 | + const debug = false; // true false |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * an array of raw ticket data from EED_Ticket_Selector |
@@ -209,17 +209,17 @@ discard block |
||
| 209 | 209 | /** @var EE_Line_Item $total_line_item */ |
| 210 | 210 | $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
| 211 | 211 | foreach ($ticket_line_items as $ticket_line_item) { |
| 212 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
| 212 | + if ( ! $ticket_line_item instanceof EE_Line_Item) { |
|
| 213 | 213 | continue; |
| 214 | 214 | } |
| 215 | 215 | if ($total_line_item->timestamp(true) <= $expired) { |
| 216 | - $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
| 216 | + $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
| 217 | 217 | } else { |
| 218 | - $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
| 218 | + $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | - if (! empty($expired_ticket_IDs)) { |
|
| 222 | + if ( ! empty($expired_ticket_IDs)) { |
|
| 223 | 223 | EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
| 224 | 224 | \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
| 225 | 225 | $valid_ticket_line_items |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
| 262 | 262 | } |
| 263 | 263 | if (self::debug) { |
| 264 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 265 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 264 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'()'; |
|
| 265 | + echo '<br /><br /><b> RETURNED QTY: '.$qty.'</b>'; |
|
| 266 | 266 | } |
| 267 | 267 | return $qty; |
| 268 | 268 | } |
@@ -281,36 +281,36 @@ discard block |
||
| 281 | 281 | protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
| 282 | 282 | { |
| 283 | 283 | if (self::debug) { |
| 284 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 284 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 285 | 285 | } |
| 286 | - if (! $ticket instanceof EE_Ticket) { |
|
| 286 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 287 | 287 | return 0; |
| 288 | 288 | } |
| 289 | 289 | if (self::debug) { |
| 290 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 291 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
| 290 | + echo '<br /><b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
| 291 | + echo '<br /> . original ticket->reserved: '.$ticket->reserved(); |
|
| 292 | 292 | } |
| 293 | 293 | $ticket->refresh_from_db(); |
| 294 | 294 | // first let's determine the ticket availability based on sales |
| 295 | 295 | $available = $ticket->qty('saleable'); |
| 296 | 296 | if (self::debug) { |
| 297 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
| 298 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
| 299 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 300 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 301 | - echo '<br /> . . . available: ' . $available; |
|
| 297 | + echo '<br /> . . . ticket->qty: '.$ticket->qty(); |
|
| 298 | + echo '<br /> . . . ticket->sold: '.$ticket->sold(); |
|
| 299 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
| 300 | + echo '<br /> . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
| 301 | + echo '<br /> . . . available: '.$available; |
|
| 302 | 302 | } |
| 303 | 303 | if ($available < 1) { |
| 304 | 304 | $this->_ticket_sold_out($ticket); |
| 305 | 305 | return 0; |
| 306 | 306 | } |
| 307 | 307 | if (self::debug) { |
| 308 | - echo '<br /> . . . qty: ' . $qty; |
|
| 308 | + echo '<br /> . . . qty: '.$qty; |
|
| 309 | 309 | } |
| 310 | 310 | if ($available < $qty) { |
| 311 | 311 | $qty = $available; |
| 312 | 312 | if (self::debug) { |
| 313 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
| 313 | + echo '<br /> . . . QTY ADJUSTED: '.$qty; |
|
| 314 | 314 | } |
| 315 | 315 | $this->_ticket_quantity_decremented($ticket); |
| 316 | 316 | } |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
| 332 | 332 | { |
| 333 | 333 | if (self::debug) { |
| 334 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
| 334 | + echo '<br /><br /> . . . INCREASE RESERVED: '.$quantity; |
|
| 335 | 335 | } |
| 336 | 336 | $ticket->increase_reserved($quantity); |
| 337 | 337 | return $ticket->save(); |
@@ -348,12 +348,12 @@ discard block |
||
| 348 | 348 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
| 349 | 349 | { |
| 350 | 350 | if (self::debug) { |
| 351 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
| 352 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 351 | + echo '<br /> . . . ticket->ID: '.$ticket->ID(); |
|
| 352 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
| 353 | 353 | } |
| 354 | 354 | $ticket->decrease_reserved($quantity); |
| 355 | 355 | if (self::debug) { |
| 356 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 356 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
| 357 | 357 | } |
| 358 | 358 | return $ticket->save() ? 1 : 0; |
| 359 | 359 | } |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | protected function _ticket_sold_out(EE_Ticket $ticket) |
| 372 | 372 | { |
| 373 | 373 | if (self::debug) { |
| 374 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 375 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 374 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 375 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
| 376 | 376 | } |
| 377 | 377 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
| 378 | 378 | } |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
| 391 | 391 | { |
| 392 | 392 | if (self::debug) { |
| 393 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 394 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 393 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 394 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
| 395 | 395 | } |
| 396 | 396 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
| 397 | 397 | } |
@@ -497,18 +497,18 @@ discard block |
||
| 497 | 497 | protected function _post_notices() |
| 498 | 498 | { |
| 499 | 499 | if (self::debug) { |
| 500 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 500 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 501 | 501 | } |
| 502 | 502 | $refresh_msg = ''; |
| 503 | 503 | $none_added_msg = ''; |
| 504 | 504 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 505 | - $refresh_msg = __( |
|
| 505 | + $refresh_msg = __( |
|
| 506 | 506 | 'Please refresh the page to view updated ticket quantities.', |
| 507 | 507 | 'event_espresso' |
| 508 | 508 | ); |
| 509 | 509 | $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
| 510 | 510 | } |
| 511 | - if (! empty($this->sold_out_tickets)) { |
|
| 511 | + if ( ! empty($this->sold_out_tickets)) { |
|
| 512 | 512 | EE_Error::add_attention( |
| 513 | 513 | sprintf( |
| 514 | 514 | apply_filters( |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | // and reset the cart |
| 532 | 532 | EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
| 533 | 533 | } |
| 534 | - if (! empty($this->decremented_tickets)) { |
|
| 534 | + if ( ! empty($this->decremented_tickets)) { |
|
| 535 | 535 | EE_Error::add_attention( |
| 536 | 536 | sprintf( |
| 537 | 537 | apply_filters( |
@@ -569,8 +569,8 @@ discard block |
||
| 569 | 569 | protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
| 570 | 570 | { |
| 571 | 571 | if (self::debug) { |
| 572 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 573 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
| 572 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 573 | + echo '<br /> . transaction->ID: '.$transaction->ID(); |
|
| 574 | 574 | } |
| 575 | 575 | // check if 'finalize_registration' step has been completed... |
| 576 | 576 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -582,13 +582,13 @@ discard block |
||
| 582 | 582 | __LINE__, |
| 583 | 583 | array('finalized' => $finalized), |
| 584 | 584 | false, |
| 585 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 585 | + 'EE_Transaction: '.$transaction->ID() |
|
| 586 | 586 | ); |
| 587 | 587 | } |
| 588 | 588 | // how many tickets were released |
| 589 | 589 | $count = 0; |
| 590 | 590 | if (self::debug) { |
| 591 | - echo '<br /> . . . finalized: ' . $finalized; |
|
| 591 | + echo '<br /> . . . finalized: '.$finalized; |
|
| 592 | 592 | } |
| 593 | 593 | $release_tickets_with_TXN_status = array( |
| 594 | 594 | EEM_Transaction::failed_status_code, |
@@ -596,10 +596,10 @@ discard block |
||
| 596 | 596 | EEM_Transaction::incomplete_status_code, |
| 597 | 597 | ); |
| 598 | 598 | // if the session is getting cleared BEFORE the TXN has been finalized |
| 599 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 599 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 600 | 600 | // let's cancel any reserved tickets |
| 601 | 601 | $registrations = $transaction->registrations(); |
| 602 | - if (! empty($registrations)) { |
|
| 602 | + if ( ! empty($registrations)) { |
|
| 603 | 603 | foreach ($registrations as $registration) { |
| 604 | 604 | if ($registration instanceof EE_Registration) { |
| 605 | 605 | $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
@@ -627,10 +627,10 @@ discard block |
||
| 627 | 627 | ) { |
| 628 | 628 | $STS_ID = $transaction->status_ID(); |
| 629 | 629 | if (self::debug) { |
| 630 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 631 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
| 632 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
| 633 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
| 630 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 631 | + echo '<br /> . . registration->ID: '.$registration->ID(); |
|
| 632 | + echo '<br /> . . registration->status_ID: '.$registration->status_ID(); |
|
| 633 | + echo '<br /> . . transaction->status_ID(): '.$STS_ID; |
|
| 634 | 634 | } |
| 635 | 635 | if ( |
| 636 | 636 | // release Tickets for Failed Transactions and Abandoned Transactions |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | public static function session_cart_reset(EE_Session $session) |
| 671 | 671 | { |
| 672 | 672 | if (self::debug) { |
| 673 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 673 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 674 | 674 | } |
| 675 | 675 | $cart = $session->cart(); |
| 676 | 676 | if ($cart instanceof EE_Cart) { |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | protected function _session_cart_reset(EE_Cart $cart) |
| 703 | 703 | { |
| 704 | 704 | if (self::debug) { |
| 705 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 705 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 706 | 706 | } |
| 707 | 707 | EE_Registry::instance()->load_helper('Line_Item'); |
| 708 | 708 | $ticket_line_items = $cart->get_tickets(); |
@@ -711,17 +711,17 @@ discard block |
||
| 711 | 711 | } |
| 712 | 712 | foreach ($ticket_line_items as $ticket_line_item) { |
| 713 | 713 | if (self::debug) { |
| 714 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 714 | + echo '<br /> . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
| 715 | 715 | } |
| 716 | 716 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
| 717 | 717 | if (self::debug) { |
| 718 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 718 | + echo '<br /> . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
| 719 | 719 | } |
| 720 | 720 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
| 721 | 721 | if ($ticket instanceof EE_Ticket) { |
| 722 | 722 | if (self::debug) { |
| 723 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
| 724 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 723 | + echo '<br /> . . ticket->ID(): '.$ticket->ID(); |
|
| 724 | + echo '<br /> . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
| 725 | 725 | } |
| 726 | 726 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
| 727 | 727 | } |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | protected function _session_checkout_reset(EE_Checkout $checkout) |
| 768 | 768 | { |
| 769 | 769 | if (self::debug) { |
| 770 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 770 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 771 | 771 | } |
| 772 | 772 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
| 773 | 773 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | __LINE__, |
| 818 | 818 | array($transaction), |
| 819 | 819 | false, |
| 820 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 820 | + 'EE_Transaction: '.$transaction->ID() |
|
| 821 | 821 | ); |
| 822 | 822 | } |
| 823 | 823 | return; |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | __LINE__, |
| 835 | 835 | array($payment), |
| 836 | 836 | false, |
| 837 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 837 | + 'EE_Transaction: '.$transaction->ID() |
|
| 838 | 838 | ); |
| 839 | 839 | } |
| 840 | 840 | return; |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | } |
| 895 | 895 | $total_line_item = $transaction->total_line_item(); |
| 896 | 896 | // $transaction_in_progress->line |
| 897 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
| 897 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
| 898 | 898 | throw new DomainException( |
| 899 | 899 | esc_html__( |
| 900 | 900 | 'Transaction does not have a valid Total Line Item associated with it.', |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | $total_tickets_released = 0; |
| 955 | 955 | $sold_out_events = array(); |
| 956 | 956 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
| 957 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 957 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 958 | 958 | continue; |
| 959 | 959 | } |
| 960 | 960 | $reserved_qty = $ticket_with_reservations->reserved(); |
@@ -978,7 +978,7 @@ discard block |
||
| 978 | 978 | } |
| 979 | 979 | } |
| 980 | 980 | // double check whether sold out events should remain sold out after releasing tickets |
| 981 | - if($sold_out_events !== array()){ |
|
| 981 | + if ($sold_out_events !== array()) { |
|
| 982 | 982 | foreach ($sold_out_events as $sold_out_event) { |
| 983 | 983 | /** @var EE_Event $sold_out_event */ |
| 984 | 984 | $sold_out_event->perform_sold_out_status_check(); |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | global $wpdb; |
| 1007 | 1007 | return $wpdb->query( |
| 1008 | 1008 | $wpdb->prepare( |
| 1009 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 1009 | + 'DELETE FROM '.EEM_Line_Item::instance()->table().' |
|
| 1010 | 1010 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
| 1011 | 1011 | // use GMT time because that's what LIN_timestamps are in |
| 1012 | 1012 | date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
@@ -15,115 +15,115 @@ |
||
| 15 | 15 | class Extend_EE_Registrations_List_Table extends EE_Registrations_List_Table |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @param EE_Registration $item |
|
| 20 | - * @return string |
|
| 21 | - * @throws EE_Error |
|
| 22 | - * @throws InvalidArgumentException |
|
| 23 | - * @throws ReflectionException |
|
| 24 | - * @throws InvalidDataTypeException |
|
| 25 | - * @throws InvalidInterfaceException |
|
| 26 | - */ |
|
| 27 | - function column__REG_date(EE_Registration $item) |
|
| 28 | - { |
|
| 29 | - $date_linked = parent::column__REG_date($item); |
|
| 30 | - $actions = array(); |
|
| 31 | - //Build row actions |
|
| 32 | - $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 33 | - 'action' => 'event_registrations', |
|
| 34 | - 'event_id' => $item->event_ID(), |
|
| 35 | - ), REG_ADMIN_URL); |
|
| 36 | - $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 37 | - 'ee_read_registration', |
|
| 38 | - 'espresso_registrations_registration_checkins', |
|
| 39 | - $item->ID() |
|
| 40 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 41 | - 'ee_read_checkins', |
|
| 42 | - 'espresso_registrations_registration_checkins' |
|
| 43 | - ) |
|
| 44 | - ? '<a href="' . $check_in_url . '"' |
|
| 45 | - . ' title="' . esc_attr__( |
|
| 46 | - 'The Check-In List allows you to easily toggle check-in status for this event', |
|
| 47 | - 'event_espresso' |
|
| 48 | - ) |
|
| 49 | - . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
| 50 | - : esc_html__('View Check-ins', 'event_espresso'); |
|
| 18 | + /** |
|
| 19 | + * @param EE_Registration $item |
|
| 20 | + * @return string |
|
| 21 | + * @throws EE_Error |
|
| 22 | + * @throws InvalidArgumentException |
|
| 23 | + * @throws ReflectionException |
|
| 24 | + * @throws InvalidDataTypeException |
|
| 25 | + * @throws InvalidInterfaceException |
|
| 26 | + */ |
|
| 27 | + function column__REG_date(EE_Registration $item) |
|
| 28 | + { |
|
| 29 | + $date_linked = parent::column__REG_date($item); |
|
| 30 | + $actions = array(); |
|
| 31 | + //Build row actions |
|
| 32 | + $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 33 | + 'action' => 'event_registrations', |
|
| 34 | + 'event_id' => $item->event_ID(), |
|
| 35 | + ), REG_ADMIN_URL); |
|
| 36 | + $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 37 | + 'ee_read_registration', |
|
| 38 | + 'espresso_registrations_registration_checkins', |
|
| 39 | + $item->ID() |
|
| 40 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 41 | + 'ee_read_checkins', |
|
| 42 | + 'espresso_registrations_registration_checkins' |
|
| 43 | + ) |
|
| 44 | + ? '<a href="' . $check_in_url . '"' |
|
| 45 | + . ' title="' . esc_attr__( |
|
| 46 | + 'The Check-In List allows you to easily toggle check-in status for this event', |
|
| 47 | + 'event_espresso' |
|
| 48 | + ) |
|
| 49 | + . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
| 50 | + : esc_html__('View Check-ins', 'event_espresso'); |
|
| 51 | 51 | |
| 52 | - return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
|
| 53 | - } |
|
| 52 | + return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * column_default |
|
| 58 | - * |
|
| 59 | - * @param \EE_Registration $item |
|
| 60 | - * @return string |
|
| 61 | - * @throws EE_Error |
|
| 62 | - * @throws InvalidArgumentException |
|
| 63 | - * @throws InvalidDataTypeException |
|
| 64 | - * @throws InvalidInterfaceException |
|
| 65 | - * @throws ReflectionException |
|
| 66 | - */ |
|
| 67 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
| 68 | - { |
|
| 69 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 70 | - $ticket = $item->ticket(); |
|
| 71 | - $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
| 72 | - $EVT_ID = $item->event_ID(); |
|
| 73 | - $datetimes_for_display = array(); |
|
| 74 | - foreach ($datetimes as $datetime) { |
|
| 75 | - $datetime_string = ''; |
|
| 76 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 77 | - 'ee_read_checkin', |
|
| 78 | - 'espresso_registrations_registration_checkins', |
|
| 79 | - $item->ID() |
|
| 80 | - )) { |
|
| 81 | - // open "a" tag and "href" |
|
| 82 | - $datetime_string .= '<a href="'; |
|
| 83 | - // checkin URL |
|
| 84 | - $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 85 | - array( |
|
| 86 | - 'action' => 'event_registrations', |
|
| 87 | - 'event_id' => $EVT_ID, |
|
| 88 | - 'DTT_ID' => $datetime->ID(), |
|
| 89 | - ), |
|
| 90 | - REG_ADMIN_URL |
|
| 91 | - ); |
|
| 92 | - // close "href" |
|
| 93 | - $datetime_string .= '"'; |
|
| 94 | - // open "title" tag |
|
| 95 | - $datetime_string .= ' title="'; |
|
| 96 | - // link title text |
|
| 97 | - $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
| 98 | - // close "title" tag and end of "a" tag opening |
|
| 99 | - $datetime_string .= '">'; |
|
| 100 | - // link text |
|
| 101 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 102 | - // close "a" tag |
|
| 103 | - $datetime_string .= '</a>'; |
|
| 104 | - } else { |
|
| 105 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 106 | - } |
|
| 107 | - // add a "View Registrations" link that filters list by event AND datetime |
|
| 108 | - $datetime_string .= $this->row_actions( |
|
| 109 | - array( |
|
| 110 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 111 | - array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
| 112 | - REG_ADMIN_URL |
|
| 113 | - ) |
|
| 114 | - . '" title="' . sprintf( |
|
| 115 | - esc_attr__( |
|
| 116 | - 'Filter this list to only show registrations for this datetime %s', |
|
| 117 | - 'event_espresso' |
|
| 118 | - ), |
|
| 119 | - $datetime->name() |
|
| 120 | - ) . '">' |
|
| 121 | - . esc_html__('View Registrations', 'event_espresso') |
|
| 122 | - . '</a>', |
|
| 123 | - ) |
|
| 124 | - ); |
|
| 125 | - $datetimes_for_display[] = $datetime_string; |
|
| 126 | - } |
|
| 127 | - return $this->generateDisplayForDateTimes($datetimes_for_display); |
|
| 128 | - } |
|
| 56 | + /** |
|
| 57 | + * column_default |
|
| 58 | + * |
|
| 59 | + * @param \EE_Registration $item |
|
| 60 | + * @return string |
|
| 61 | + * @throws EE_Error |
|
| 62 | + * @throws InvalidArgumentException |
|
| 63 | + * @throws InvalidDataTypeException |
|
| 64 | + * @throws InvalidInterfaceException |
|
| 65 | + * @throws ReflectionException |
|
| 66 | + */ |
|
| 67 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
| 68 | + { |
|
| 69 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 70 | + $ticket = $item->ticket(); |
|
| 71 | + $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
| 72 | + $EVT_ID = $item->event_ID(); |
|
| 73 | + $datetimes_for_display = array(); |
|
| 74 | + foreach ($datetimes as $datetime) { |
|
| 75 | + $datetime_string = ''; |
|
| 76 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 77 | + 'ee_read_checkin', |
|
| 78 | + 'espresso_registrations_registration_checkins', |
|
| 79 | + $item->ID() |
|
| 80 | + )) { |
|
| 81 | + // open "a" tag and "href" |
|
| 82 | + $datetime_string .= '<a href="'; |
|
| 83 | + // checkin URL |
|
| 84 | + $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 85 | + array( |
|
| 86 | + 'action' => 'event_registrations', |
|
| 87 | + 'event_id' => $EVT_ID, |
|
| 88 | + 'DTT_ID' => $datetime->ID(), |
|
| 89 | + ), |
|
| 90 | + REG_ADMIN_URL |
|
| 91 | + ); |
|
| 92 | + // close "href" |
|
| 93 | + $datetime_string .= '"'; |
|
| 94 | + // open "title" tag |
|
| 95 | + $datetime_string .= ' title="'; |
|
| 96 | + // link title text |
|
| 97 | + $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
| 98 | + // close "title" tag and end of "a" tag opening |
|
| 99 | + $datetime_string .= '">'; |
|
| 100 | + // link text |
|
| 101 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 102 | + // close "a" tag |
|
| 103 | + $datetime_string .= '</a>'; |
|
| 104 | + } else { |
|
| 105 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 106 | + } |
|
| 107 | + // add a "View Registrations" link that filters list by event AND datetime |
|
| 108 | + $datetime_string .= $this->row_actions( |
|
| 109 | + array( |
|
| 110 | + 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 111 | + array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
| 112 | + REG_ADMIN_URL |
|
| 113 | + ) |
|
| 114 | + . '" title="' . sprintf( |
|
| 115 | + esc_attr__( |
|
| 116 | + 'Filter this list to only show registrations for this datetime %s', |
|
| 117 | + 'event_espresso' |
|
| 118 | + ), |
|
| 119 | + $datetime->name() |
|
| 120 | + ) . '">' |
|
| 121 | + . esc_html__('View Registrations', 'event_espresso') |
|
| 122 | + . '</a>', |
|
| 123 | + ) |
|
| 124 | + ); |
|
| 125 | + $datetimes_for_display[] = $datetime_string; |
|
| 126 | + } |
|
| 127 | + return $this->generateDisplayForDateTimes($datetimes_for_display); |
|
| 128 | + } |
|
| 129 | 129 | } |
@@ -41,12 +41,12 @@ discard block |
||
| 41 | 41 | 'ee_read_checkins', |
| 42 | 42 | 'espresso_registrations_registration_checkins' |
| 43 | 43 | ) |
| 44 | - ? '<a href="' . $check_in_url . '"' |
|
| 45 | - . ' title="' . esc_attr__( |
|
| 44 | + ? '<a href="'.$check_in_url.'"' |
|
| 45 | + . ' title="'.esc_attr__( |
|
| 46 | 46 | 'The Check-In List allows you to easily toggle check-in status for this event', |
| 47 | 47 | 'event_espresso' |
| 48 | 48 | ) |
| 49 | - . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
| 49 | + . '">'.esc_html__('View Check-ins', 'event_espresso').'</a>' |
|
| 50 | 50 | : esc_html__('View Check-ins', 'event_espresso'); |
| 51 | 51 | |
| 52 | 52 | return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
@@ -107,17 +107,17 @@ discard block |
||
| 107 | 107 | // add a "View Registrations" link that filters list by event AND datetime |
| 108 | 108 | $datetime_string .= $this->row_actions( |
| 109 | 109 | array( |
| 110 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 110 | + 'event_datetime_filter' => '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
| 111 | 111 | array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
| 112 | 112 | REG_ADMIN_URL |
| 113 | 113 | ) |
| 114 | - . '" title="' . sprintf( |
|
| 114 | + . '" title="'.sprintf( |
|
| 115 | 115 | esc_attr__( |
| 116 | 116 | 'Filter this list to only show registrations for this datetime %s', |
| 117 | 117 | 'event_espresso' |
| 118 | 118 | ), |
| 119 | 119 | $datetime->name() |
| 120 | - ) . '">' |
|
| 120 | + ).'">' |
|
| 121 | 121 | . esc_html__('View Registrations', 'event_espresso') |
| 122 | 122 | . '</a>', |
| 123 | 123 | ) |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 4 | 4 | |
| 5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 6 | - exit('No direct script access allowed'); |
|
| 6 | + exit('No direct script access allowed'); |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | |
@@ -28,1006 +28,1006 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - private $_status; |
|
| 31 | + /** |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + private $_status; |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * An array of transaction details for the related transaction to the registration being processed. |
|
| 39 | - * This is set via the _set_related_details method. |
|
| 40 | - * |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - protected $_transaction_details = array(); |
|
| 37 | + /** |
|
| 38 | + * An array of transaction details for the related transaction to the registration being processed. |
|
| 39 | + * This is set via the _set_related_details method. |
|
| 40 | + * |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + protected $_transaction_details = array(); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * An array of event details for the related event to the registration being processed. |
|
| 48 | - * This is set via the _set_related_details method. |
|
| 49 | - * |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - protected $_event_details = array(); |
|
| 46 | + /** |
|
| 47 | + * An array of event details for the related event to the registration being processed. |
|
| 48 | + * This is set via the _set_related_details method. |
|
| 49 | + * |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + protected $_event_details = array(); |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param \Registrations_Admin_Page $admin_page |
|
| 57 | - */ |
|
| 58 | - public function __construct(Registrations_Admin_Page $admin_page) |
|
| 59 | - { |
|
| 60 | - if (! empty($_GET['event_id'])) { |
|
| 61 | - $extra_query_args = array(); |
|
| 62 | - foreach ($admin_page->get_views() as $key => $view_details) { |
|
| 63 | - $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
|
| 64 | - } |
|
| 65 | - $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
|
| 66 | - } |
|
| 67 | - parent::__construct($admin_page); |
|
| 68 | - $this->_status = $this->_admin_page->get_registration_status_array(); |
|
| 69 | - } |
|
| 55 | + /** |
|
| 56 | + * @param \Registrations_Admin_Page $admin_page |
|
| 57 | + */ |
|
| 58 | + public function __construct(Registrations_Admin_Page $admin_page) |
|
| 59 | + { |
|
| 60 | + if (! empty($_GET['event_id'])) { |
|
| 61 | + $extra_query_args = array(); |
|
| 62 | + foreach ($admin_page->get_views() as $key => $view_details) { |
|
| 63 | + $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
|
| 64 | + } |
|
| 65 | + $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
|
| 66 | + } |
|
| 67 | + parent::__construct($admin_page); |
|
| 68 | + $this->_status = $this->_admin_page->get_registration_status_array(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * _setup_data |
|
| 74 | - * |
|
| 75 | - * @access protected |
|
| 76 | - * @return void |
|
| 77 | - */ |
|
| 78 | - protected function _setup_data() |
|
| 79 | - { |
|
| 80 | - $this->_data = $this->_admin_page->get_registrations($this->_per_page); |
|
| 81 | - $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false); |
|
| 82 | - } |
|
| 72 | + /** |
|
| 73 | + * _setup_data |
|
| 74 | + * |
|
| 75 | + * @access protected |
|
| 76 | + * @return void |
|
| 77 | + */ |
|
| 78 | + protected function _setup_data() |
|
| 79 | + { |
|
| 80 | + $this->_data = $this->_admin_page->get_registrations($this->_per_page); |
|
| 81 | + $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * _set_properties |
|
| 87 | - * |
|
| 88 | - * @access protected |
|
| 89 | - * @return void |
|
| 90 | - */ |
|
| 91 | - protected function _set_properties() |
|
| 92 | - { |
|
| 93 | - $this->_wp_list_args = array( |
|
| 94 | - 'singular' => __('registration', 'event_espresso'), |
|
| 95 | - 'plural' => __('registrations', 'event_espresso'), |
|
| 96 | - 'ajax' => true, |
|
| 97 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 98 | - ); |
|
| 99 | - $ID_column_name = __('ID', 'event_espresso'); |
|
| 100 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
| 101 | - $ID_column_name .= __('Registrant Name', 'event_espresso'); |
|
| 102 | - $ID_column_name .= '</span> '; |
|
| 103 | - if (isset($_GET['event_id'])) { |
|
| 104 | - $this->_columns = array( |
|
| 105 | - 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
| 106 | - '_REG_ID' => $ID_column_name, |
|
| 107 | - 'ATT_fname' => __('Name', 'event_espresso'), |
|
| 108 | - 'ATT_email' => __('Email', 'event_espresso'), |
|
| 109 | - '_REG_date' => __('Reg Date', 'event_espresso'), |
|
| 110 | - 'PRC_amount' => __('TKT Price', 'event_espresso'), |
|
| 111 | - '_REG_final_price' => __('Final Price', 'event_espresso'), |
|
| 112 | - 'TXN_total' => __('Total Txn', 'event_espresso'), |
|
| 113 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
| 114 | - 'actions' => __('Actions', 'event_espresso'), |
|
| 115 | - ); |
|
| 116 | - $this->_bottom_buttons = array( |
|
| 117 | - 'report' => array( |
|
| 118 | - 'route' => 'registrations_report', |
|
| 119 | - 'extra_request' => array( |
|
| 120 | - 'EVT_ID' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 121 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 122 | - ), |
|
| 123 | - ), |
|
| 124 | - ); |
|
| 125 | - } else { |
|
| 126 | - $this->_columns = array( |
|
| 127 | - 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
| 128 | - '_REG_ID' => $ID_column_name, |
|
| 129 | - 'ATT_fname' => __('Name', 'event_espresso'), |
|
| 130 | - '_REG_date' => __('TXN Date', 'event_espresso'), |
|
| 131 | - 'event_name' => __('Event', 'event_espresso'), |
|
| 132 | - 'DTT_EVT_start' => __('Event Date', 'event_espresso'), |
|
| 133 | - '_REG_final_price' => __('Price', 'event_espresso'), |
|
| 134 | - '_REG_paid' => __('Paid', 'event_espresso'), |
|
| 135 | - 'actions' => __('Actions', 'event_espresso'), |
|
| 136 | - ); |
|
| 137 | - $this->_bottom_buttons = array( |
|
| 138 | - 'report_all' => array( |
|
| 139 | - 'route' => 'registrations_report', |
|
| 140 | - 'extra_request' => array( |
|
| 141 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 142 | - ), |
|
| 143 | - ), |
|
| 144 | - ); |
|
| 145 | - } |
|
| 146 | - $this->_bottom_buttons['report_filtered'] = array( |
|
| 147 | - 'route' => 'registrations_report', |
|
| 148 | - 'extra_request' => array( |
|
| 149 | - 'use_filters' => true, |
|
| 150 | - 'filters' => array_diff_key($this->_req_data, array_flip(array( |
|
| 151 | - 'page', |
|
| 152 | - 'action', |
|
| 153 | - 'default_nonce', |
|
| 154 | - ))), |
|
| 155 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 156 | - ), |
|
| 157 | - ); |
|
| 158 | - $this->_primary_column = '_REG_ID'; |
|
| 159 | - $this->_sortable_columns = array( |
|
| 160 | - '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
| 161 | - /** |
|
| 162 | - * Allows users to change the default sort if they wish. |
|
| 163 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last |
|
| 164 | - * name. |
|
| 165 | - */ |
|
| 166 | - 'ATT_fname' => array( |
|
| 167 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
| 168 | - true, |
|
| 169 | - $this, |
|
| 170 | - ) |
|
| 171 | - ? array('ATT_lname' => false) |
|
| 172 | - : array('ATT_fname' => false), |
|
| 173 | - 'event_name' => array('event_name' => false), |
|
| 174 | - 'DTT_EVT_start' => array('DTT_EVT_start' => false), |
|
| 175 | - '_REG_ID' => array('_REG_ID' => false), |
|
| 176 | - ); |
|
| 177 | - $this->_hidden_columns = array(); |
|
| 178 | - } |
|
| 85 | + /** |
|
| 86 | + * _set_properties |
|
| 87 | + * |
|
| 88 | + * @access protected |
|
| 89 | + * @return void |
|
| 90 | + */ |
|
| 91 | + protected function _set_properties() |
|
| 92 | + { |
|
| 93 | + $this->_wp_list_args = array( |
|
| 94 | + 'singular' => __('registration', 'event_espresso'), |
|
| 95 | + 'plural' => __('registrations', 'event_espresso'), |
|
| 96 | + 'ajax' => true, |
|
| 97 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 98 | + ); |
|
| 99 | + $ID_column_name = __('ID', 'event_espresso'); |
|
| 100 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
| 101 | + $ID_column_name .= __('Registrant Name', 'event_espresso'); |
|
| 102 | + $ID_column_name .= '</span> '; |
|
| 103 | + if (isset($_GET['event_id'])) { |
|
| 104 | + $this->_columns = array( |
|
| 105 | + 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
| 106 | + '_REG_ID' => $ID_column_name, |
|
| 107 | + 'ATT_fname' => __('Name', 'event_espresso'), |
|
| 108 | + 'ATT_email' => __('Email', 'event_espresso'), |
|
| 109 | + '_REG_date' => __('Reg Date', 'event_espresso'), |
|
| 110 | + 'PRC_amount' => __('TKT Price', 'event_espresso'), |
|
| 111 | + '_REG_final_price' => __('Final Price', 'event_espresso'), |
|
| 112 | + 'TXN_total' => __('Total Txn', 'event_espresso'), |
|
| 113 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
| 114 | + 'actions' => __('Actions', 'event_espresso'), |
|
| 115 | + ); |
|
| 116 | + $this->_bottom_buttons = array( |
|
| 117 | + 'report' => array( |
|
| 118 | + 'route' => 'registrations_report', |
|
| 119 | + 'extra_request' => array( |
|
| 120 | + 'EVT_ID' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 121 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 122 | + ), |
|
| 123 | + ), |
|
| 124 | + ); |
|
| 125 | + } else { |
|
| 126 | + $this->_columns = array( |
|
| 127 | + 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
| 128 | + '_REG_ID' => $ID_column_name, |
|
| 129 | + 'ATT_fname' => __('Name', 'event_espresso'), |
|
| 130 | + '_REG_date' => __('TXN Date', 'event_espresso'), |
|
| 131 | + 'event_name' => __('Event', 'event_espresso'), |
|
| 132 | + 'DTT_EVT_start' => __('Event Date', 'event_espresso'), |
|
| 133 | + '_REG_final_price' => __('Price', 'event_espresso'), |
|
| 134 | + '_REG_paid' => __('Paid', 'event_espresso'), |
|
| 135 | + 'actions' => __('Actions', 'event_espresso'), |
|
| 136 | + ); |
|
| 137 | + $this->_bottom_buttons = array( |
|
| 138 | + 'report_all' => array( |
|
| 139 | + 'route' => 'registrations_report', |
|
| 140 | + 'extra_request' => array( |
|
| 141 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 142 | + ), |
|
| 143 | + ), |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | + $this->_bottom_buttons['report_filtered'] = array( |
|
| 147 | + 'route' => 'registrations_report', |
|
| 148 | + 'extra_request' => array( |
|
| 149 | + 'use_filters' => true, |
|
| 150 | + 'filters' => array_diff_key($this->_req_data, array_flip(array( |
|
| 151 | + 'page', |
|
| 152 | + 'action', |
|
| 153 | + 'default_nonce', |
|
| 154 | + ))), |
|
| 155 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 156 | + ), |
|
| 157 | + ); |
|
| 158 | + $this->_primary_column = '_REG_ID'; |
|
| 159 | + $this->_sortable_columns = array( |
|
| 160 | + '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
| 161 | + /** |
|
| 162 | + * Allows users to change the default sort if they wish. |
|
| 163 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last |
|
| 164 | + * name. |
|
| 165 | + */ |
|
| 166 | + 'ATT_fname' => array( |
|
| 167 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
| 168 | + true, |
|
| 169 | + $this, |
|
| 170 | + ) |
|
| 171 | + ? array('ATT_lname' => false) |
|
| 172 | + : array('ATT_fname' => false), |
|
| 173 | + 'event_name' => array('event_name' => false), |
|
| 174 | + 'DTT_EVT_start' => array('DTT_EVT_start' => false), |
|
| 175 | + '_REG_ID' => array('_REG_ID' => false), |
|
| 176 | + ); |
|
| 177 | + $this->_hidden_columns = array(); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * This simply sets up the row class for the table rows. |
|
| 183 | - * Allows for easier overriding of child methods for setting up sorting. |
|
| 184 | - * |
|
| 185 | - * @param EE_Registration $item the current item |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - protected function _get_row_class($item) |
|
| 189 | - { |
|
| 190 | - $class = parent::_get_row_class($item); |
|
| 191 | - //add status class |
|
| 192 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
| 193 | - if ($this->_has_checkbox_column) { |
|
| 194 | - $class .= ' has-checkbox-column'; |
|
| 195 | - } |
|
| 196 | - return $class; |
|
| 197 | - } |
|
| 181 | + /** |
|
| 182 | + * This simply sets up the row class for the table rows. |
|
| 183 | + * Allows for easier overriding of child methods for setting up sorting. |
|
| 184 | + * |
|
| 185 | + * @param EE_Registration $item the current item |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + protected function _get_row_class($item) |
|
| 189 | + { |
|
| 190 | + $class = parent::_get_row_class($item); |
|
| 191 | + //add status class |
|
| 192 | + $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
| 193 | + if ($this->_has_checkbox_column) { |
|
| 194 | + $class .= ' has-checkbox-column'; |
|
| 195 | + } |
|
| 196 | + return $class; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * Set the $_transaction_details property if not set yet. |
|
| 202 | - * |
|
| 203 | - * @param EE_Registration $registration |
|
| 204 | - * @throws EE_Error |
|
| 205 | - * @throws InvalidArgumentException |
|
| 206 | - * @throws ReflectionException |
|
| 207 | - * @throws InvalidDataTypeException |
|
| 208 | - * @throws InvalidInterfaceException |
|
| 209 | - */ |
|
| 210 | - protected function _set_related_details(EE_Registration $registration) |
|
| 211 | - { |
|
| 212 | - $transaction = $registration->get_first_related('Transaction'); |
|
| 213 | - $status = $transaction instanceof EE_Transaction ? $transaction->status_ID() |
|
| 214 | - : EEM_Transaction::failed_status_code; |
|
| 215 | - $this->_transaction_details = array( |
|
| 216 | - 'transaction' => $transaction, |
|
| 217 | - 'status' => $status, |
|
| 218 | - 'id' => $transaction instanceof EE_Transaction ? $transaction->ID() : 0, |
|
| 219 | - 'title_attr' => sprintf( |
|
| 220 | - __('View Transaction Details (%s)', 'event_espresso'), |
|
| 221 | - EEH_Template::pretty_status($status, false, 'sentence') |
|
| 222 | - ), |
|
| 223 | - ); |
|
| 224 | - try { |
|
| 225 | - $event = $registration->event(); |
|
| 226 | - } catch (EntityNotFoundException $e) { |
|
| 227 | - $event = null; |
|
| 228 | - } |
|
| 229 | - $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive; |
|
| 230 | - $this->_event_details = array( |
|
| 231 | - 'event' => $event, |
|
| 232 | - 'status' => $status, |
|
| 233 | - 'id' => $event instanceof EE_Event ? $event->ID() : 0, |
|
| 234 | - 'title_attr' => sprintf( |
|
| 235 | - __('Edit Event (%s)', 'event_espresso'), |
|
| 236 | - EEH_Template::pretty_status($status, false, 'sentence') |
|
| 237 | - ), |
|
| 238 | - ); |
|
| 239 | - } |
|
| 200 | + /** |
|
| 201 | + * Set the $_transaction_details property if not set yet. |
|
| 202 | + * |
|
| 203 | + * @param EE_Registration $registration |
|
| 204 | + * @throws EE_Error |
|
| 205 | + * @throws InvalidArgumentException |
|
| 206 | + * @throws ReflectionException |
|
| 207 | + * @throws InvalidDataTypeException |
|
| 208 | + * @throws InvalidInterfaceException |
|
| 209 | + */ |
|
| 210 | + protected function _set_related_details(EE_Registration $registration) |
|
| 211 | + { |
|
| 212 | + $transaction = $registration->get_first_related('Transaction'); |
|
| 213 | + $status = $transaction instanceof EE_Transaction ? $transaction->status_ID() |
|
| 214 | + : EEM_Transaction::failed_status_code; |
|
| 215 | + $this->_transaction_details = array( |
|
| 216 | + 'transaction' => $transaction, |
|
| 217 | + 'status' => $status, |
|
| 218 | + 'id' => $transaction instanceof EE_Transaction ? $transaction->ID() : 0, |
|
| 219 | + 'title_attr' => sprintf( |
|
| 220 | + __('View Transaction Details (%s)', 'event_espresso'), |
|
| 221 | + EEH_Template::pretty_status($status, false, 'sentence') |
|
| 222 | + ), |
|
| 223 | + ); |
|
| 224 | + try { |
|
| 225 | + $event = $registration->event(); |
|
| 226 | + } catch (EntityNotFoundException $e) { |
|
| 227 | + $event = null; |
|
| 228 | + } |
|
| 229 | + $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive; |
|
| 230 | + $this->_event_details = array( |
|
| 231 | + 'event' => $event, |
|
| 232 | + 'status' => $status, |
|
| 233 | + 'id' => $event instanceof EE_Event ? $event->ID() : 0, |
|
| 234 | + 'title_attr' => sprintf( |
|
| 235 | + __('Edit Event (%s)', 'event_espresso'), |
|
| 236 | + EEH_Template::pretty_status($status, false, 'sentence') |
|
| 237 | + ), |
|
| 238 | + ); |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * _get_table_filters |
|
| 244 | - * |
|
| 245 | - * @access protected |
|
| 246 | - * @return array |
|
| 247 | - */ |
|
| 248 | - protected function _get_table_filters() |
|
| 249 | - { |
|
| 250 | - $filters = array(); |
|
| 251 | - //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as |
|
| 252 | - // methods. |
|
| 253 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 254 | - $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 255 | - $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : ''; |
|
| 256 | - $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category); |
|
| 257 | - $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category); |
|
| 258 | - $status = array(); |
|
| 259 | - $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso')); |
|
| 260 | - foreach ($this->_status as $key => $value) { |
|
| 261 | - $status[] = array('id' => $key, 'text' => $value); |
|
| 262 | - } |
|
| 263 | - if ($this->_view !== 'incomplete') { |
|
| 264 | - $filters[] = EEH_Form_Fields::select_input( |
|
| 265 | - '_reg_status', |
|
| 266 | - $status, |
|
| 267 | - isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status'])) |
|
| 268 | - : '' |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - if (isset($this->_req_data['event_id'])) { |
|
| 272 | - $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id'); |
|
| 273 | - } |
|
| 274 | - return $filters; |
|
| 275 | - } |
|
| 242 | + /** |
|
| 243 | + * _get_table_filters |
|
| 244 | + * |
|
| 245 | + * @access protected |
|
| 246 | + * @return array |
|
| 247 | + */ |
|
| 248 | + protected function _get_table_filters() |
|
| 249 | + { |
|
| 250 | + $filters = array(); |
|
| 251 | + //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as |
|
| 252 | + // methods. |
|
| 253 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 254 | + $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 255 | + $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : ''; |
|
| 256 | + $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category); |
|
| 257 | + $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category); |
|
| 258 | + $status = array(); |
|
| 259 | + $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso')); |
|
| 260 | + foreach ($this->_status as $key => $value) { |
|
| 261 | + $status[] = array('id' => $key, 'text' => $value); |
|
| 262 | + } |
|
| 263 | + if ($this->_view !== 'incomplete') { |
|
| 264 | + $filters[] = EEH_Form_Fields::select_input( |
|
| 265 | + '_reg_status', |
|
| 266 | + $status, |
|
| 267 | + isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status'])) |
|
| 268 | + : '' |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + if (isset($this->_req_data['event_id'])) { |
|
| 272 | + $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id'); |
|
| 273 | + } |
|
| 274 | + return $filters; |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * _add_view_counts |
|
| 280 | - * |
|
| 281 | - * @access protected |
|
| 282 | - * @return void |
|
| 283 | - * @throws EE_Error |
|
| 284 | - * @throws InvalidArgumentException |
|
| 285 | - * @throws InvalidDataTypeException |
|
| 286 | - * @throws InvalidInterfaceException |
|
| 287 | - */ |
|
| 288 | - protected function _add_view_counts() |
|
| 289 | - { |
|
| 290 | - $this->_views['all']['count'] = $this->_total_registrations(); |
|
| 291 | - $this->_views['month']['count'] = $this->_total_registrations_this_month(); |
|
| 292 | - $this->_views['today']['count'] = $this->_total_registrations_today(); |
|
| 293 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 294 | - 'ee_delete_registrations', |
|
| 295 | - 'espresso_registrations_trash_registrations' |
|
| 296 | - )) { |
|
| 297 | - $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete'); |
|
| 298 | - $this->_views['trash']['count'] = $this->_total_registrations('trash'); |
|
| 299 | - } |
|
| 300 | - } |
|
| 278 | + /** |
|
| 279 | + * _add_view_counts |
|
| 280 | + * |
|
| 281 | + * @access protected |
|
| 282 | + * @return void |
|
| 283 | + * @throws EE_Error |
|
| 284 | + * @throws InvalidArgumentException |
|
| 285 | + * @throws InvalidDataTypeException |
|
| 286 | + * @throws InvalidInterfaceException |
|
| 287 | + */ |
|
| 288 | + protected function _add_view_counts() |
|
| 289 | + { |
|
| 290 | + $this->_views['all']['count'] = $this->_total_registrations(); |
|
| 291 | + $this->_views['month']['count'] = $this->_total_registrations_this_month(); |
|
| 292 | + $this->_views['today']['count'] = $this->_total_registrations_today(); |
|
| 293 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 294 | + 'ee_delete_registrations', |
|
| 295 | + 'espresso_registrations_trash_registrations' |
|
| 296 | + )) { |
|
| 297 | + $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete'); |
|
| 298 | + $this->_views['trash']['count'] = $this->_total_registrations('trash'); |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | 302 | |
| 303 | - /** |
|
| 304 | - * _total_registrations |
|
| 305 | - * |
|
| 306 | - * @access protected |
|
| 307 | - * @param string $view |
|
| 308 | - * @return int |
|
| 309 | - * @throws EE_Error |
|
| 310 | - * @throws InvalidArgumentException |
|
| 311 | - * @throws InvalidDataTypeException |
|
| 312 | - * @throws InvalidInterfaceException |
|
| 313 | - */ |
|
| 314 | - protected function _total_registrations($view = '') |
|
| 315 | - { |
|
| 316 | - $_where = array(); |
|
| 317 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 318 | - if ($EVT_ID) { |
|
| 319 | - $_where['EVT_ID'] = $EVT_ID; |
|
| 320 | - } |
|
| 321 | - switch ($view) { |
|
| 322 | - case 'trash': |
|
| 323 | - return EEM_Registration::instance()->count_deleted(array($_where)); |
|
| 324 | - break; |
|
| 325 | - case 'incomplete': |
|
| 326 | - $_where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 327 | - break; |
|
| 328 | - default: |
|
| 329 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 330 | - } |
|
| 331 | - return EEM_Registration::instance()->count(array($_where)); |
|
| 332 | - } |
|
| 303 | + /** |
|
| 304 | + * _total_registrations |
|
| 305 | + * |
|
| 306 | + * @access protected |
|
| 307 | + * @param string $view |
|
| 308 | + * @return int |
|
| 309 | + * @throws EE_Error |
|
| 310 | + * @throws InvalidArgumentException |
|
| 311 | + * @throws InvalidDataTypeException |
|
| 312 | + * @throws InvalidInterfaceException |
|
| 313 | + */ |
|
| 314 | + protected function _total_registrations($view = '') |
|
| 315 | + { |
|
| 316 | + $_where = array(); |
|
| 317 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 318 | + if ($EVT_ID) { |
|
| 319 | + $_where['EVT_ID'] = $EVT_ID; |
|
| 320 | + } |
|
| 321 | + switch ($view) { |
|
| 322 | + case 'trash': |
|
| 323 | + return EEM_Registration::instance()->count_deleted(array($_where)); |
|
| 324 | + break; |
|
| 325 | + case 'incomplete': |
|
| 326 | + $_where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 327 | + break; |
|
| 328 | + default: |
|
| 329 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 330 | + } |
|
| 331 | + return EEM_Registration::instance()->count(array($_where)); |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | 334 | |
| 335 | - /** |
|
| 336 | - * _total_registrations_this_month |
|
| 337 | - * |
|
| 338 | - * @access protected |
|
| 339 | - * @return int |
|
| 340 | - * @throws EE_Error |
|
| 341 | - * @throws InvalidArgumentException |
|
| 342 | - * @throws InvalidDataTypeException |
|
| 343 | - * @throws InvalidInterfaceException |
|
| 344 | - */ |
|
| 345 | - protected function _total_registrations_this_month() |
|
| 346 | - { |
|
| 347 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 348 | - $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
| 349 | - $this_year_r = date('Y', current_time('timestamp')); |
|
| 350 | - $time_start = ' 00:00:00'; |
|
| 351 | - $time_end = ' 23:59:59'; |
|
| 352 | - $this_month_r = date('m', current_time('timestamp')); |
|
| 353 | - $days_this_month = date('t', current_time('timestamp')); |
|
| 354 | - //setup date query. |
|
| 355 | - $beginning_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
| 356 | - 'REG_date', |
|
| 357 | - $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
| 358 | - 'Y-m-d H:i:s' |
|
| 359 | - ); |
|
| 360 | - $end_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
| 361 | - 'REG_date', |
|
| 362 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
| 363 | - 'Y-m-d H:i:s' |
|
| 364 | - ); |
|
| 365 | - $_where['REG_date'] = array( |
|
| 366 | - 'BETWEEN', |
|
| 367 | - array( |
|
| 368 | - $beginning_string, |
|
| 369 | - $end_string, |
|
| 370 | - ), |
|
| 371 | - ); |
|
| 372 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 373 | - return EEM_Registration::instance()->count(array($_where)); |
|
| 374 | - } |
|
| 335 | + /** |
|
| 336 | + * _total_registrations_this_month |
|
| 337 | + * |
|
| 338 | + * @access protected |
|
| 339 | + * @return int |
|
| 340 | + * @throws EE_Error |
|
| 341 | + * @throws InvalidArgumentException |
|
| 342 | + * @throws InvalidDataTypeException |
|
| 343 | + * @throws InvalidInterfaceException |
|
| 344 | + */ |
|
| 345 | + protected function _total_registrations_this_month() |
|
| 346 | + { |
|
| 347 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 348 | + $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
| 349 | + $this_year_r = date('Y', current_time('timestamp')); |
|
| 350 | + $time_start = ' 00:00:00'; |
|
| 351 | + $time_end = ' 23:59:59'; |
|
| 352 | + $this_month_r = date('m', current_time('timestamp')); |
|
| 353 | + $days_this_month = date('t', current_time('timestamp')); |
|
| 354 | + //setup date query. |
|
| 355 | + $beginning_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
| 356 | + 'REG_date', |
|
| 357 | + $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
| 358 | + 'Y-m-d H:i:s' |
|
| 359 | + ); |
|
| 360 | + $end_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
| 361 | + 'REG_date', |
|
| 362 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
| 363 | + 'Y-m-d H:i:s' |
|
| 364 | + ); |
|
| 365 | + $_where['REG_date'] = array( |
|
| 366 | + 'BETWEEN', |
|
| 367 | + array( |
|
| 368 | + $beginning_string, |
|
| 369 | + $end_string, |
|
| 370 | + ), |
|
| 371 | + ); |
|
| 372 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 373 | + return EEM_Registration::instance()->count(array($_where)); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | 376 | |
| 377 | - /** |
|
| 378 | - * _total_registrations_today |
|
| 379 | - * |
|
| 380 | - * @access protected |
|
| 381 | - * @return int |
|
| 382 | - * @throws EE_Error |
|
| 383 | - * @throws InvalidArgumentException |
|
| 384 | - * @throws InvalidDataTypeException |
|
| 385 | - * @throws InvalidInterfaceException |
|
| 386 | - */ |
|
| 387 | - protected function _total_registrations_today() |
|
| 388 | - { |
|
| 389 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 390 | - $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
| 391 | - $current_date = date('Y-m-d', current_time('timestamp')); |
|
| 392 | - $time_start = ' 00:00:00'; |
|
| 393 | - $time_end = ' 23:59:59'; |
|
| 394 | - $_where['REG_date'] = array( |
|
| 395 | - 'BETWEEN', |
|
| 396 | - array( |
|
| 397 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 398 | - 'REG_date', |
|
| 399 | - $current_date . $time_start, |
|
| 400 | - 'Y-m-d H:i:s' |
|
| 401 | - ), |
|
| 402 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 403 | - 'REG_date', |
|
| 404 | - $current_date . $time_end, |
|
| 405 | - 'Y-m-d H:i:s' |
|
| 406 | - ), |
|
| 407 | - ), |
|
| 408 | - ); |
|
| 409 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 410 | - return EEM_Registration::instance()->count(array($_where)); |
|
| 411 | - } |
|
| 377 | + /** |
|
| 378 | + * _total_registrations_today |
|
| 379 | + * |
|
| 380 | + * @access protected |
|
| 381 | + * @return int |
|
| 382 | + * @throws EE_Error |
|
| 383 | + * @throws InvalidArgumentException |
|
| 384 | + * @throws InvalidDataTypeException |
|
| 385 | + * @throws InvalidInterfaceException |
|
| 386 | + */ |
|
| 387 | + protected function _total_registrations_today() |
|
| 388 | + { |
|
| 389 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 390 | + $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
| 391 | + $current_date = date('Y-m-d', current_time('timestamp')); |
|
| 392 | + $time_start = ' 00:00:00'; |
|
| 393 | + $time_end = ' 23:59:59'; |
|
| 394 | + $_where['REG_date'] = array( |
|
| 395 | + 'BETWEEN', |
|
| 396 | + array( |
|
| 397 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 398 | + 'REG_date', |
|
| 399 | + $current_date . $time_start, |
|
| 400 | + 'Y-m-d H:i:s' |
|
| 401 | + ), |
|
| 402 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 403 | + 'REG_date', |
|
| 404 | + $current_date . $time_end, |
|
| 405 | + 'Y-m-d H:i:s' |
|
| 406 | + ), |
|
| 407 | + ), |
|
| 408 | + ); |
|
| 409 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 410 | + return EEM_Registration::instance()->count(array($_where)); |
|
| 411 | + } |
|
| 412 | 412 | |
| 413 | 413 | |
| 414 | - /** |
|
| 415 | - * column_cb |
|
| 416 | - * |
|
| 417 | - * @access public |
|
| 418 | - * @param \EE_Registration $item |
|
| 419 | - * @return string |
|
| 420 | - * @throws EE_Error |
|
| 421 | - * @throws InvalidArgumentException |
|
| 422 | - * @throws InvalidDataTypeException |
|
| 423 | - * @throws InvalidInterfaceException |
|
| 424 | - * @throws ReflectionException |
|
| 425 | - */ |
|
| 426 | - public function column_cb($item) |
|
| 427 | - { |
|
| 428 | - /** checkbox/lock **/ |
|
| 429 | - $transaction = $item->get_first_related('Transaction'); |
|
| 430 | - $payment_count = $transaction instanceof EE_Transaction |
|
| 431 | - ? $transaction->count_related('Payment') |
|
| 432 | - : 0; |
|
| 433 | - return $payment_count > 0 |
|
| 434 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 435 | - 'ee_edit_registration', |
|
| 436 | - 'registration_list_table_checkbox_input', |
|
| 437 | - $item->ID() |
|
| 438 | - ) |
|
| 439 | - ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()) |
|
| 440 | - . '<span class="ee-lock-icon"></span>' |
|
| 441 | - : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()); |
|
| 442 | - } |
|
| 414 | + /** |
|
| 415 | + * column_cb |
|
| 416 | + * |
|
| 417 | + * @access public |
|
| 418 | + * @param \EE_Registration $item |
|
| 419 | + * @return string |
|
| 420 | + * @throws EE_Error |
|
| 421 | + * @throws InvalidArgumentException |
|
| 422 | + * @throws InvalidDataTypeException |
|
| 423 | + * @throws InvalidInterfaceException |
|
| 424 | + * @throws ReflectionException |
|
| 425 | + */ |
|
| 426 | + public function column_cb($item) |
|
| 427 | + { |
|
| 428 | + /** checkbox/lock **/ |
|
| 429 | + $transaction = $item->get_first_related('Transaction'); |
|
| 430 | + $payment_count = $transaction instanceof EE_Transaction |
|
| 431 | + ? $transaction->count_related('Payment') |
|
| 432 | + : 0; |
|
| 433 | + return $payment_count > 0 |
|
| 434 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 435 | + 'ee_edit_registration', |
|
| 436 | + 'registration_list_table_checkbox_input', |
|
| 437 | + $item->ID() |
|
| 438 | + ) |
|
| 439 | + ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()) |
|
| 440 | + . '<span class="ee-lock-icon"></span>' |
|
| 441 | + : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()); |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | 444 | |
| 445 | - /** |
|
| 446 | - * column__REG_ID |
|
| 447 | - * |
|
| 448 | - * @access public |
|
| 449 | - * @param \EE_Registration $item |
|
| 450 | - * @return string |
|
| 451 | - * @throws EE_Error |
|
| 452 | - * @throws InvalidArgumentException |
|
| 453 | - * @throws InvalidDataTypeException |
|
| 454 | - * @throws InvalidInterfaceException |
|
| 455 | - * @throws ReflectionException |
|
| 456 | - */ |
|
| 457 | - public function column__REG_ID(EE_Registration $item) |
|
| 458 | - { |
|
| 459 | - $attendee = $item->attendee(); |
|
| 460 | - $content = $item->ID(); |
|
| 461 | - $content .= '<div class="show-on-mobile-view-only">'; |
|
| 462 | - $content .= '<br>'; |
|
| 463 | - $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 464 | - $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 465 | - $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 466 | - $content .= '</div>'; |
|
| 467 | - return $content; |
|
| 468 | - } |
|
| 445 | + /** |
|
| 446 | + * column__REG_ID |
|
| 447 | + * |
|
| 448 | + * @access public |
|
| 449 | + * @param \EE_Registration $item |
|
| 450 | + * @return string |
|
| 451 | + * @throws EE_Error |
|
| 452 | + * @throws InvalidArgumentException |
|
| 453 | + * @throws InvalidDataTypeException |
|
| 454 | + * @throws InvalidInterfaceException |
|
| 455 | + * @throws ReflectionException |
|
| 456 | + */ |
|
| 457 | + public function column__REG_ID(EE_Registration $item) |
|
| 458 | + { |
|
| 459 | + $attendee = $item->attendee(); |
|
| 460 | + $content = $item->ID(); |
|
| 461 | + $content .= '<div class="show-on-mobile-view-only">'; |
|
| 462 | + $content .= '<br>'; |
|
| 463 | + $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 464 | + $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 465 | + $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 466 | + $content .= '</div>'; |
|
| 467 | + return $content; |
|
| 468 | + } |
|
| 469 | 469 | |
| 470 | 470 | |
| 471 | - /** |
|
| 472 | - * column__REG_date |
|
| 473 | - * |
|
| 474 | - * @access public |
|
| 475 | - * @param \EE_Registration $item |
|
| 476 | - * @return string |
|
| 477 | - * @throws EE_Error |
|
| 478 | - * @throws InvalidArgumentException |
|
| 479 | - * @throws InvalidDataTypeException |
|
| 480 | - * @throws InvalidInterfaceException |
|
| 481 | - * @throws ReflectionException |
|
| 482 | - */ |
|
| 483 | - public function column__REG_date(EE_Registration $item) |
|
| 484 | - { |
|
| 485 | - $this->_set_related_details($item); |
|
| 486 | - //Build row actions |
|
| 487 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 488 | - 'action' => 'view_transaction', |
|
| 489 | - 'TXN_ID' => $this->_transaction_details['id'], |
|
| 490 | - ), TXN_ADMIN_URL); |
|
| 491 | - $view_link = EE_Registry::instance()->CAP->current_user_can( |
|
| 492 | - 'ee_read_transaction', |
|
| 493 | - 'espresso_transactions_view_transaction' |
|
| 494 | - ) |
|
| 495 | - ? '<a class="ee-status-color-' |
|
| 496 | - . $this->_transaction_details['status'] |
|
| 497 | - . '" href="' |
|
| 498 | - . $view_lnk_url |
|
| 499 | - . '" title="' |
|
| 500 | - . esc_attr($this->_transaction_details['title_attr']) |
|
| 501 | - . '">' |
|
| 502 | - . $item->get_i18n_datetime('REG_date') |
|
| 503 | - . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
| 504 | - $view_link .= '<br><span class="ee-status-text-small">' |
|
| 505 | - . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence') |
|
| 506 | - . '</span>'; |
|
| 507 | - return $view_link; |
|
| 508 | - } |
|
| 471 | + /** |
|
| 472 | + * column__REG_date |
|
| 473 | + * |
|
| 474 | + * @access public |
|
| 475 | + * @param \EE_Registration $item |
|
| 476 | + * @return string |
|
| 477 | + * @throws EE_Error |
|
| 478 | + * @throws InvalidArgumentException |
|
| 479 | + * @throws InvalidDataTypeException |
|
| 480 | + * @throws InvalidInterfaceException |
|
| 481 | + * @throws ReflectionException |
|
| 482 | + */ |
|
| 483 | + public function column__REG_date(EE_Registration $item) |
|
| 484 | + { |
|
| 485 | + $this->_set_related_details($item); |
|
| 486 | + //Build row actions |
|
| 487 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 488 | + 'action' => 'view_transaction', |
|
| 489 | + 'TXN_ID' => $this->_transaction_details['id'], |
|
| 490 | + ), TXN_ADMIN_URL); |
|
| 491 | + $view_link = EE_Registry::instance()->CAP->current_user_can( |
|
| 492 | + 'ee_read_transaction', |
|
| 493 | + 'espresso_transactions_view_transaction' |
|
| 494 | + ) |
|
| 495 | + ? '<a class="ee-status-color-' |
|
| 496 | + . $this->_transaction_details['status'] |
|
| 497 | + . '" href="' |
|
| 498 | + . $view_lnk_url |
|
| 499 | + . '" title="' |
|
| 500 | + . esc_attr($this->_transaction_details['title_attr']) |
|
| 501 | + . '">' |
|
| 502 | + . $item->get_i18n_datetime('REG_date') |
|
| 503 | + . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
| 504 | + $view_link .= '<br><span class="ee-status-text-small">' |
|
| 505 | + . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence') |
|
| 506 | + . '</span>'; |
|
| 507 | + return $view_link; |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | 510 | |
| 511 | - /** |
|
| 512 | - * column_event_name |
|
| 513 | - * |
|
| 514 | - * @access public |
|
| 515 | - * @param \EE_Registration $item |
|
| 516 | - * @return string |
|
| 517 | - * @throws EE_Error |
|
| 518 | - * @throws InvalidArgumentException |
|
| 519 | - * @throws InvalidDataTypeException |
|
| 520 | - * @throws InvalidInterfaceException |
|
| 521 | - * @throws ReflectionException |
|
| 522 | - */ |
|
| 523 | - public function column_event_name(EE_Registration $item) |
|
| 524 | - { |
|
| 525 | - $this->_set_related_details($item); |
|
| 526 | - // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62 |
|
| 527 | - $EVT_ID = $item->event_ID(); |
|
| 528 | - $event_name = $item->event_name(); |
|
| 529 | - $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso'); |
|
| 530 | - $event_name = wp_trim_words($event_name, 30, '...'); |
|
| 531 | - if ($EVT_ID) { |
|
| 532 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 533 | - array('action' => 'edit', 'post' => $EVT_ID), |
|
| 534 | - EVENTS_ADMIN_URL |
|
| 535 | - ); |
|
| 536 | - $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID) |
|
| 537 | - ? '<a class="ee-status-color-' |
|
| 538 | - . $this->_event_details['status'] |
|
| 539 | - . '" href="' |
|
| 540 | - . $edit_event_url |
|
| 541 | - . '" title="' |
|
| 542 | - . esc_attr($this->_event_details['title_attr']) |
|
| 543 | - . '">' |
|
| 544 | - . $event_name |
|
| 545 | - . '</a>' : $event_name; |
|
| 546 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
|
| 547 | - $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
| 548 | - $actions['event_filter'] .= sprintf( |
|
| 549 | - esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'), |
|
| 550 | - $event_name |
|
| 551 | - ); |
|
| 552 | - $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
| 553 | - } else { |
|
| 554 | - $edit_event = $event_name; |
|
| 555 | - $actions['event_filter'] = ''; |
|
| 556 | - } |
|
| 557 | - return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions)); |
|
| 558 | - } |
|
| 511 | + /** |
|
| 512 | + * column_event_name |
|
| 513 | + * |
|
| 514 | + * @access public |
|
| 515 | + * @param \EE_Registration $item |
|
| 516 | + * @return string |
|
| 517 | + * @throws EE_Error |
|
| 518 | + * @throws InvalidArgumentException |
|
| 519 | + * @throws InvalidDataTypeException |
|
| 520 | + * @throws InvalidInterfaceException |
|
| 521 | + * @throws ReflectionException |
|
| 522 | + */ |
|
| 523 | + public function column_event_name(EE_Registration $item) |
|
| 524 | + { |
|
| 525 | + $this->_set_related_details($item); |
|
| 526 | + // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62 |
|
| 527 | + $EVT_ID = $item->event_ID(); |
|
| 528 | + $event_name = $item->event_name(); |
|
| 529 | + $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso'); |
|
| 530 | + $event_name = wp_trim_words($event_name, 30, '...'); |
|
| 531 | + if ($EVT_ID) { |
|
| 532 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 533 | + array('action' => 'edit', 'post' => $EVT_ID), |
|
| 534 | + EVENTS_ADMIN_URL |
|
| 535 | + ); |
|
| 536 | + $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID) |
|
| 537 | + ? '<a class="ee-status-color-' |
|
| 538 | + . $this->_event_details['status'] |
|
| 539 | + . '" href="' |
|
| 540 | + . $edit_event_url |
|
| 541 | + . '" title="' |
|
| 542 | + . esc_attr($this->_event_details['title_attr']) |
|
| 543 | + . '">' |
|
| 544 | + . $event_name |
|
| 545 | + . '</a>' : $event_name; |
|
| 546 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
|
| 547 | + $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
| 548 | + $actions['event_filter'] .= sprintf( |
|
| 549 | + esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'), |
|
| 550 | + $event_name |
|
| 551 | + ); |
|
| 552 | + $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
| 553 | + } else { |
|
| 554 | + $edit_event = $event_name; |
|
| 555 | + $actions['event_filter'] = ''; |
|
| 556 | + } |
|
| 557 | + return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions)); |
|
| 558 | + } |
|
| 559 | 559 | |
| 560 | 560 | |
| 561 | - /** |
|
| 562 | - * column_DTT_EVT_start |
|
| 563 | - * |
|
| 564 | - * @access public |
|
| 565 | - * @param \EE_Registration $item |
|
| 566 | - * @return string |
|
| 567 | - * @throws EE_Error |
|
| 568 | - * @throws InvalidArgumentException |
|
| 569 | - * @throws InvalidDataTypeException |
|
| 570 | - * @throws InvalidInterfaceException |
|
| 571 | - * @throws ReflectionException |
|
| 572 | - */ |
|
| 573 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
| 574 | - { |
|
| 575 | - $datetime_strings = array(); |
|
| 576 | - $ticket = $item->ticket(true); |
|
| 577 | - if ($ticket instanceof EE_Ticket) { |
|
| 578 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 579 | - $datetimes = $ticket->datetimes($remove_defaults); |
|
| 580 | - foreach ($datetimes as $datetime) { |
|
| 581 | - $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 582 | - } |
|
| 583 | - return $this->generateDisplayForDatetimes($datetime_strings); |
|
| 584 | - } |
|
| 585 | - return __('There is no ticket on this registration', 'event_espresso'); |
|
| 586 | - } |
|
| 561 | + /** |
|
| 562 | + * column_DTT_EVT_start |
|
| 563 | + * |
|
| 564 | + * @access public |
|
| 565 | + * @param \EE_Registration $item |
|
| 566 | + * @return string |
|
| 567 | + * @throws EE_Error |
|
| 568 | + * @throws InvalidArgumentException |
|
| 569 | + * @throws InvalidDataTypeException |
|
| 570 | + * @throws InvalidInterfaceException |
|
| 571 | + * @throws ReflectionException |
|
| 572 | + */ |
|
| 573 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
| 574 | + { |
|
| 575 | + $datetime_strings = array(); |
|
| 576 | + $ticket = $item->ticket(true); |
|
| 577 | + if ($ticket instanceof EE_Ticket) { |
|
| 578 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 579 | + $datetimes = $ticket->datetimes($remove_defaults); |
|
| 580 | + foreach ($datetimes as $datetime) { |
|
| 581 | + $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 582 | + } |
|
| 583 | + return $this->generateDisplayForDatetimes($datetime_strings); |
|
| 584 | + } |
|
| 585 | + return __('There is no ticket on this registration', 'event_espresso'); |
|
| 586 | + } |
|
| 587 | 587 | |
| 588 | 588 | |
| 589 | - /** |
|
| 590 | - * Receives an array of datetime strings to display and converts them to the html container for the column. |
|
| 591 | - * |
|
| 592 | - * @param array $datetime_strings |
|
| 593 | - * @return string |
|
| 594 | - */ |
|
| 595 | - public function generateDisplayForDateTimes(array $datetime_strings) |
|
| 596 | - { |
|
| 597 | - $content = '<div class="ee-registration-event-datetimes-container">'; |
|
| 598 | - $expand_toggle = count($datetime_strings) > 1 |
|
| 599 | - ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso') |
|
| 600 | - . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>' |
|
| 601 | - : ''; |
|
| 602 | - //get first item for initial visibility |
|
| 603 | - $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>'; |
|
| 604 | - $content .= $expand_toggle; |
|
| 605 | - if ($datetime_strings) { |
|
| 606 | - $content .= '<div style="clear:both"></div>'; |
|
| 607 | - $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">'; |
|
| 608 | - $content .= implode("<br />", $datetime_strings); |
|
| 609 | - $content .= '</div>'; |
|
| 610 | - } |
|
| 611 | - $content .= '</div>'; |
|
| 612 | - return $content; |
|
| 613 | - } |
|
| 589 | + /** |
|
| 590 | + * Receives an array of datetime strings to display and converts them to the html container for the column. |
|
| 591 | + * |
|
| 592 | + * @param array $datetime_strings |
|
| 593 | + * @return string |
|
| 594 | + */ |
|
| 595 | + public function generateDisplayForDateTimes(array $datetime_strings) |
|
| 596 | + { |
|
| 597 | + $content = '<div class="ee-registration-event-datetimes-container">'; |
|
| 598 | + $expand_toggle = count($datetime_strings) > 1 |
|
| 599 | + ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso') |
|
| 600 | + . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>' |
|
| 601 | + : ''; |
|
| 602 | + //get first item for initial visibility |
|
| 603 | + $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>'; |
|
| 604 | + $content .= $expand_toggle; |
|
| 605 | + if ($datetime_strings) { |
|
| 606 | + $content .= '<div style="clear:both"></div>'; |
|
| 607 | + $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">'; |
|
| 608 | + $content .= implode("<br />", $datetime_strings); |
|
| 609 | + $content .= '</div>'; |
|
| 610 | + } |
|
| 611 | + $content .= '</div>'; |
|
| 612 | + return $content; |
|
| 613 | + } |
|
| 614 | 614 | |
| 615 | 615 | |
| 616 | - /** |
|
| 617 | - * column_ATT_fname |
|
| 618 | - * |
|
| 619 | - * @access public |
|
| 620 | - * @param \EE_Registration $item |
|
| 621 | - * @return string |
|
| 622 | - * @throws EE_Error |
|
| 623 | - * @throws InvalidArgumentException |
|
| 624 | - * @throws InvalidDataTypeException |
|
| 625 | - * @throws InvalidInterfaceException |
|
| 626 | - * @throws ReflectionException |
|
| 627 | - */ |
|
| 628 | - public function column_ATT_fname(EE_Registration $item) |
|
| 629 | - { |
|
| 630 | - $attendee = $item->attendee(); |
|
| 631 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 632 | - 'action' => 'view_registration', |
|
| 633 | - '_REG_ID' => $item->ID(), |
|
| 634 | - ), REG_ADMIN_URL); |
|
| 635 | - $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 636 | - $link = EE_Registry::instance()->CAP->current_user_can( |
|
| 637 | - 'ee_read_registration', |
|
| 638 | - 'espresso_registrations_view_registration', |
|
| 639 | - $item->ID() |
|
| 640 | - ) |
|
| 641 | - ? '<a href="' |
|
| 642 | - . $edit_lnk_url |
|
| 643 | - . '" title="' |
|
| 644 | - . esc_attr__('View Registration Details', 'event_espresso') |
|
| 645 | - . '">' |
|
| 646 | - . $attendee_name |
|
| 647 | - . '</a>' : $attendee_name; |
|
| 648 | - $link .= $item->count() === 1 |
|
| 649 | - ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : ''; |
|
| 650 | - $t = $item->get_first_related('Transaction'); |
|
| 651 | - $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
|
| 652 | - //append group count to name |
|
| 653 | - $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 654 | - //append reg_code |
|
| 655 | - $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 656 | - //reg status text for accessibility |
|
| 657 | - $link .= '<br><span class="ee-status-text-small">' |
|
| 658 | - . EEH_Template::pretty_status($item->status_ID(), false, 'sentence') |
|
| 659 | - . '</span>'; |
|
| 660 | - //trash/restore/delete actions |
|
| 661 | - $actions = array(); |
|
| 662 | - if ($this->_view !== 'trash' |
|
| 663 | - && $payment_count === 0 |
|
| 664 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 665 | - 'ee_delete_registration', |
|
| 666 | - 'espresso_registrations_trash_registrations', |
|
| 667 | - $item->ID() |
|
| 668 | - )) { |
|
| 669 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 670 | - 'action' => 'trash_registrations', |
|
| 671 | - '_REG_ID' => $item->ID(), |
|
| 672 | - ), REG_ADMIN_URL); |
|
| 673 | - $actions['trash'] = '<a href="' |
|
| 674 | - . $trash_lnk_url |
|
| 675 | - . '" title="' |
|
| 676 | - . esc_attr__('Trash Registration', 'event_espresso') |
|
| 677 | - . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
| 678 | - } elseif ($this->_view === 'trash') { |
|
| 679 | - // restore registration link |
|
| 680 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 681 | - 'ee_delete_registration', |
|
| 682 | - 'espresso_registrations_restore_registrations', |
|
| 683 | - $item->ID() |
|
| 684 | - )) { |
|
| 685 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 686 | - 'action' => 'restore_registrations', |
|
| 687 | - '_REG_ID' => $item->ID(), |
|
| 688 | - ), REG_ADMIN_URL); |
|
| 689 | - $actions['restore'] = '<a href="' |
|
| 690 | - . $restore_lnk_url |
|
| 691 | - . '" title="' |
|
| 692 | - . esc_attr__('Restore Registration', 'event_espresso') . '">' |
|
| 693 | - . __('Restore', 'event_espresso') . '</a>'; |
|
| 694 | - } |
|
| 695 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 696 | - 'ee_delete_registration', |
|
| 697 | - 'espresso_registrations_ee_delete_registrations', |
|
| 698 | - $item->ID() |
|
| 699 | - )) { |
|
| 700 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 701 | - 'action' => 'delete_registrations', |
|
| 702 | - '_REG_ID' => $item->ID(), |
|
| 703 | - ), REG_ADMIN_URL); |
|
| 704 | - $actions['delete'] = '<a href="' |
|
| 705 | - . $delete_lnk_url |
|
| 706 | - . '" title="' |
|
| 707 | - . esc_attr__('Delete Registration Permanently', 'event_espresso') |
|
| 708 | - . '">' |
|
| 709 | - . __('Delete', 'event_espresso') |
|
| 710 | - . '</a>'; |
|
| 711 | - } |
|
| 712 | - } |
|
| 713 | - return sprintf('%1$s %2$s', $link, $this->row_actions($actions)); |
|
| 714 | - } |
|
| 616 | + /** |
|
| 617 | + * column_ATT_fname |
|
| 618 | + * |
|
| 619 | + * @access public |
|
| 620 | + * @param \EE_Registration $item |
|
| 621 | + * @return string |
|
| 622 | + * @throws EE_Error |
|
| 623 | + * @throws InvalidArgumentException |
|
| 624 | + * @throws InvalidDataTypeException |
|
| 625 | + * @throws InvalidInterfaceException |
|
| 626 | + * @throws ReflectionException |
|
| 627 | + */ |
|
| 628 | + public function column_ATT_fname(EE_Registration $item) |
|
| 629 | + { |
|
| 630 | + $attendee = $item->attendee(); |
|
| 631 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 632 | + 'action' => 'view_registration', |
|
| 633 | + '_REG_ID' => $item->ID(), |
|
| 634 | + ), REG_ADMIN_URL); |
|
| 635 | + $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 636 | + $link = EE_Registry::instance()->CAP->current_user_can( |
|
| 637 | + 'ee_read_registration', |
|
| 638 | + 'espresso_registrations_view_registration', |
|
| 639 | + $item->ID() |
|
| 640 | + ) |
|
| 641 | + ? '<a href="' |
|
| 642 | + . $edit_lnk_url |
|
| 643 | + . '" title="' |
|
| 644 | + . esc_attr__('View Registration Details', 'event_espresso') |
|
| 645 | + . '">' |
|
| 646 | + . $attendee_name |
|
| 647 | + . '</a>' : $attendee_name; |
|
| 648 | + $link .= $item->count() === 1 |
|
| 649 | + ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : ''; |
|
| 650 | + $t = $item->get_first_related('Transaction'); |
|
| 651 | + $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
|
| 652 | + //append group count to name |
|
| 653 | + $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 654 | + //append reg_code |
|
| 655 | + $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 656 | + //reg status text for accessibility |
|
| 657 | + $link .= '<br><span class="ee-status-text-small">' |
|
| 658 | + . EEH_Template::pretty_status($item->status_ID(), false, 'sentence') |
|
| 659 | + . '</span>'; |
|
| 660 | + //trash/restore/delete actions |
|
| 661 | + $actions = array(); |
|
| 662 | + if ($this->_view !== 'trash' |
|
| 663 | + && $payment_count === 0 |
|
| 664 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 665 | + 'ee_delete_registration', |
|
| 666 | + 'espresso_registrations_trash_registrations', |
|
| 667 | + $item->ID() |
|
| 668 | + )) { |
|
| 669 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 670 | + 'action' => 'trash_registrations', |
|
| 671 | + '_REG_ID' => $item->ID(), |
|
| 672 | + ), REG_ADMIN_URL); |
|
| 673 | + $actions['trash'] = '<a href="' |
|
| 674 | + . $trash_lnk_url |
|
| 675 | + . '" title="' |
|
| 676 | + . esc_attr__('Trash Registration', 'event_espresso') |
|
| 677 | + . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
| 678 | + } elseif ($this->_view === 'trash') { |
|
| 679 | + // restore registration link |
|
| 680 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 681 | + 'ee_delete_registration', |
|
| 682 | + 'espresso_registrations_restore_registrations', |
|
| 683 | + $item->ID() |
|
| 684 | + )) { |
|
| 685 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 686 | + 'action' => 'restore_registrations', |
|
| 687 | + '_REG_ID' => $item->ID(), |
|
| 688 | + ), REG_ADMIN_URL); |
|
| 689 | + $actions['restore'] = '<a href="' |
|
| 690 | + . $restore_lnk_url |
|
| 691 | + . '" title="' |
|
| 692 | + . esc_attr__('Restore Registration', 'event_espresso') . '">' |
|
| 693 | + . __('Restore', 'event_espresso') . '</a>'; |
|
| 694 | + } |
|
| 695 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 696 | + 'ee_delete_registration', |
|
| 697 | + 'espresso_registrations_ee_delete_registrations', |
|
| 698 | + $item->ID() |
|
| 699 | + )) { |
|
| 700 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 701 | + 'action' => 'delete_registrations', |
|
| 702 | + '_REG_ID' => $item->ID(), |
|
| 703 | + ), REG_ADMIN_URL); |
|
| 704 | + $actions['delete'] = '<a href="' |
|
| 705 | + . $delete_lnk_url |
|
| 706 | + . '" title="' |
|
| 707 | + . esc_attr__('Delete Registration Permanently', 'event_espresso') |
|
| 708 | + . '">' |
|
| 709 | + . __('Delete', 'event_espresso') |
|
| 710 | + . '</a>'; |
|
| 711 | + } |
|
| 712 | + } |
|
| 713 | + return sprintf('%1$s %2$s', $link, $this->row_actions($actions)); |
|
| 714 | + } |
|
| 715 | 715 | |
| 716 | 716 | |
| 717 | - /** |
|
| 718 | - * column_ATT_email |
|
| 719 | - * |
|
| 720 | - * @access public |
|
| 721 | - * @param \EE_Registration $item |
|
| 722 | - * @return string |
|
| 723 | - * @throws EE_Error |
|
| 724 | - * @throws InvalidArgumentException |
|
| 725 | - * @throws InvalidDataTypeException |
|
| 726 | - * @throws InvalidInterfaceException |
|
| 727 | - * @throws ReflectionException |
|
| 728 | - */ |
|
| 729 | - public function column_ATT_email(EE_Registration $item) |
|
| 730 | - { |
|
| 731 | - $attendee = $item->get_first_related('Attendee'); |
|
| 732 | - return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso') |
|
| 733 | - : $attendee->email(); |
|
| 734 | - } |
|
| 717 | + /** |
|
| 718 | + * column_ATT_email |
|
| 719 | + * |
|
| 720 | + * @access public |
|
| 721 | + * @param \EE_Registration $item |
|
| 722 | + * @return string |
|
| 723 | + * @throws EE_Error |
|
| 724 | + * @throws InvalidArgumentException |
|
| 725 | + * @throws InvalidDataTypeException |
|
| 726 | + * @throws InvalidInterfaceException |
|
| 727 | + * @throws ReflectionException |
|
| 728 | + */ |
|
| 729 | + public function column_ATT_email(EE_Registration $item) |
|
| 730 | + { |
|
| 731 | + $attendee = $item->get_first_related('Attendee'); |
|
| 732 | + return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso') |
|
| 733 | + : $attendee->email(); |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | 736 | |
| 737 | - /** |
|
| 738 | - * column__REG_count |
|
| 739 | - * |
|
| 740 | - * @access public |
|
| 741 | - * @param \EE_Registration $item |
|
| 742 | - * @return string |
|
| 743 | - */ |
|
| 744 | - public function column__REG_count(EE_Registration $item) |
|
| 745 | - { |
|
| 746 | - return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 747 | - } |
|
| 737 | + /** |
|
| 738 | + * column__REG_count |
|
| 739 | + * |
|
| 740 | + * @access public |
|
| 741 | + * @param \EE_Registration $item |
|
| 742 | + * @return string |
|
| 743 | + */ |
|
| 744 | + public function column__REG_count(EE_Registration $item) |
|
| 745 | + { |
|
| 746 | + return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 747 | + } |
|
| 748 | 748 | |
| 749 | 749 | |
| 750 | - /** |
|
| 751 | - * column_PRC_amount |
|
| 752 | - * |
|
| 753 | - * @access public |
|
| 754 | - * @param \EE_Registration $item |
|
| 755 | - * @return string |
|
| 756 | - * @throws EE_Error |
|
| 757 | - */ |
|
| 758 | - public function column_PRC_amount(EE_Registration $item) |
|
| 759 | - { |
|
| 760 | - $ticket = $item->ticket(); |
|
| 761 | - $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">' |
|
| 762 | - . $ticket->name() |
|
| 763 | - . '</span><br />' : ''; |
|
| 764 | - if ($item->final_price() > 0) { |
|
| 765 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 766 | - } else { |
|
| 767 | - // free event |
|
| 768 | - $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
|
| 769 | - . __('free', 'event_espresso') |
|
| 770 | - . '</span>'; |
|
| 771 | - } |
|
| 772 | - return $content; |
|
| 773 | - } |
|
| 750 | + /** |
|
| 751 | + * column_PRC_amount |
|
| 752 | + * |
|
| 753 | + * @access public |
|
| 754 | + * @param \EE_Registration $item |
|
| 755 | + * @return string |
|
| 756 | + * @throws EE_Error |
|
| 757 | + */ |
|
| 758 | + public function column_PRC_amount(EE_Registration $item) |
|
| 759 | + { |
|
| 760 | + $ticket = $item->ticket(); |
|
| 761 | + $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">' |
|
| 762 | + . $ticket->name() |
|
| 763 | + . '</span><br />' : ''; |
|
| 764 | + if ($item->final_price() > 0) { |
|
| 765 | + $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 766 | + } else { |
|
| 767 | + // free event |
|
| 768 | + $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
|
| 769 | + . __('free', 'event_espresso') |
|
| 770 | + . '</span>'; |
|
| 771 | + } |
|
| 772 | + return $content; |
|
| 773 | + } |
|
| 774 | 774 | |
| 775 | 775 | |
| 776 | - /** |
|
| 777 | - * column__REG_final_price |
|
| 778 | - * |
|
| 779 | - * @access public |
|
| 780 | - * @param \EE_Registration $item |
|
| 781 | - * @return string |
|
| 782 | - * @throws EE_Error |
|
| 783 | - */ |
|
| 784 | - public function column__REG_final_price(EE_Registration $item) |
|
| 785 | - { |
|
| 786 | - $ticket = $item->ticket(); |
|
| 787 | - $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket |
|
| 788 | - ? '' |
|
| 789 | - : '<span class="TKT_name">' |
|
| 790 | - . $ticket->name() |
|
| 791 | - . '</span><br />'; |
|
| 792 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 793 | - return $content; |
|
| 794 | - } |
|
| 776 | + /** |
|
| 777 | + * column__REG_final_price |
|
| 778 | + * |
|
| 779 | + * @access public |
|
| 780 | + * @param \EE_Registration $item |
|
| 781 | + * @return string |
|
| 782 | + * @throws EE_Error |
|
| 783 | + */ |
|
| 784 | + public function column__REG_final_price(EE_Registration $item) |
|
| 785 | + { |
|
| 786 | + $ticket = $item->ticket(); |
|
| 787 | + $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket |
|
| 788 | + ? '' |
|
| 789 | + : '<span class="TKT_name">' |
|
| 790 | + . $ticket->name() |
|
| 791 | + . '</span><br />'; |
|
| 792 | + $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 793 | + return $content; |
|
| 794 | + } |
|
| 795 | 795 | |
| 796 | 796 | |
| 797 | - /** |
|
| 798 | - * column__REG_paid |
|
| 799 | - * |
|
| 800 | - * @access public |
|
| 801 | - * @param \EE_Registration $item |
|
| 802 | - * @return string |
|
| 803 | - * @throws EE_Error |
|
| 804 | - */ |
|
| 805 | - public function column__REG_paid(EE_Registration $item) |
|
| 806 | - { |
|
| 807 | - $payment_method = $item->payment_method(); |
|
| 808 | - $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
|
| 809 | - : __('Unknown', 'event_espresso'); |
|
| 810 | - $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
| 811 | - if ($item->paid() > 0) { |
|
| 812 | - $content .= '<br><span class="ee-status-text-small">' |
|
| 813 | - . sprintf( |
|
| 814 | - __('...via %s', 'event_espresso'), |
|
| 815 | - $payment_method_name |
|
| 816 | - ) |
|
| 817 | - . '</span>'; |
|
| 818 | - } |
|
| 819 | - return $content; |
|
| 820 | - } |
|
| 797 | + /** |
|
| 798 | + * column__REG_paid |
|
| 799 | + * |
|
| 800 | + * @access public |
|
| 801 | + * @param \EE_Registration $item |
|
| 802 | + * @return string |
|
| 803 | + * @throws EE_Error |
|
| 804 | + */ |
|
| 805 | + public function column__REG_paid(EE_Registration $item) |
|
| 806 | + { |
|
| 807 | + $payment_method = $item->payment_method(); |
|
| 808 | + $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
|
| 809 | + : __('Unknown', 'event_espresso'); |
|
| 810 | + $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
| 811 | + if ($item->paid() > 0) { |
|
| 812 | + $content .= '<br><span class="ee-status-text-small">' |
|
| 813 | + . sprintf( |
|
| 814 | + __('...via %s', 'event_espresso'), |
|
| 815 | + $payment_method_name |
|
| 816 | + ) |
|
| 817 | + . '</span>'; |
|
| 818 | + } |
|
| 819 | + return $content; |
|
| 820 | + } |
|
| 821 | 821 | |
| 822 | 822 | |
| 823 | - /** |
|
| 824 | - * column_TXN_total |
|
| 825 | - * |
|
| 826 | - * @access public |
|
| 827 | - * @param \EE_Registration $item |
|
| 828 | - * @return string |
|
| 829 | - * @throws EE_Error |
|
| 830 | - * @throws EntityNotFoundException |
|
| 831 | - * @throws InvalidArgumentException |
|
| 832 | - * @throws InvalidDataTypeException |
|
| 833 | - * @throws InvalidInterfaceException |
|
| 834 | - */ |
|
| 835 | - public function column_TXN_total(EE_Registration $item) |
|
| 836 | - { |
|
| 837 | - if ($item->transaction()) { |
|
| 838 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 839 | - 'action' => 'view_transaction', |
|
| 840 | - 'TXN_ID' => $item->transaction_ID(), |
|
| 841 | - ), TXN_ADMIN_URL); |
|
| 842 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 843 | - 'ee_read_transaction', |
|
| 844 | - 'espresso_transactions_view_transaction', |
|
| 845 | - $item->transaction_ID() |
|
| 846 | - ) |
|
| 847 | - ? '<span class="reg-pad-rght"><a class="status-' |
|
| 848 | - . $item->transaction()->status_ID() |
|
| 849 | - . '" href="' |
|
| 850 | - . $view_txn_lnk_url |
|
| 851 | - . '" title="' |
|
| 852 | - . esc_attr__('View Transaction', 'event_espresso') |
|
| 853 | - . '">' |
|
| 854 | - . $item->transaction()->pretty_total() |
|
| 855 | - . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
| 856 | - } else { |
|
| 857 | - return __("None", "event_espresso"); |
|
| 858 | - } |
|
| 859 | - } |
|
| 823 | + /** |
|
| 824 | + * column_TXN_total |
|
| 825 | + * |
|
| 826 | + * @access public |
|
| 827 | + * @param \EE_Registration $item |
|
| 828 | + * @return string |
|
| 829 | + * @throws EE_Error |
|
| 830 | + * @throws EntityNotFoundException |
|
| 831 | + * @throws InvalidArgumentException |
|
| 832 | + * @throws InvalidDataTypeException |
|
| 833 | + * @throws InvalidInterfaceException |
|
| 834 | + */ |
|
| 835 | + public function column_TXN_total(EE_Registration $item) |
|
| 836 | + { |
|
| 837 | + if ($item->transaction()) { |
|
| 838 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 839 | + 'action' => 'view_transaction', |
|
| 840 | + 'TXN_ID' => $item->transaction_ID(), |
|
| 841 | + ), TXN_ADMIN_URL); |
|
| 842 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 843 | + 'ee_read_transaction', |
|
| 844 | + 'espresso_transactions_view_transaction', |
|
| 845 | + $item->transaction_ID() |
|
| 846 | + ) |
|
| 847 | + ? '<span class="reg-pad-rght"><a class="status-' |
|
| 848 | + . $item->transaction()->status_ID() |
|
| 849 | + . '" href="' |
|
| 850 | + . $view_txn_lnk_url |
|
| 851 | + . '" title="' |
|
| 852 | + . esc_attr__('View Transaction', 'event_espresso') |
|
| 853 | + . '">' |
|
| 854 | + . $item->transaction()->pretty_total() |
|
| 855 | + . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
| 856 | + } else { |
|
| 857 | + return __("None", "event_espresso"); |
|
| 858 | + } |
|
| 859 | + } |
|
| 860 | 860 | |
| 861 | 861 | |
| 862 | - /** |
|
| 863 | - * column_TXN_paid |
|
| 864 | - * |
|
| 865 | - * @access public |
|
| 866 | - * @param \EE_Registration $item |
|
| 867 | - * @return string |
|
| 868 | - * @throws EE_Error |
|
| 869 | - * @throws EntityNotFoundException |
|
| 870 | - * @throws InvalidArgumentException |
|
| 871 | - * @throws InvalidDataTypeException |
|
| 872 | - * @throws InvalidInterfaceException |
|
| 873 | - */ |
|
| 874 | - public function column_TXN_paid(EE_Registration $item) |
|
| 875 | - { |
|
| 876 | - if ($item->count() === 1) { |
|
| 877 | - $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance(); |
|
| 878 | - if ($transaction->paid() >= $transaction->total()) { |
|
| 879 | - return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
| 880 | - } else { |
|
| 881 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 882 | - 'action' => 'view_transaction', |
|
| 883 | - 'TXN_ID' => $item->transaction_ID(), |
|
| 884 | - ), TXN_ADMIN_URL); |
|
| 885 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 886 | - 'ee_read_transaction', |
|
| 887 | - 'espresso_transactions_view_transaction', |
|
| 888 | - $item->transaction_ID() |
|
| 889 | - ) |
|
| 890 | - ? '<span class="reg-pad-rght"><a class="status-' |
|
| 891 | - . $transaction->status_ID() |
|
| 892 | - . '" href="' |
|
| 893 | - . $view_txn_lnk_url |
|
| 894 | - . '" title="' |
|
| 895 | - . esc_attr__('View Transaction', 'event_espresso') |
|
| 896 | - . '">' |
|
| 897 | - . $item->transaction()->pretty_paid() |
|
| 898 | - . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
| 899 | - } |
|
| 900 | - } |
|
| 901 | - return ' '; |
|
| 902 | - } |
|
| 862 | + /** |
|
| 863 | + * column_TXN_paid |
|
| 864 | + * |
|
| 865 | + * @access public |
|
| 866 | + * @param \EE_Registration $item |
|
| 867 | + * @return string |
|
| 868 | + * @throws EE_Error |
|
| 869 | + * @throws EntityNotFoundException |
|
| 870 | + * @throws InvalidArgumentException |
|
| 871 | + * @throws InvalidDataTypeException |
|
| 872 | + * @throws InvalidInterfaceException |
|
| 873 | + */ |
|
| 874 | + public function column_TXN_paid(EE_Registration $item) |
|
| 875 | + { |
|
| 876 | + if ($item->count() === 1) { |
|
| 877 | + $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance(); |
|
| 878 | + if ($transaction->paid() >= $transaction->total()) { |
|
| 879 | + return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
| 880 | + } else { |
|
| 881 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 882 | + 'action' => 'view_transaction', |
|
| 883 | + 'TXN_ID' => $item->transaction_ID(), |
|
| 884 | + ), TXN_ADMIN_URL); |
|
| 885 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 886 | + 'ee_read_transaction', |
|
| 887 | + 'espresso_transactions_view_transaction', |
|
| 888 | + $item->transaction_ID() |
|
| 889 | + ) |
|
| 890 | + ? '<span class="reg-pad-rght"><a class="status-' |
|
| 891 | + . $transaction->status_ID() |
|
| 892 | + . '" href="' |
|
| 893 | + . $view_txn_lnk_url |
|
| 894 | + . '" title="' |
|
| 895 | + . esc_attr__('View Transaction', 'event_espresso') |
|
| 896 | + . '">' |
|
| 897 | + . $item->transaction()->pretty_paid() |
|
| 898 | + . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
| 899 | + } |
|
| 900 | + } |
|
| 901 | + return ' '; |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | 904 | |
| 905 | - /** |
|
| 906 | - * column_actions |
|
| 907 | - * |
|
| 908 | - * @access public |
|
| 909 | - * @param \EE_Registration $item |
|
| 910 | - * @return string |
|
| 911 | - * @throws EE_Error |
|
| 912 | - * @throws InvalidArgumentException |
|
| 913 | - * @throws InvalidDataTypeException |
|
| 914 | - * @throws InvalidInterfaceException |
|
| 915 | - * @throws ReflectionException |
|
| 916 | - */ |
|
| 917 | - public function column_actions(EE_Registration $item) |
|
| 918 | - { |
|
| 919 | - $actions = array(); |
|
| 920 | - $attendee = $item->attendee(); |
|
| 921 | - $this->_set_related_details($item); |
|
| 922 | - //Build row actions |
|
| 923 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 924 | - 'action' => 'view_registration', |
|
| 925 | - '_REG_ID' => $item->ID(), |
|
| 926 | - ), REG_ADMIN_URL); |
|
| 927 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 928 | - 'action' => 'edit_attendee', |
|
| 929 | - 'post' => $item->attendee_ID(), |
|
| 930 | - ), REG_ADMIN_URL); |
|
| 931 | - // page=attendees&event_admin_reports=resend_email®istration_id=43653465634&event_id=2&form_action=resend_email |
|
| 932 | - //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID ); |
|
| 933 | - $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 934 | - 'action' => 'resend_registration', |
|
| 935 | - '_REG_ID' => $item->ID(), |
|
| 936 | - ), REG_ADMIN_URL, true); |
|
| 937 | - //Build row actions |
|
| 938 | - $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 939 | - 'ee_read_registration', |
|
| 940 | - 'espresso_registrations_view_registration', |
|
| 941 | - $item->ID() |
|
| 942 | - ) ? '<li><a href="' |
|
| 943 | - . $view_lnk_url |
|
| 944 | - . '" title="' |
|
| 945 | - . esc_attr__('View Registration Details', 'event_espresso') |
|
| 946 | - . '" class="tiny-text"> |
|
| 905 | + /** |
|
| 906 | + * column_actions |
|
| 907 | + * |
|
| 908 | + * @access public |
|
| 909 | + * @param \EE_Registration $item |
|
| 910 | + * @return string |
|
| 911 | + * @throws EE_Error |
|
| 912 | + * @throws InvalidArgumentException |
|
| 913 | + * @throws InvalidDataTypeException |
|
| 914 | + * @throws InvalidInterfaceException |
|
| 915 | + * @throws ReflectionException |
|
| 916 | + */ |
|
| 917 | + public function column_actions(EE_Registration $item) |
|
| 918 | + { |
|
| 919 | + $actions = array(); |
|
| 920 | + $attendee = $item->attendee(); |
|
| 921 | + $this->_set_related_details($item); |
|
| 922 | + //Build row actions |
|
| 923 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 924 | + 'action' => 'view_registration', |
|
| 925 | + '_REG_ID' => $item->ID(), |
|
| 926 | + ), REG_ADMIN_URL); |
|
| 927 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 928 | + 'action' => 'edit_attendee', |
|
| 929 | + 'post' => $item->attendee_ID(), |
|
| 930 | + ), REG_ADMIN_URL); |
|
| 931 | + // page=attendees&event_admin_reports=resend_email®istration_id=43653465634&event_id=2&form_action=resend_email |
|
| 932 | + //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID ); |
|
| 933 | + $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 934 | + 'action' => 'resend_registration', |
|
| 935 | + '_REG_ID' => $item->ID(), |
|
| 936 | + ), REG_ADMIN_URL, true); |
|
| 937 | + //Build row actions |
|
| 938 | + $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 939 | + 'ee_read_registration', |
|
| 940 | + 'espresso_registrations_view_registration', |
|
| 941 | + $item->ID() |
|
| 942 | + ) ? '<li><a href="' |
|
| 943 | + . $view_lnk_url |
|
| 944 | + . '" title="' |
|
| 945 | + . esc_attr__('View Registration Details', 'event_espresso') |
|
| 946 | + . '" class="tiny-text"> |
|
| 947 | 947 | <div class="dashicons dashicons-clipboard"></div> |
| 948 | 948 | </a> |
| 949 | 949 | </li>' |
| 950 | - : ''; |
|
| 951 | - $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 952 | - 'ee_edit_contacts', |
|
| 953 | - 'espresso_registrations_edit_attendee' |
|
| 954 | - ) |
|
| 955 | - && $attendee instanceof EE_Attendee |
|
| 956 | - ? ' |
|
| 950 | + : ''; |
|
| 951 | + $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 952 | + 'ee_edit_contacts', |
|
| 953 | + 'espresso_registrations_edit_attendee' |
|
| 954 | + ) |
|
| 955 | + && $attendee instanceof EE_Attendee |
|
| 956 | + ? ' |
|
| 957 | 957 | <li> |
| 958 | 958 | <a href="' . $edit_lnk_url . '" title="' |
| 959 | - . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
| 959 | + . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
| 960 | 960 | <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div> |
| 961 | 961 | </a> |
| 962 | 962 | </li>' : ''; |
| 963 | - $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee |
|
| 964 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 965 | - 'ee_send_message', |
|
| 966 | - 'espresso_registrations_resend_registration', |
|
| 967 | - $item->ID() |
|
| 968 | - ) |
|
| 969 | - ? ' |
|
| 963 | + $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee |
|
| 964 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 965 | + 'ee_send_message', |
|
| 966 | + 'espresso_registrations_resend_registration', |
|
| 967 | + $item->ID() |
|
| 968 | + ) |
|
| 969 | + ? ' |
|
| 970 | 970 | <li> |
| 971 | 971 | <a href="' |
| 972 | - . $resend_reg_lnk_url |
|
| 973 | - . '" title="' |
|
| 974 | - . esc_attr__('Resend Registration Details', 'event_espresso') |
|
| 975 | - . '" class="tiny-text"> |
|
| 972 | + . $resend_reg_lnk_url |
|
| 973 | + . '" title="' |
|
| 974 | + . esc_attr__('Resend Registration Details', 'event_espresso') |
|
| 975 | + . '" class="tiny-text"> |
|
| 976 | 976 | <div class="dashicons dashicons-email-alt"></div> |
| 977 | 977 | </a> |
| 978 | 978 | </li>' : ''; |
| 979 | - // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb |
|
| 980 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 981 | - 'action' => 'view_transaction', |
|
| 982 | - 'TXN_ID' => $this->_transaction_details['id'], |
|
| 983 | - ), TXN_ADMIN_URL); |
|
| 984 | - $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 985 | - 'ee_read_transaction', |
|
| 986 | - 'espresso_transactions_view_transaction', |
|
| 987 | - $this->_transaction_details['id'] |
|
| 988 | - ) |
|
| 989 | - ? ' |
|
| 979 | + // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb |
|
| 980 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 981 | + 'action' => 'view_transaction', |
|
| 982 | + 'TXN_ID' => $this->_transaction_details['id'], |
|
| 983 | + ), TXN_ADMIN_URL); |
|
| 984 | + $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 985 | + 'ee_read_transaction', |
|
| 986 | + 'espresso_transactions_view_transaction', |
|
| 987 | + $this->_transaction_details['id'] |
|
| 988 | + ) |
|
| 989 | + ? ' |
|
| 990 | 990 | <li> |
| 991 | 991 | <a class="ee-status-color-' |
| 992 | - . $this->_transaction_details['status'] |
|
| 993 | - . ' tiny-text" href="' |
|
| 994 | - . $view_txn_lnk_url |
|
| 995 | - . '" title="' |
|
| 996 | - . $this->_transaction_details['title_attr'] |
|
| 997 | - . '"> |
|
| 992 | + . $this->_transaction_details['status'] |
|
| 993 | + . ' tiny-text" href="' |
|
| 994 | + . $view_txn_lnk_url |
|
| 995 | + . '" title="' |
|
| 996 | + . $this->_transaction_details['title_attr'] |
|
| 997 | + . '"> |
|
| 998 | 998 | <div class="dashicons dashicons-cart"></div> |
| 999 | 999 | </a> |
| 1000 | 1000 | </li>' : ''; |
| 1001 | - //invoice link |
|
| 1002 | - $actions['dl_invoice_lnk'] = ''; |
|
| 1003 | - $dl_invoice_lnk_url = $item->invoice_url(); |
|
| 1004 | - //only show invoice link if message type is active. |
|
| 1005 | - if ($attendee instanceof EE_Attendee |
|
| 1006 | - && $item->is_primary_registrant() |
|
| 1007 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
| 1008 | - ) { |
|
| 1009 | - $actions['dl_invoice_lnk'] = ' |
|
| 1001 | + //invoice link |
|
| 1002 | + $actions['dl_invoice_lnk'] = ''; |
|
| 1003 | + $dl_invoice_lnk_url = $item->invoice_url(); |
|
| 1004 | + //only show invoice link if message type is active. |
|
| 1005 | + if ($attendee instanceof EE_Attendee |
|
| 1006 | + && $item->is_primary_registrant() |
|
| 1007 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
| 1008 | + ) { |
|
| 1009 | + $actions['dl_invoice_lnk'] = ' |
|
| 1010 | 1010 | <li> |
| 1011 | 1011 | <a title="' |
| 1012 | - . esc_attr__('View Transaction Invoice', 'event_espresso') |
|
| 1013 | - . '" target="_blank" href="' |
|
| 1014 | - . $dl_invoice_lnk_url |
|
| 1015 | - . '" class="tiny-text"> |
|
| 1012 | + . esc_attr__('View Transaction Invoice', 'event_espresso') |
|
| 1013 | + . '" target="_blank" href="' |
|
| 1014 | + . $dl_invoice_lnk_url |
|
| 1015 | + . '" class="tiny-text"> |
|
| 1016 | 1016 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
| 1017 | 1017 | </a> |
| 1018 | 1018 | </li>'; |
| 1019 | - } |
|
| 1020 | - $actions['filtered_messages_link'] = ''; |
|
| 1021 | - //message list table link (filtered by REG_ID |
|
| 1022 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 1023 | - $actions['filtered_messages_link'] = '<li>' |
|
| 1024 | - . EEH_MSG_Template::get_message_action_link( |
|
| 1025 | - 'see_notifications_for', |
|
| 1026 | - null, |
|
| 1027 | - array('_REG_ID' => $item->ID()) |
|
| 1028 | - ) . '</li>'; |
|
| 1029 | - } |
|
| 1030 | - $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
|
| 1031 | - return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
|
| 1032 | - } |
|
| 1019 | + } |
|
| 1020 | + $actions['filtered_messages_link'] = ''; |
|
| 1021 | + //message list table link (filtered by REG_ID |
|
| 1022 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 1023 | + $actions['filtered_messages_link'] = '<li>' |
|
| 1024 | + . EEH_MSG_Template::get_message_action_link( |
|
| 1025 | + 'see_notifications_for', |
|
| 1026 | + null, |
|
| 1027 | + array('_REG_ID' => $item->ID()) |
|
| 1028 | + ) . '</li>'; |
|
| 1029 | + } |
|
| 1030 | + $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
|
| 1031 | + return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
|
| 1032 | + } |
|
| 1033 | 1033 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
| 3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 4 | 4 | |
| 5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 6 | 6 | exit('No direct script access allowed'); |
| 7 | 7 | } |
| 8 | 8 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct(Registrations_Admin_Page $admin_page) |
| 59 | 59 | { |
| 60 | - if (! empty($_GET['event_id'])) { |
|
| 60 | + if ( ! empty($_GET['event_id'])) { |
|
| 61 | 61 | $extra_query_args = array(); |
| 62 | 62 | foreach ($admin_page->get_views() as $key => $view_details) { |
| 63 | 63 | $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | ); |
| 158 | 158 | $this->_primary_column = '_REG_ID'; |
| 159 | 159 | $this->_sortable_columns = array( |
| 160 | - '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
| 160 | + '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
| 161 | 161 | /** |
| 162 | 162 | * Allows users to change the default sort if they wish. |
| 163 | 163 | * Returning a falsey on this filter will result in the default sort to be by firstname rather than last |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | { |
| 190 | 190 | $class = parent::_get_row_class($item); |
| 191 | 191 | //add status class |
| 192 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
| 192 | + $class .= ' ee-status-strip reg-status-'.$item->status_ID(); |
|
| 193 | 193 | if ($this->_has_checkbox_column) { |
| 194 | 194 | $class .= ' has-checkbox-column'; |
| 195 | 195 | } |
@@ -354,12 +354,12 @@ discard block |
||
| 354 | 354 | //setup date query. |
| 355 | 355 | $beginning_string = EEM_Registration::instance()->convert_datetime_for_query( |
| 356 | 356 | 'REG_date', |
| 357 | - $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
| 357 | + $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start, |
|
| 358 | 358 | 'Y-m-d H:i:s' |
| 359 | 359 | ); |
| 360 | 360 | $end_string = EEM_Registration::instance()->convert_datetime_for_query( |
| 361 | 361 | 'REG_date', |
| 362 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
| 362 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end, |
|
| 363 | 363 | 'Y-m-d H:i:s' |
| 364 | 364 | ); |
| 365 | 365 | $_where['REG_date'] = array( |
@@ -396,12 +396,12 @@ discard block |
||
| 396 | 396 | array( |
| 397 | 397 | EEM_Registration::instance()->convert_datetime_for_query( |
| 398 | 398 | 'REG_date', |
| 399 | - $current_date . $time_start, |
|
| 399 | + $current_date.$time_start, |
|
| 400 | 400 | 'Y-m-d H:i:s' |
| 401 | 401 | ), |
| 402 | 402 | EEM_Registration::instance()->convert_datetime_for_query( |
| 403 | 403 | 'REG_date', |
| 404 | - $current_date . $time_end, |
|
| 404 | + $current_date.$time_end, |
|
| 405 | 405 | 'Y-m-d H:i:s' |
| 406 | 406 | ), |
| 407 | 407 | ), |
@@ -461,8 +461,8 @@ discard block |
||
| 461 | 461 | $content .= '<div class="show-on-mobile-view-only">'; |
| 462 | 462 | $content .= '<br>'; |
| 463 | 463 | $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
| 464 | - $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 465 | - $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 464 | + $content .= ' '.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 465 | + $content .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 466 | 466 | $content .= '</div>'; |
| 467 | 467 | return $content; |
| 468 | 468 | } |
@@ -544,12 +544,12 @@ discard block |
||
| 544 | 544 | . $event_name |
| 545 | 545 | . '</a>' : $event_name; |
| 546 | 546 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
| 547 | - $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
| 547 | + $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="'; |
|
| 548 | 548 | $actions['event_filter'] .= sprintf( |
| 549 | 549 | esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'), |
| 550 | 550 | $event_name |
| 551 | 551 | ); |
| 552 | - $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
| 552 | + $actions['event_filter'] .= '">'.__('View Registrations', 'event_espresso').'</a>'; |
|
| 553 | 553 | } else { |
| 554 | 554 | $edit_event = $event_name; |
| 555 | 555 | $actions['event_filter'] = ''; |
@@ -596,11 +596,11 @@ discard block |
||
| 596 | 596 | { |
| 597 | 597 | $content = '<div class="ee-registration-event-datetimes-container">'; |
| 598 | 598 | $expand_toggle = count($datetime_strings) > 1 |
| 599 | - ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso') |
|
| 599 | + ? ' <span title="'.esc_attr__('Click to view all dates', 'event_espresso') |
|
| 600 | 600 | . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>' |
| 601 | 601 | : ''; |
| 602 | 602 | //get first item for initial visibility |
| 603 | - $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>'; |
|
| 603 | + $content .= '<div class="left">'.array_shift($datetime_strings).'</div>'; |
|
| 604 | 604 | $content .= $expand_toggle; |
| 605 | 605 | if ($datetime_strings) { |
| 606 | 606 | $content .= '<div style="clear:both"></div>'; |
@@ -650,9 +650,9 @@ discard block |
||
| 650 | 650 | $t = $item->get_first_related('Transaction'); |
| 651 | 651 | $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
| 652 | 652 | //append group count to name |
| 653 | - $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 653 | + $link .= ' '.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 654 | 654 | //append reg_code |
| 655 | - $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 655 | + $link .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 656 | 656 | //reg status text for accessibility |
| 657 | 657 | $link .= '<br><span class="ee-status-text-small">' |
| 658 | 658 | . EEH_Template::pretty_status($item->status_ID(), false, 'sentence') |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | . $trash_lnk_url |
| 675 | 675 | . '" title="' |
| 676 | 676 | . esc_attr__('Trash Registration', 'event_espresso') |
| 677 | - . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
| 677 | + . '">'.__('Trash', 'event_espresso').'</a>'; |
|
| 678 | 678 | } elseif ($this->_view === 'trash') { |
| 679 | 679 | // restore registration link |
| 680 | 680 | if (EE_Registry::instance()->CAP->current_user_can( |
@@ -689,8 +689,8 @@ discard block |
||
| 689 | 689 | $actions['restore'] = '<a href="' |
| 690 | 690 | . $restore_lnk_url |
| 691 | 691 | . '" title="' |
| 692 | - . esc_attr__('Restore Registration', 'event_espresso') . '">' |
|
| 693 | - . __('Restore', 'event_espresso') . '</a>'; |
|
| 692 | + . esc_attr__('Restore Registration', 'event_espresso').'">' |
|
| 693 | + . __('Restore', 'event_espresso').'</a>'; |
|
| 694 | 694 | } |
| 695 | 695 | if (EE_Registry::instance()->CAP->current_user_can( |
| 696 | 696 | 'ee_delete_registration', |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | . $ticket->name() |
| 763 | 763 | . '</span><br />' : ''; |
| 764 | 764 | if ($item->final_price() > 0) { |
| 765 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 765 | + $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>'; |
|
| 766 | 766 | } else { |
| 767 | 767 | // free event |
| 768 | 768 | $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | : '<span class="TKT_name">' |
| 790 | 790 | . $ticket->name() |
| 791 | 791 | . '</span><br />'; |
| 792 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 792 | + $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>'; |
|
| 793 | 793 | return $content; |
| 794 | 794 | } |
| 795 | 795 | |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | $payment_method = $item->payment_method(); |
| 808 | 808 | $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
| 809 | 809 | : __('Unknown', 'event_espresso'); |
| 810 | - $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
| 810 | + $content = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>'; |
|
| 811 | 811 | if ($item->paid() > 0) { |
| 812 | 812 | $content .= '<br><span class="ee-status-text-small">' |
| 813 | 813 | . sprintf( |
@@ -852,7 +852,7 @@ discard block |
||
| 852 | 852 | . esc_attr__('View Transaction', 'event_espresso') |
| 853 | 853 | . '">' |
| 854 | 854 | . $item->transaction()->pretty_total() |
| 855 | - . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
| 855 | + . '</a></span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>'; |
|
| 856 | 856 | } else { |
| 857 | 857 | return __("None", "event_espresso"); |
| 858 | 858 | } |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | . esc_attr__('View Transaction', 'event_espresso') |
| 896 | 896 | . '">' |
| 897 | 897 | . $item->transaction()->pretty_paid() |
| 898 | - . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
| 898 | + . '</a><span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>'; |
|
| 899 | 899 | } |
| 900 | 900 | } |
| 901 | 901 | return ' '; |
@@ -955,8 +955,8 @@ discard block |
||
| 955 | 955 | && $attendee instanceof EE_Attendee |
| 956 | 956 | ? ' |
| 957 | 957 | <li> |
| 958 | - <a href="' . $edit_lnk_url . '" title="' |
|
| 959 | - . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
| 958 | + <a href="' . $edit_lnk_url.'" title="' |
|
| 959 | + . esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text"> |
|
| 960 | 960 | <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div> |
| 961 | 961 | </a> |
| 962 | 962 | </li>' : ''; |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | 'see_notifications_for', |
| 1026 | 1026 | null, |
| 1027 | 1027 | array('_REG_ID' => $item->ID()) |
| 1028 | - ) . '</li>'; |
|
| 1028 | + ).'</li>'; |
|
| 1029 | 1029 | } |
| 1030 | 1030 | $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
| 1031 | 1031 | return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
@@ -21,199 +21,199 @@ |
||
| 21 | 21 | { |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * converts a Request to a Response |
|
| 26 | - * |
|
| 27 | - * @param EE_Request $request |
|
| 28 | - * @param EE_Response $response |
|
| 29 | - * @return EE_Response |
|
| 30 | - * @throws InvalidDataTypeException |
|
| 31 | - */ |
|
| 32 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
| 33 | - { |
|
| 34 | - $this->_request = $request; |
|
| 35 | - $this->_response = $response; |
|
| 36 | - //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
|
| 37 | - //$this->_response->set_notice( 1, 'hey look at this' ); |
|
| 38 | - // check required WP version |
|
| 39 | - if (! $this->_minimum_wp_version_required()) { |
|
| 40 | - $this->_request->un_set('activate', true); |
|
| 41 | - add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
| 42 | - //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
|
| 43 | - $this->_response->terminate_request(); |
|
| 44 | - $this->_response->deactivate_plugin(); |
|
| 45 | - } |
|
| 46 | - // check recommended PHP version |
|
| 47 | - if (! $this->_minimum_php_version_recommended()) { |
|
| 48 | - $this->_display_minimum_recommended_php_version_notice(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - //upcoming required version |
|
| 52 | - if (! $this->upcomingRequiredPhpVersion()) { |
|
| 53 | - $this->displayUpcomingRequiredVersion(); |
|
| 54 | - } |
|
| 55 | - $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
| 56 | - //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
|
| 57 | - return $this->_response; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Helper method to assess installed wp version against given values. |
|
| 63 | - * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
| 64 | - * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked |
|
| 65 | - * against) so consider that when sending in your values. |
|
| 66 | - * |
|
| 67 | - * @param string $version_to_check |
|
| 68 | - * @param string $operator |
|
| 69 | - * @return bool |
|
| 70 | - */ |
|
| 71 | - public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
| 72 | - { |
|
| 73 | - global $wp_version; |
|
| 74 | - return version_compare( |
|
| 75 | - // first account for wp_version being pre-release |
|
| 76 | - // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519 |
|
| 77 | - strpos($wp_version, '-') > 0 |
|
| 78 | - ? substr($wp_version, 0, strpos($wp_version, '-')) |
|
| 79 | - : $wp_version, |
|
| 80 | - $version_to_check, |
|
| 81 | - $operator |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * _minimum_wp_version_required |
|
| 89 | - * |
|
| 90 | - * @access private |
|
| 91 | - * @return boolean |
|
| 92 | - */ |
|
| 93 | - private function _minimum_wp_version_required() |
|
| 94 | - { |
|
| 95 | - return EE_Recommended_Versions::check_wp_version(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * _check_php_version |
|
| 102 | - * |
|
| 103 | - * @access private |
|
| 104 | - * @param string $min_version |
|
| 105 | - * @return boolean |
|
| 106 | - */ |
|
| 107 | - private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
| 108 | - { |
|
| 109 | - return version_compare(PHP_VERSION, $min_version, '>='); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * _minimum_php_version_recommended |
|
| 116 | - * |
|
| 117 | - * @access private |
|
| 118 | - * @return boolean |
|
| 119 | - */ |
|
| 120 | - private function _minimum_php_version_recommended() |
|
| 121 | - { |
|
| 122 | - return $this->_check_php_version(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Returns whether the provided php version number is greater than the current version of php installed on the server. |
|
| 128 | - * @param string $version_required |
|
| 129 | - * @return bool |
|
| 130 | - */ |
|
| 131 | - private function upcomingRequiredPhpVersion($version_required = '5.5') |
|
| 132 | - { |
|
| 133 | - return $this->_check_php_version($version_required); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * minimum_wp_version_error |
|
| 140 | - * |
|
| 141 | - * @return void |
|
| 142 | - */ |
|
| 143 | - public function minimum_wp_version_error() |
|
| 144 | - { |
|
| 145 | - global $wp_version; |
|
| 146 | - ?> |
|
| 24 | + /** |
|
| 25 | + * converts a Request to a Response |
|
| 26 | + * |
|
| 27 | + * @param EE_Request $request |
|
| 28 | + * @param EE_Response $response |
|
| 29 | + * @return EE_Response |
|
| 30 | + * @throws InvalidDataTypeException |
|
| 31 | + */ |
|
| 32 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
| 33 | + { |
|
| 34 | + $this->_request = $request; |
|
| 35 | + $this->_response = $response; |
|
| 36 | + //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
|
| 37 | + //$this->_response->set_notice( 1, 'hey look at this' ); |
|
| 38 | + // check required WP version |
|
| 39 | + if (! $this->_minimum_wp_version_required()) { |
|
| 40 | + $this->_request->un_set('activate', true); |
|
| 41 | + add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
| 42 | + //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
|
| 43 | + $this->_response->terminate_request(); |
|
| 44 | + $this->_response->deactivate_plugin(); |
|
| 45 | + } |
|
| 46 | + // check recommended PHP version |
|
| 47 | + if (! $this->_minimum_php_version_recommended()) { |
|
| 48 | + $this->_display_minimum_recommended_php_version_notice(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + //upcoming required version |
|
| 52 | + if (! $this->upcomingRequiredPhpVersion()) { |
|
| 53 | + $this->displayUpcomingRequiredVersion(); |
|
| 54 | + } |
|
| 55 | + $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
| 56 | + //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
|
| 57 | + return $this->_response; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Helper method to assess installed wp version against given values. |
|
| 63 | + * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
| 64 | + * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked |
|
| 65 | + * against) so consider that when sending in your values. |
|
| 66 | + * |
|
| 67 | + * @param string $version_to_check |
|
| 68 | + * @param string $operator |
|
| 69 | + * @return bool |
|
| 70 | + */ |
|
| 71 | + public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
| 72 | + { |
|
| 73 | + global $wp_version; |
|
| 74 | + return version_compare( |
|
| 75 | + // first account for wp_version being pre-release |
|
| 76 | + // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519 |
|
| 77 | + strpos($wp_version, '-') > 0 |
|
| 78 | + ? substr($wp_version, 0, strpos($wp_version, '-')) |
|
| 79 | + : $wp_version, |
|
| 80 | + $version_to_check, |
|
| 81 | + $operator |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * _minimum_wp_version_required |
|
| 89 | + * |
|
| 90 | + * @access private |
|
| 91 | + * @return boolean |
|
| 92 | + */ |
|
| 93 | + private function _minimum_wp_version_required() |
|
| 94 | + { |
|
| 95 | + return EE_Recommended_Versions::check_wp_version(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * _check_php_version |
|
| 102 | + * |
|
| 103 | + * @access private |
|
| 104 | + * @param string $min_version |
|
| 105 | + * @return boolean |
|
| 106 | + */ |
|
| 107 | + private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
| 108 | + { |
|
| 109 | + return version_compare(PHP_VERSION, $min_version, '>='); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * _minimum_php_version_recommended |
|
| 116 | + * |
|
| 117 | + * @access private |
|
| 118 | + * @return boolean |
|
| 119 | + */ |
|
| 120 | + private function _minimum_php_version_recommended() |
|
| 121 | + { |
|
| 122 | + return $this->_check_php_version(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Returns whether the provided php version number is greater than the current version of php installed on the server. |
|
| 128 | + * @param string $version_required |
|
| 129 | + * @return bool |
|
| 130 | + */ |
|
| 131 | + private function upcomingRequiredPhpVersion($version_required = '5.5') |
|
| 132 | + { |
|
| 133 | + return $this->_check_php_version($version_required); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * minimum_wp_version_error |
|
| 140 | + * |
|
| 141 | + * @return void |
|
| 142 | + */ |
|
| 143 | + public function minimum_wp_version_error() |
|
| 144 | + { |
|
| 145 | + global $wp_version; |
|
| 146 | + ?> |
|
| 147 | 147 | <div class="error"> |
| 148 | 148 | <p> |
| 149 | 149 | <?php |
| 150 | - printf( |
|
| 151 | - __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
| 152 | - 'event_espresso'), |
|
| 153 | - EE_MIN_WP_VER_REQUIRED, |
|
| 154 | - $wp_version, |
|
| 155 | - '<br/>', |
|
| 156 | - '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
| 157 | - ); |
|
| 158 | - ?> |
|
| 150 | + printf( |
|
| 151 | + __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
| 152 | + 'event_espresso'), |
|
| 153 | + EE_MIN_WP_VER_REQUIRED, |
|
| 154 | + $wp_version, |
|
| 155 | + '<br/>', |
|
| 156 | + '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
| 157 | + ); |
|
| 158 | + ?> |
|
| 159 | 159 | </p> |
| 160 | 160 | </div> |
| 161 | 161 | <?php |
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * _display_minimum_recommended_php_version_notice |
|
| 168 | - * |
|
| 169 | - * @access private |
|
| 170 | - * @return void |
|
| 171 | - * @throws InvalidDataTypeException |
|
| 172 | - */ |
|
| 173 | - private function _display_minimum_recommended_php_version_notice() |
|
| 174 | - { |
|
| 175 | - if($this->_request->isAdmin()){ |
|
| 176 | - new PersistentAdminNotice( |
|
| 177 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
| 178 | - sprintf( |
|
| 179 | - __( |
|
| 180 | - 'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 181 | - 'event_espresso' |
|
| 182 | - ), |
|
| 183 | - EE_MIN_PHP_VER_RECOMMENDED, |
|
| 184 | - PHP_VERSION, |
|
| 185 | - '<br/>', |
|
| 186 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 187 | - ) |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Sets a notice for an upcoming required version of PHP in the next update of EE core. |
|
| 195 | - */ |
|
| 196 | - private function displayUpcomingRequiredVersion() |
|
| 197 | - { |
|
| 198 | - if ($this->_request->isAdmin() |
|
| 199 | - && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->_request) |
|
| 200 | - && current_user_can('update_plugins') |
|
| 201 | - ) { |
|
| 202 | - add_action('admin_notices', function () { |
|
| 203 | - echo '<div class="notice event-espresso-admin-notice notice-warning"><p>' |
|
| 204 | - . sprintf( |
|
| 205 | - esc_html__( |
|
| 206 | - 'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater. Your web server\'s PHP version is %3$s. You can contact your host and ask them to update your PHP version to at least PHP 5.6. Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s', |
|
| 207 | - 'event_espresso' |
|
| 208 | - ), |
|
| 209 | - '<strong>', |
|
| 210 | - '</strong>', |
|
| 211 | - PHP_VERSION, |
|
| 212 | - '<a href="https://wordpress.org/support/upgrade-php/">', |
|
| 213 | - '</a>' |
|
| 214 | - ) |
|
| 215 | - . '</p></div>'; |
|
| 216 | - }); |
|
| 217 | - } |
|
| 218 | - } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * _display_minimum_recommended_php_version_notice |
|
| 168 | + * |
|
| 169 | + * @access private |
|
| 170 | + * @return void |
|
| 171 | + * @throws InvalidDataTypeException |
|
| 172 | + */ |
|
| 173 | + private function _display_minimum_recommended_php_version_notice() |
|
| 174 | + { |
|
| 175 | + if($this->_request->isAdmin()){ |
|
| 176 | + new PersistentAdminNotice( |
|
| 177 | + 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
| 178 | + sprintf( |
|
| 179 | + __( |
|
| 180 | + 'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 181 | + 'event_espresso' |
|
| 182 | + ), |
|
| 183 | + EE_MIN_PHP_VER_RECOMMENDED, |
|
| 184 | + PHP_VERSION, |
|
| 185 | + '<br/>', |
|
| 186 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 187 | + ) |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Sets a notice for an upcoming required version of PHP in the next update of EE core. |
|
| 195 | + */ |
|
| 196 | + private function displayUpcomingRequiredVersion() |
|
| 197 | + { |
|
| 198 | + if ($this->_request->isAdmin() |
|
| 199 | + && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->_request) |
|
| 200 | + && current_user_can('update_plugins') |
|
| 201 | + ) { |
|
| 202 | + add_action('admin_notices', function () { |
|
| 203 | + echo '<div class="notice event-espresso-admin-notice notice-warning"><p>' |
|
| 204 | + . sprintf( |
|
| 205 | + esc_html__( |
|
| 206 | + 'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater. Your web server\'s PHP version is %3$s. You can contact your host and ask them to update your PHP version to at least PHP 5.6. Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s', |
|
| 207 | + 'event_espresso' |
|
| 208 | + ), |
|
| 209 | + '<strong>', |
|
| 210 | + '</strong>', |
|
| 211 | + PHP_VERSION, |
|
| 212 | + '<a href="https://wordpress.org/support/upgrade-php/">', |
|
| 213 | + '</a>' |
|
| 214 | + ) |
|
| 215 | + . '</p></div>'; |
|
| 216 | + }); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | 219 | } |
@@ -8,644 +8,644 @@ |
||
| 8 | 8 | class EE_Email_messenger extends EE_messenger |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * To field for email |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $_to = ''; |
|
| 16 | - |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * CC field for email. |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $_cc = ''; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * From field for email |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - protected $_from = ''; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Subject field for email |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $_subject = ''; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Content field for email |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - protected $_content = ''; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * constructor |
|
| 47 | - * |
|
| 48 | - * @access public |
|
| 49 | - */ |
|
| 50 | - public function __construct() |
|
| 51 | - { |
|
| 52 | - //set name and description properties |
|
| 53 | - $this->name = 'email'; |
|
| 54 | - $this->description = sprintf( |
|
| 55 | - esc_html__( |
|
| 56 | - 'This messenger delivers messages via email using the built-in %s function included with WordPress', |
|
| 57 | - 'event_espresso' |
|
| 58 | - ), |
|
| 59 | - '<code>wp_mail</code>' |
|
| 60 | - ); |
|
| 61 | - $this->label = array( |
|
| 62 | - 'singular' => esc_html__('email', 'event_espresso'), |
|
| 63 | - 'plural' => esc_html__('emails', 'event_espresso'), |
|
| 64 | - ); |
|
| 65 | - $this->activate_on_install = true; |
|
| 66 | - |
|
| 67 | - //we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
| 68 | - // properties |
|
| 69 | - parent::__construct(); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * see abstract declaration in parent class for details. |
|
| 75 | - */ |
|
| 76 | - protected function _set_admin_pages() |
|
| 77 | - { |
|
| 78 | - $this->admin_registered_pages = array( |
|
| 79 | - 'events_edit' => true, |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * see abstract declaration in parent class for details |
|
| 86 | - */ |
|
| 87 | - protected function _set_valid_shortcodes() |
|
| 88 | - { |
|
| 89 | - //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
| 90 | - // message type. |
|
| 91 | - $this->_valid_shortcodes = array( |
|
| 92 | - 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 93 | - 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 94 | - 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * see abstract declaration in parent class for details |
|
| 101 | - * |
|
| 102 | - * @access protected |
|
| 103 | - * @return void |
|
| 104 | - */ |
|
| 105 | - protected function _set_validator_config() |
|
| 106 | - { |
|
| 107 | - $valid_shortcodes = $this->get_valid_shortcodes(); |
|
| 108 | - |
|
| 109 | - $this->_validator_config = array( |
|
| 110 | - 'to' => array( |
|
| 111 | - 'shortcodes' => $valid_shortcodes['to'], |
|
| 112 | - 'type' => 'email', |
|
| 113 | - ), |
|
| 114 | - 'cc' => array( |
|
| 115 | - 'shortcodes' => $valid_shortcodes['to'], |
|
| 116 | - 'type' => 'email', |
|
| 117 | - ), |
|
| 118 | - 'from' => array( |
|
| 119 | - 'shortcodes' => $valid_shortcodes['from'], |
|
| 120 | - 'type' => 'email', |
|
| 121 | - ), |
|
| 122 | - 'subject' => array( |
|
| 123 | - 'shortcodes' => array( |
|
| 124 | - 'organization', |
|
| 125 | - 'primary_registration_details', |
|
| 126 | - 'event_author', |
|
| 127 | - 'primary_registration_details', |
|
| 128 | - 'recipient_details', |
|
| 129 | - ), |
|
| 130 | - ), |
|
| 131 | - 'content' => array( |
|
| 132 | - 'shortcodes' => array( |
|
| 133 | - 'event_list', |
|
| 134 | - 'attendee_list', |
|
| 135 | - 'ticket_list', |
|
| 136 | - 'organization', |
|
| 137 | - 'primary_registration_details', |
|
| 138 | - 'primary_registration_list', |
|
| 139 | - 'event_author', |
|
| 140 | - 'recipient_details', |
|
| 141 | - 'recipient_list', |
|
| 142 | - 'transaction', |
|
| 143 | - 'messenger', |
|
| 144 | - ), |
|
| 145 | - ), |
|
| 146 | - 'attendee_list' => array( |
|
| 147 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
| 148 | - 'required' => array('[ATTENDEE_LIST]'), |
|
| 149 | - ), |
|
| 150 | - 'event_list' => array( |
|
| 151 | - 'shortcodes' => array( |
|
| 152 | - 'event', |
|
| 153 | - 'attendee_list', |
|
| 154 | - 'ticket_list', |
|
| 155 | - 'venue', |
|
| 156 | - 'datetime_list', |
|
| 157 | - 'attendee', |
|
| 158 | - 'primary_registration_details', |
|
| 159 | - 'primary_registration_list', |
|
| 160 | - 'event_author', |
|
| 161 | - 'recipient_details', |
|
| 162 | - 'recipient_list', |
|
| 163 | - ), |
|
| 164 | - 'required' => array('[EVENT_LIST]'), |
|
| 165 | - ), |
|
| 166 | - 'ticket_list' => array( |
|
| 167 | - 'shortcodes' => array( |
|
| 168 | - 'event_list', |
|
| 169 | - 'attendee_list', |
|
| 170 | - 'ticket', |
|
| 171 | - 'datetime_list', |
|
| 172 | - 'primary_registration_details', |
|
| 173 | - 'recipient_details', |
|
| 174 | - ), |
|
| 175 | - 'required' => array('[TICKET_LIST]'), |
|
| 176 | - ), |
|
| 177 | - 'datetime_list' => array( |
|
| 178 | - 'shortcodes' => array('datetime'), |
|
| 179 | - 'required' => array('[DATETIME_LIST]'), |
|
| 180 | - ), |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @see parent EE_messenger class for docs |
|
| 187 | - * @since 4.5.0 |
|
| 188 | - */ |
|
| 189 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
| 190 | - { |
|
| 191 | - if ($sending_messenger_name = 'html') { |
|
| 192 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - public function add_email_css( |
|
| 198 | - $variation_path, |
|
| 199 | - $messenger, |
|
| 200 | - $message_type, |
|
| 201 | - $type, |
|
| 202 | - $variation, |
|
| 203 | - $file_extension, |
|
| 204 | - $url, |
|
| 205 | - EE_Messages_Template_Pack $template_pack |
|
| 206 | - ) { |
|
| 207 | - //prevent recursion on this callback. |
|
| 208 | - remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
| 209 | - $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
| 210 | - |
|
| 211 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
| 212 | - return $variation; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * See parent for details |
|
| 218 | - * |
|
| 219 | - * @access protected |
|
| 220 | - * @return void |
|
| 221 | - */ |
|
| 222 | - protected function _set_test_settings_fields() |
|
| 223 | - { |
|
| 224 | - $this->_test_settings_fields = array( |
|
| 225 | - 'to' => array( |
|
| 226 | - 'input' => 'text', |
|
| 227 | - 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
| 228 | - 'type' => 'email', |
|
| 229 | - 'required' => true, |
|
| 230 | - 'validation' => true, |
|
| 231 | - 'css_class' => 'large-text', |
|
| 232 | - 'format' => '%s', |
|
| 233 | - 'default' => get_bloginfo('admin_email'), |
|
| 234 | - ), |
|
| 235 | - 'subject' => array( |
|
| 236 | - 'input' => 'hidden', |
|
| 237 | - 'label' => '', |
|
| 238 | - 'type' => 'string', |
|
| 239 | - 'required' => false, |
|
| 240 | - 'validation' => false, |
|
| 241 | - 'format' => '%s', |
|
| 242 | - 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
| 243 | - 'default' => '', |
|
| 244 | - 'css_class' => '', |
|
| 245 | - ), |
|
| 246 | - ); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * _set_template_fields |
|
| 252 | - * This sets up the fields that a messenger requires for the message to go out. |
|
| 253 | - * |
|
| 254 | - * @access protected |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - protected function _set_template_fields() |
|
| 258 | - { |
|
| 259 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
| 260 | - // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
| 261 | - // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
| 262 | - // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
| 263 | - // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
| 264 | - // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
| 265 | - // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
| 266 | - // will not be displayed/parsed. |
|
| 267 | - $this->_template_fields = array( |
|
| 268 | - 'to' => array( |
|
| 269 | - 'input' => 'text', |
|
| 270 | - 'label' => esc_html_x( |
|
| 271 | - 'To', |
|
| 272 | - 'Label for the "To" field for email addresses', |
|
| 273 | - 'event_espresso' |
|
| 274 | - ), |
|
| 275 | - 'type' => 'string', |
|
| 276 | - 'required' => true, |
|
| 277 | - 'validation' => true, |
|
| 278 | - 'css_class' => 'large-text', |
|
| 279 | - 'format' => '%s', |
|
| 280 | - ), |
|
| 281 | - 'cc' => array( |
|
| 282 | - 'input' => 'text', |
|
| 283 | - 'label' => esc_html_x( |
|
| 284 | - 'CC', |
|
| 285 | - 'Label for the "Carbon Copy" field used for additional email addresses', |
|
| 286 | - 'event_espresso' |
|
| 287 | - ), |
|
| 288 | - 'type' => 'string', |
|
| 289 | - 'required' => false, |
|
| 290 | - 'validation' => true, |
|
| 291 | - 'css_class' => 'large-text', |
|
| 292 | - 'format' => '%s', |
|
| 293 | - ), |
|
| 294 | - 'from' => array( |
|
| 295 | - 'input' => 'text', |
|
| 296 | - 'label' => esc_html_x( |
|
| 297 | - 'From', |
|
| 298 | - 'Label for the "From" field for email addresses.', |
|
| 299 | - 'event_espresso' |
|
| 300 | - ), |
|
| 301 | - 'type' => 'string', |
|
| 302 | - 'required' => true, |
|
| 303 | - 'validation' => true, |
|
| 304 | - 'css_class' => 'large-text', |
|
| 305 | - 'format' => '%s', |
|
| 306 | - ), |
|
| 307 | - 'subject' => array( |
|
| 308 | - 'input' => 'text', |
|
| 309 | - 'label' => esc_html_x( |
|
| 310 | - 'Subject', |
|
| 311 | - 'Label for the "Subject" field (short description of contents) for emails.', |
|
| 312 | - 'event_espresso' |
|
| 313 | - ), |
|
| 314 | - 'type' => 'string', |
|
| 315 | - 'required' => true, |
|
| 316 | - 'validation' => true, |
|
| 317 | - 'css_class' => 'large-text', |
|
| 318 | - 'format' => '%s', |
|
| 319 | - ), |
|
| 320 | - 'content' => '', |
|
| 321 | - //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
| 322 | - 'extra' => array( |
|
| 323 | - 'content' => array( |
|
| 324 | - 'main' => array( |
|
| 325 | - 'input' => 'wp_editor', |
|
| 326 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
| 327 | - 'type' => 'string', |
|
| 328 | - 'required' => true, |
|
| 329 | - 'validation' => true, |
|
| 330 | - 'format' => '%s', |
|
| 331 | - 'rows' => '15', |
|
| 332 | - ), |
|
| 333 | - 'event_list' => array( |
|
| 334 | - 'input' => 'wp_editor', |
|
| 335 | - 'label' => '[EVENT_LIST]', |
|
| 336 | - 'type' => 'string', |
|
| 337 | - 'required' => true, |
|
| 338 | - 'validation' => true, |
|
| 339 | - 'format' => '%s', |
|
| 340 | - 'rows' => '15', |
|
| 341 | - 'shortcodes_required' => array('[EVENT_LIST]'), |
|
| 342 | - ), |
|
| 343 | - 'attendee_list' => array( |
|
| 344 | - 'input' => 'textarea', |
|
| 345 | - 'label' => '[ATTENDEE_LIST]', |
|
| 346 | - 'type' => 'string', |
|
| 347 | - 'required' => true, |
|
| 348 | - 'validation' => true, |
|
| 349 | - 'format' => '%s', |
|
| 350 | - 'css_class' => 'large-text', |
|
| 351 | - 'rows' => '5', |
|
| 352 | - 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
| 353 | - ), |
|
| 354 | - 'ticket_list' => array( |
|
| 355 | - 'input' => 'textarea', |
|
| 356 | - 'label' => '[TICKET_LIST]', |
|
| 357 | - 'type' => 'string', |
|
| 358 | - 'required' => true, |
|
| 359 | - 'validation' => true, |
|
| 360 | - 'format' => '%s', |
|
| 361 | - 'css_class' => 'large-text', |
|
| 362 | - 'rows' => '10', |
|
| 363 | - 'shortcodes_required' => array('[TICKET_LIST]'), |
|
| 364 | - ), |
|
| 365 | - 'datetime_list' => array( |
|
| 366 | - 'input' => 'textarea', |
|
| 367 | - 'label' => '[DATETIME_LIST]', |
|
| 368 | - 'type' => 'string', |
|
| 369 | - 'required' => true, |
|
| 370 | - 'validation' => true, |
|
| 371 | - 'format' => '%s', |
|
| 372 | - 'css_class' => 'large-text', |
|
| 373 | - 'rows' => '10', |
|
| 374 | - 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
| 375 | - ), |
|
| 376 | - ), |
|
| 377 | - ), |
|
| 378 | - ); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * See definition of this class in parent |
|
| 384 | - */ |
|
| 385 | - protected function _set_default_message_types() |
|
| 386 | - { |
|
| 387 | - $this->_default_message_types = array( |
|
| 388 | - 'payment', |
|
| 389 | - 'payment_refund', |
|
| 390 | - 'registration', |
|
| 391 | - 'not_approved_registration', |
|
| 392 | - 'pending_approval', |
|
| 393 | - ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * @see definition of this class in parent |
|
| 399 | - * @since 4.5.0 |
|
| 400 | - */ |
|
| 401 | - protected function _set_valid_message_types() |
|
| 402 | - { |
|
| 403 | - $this->_valid_message_types = array( |
|
| 404 | - 'payment', |
|
| 405 | - 'registration', |
|
| 406 | - 'not_approved_registration', |
|
| 407 | - 'declined_registration', |
|
| 408 | - 'cancelled_registration', |
|
| 409 | - 'pending_approval', |
|
| 410 | - 'registration_summary', |
|
| 411 | - 'payment_reminder', |
|
| 412 | - 'payment_declined', |
|
| 413 | - 'payment_refund', |
|
| 414 | - ); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * setting up admin_settings_fields for messenger. |
|
| 420 | - */ |
|
| 421 | - protected function _set_admin_settings_fields() |
|
| 422 | - { |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * We just deliver the messages don't kill us!! |
|
| 427 | - * |
|
| 428 | - * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
| 429 | - * present. |
|
| 430 | - * @throws EE_Error |
|
| 431 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 432 | - */ |
|
| 433 | - protected function _send_message() |
|
| 434 | - { |
|
| 435 | - $success = wp_mail( |
|
| 436 | - $this->_to, |
|
| 437 | - //some old values for subject may be expecting HTML entities to be decoded in the subject |
|
| 438 | - //and subjects aren't interpreted as HTML, so there should be no HTML in them |
|
| 439 | - wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)), |
|
| 440 | - $this->_body(), |
|
| 441 | - $this->_headers() |
|
| 442 | - ); |
|
| 443 | - if (! $success) { |
|
| 444 | - EE_Error::add_error( |
|
| 445 | - sprintf( |
|
| 446 | - esc_html__( |
|
| 447 | - 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
| 448 | - 'event_espresso' |
|
| 449 | - ), |
|
| 450 | - $this->_to, |
|
| 451 | - $this->_from, |
|
| 452 | - '<br />' |
|
| 453 | - ), |
|
| 454 | - __FILE__, |
|
| 455 | - __FUNCTION__, |
|
| 456 | - __LINE__ |
|
| 457 | - ); |
|
| 458 | - } |
|
| 459 | - return $success; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * see parent for definition |
|
| 465 | - * |
|
| 466 | - * @return string html body of the message content and the related css. |
|
| 467 | - * @throws EE_Error |
|
| 468 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 469 | - */ |
|
| 470 | - protected function _preview() |
|
| 471 | - { |
|
| 472 | - return $this->_body(true); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * Setup headers for email |
|
| 478 | - * |
|
| 479 | - * @access protected |
|
| 480 | - * @return string formatted header for email |
|
| 481 | - */ |
|
| 482 | - protected function _headers() |
|
| 483 | - { |
|
| 484 | - $this->_ensure_has_from_email_address(); |
|
| 485 | - $from = $this->_from; |
|
| 486 | - $headers = array( |
|
| 487 | - 'From:' . $from, |
|
| 488 | - 'Reply-To:' . $from, |
|
| 489 | - 'Content-Type:text/html; charset=utf-8', |
|
| 490 | - ); |
|
| 491 | - |
|
| 492 | - if (! empty($this->_cc)) { |
|
| 493 | - $headers[] = 'cc: ' . $this->_cc; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
| 497 | - // header. |
|
| 498 | - add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
| 499 | - add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
| 500 | - return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
| 506 | - * address for the from address to avoid problems with sending emails. |
|
| 507 | - */ |
|
| 508 | - protected function _ensure_has_from_email_address() |
|
| 509 | - { |
|
| 510 | - if (empty($this->_from)) { |
|
| 511 | - $this->_from = get_bloginfo('admin_email'); |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
| 518 | - * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
| 519 | - * be empty |
|
| 520 | - * |
|
| 521 | - * @since 4.3.1 |
|
| 522 | - * @return array |
|
| 523 | - */ |
|
| 524 | - private function _parse_from() |
|
| 525 | - { |
|
| 526 | - if (strpos($this->_from, '<') !== false) { |
|
| 527 | - $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
| 528 | - $from_name = str_replace('"', '', $from_name); |
|
| 529 | - $from_name = trim($from_name); |
|
| 530 | - |
|
| 531 | - $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
| 532 | - $from_email = str_replace('>', '', $from_email); |
|
| 533 | - $from_email = trim($from_email); |
|
| 534 | - } elseif (trim($this->_from) !== '') { |
|
| 535 | - $from_name = ''; |
|
| 536 | - $from_email = trim($this->_from); |
|
| 537 | - } else { |
|
| 538 | - $from_name = $from_email = ''; |
|
| 539 | - } |
|
| 540 | - return array($from_name, $from_email); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * Callback for the wp_mail_from filter. |
|
| 546 | - * |
|
| 547 | - * @since 4.3.1 |
|
| 548 | - * @param string $from_email What the original from_email is. |
|
| 549 | - * @return string |
|
| 550 | - */ |
|
| 551 | - public function set_from_address($from_email) |
|
| 552 | - { |
|
| 553 | - $parsed_from = $this->_parse_from(); |
|
| 554 | - //includes fallback if the parsing failed. |
|
| 555 | - $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
| 556 | - ? $parsed_from[1] |
|
| 557 | - : get_bloginfo('admin_email'); |
|
| 558 | - return $from_email; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * Callback fro the wp_mail_from_name filter. |
|
| 564 | - * |
|
| 565 | - * @since 4.3.1 |
|
| 566 | - * @param string $from_name The original from_name. |
|
| 567 | - * @return string |
|
| 568 | - */ |
|
| 569 | - public function set_from_name($from_name) |
|
| 570 | - { |
|
| 571 | - $parsed_from = $this->_parse_from(); |
|
| 572 | - if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
| 573 | - $from_name = $parsed_from[0]; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
| 577 | - //but realize the default name is HTML entity-encoded |
|
| 578 | - $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name; |
|
| 579 | - |
|
| 580 | - return $from_name; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * setup body for email |
|
| 586 | - * |
|
| 587 | - * @param bool $preview will determine whether this is preview template or not. |
|
| 588 | - * @return string formatted body for email. |
|
| 589 | - * @throws EE_Error |
|
| 590 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 591 | - */ |
|
| 592 | - protected function _body($preview = false) |
|
| 593 | - { |
|
| 594 | - //setup template args! |
|
| 595 | - $this->_template_args = array( |
|
| 596 | - 'subject' => $this->_subject, |
|
| 597 | - 'from' => $this->_from, |
|
| 598 | - 'main_body' => wpautop($this->_content), |
|
| 599 | - ); |
|
| 600 | - $body = $this->_get_main_template($preview); |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
| 604 | - * |
|
| 605 | - * @type bool $preview Indicates whether a preview is being generated or not. |
|
| 606 | - * @return bool true indicates to use the inliner, false bypasses it. |
|
| 607 | - */ |
|
| 608 | - if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
| 609 | - //require CssToInlineStyles library and its dependencies via composer autoloader |
|
| 610 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
| 611 | - |
|
| 612 | - //now if this isn't a preview, let's setup the body so it has inline styles |
|
| 613 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
| 614 | - $style = file_get_contents( |
|
| 615 | - $this->get_variation( |
|
| 616 | - $this->_tmp_pack, |
|
| 617 | - $this->_incoming_message_type->name, |
|
| 618 | - false, |
|
| 619 | - 'main', |
|
| 620 | - $this->_variation |
|
| 621 | - ), |
|
| 622 | - true |
|
| 623 | - ); |
|
| 624 | - $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
| 625 | - //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
| 626 | - $body = ltrim($CSS->convert(true), ">\n"); |
|
| 627 | - //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
| 628 | - $body = ltrim($body, "<?"); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - } |
|
| 632 | - return $body; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * This just returns any existing test settings that might be saved in the database |
|
| 638 | - * |
|
| 639 | - * @access public |
|
| 640 | - * @return array |
|
| 641 | - */ |
|
| 642 | - public function get_existing_test_settings() |
|
| 643 | - { |
|
| 644 | - $settings = parent::get_existing_test_settings(); |
|
| 645 | - //override subject if present because we always want it to be fresh. |
|
| 646 | - if (is_array($settings) && ! empty($settings['subject'])) { |
|
| 647 | - $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
| 648 | - } |
|
| 649 | - return $settings; |
|
| 650 | - } |
|
| 11 | + /** |
|
| 12 | + * To field for email |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $_to = ''; |
|
| 16 | + |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * CC field for email. |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $_cc = ''; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * From field for email |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + protected $_from = ''; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Subject field for email |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $_subject = ''; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Content field for email |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + protected $_content = ''; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * constructor |
|
| 47 | + * |
|
| 48 | + * @access public |
|
| 49 | + */ |
|
| 50 | + public function __construct() |
|
| 51 | + { |
|
| 52 | + //set name and description properties |
|
| 53 | + $this->name = 'email'; |
|
| 54 | + $this->description = sprintf( |
|
| 55 | + esc_html__( |
|
| 56 | + 'This messenger delivers messages via email using the built-in %s function included with WordPress', |
|
| 57 | + 'event_espresso' |
|
| 58 | + ), |
|
| 59 | + '<code>wp_mail</code>' |
|
| 60 | + ); |
|
| 61 | + $this->label = array( |
|
| 62 | + 'singular' => esc_html__('email', 'event_espresso'), |
|
| 63 | + 'plural' => esc_html__('emails', 'event_espresso'), |
|
| 64 | + ); |
|
| 65 | + $this->activate_on_install = true; |
|
| 66 | + |
|
| 67 | + //we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
| 68 | + // properties |
|
| 69 | + parent::__construct(); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * see abstract declaration in parent class for details. |
|
| 75 | + */ |
|
| 76 | + protected function _set_admin_pages() |
|
| 77 | + { |
|
| 78 | + $this->admin_registered_pages = array( |
|
| 79 | + 'events_edit' => true, |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * see abstract declaration in parent class for details |
|
| 86 | + */ |
|
| 87 | + protected function _set_valid_shortcodes() |
|
| 88 | + { |
|
| 89 | + //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
| 90 | + // message type. |
|
| 91 | + $this->_valid_shortcodes = array( |
|
| 92 | + 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 93 | + 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 94 | + 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * see abstract declaration in parent class for details |
|
| 101 | + * |
|
| 102 | + * @access protected |
|
| 103 | + * @return void |
|
| 104 | + */ |
|
| 105 | + protected function _set_validator_config() |
|
| 106 | + { |
|
| 107 | + $valid_shortcodes = $this->get_valid_shortcodes(); |
|
| 108 | + |
|
| 109 | + $this->_validator_config = array( |
|
| 110 | + 'to' => array( |
|
| 111 | + 'shortcodes' => $valid_shortcodes['to'], |
|
| 112 | + 'type' => 'email', |
|
| 113 | + ), |
|
| 114 | + 'cc' => array( |
|
| 115 | + 'shortcodes' => $valid_shortcodes['to'], |
|
| 116 | + 'type' => 'email', |
|
| 117 | + ), |
|
| 118 | + 'from' => array( |
|
| 119 | + 'shortcodes' => $valid_shortcodes['from'], |
|
| 120 | + 'type' => 'email', |
|
| 121 | + ), |
|
| 122 | + 'subject' => array( |
|
| 123 | + 'shortcodes' => array( |
|
| 124 | + 'organization', |
|
| 125 | + 'primary_registration_details', |
|
| 126 | + 'event_author', |
|
| 127 | + 'primary_registration_details', |
|
| 128 | + 'recipient_details', |
|
| 129 | + ), |
|
| 130 | + ), |
|
| 131 | + 'content' => array( |
|
| 132 | + 'shortcodes' => array( |
|
| 133 | + 'event_list', |
|
| 134 | + 'attendee_list', |
|
| 135 | + 'ticket_list', |
|
| 136 | + 'organization', |
|
| 137 | + 'primary_registration_details', |
|
| 138 | + 'primary_registration_list', |
|
| 139 | + 'event_author', |
|
| 140 | + 'recipient_details', |
|
| 141 | + 'recipient_list', |
|
| 142 | + 'transaction', |
|
| 143 | + 'messenger', |
|
| 144 | + ), |
|
| 145 | + ), |
|
| 146 | + 'attendee_list' => array( |
|
| 147 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
| 148 | + 'required' => array('[ATTENDEE_LIST]'), |
|
| 149 | + ), |
|
| 150 | + 'event_list' => array( |
|
| 151 | + 'shortcodes' => array( |
|
| 152 | + 'event', |
|
| 153 | + 'attendee_list', |
|
| 154 | + 'ticket_list', |
|
| 155 | + 'venue', |
|
| 156 | + 'datetime_list', |
|
| 157 | + 'attendee', |
|
| 158 | + 'primary_registration_details', |
|
| 159 | + 'primary_registration_list', |
|
| 160 | + 'event_author', |
|
| 161 | + 'recipient_details', |
|
| 162 | + 'recipient_list', |
|
| 163 | + ), |
|
| 164 | + 'required' => array('[EVENT_LIST]'), |
|
| 165 | + ), |
|
| 166 | + 'ticket_list' => array( |
|
| 167 | + 'shortcodes' => array( |
|
| 168 | + 'event_list', |
|
| 169 | + 'attendee_list', |
|
| 170 | + 'ticket', |
|
| 171 | + 'datetime_list', |
|
| 172 | + 'primary_registration_details', |
|
| 173 | + 'recipient_details', |
|
| 174 | + ), |
|
| 175 | + 'required' => array('[TICKET_LIST]'), |
|
| 176 | + ), |
|
| 177 | + 'datetime_list' => array( |
|
| 178 | + 'shortcodes' => array('datetime'), |
|
| 179 | + 'required' => array('[DATETIME_LIST]'), |
|
| 180 | + ), |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @see parent EE_messenger class for docs |
|
| 187 | + * @since 4.5.0 |
|
| 188 | + */ |
|
| 189 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
| 190 | + { |
|
| 191 | + if ($sending_messenger_name = 'html') { |
|
| 192 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + public function add_email_css( |
|
| 198 | + $variation_path, |
|
| 199 | + $messenger, |
|
| 200 | + $message_type, |
|
| 201 | + $type, |
|
| 202 | + $variation, |
|
| 203 | + $file_extension, |
|
| 204 | + $url, |
|
| 205 | + EE_Messages_Template_Pack $template_pack |
|
| 206 | + ) { |
|
| 207 | + //prevent recursion on this callback. |
|
| 208 | + remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
| 209 | + $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
| 210 | + |
|
| 211 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
| 212 | + return $variation; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * See parent for details |
|
| 218 | + * |
|
| 219 | + * @access protected |
|
| 220 | + * @return void |
|
| 221 | + */ |
|
| 222 | + protected function _set_test_settings_fields() |
|
| 223 | + { |
|
| 224 | + $this->_test_settings_fields = array( |
|
| 225 | + 'to' => array( |
|
| 226 | + 'input' => 'text', |
|
| 227 | + 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
| 228 | + 'type' => 'email', |
|
| 229 | + 'required' => true, |
|
| 230 | + 'validation' => true, |
|
| 231 | + 'css_class' => 'large-text', |
|
| 232 | + 'format' => '%s', |
|
| 233 | + 'default' => get_bloginfo('admin_email'), |
|
| 234 | + ), |
|
| 235 | + 'subject' => array( |
|
| 236 | + 'input' => 'hidden', |
|
| 237 | + 'label' => '', |
|
| 238 | + 'type' => 'string', |
|
| 239 | + 'required' => false, |
|
| 240 | + 'validation' => false, |
|
| 241 | + 'format' => '%s', |
|
| 242 | + 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
| 243 | + 'default' => '', |
|
| 244 | + 'css_class' => '', |
|
| 245 | + ), |
|
| 246 | + ); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * _set_template_fields |
|
| 252 | + * This sets up the fields that a messenger requires for the message to go out. |
|
| 253 | + * |
|
| 254 | + * @access protected |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + protected function _set_template_fields() |
|
| 258 | + { |
|
| 259 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
| 260 | + // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
| 261 | + // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
| 262 | + // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
| 263 | + // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
| 264 | + // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
| 265 | + // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
| 266 | + // will not be displayed/parsed. |
|
| 267 | + $this->_template_fields = array( |
|
| 268 | + 'to' => array( |
|
| 269 | + 'input' => 'text', |
|
| 270 | + 'label' => esc_html_x( |
|
| 271 | + 'To', |
|
| 272 | + 'Label for the "To" field for email addresses', |
|
| 273 | + 'event_espresso' |
|
| 274 | + ), |
|
| 275 | + 'type' => 'string', |
|
| 276 | + 'required' => true, |
|
| 277 | + 'validation' => true, |
|
| 278 | + 'css_class' => 'large-text', |
|
| 279 | + 'format' => '%s', |
|
| 280 | + ), |
|
| 281 | + 'cc' => array( |
|
| 282 | + 'input' => 'text', |
|
| 283 | + 'label' => esc_html_x( |
|
| 284 | + 'CC', |
|
| 285 | + 'Label for the "Carbon Copy" field used for additional email addresses', |
|
| 286 | + 'event_espresso' |
|
| 287 | + ), |
|
| 288 | + 'type' => 'string', |
|
| 289 | + 'required' => false, |
|
| 290 | + 'validation' => true, |
|
| 291 | + 'css_class' => 'large-text', |
|
| 292 | + 'format' => '%s', |
|
| 293 | + ), |
|
| 294 | + 'from' => array( |
|
| 295 | + 'input' => 'text', |
|
| 296 | + 'label' => esc_html_x( |
|
| 297 | + 'From', |
|
| 298 | + 'Label for the "From" field for email addresses.', |
|
| 299 | + 'event_espresso' |
|
| 300 | + ), |
|
| 301 | + 'type' => 'string', |
|
| 302 | + 'required' => true, |
|
| 303 | + 'validation' => true, |
|
| 304 | + 'css_class' => 'large-text', |
|
| 305 | + 'format' => '%s', |
|
| 306 | + ), |
|
| 307 | + 'subject' => array( |
|
| 308 | + 'input' => 'text', |
|
| 309 | + 'label' => esc_html_x( |
|
| 310 | + 'Subject', |
|
| 311 | + 'Label for the "Subject" field (short description of contents) for emails.', |
|
| 312 | + 'event_espresso' |
|
| 313 | + ), |
|
| 314 | + 'type' => 'string', |
|
| 315 | + 'required' => true, |
|
| 316 | + 'validation' => true, |
|
| 317 | + 'css_class' => 'large-text', |
|
| 318 | + 'format' => '%s', |
|
| 319 | + ), |
|
| 320 | + 'content' => '', |
|
| 321 | + //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
| 322 | + 'extra' => array( |
|
| 323 | + 'content' => array( |
|
| 324 | + 'main' => array( |
|
| 325 | + 'input' => 'wp_editor', |
|
| 326 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
| 327 | + 'type' => 'string', |
|
| 328 | + 'required' => true, |
|
| 329 | + 'validation' => true, |
|
| 330 | + 'format' => '%s', |
|
| 331 | + 'rows' => '15', |
|
| 332 | + ), |
|
| 333 | + 'event_list' => array( |
|
| 334 | + 'input' => 'wp_editor', |
|
| 335 | + 'label' => '[EVENT_LIST]', |
|
| 336 | + 'type' => 'string', |
|
| 337 | + 'required' => true, |
|
| 338 | + 'validation' => true, |
|
| 339 | + 'format' => '%s', |
|
| 340 | + 'rows' => '15', |
|
| 341 | + 'shortcodes_required' => array('[EVENT_LIST]'), |
|
| 342 | + ), |
|
| 343 | + 'attendee_list' => array( |
|
| 344 | + 'input' => 'textarea', |
|
| 345 | + 'label' => '[ATTENDEE_LIST]', |
|
| 346 | + 'type' => 'string', |
|
| 347 | + 'required' => true, |
|
| 348 | + 'validation' => true, |
|
| 349 | + 'format' => '%s', |
|
| 350 | + 'css_class' => 'large-text', |
|
| 351 | + 'rows' => '5', |
|
| 352 | + 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
| 353 | + ), |
|
| 354 | + 'ticket_list' => array( |
|
| 355 | + 'input' => 'textarea', |
|
| 356 | + 'label' => '[TICKET_LIST]', |
|
| 357 | + 'type' => 'string', |
|
| 358 | + 'required' => true, |
|
| 359 | + 'validation' => true, |
|
| 360 | + 'format' => '%s', |
|
| 361 | + 'css_class' => 'large-text', |
|
| 362 | + 'rows' => '10', |
|
| 363 | + 'shortcodes_required' => array('[TICKET_LIST]'), |
|
| 364 | + ), |
|
| 365 | + 'datetime_list' => array( |
|
| 366 | + 'input' => 'textarea', |
|
| 367 | + 'label' => '[DATETIME_LIST]', |
|
| 368 | + 'type' => 'string', |
|
| 369 | + 'required' => true, |
|
| 370 | + 'validation' => true, |
|
| 371 | + 'format' => '%s', |
|
| 372 | + 'css_class' => 'large-text', |
|
| 373 | + 'rows' => '10', |
|
| 374 | + 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
| 375 | + ), |
|
| 376 | + ), |
|
| 377 | + ), |
|
| 378 | + ); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * See definition of this class in parent |
|
| 384 | + */ |
|
| 385 | + protected function _set_default_message_types() |
|
| 386 | + { |
|
| 387 | + $this->_default_message_types = array( |
|
| 388 | + 'payment', |
|
| 389 | + 'payment_refund', |
|
| 390 | + 'registration', |
|
| 391 | + 'not_approved_registration', |
|
| 392 | + 'pending_approval', |
|
| 393 | + ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * @see definition of this class in parent |
|
| 399 | + * @since 4.5.0 |
|
| 400 | + */ |
|
| 401 | + protected function _set_valid_message_types() |
|
| 402 | + { |
|
| 403 | + $this->_valid_message_types = array( |
|
| 404 | + 'payment', |
|
| 405 | + 'registration', |
|
| 406 | + 'not_approved_registration', |
|
| 407 | + 'declined_registration', |
|
| 408 | + 'cancelled_registration', |
|
| 409 | + 'pending_approval', |
|
| 410 | + 'registration_summary', |
|
| 411 | + 'payment_reminder', |
|
| 412 | + 'payment_declined', |
|
| 413 | + 'payment_refund', |
|
| 414 | + ); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * setting up admin_settings_fields for messenger. |
|
| 420 | + */ |
|
| 421 | + protected function _set_admin_settings_fields() |
|
| 422 | + { |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * We just deliver the messages don't kill us!! |
|
| 427 | + * |
|
| 428 | + * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
| 429 | + * present. |
|
| 430 | + * @throws EE_Error |
|
| 431 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 432 | + */ |
|
| 433 | + protected function _send_message() |
|
| 434 | + { |
|
| 435 | + $success = wp_mail( |
|
| 436 | + $this->_to, |
|
| 437 | + //some old values for subject may be expecting HTML entities to be decoded in the subject |
|
| 438 | + //and subjects aren't interpreted as HTML, so there should be no HTML in them |
|
| 439 | + wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)), |
|
| 440 | + $this->_body(), |
|
| 441 | + $this->_headers() |
|
| 442 | + ); |
|
| 443 | + if (! $success) { |
|
| 444 | + EE_Error::add_error( |
|
| 445 | + sprintf( |
|
| 446 | + esc_html__( |
|
| 447 | + 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
| 448 | + 'event_espresso' |
|
| 449 | + ), |
|
| 450 | + $this->_to, |
|
| 451 | + $this->_from, |
|
| 452 | + '<br />' |
|
| 453 | + ), |
|
| 454 | + __FILE__, |
|
| 455 | + __FUNCTION__, |
|
| 456 | + __LINE__ |
|
| 457 | + ); |
|
| 458 | + } |
|
| 459 | + return $success; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * see parent for definition |
|
| 465 | + * |
|
| 466 | + * @return string html body of the message content and the related css. |
|
| 467 | + * @throws EE_Error |
|
| 468 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 469 | + */ |
|
| 470 | + protected function _preview() |
|
| 471 | + { |
|
| 472 | + return $this->_body(true); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * Setup headers for email |
|
| 478 | + * |
|
| 479 | + * @access protected |
|
| 480 | + * @return string formatted header for email |
|
| 481 | + */ |
|
| 482 | + protected function _headers() |
|
| 483 | + { |
|
| 484 | + $this->_ensure_has_from_email_address(); |
|
| 485 | + $from = $this->_from; |
|
| 486 | + $headers = array( |
|
| 487 | + 'From:' . $from, |
|
| 488 | + 'Reply-To:' . $from, |
|
| 489 | + 'Content-Type:text/html; charset=utf-8', |
|
| 490 | + ); |
|
| 491 | + |
|
| 492 | + if (! empty($this->_cc)) { |
|
| 493 | + $headers[] = 'cc: ' . $this->_cc; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
| 497 | + // header. |
|
| 498 | + add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
| 499 | + add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
| 500 | + return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
| 506 | + * address for the from address to avoid problems with sending emails. |
|
| 507 | + */ |
|
| 508 | + protected function _ensure_has_from_email_address() |
|
| 509 | + { |
|
| 510 | + if (empty($this->_from)) { |
|
| 511 | + $this->_from = get_bloginfo('admin_email'); |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
| 518 | + * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
| 519 | + * be empty |
|
| 520 | + * |
|
| 521 | + * @since 4.3.1 |
|
| 522 | + * @return array |
|
| 523 | + */ |
|
| 524 | + private function _parse_from() |
|
| 525 | + { |
|
| 526 | + if (strpos($this->_from, '<') !== false) { |
|
| 527 | + $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
| 528 | + $from_name = str_replace('"', '', $from_name); |
|
| 529 | + $from_name = trim($from_name); |
|
| 530 | + |
|
| 531 | + $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
| 532 | + $from_email = str_replace('>', '', $from_email); |
|
| 533 | + $from_email = trim($from_email); |
|
| 534 | + } elseif (trim($this->_from) !== '') { |
|
| 535 | + $from_name = ''; |
|
| 536 | + $from_email = trim($this->_from); |
|
| 537 | + } else { |
|
| 538 | + $from_name = $from_email = ''; |
|
| 539 | + } |
|
| 540 | + return array($from_name, $from_email); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * Callback for the wp_mail_from filter. |
|
| 546 | + * |
|
| 547 | + * @since 4.3.1 |
|
| 548 | + * @param string $from_email What the original from_email is. |
|
| 549 | + * @return string |
|
| 550 | + */ |
|
| 551 | + public function set_from_address($from_email) |
|
| 552 | + { |
|
| 553 | + $parsed_from = $this->_parse_from(); |
|
| 554 | + //includes fallback if the parsing failed. |
|
| 555 | + $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
| 556 | + ? $parsed_from[1] |
|
| 557 | + : get_bloginfo('admin_email'); |
|
| 558 | + return $from_email; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * Callback fro the wp_mail_from_name filter. |
|
| 564 | + * |
|
| 565 | + * @since 4.3.1 |
|
| 566 | + * @param string $from_name The original from_name. |
|
| 567 | + * @return string |
|
| 568 | + */ |
|
| 569 | + public function set_from_name($from_name) |
|
| 570 | + { |
|
| 571 | + $parsed_from = $this->_parse_from(); |
|
| 572 | + if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
| 573 | + $from_name = $parsed_from[0]; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
| 577 | + //but realize the default name is HTML entity-encoded |
|
| 578 | + $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name; |
|
| 579 | + |
|
| 580 | + return $from_name; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * setup body for email |
|
| 586 | + * |
|
| 587 | + * @param bool $preview will determine whether this is preview template or not. |
|
| 588 | + * @return string formatted body for email. |
|
| 589 | + * @throws EE_Error |
|
| 590 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 591 | + */ |
|
| 592 | + protected function _body($preview = false) |
|
| 593 | + { |
|
| 594 | + //setup template args! |
|
| 595 | + $this->_template_args = array( |
|
| 596 | + 'subject' => $this->_subject, |
|
| 597 | + 'from' => $this->_from, |
|
| 598 | + 'main_body' => wpautop($this->_content), |
|
| 599 | + ); |
|
| 600 | + $body = $this->_get_main_template($preview); |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
| 604 | + * |
|
| 605 | + * @type bool $preview Indicates whether a preview is being generated or not. |
|
| 606 | + * @return bool true indicates to use the inliner, false bypasses it. |
|
| 607 | + */ |
|
| 608 | + if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
| 609 | + //require CssToInlineStyles library and its dependencies via composer autoloader |
|
| 610 | + require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
| 611 | + |
|
| 612 | + //now if this isn't a preview, let's setup the body so it has inline styles |
|
| 613 | + if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
| 614 | + $style = file_get_contents( |
|
| 615 | + $this->get_variation( |
|
| 616 | + $this->_tmp_pack, |
|
| 617 | + $this->_incoming_message_type->name, |
|
| 618 | + false, |
|
| 619 | + 'main', |
|
| 620 | + $this->_variation |
|
| 621 | + ), |
|
| 622 | + true |
|
| 623 | + ); |
|
| 624 | + $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
| 625 | + //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
| 626 | + $body = ltrim($CSS->convert(true), ">\n"); |
|
| 627 | + //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
| 628 | + $body = ltrim($body, "<?"); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + } |
|
| 632 | + return $body; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * This just returns any existing test settings that might be saved in the database |
|
| 638 | + * |
|
| 639 | + * @access public |
|
| 640 | + * @return array |
|
| 641 | + */ |
|
| 642 | + public function get_existing_test_settings() |
|
| 643 | + { |
|
| 644 | + $settings = parent::get_existing_test_settings(); |
|
| 645 | + //override subject if present because we always want it to be fresh. |
|
| 646 | + if (is_array($settings) && ! empty($settings['subject'])) { |
|
| 647 | + $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
| 648 | + } |
|
| 649 | + return $settings; |
|
| 650 | + } |
|
| 651 | 651 | } |